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.
  • Under the IA-64 ABI, a null pointer to data member is -1 rather 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 recursive fill_out_nested_ptr_to_data_member_initialization applies fill_out_aggregate_ptr_to_data_member_initialization (now exported from src/lower_il.c) to each level.

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 (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).
  • 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 cases where omitted members in nested aggregates could remain uninitialized when other initializer parts required runtime evaluation. Omitted members are now zero-initialized in aggregate, array, conditional-expression, and comma-expression initializers while 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 code. When the remainder was not zeroed, it retains implicit zero values for omitted members. Under IA64_ABI, it also fills out nested pointer-to-data-member initializers. A note and regression tests describe and exercise these cases.

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 initialization code. Aggregate lowering uses that result to preserve the aggregate constant when omitted values were not zeroed. Under IA64_ABI, it fills out nested pointer-to-data-member initializers.
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-data-member initialization under C++11 and C++17.

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • edgcpp/compiler#569: Changes aggregate initialization lowering and handles the IA-64 null pointer-to-data-member representation, which overlaps with this PR’s lowering changes.

Suggested labels: bug

Suggested reviewers: darkarc, nv-cmeerw

Merge Risk: Minimal · up to 6f173

The change makes omitted members of nested or conditional aggregate initializers zero-initialize, including null pointers to data members, and adds regression tests for those cases. No merge-blocking risk was identified in the supplied material.

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 were not zero-initialized, which the PR fixes. The changeset matches this. It adds zeroing…
Linked Issues check Passed Issue #625 requires zero-initialization of omitted members when a partial braced initializer needs code, has no constant part, and either initializes part of an enclosing initializer or is a ?/, o…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes src/lower_init.c, which contains the #625 fix. It changes src/lower_il.c only by removing static from `fill_out_aggregate_ptr_to_data_member_initiali…
Full details: Title check

Explanation

The title names the main change: omitted members of nested aggregate initializers and of ?/, initializers were not zero-initialized, which the PR fixes. The changeset matches this. It adds zeroing in lower_dynamic_init and stretch_partial_initialization_if_necessary, a regression test for GH #625, and a pending-change note. The title also gives the issue number, so a reader scanning history can find the fix.

Full details: Linked Issues check

Explanation

Issue #625 requires zero-initialization of omitted members when a partial braced initializer needs code, has no constant part, and either initializes part of an enclosing initializer or is a ?/, operand that initializes a variable. The reviewed head implements this in src/lower_init.c. stretch_partial_initialization_if_necessary now returns whether it generated zeroing code. In lower_dynamic_init, when variable == NULL, the initializer is partial, and no zeroing was generated, the code sets keep_constant = TRUE. The kept constant's implicit zero elements then initialize omitted members before the dynamic code. Under IA64_ABI, fill_out_nested_ptr_to_data_member_initialization makes omitted pointers to data members explicit at each nested level, which covers the non-zero null representation. The regression test tests/tests/regressions/gh-625.sft.cpp, per the summary, covers class and non-class members, arrays, nested aggregates, and ?/, operands. The test was not read directly. The core change was verified from the whole-PR diff against the merge base. The prior PASS is supported by the current code.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes src/lower_init.c, which contains the #625 fix. It changes src/lower_il.c only by removing static from fill_out_aggregate_ptr_to_data_member_initialization. The helper is declared in src/lower_il.h under IA64_ABI, and the IA64 path in lower_init.c calls it, so the linkage change supports the objective. The other files are the regression test, the pending-change note, and the .rto fixtures. These support the #625 fix and its testing. No unrelated functional change was found. The regression test and .rto contents were not read directly and rest on the summary.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • 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 b8381ee and 6f173c2.

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

@daveedvdv-nvidia

Copy link
Copy Markdown
Contributor Author

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

Thanks! Hopefully fixed for real now.

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