re PR tree-optimization/73434 (Wrong code with casting, branches and aliasing)

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
This commit is contained in:
Richard Biener 2016-08-15 09:56:00 +00:00 committed by Richard Biener
parent 980bd53780
commit e4969090b6
4 changed files with 42 additions and 0 deletions

View 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

View 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

View File

@ -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;
}

View 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);