[Bug c/45884] New: Incorrect removal of check for "less than zero" after adding value to (signed) long

anders_jagd at yahoo dot com gcc-bugzilla@gcc.gnu.org
Mon Oct 4 17:58:00 GMT 2010


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

           Summary: Incorrect removal of check for "less than zero" after
                    adding value to (signed) long
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: anders_jagd@yahoo.com


Created attachment 21959
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=21959
Source (test.c), Makefile, Binaries, test.i, gcc -dumpspecs etc. See README.txt

When compiled with -O2, the below (val < 0) check is, under some conditions
(see attachment), optimized away:

...
long val10, val;
char *s;
...
if((*s >= '0') && (*s <= '9')) {
    val10 = val * 10; // Skip overflow check, not the issue we are showing
    val   = val10 + (*s - '0');

    /****** OPTIMIZED AWAY IN CASE OF -O2 ******/
    if(val < 0) {
    /* Overflow */
    return -1;
    }
    ...
}

Build on ubuntu (2.6.32-25-generic)
gcc version 4.4.3-4ubuntu5
machine i486-linux-gnu

Attaching complete test case with:

   Makefile
   Source (test.c)
   Binaries
   Result from compiling with -save-temps (test.i)
   System configuration, gcc -dumpspecs, etc.



More information about the Gcc-bugs mailing list