BUG: Incorrect Code Generated with /Og OptimizationID: Q194608
|
A code sequence similar to the following generates incorrect code when
compiled with global (/Og) optimization:
( ( ConstantValue << Variable ) + OptimizableValue );
You can work around this problem by removing global optimization from the
command line or by disabling global optimization on a per-function basis
with the optimize pragma.
Another workaround is to simplify the code and use a temporary global
variable as illustrated in the MORE INFORMATION section of this article.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
The following code outputs 0 if compiled with /Og and 1 if compiled with /Od.
#include <iostream>
#define SIZE (unsigned int)512
static unsigned int new_depth = 1;
// #pragma optimize("g",off) // Uncomment for Workaround One.
int main()
{
unsigned int result = ( ( 8 << new_depth ) + SIZE - 1 ) / SIZE;
std::cout << "Result = " << result ;
return 0;
}
// #pragma optimize("g",on) // Uncomment for Workaround One.
#include <iostream>
#define SIZE (unsigned int)512
static unsigned int new_depth = 1;
unsigned int result1;
int main()
{
result1 = ( 8 << new_depth );
unsigned int result2 = ( ( result1 + SIZE - 1 ) / SIZE );
std::cout << "Result = " << result2 ;
return 0;
}
Additional query words: compiler
Keywords : kbCodeGen kbCompiler kbVC500bug kbVC600bug
Version : winnt:5.0,6.0
Platform : winnt
Issue type : kbbug
Last Reviewed: July 8, 1999