diff options
author | Jakub Jelinek <jakub@redhat.com> | 2004-11-27 11:13:56 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2004-11-27 11:13:56 +0100 |
commit | 47d42ce2710bf905381c70cf2cd8c7b3495b4af0 (patch) | |
tree | d42b0016cfb2a956039363a27cfd89764e73ef14 /gcc/fold-const.c | |
parent | 87980da05e5466d35e0de2b767112896292cd2c9 (diff) | |
download | gcc-47d42ce2710bf905381c70cf2cd8c7b3495b4af0.zip gcc-47d42ce2710bf905381c70cf2cd8c7b3495b4af0.tar.gz gcc-47d42ce2710bf905381c70cf2cd8c7b3495b4af0.tar.bz2 |
fold-const.c (extract_muldiv_1): If ctype is unsigned and type signed...
* fold-const.c (extract_muldiv_1) <case ABS_EXPR>: If ctype is
unsigned and type signed, build ABS_EXPR with signed_type (ctype)
and only afterwards convert to ctype.
* gcc.c-torture/execute/20041126-1.c: New test.
From-SVN: r91373
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 167fc03..eca8c96 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5127,7 +5127,21 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) return t1; break; - case NEGATE_EXPR: case ABS_EXPR: + case ABS_EXPR: + /* If widening the type changes it from signed to unsigned, then we + must avoid building ABS_EXPR itself as unsigned. */ + if (TYPE_UNSIGNED (ctype) && !TYPE_UNSIGNED (type)) + { + tree cstype = (*lang_hooks.types.signed_type) (ctype); + if ((t1 = extract_muldiv (op0, c, code, cstype)) != 0) + { + t1 = fold (build1 (tcode, cstype, fold_convert (cstype, t1))); + return fold_convert (ctype, t1); + } + break; + } + /* FALLTHROUGH */ + case NEGATE_EXPR: if ((t1 = extract_muldiv (op0, c, code, wide_type)) != 0) return fold (build1 (tcode, ctype, fold_convert (ctype, t1))); break; |