Skip to content

JIT: Fix null-check ordering in EH regions - #133827

Merged
AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix-133714-null-check-ordering
Sep 17, 2026
Merged

AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix-133714-null-check-ordering

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Ensure this pointer null checks happen before inlinee side effects observable
by catch handlers and exception filters. Prevent early propagation from folding
these checks across such side effects, and add regression coverage for both
cases.

Fixes #133714

Note

This pull request description was generated by GitHub Copilot.

Ensure this pointer null checks happen before inlinee side effects observable
by catch handlers and exception filters. Prevent early propagation from folding
these checks across such side effects, and add regression coverage for both
cases.

Fixes dotnet#133714

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 13, 2026 16:58
@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 13, 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.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@EgorBo PTAL
fyi @dotnet/jit-contrib

No diffs expected

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.

🟡 Changes recommended

Nested inlining can still miss the enclosing protected-region state, leaving the null-check ordering bug unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

JIT: Fix null-check ordering in EH regions

This PR preserves receiver null-check ordering across inlinee side effects observable by exception handlers and filters.

Changes:

  • Treat assignments as visible side effects in protected regions.
  • Prevent unsafe null-check folding.
  • Add catch and filter regression coverage.
File summaries
File Summary
src/tests/JIT/Regression_ro_2/Runtime_133714.cs Adds regression coverage.
src/coreclr/jit/importer.cpp Preserves null checks across inlinee assignments.
src/coreclr/jit/earlyprop.cpp Restricts null-check folding in EH regions.
src/coreclr/jit/compiler.h Updates the helper parameter name.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/coreclr/jit/importer.cpp Outdated
@AndyAyersMS

Copy link
Copy Markdown
Member Author

diffs

There were a couple of minor diffs, looks like just one method.

Comment thread src/coreclr/jit/earlyprop.cpp Outdated
Comment thread src/coreclr/jit/importer.cpp Outdated
Use HasPotentialEHSuccs to identify try and filter regions when preserving null-check ordering.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3fb0bcff-10ee-4de2-a4dd-442ad89b2b11
Copilot AI review requested due to automatic review settings September 15, 2026 15:37

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

The new test is failing on mono and coreclr Wasm. Going to exclude mono and see if #133932 fixes things for Wasm.

The exception-filter scenario targets CoreCLR JIT behavior and fails on Mono. Keep the catch scenario cross-runtime while restricting only the filter regression to non-Mono runtimes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3fb0bcff-10ee-4de2-a4dd-442ad89b2b11
@AndyAyersMS

Copy link
Copy Markdown
Member Author

The new test is failing on mono and coreclr Wasm. Going to exclude mono and see if #133932 fixes things for Wasm.

Yes, that fixes the Wasm failure. So will wait on that PR.

Copilot AI review requested due to automatic review settings September 17, 2026 02:10

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

A moderate unresolved concern remains about broad assignment visibility in EH regions.

Review details

Suppressed comments (1)

src/coreclr/jit/importer.cpp:14846

  • This broadens the side-effect test from GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS to every GTF_ASG whenever the call site has EH successors. That makes assignments to inlinee-private temporaries EH-visible too, so an inlined method that initializes an unobservable local before its first this dereference will retain a separate null check inside every protected region, even though no handler can observe that local. Please restrict this to stores that can actually reach an EH successor (rather than treating all assignments as visible) to avoid a broad null-check-elimination regression.
        return GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS(flags) || (localStoresAreVisible && ((flags & GTF_ASG) != 0));
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@jakobbotsch will need re-approval, the new test causes mono failures and a (since fixed) Wasm failure.

@AndyAyersMS
AndyAyersMS merged commit 661f13d into dotnet:main Sep 17, 2026
142 of 143 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 18, 2026
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 18, 2026
Ensure this pointer null checks happen before inlinee side effects
observable
by catch handlers and exception filters. Prevent early propagation from
folding
these checks across such side effects, and add regression coverage for
both
cases.

Fixes dotnet#133714

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3fb0bcff-10ee-4de2-a4dd-442ad89b2b11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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) inlined callee's write to a caller local runs before the receiver null check throws

4 participants