Skip to content

Assertion failed 'inVarToRegMap[varIndex] == REG_STK' during 'LSRA allocate'  #66579

Closed

Description

@jakobbotsch

Description

The following program hits a JIT assert on arm32 when optimizing.

Reproduction Steps

// Generated by Fuzzlyn v1.5 on 2022-06-12 16:26:10
// Run on Arm Linux
// Seed: 4638851666693439758
// Reduced from 219.8 KiB to 1.7 KiB in 00:07:17
// Hits JIT assert in Release:
// Assertion failed 'inVarToRegMap[varIndex] == REG_STK' in 'Program:M41()' during 'LSRA allocate' (IL size 78; hash 0x996e4c42; FullOpts)
// 
//     File: /__w/1/s/src/coreclr/jit/lsra.cpp Line: 4040
// 
public class Program
{
    public static byte[, ] s_4;
    public static ulong s_35;
    public static int s_36;
    public static int[, ] s_40;
    public static int s_42;
    public static void Main()
    {
        CollectibleALC alc = new CollectibleALC();
        System.Reflection.Assembly asm = alc.LoadFromAssemblyPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
        System.Reflection.MethodInfo mi = asm.GetType(typeof(Program).FullName).GetMethod(nameof(MainInner));
        System.Type runtimeTy = asm.GetType(typeof(Runtime).FullName);
        mi.Invoke(null, new object[]{System.Activator.CreateInstance(runtimeTy)});
    }

    public static void MainInner(IRuntime rt)
    {
        M41();
    }

    public static void M41()
    {
        for (int var0 = 0; var0 < 1; var0++)
        {
            return;
        }

        try
        {
            s_36 = s_36;
        }
        finally
        {
            ulong vr0 = default(ulong);
            if (s_35 != vr0)
            {
                try
                {
                    s_40 = s_40;
                }
                finally
                {
                    for (int var6 = 0; var6 < 2; var6++)
                    {
                    }
                }
            }

            s_4 = new byte[, ]{{0}};
            s_42 = 0;
        }
    }
}

public interface IRuntime
{
    void WriteLine<T>(string site, T value);
}

public class Runtime : IRuntime
{
    public void WriteLine<T>(string site, T value) => System.Console.WriteLine(value);
}

public class CollectibleALC : System.Runtime.Loader.AssemblyLoadContext
{
    public CollectibleALC(): base(true)
    {
    }
}

Expected behavior

No assert hit.

Actual behavior

Assert is hit.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

