Repository navigation
Members omitted from nested or "?"/"," aggregate initializers not zeroed [GH #625] - #626
daveedvdv-nvidia wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
440c656 to
1b82cbc
Compare
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI success. |
1b82cbc to
b8381ee
Compare
Oh, yes. Thanks! That's hopefully fixed now. |
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI success. |
|
Another one with nested initializers: struct C { int n; C() { }; };
struct S { C c; int C::*p; };
struct O { S s; };
void g() { }
int main() {
O o = (g(), O{{}});
return o.s.p != nullptr;
} |
b8381ee to
6f173c2
Compare
Thanks! Hopefully fixed for real now. |
Fixes #625: In configurations that do IL lowering, a member omitted from a braced aggregate initializer could be left uninitialized instead of zero-initialized.
This happened when the initializer's other parts need code (e.g., a constructor call), the initializer has no constant part, and it either initializes part of an enclosing initializer or is an operand of a
?or,operator initializing a variable:Cause
When a variable's own initializer is partial, lowering marks the variable for zero-initialization as a whole, and
stretch_partial_initialization_if_necessaryzeroes partially initialized entities reached through a pointer. Neither applies here, and since there's no constant part, no aggregate constant is kept whose implicit zeros would cover the omitted members.Fix (
src/lower_init.c)stretch_partial_initialization_if_necessarynow returns whether it generated zeroing code.dik_nonconstant_aggregatecase oflower_dynamic_init, a partial initializer with no variable of its own that wasn't zeroed now keeps its constant. Its implicit zeros are then put out ahead of the dynamic code: through the existing static-temporary copy for the?/,case, or as part of the enclosing variable's C initializer when nested.-1rather than all zero bits, so such a pointer's implicit zero can't be left to the C initializer. The kept constant's omitted pointers to data members are therefore made explicit, also in its nested aggregates: the new recursivefill_out_nested_ptr_to_data_member_initializationappliesfill_out_aggregate_ptr_to_data_member_initialization(now exported fromsrc/lower_il.c) to each level.A
memsetof the subobject was not used instead, since it would run after the enclosing initializer and wipe constants the nested initializer keeps (e.g., the5in{ P3{ C(), 5 }, g() }).Testing
regressions/gh-625(24 checks, some of them on pointers to data members omitted at nested levels, each run on a stack filled with garbage; fails without the fix).cwg1835,cwg2881,pr106188,pr115905,lambda-04-templ-parm).Summary by CodeRabbit