Skip to content

JIT: expand all stack array allocations in a statement - #133531

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-stack-array-expand
Sep 9, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-stack-array-expand

Conversation

@EgorBo

@EgorBo EgorBo commented Sep 9, 2026

Copy link
Copy Markdown
Member

Fixes #133523

fgExpandStackArrayAllocations stopped after expanding the first allocation in a statement. gtSplitTree only moves the part of the tree evaluated before the split point into new statements, so any further NEWARR helper calls stayed in the statement and were never expanded - leaving a helper call with a bogus StackArrayLocal arg (asserts in lowering, AVs in release).

No SPMI asm diffs.

fgExpandStackArrayAllocations stopped after the first expansion in a statement,
but splitting only moves the preceding part of the tree out, so any remaining
NEWARR helper calls stayed behind with a StackArrayLocal arg.

Fixes dotnet#133523

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3b9596b9-f3b3-47d1-b1ca-1a8781e56de7
Copilot AI lite review requested due to automatic review settings September 9, 2026 20:15
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI 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.

🟢 Approval recommended

The fix is localized, maintains statement side-effect flag correctness via gtUpdateStmtSideEffects, and is backed by a targeted regression test covering the reported scenario.

Pull request overview

This PR fixes a CoreCLR JIT correctness bug where stack-array allocation expansion would only expand the first eligible NEWARR helper call within a statement, potentially leaving later stack-array allocations in the same statement unexpanded and malformed.

Changes:

  • Update Compiler::fgExpandStackArrayAllocations to rescan a statement after each successful expansion until no more stack-array allocations remain.
  • Add a JIT regression test covering multiple stack-allocated arrays in one statement (including a 3-array variant).
  • Register the new regression test source file in Regression_ro_2.csproj.
File summaries
File Description
src/coreclr/jit/helperexpansion.cpp Rescans a statement until all stack-array allocation helper calls in that statement are expanded.
src/tests/JIT/Regression/Regression_ro_2.csproj Includes the new Runtime_133523 regression test in the build.
src/tests/JIT/Regression/JitBlue/Runtime_133523/Runtime_133523.cs Adds an xUnit regression test reproducing multiple stack-array allocations within one statement.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

@EgorBo
EgorBo merged commit ef97eb5 into dotnet:main Sep 9, 2026
143 of 144 checks passed
@EgorBo
EgorBo deleted the fix-stack-array-expand branch September 9, 2026 23:24
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 10, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: two stack-allocated arrays in one statement crash the process

3 participants