Skip to content

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

Closed

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

Activity

  1. ghost added
    untriaged
    on Aug 9, 2022
  2. added
    area-CodeGen-coreclr
    and removed
    untriaged
    on Aug 9, 2022
  3. added this to the 8.0.0 milestone on Aug 9, 2022
  4. added a commit that references this issue on May 23, 2023
    672a925
  5. ghost added
    in-pr
    on May 23, 2023
  6. ghost removed
    in-pr
    on May 23, 2023
  7. added
    blocked
    on May 23, 2023
  8. jakobbotsch commented on May 23, 2023

    @jakobbotsch
    MemberAuthor

    This needs to wait for dotnet/roslyn#63221 for a runtime side fix. As of writing this the C# compiler has been fixed, but not the VB.NET compiler.

  9. added
    Priority:3
    on Jun 20, 2023
  10. jakobbotsch commented on Jul 24, 2023

    @jakobbotsch
    MemberAuthor

    I'm going to move this to 9.0 since it's blocked waiting for a Roslyn VB.NET fix.

  11. modified the milestones: 8.0.0, 9.0.0 on Jul 24, 2023
  12. AlekseyTs commented on Nov 2, 2023

    @AlekseyTs
    Contributor

    @jakobbotsch FYI, the fix for dotnet/roslyn#63221 for VB got merged into Roslyn.

  13. added
    in-pr
    on Apr 8, 2024
  14. removed
    blocked
    on Apr 8, 2024
  15. added a commit that references this issue on Apr 16, 2024
    42f2b33
  16. added a commit that references this issue on Apr 30, 2024
    20c9a25
  17. locked and limited conversation to collaborators on May 16, 2024
  18. added a commit that references this issue on May 30, 2024
    2352370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:3area-CodeGen-coreclrbugin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions