re PR tree-optimization/73434 (Wrong code with casting, branches and aliasing)
authorRichard Biener <rguenther@suse.de>
Mon, 15 Aug 2016 09:56:00 +0000 (09:56 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 15 Aug 2016 09:56:00 +0000 (09:56 +0000)
2016-08-15  Richard Biener  <rguenther@suse.de>

PR tree-optimization/73434
* tree-ssa-sccvn.c (vn_reference_maybe_forwprop_address): Preserve
TBAA info on the base when forwarding a non-invariant address.

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

From-SVN: r239471

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

index 32e9439d0d40fb496708f34ef7120d46e030f03f..4e6ffb46a3ca21002cf9902695358526eca6b710 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-15  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/73434
+       * tree-ssa-sccvn.c (vn_reference_maybe_forwprop_address): Preserve
+       TBAA info on the base when forwarding a non-invariant address.
+
 2016-08-15  Jakub Jelinek  <jakub@redhat.com>
 
        * dwarf2out.c (struct checksum_attributes): Add
index 6fa7c1f274f9b0db3cc2e7b3d4c98426f4e6e70f..fc25482e1bb735a2ed3b9be0d4b2984d90cae792 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-15  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/73434
+       * gcc.dg/torture/pr73434.c: New testcase.
+
 2016-08-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/72824
diff --git a/gcc/testsuite/gcc.dg/torture/pr73434.c b/gcc/testsuite/gcc.dg/torture/pr73434.c
new file mode 100644 (file)
index 0000000..624e0c6
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+typedef struct { unsigned char x; } A;
+typedef struct { unsigned char x; } B;
+
+int idx = 0;
+
+A objs[1] = {{0}};
+
+int main()
+{
+  B *b = (B*)&objs[idx];
+  b->x++;
+  if (b->x)
+    b->x = 0;
+  if (b->x)
+    __builtin_abort ();
+  return 0;
+}
index e889d6063e6ec99a1a00ee778ecd0816dcf3e3d7..21b3d56605278f80b661c8ae8449fa6e5eb410db 100644 (file)
@@ -1225,6 +1225,18 @@ vn_reference_maybe_forwprop_address (vec<vn_reference_op_s> *ops,
        {
          auto_vec<vn_reference_op_s, 32> tem;
          copy_reference_ops_from_ref (TREE_OPERAND (addr, 0), &tem);
+         /* Make sure to preserve TBAA info.  The only objects not
+            wrapped in MEM_REFs that can have their address taken are
+            STRING_CSTs.  */
+         if (tem.length () >= 2
+             && tem[tem.length () - 2].opcode == MEM_REF)
+           {
+             vn_reference_op_t new_mem_op = &tem[tem.length () - 2];
+             new_mem_op->op0 = fold_convert (TREE_TYPE (mem_op->op0),
+                                             new_mem_op->op0);
+           }
+         else
+           gcc_assert (tem.last ().opcode == STRING_CST);
          ops->pop ();
          ops->pop ();
          ops->safe_splice (tem);