]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/35163 (folding comparison loses cast)
authorRichard Guenther <rguenther@suse.de>
Tue, 25 Mar 2008 10:14:15 +0000 (10:14 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 25 Mar 2008 10:14:15 +0000 (10:14 +0000)
2008-03-25  Richard Guenther  <rguenther@suse.de>

        Backport from mainline:
        2008-02-12  Richard Guenther  <rguenther@suse.de>

        PR middle-end/35163
        * fold-const.c (fold_widened_comparison): Use get_unwidened in
        value-preserving mode.  Disallow final truncation.

        * gcc.c-torture/execute/pr35163.c: New testcase.

From-SVN: r133508

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr35163.c [new file with mode: 0644]

index 5690848458d29a427d2198caac0fc45b7fe584e4..c6890b7735934bdc1fb5671b75ee61547b53570a 100644 (file)
@@ -1,3 +1,12 @@
+2008-03-25  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2008-02-12  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/35163
+       * fold-const.c (fold_widened_comparison): Use get_unwidened in
+       value-preserving mode.  Disallow final truncation.
+
 2008-03-13  David Edelsohn  <edelsohn@gnu.org>
 
        Backport from mainline:
index 782a30200ce96ec257aca585b7ca9dbab341fdd7..23523debf41fea038dc1f86e9f63b074284f1622 100644 (file)
@@ -6656,12 +6656,14 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
   if (TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (shorter_type))
     return NULL_TREE;
 
-  arg1_unw = get_unwidened (arg1, shorter_type);
+  arg1_unw = get_unwidened (arg1, NULL_TREE);
 
   /* If possible, express the comparison in the shorter mode.  */
   if ((code == EQ_EXPR || code == NE_EXPR
        || TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type))
       && (TREE_TYPE (arg1_unw) == shorter_type
+         || (TYPE_PRECISION (shorter_type)
+             >= TYPE_PRECISION (TREE_TYPE (arg1_unw)))
          || (TREE_CODE (arg1_unw) == INTEGER_CST
              && (TREE_CODE (shorter_type) == INTEGER_TYPE
                  || TREE_CODE (shorter_type) == BOOLEAN_TYPE)
index e7ff577516681aca9980c267630434f7d77c9478..10d1710f3834c454758189172e8dc7abde144617 100644 (file)
@@ -1,3 +1,11 @@
+2008-03-25  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2008-02-12  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/35163
+       * gcc.c-torture/execute/pr35163.c: New testcase.
+
 2008-03-09  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/frame_overflow.adb: Improve portability.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr35163.c b/gcc/testsuite/gcc.c-torture/execute/pr35163.c
new file mode 100644 (file)
index 0000000..4950d6d
--- /dev/null
@@ -0,0 +1,11 @@
+extern void abort(void);
+
+int main()
+{
+  signed char a = -30;
+  signed char b = -31;
+  if (a > (unsigned short)b)
+    abort ();
+  return 0;
+}
+