https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119085

            Bug ID: 119085
           Summary: tree-sra generates wrong code for unions containing
                    structs with holes
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pipcet at protonmail dot com
  Target Milestone: ---

Created attachment 60633
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60633&action=edit
test case

The attached test case asserts when compiled with trunk gcc:

$ gcc -O3 -o gcc-001 gcc-001.c -fdump-tree-sra
$ ./gcc-001 
gcc-001: gcc-001.c:32: main: Assertion `u.without_hole.y == -1' failed.
Aborted

I believe it should succeed, as it does when I specify -fno-tree-sra.

Po Lu identified the problem to most likely reside in
sort_and_splice_var_accesses, which chooses as the representative access for an
access group one which uses the "with_hole" structure, which has a hole, which
results in an incomplete copy being made.

This is similar to PR 58416, which introduced types_risk_mangled_binary_repr_p,
except that it is aggregate types which aren't "compatible" rather than integer
types.

A quick fix would be to replace types_risk_mangled_binary_repr_p by
!types_compatible_p, but that uses the language backend's definition of
compatibility, whereas we're only interested in the types having equivalent
"bit masks", meaning that the same bits are copied.

My apologies if I messed up in reducing the test case, but I'm convinced the
bug is real.

Reply via email to