From: Richard Biener Date: Mon, 15 Aug 2016 09:56:00 +0000 (+0000) Subject: re PR tree-optimization/73434 (Wrong code with casting, branches and aliasing) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e4969090b68ff266b29c86b6aebec25812666fc4;p=gcc.git re PR tree-optimization/73434 (Wrong code with casting, branches and aliasing) 2016-08-15 Richard Biener 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 32e9439d0d4..4e6ffb46a3c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-08-15 Richard Biener + + 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 * dwarf2out.c (struct checksum_attributes): Add diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6fa7c1f274f..fc25482e1bb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-15 Richard Biener + + PR tree-optimization/73434 + * gcc.dg/torture/pr73434.c: New testcase. + 2016-08-15 Jakub Jelinek 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 index 00000000000..624e0c6ccfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr73434.c @@ -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; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index e889d6063e6..21b3d566052 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1225,6 +1225,18 @@ vn_reference_maybe_forwprop_address (vec *ops, { auto_vec 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);