stor-layout: Create DECL_BIT_FIELD_REPRESENTATIVE even for bitfields in unions [PR101062]
authorJakub Jelinek <jakub@redhat.com>
Wed, 16 Jun 2021 10:17:55 +0000 (12:17 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 16 Jun 2021 10:17:55 +0000 (12:17 +0200)
commitb4b50bf2864e09f028a39a3f460222632c4d7348
tree158ad7b885e22418c2dac6cabb0002f47d740772
parent43fc4234ad3d9302d3460385b6fdb5e3f59b6986
stor-layout: Create DECL_BIT_FIELD_REPRESENTATIVE even for bitfields in unions [PR101062]

The following testcase is miscompiled on x86_64-linux, the bitfield store
is implemented as a RMW 64-bit operation at d+24 when the d variable has
size of only 28 bytes and scheduling moves in between the R and W part
a store to a different variable that happens to be right after the d
variable.

The reason for this is that we weren't creating
DECL_BIT_FIELD_REPRESENTATIVEs for bitfields in unions.

The following patch does create them, but treats all such bitfields as if
they were in a structure where the particular bitfield is the only field.

2021-06-16  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/101062
* stor-layout.c (finish_bitfield_representative): For fields in unions
assume nextf is always NULL.
(finish_bitfield_layout): Compute bit field representatives also in
unions, but handle it as if each bitfield was the only field in the
aggregate.

* gcc.dg/pr101062.c: New test.
gcc/stor-layout.c
gcc/testsuite/gcc.dg/pr101062.c [new file with mode: 0644]