Skip to content

Conversation

@davidwrighton
Copy link
Member

Fixes Runtime_68568 test

Copilot AI review requested due to automatic review settings December 9, 2025 22:49
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 9, 2025
@davidwrighton davidwrighton removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 9, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Copy link
Contributor

Copilot AI left a 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_SAT opcode 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_MAX to UINT32_MAX before 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants