- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
[clr-interp] Fix switch statement stack slot handling #120756
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
          
     Merged
      
      
            davidwrighton
  merged 4 commits into
  dotnet:main
from
davidwrighton:switch_incoming_stack_slots
  
      
      
   
  Oct 17, 2025 
      
    
      
        
          +140
        
        
          −6
        
        
          
        
      
    
  
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            4 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1f85f6f
              
                [clr-interp] Fix issue where switch instructions did not properly han…
              
              
                davidwrighton 6bd41f3
              
                oops wrong define value
              
              
                davidwrighton 39a2bcf
              
                Add test case covering multiple cases in the switch statement with pr…
              
              
                davidwrighton 439087e
              
                Merge branch 'switch_incoming_stack_slots' of https://github.com/davi…
              
              
                davidwrighton File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              
        
          
          
            100 changes: 100 additions & 0 deletions
          
          100 
        
  src/tests/JIT/Regression/CLR-x86-JIT/V1-M11-Beta1/b44861/b44861_2.il
  
  
      
      
   
        
      
      
    
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
| .assembly extern mscorlib { } | ||
| .assembly extern System.Console | ||
| { | ||
| .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) | ||
| .ver 4:0:0:0 | ||
| } | ||
| .assembly 'b44861_2'// as "b" | ||
| { | ||
|  | ||
|  | ||
| // bool) = ( 01 00 00 01 00 00 ) | ||
|  | ||
|  | ||
| } | ||
| .assembly extern xunit.core {} | ||
| // MVID: {0573B9C2-3980-4A83-9B01-889CCC1D6FBC} | ||
| .namespace Test | ||
| { | ||
| .class public auto ansi App | ||
| extends [mscorlib]System.Object | ||
| { | ||
| .method public hidebysig static int32 | ||
| Main() il managed | ||
| { | ||
| .custom instance void [xunit.core]Xunit.FactAttribute::.ctor() = ( | ||
| 01 00 00 00 | ||
| ) | ||
| .entrypoint | ||
| // Code size 31 (0x1f) | ||
| .maxstack 6 | ||
| //init counter with -1 | ||
| ldc.i4.m1 | ||
| first_again: | ||
| ldc.i4.1 | ||
| add | ||
| //print out counter | ||
| ldstr "first_again value is " | ||
| call void [System.Console]System.Console::Write(class [mscorlib]System.String) | ||
| dup | ||
| call void [System.Console]System.Console::WriteLine(int32) | ||
| dup | ||
| brtrue do_switch | ||
| pop | ||
| ldc.i4.m1 | ||
| again: | ||
| //increment counter | ||
| ldc.i4.1 | ||
| add | ||
| //print out counter | ||
| ldstr "value is " | ||
| call void [System.Console]System.Console::Write(class [mscorlib]System.String) | ||
| dup | ||
| call void [System.Console]System.Console::WriteLine(int32) | ||
| do_switch: | ||
| //make a switch | ||
| dup | ||
| switch (first_again, first_again, first_again, again, again, again, stop) | ||
| //switch worked incorrectly | ||
| //throw an exception | ||
| newobj instance void [mscorlib]System.Exception::.ctor() | ||
| throw | ||
| stop: | ||
| //check counter | ||
| //we should reach here when counter=6 | ||
| ldc.i4 6 | ||
| ceq | ||
| brfalse wrong | ||
| ldstr "passed" | ||
| call void [System.Console]System.Console::Write(class [mscorlib]System.String) | ||
| br done | ||
| wrong: | ||
| ldstr "failed" | ||
| call void [System.Console]System.Console::Write(class [mscorlib]System.String) | ||
| done: | ||
| ldc.i4 100 | ||
| ret | ||
| } // end of method 'App::Main' | ||
|  | ||
| .method public hidebysig specialname rtspecialname | ||
| instance void .ctor() il managed | ||
| { | ||
| // Code size 7 (0x7) | ||
| .maxstack 8 | ||
| IL_0000: ldarg.0 | ||
| IL_0001: call instance void [mscorlib]System.Object::.ctor() | ||
| IL_0006: ret | ||
| } // end of method 'App::.ctor' | ||
|  | ||
| } // end of class 'App' | ||
|  | ||
| } // end of namespace 'Test' | ||
|  | ||
| //*********** DISASSEMBLY COMPLETE *********************** | 
        
          
          
            12 changes: 12 additions & 0 deletions
          
          12 
        
  src/tests/JIT/Regression/CLR-x86-JIT/V1-M11-Beta1/b44861/b44861_2.ilproj
  
  
      
      
   
        
      
      
    
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.IL"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <DebugType>PdbOnly</DebugType> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).il" /> | ||
| </ItemGroup> | ||
| </Project> | 
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.