FIX: Global Code Optimization Generates Incorrect CodeLast reviewed: September 18, 1997Article ID: Q115527 |
|
7.00 | 1.00 1.50
MS-DOS | WINDOWS
kbtool kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSThe code below illustrates a bug in the C/C++ compiler that occurs when the /Ox, /Ol, /Oe, or /Og compiler switch is used. As a result of the optimization, the code below is stuck executing an infinite loop because of source code optimization. By using the /Fc compiler option, the code within the if statement is optimized out of the source code, as shown in the assembly output.
RESOLUTIONThere are four workarounds to this problem:
STATUSMicrosoft has confirmed this to be a bug in the products listed above. This problem was corrected in C/C++ compiler version 9.0, included with Visual C++ 32-bit Edition, version 2.0.
MORE INFORMATIONThe following sample demonstrates this problem.
Sample Code
/* Compile options needed: /c /Fc /Ox (or /Ol, /Oe, or /Og)
*/
#include <stdio.h>
static int fault, state;
int test_func (void)
{
if (state == 2)
{
state=0; // No code generated for this block if
optimized
/* state=0; */ // works if this line's comment is removed
if (fault == 0) //
return(1); //
else //
return(-1); //
}
else
return(0);
}
void main(void)
{
state = 2;
while (test_func() == 1);
printf("done\n");
}
|
Additional reference words: 1.00 1.50 7.00 8.00 8.00c
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |