From 0f0bcf2a6531825c9aa7aea5dbb3ce7f732ef718 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Mon, 16 Mar 2026 14:38:37 +0100 Subject: [PATCH] [release/10.0] Fix missing call to write barrier in static constructors of ref structs The JIT was incorrectly handling initialization of static fields of ref structs. It was not adding call to JIT_ByRefWriteBarrier when setting these fields even though these statics live in GC heap. This issue was introduced in .NET 10 in #111733 This change fixes it and adds a regression test that causes fatal error when run with DOTNET_HeapVerify=1. --- src/coreclr/jit/importer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 27550eac30073a..9cb0569f7e0601 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -9814,9 +9814,9 @@ void Compiler::impImportBlockCode(BasicBlock* block) // Field's type is a byref-like struct -> address is not on the heap. indirFlags |= GTF_IND_TGT_NOT_HEAP; } - else + else if ((fieldInfo.fieldFlags & CORINFO_FLG_FIELD_STATIC) == 0) { - // Field's owner is a byref-like struct -> address is not on the heap. + // Field's owner is a byref-like struct and the field is not static -> address is not on the heap. CORINFO_CLASS_HANDLE fldOwner = info.compCompHnd->getFieldClass(resolvedToken.hField); if ((fldOwner != NO_CLASS_HANDLE) && eeIsByrefLike(fldOwner)) {