C9110003: Incorrect Code Generation When Using /Oe

ID Number: Q77140

6.00a 6.00ax | 6.00a 6.00ax

MS-DOS | OS/2

buglist6.00a buglist6.00ax fixlist7.00

Summary:

PROBLEM ID: C9110003

SYMPTOMS

When using the Microsoft C compiler version 6.0a or 6.0ax, and

compiling with the /Oe (enables global register allocation)

optimization switch, the code example below generates incorrect

code. However, C version 6.0 generates correct code.

The code example generates assembly instructions that rely on the

AX register to be cleared. Note, however, in the code fragment

below, that AX is not cleared at the appropriate time, as it is

when compiling with other optimizations.

RESOLUTION

To work around the problem, compile with the /qc (Quick Compile)

switch, do not use the /Oe option, or add a #pragma optimize

statement to disable global register optimizations (/Oe) for this

function.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0a and

6.0ax. This problem was corrected in C version 7.0

More Information:

Sample Code

-----------

/* Compile options needed: /c /Oe /Fc

*/

void test2(int,int,unsigned short);

void test1(int a,int b)

{

float f1=1.0f,f2=2.0f;

unsigned short size=b;

if(a) test2((int)(size*f2),(int)(size*f1),size);

else test2(1,1,size);

}

Sample Listing File Excerpt

---------------------------

;|*** if(a) test2((int)(size*f2),(int)(size*f1),size);

; Line 9

*** 000014 83 7e 04 00 cmp WORD PTR [bp+4],0

;a

*** 000018 74 36 je $I108

*** 00001a 56 push si

*** 00001b 2b c0 sub ax,ax

*** 00001d 89 46 f6 mov WORD PTR [bp-10],ax

*** 000020 89 46 f4 mov WORD PTR [bp-12],ax

*** 000023 89 46 f2 mov WORD PTR [bp-14],ax

*** 000026 89 76 f0 mov WORD PTR [bp-16],si

*** 000029 9b df 6e f0 fild QWORD PTR [bp-16]

*** 00002d e8 00 00 call __aNftol

*** 000030 50 push ax

;sub ax,ax should be generated here

*** 000031 c7 46 ee 00 00 mov WORD PTR [bp-

18],0

*** 000036 c7 46 ec 00 00 mov WORD PTR [bp-

20],0

*** 00003b 89 46 ea mov WORD PTR [bp-

22],ax

*** 00003e 89 76 e8 mov WORD PTR [bp-

24],si

.

.

.

Additional reference words: 6.00a 6.00ax