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/44828] possible integer wrong code bug
Date: Tue, 06 Jul 2010 10:35:00 -0000	[thread overview]
Message-ID: <20100706103515.10586.qmail@sourceware.org> (raw)
In-Reply-To: <bug-44828-12544@http.gcc.gnu.org/bugzilla/>



------- Comment #3 from rguenth at gcc dot gnu dot org  2010-07-06 10:35 -------
The bug is that we have in .original

{
  return si1 * si2;
}

while it should have been

{
  return (char)((unsigned char) si1 * (unsigned char) si2);
}

which is premature optimization by convert_to_integer, short-cutting
the correctly implemented fold of (signed char)((int) si1 * (int) si2)
to the above.

Index: gcc/convert.c
===================================================================
--- gcc/convert.c       (revision 161840)
+++ gcc/convert.c       (working copy)
@@ -774,7 +774,8 @@ convert_to_integer (tree type, tree expr
                        || ((!TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0))
                             || !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1)))
                            && (ex_form == PLUS_EXPR
-                               || ex_form == MINUS_EXPR)))
+                               || ex_form == MINUS_EXPR
+                               || ex_form == MULT_EXPR)))
                      typex = unsigned_type_for (typex);
                    else
                      typex = signed_type_for (typex);

fixes this.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-06 10:35:15
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44828


  parent reply	other threads:[~2010-07-06 10:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05 22:52 [Bug c/44828] New: " regehr at cs dot utah dot edu
2010-07-06  9:25 ` [Bug c/44828] " jakub at gcc dot gnu dot org
2010-07-06  9:33 ` jakub at gcc dot gnu dot org
2010-07-06 10:35 ` rguenth at gcc dot gnu dot org [this message]
2010-07-06 13:38 ` rguenth at gcc dot gnu dot org
2010-07-06 13:41 ` [Bug c/44828] [4.3/4.4/4.5 Regression] " rguenth at gcc dot gnu dot org
2010-07-06 14:11 ` regehr at cs dot utah dot edu
2010-07-07 22:52 ` bergner at gcc dot gnu dot org
2010-07-08  4:12 ` bergner at gcc dot gnu dot org
2010-07-08  4:19 ` bergner at gcc dot gnu dot org
2010-07-08  7:47 ` jakub at gcc dot gnu dot org
2010-07-08 11:57 ` [Bug c/44828] [4.3/4.4 " rguenth at gcc dot gnu dot org
2010-07-08 11:57 ` [Bug c/44828] [4.3/4.4/4.5 " rguenth at gcc dot gnu dot org
2010-07-08 14:18 ` [Bug c/44828] [4.3/4.4 " bergner at gcc dot gnu dot org
2010-07-27 11:24 ` rguenth at gcc dot gnu 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=20100706103515.10586.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).