From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10688 invoked by alias); 6 Jul 2010 10:35:34 -0000 Received: (qmail 10587 invoked by uid 48); 6 Jul 2010 10:35:15 -0000 Date: Tue, 06 Jul 2010 10:35:00 -0000 Message-ID: <20100706103515.10586.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/44828] possible integer wrong code bug In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg00542.txt.bz2 ------- 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