public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcczilla at achurch dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/36402] New: -0x80000000 (INT_MIN) erroneously treated as unsigned
Date: Sat, 31 May 2008 19:39:00 -0000 [thread overview]
Message-ID: <bug-36402-6266@http.gcc.gnu.org/bugzilla/> (raw)
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
next reply other threads:[~2008-05-31 19:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-31 19:39 gcczilla at achurch dot org [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-36402-6266@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).