public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36402]  New: -0x80000000 (INT_MIN) erroneously treated as unsigned
@ 2008-05-31 19:39 gcczilla at achurch dot org
  2008-05-31 19:50 ` [Bug c/36402] " ebotcazou at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcczilla at achurch dot org @ 2008-05-31 19:39 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-06-01 14:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-31 19:39 [Bug c/36402] New: -0x80000000 (INT_MIN) erroneously treated as unsigned gcczilla at achurch dot org
2008-05-31 19:50 ` [Bug c/36402] " ebotcazou at gcc dot gnu dot org
2008-06-01  4:17 ` gcczilla at achurch dot org
2008-06-01  7:26 ` ebotcazou at gcc dot gnu dot org
2008-06-01 12:22 ` joseph at codesourcery dot com
2008-06-01 14:00 ` [Bug c/36402] -0x80000000 (INT_MIN, -2147483648) " gcczilla at achurch dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).