Skip to content

JIT incorrectly reorders constrained call 'this' indirections with other arguments #73615

@jakobbotsch

Description

@jakobbotsch

Small example:

using InlineIL;
using System;
using System.Runtime.CompilerServices;

public class Program
{
    public static void Main()
    {
        Foo(new C("A"));
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Foo(C arg)
    {
        IL.Emit.Ldarga(nameof(arg));
        IL.Emit.Ldarga(nameof(arg));
        IL.Emit.Call(new MethodRef(typeof(Program), nameof(Bar)));
        IL.Emit.Constrained<C>();
        IL.Emit.Callvirt(new MethodRef(typeof(C), nameof(arg.Baz)));
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static int Bar(ref C o)
    {
        o = new C("B");
        return 0;
    }
}

public record class C(string Name)
{
    public void Baz(int arg)
    {
        Console.WriteLine(Name);
    }
}

Expected: B
Actual: A

Seen in #73606 (comment)

category:correctness
theme:importer
skill-level:intermediate
cost:small
impact:small

Metadata

Metadata

Assignees

Labels

Priority:3Work that is nice to havearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbugin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions