JIT crash (SIGSEGV) in gtCanSkipCovariantStoreCheck when a delegate inlined by pgo stores a reference and the array is an array of primitives
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 18/100
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
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:
- All reference types share the code of
Call<__Canon>and its profile. In the program below, that profile names the lambda ofStoreReference, whereTisobject[]. - The JIT inlines
Call<int[]>intoStoreNumber, it takes the lambda ofStoreReferenceas 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 - The body has a
stelem.ref, and the array that the JIT sees is anint[].getChildTypeleavesarrayElementHandlenull for an array of primitives, and the assert onCORINFO_TYPE_CLASSis not in a release build. isExactType(arrayElementHandle)gets the null handle. The check forNO_CLASS_HANDLEis 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=0DOTNET_TieredCompilation=0[MethodImpl(MethodImplOptions.NoInlining)]onCall
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
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Collections untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dotnet/runtime#138090 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Text.Json untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/runtime#138089 · 1 comment ·
Maintainers usually reply within 1 day
-
area-Setup untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/runtime#137376 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Memory untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dotnet/runtime#137334 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Add `net10.0`Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day