Skip to content

InvalidProgramException in Debug build only (SIMD/AVX-512 intrinsics, CPU-dependent) #126584

Closed

Description

@pawlos

Description

A Fuzzlyn-generated program throws System.InvalidProgramException: Common Language Runtime detected an invalid program when compiled and run in Debug configuration. The same program runs without errors in Release configuration.
ILVerify reports the IL as valid (All Classes and Methods Verified), suggesting the JIT incorrectly rejects legal IL in unoptimized (MinOpts/Debug) mode.

Reproduction Steps

The program was found by Fuzzlyn with seed:

4401835540114508456-vectort,vector128,vector256,vector512,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86avx512vbmi,x86avx512vbmivl,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86gfni,x86gfniv256,x86gfniv512,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86pclmulqdqv256,x86pclmulqdqv512,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base

The code is a massive 2k lines (Program-full.cs) line program that uses intrinsic. Fuzzlyn reducer was taking too much time to reduce so I tried to do a partial cleanup by hand (Program-reduced.cs). Reduced to ~200 lines that still throws InvalidProgramException in Debug.

So both (full repro and the reduced one) when run in debug mode

dotnet run -c Debug

produces the same unhandled exception

Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at Program.M0()
   at Program.Main() in Program.cs:line XXX

There's slightly different output in release

dotnet run -c Release

The full repro produces no exception, runs to completion (no output expected - the program has no Console.WriteLine). The reduced on throws IndexOutOfRangeException exception (I was probably cleaned too much by focusing on having InvalidProgramException in Debug; didn't check the Release mode).

Expected behavior

The program should behave identically in Debug and Release configurations. ILVerify confirms the IL is valid, so the JIT should not reject it.

Actual behavior

Debug: throws InvalidProgramException during JIT compilation of method M0().
Release: runs without error. (full repro)/ IndexOutOfRangeException (reduced repro)

Regression?

Unknown. Not tested on versions prior to .NET 10.

Known Workarounds

No known workarounds

Configuration

.NET SDK: 10.0.201
Runtime: Microsoft.NETCore.App 10.0.5
OS: Windows 11 x64 (Build 26200)
Architecture: x64
CPU: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80 GHz

The bug is CPU-dependent. It reproduces only on CPUs with extended AVX-512 extensions (e.g. VBMI, GFNI, VPCLMULQDQ), not on CPUs with basic AVX-512 only (F, BW, DQ, CD, VL).

CPU where bug reproduces (extended AVX-512):
avx512f avx512dq avx512cd avx512bw avx512vl avx512ifma avx512vbmi avx512_vbmi2 avx512_vnni avx512_bitalg avx512_vpopcntdq avx512_vp2intersect gfni vaes vpclmulqdq sha_ni

CPU where bug does NOT reproduce (basic AVX-512 only):
avx512f avx512dq avx512cd avx512bw avx512vl

Extensions present only on the affected CPU:
avx512ifma, avx512vbmi, avx512_vbmi2, avx512_vnni, avx512_bitalg, avx512_vpopcntdq, avx512_vp2intersect, gfni, vaes, vpclmulqdq, sha_ni

Several of these match extensions enabled in the Fuzzlyn seed (x86avx512vbmi, x86avx512vbmivl, x86gfni, x86gfniv256, x86gfniv512, x86pclmulqdq, x86pclmulqdqv256, x86pclmulqdqv512), suggesting the JIT codegen path for one of these extensions triggers the bug.

Other information

I've also run the fully generated code sample on a docker with dotnet/nightly/sdk:11.0-preview with the same effect (Debug - InvalidProgramExchaption).

Attached:

  • Full generated program (~2k lines, reproduces exactly: Debug throws InvalidProgramException, Release runs clean)
  • Partially reduced program (~200 lines, Debug still throws InvalidProgramException, but Release behavior differs from original due to reduction)

examples.zip

Activity

  1. added
    untriaged
    on Apr 6, 2026
  2. added
    area-CodeGen-coreclr
    on Apr 6, 2026
  3. dotnet-policy-service commented on Apr 6, 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. tannergooding commented on Apr 6, 2026

    @tannergooding
    Member

    I'd just note that calling it 200 lines is a bit of a misnomer, IMO. There are a few lines that are themselves several hundred nested expressions (and with wordwrap turn into a hundred lines themselves).

    Going to take a look at this and see if I can simplify it more or find out what's faulting

  5. tannergooding commented on Apr 6, 2026

    @tannergooding
    Member

    Looks like an emit failure in M0. Specifically the following stacktrace where we hit an impl limitation:

    IMPL_LIMITATION("JIT doesn't support offsets larger than 255 into valuetypes for local vars > 32767\n");

     	clrjit.dll!emitLclVarAddr::initLclVarAddr(int varNum, unsigned int offset) Line 695	C++
     	clrjit.dll!emitter::emitIns_S_R(instruction ins, emitAttr attr, _regNumber_enum ireg, int varx, int offs, insOpts instOptions) Line 10761	C++
     	clrjit.dll!CodeGen::genCodeForInitBlkUnroll::__l2::<lambda_1>::operator()(instruction ins, unsigned int width, _regNumber_enum target) Line 3163	C++
    >	clrjit.dll!CodeGen::genCodeForInitBlkUnroll(GenTreeBlk * node) Line 3209	C++
     	clrjit.dll!CodeGen::genCodeForStoreBlk(GenTreeBlk * storeBlkNode) Line 3060	C++
     	clrjit.dll!CodeGen::genCodeForTreeNode(GenTree * treeNode) Line 2136	C++
     	clrjit.dll!CodeGen::genCodeForBBlist() Line 507	C++
     	clrjit.dll!CodeGen::genGenerateMachineCode() Line 2176	C++
     	clrjit.dll!CodeGenPhase::DoPhase() Line 1667	C++
    
  6. pawlos commented on Apr 7, 2026

    @pawlos
    Author

    I'd just note that calling it 200 lines is a bit of a misnomer, IMO. There are a few lines that are themselves several hundred nested expressions (and with wordwrap turn into a hundred lines themselves).

    Ok. The lines are indeed quite long. But I was hoping the 200 of those would be more manageable than 2k.

  7. added this to the Future milestone on Apr 7, 2026
  8. removed
    untriaged
    on Apr 7, 2026
  9. EgorBo commented on Apr 7, 2026

    @EgorBo
    Member

    Marking as Future - the repro is not realistic (>32k locals) + it doesn't lead to an undefined behavior/memory safety issue, just a well-defined InvalidProgramException. The fix seems to be straightforward, but we might have more places like that.

  10. added a commit that references this issue on Jul 21, 2026
    842d3a1
  11. locked and limited conversation to collaborators on Aug 22, 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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions