re PR tree-optimization/32100 (vrp bitfield miscompilation)
authorAndrew Pinski <andrew_pinski@playstation.sony.com>
Mon, 28 May 2007 19:43:10 +0000 (19:43 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Mon, 28 May 2007 19:43:10 +0000 (12:43 -0700)
2007-05-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/32100
        * fold-const.c (tree_expr_nonnegative_warnv_p): Don't
        return true when truth_value_p is true and the type
        is of signed:1.

2007-05-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/32100
         * gcc.c-torture/execute/vrp-7.c: New test.

From-SVN: r125139

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

index db6a377..0b34249 100644 (file)
@@ -1,3 +1,10 @@
+2007-05-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR tree-opt/32100
+       * fold-const.c (tree_expr_nonnegative_warnv_p): Don't
+       return true when truth_value_p is true and the type
+       is of signed:1.
+
 2007-05-28  Gerald Pfeifer  <gerald@pfeifer.com>
 
        * doc/install.texi (Prerequisites): We no longer require Autoconf
index 16dfd3b..01ce961 100644 (file)
@@ -13485,9 +13485,14 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p)
       /* ... fall through ...  */
 
     default:
-      if (truth_value_p (TREE_CODE (t)))
-       /* Truth values evaluate to 0 or 1, which is nonnegative.  */
-       return true;
+      {
+       tree type = TREE_TYPE (t);
+       if ((TYPE_PRECISION (type) != 1 || TYPE_UNSIGNED (type))
+           && truth_value_p (TREE_CODE (t)))
+         /* Truth values evaluate to 0 or 1, which is nonnegative unless we
+             have a signed:1 type (where the value is -1 and 0).  */
+         return true;
+      }
     }
 
   /* We don't know sign of `t', so be conservative and return false.  */
index 86111bf..2e546eb 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR tree-opt/32100
+       * gcc.c-torture/execute/vrp-7.c: New test.
+        
 2007-05-28  Brooks Moses  <brooks.moses@codesourcery.com>
 
        * gfortran.dg/transfer_simplify_4.f90: New test.
diff --git a/gcc/testsuite/gcc.c-torture/execute/vrp-7.c b/gcc/testsuite/gcc.c-torture/execute/vrp-7.c
new file mode 100644 (file)
index 0000000..b4c9e62
--- /dev/null
@@ -0,0 +1,20 @@
+
+void abort (void);
+
+struct T
+{
+  int b : 1;
+} t;
+
+void __attribute__((noinline)) foo (int f)
+{
+  t.b = (f & 0x10) ? 1 : 0;
+}
+
+int main (void)
+{
+  foo (0x10);
+  if (!t.b)
+    abort ();
+  return 0;
+}