Skip to content

Members omitted from nested or "?"/"," aggregate initializers not zeroed [GH #625] - #626

Open
daveedvdv-nvidia wants to merge 1 commit into
mainfrom
fix/625
Open

daveedvdv-nvidia wants to merge 1 commit into
mainfrom
fix/625

Conversation

@daveedvdv-nvidia

@daveedvdv-nvidia daveedvdv-nvidia commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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:

struct C { C(); };
struct P { C c; int k; };
int g();
P x = (g(), P{});        // x.k not zeroed
P y = b ? P{} : P{};     // y.k not zeroed
P z[1] = { P{} };        // z[0].k not zeroed

Cause

When a variable's own initializer is partial, lowering marks the variable for zero-initialization as a whole, and stretch_partial_initialization_if_necessary zeroes 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_necessary now returns whether it generated zeroing code.
  • In the dik_nonconstant_aggregate case of lower_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.

A memset of the subobject was not used instead, since it would run after the enclosing initializer and wipe constants the nested initializer keeps (e.g., the 5 in { P3{ C(), 5 }, g() }).

Testing

  • New runtime test regressions/gh-625 (12 checks, each run on a stack filled with garbage; fails without the fix).
  • Full default test suite: only the five known pre-existing mismatches (cwg1835, cwg2881, pr106188, pr115905, lambda-04-templ-parm).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed aggregate initialization cases where omitted members could remain uninitialized when other initializer parts required runtime evaluation. Omitted members are now zero-initialized in nested aggregates and initializers involving conditional or comma expressions, while explicitly provided values are preserved. Pointer-to-member fields are also initialized correctly on IA-64.
  • Tests
    • Added regression coverage for omitted members across aggregate, array, and expression-based initialization cases.

@daveedvdv-nvidia
daveedvdv-nvidia requested a review from a team December 1, 2026 01:23
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Aggregate lowering now tracks whether partial initialization generated zero-initialization. When needed, it retains implicit zero values. The change also handles aggregate pointer-to-data-member initialization under IA64_ABI. A GH-625 note and regression tests cover omitted members in several initializer forms.

Changes: Aggregate initialization zeroing

Layer / File(s) Summary
Track zeroing during aggregate lowering
src/lower_init.c, src/lower_il.c, src/lower_il.h
The partial-initialization helper reports whether it generated zeroing code. Aggregate lowering uses that result to preserve the aggregate constant when omitted values were not zeroed. Under IA64_ABI, it also fills in pointer-to-data-member initialization for the retained constant.
Document and test omitted-member zeroing
src/pending_changes/gh-625-nested-aggregate-init-zeroing.txt, tests/tests/regressions/gh-625.sft.cpp, tests/tests/regressions/.gh-625.rto/*
The note describes affected cases. Regression tests check omitted members in comma and conditional expressions, nested aggregates, arrays, returns, and pointer-to-member initialization.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: bug

Suggested reviewers: darkarc, nv-cmeerw

Merge Risk: Minimal · up to b8381

This change zero-initializes omitted members of nonconstant aggregate initializers in the affected cases, including null data-member pointers under IA64. A new regression test covers these cases. No concrete defect was found, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: omitted members of nested aggregate initializers and of initializers used with "?" or "," were not zero-initialized, and the PR zero-initializes them. It also cites th…
Linked Issues check Passed Issue #625 requires zero-initialization of omitted members in a partial nonconstant aggregate initializer when the initializer needs code, has no constant part, and either initializes part of an enclo…
Out of Scope Changes check Passed The changes since the previous review add the IA64_ABI pointer-to-data-member zeroing path. This path makes the static helper fill_out_aggregate_ptr_to_data_member_initialization externally linked…
Full details: Title check

Explanation

The title names the main change: omitted members of nested aggregate initializers and of initializers used with "?" or "," were not zero-initialized, and the PR zero-initializes them. It also cites the linked issue GH #625. The title is specific and matches the changeset and the linked issue objectives. It is 82 characters, which is slightly long but acceptable.

Full details: Linked Issues check

Explanation

Issue #625 requires zero-initialization of omitted members in a partial nonconstant aggregate initializer when the initializer needs code, has no constant part, and either initializes part of an enclosing initializer or is a ?/, operand that initializes a variable. The previous assessment found this implemented in src/lower_init.c. stretch_partial_initialization_if_necessary returns whether it generated zeroing code. In the dik_nonconstant_aggregate path, a partial initializer with variable == NULL that was not zeroed keeps its constant, so implicit zeros precede the dynamic code. The new head adds IA64_ABI handling for pointer-to-data-member fields. The header diff (base to head) declares fill_out_aggregate_ptr_to_data_member_initialization. The raw summary states that src/lower_il.c exports this function and that lower_init.c calls it under IA64_ABI. This covers the issue's requirement that omitted members, including non-class members, become zero. Pointer-to-data-member fields are not all-zero bits under IA64_ABI, so a plain zero fill would be wrong there. The regression test tests/tests/regressions/gh-625.sft.cpp is stated to check that omitted pointer-to-member fields become null. The diff for src/lower_il.c and src/lower_init.c could not be read in this review (diff metadata unavailable), so the IA64 path rests on the header diff and the summary. The prior PASS for the core fix is preserved.

Full details: Out of Scope Changes check

Explanation

The changes since the previous review add the IA64_ABI pointer-to-data-member zeroing path. This path makes the static helper fill_out_aggregate_ptr_to_data_member_initialization externally linked and declares it in src/lower_il.h. The PR's review comment raised the pointer-to-member case for P p = (g(), P{});, so the helper supports the #625 zeroing objective. It is not unrelated work. The PR description does not mention this path. The function's linkage change is internal to the compiler, with no exported API change of user-facing behavior. The other files (regression test, pending_changes note, .rto fixtures) support the objective. The source diff for src/lower_il.c could not be read directly, so the claim that its body is unchanged rests on the summary.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1b82cbc and b8381ee.

Files selected for processing: 9

  • src/lower_il.c
  • src/lower_il.h
  • src/lower_init.c
  • src/pending_changes/gh-625-nested-aggregate-init-zeroing.txt
  • tests/tests/regressions/.gh-625.rto/default.1.1.txt
  • tests/tests/regressions/.gh-625.rto/default.1.2.txt
  • tests/tests/regressions/.gh-625.rto/default.2.1.txt
  • tests/tests/regressions/.gh-625.rto/default.2.2.txt
  • tests/tests/regressions/gh-625.sft.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 1b82cbc3ac99:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 1b82cbc3ac99:

CI success.

@nv-cmeerw nv-cmeerw left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For pointer to member types it shouldn't be just zeroed:

struct C { C() { } };
struct P { C c; int C::*k; };

void g() {}

int main()
{
  P p = (g(), P{});
  return p.k != nullptr;
}

@daveedvdv-nvidia

Copy link
Copy Markdown
Contributor Author

For pointer to member types it shouldn't be just zeroed:

struct C { C() { } };
struct P { C c; int C::*k; };

void g() {}

int main()
{
P p = (g(), P{});
return p.k != nullptr;
}

Oh, yes. Thanks!

That's hopefully fixed now.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for b8381ee528a8:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for b8381ee528a8:

CI success.

@nv-cmeerw

Copy link
Copy Markdown
Contributor

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;
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Members omitted from a nonconstant aggregate initializer left uninitialized

3 participants