C++ compiler pointer arithmetic problem (wrong result with /Od optimization) - by Ilias A

Status : 


Sign in
to vote
ID 778524 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/5/2013 12:52:03 AM
Access Restriction Public


When trying to get a sum of 2 numeric value of addresses that belong to char buffer one of the terms is ignored depending on the presence of parentheses. This only happens with /Od optimization. With optimizations /O1 and /O2 the result of computation is always correct.
Sign in to post a comment.
Posted by Microsoft on 11/13/2013 at 2:25 PM
Hi, we will address this in a future release. I am closing this MSConnect item. Feel free to respond if you need anything else.

Eric Brumer
Microsoft Visual C++ Team
Posted by Microsoft on 2/19/2013 at 1:25 PM
Hi, thanks for the bug report. I have confirmed that this is a compiler bug when optimizations are not enabled. Even without optimization, the compiler attempts to generate good code for x86 by combining elements into an efficient address mode (that can do base + index * scale addressing).

In this case, the compiler is failing to include the address of tmp_arr in the address mode correctly.

You can work around the bug by using a different code pattern (as in the assignment to v1) or by introducing a local variable for the second calculation ((unsigned long)(tmp_arr) + 1).

Mark Levine
Microsoft VC++ team
Posted by Microsoft on 2/5/2013 at 2:47 AM
Thanks for your feedback.

We are rerouting 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 Microsoft on 2/5/2013 at 1:50 AM
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)