GCC seems to treat the 32-bit integer constant -0x80000000 (INT_MIN) as an
unsigned value, when it should be signed.  (I don't think this is a duplicate
of bug 25329, since I'm not trying to negate the constant.)  For example:

int a = 1;
int foo(void)
{
    return -0x80000000 < a;
}

improperly returns 0, even though -0x80000000 is less than any positive value. 
>From the assembly output, it seems as though GCC is treating -0x80000000 as an
unsigned value (using the unsigned "seta" instruction to interpret the
comparison result):

        movl    a, %eax
        cmpl    $-2147483648, %eax
        seta    %al

Changing the comparison to:
    return (int)-0x80000000 < a;  // Cast to signed
succeeds, as expected (interestingly using "setne" rather than "setg", though
certainly either works).


-- 
           Summary: -0x80000000 (INT_MIN) erroneously treated as unsigned
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcczilla at achurch dot org


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

Reply via email to