2008-02-12 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Feb 2008 21:26:49 +0000 (21:26 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Feb 2008 21:26:49 +0000 (21:26 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132269 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 36e3c46..61d1567 100644 (file)
@@ -1,3 +1,9 @@
+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-02-12  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR middle-end/35136
index ea0b43e..a33b2b0 100644 (file)
@@ -7045,12 +7045,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 3fc12f5..00a713e 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-12  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/35163
+       * gcc.c-torture/execute/pr35163.c: New testcase.
+
 2008-02-12  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/asm-3.c: Fix dg-skip-if for all 32bit PIC targets.
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;
+}
+