diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-03-16 23:53:20 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-03-16 23:56:38 +0100 |
commit | 2691ffe6dbaffb704593dd6220178c28848b3855 (patch) | |
tree | 6bb3b115d089bfd0e1c6a6f2dd778cd75c4ca4b7 /gcc/d | |
parent | c62f5e6e1f457462b1cea74792833821bbea64bb (diff) |
d: Fix assignment to anonymous union member corrupts sibling members in struct
gcc/d/ChangeLog:
PR d/92309
* types.cc (fixup_anonymous_offset): Don't set DECL_FIELD_OFFSET on
anonymous fields.
gcc/testsuite/ChangeLog:
PR d/92309
* gdc.dg/pr92309.d: New test.
Diffstat (limited to 'gcc/d')
-rw-r--r-- | gcc/d/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/d/types.cc | 10 |
2 files changed, 13 insertions, 3 deletions
diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog index d9c7657eaac..ea43e3e82bd 100644 --- a/gcc/d/ChangeLog +++ b/gcc/d/ChangeLog @@ -1,5 +1,11 @@ 2020-03-16 Iain Buclaw <ibuclaw@gdcproject.org> + PR d/92309 + * types.cc (fixup_anonymous_offset): Don't set DECL_FIELD_OFFSET on + anonymous fields. + +2020-03-16 Iain Buclaw <ibuclaw@gdcproject.org> + PR d/92216 * decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target function is external to the current compilation. diff --git a/gcc/d/types.cc b/gcc/d/types.cc index 736f128422c..866da965b40 100644 --- a/gcc/d/types.cc +++ b/gcc/d/types.cc @@ -234,16 +234,20 @@ insert_aggregate_field (tree type, tree field, size_t offset) static void fixup_anonymous_offset (tree fields, tree offset) { + /* No adjustment in field offset required. */ + if (integer_zerop (offset)) + return; + while (fields != NULL_TREE) { - /* Traverse all nested anonymous aggregates to update their offset. - Set the anonymous decl offset to its first member. */ + /* Traverse all nested anonymous aggregates to update the offset of their + fields. Note that the anonymous field itself is not adjusted, as it + already has an offset relative to its outer aggregate. */ tree ftype = TREE_TYPE (fields); if (TYPE_NAME (ftype) && IDENTIFIER_ANON_P (TYPE_IDENTIFIER (ftype))) { tree vfields = TYPE_FIELDS (ftype); fixup_anonymous_offset (vfields, offset); - DECL_FIELD_OFFSET (fields) = DECL_FIELD_OFFSET (vfields); } else { |