Skip to content

Avoid linear AST expansion for local array initializers - #603

Open
admkopec wants to merge 1 commit into
AbsInt:masterfrom
admkopec:fix/local-array-initializer-expansion
Open

admkopec wants to merge 1 commit into
AbsInt:masterfrom
admkopec:fix/local-array-initializer-expansion

Conversation

@admkopec

@admkopec admkopec commented Oct 4, 2026

Copy link
Copy Markdown

Fixes #602.

Change

When lowering a local array declaration, Unblock currently emits a separate assignment AST node for every element not explicitly listed in the initializer. Consequently, the AST and compiler memory usage grow with the declared array bound even when the initializer has a fixed source size, such as { 0 }.

This PR retains the existing individual assignments for explicitly initialized elements and represents the remaining implicit tail with a counted Sfor loop. The generated loop uses a unique compiler-created size_t index.

For each omitted element, the loop body performs the same type-specific initialization as the current lowering. This includes recursive initialization of nested arrays and structures, as well as typed initialization of pointers, floating-point values, and volatile subobjects.

As a result, the generated AST no longer grows with the number of omitted array elements. The change constructs only existing assignment and Sfor AST nodes and does not modify any verified compiler pass or proof.

Scope

The change applies to automatic declaration initializers handled by process_decl. Global and static initializers are unchanged.

Local compound literals retain the existing expression-based lowering because supporting statement-level loops there requires separate handling of expression sequence points.

I can also propose some regression tests into CompCert-small-tests once the lowering approach is reviewed.

Validation

Tested from CompCert 3.18 commit 66a9fd06:

  • completed a full CompCert build, including proofs, extraction, ccomp, and the runtime library,
  • compiled the complete existing regression suite,
  • completed make test SIMU=qemu-x86_64,
  • verified bounded post-Unblock output for a 100,000-element array.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Local array initializers can cause linear AST growth and compiler memory exhaustion

2 participants