Skip to content

JIT: Invalid codegen with byref return #125432

@jakobbotsch

Description

@jakobbotsch
// Generated by Fuzzlyn v3.3 on 2026-03-09 17:21:47
// Run on X64 Windows
// Seed: 1163906270042266374-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 209.6 KiB to 3.6 KiB in 00:11:12
// Debug: Runs successfully
// Release: Throws 'System.NullReferenceException'
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public class C0
{
    public Vector256<int> F0;
}

public struct S0
{
    public short F0;
    public sbyte F2;
}

public struct S1
{
    public S0 F3;
    public byte F7;
    public S0 F8;
}

public class C2
{
    public S1 F0;
    public S1 F1;
    public ushort F3;
    public S1 F5;
}

public struct S3
{
    public C0 F1;
    public short F2;
    public S3(C0 f1) : this()
    {
        F1 = f1;
    }

    public S3 M4(byte arg0, byte arg1, Vector128<uint> arg2, ref Vector<long> arg3, S4 arg4)
    {
        var vr4 = this.F2;
        var vr3 = Vector256.Create<short>(vr4);
        var vr7 = (short)0;
        var vr6 = Vector128.CreateScalar(vr7);
        var vr11 = (short)-23116;
        var vr9 = Vector128.CreateScalar(vr11);
        var vr5 = Sse2.Xor(vr6, vr9);
        var vr1 = Avx2.ShiftRightArithmetic(vr3, vr5);
        Vector256.CreateScalar(-29675);
        Program.s_rt.WriteLine("c_19", arg0);
        Program.s_rt.WriteLine("c_20", arg1);
        Program.s_rt.WriteLine("c_21", arg2);
        Program.s_rt.WriteLine("c_22", arg3);
        return this;
    }
}

public struct S4
{
    public uint F1;
    public long F4;
    public short F5;
    public S4(uint f1, short f2, long f4, short f5, sbyte f7) : this()
    {
        F1 = f1;
        F4 = f4;
        F5 = f5;
    }
}

public class Program
{
    public static IRuntime s_rt;
    public static uint s_2;
    public static S1 s_6;
    public static Vector<long>[] s_9 = new Vector<long>[]
    {
        Vector128.CreateScalar(0L).AsVector()
    };
    public static S3 s_10;
    public static C2[] s_18 = new C2[]
    {
        new C2()
    };
    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)
    {
        s_rt = rt;
        var vr16 = s_18[0];
        var vr17 = M16();
        M2(vr16, vr17);
        s_rt.WriteLine("c_799", s_10.F1.F0);
    }

    public static ref S3 M16()
    {
        try
        {
            return ref s_10;
        }
        catch (System.Exception)
        {
        }

        return ref s_10;
    }

    public static void M2(C2 argThis, S3 arg0)
    {
        arg0 = new S3(new C0());
        try
        {
            M16() = arg0;
        }
        finally
        {
            argThis.F1 = s_6;
            byte vr25 = default(byte);
            var vr10 = (byte)Sse42.X64.Crc32(0, 0);
            var vr13 = Vector128.Create<uint>(s_2);
            var vr15 = new S4(argThis.F3, s_6.F3.F0++, (argThis.F3 >> argThis.F5.F7), argThis.F0.F8.F0, argThis.F0.F8.F2++);
            arg0.M4(vr25, vr10, vr13, ref s_9[0], vr15);
            argThis.F5.F8 = argThis.F0.F8;
            argThis.F0.F7 = argThis.F5.F7;
        }
    }
}

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)
    {
    }
}

Bisected to 703be08

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions