fold-const.c (fold_widened_comparison): Do not allow sign-changes that change the...
authorRichard Guenther <rguenther@suse.de>
Tue, 8 Apr 2008 21:57:43 +0000 (21:57 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 8 Apr 2008 21:57:43 +0000 (21:57 +0000)
2008-04-08  Richard Guenther  <rguenther@suse.de>

* fold-const.c (fold_widened_comparison): Do not allow
sign-changes that change the result.

* gcc.c-torture/execute/20080408-1.c: New testcase.

From-SVN: r134108

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

index c7b8ad017f994cef1e2c6b9509bf4cf9b5c0acd0..1151620508ed8d751c32468efc5cf37c5438dac2 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-08  Richard Guenther  <rguenther@suse.de>
+
+       * fold-const.c (fold_widened_comparison): Do not allow
+       sign-changes that change the result.
+
 2008-04-08  Janis Johnson  <janis187@us.ibm.com>
 
        PR target/35839
index 26550b911698ca69af9f54c2809e60fe3a79a2a2..66e72a7d0ad7aaf2ce771039bc98b8dbc53a2121 100644 (file)
@@ -6721,7 +6721,11 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
        || 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)))
+             > TYPE_PRECISION (TREE_TYPE (arg1_unw)))
+         || ((TYPE_PRECISION (shorter_type)
+              == TYPE_PRECISION (TREE_TYPE (arg1_unw)))
+             && (TYPE_UNSIGNED (shorter_type)
+                 == TYPE_UNSIGNED (TREE_TYPE (arg1_unw))))
          || (TREE_CODE (arg1_unw) == INTEGER_CST
              && (TREE_CODE (shorter_type) == INTEGER_TYPE
                  || TREE_CODE (shorter_type) == BOOLEAN_TYPE)
index 89353a747871f239270db368d6f2af6565536443..be29996431676d4415538d5fc0be03a512f00d21 100644 (file)
@@ -1,3 +1,7 @@
+2008-04-08  Richard Guenther  <rguenther@suse.de>
+
+       * gcc.c-torture/execute/20080408-1.c: New testcase.
+
 2008-04-08  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/pack6.adb: New test.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20080408-1.c b/gcc/testsuite/gcc.c-torture/execute/20080408-1.c
new file mode 100644 (file)
index 0000000..9e1ff63
--- /dev/null
@@ -0,0 +1,11 @@
+extern void abort (void);
+int main ()
+{
+  short ssi = 126;
+  unsigned short usi = 65280;
+  int fail = !(ssi < usi);
+  if (fail)
+    abort ();
+  return 0;
+}
+