re PR tree-optimization/71452 (Wrong optimization of stores to _Bool via char*)
authorRichard Biener <rguenther@suse.de>
Wed, 8 Jun 2016 13:11:43 +0000 (13:11 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 8 Jun 2016 13:11:43 +0000 (13:11 +0000)
2016-06-08  Richard Biener  <rguenther@suse.de>

PR tree-optimization/71452
* tree-ssa.c (non_rewritable_lvalue_p): Make sure that the
type used for the SSA rewrite has enough precision to cover
the dynamic type of the location.

* gcc.dg/torture/pr71452.c: New testcase.

From-SVN: r237214

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr71452.c [new file with mode: 0644]
gcc/tree-ssa.c

index 6ad6ddc5b907557279290cd0de78d394bbbc82e5..4f5d3177f1e2d24f64eb96a06ccbda44f909ba71 100644 (file)
@@ -1,3 +1,10 @@
+2016-06-08  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71452
+       * tree-ssa.c (non_rewritable_lvalue_p): Make sure that the
+       type used for the SSA rewrite has enough precision to cover
+       the dynamic type of the location.
+
 2016-06-08  Jakub Jelinek  <jakub@redhat.com>
            Richard Biener  <rguenther@suse.de>
 
index d8b668cfaabda6e692999ad924be6fe4b0ab09c2..28b17cf4d02751e1cbe4d3ad1ff6c8dcb653cd8a 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-08  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71452
+       * gcc.dg/torture/pr71452.c: New testcase.
+
 2016-06-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/71448
diff --git a/gcc/testsuite/gcc.dg/torture/pr71452.c b/gcc/testsuite/gcc.dg/torture/pr71452.c
new file mode 100644 (file)
index 0000000..8948d39
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+int main()
+{
+  _Bool b;
+  *(char *)&b = 123;
+  if (*(char *)&b != 123)
+    __builtin_abort ();
+  return 0;
+}
index 2f3caf341ddce94076ce56f07ab9ccc7042c97ac..30c6269e34530a1a11d8e04aeabc900239bce3db 100644 (file)
@@ -1292,6 +1292,14 @@ non_rewritable_lvalue_p (tree lhs)
       if (integer_zerop (TREE_OPERAND (lhs, 1))
          && DECL_P (decl)
          && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
+         /* If the dynamic type of the decl has larger precision than
+            the decl itself we can't use the decls type for SSA rewriting.  */
+         && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl))
+              || compare_tree_int (DECL_SIZE (decl),
+                                   TYPE_PRECISION (TREE_TYPE (decl))) == 0)
+             || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
+                 && (TYPE_PRECISION (TREE_TYPE (decl))
+                     >= TYPE_PRECISION (TREE_TYPE (lhs)))))
          && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
        return false;