]> gcc.gnu.org Git - gcc.git/commit
tree-sra: Fix union handling in build_reconstructed_reference
authorMartin Jambor <mjambor@suse.cz>
Fri, 1 Jul 2022 18:57:18 +0000 (20:57 +0200)
committerMartin Jambor <mjambor@suse.cz>
Mon, 4 Jul 2022 15:07:04 +0000 (17:07 +0200)
commitb110e5283e368b5377e04766e4ff82cd52634208
treeb969fd0417da3f245932d3ea64abaf6f9f08daaf
parent3769ad4ccea9589b3f7edaef901cb542aa10f49a
tree-sra: Fix union handling in build_reconstructed_reference

As the testcase in PR 105860 shows, the code that tries to re-use the
handled_component chains in SRA can be horribly confused by unions,
where it thinks it has found a compatible structure under which it can
chain the references, but in fact it found the type it was looking
for elsewhere in a union and generated a write to a completely wrong
part of an aggregate.

I don't remember whether the plan was to support unions at all in
build_reconstructed_reference but it can work, to an extent, if we
make sure that we start the search only outside the outermost union,
which is what the patch does (and the extra testcase verifies).

gcc/ChangeLog:

2022-07-01  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/105860
* tree-sra.cc (build_reconstructed_reference): Start expr
traversal only just below the outermost union.

gcc/testsuite/ChangeLog:

2022-07-01  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/105860
* gcc.dg/tree-ssa/alias-access-path-13.c: New test.
* gcc.dg/tree-ssa/pr105860.c: Likewise.
gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-13.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr105860.c [new file with mode: 0644]
gcc/tree-sra.cc
This page took 0.065918 seconds and 5 git commands to generate.