Skip to content

Fix assertions generated by optCreateJumpTableImpliedAssertions#123240

Merged
EgorBo merged 1 commit intodotnet:mainfrom
EgorBo:fix-optCreateJumpTableImpliedAssertions
Jan 16, 2026
Merged

Fix assertions generated by optCreateJumpTableImpliedAssertions#123240
EgorBo merged 1 commit intodotnet:mainfrom
EgorBo:fix-optCreateJumpTableImpliedAssertions

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 16, 2026

Fixes #122254

bug repro:

switch (X)
{
    case 2:
        // ...
        break;
    case 3:
        // ...
        break;
    case 4:
        // ...
        break;
    default:
        // "X >= 5" assertion was created here (which is incorrect, X can be 0 or 1 as well)  
        break;
}

Copilot AI review requested due to automatic review settings January 16, 2026 00:40
@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 Jan 16, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.

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 JIT compiler's assertion propagation optimization where incorrect assertions were being generated for switch statement default cases when the switch expression involved an offset.

Changes:

  • Fixed assertion generation logic in optCreateJumpTableImpliedAssertions to only create range assertions for default cases when there's no offset
  • Added a regression test to verify the fix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/assertionprop.cpp Added condition to check offset == 0 before creating assertions for default case, with explanatory comment
src/tests/JIT/Regression/JitBlue/Runtime_122254/Runtime_122254.cs Added regression test with switch statement to verify correct behavior when block value is 0

@EgorBo EgorBo merged commit 05a7c03 into dotnet:main Jan 16, 2026
138 of 139 checks passed
rosebyte pushed a commit that referenced this pull request Jan 19, 2026
)

Fixes #122254

bug repro:
```c
switch (X)
{
    case 2:
        // ...
        break;
    case 3:
        // ...
        break;
    case 4:
        // ...
        break;
    default:
        // "X >= 5" assertion was created here (which is incorrect, X can be 0 or 1 as well)  
        break;
}
```
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.

Optimizations for a specific function is causing runtime misbehavior

2 participants