https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124356
Bug ID: 124356
Summary: redundant initialization of inactive union member
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: xry111 at gcc dot gnu.org
Target Milestone: ---
struct r
{
int z;
union
{
int p[1000];
struct
{
int x, y;
};
};
} r;
int
main (void)
{
int x, y;
asm ("" : "=r"(x), "=r"(y));
struct r test = { .x = x, .y = y, };
asm ("" ::"m"(test));
return 0;
}
GCC insists to redundantly zero the entire struct
test = {};
test.D.2966.D.2965.x = x;
test.D.2966.D.2965.y = y;
Interestingly, explicitly initializing z to 0, i. e. struct r test = { .x = x,
.y = y, .z = 0 }; (IIUC it shouldn't cause a difference per the standard) makes
the zeroing gone:
test.z = 0;
test.D.2966.D.2965.x = x;
test.D.2966.D.2965.y = y;