public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/29919] New: constant propogation around comparison operators breaks things on underflow
@ 2006-11-20 22:04 bardwell at curl dot com
2006-11-20 22:12 ` [Bug middle-end/29919] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: bardwell at curl dot com @ 2006-11-20 22:04 UTC (permalink / raw)
To: gcc-bugs
There seems to be some constant propogation around comparison operators going
on, even with no optimization turned on which produces different behavior that
it used to with gcc-3.4.4 and different than what happens if you do some
casting.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = atoi(argv[1]);
if (0 <= (i - 1))
printf("no casting true\n");
else
printf("no casting false\n");
if (0 <= (signed int)((unsigned int)i - 1))
printf("casting true\n");
else
printf("casting false\n");
return 0;
}
produces different answers for the two comparisons if you give it INT_MIN
(-2147483647) because of over/underflow.
--
Summary: constant propogation around comparison operators breaks
things on underflow
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bardwell at curl dot com
GCC build triplet: gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)
GCC host triplet: i686-redhat-linux
GCC target triplet: i686-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29919
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/29919] constant propogation around comparison operators breaks things on underflow
2006-11-20 22:04 [Bug middle-end/29919] New: constant propogation around comparison operators breaks things on underflow bardwell at curl dot com
@ 2006-11-20 22:12 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-20 22:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2006-11-20 22:11 -------
if i is -2147483647, then i-1 will overflow which causes undefined behavior as
signed overflow in C is undefined (as declared by the C standard).
Use either -fwrapv which makes signed overflow as wrapping or the casts as you
already do.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29919
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-11-20 22:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-20 22:04 [Bug middle-end/29919] New: constant propogation around comparison operators breaks things on underflow bardwell at curl dot com
2006-11-20 22:12 ` [Bug middle-end/29919] " pinskia at gcc dot gnu 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).