VC++ 2008 64-bit compiler optimization bug - by Aaron Severn

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 518179 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 12/4/2009 9:26:40 AM
Access Restriction Public


I've attached an example of a 64-bit VC++ compiler optimization bug that I recently ran into, along with the asm that was produced, annotated to show the problem.  The example is highly contrived, but I originally found the bug in a proprietary math library.
Sign in to post a comment.
Posted by Microsoft on 12/23/2009 at 11:14 AM
Thank you for reporting this issue. It is under investigation.

As a workaround, you might enclose the code updating the pointer with EH construct. For example:
try {
    while (*A->current->t < w) {
        A->current = A->current->next;
} catch(...){
// do nothing
Posted by Microsoft on 12/8/2009 at 7:38 PM
Thanks for your feedback. We were able to reproduce the issue you are seeing. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Aaron Severn on 12/8/2009 at 8:39 AM
Here is the contents of the build log, showing all compiler options, linked libraries, etc.

Creating temporary file "c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\RSP00000539843464.rsp" with contents
/O2 /Oi /GL /D "_MBCS" /FD /EHsc /MD /Gy /Fo"x64\Release\\" /Fd"x64\Release\vc90.pdb" /W3 /c /Zi /TP "..\..\OptimizationBug\OptimizationBug\Source1.cpp"
Creating command line "cl.exe @"c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\RSP00000539843464.rsp" /nologo /errorReport:prompt"
Creating temporary file "c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\RSP00000639843464.rsp" with contents
/OUT:"C:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\x64\Release\OptimizationBug2.exe" /MANIFEST /MANIFESTFILE:"x64\Release\OptimizationBug2.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\x64\Release\OptimizationBug2.pdb" /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

Creating command line "link.exe @"c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\RSP00000639843464.rsp" /NOLOGO /ERRORREPORT:PROMPT"
Creating temporary file "c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\RSP00000739843464.rsp" with contents
/outputresource:"..\x64\Release\OptimizationBug2.exe;#1" /manifest

Creating command line "mt.exe @"c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\RSP00000739843464.rsp" /nologo"
Creating temporary file "c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\BAT00000839843464.bat" with contents
@echo Manifest resource last updated at %TIME% on %DATE% > ".\x64\Release\mt.dep"
Creating command line """c:\My Documents\Visual Studio 2008\Projects\OptimizationBug2\OptimizationBug2\x64\Release\BAT00000839843464.bat"""
Output Window     Compiling...
Generating code
Finished generating code
Embedding manifest...
Posted by Aaron Severn on 12/8/2009 at 7:13 AM
I can reproduce it by the following steps, using MS Visual Studio 2008 Professional.

1. Create a new empty project.
2. In the Configuration Manager, add a new configuration for x64 (using only default settings).
3. Add the file that I attached (Source1.cpp) to the project.
4. Change to Release.
5. Build Solution.

Running it will produce the wrong result, viewing the disassembly will show the incorrect asm that I provided.
Posted by Microsoft on 12/8/2009 at 2:54 AM

Thanks for reporting the issue.
In order to fix the issue, we must first reproduce the issue in our labs. We are unable to reproduce the issue with the steps you provided.

Could you please provide the command you used to compile the file?

Thanks again for your efforts and we look forward to hearing from you.
Visual Studio Product Team
Posted by Microsoft on 12/5/2009 at 1:05 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(