This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Bugfix to convert_to_integer
- To: gcc-patches at gcc dot gnu dot org
- Subject: Bugfix to convert_to_integer
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- Date: Fri, 23 Feb 01 16:15:09 EST
It isn't safe to use an unsigned type for a computation if only one operand
was unsigned. We might have had a case where an unsigned type was converted
to a wider signed type and then had a negative number added in that type.
Doing the computation as unsigned in the narrower type is wrong.
Tested on alphaev56 and applied to main and GCC 3.0 branch.
Fri Feb 23 15:28:39 2001 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* convert.c (convert_to_integer): Don't do unsigned unless result or
both inputs are unsigned.
*** convert.c 2000/07/12 16:17:15 1.12
--- convert.c 2001/02/23 19:27:10
*************** convert_to_integer (type, expr)
*** 311,321 ****
/* Don't do unsigned arithmetic where signed was wanted,
or vice versa.
! Exception: if either of the original operands were
unsigned then can safely do the work as unsigned.
And we may need to do it as unsigned
if we truncate to the original size. */
typex = ((TREE_UNSIGNED (TREE_TYPE (expr))
! || TREE_UNSIGNED (TREE_TYPE (arg0))
! || TREE_UNSIGNED (TREE_TYPE (arg1)))
? unsigned_type (typex) : signed_type (typex));
return convert (type,
--- 311,321 ----
/* Don't do unsigned arithmetic where signed was wanted,
or vice versa.
! Exception: if both of the original operands were
unsigned then can safely do the work as unsigned.
And we may need to do it as unsigned
if we truncate to the original size. */
typex = ((TREE_UNSIGNED (TREE_TYPE (expr))
! || (TREE_UNSIGNED (TREE_TYPE (arg0))
! && TREE_UNSIGNED (TREE_TYPE (arg1))))
? unsigned_type (typex) : signed_type (typex));
return convert (type,