Skip to content

Diagnose array designators in initializers of variable-length arrays [GH #556] - #568

Open
lexx42xxel wants to merge 1 commit into
edgcpp:mainfrom
lexx42xxel:fix/vla-array-designator-diagnostic
Open

lexx42xxel wants to merge 1 commit into
edgcpp:mainfrom
lexx42xxel:fix/vla-array-designator-diagnostic

Conversation

@lexx42xxel

@lexx42xxel lexx42xxel commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes the problem reported in triage discussion #556.

Problem and fix

GNU C++ mode accepts an initializer for a variable-length array, but the
lowering of designated initializers assumes that the designated array has
a constant size. An array designator in such an initializer (for the VLA
itself or for a VLA nested in it) silently lost the designated values,
wrote rows past the end of the array, or hit an internal error; range
designators hit an internal error as well. g++ does not support these
initializers either. Issue an error instead. Designators for arrays of
constant size within the initializer, field designators, and designators
for arrays of pointers to VLAs are still accepted.

Alternatives considered

Implement designated initialization with run-time indices. Rejected for now: large change for a GNU extension combination that g++ itself rejects ("sorry, unimplemented").

Tests

New: tests/tests/regressions/vla-array-designator-negative.sft.cpp.
Verified failing on main and passing with the fix (IA-64 and non-IA-64 builds); reproducer in the discussion.

Checklist

  • Open issue: not yet; reported in triage discussion Array designators in GNU VLA initializers lose values or crash the compiler #556, per CONTRIBUTING.
    Commits are tagged [GH #556] with the discussion number; happy to retag once an issue is opened.
  • Commits are tagged [GH #556].
  • Design and alternatives are described above.
  • No measurable compile-time/memory impact expected (localized lowering change); see the bench job.
  • Changes are localized (src/decl_inits.c, src/error_msg.txt).
  • EDG style; comments updated.
  • Changes entry: src/pending_changes/gh-556-vla-array-designator.txt.
  • Tests fail before and pass after: vla-array-designator-negative.
  • edg-docker-test --posture=extensive (edg_x86_64, edg_x86_64_cp, edg_x86_32, edg_x86_32_cp): no regressions; recordings updated with -W.

Summary by CodeRabbit

  • Bug Fixes
    • GNU C++ mode now reports an error when array designators are used to initialize variable-length arrays, including nested and range designators.
    • Invalid initializers are handled without losing designated values, writing beyond array bounds, or triggering an internal error.
    • Array designators for fixed-size arrays, field designators, and positional initialization remain accepted.

@lexx42xxel
lexx42xxel requested a review from a team November 20, 2026 07:47
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Non-C modes now diagnose array designators for variable-length arrays and follow the invalid-designator recovery path. A regression test covers six such cases and four accepted controls. The diagnostic catalog and a pending-changes note also include the change.

Changes: VLA array designator diagnosis

Layer / File(s) Summary
Diagnose VLA array designators
src/decl_inits.c, src/error_msg.txt, tests/tests/regressions/vla-array-designator-negative.sft.cpp, tests/tests/regressions/.vla-array-designator-negative.rto/default.1.1.txt, src/pending_changes/gh-556-vla-array-designator.txt
Non-C modes now report a dedicated diagnostic for array designators in variable-length array initializers and use the invalid-designator recovery path. C mode retains its existing bounds check. The regression test covers six rejected cases and four accepted controls; the expected output records six errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: daveedvdv, daveedvdv-nvidia

Merge Risk: Minimal · up to f9a4a

This change makes the compiler report an error for array designators in variable-length array initializers in non-C modes, instead of risking lost values, out-of-bounds writes or internal errors. Constant-size arrays and field designators are still accepted. No actionable merge risk was found.

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 states the main change: array designators in initializers of variable-length arrays are now diagnosed. The raw summary confirms that aggr_init_array_designator reports ec_array_designator_fo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: array designators in initializers of variable-length arrays are now diagnosed. The raw summary confirms that aggr_init_array_designator reports ec_array_designator_for_vla for VLA types in non-C modes, and the objectives describe the same goal. The GH #556 reference matches the linked triage discussion. The title is specific, concise, and free of vague terms.

Finishing Touches

Generate unit tests (beta)

  • 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 123522f and f9a4a66.

Files selected for processing: 5

  • src/decl_inits.c
  • src/error_msg.txt
  • src/pending_changes/gh-556-vla-array-designator.txt
  • tests/tests/regressions/.vla-array-designator-negative.rto/default.1.1.txt
  • tests/tests/regressions/vla-array-designator-negative.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 fd527d711e3d:

…[GH edgcpp#556]

GNU C++ mode accepts an initializer for a variable-length array, but the
lowering of designated initializers assumes that the designated array has
a constant size.  An array designator in such an initializer (for the VLA
itself or for a VLA nested in it) silently lost the designated values,
wrote rows past the end of the array, or hit an internal error; range
designators hit an internal error as well.  g++ does not support these
initializers either.  Issue an error instead.  Designators for arrays of
constant size within the initializer, field designators, and designators
for arrays of pointers to VLAs are still accepted.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lexx42xxel
lexx42xxel force-pushed the fix/vla-array-designator-diagnostic branch from fd527d7 to f9a4a66 Compare November 20, 2026 10:39
@lexx42xxel

Copy link
Copy Markdown
Author

Rebased onto current main (123522f) to resolve a merge conflict in src/error_msg.txt. #477 ("Initial support for C++26 enumerating expansion statements", commit e88c89d, GH #216) appended 8 ec_* messages at the same place as this PR's ec_array_designator_for_vla. The conflict is only in where the line goes: the new message now comes after those 8, so the existing message numbers are unchanged. No other changes.

Retested after the rebase: rebuilt, and ran all regressions/ tests plus all VLA and designator tests (295 tests) on edg_x86_64, edg_x86_64_cp, edg_x86_32 and edg_x86_32_cp, with no differences.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for f9a4a66330a5:

CI success.

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.

2 participants