[comp.sys.ibm.pc.programmer] Microsoft C 6.0 BAD code generation

mshiels@tmsoft.uucp (Michael A. Shiels) (06/13/90)

One of my co workers was trying to start using Microsoft C 6.0 but found out
that it's just like Microsfot C 5.1.  You have to disable most of the
optimizations so it will generate correct code.  Here's his very simple sample
code which doesn't have anything to do with loops but is broken when you specify
loop optimizations.

 
/**************************************************************************/
/* cl -c -Gs -Zl -FPc -Oswrl -Awfl -W4 -Fa c6badeg.c                          */
/*                                                                          */
/* NOTE:  THIS WORKS IF THE '-O...l' IS NOT INCLUDED!                     */
/*          I PERSONALLY DON'T KNOW WHAT LOOP OPTIMIZATION HAS TO DO WITH   */
/*          THIS CODE.                                                          */
/*          '-Oswer' DOESN'T WORK EITHER!!                                  */
/**************************************************************************/
 
struct graphd {
    double  mins[2];
    double  maxs[2];
};
 
extern        struct        graphd *CurrentGraph;
 
 
void        check_range(
double *val,
int        range)
{
    if (*val > CurrentGraph->maxs[range])
        CurrentGraph->maxs[range] = *val;
    if (*val < CurrentGraph->mins[range])
        CurrentGraph->mins[range] = *val;
}
 
/**************************************************************************/
/*
;        Static Name Aliases
;
        TITLE        c6badeg.c
        .8087
C6BADEG_TEXT   SEGMENT        WORD PUBLIC 'CODE'
C6BADEG_TEXT   ENDS
_DATA        SEGMENT  WORD PUBLIC 'DATA'
_DATA        ENDS
CONST        SEGMENT  WORD PUBLIC 'CONST'
CONST        ENDS
_BSS        SEGMENT  WORD PUBLIC 'BSS'
_BSS        ENDS
DGROUP        GROUP        CONST, _BSS, _DATA
        ASSUME DS: DGROUP
        ASSUME        SS: NOTHING
EXTRN        __aFeldd:FAR
EXTRN        __aFfcompp:FAR
EXTRN        _CurrentGraph:DWORD
EXTRN        __fltused:NEAR
C6BADEG_TEXT          SEGMENT
        ASSUME        CS: C6BADEG_TEXT
; Line 1
; Line 14
C6BADEG_TEXT          ENDS
CONST           SEGMENT
$T20001 DW SEG _CurrentGraph
CONST           ENDS
C6BADEG_TEXT          SEGMENT
        ASSUME        CS: C6BADEG_TEXT
        PUBLIC        _check_range
_check_range        PROC FAR
        push        bp
        mov        bp,sp
        push        di
        push        si
;        val = 6
;        range = 10
; Line 15
        les        bx,DWORD PTR [bp+6]        ;val
        call        FAR PTR __aFeldd
        mov        es,WORD PTR $T20001
        les        bx,DWORD PTR es:_CurrentGraph
        add        bx,16
        mov        cl,3
        mov        si,WORD PTR [bp+10]        ;range
        shl        si,cl
        lea        bx,WORD PTR [bx][si]
        call        FAR PTR __aFeldd
        call        FAR PTR __aFfcompp
        jae        $I106
; Line 16
        mov        cl,3
        mov        bx,WORD PTR [bp+10]        ;range
        shl        bx,cl
        mov        es,WORD PTR $T20001
        les        si,DWORD PTR es:_CurrentGraph
        mov        ax,WORD PTR [bp+6]        ;val
        mov        dx,WORD PTR [bp+8]
        push        ds
        lea        di,WORD PTR [bx+16][si]
        mov        si,ax
        mov        ds,dx
        ASSUME DS: NOTHING
        movsw
        movsw
        movsw
        movsw
        pop        ds
        ASSUME DS: DGROUP
; Line 17
$I106:
        les        bx,DWORD PTR [bp+6]        ;val
        call        FAR PTR __aFeldd
        mov        es,WORD PTR $T20001
        les        bx,DWORD PTR es:_CurrentGraph
        mov        cl,3
        mov        si,WORD PTR [bp+10]        ;range
        shl        si,cl
        lea        bx,WORD PTR [bx][si]
        call        FAR PTR __aFeldd
        call        FAR PTR __aFfcompp
        jbe        $EX105
; Line 18
        mov        es,WORD PTR $T20001
        les        bx,DWORD PTR es:_CurrentGraph
        mov        si,WORD PTR [bp+6]        ;val
        mov        dx,WORD PTR [bp+8]
        push        ds
        lea        di,WORD PTR [bx][si]
        mov        ds,dx
        ASSUME DS: NOTHING
        movsw
        movsw
        movsw
        movsw
        pop        ds
        ASSUME DS: DGROUP
; Line 19
$EX105:
        pop        si
        pop        di
        mov        sp,bp
        pop        bp
        ret
 
_check_range        ENDP
C6BADEG_TEXT   ENDS
END
*/