FIX: Bad Code Generated by Global Optimization (236349)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q236349 SYMPTOMS
For builds that use global optimization (/Og), the condition of an if or while statement in which two pointers are compared and incremented, can appear to be false when in fact the condition is true. This problem occurs only under a fairly narrow set of circumstances. See the sample code in the "More Information" section for an example. Note that both the "maximize speed" (/O2) and "minimize size" (/O1) optimizations are composite optimization switches that include /Og.
CAUSE
The optimizer has incorrectly removed a CMP instruction.
RESOLUTION
Disable the global optimizations for the function, source file, or project in question. Global optimizations can be disabled on a function-by-function basis by using #pragma optimize. Global optimizations can be disabled for a source file (or project) by adding /Og- to the file's (or project's) settings. See "workaround #2" in the "More Information" section for an example of the #pragma approach.
Another workaround is to move the increment (or decrement) of the pointers outside the comparison. See "workaround #3" in the "More Information" section for an example of this approach.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This problem was corrected in Microsoft Visual C++ .NET.
Modification Type: | Major | Last Reviewed: | 11/18/2003 |
---|
Keywords: | kbBug kbCodeGen kbfix kbNoUpdate KB236349 |
---|
|