BUG: Optimization Causes Code Generation Error In a Conditional StatementID: Q236119
|
The optimizer may generate incorrect code for an if statement that contains identical expressions in both conditional statements.
The optimizer makes a mistake when trying to move common sub-expressions to a single location.
There are 3 potential ways to work around this bug:
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
The following code demonstrates the problem and resolutions 1 and 3.
// compiler options: cl /Og
#include <iostream>
static long llll = 0;
double dTry1(double d) {
if (d < 0.0) {
llll++;
return(0.0);
} else {
llll++;
return(100.0);
}
}
#pragma optimize("g",off)
double dTry2(double d) {
if (d < 0.0) {
llll++;
return(0.0);
} else {
llll++;
return(100.0);
}
}
#pragma optimize("",on)
double dTry3(double d) {
llll++;
if (d < 0.0)
return(0.0);
else
return(100.0);
}
void main(){
using namespace std;
cout << "Result with Optimizer: " << dTry1(100.0) <<endl;
cout << "Result without Optimizer: " << dTry2(100.0) <<endl;
cout << "Result with moved sub-expression: " << dTry3(100.0) <<endl;
}
Additional query words:
Keywords : kbCodeGen kbVC500bug kbVC600bug kbDSupport kbGrpVCCompiler
Version : winnt:5.0,6.0
Platform : winnt
Issue type : kbbug
Last Reviewed: July 12, 1999