summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/convert.c
diff options
context:
space:
mode:
authorkan <kan@FreeBSD.org>2002-09-01 20:38:57 +0000
committerkan <kan@FreeBSD.org>2002-09-01 20:38:57 +0000
commit2e25f3a6c57335cba50111faceb0ce2ab59e9bcb (patch)
treec6857d31c36dbd89a881b0229bf38b062797d413 /contrib/gcc/convert.c
parent0895e1acb698e05d503c26bec5471de2e88b7d93 (diff)
downloadFreeBSD-src-2e25f3a6c57335cba50111faceb0ce2ab59e9bcb.zip
FreeBSD-src-2e25f3a6c57335cba50111faceb0ce2ab59e9bcb.tar.gz
Gcc 3.2.1-prerelease from the FSF anoncvs repo gcc-3_2-branch on 1-Sep-2002 00:00:01 EDT.
Diffstat (limited to 'contrib/gcc/convert.c')
-rw-r--r--contrib/gcc/convert.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/contrib/gcc/convert.c b/contrib/gcc/convert.c
index 127b22b..156c2cf 100644
--- a/contrib/gcc/convert.c
+++ b/contrib/gcc/convert.c
@@ -227,9 +227,11 @@ convert_to_integer (type, expr)
case LSHIFT_EXPR:
/* We can pass truncation down through left shifting
- when the shift count is a nonnegative constant. */
+ when the shift count is a nonnegative constant and
+ the target type is unsigned. */
if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
&& tree_int_cst_sgn (TREE_OPERAND (expr, 1)) >= 0
+ && TREE_UNSIGNED (type)
&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
{
/* If shift count is less than the width of the truncated type,
@@ -311,12 +313,15 @@ convert_to_integer (type, expr)
/* 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.
+ unsigned then we can safely do the work as unsigned;
+ if we are distributing through a LSHIFT_EXPR, we must
+ do the work as unsigned to avoid a signed overflow.
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))))
+ && TREE_UNSIGNED (TREE_TYPE (arg1)))
+ || ex_form == LSHIFT_EXPR)
? unsigned_type (typex) : signed_type (typex));
return convert (type,
fold (build (ex_form, typex,
OpenPOWER on IntegriCloud