Skip to content

JIT: Fix MD array store evaluation order - #133740

Merged
AndyAyersMS merged 1 commit into
mainfrom
fix-mdarray-store-evaluation-order
Sep 14, 2026
Merged

AndyAyersMS merged 1 commit into
mainfrom
fix-mdarray-store-evaluation-order

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Multidimensional array stores performed null and bounds checks before
side-effecting RHS values. Spill the RHS first to preserve evaluation
order.

Fixes #133717.

Note

This pull request description was created by GitHub Copilot.

Multidimensional array stores performed null and bounds checks before
side-effecting RHS values. Spill the RHS first to preserve evaluation
order.

Fixes #133717.

Co-authored-by: Copilot <[email protected]>
Copilot AI lite review requested due to automatic review settings September 11, 2026 20:29
@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 11, 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.

🔵 Needs a closer look

The spill guard does not handle GTF_ORDER_SIDEEFF, allowing some RHS values to remain embedded in the store.

Pull request overview

Fixes JIT evaluation order for multidimensional array stores by spilling side-effecting RHS values before array checks.

Changes:

  • Updates MD-array store expansion.
  • Adds 2D/3D evaluation-order regression tests.
File summaries
File Summary
src/tests/JIT/opt/MDArray/MDArrayIntrinsicExpansion.cs Adds regression coverage for MD-array store evaluation order.
src/coreclr/jit/importercalls.cpp Spills side-effecting RHS values before MD-array checks.
Review details

Suppressed comments (1)

src/coreclr/jit/importercalls.cpp:13564

  • This guard only recognizes GTF_SIDE_EFFECT, but GT_CATCH_ARG carries only GTF_ORDER_SIDEEFF (src/coreclr/jit/importer.cpp:1994-1999). A valid low-level handler can pass the catch argument directly to Set; because the value is popped without calling impSpillSpecialSideEff, it can remain embedded in the store instead of being the first evaluated statement, violating the invariant checked in fgdiagnostic.cpp:3738-3746. Include GTF_ORDER_SIDEEFF in the guard (or call impSpillSpecialSideEff unconditionally) before popping the value.
        if ((impStackTop().val->gtFlags & GTF_SIDE_EFFECT) != 0)
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@jakobbotsch PTAL
fyi @dotnet/jit-contrib

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g known mono test failures

@AndyAyersMS
AndyAyersMS merged commit 3a046d6 into main Sep 14, 2026
144 of 146 checks passed
@AndyAyersMS
AndyAyersMS deleted the fix-mdarray-store-evaluation-order branch September 14, 2026 14:41
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 15, 2026
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 18, 2026
Multidimensional array stores performed null and bounds checks before
side-effecting RHS values. Spill the RHS first to preserve evaluation
order.

Fixes dotnet#133717.

> [!NOTE]
> This pull request description was created by GitHub Copilot.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 15, 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: (bug) multi-dimensional array Set checks bounds/null before evaluating the stored value

3 participants