Skip to content

Commit 48fd2f3

Browse files
authored
Fix DoesValueTypeContainGCRefs in the interpreter (#121846)
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.
1 parent 3fc131a commit 48fd2f3

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,17 +2886,9 @@ static bool DoesValueTypeContainGCRefs(COMP_HANDLE compHnd, CORINFO_CLASS_HANDLE
28862886
// getClassGClayout assumes it's given a buffer of exactly this size
28872887
unsigned maxGcPtrs = (size + sizeof(void *) - 1) / sizeof(void *);
28882888
BYTE *gcLayout = (BYTE *)alloca(maxGcPtrs + 1);
2889-
uint32_t numSlots = compHnd->getClassGClayout(clsHnd, gcLayout);
2889+
uint32_t numGCRefs = compHnd->getClassGClayout(clsHnd, gcLayout);
28902890

2891-
for (uint32_t i = 0; i < numSlots; ++i)
2892-
{
2893-
if (gcLayout[i] != TYPE_GC_NONE)
2894-
{
2895-
return true;
2896-
}
2897-
}
2898-
2899-
return false;
2891+
return numGCRefs > 0;
29002892
}
29012893

29022894
void InterpCompiler::ConvertFloatingPointStackEntryToStackType(StackInfo* entry, StackType type)

0 commit comments

Comments
 (0)