aboutsummaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-06-16 12:17:55 +0200
committerJakub Jelinek <jakub@redhat.com>2021-06-16 12:17:55 +0200
commitb4b50bf2864e09f028a39a3f460222632c4d7348 (patch)
tree158ad7b885e22418c2dac6cabb0002f47d740772 /gcc/stor-layout.c
parent43fc4234ad3d9302d3460385b6fdb5e3f59b6986 (diff)
downloadgcc-b4b50bf2864e09f028a39a3f460222632c4d7348.zip
gcc-b4b50bf2864e09f028a39a3f460222632c4d7348.tar.gz
gcc-b4b50bf2864e09f028a39a3f460222632c4d7348.tar.bz2
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.
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 94b8b21..4e3a41b 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2072,9 +2072,14 @@ finish_bitfield_representative (tree repr, tree field)
bitsize = (bitsize + BITS_PER_UNIT - 1) & ~(BITS_PER_UNIT - 1);
/* Now nothing tells us how to pad out bitsize ... */
- nextf = DECL_CHAIN (field);
- while (nextf && TREE_CODE (nextf) != FIELD_DECL)
- nextf = DECL_CHAIN (nextf);
+ if (TREE_CODE (DECL_CONTEXT (field)) == RECORD_TYPE)
+ {
+ nextf = DECL_CHAIN (field);
+ while (nextf && TREE_CODE (nextf) != FIELD_DECL)
+ nextf = DECL_CHAIN (nextf);
+ }
+ else
+ nextf = NULL_TREE;
if (nextf)
{
tree maxsize;
@@ -2167,13 +2172,6 @@ finish_bitfield_layout (tree t)
tree field, prev;
tree repr = NULL_TREE;
- /* Unions would be special, for the ease of type-punning optimizations
- we could use the underlying type as hint for the representative
- if the bitfield would fit and the representative would not exceed
- the union in size. */
- if (TREE_CODE (t) != RECORD_TYPE)
- return;
-
for (prev = NULL_TREE, field = TYPE_FIELDS (t);
field; field = DECL_CHAIN (field))
{
@@ -2233,7 +2231,13 @@ finish_bitfield_layout (tree t)
if (repr)
DECL_BIT_FIELD_REPRESENTATIVE (field) = repr;
- prev = field;
+ if (TREE_CODE (t) == RECORD_TYPE)
+ prev = field;
+ else if (repr)
+ {
+ finish_bitfield_representative (repr, field);
+ repr = NULL_TREE;
+ }
}
if (repr)