Skip to content

ushort argument mysteriously mutated #66624

Closed
@bradmarder

Description

@bradmarder

Description

Discovered with Fuzzlyn.

M10(ushort arg0) is called with the value 53474 and is never reassigned inside the method. When the value of the arg is printed in debug mode, it is correctly 53474, while release mode prints 226.

Reproduction Steps

// Generated by Fuzzlyn v1.5 on 2022-03-14 21:20:55
// Run on X64 Windows
// Seed: 16520696696442011600
// Reduced from 677.9 KiB to 2.4 KiB in 00:04:01
// Debug: Outputs 53474
// Release: Outputs 226
public class C0
{
    public byte F0;
    public sbyte F3;
    public byte F4;
    public byte F5;
    public uint F6;
    public C0(byte f4, byte f5, uint f6)
    {
        F4 = f4;
        F5 = f5;
        F6 = f6;
    }
}

public class C1
{
    public C0 F4;
    public C1(C0 f4)
    {
        F4 = f4;
    }
}

public struct S0
{
    public sbyte F0;
    public C0 F2;
    public bool F4;
    public ulong F5;
    public uint F6;
    public bool F7;
    public S0(sbyte f0, C0 f1, C0 f2, bool f4, ulong f5, uint f6, bool f7) : this()
    {
        F0 = f0;
        F2 = f2;
        F4 = f4;
        F5 = f5;
        F6 = f6;
        F7 = f7;
    }
}

public class Program
{
    public static IRuntime s_rt;
    public static C0 s_1 = new C0(0, 0, 0);
    public static C1[][] s_3 = new C1[][] { new C1[] { new C1(new C0(0, 0, 0)) } };
    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;
        M10(53474);
    }

    public static void M10(ushort arg0)
    {
        var vr1 = new S0[] { new S0(0, new C0(0, 0, 0), new C0(0, 0, 0), false, 0, 0, false) };
        S0 var1 = new S0(s_1.F3, new C0(0, 0, s_3[0][0].F4.F6), new C0(0, 0, 0), true, 0, 0, false);
        try
        {
            byte vr5 = var1.F2.F0;
        }
        finally
        {
            var1 = new S0(0, new C0(0, 0, 0), new C0(0, 1, 0), true, 0, 0, true);
        }

        if ((byte)arg0 < 1)
        {
            C0[] var4 = new C0[] { new C0(0, 0, 0) };
        }

        s_rt.WriteLine("c_4102", arg0);
    }
}

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

The printed value of arg0 should be 53474.

Actual behavior

The printed value of arg0 is 226.

Regression?

Appears to be a regression as of .net 6 (this works correctly in .net 5).

Known Workarounds

No response

Configuration

win10 x64 and tested with 7.0.100-preview.1.22110.4

Other information

No response

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions