Skip to content

Commit 74bb2b3

Browse files
committed
Report and explicitly test byrefs
1 parent 5356a49 commit 74bb2b3

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,27 +879,36 @@ void InterpCompiler::BuildGCInfo(InterpMethod *pInterpMethod)
879879
for (int i = 0; i < m_varsSize; i++)
880880
{
881881
InterpVar *pVar = &m_pVars[i];
882-
if (pVar->interpType != InterpTypeO)
883-
continue;
882+
GcSlotFlags flags;
883+
switch (pVar->interpType) {
884+
case InterpTypeO:
885+
flags = (GcSlotFlags)(pVar->global ? GC_SLOT_UNTRACKED : 0);
886+
break;
887+
case InterpTypeByRef:
888+
flags = (GcSlotFlags)(pVar->global ? GC_SLOT_UNTRACKED | GC_SLOT_INTERIOR : GC_SLOT_INTERIOR);
889+
break;
890+
default:
891+
continue;
892+
}
884893

885-
// Globals are untracked and shouldn't need liveness ranges recorded in the info
886-
GcSlotFlags flags = (GcSlotFlags)(pVar->global ? GC_SLOT_UNTRACKED : 0);
887894
uint32_t slotIndex = pVar->offset / INTERP_STACK_SLOT_SIZE;
888895
if (slotsByOffset[slotIndex] == ((GcSlotId)-1))
889896
{
890897
// Important to pass GC_xxx_REL, the default is broken due to GET_CALLER_SP being unimplemented
891898
slotsByOffset[slotIndex] = gcInfoEncoder->GetStackSlotId(pVar->offset, flags, GC_FRAMEREG_REL);
892899
INTERP_DUMP(
893-
"Allocated gcinfo slot %u for %svar #%d at offset %d\n",
900+
"Allocated gcinfo slot %u for %s%svar #%d at offset %d\n",
894901
slotsByOffset[slotIndex], pVar->global ? "global " : "",
902+
pVar->interpType == InterpTypeByRef ? "byref " : "",
895903
i, pVar->offset
896904
);
897905
}
898906
else
899907
{
900908
INTERP_DUMP(
901-
"Reused gcinfo slot %u for %svar #%d at offset %d\n",
909+
"Reused gcinfo slot %u for %s%svar #%d at offset %d\n",
902910
slotsByOffset[slotIndex], pVar->global ? "global " : "",
911+
pVar->interpType == InterpTypeByRef ? "byref " : "",
903912
i, pVar->offset
904913
);
905914
assert(!pVar->global);
@@ -913,7 +922,7 @@ void InterpCompiler::BuildGCInfo(InterpMethod *pInterpMethod)
913922
{
914923
InterpVar *pVar = &m_pVars[i];
915924
// Even if we have a gc slot for this offset, this var might not be an object reference
916-
if (pVar->interpType != InterpTypeO)
925+
if ((pVar->interpType != InterpTypeO) && (pVar->interpType != InterpTypeByRef))
917926
continue;
918927
// We don't need to report liveness ranges for untracked vars, the gc info decoder will report them
919928
// unconditionally.

src/tests/JIT/interpreter/Interpreter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public static bool TestFields()
160160
if (sum != 33)
161161
return false;
162162

163+
ref int str_a = ref str.str.a;
164+
163165
System.GC.Collect();
164166

165167
staticObj = obj;
@@ -171,12 +173,15 @@ public static bool TestFields()
171173
if (sum != 33)
172174
return false;
173175

174-
WriteInt(ref str.str.a, 11);
176+
WriteInt(ref str_a, 11);
175177
WriteInt(ref staticObj.str.a, 22);
176-
sum = ReadInt(ref str.str.a) + ReadInt(ref staticObj.str.a);
178+
sum = ReadInt(ref str_a) + ReadInt(ref staticObj.str.a);
177179
if (sum != 33)
178180
return false;
179181

182+
if (str_a != str.str.a)
183+
return false;
184+
180185
return true;
181186
}
182187

0 commit comments

Comments
 (0)