JIT crash (SIGSEGV) in gtCanSkipCovariantStoreCheck when a delegate inlined by pgo stores a reference and the array is an array of primitives

Open
#138,142 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, csharp
Domain
compilers

Research direction

The crash is in Compiler::gtCanSkipCovariantStoreCheck in src/coreclr/jit/gentree.cpp, where isExactType is called on arrayElementHandle before the NO_CLASS_HANDLE check. Start by reading that function and getChildType, then reproduce with the C# program in the issue in Release. Done means the JIT no longer dereferences a null handle when inlining a delegate into an array-of-primitives store, with the workarounds' behaviour preserved.

Written by the indexing model from the issue text.

Description

area-CodeGen-coreclr untriaged
Description

The JIT crashes with a null dereference in Compiler::gtCanSkipCovariantStoreCheck and the process ends with SIGSEGV (no unsafe code needed).

It happens when Tier 1 compiles a method that calls a generic method with a delegate: Call<T>(int, T, Action<int, T>) and knows the exact T.

This is my reading of the source:

  1. All reference types share the code of Call<__Canon> and its profile. In the program below, that profile names the lambda of StoreReference, where T is object[].
  2. The JIT inlines Call<int[]> into StoreNumber, it takes the lambda of StoreReference as its guess for the delegate call and then inlines that too. The guess can never be right there but its body is imported before any guard runs
  3. The body has a stelem.ref, and the array that the JIT sees is an int[]. getChildType leaves arrayElementHandle null for an array of primitives, and the assert on CORINFO_TYPE_CLASS is not in a release build.
  4. isExactType(arrayElementHandle) gets the null handle. The check for NO_CLASS_HANDLE is in the next statement, one step too late:

https://github.com/dotnet/runtime/blob/v10.0.9/src/coreclr/jit/gentree.cpp#L34185-L34204

main had the same code on 2026-11-23

Reproduction Steps
  using System;
  using System.Threading;

  static class Program
  {
      static void Call<T>(int index, T state, Action<int, T> action) => action(index, state);

      static void StoreReference()
      {
          object[] array = new object[1];
          Call(0, array, static (i, a) => a[i] = a);
      }

      static void StoreNumber()
      {
          int[] array = new int[1];
          Call(0, array, static (i, a) => a[i] = i);
      }

      static void Main()
      {
          Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);

          // the profile of Call<__Canon> names the delegate of StoreReference
          for (int round = 0; round < 20; round++)
          {
              for (int i = 0; i < 2000; i++)
                  StoreReference();

              Thread.Sleep(20);
          }

          // the JIT inlines Call<int[]> here, with that profile
          for (int round = 0; round < 100; round++)
          {
              for (int i = 0; i < 2000; i++)
                  StoreNumber();

              Thread.Sleep(5);
          }

          Console.WriteLine("ok");
      }
  }

Build it in Release and run it

Expected behavior

The program prints ok

Actual behavior

The process ends with SIGSEGV (exit code 139), it crashed in every run that I made with the default settings

Regression?

Yes

Runtime Result of 3 runs
8.0.8 ok
9.0.0 ok
10.0.9 SIGSEGV
11.0.0 SIGSEGV
Known Workarounds

Each of these gave ok in 3 runs on 10.0.9:

  • DOTNET_TieredPGO=0
  • DOTNET_TieredCompilation=0
  • [MethodImpl(MethodImplOptions.NoInlining)] on Call

DOTNET_TC_OnStackReplacement=0 does not help.

Configuration
  • .NET 10.0.9 and .NET 11.0.0
  • macOS 26.5.2 (25F84), arm64 (Apple M3)

No other OS was tested

Other information

The stack on 10.0.9 on the tiered compilation background thread:

TypeHandle::IsArray() const
CEEInfo::isExactType(CORINFO_CLASS_STRUCT_*)
Compiler::gtCanSkipCovariantStoreCheck(GenTree*, GenTree*)
Compiler::impImportBlockCode(BasicBlock*)
Compiler::impImportBlock(BasicBlock*)
Compiler::impImport()
Compiler::fgImport()
Compiler::compCompile(...)
Compiler::compCompileHelper(...)
jitNativeCode(...)
Compiler::fgInvokeInlineeCompiler(...)
Compiler::fgMorphCallInlineHelper(...)
Compiler::fgInline()
Compiler::compCompile(...)
CILJit::compileMethod(...)
UnsafeJitFunction(...)
MethodDesc::JitCompileCode(PrepareCodeConfig*)
MethodDesc::PrepareILBasedCode(PrepareCodeConfig*)
TieredCompilationManager::CompileCodeVersion(NativeCodeVersion)
TieredCompilationManager::BackgroundWorkerStart()
Dominant language
C#
Stars
18.5k
Forks
5.8k
Avg merge
2d 18h
Merged PRs (30d)
588

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.