Fix 4 bugs in TypePreinit IL interpreter - #125947
Merged
MichalStrehovsky merged 1 commit intoMar 23, 2026
Merged
Conversation
- Fix ceq opcode for float NaN: use IEEE 754 equality instead of byte-wise comparison so NaN == NaN correctly returns false - Fix TryLoadElement off-by-one bounds check: change > to >= to match TryStoreElement and prevent out-of-bounds access at index == Length - Fix int.MinValue / -1 and long.MinValue / -1 compiler crash: return Status.Fail for signed division/remainder overflow instead of letting OverflowException propagate and crash the AOT compiler - Add shl to Int64 arithmetic switch to prevent NotImplementedException crash when both operands normalize to Int64 (e.g. nint << nint) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes multiple correctness issues in the NativeAOT TypePreinit IL interpreter to avoid incorrect constant-folding and prevent AOT compiler crashes during preinitialization.
Changes:
- Fix
ceqbehavior for floating-point NaN comparisons to follow IEEE 754 equality semantics. - Fix an off-by-one bounds check in
TryLoadElementto prevent out-of-range reads atindex == Length. - Prevent AOT compiler crashes on signed division/remainder overflow (
MinValue / -1) and implement missingshlhandling for Int64-normalized operands. - Add new smoke tests covering array load bounds, float NaN comparison, and division overflow scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/Preinitialization/Preinitialization.cs | Adds new smoke tests that validate the fixed interpreter behaviors during type preinitialization. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs | Fixes float ceq, signed div/rem overflow handling, adds Int64 shl, and corrects array element load bounds checking. |
This was referenced Mar 23, 2026
Open
jkotas
approved these changes
Mar 23, 2026
sbomer
approved these changes
Mar 23, 2026
Member
Author
|
/ba-g timeout in unrelated test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Asked Opus 4.6 to review TypePreinit.cs for correctness. It found bugs. It fixed bugs. It almost wrote good tests (couldn't make a good one for TryLoadElement so that one is mine)
They're not very concerning, but bugs nevertheless.