public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/40907] -O2 generates incorrect code on i386
Date: Wed, 29 Jul 2009 18:13:00 -0000	[thread overview]
Message-ID: <20090729181251.17574.qmail@sourceware.org> (raw)
In-Reply-To: <bug-40907-18000@http.gcc.gnu.org/bugzilla/>



------- 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


      parent reply	other threads:[~2009-07-29 18:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-29 17:35 [Bug c/40907] New: " sperber at deinprogramm dot de
2009-07-29 17:37 ` [Bug c/40907] " sperber at deinprogramm dot de
2009-07-29 17:40 ` pinskia at gcc dot gnu dot org
2009-07-29 17:41 ` pinskia at gcc dot gnu dot org
2009-07-29 17:42 ` sperber at deinprogramm dot de
2009-07-29 18:13 ` rguenth at gcc dot gnu dot org [this message]

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=20090729181251.17574.qmail@sourceware.org \
    --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).