Home Dashboard Directory Help

VC++2010 ignores side effects when skips initialization of unused variables by NKolotey


 as Deferred Help for as Deferred

Sign in
to vote
Type: Bug
ID: 678200
Opened: 7/2/2011 9:23:06 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
User(s) can reproduce this bug


When VC++2010 builds code in Release configuration with default options, compiler skips initialization of unused variables, but this sometimes lead to skipping calls of functions that have side effects. This behavoiur is inobvious and can lead to security holes.
Sign in to post a comment.
Posted by Microsoft on 7/19/2011 at 3:42 PM
Thanks for reporting this issue. Their appears to be an error in the optimizer regarding recursive function calls and global side-effects. The problem can manifest in any function that modifies global state and calls itself.
To work around this limitation you can disable optimizations in the function that is exhibiting the problem (the recursive function). This can be done by placing #pragma optimize(“”, off)/#pragma optimize(“”, on) around the function (see MSDN for more details on this pragma). Another option is to mark the global variable used in the function as volatile. Both of these options will fix the issue at some cost to code quality.
This issue is currently being addressed and will be fixed in a future release of Visual Studio.
ian Bearman
VC++ Code Generation and Optimization
Posted by MS-Moderator09 [Feedback Moderator] on 7/4/2011 at 12:06 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 7/2/2011 at 9:48 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.
Posted by NKolotey on 7/2/2011 at 9:26 PM
Add "volatile" specifier to "int count". Or comment /*int foo =*/