Commit 2691ffe6 by Iain Buclaw

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.
parent c62f5e6e
2020-03-16 Iain Buclaw <ibuclaw@gdcproject.org> 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 PR d/92216
* decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target * decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target
function is external to the current compilation. function is external to the current compilation.
......
...@@ -234,16 +234,20 @@ insert_aggregate_field (tree type, tree field, size_t offset) ...@@ -234,16 +234,20 @@ insert_aggregate_field (tree type, tree field, size_t offset)
static void static void
fixup_anonymous_offset (tree fields, tree offset) fixup_anonymous_offset (tree fields, tree offset)
{ {
/* No adjustment in field offset required. */
if (integer_zerop (offset))
return;
while (fields != NULL_TREE) while (fields != NULL_TREE)
{ {
/* Traverse all nested anonymous aggregates to update their offset. /* Traverse all nested anonymous aggregates to update the offset of their
Set the anonymous decl offset to its first member. */ 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); tree ftype = TREE_TYPE (fields);
if (TYPE_NAME (ftype) && IDENTIFIER_ANON_P (TYPE_IDENTIFIER (ftype))) if (TYPE_NAME (ftype) && IDENTIFIER_ANON_P (TYPE_IDENTIFIER (ftype)))
{ {
tree vfields = TYPE_FIELDS (ftype); tree vfields = TYPE_FIELDS (ftype);
fixup_anonymous_offset (vfields, offset); fixup_anonymous_offset (vfields, offset);
DECL_FIELD_OFFSET (fields) = DECL_FIELD_OFFSET (vfields);
} }
else else
{ {
......
2020-03-16 Iain Buclaw <ibuclaw@gdcproject.org> 2020-03-16 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/92309
* gdc.dg/pr92309.d: New test.
2020-03-16 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/92216 PR d/92216
* gdc.dg/imports/pr92216.d: New. * gdc.dg/imports/pr92216.d: New.
* gdc.dg/pr92216.d: New test. * gdc.dg/pr92216.d: New test.
......
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92309
// { dg-do run { target hw } }
// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
union U
{
struct
{
size_t a;
size_t b;
union
{
size_t c;
size_t d;
}
}
}
void main()
{
U u;
assert(u.a == 0);
u.d = 1;
assert(u.a == 0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment