Skip to content

Commit b142ec3

Browse files
authored
Fix LDTOKEN in interpreter (#116234)
The CEE_LDTOKEN compilation incorrectly assumes that the resolved token contains either hClass or hField or hMethod and it checks for the hClass first. But the hClass is present always, so resolving token for method or field doesn't work correctly. This change fixes it by reordering the checks in an order matching what JIT does.
1 parent 9d1d2a9 commit b142ec3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,20 +4226,20 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
42264226

42274227
// see jit/importer.cpp CEE_LDTOKEN
42284228
CorInfoHelpFunc helper;
4229-
if (resolvedToken.hClass)
4229+
if (resolvedToken.hField)
42304230
{
4231-
helper = CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE;
4232-
m_pLastNewIns->data[0] = GetDataItemIndex(resolvedToken.hClass);
4231+
helper = CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD;
4232+
m_pLastNewIns->data[0] = GetDataItemIndex(resolvedToken.hField);
42334233
}
42344234
else if (resolvedToken.hMethod)
42354235
{
42364236
helper = CORINFO_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD;
42374237
m_pLastNewIns->data[0] = GetDataItemIndex(resolvedToken.hMethod);
42384238
}
4239-
else if (resolvedToken.hField)
4239+
else if (resolvedToken.hClass)
42404240
{
4241-
helper = CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD;
4242-
m_pLastNewIns->data[0] = GetDataItemIndex(resolvedToken.hField);
4241+
helper = CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE;
4242+
m_pLastNewIns->data[0] = GetDataItemIndex(resolvedToken.hClass);
42434243
}
42444244
else
42454245
{

0 commit comments

Comments
 (0)