[clr-interp] fix native int input to switch statements#122364
Merged
davidwrighton merged 2 commits intodotnet:mainfrom Dec 10, 2025
Merged
[clr-interp] fix native int input to switch statements#122364davidwrighton merged 2 commits intodotnet:mainfrom
davidwrighton merged 2 commits intodotnet:mainfrom
Conversation
Fixes Runtime_68568 test
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the CLR interpreter where native int (nint) values were not being properly converted when used as input to switch statements on 64-bit platforms. The fix adds a saturating conversion from 64-bit unsigned integers (U8) to 32-bit unsigned integers (U4), which ensures that native int values are properly clamped to the valid range expected by the switch instruction.
Key Changes
- Added new
INTOP_CONV_U4_U8_SATopcode for saturating U8→U4 conversion - Compiler now emits this conversion on 64-bit targets when a
StackTypeI(native int) is used with a switch statement - Runtime implementation clamps values exceeding
UINT32_MAXtoUINT32_MAXbefore performing the conversion
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/coreclr/interpreter/inc/intops.def |
Defines the new INTOP_CONV_U4_U8_SAT opcode with standard 3-byte instruction format |
src/coreclr/interpreter/compiler.cpp |
Adds compile-time logic to emit saturating conversion for native int inputs to switch statements on 64-bit platforms |
src/coreclr/vm/interpexec.cpp |
Implements runtime behavior for the saturating conversion, clamping values to UINT32_MAX |
Co-authored-by: Copilot <[email protected]>
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.
Fixes Runtime_68568 test