Repository navigation
JIT: preserve null check for unused GT_BLK arg when inlining - #130417
Conversation
… and regression test Co-authored-by: JulieLeeMSFT <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates the CoreCLR JIT inliner’s handling of unused struct-by-value arguments so that required faulting semantics (null dereference) are preserved when the argument is represented as a GT_BLK and the inlinee never consumes it.
Changes:
- In
fgInsertInlineeArgument, when an unusedGT_BLKargument may fault, emit aGT_NULLCHECKinstead of reducing the tree to a dead address expression. - Add a new JIT regression test
Runtime_72808intended to validate thatProblem(null)still throwsNullReferenceExceptionin the inlining scenario.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/coreclr/jit/fginline.cpp |
Preserves null-check semantics for unused GT_BLK inlinee arguments by emitting GT_NULLCHECK when the indirection may fault. |
src/tests/JIT/Regression/JitBlue/Runtime_72808/Runtime_72808.cs |
Adds a regression test covering the inline-time elimination of a faulting struct load from a null pointer. |
src/tests/JIT/Regression/JitBlue/Runtime_72808/Runtime_72808.csproj |
Adds the project file to build the new regression test (optimized, unsafe enabled). |
|
Rerunning failed tests. |
|
/ba-g test failures are on mono. |
|
@EgorBo, mono pipelines constantly fail even after a few retries. Can you check SPMI diffs? |
|
@copilot please remove |
…} block Co-authored-by: EgorBo <[email protected]>
Done. Removed |
When inlining a callee that accepts a struct argument by value but never uses it, the JIT was silently dropping the
GT_BLKdereference, swallowing aNullReferenceExceptionthat should have been thrown:Root cause: In
fgInsertInlineeArgument, when aGT_BLKargument is unused (argIsUsed == false) but has side effects, the code stripped it to just the address operand and wrapped it in agtUnusedValNode. The bare address has no side effects, so the optimizer discarded it entirely.Fix (
fginline.cpp): CheckIndirMayFaulton theGT_BLK. If the indirection can fault, emit aGT_NULLCHECKinstead of a dead value expression — preserving the null-dereference semantics without placing aGT_BLKunderGT_COMMA(which codegen can't handle).Test: Added
src/tests/JIT/Regression/JitBlue/Runtime_72808— callsProblem(null)underAggressiveOptimizationand expectsNullReferenceException.