[Bug c/55075] New: GCC optimizer makes bad assumptions on data range

2012-10-25 Thread julvr at broadcom dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55075



 Bug #: 55075

   Summary: GCC optimizer makes bad assumptions on data range

Classification: Unclassified

   Product: gcc

   Version: 4.6.2

Status: UNCONFIRMED

  Severity: major

  Priority: P3

 Component: c

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: ju...@broadcom.com





Created attachment 28531

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28531

Simple file to demonstrate problem



When compiling a simple program, the compiler makes a bad assumption about the

possible range a value can have.  As a result, in the attached example, it

raises a compile error.  It is unknown if this can cause other, more subtle

errors at this time, however, it is suspected that it may produce bad code in

certain circumstances.



This bug is visible in gcc versions 4.6.2 (cross compiler for mips) and 4.7.1

(native compiler for pc).   This bug does not occur on 4.5.1.



It is also known that the bug only occurs with optimization level -O2.  It does

not occur with -O1.





I have attached test1.c.  To reproduce the bug, compile with:



gcc -O2 -Werror=array-bounds -c test1.c





test1.c:



static int x = 0;

int main(void) {

while (1) {

{ volatile int somearray[1]; somearray[x] = 0; }

x--;

if (x <= 0) {

   return;

}

{ volatile int somearray[1]; somearray[x] = 0; }



}

}


[Bug tree-optimization/55075] GCC optimizer makes bad assumptions on data range

2012-10-25 Thread julvr at broadcom dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55075



John Ulvr  changed:



   What|Removed |Added



 Status|UNCONFIRMED |RESOLVED

 Resolution||INVALID



--- Comment #2 from John Ulvr  2012-10-25 21:44:23 
UTC ---

Sorry, so this is my bad -- In our original environment, x was restricted to 0

or 1, but the compiler would likely not have caught on to this.



I am closing.



Thanks



John