Skip to content

JIT: Read Nullable hasValue before paramName in Tier0 ThrowIfNull - #137644

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-137639-throwifnull-nullable
Nov 18, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-137639-throwifnull-nullable

Conversation

@EgorBo

@EgorBo EgorBo commented Nov 16, 2026

Copy link
Copy Markdown
Member

At Tier0, impThrowIfNull folds ArgumentNullException.ThrowIfNull(CORINFO_HELP_BOX_NULLABLE(cls, addr), paramName) into addr->hasValue != 0 ? NOP : ThrowIfNull(null, paramName). It spilled addr and paramName, but the hasValue read (and the implicit null check on addr) happened later, in the QMARK condition. So any exception (or write to the source) from evaluating paramName was observed before the source was read, while the original box reads the source first.

Spill the hasValue read itself before paramName, matching when the box helper reads the value.

Fixes #137639

@azure-pipelines

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

At Tier0, `impThrowIfNull` folds `ArgumentNullException.ThrowIfNull(CORINFO_HELP_BOX_NULLABLE(cls, addr), paramName)` into `addr->hasValue != 0 ? NOP : ThrowIfNull(null, paramName)`. It spilled `addr` and `paramName`, but the `hasValue` read (and the implicit null check on `addr`) happened later, in the QMARK condition. So any exception (or write to the source) from evaluating `paramName` was observed before the source was read, while the original box reads the source first.

Spill the `hasValue` read itself before `paramName`, matching when the box helper reads the value.

Fixes dotnet#137639

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3e6c4fb6-77fd-4a5a-9011-1cf5506af1bb
@EgorBo
EgorBo force-pushed the fix-137639-throwifnull-nullable branch from ae64a19 to 99d3004 Compare November 16, 2026 17:45
@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 Nov 16, 2026
@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.

@EgorBo

EgorBo commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

PTAL @AndyAyersMS @dotnet/jit-contrib

@EgorBo
EgorBo merged commit 9d756a9 into dotnet:main Nov 18, 2026
122 of 127 checks passed
@EgorBo
EgorBo deleted the fix-137639-throwifnull-nullable branch November 18, 2026 13:42
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
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) Tier0: ArgumentNullException.ThrowIfNull(Nullable<T>, paramName) evaluates paramName before reading the source

2 participants