]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.c (extract_muldiv_1): If ctype is unsigned and type signed...
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 Nov 2004 15:07:47 +0000 (16:07 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 Nov 2004 15:07:47 +0000 (16:07 +0100)
* 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: r91526

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog

index 714d1fefa1afa7fca187e58341d43fd91a8edc75..ebd1d81d4730be9fef4125aee2ae06a137f7a457 100644 (file)
@@ -1,3 +1,9 @@
+2004-11-30  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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.
+
 2004-11-29  Richard Henderson  <rth@redhat.com>
 
        PR target/17224
index b2bbf30cf92149023ca64cc869343041ccfbc8b9..e0889ce55cfd3d6aa84d0e2b8efe7e18a6eeea6a 100644 (file)
@@ -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;
index 4d6db2e9373e9854e508184c731ae95b60ede5b7..695af58565093f098aeafdc25c66ecd0ca09e83f 100644 (file)
@@ -1,3 +1,7 @@
+2004-11-30  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc.c-torture/execute/20041126-1.c: New test.
+
 2004-11-27  Falk Hueffner  <falk@debian.org>
 
        * gcc.dg/loop-6.c: New test.