Search

bug in cl (c compiler) by Dmitry Volkinshtein

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 676584
Opened: 6/22/2011 10:00:50 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
The following program gives incorrect output when compiled with optimization on x86 machine


#include <stdio.h>
#include <limits.h>

int main(int argc, char *argv[])
{
    volatile int i10 = 10;
    printf("%d\n", -(INT_MIN/i10));
    getchar();
}

The problem seems to be the following:
During the optimization process, the compiler tries to save the '-' at the end of the calculation by changing the sign of the constant dividend first instead. It is ok for all constant ints except INT_MIN because of the 2's complement feature: -INT_MIN==INT_MIN and the result of (-INT_MIN)/10 is negative. The output of the program is correct for other constants, and when the optimization if off (Debug)
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

Compile and run the program with optimization (Release) on x86 machine.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

-214748364

Expected results

214748364
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 6/23/2011 at 3:50 PM
Dimitry, my original response seems to have gotten lost in the ether. I wanted to thank for reporting all code generation issues that you've been submitting. This kind of feedback is valuable to us.

As you've correctly surmised in your report the optimizer is ignoring the case of MIN_INT when distrubuting the negation over the division. This will be fixed in the next major release of Visual Studio.

In the meantime this should be easy enough to identify and work around.

thanks,
ian Bearman
VC++ Code Generation and Optimization Team
Posted by MS-Moderator08 [Feedback Moderator] on 6/23/2011 at 2:17 AM
Thank you for reporting the issue.
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 MS-Moderator01 on 6/22/2011 at 10:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.