Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException with bulk memory copy helper on win-x86 #102138

Closed
jakobbotsch opened this issue May 12, 2024 · 6 comments · Fixed by #102171
Closed

NullReferenceException with bulk memory copy helper on win-x86 #102138

jakobbotsch opened this issue May 12, 2024 · 6 comments · Fixed by #102171
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented May 12, 2024

// Generated by Fuzzlyn v1.6 on 2024-05-12 19:09:35
// Run on X86 Windows
// Seed: 9851999836185511275
// Reduced from 93.1 KiB to 0.8 KiB in 00:03:30
// Debug: Runs successfully
// Release: Throws 'System.NullReferenceException'
using System.Runtime.CompilerServices;

public class C0
{
}

public struct S0
{
    public C0 F0;
    public C0 F1;
}

public struct S1
{
    public C0 F1;
    public S0 F2;
    public C0 F3;
}

public struct S2
{
    public S1 F4;
}

public struct S3
{
    public S2 F0;
}

public struct S5
{
    public int F0;
}

public class Program
{
    public static S3 s_10;
    public static byte[] s_11;
    public static void Main()
    {
        var vr3 = new short[][][]{new short[][]{new short[]{0}}};
        var vr8 = new S5();
        s_10 = M8(vr8, ref s_11, vr3);
    }

    public static ref S3 M8(S5 argThis, ref byte[] arg0, short[][][] arg1)
    {
        arg1[0] = new short[][]{new short[]{0}};
        return ref s_10;
    }
}

cc @EgorBo, it looks like the transformation in lowering is not correct for the x86 invariants around the ordering of arguments when they need to be pushed on the stack. The size that is supposed to be passed to the bulk write barrier ends up pushed to M8 as its last parameter here, so inside M8 we have arg1 = 16.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 12, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Member Author

Might also be related to #101890

@EgorBo EgorBo self-assigned this May 12, 2024
@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label May 12, 2024
@EgorBo EgorBo added this to the 9.0.0 milestone May 12, 2024
@EgorBo
Copy link
Member

EgorBo commented May 12, 2024

Thanks, this repro is definitely simpler to work with than #101890

@jakobbotsch
Copy link
Member Author

I think the problem is this check inside MoveCFGCallArgs:

// Non-value nodes in early args are setup nodes for late args.
if (node->IsValue())
{
assert(node->OperIsPutArg() || node->OperIsFieldList());
MoveCFGCallArg(call, node);
}

On x86 we have PUTARG_STK nodes in the early args that definitely need to be handled here, and unlike other PUTARG nodes this one isn't a value. The check should likely just be deleted, we no longer have setup nodes in calls after rationalization.

@jakobbotsch
Copy link
Member Author

That probably means this issue is unrelated to #101890.

@EgorBo
Copy link
Member

EgorBo commented May 12, 2024

can confirm that if (node->IsValue()) being removed fixes the issue 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants