From 9386ff09db8df558a1ce3498faa2088d1d2daad4 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 30 Nov 2004 16:07:47 +0100 Subject: [PATCH] fold-const.c (extract_muldiv_1): If ctype is unsigned and type signed... * fold-const.c (extract_muldiv_1) : 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: r91526 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 16 +++++++++++++++- gcc/testsuite/ChangeLog | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 714d1fefa1af..ebd1d81d4730 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-11-30 Jakub Jelinek + + * fold-const.c (extract_muldiv_1) : If ctype is + unsigned and type signed, build ABS_EXPR with signed_type (ctype) + and only afterwards convert to ctype. + 2004-11-29 Richard Henderson PR target/17224 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b2bbf30cf921..e0889ce55cfd 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4486,7 +4486,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 (TREE_UNSIGNED (ctype) && !TREE_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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4d6db2e9373e..695af5856509 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-11-30 Jakub Jelinek + + * gcc.c-torture/execute/20041126-1.c: New test. + 2004-11-27 Falk Hueffner * gcc.dg/loop-6.c: New test. -- 2.47.2