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; }



    }

}

Reply via email to