-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[clr-interp] fix native int input to switch statements #122364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes Runtime_68568 test
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
janvorli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]>
Fixes Runtime_68568 test