Bug 56672 - Bad optimization
Summary: Bad optimization
Status: RESOLVED DUPLICATE of bug 36996
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.3
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-21 08:56 UTC by Nic Roets
Modified: 2013-03-21 09:59 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
g++ -v output (498 bytes, text/plain)
2013-03-21 08:56 UTC, Nic Roets
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nic Roets 2013-03-21 08:56:35 UTC
Created attachment 29704 [details]
g++ -v output

For background see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36996

When compiled with -Os, the program below does not terminate. 

Here is my opinion: `mask` becomes undefined and it cause an unrelated variable `maskI' to become undefined. If that is a valid compilation of the program, it would make it very hard for programmers to reason about correctness.

#include <stdio.h>
int main ()
{
  int mask = 0, maskI;    
  for (maskI = 0; maskI < 4; maskI++) {              
    printf ("y %d\n", mask);
    mask += 0x55555555;
  }
  return 0;
}
Comment 1 Andreas Schwab 2013-03-21 09:21:59 UTC
A program that depends on undefined behaviour cannot be correct.
Comment 2 Richard Biener 2013-03-21 09:59:24 UTC
dup

*** This bug has been marked as a duplicate of bug 36996 ***