category:correctness
theme:register-allocator

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Mar 14, 2022
  2. ghost added
    untriaged
    on Mar 14, 2022
  3. added this to the 7.0.0 milestone on Mar 14, 2022
  4. removed
    untriaged
    on Mar 14, 2022
  5. kunalspathak commented on Apr 20, 2022

    @kunalspathak
    Contributor

    I am no longer able to repro this.

  6. jakobbotsch commented on Jun 13, 2022

    @jakobbotsch
    MemberAuthor

    Edited the OP with a new example from yesterday's Fuzzlyn run.

  7. modified the milestones: 7.0.0, 8.0.0 on Jun 13, 2022
  8. kunalspathak commented on May 5, 2023

    @kunalspathak
    Contributor

    Not able to repro this with main.

  9. 1 remaining item

  10. jakobbotsch commented on May 7, 2023

    @jakobbotsch
    MemberAuthor

    Here's a new one:

    // Generated by Fuzzlyn v1.5 on 2023-05-07 18:01:55
    // Run on Arm Linux
    // Seed: 16843426675522164433
    // Reduced from 403.5 KiB to 2.0 KiB in 00:05:45
    // Hits JIT assert in Release:
    // Assertion failed 'inVarToRegMap[varIndex] == REG_STK' in 'Program:M11()' during 'LSRA allocate' (IL size 139; hash 0x99721227; FullOpts)
    // 
    //     File: /__w/1/s/src/coreclr/jit/lsra.cpp Line: 4182
    // 
    public interface I0
    {
        byte M9();
    }
    
    public class C1
    {
        public long F9;
    }
    
    public class C2 : I0
    {
        public byte F9;
        public byte M9()
        {
            Program.M10();
            return Program.s_105.F9;
        }
    }
    
    public class Program
    {
        public static IRuntime s_rt;
        public static C2 s_5;
        public static C1 s_6;
        public static bool s_8;
        public static C2 s_105;
        public static void Main()
        {
            CollectibleALC alc = new CollectibleALC();
            System.Reflection.Assembly asm = alc.LoadFromAssemblyPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
            System.Reflection.MethodInfo mi = asm.GetType(typeof(Program).FullName).GetMethod(nameof(MainInner));
            System.Type runtimeTy = asm.GetType(typeof(Runtime).FullName);
            mi.Invoke(null, new object[]{System.Activator.CreateInstance(runtimeTy)});
        }
    
        public static void MainInner(IRuntime rt)
        {
            I0 vr0 = new C2();
            vr0.M9();
        }
    
        public static void M10()
        {
            M11();
        }
    
        public static void M11()
        {
            for (int var0 = 0; var0 < 1; var0++)
            {
                return;
            }
    
            for (int var1 = 0; var1 < 1; var1++)
            {
                try
                {
                    s_8 = false;
                }
                finally
                {
                    for (int var3 = 0; var3 < 2; var3++)
                    {
                        s_6.F9 = s_6.F9--;
                        ref byte var4 = ref s_5.F9;
                        s_rt.WriteLine("c_104", var3);
                        s_rt.WriteLine("c_105", var4);
                    }
                }
    
                s_rt.WriteLine("c_106", var1);
            }
        }
    }
    
    public interface IRuntime
    {
        void WriteLine<T>(string site, T value);
    }
    
    public class Runtime : IRuntime
    {
        public void WriteLine<T>(string site, T value) => System.Console.WriteLine(value);
    }
    
    public class CollectibleALC : System.Runtime.Loader.AssemblyLoadContext
    {
        public CollectibleALC(): base(true)
        {
        }
    }
  11. kunalspathak commented on May 9, 2023

    @kunalspathak
    Contributor

    @jakobbotsch - can you confirm the repro steps? I would typically build a Release binary from this code and use Altjit to repro it on windows machine.

  12. jakobbotsch commented on May 9, 2023

    @jakobbotsch
    MemberAuthor

    @jakobbotsch - can you confirm the repro steps? I would typically build a Release binary from this code and use Altjit to repro it on windows machine.

    That repros it for me using 32-bit arm32 altjit.

    $env:DOTNET_AltJitName="clrjit_universal_arm_x86.dll"
    $env:DOTNET_AltJit="M11"
    C:\dev\dotnet\runtime\artifacts\tests\coreclr\windows.x86.Checked\Tests\Core_Root\corerun.exe C:\dev\dotnet\playground\bin\Release\net8.0\playground.dll
    Assert failure(PID 23868 [0x00005d3c], Thread: 6000 [0x1770]): Assertion failed 'inVarToRegMap[varIndex] == REG_STK' in 'Program:M11()' during 'LSRA allocate' (IL size 139; hash 0x99721227; FullOpts)
    
        File: C:\dev\dotnet\runtime\src\coreclr\jit\lsra.cpp Line: 4182
        Image: C:\dev\dotnet\runtime\artifacts\tests\coreclr\windows.x86.Checked\Tests\Core_Root\corerun.exe
    
  13. added
    Priority:3
    on Jun 5, 2023
  14. modified the milestones: 8.0.0, 9.0.0 on Jul 30, 2023
  15. modified the milestones: 9.0.0, 10.0.0 on Jul 25, 2024
  16. kunalspathak commented on May 29, 2025

    @kunalspathak
    Contributor

    @jakobbotsch - do you still see this issue? I identified some of the problems a while back in arm LSRA resolution and sent out #109173 and #107493 and that should have fixed that.

  17. JulieLeeMSFT commented on Jul 7, 2025

    @JulieLeeMSFT
    Member

    @jakobbotsch, please close if this issue is fixed.

    #109173 and #107493 and that should have fixed that.

  18. locked and limited conversation to collaborators on Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:3arch-arm32area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions