Skip to content

JIT: (bug) Embedded masking suppresses a contained faulting load, losing NullReferenceException (AVX-512) #134197

Closed

Description

@EgorBo

On AVX-512 hardware a faulting GT_IND can be contained into an ALU intrinsic that subsequently acquires an embedded mask, so EVEX memory-fault suppression skips the access and a required NullReferenceException is never thrown.

Minimal Repro

using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;

public class Box
{
    public Vector512<int> V;
}

public static class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    public static Vector512<int> Test(Vector512<int> c1, Vector512<int> c2, Vector512<int> a, Box b, Vector512<int> f)
    {
        Vector512<int> mask = Vector512.Equals(c1, c2);
        return Vector512.ConditionalSelect(mask, a + b.V, f);
    }

    public static void Main()
    {
        try
        {
            Console.WriteLine("Result: " + Test(Vector512.Create(1), Vector512.Create(2),
                                                Vector512.Create(3), null!, Vector512.Create(4)));
        }
        catch (NullReferenceException)
        {
            Console.WriteLine("NullReferenceException");
        }
    }
}

Expected

NullReferenceException

Actual

Result: <4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4>

Notes

Requires AVX-512 hardware, x64. Correct with DOTNET_EnableEmbeddedMasking=0. Also repros on released .NET 10.0.12.
Codegen contains no explicit null check at all: vpcmpeqd k1, zmm0, zmmword ptr [r8] / vpaddd zmm1 {k1}, zmm0, zmmword ptr [rax+0x08] — the unconditional b.V load is contained into the add, which then gets embedded masking, so with k1 == 0 the access is suppressed.
GenTree::isEmbeddedMaskingCompatible (gentree.cpp) only rejects nodes whose own intrinsic ID is a load/store; it does not reject an ALU node that already has a contained faulting GT_IND operand.

Activity

  1. added this to the 12.0.0 milestone on Sep 18, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 18, 2026
  3. dotnet-policy-service commented on Sep 18, 2026

    @dotnet-policy-service
    Contributor

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

  4. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 9.0.318
    • 10.0.401
    • 11.0.100-rc.2.26467.112
  5. added a commit that references this issue on Sep 22, 2026
    e29c15e
  6. locked and limited conversation to collaborators on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions