From cd6d7ae1c2d6dcdfc17e1fe13ed10b4af3a87e5f Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Thu, 20 Nov 2025 17:06:34 +0100 Subject: [PATCH] Fix DoesValueTypeContainGCRefs in the interpreter There was a mistake in the implementation that prevented it from working correctly in some cases. The return value of the getClassSize() is not a number of slots filled in the array, but a number of GC references in the array. So if there were e.g. three slots and there was one GC reference in the second slot, the DoesValueTypeContainGCRefs returned false. --- src/coreclr/interpreter/compiler.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index ce3dd350da394b..93992918d80066 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -2870,17 +2870,9 @@ static bool DoesValueTypeContainGCRefs(COMP_HANDLE compHnd, CORINFO_CLASS_HANDLE // getClassGClayout assumes it's given a buffer of exactly this size unsigned maxGcPtrs = (size + sizeof(void *) - 1) / sizeof(void *); BYTE *gcLayout = (BYTE *)alloca(maxGcPtrs + 1); - uint32_t numSlots = compHnd->getClassGClayout(clsHnd, gcLayout); + uint32_t numGCRefs = compHnd->getClassGClayout(clsHnd, gcLayout); - for (uint32_t i = 0; i < numSlots; ++i) - { - if (gcLayout[i] != TYPE_GC_NONE) - { - return true; - } - } - - return false; + return numGCRefs > 0; } void InterpCompiler::ConvertFloatingPointStackEntryToStackType(StackInfo* entry, StackType type)