This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/40907] -O2 generates incorrect code on i386
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Jul 2009 18:12:51 -0000
- Subject: [Bug c/40907] -O2 generates incorrect code on i386
- References: <bug-40907-18000@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #5 from rguenth at gcc dot gnu dot org 2009-07-29 18:12 -------
long lo_b_2268X;
long lo_a_2267X;
long lo_c_2271X;
...
lo_a_2267X = 65535 & a_1962X;
lo_b_2268X = 65535 & b_2266X;
...
lo_c_2271X = ((lo_a_2267X) * (lo_b_2268X));
...
if ((536870911 < lo_c_2271X)) {
...
else {
if ((lo_c_2271X < 0)) {
as these are all signed quantities the multiplication in
lo_c_2271X = ((lo_a_2267X) * (lo_b_2268X)) if overflowing invokes
undefined behavior according to the C language standard. Thus
the compiler assumes that multiplying two positive signed values
is always positive.
Use -fwrapv if you want twos-complement semantics for signed integers.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907