Skip to content

Commit a927415

Browse files
authored
[clr-interp] Fix CEE_ISINST to push object reference instead of InterpTypeI (#121207)
## Description According to ECMA, CEE_ISINST must push an object reference onto stack, but it currently pushes InterpTypeI, which propagates an invalid IR stack type. In the example below, by IL_0022 the stind.ref takes an i8 instead of object reference, triggering OBJECTREF validation failure. ``` Interpreter compile method Microsoft.Maui.Controls.Platform.GesturePlatformManager:TryGetTapGestureRecognizer(Microsoft.Maui.Controls.IGestureRecognizer,byref) Create IL Vars: alloc arg var 0 to offset 0 alloc arg var 1 to offset 8 alloc arg var 2 to offset 16 Create clause Vars: BB1 (IL_0000): Chaining BB0 -> BB1 IL_0000 ldarg.2 , sp 0, IL_0001 ldarg.1 , sp 1, MP IL_0002 isinst , sp 2, O IL_0007 dup , sp 2, I8 IL_0008 brtrue.s , sp 3, I8 BB3 (IL_000a): Chaining BB1 -> BB3 IL_000a pop , sp 2, I8 IL_000b ldarg.1 , sp 1, MP IL_000c isinst , sp 2, O IL_0011 dup , sp 2, I8 IL_0012 brtrue.s , sp 3, I8 BB5 (IL_0014): Chaining BB3 -> BB5 IL_0014 pop , sp 2, I8 IL_0015 ldnull , sp 1, MP IL_0016 br.s , sp 2, O BB4 (IL_0018): Chaining BB5 -> BB4 IL_0018 call , sp 2, I8 BB6 (IL_001d): Chaining BB4 -> BB6 IL_001d isinst , sp 2, O BB2 (IL_0022): Chaining BB6 -> BB2 IL_0022 stind.ref , sp 2, I8 IL_0023 ldarg.2 , sp 0, IL_0024 ldind.ref , sp 1, MP IL_0025 ldnull , sp 1, O IL_0026 cgt.un , sp 2, O IL_0028 ret ```
1 parent e3d86c1 commit a927415

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ void InterpCompiler::LinkBBs(InterpBasicBlock *from, InterpBasicBlock *to)
461461
if (newCapacity > prevCapacity)
462462
{
463463
InterpBasicBlock **newa = (InterpBasicBlock**)AllocMemPool(newCapacity * sizeof(InterpBasicBlock*));
464-
if (from->outCount != 0)
464+
if (from->outCount != 0)
465465
{
466466
memcpy(newa, from->ppOutBBs, from->outCount * sizeof(InterpBasicBlock*));
467467
}
@@ -1878,8 +1878,8 @@ int32_t InterpCompiler::GetInterpTypeStackSize(CORINFO_CLASS_HANDLE clsHnd, Inte
18781878
if (align < INTERP_STACK_SLOT_SIZE)
18791879
align = INTERP_STACK_SLOT_SIZE;
18801880

1881-
// We do not align beyond the stack alignment
1882-
// (This is relevant for structs with very high alignment requirements,
1881+
// We do not align beyond the stack alignment
1882+
// (This is relevant for structs with very high alignment requirements,
18831883
// where we align within struct layout, but the structs are not actually
18841884
// aligned on the stack)
18851885
if (align > INTERP_STACK_ALIGNMENT)
@@ -4886,7 +4886,7 @@ class InterpILOpcodePeeps
48864886
OpcodePeep peepTypeValueType = { peepTypeValueTypeOpcodes, &InterpCompiler::IsTypeValueTypePeep, &InterpCompiler::ApplyTypeValueTypePeep, "TypeValueType" };
48874887

48884888
public:
4889-
OpcodePeep* Peeps[10] = {
4889+
OpcodePeep* Peeps[10] = {
48904890
&peepTypeEqualityCheck,
48914891
&peepStoreLoad,
48924892
&peepStoreLoad1,
@@ -4901,7 +4901,7 @@ class InterpILOpcodePeeps
49014901
bool FindAndApplyPeep(InterpCompiler* compiler)
49024902
{
49034903
const uint8_t* ip = compiler->m_ip;
4904-
4904+
49054905
for (int i = 0; Peeps[i] != NULL; i++)
49064906
{
49074907
OpcodePeep *peep = Peeps[i];
@@ -5027,7 +5027,7 @@ bool InterpCompiler::IsTypeEqualityCheckPeep(const uint8_t* ip, OpcodePeepElemen
50275027
*ppComputedInfo = (void*)(size_t)((ni == NI_System_Type_op_Equality) ? 0 : 1);
50285028
return true;
50295029
}
5030-
else
5030+
else
50315031
{
50325032
assert(compareResult == TypeCompareState::Must);
50335033
// The types are definitely equal, so we can optimize this to a constant result
@@ -5612,7 +5612,7 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
56125612
#endif
56135613

56145614
// Check for IL opcode peephole optimizations
5615-
5615+
56165616
if (ILOpcodePeeps.FindAndApplyPeep(this))
56175617
continue;
56185618

@@ -8254,7 +8254,7 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
82548254
m_compHnd->embedGenericHandle(&resolvedToken, false, m_methodInfo->ftn, &embedInfo);
82558255
m_pStackPointer--;
82568256
DeclarePointerIsClass((CORINFO_CLASS_HANDLE)embedInfo.compileTimeHandle);
8257-
EmitPushHelperCall_2(castingHelper, embedInfo, m_pStackPointer[0].var, g_stackTypeFromInterpType[*m_ip == CEE_CASTCLASS ? InterpTypeO : InterpTypeI], NULL);
8257+
EmitPushHelperCall_2(castingHelper, embedInfo, m_pStackPointer[0].var, g_stackTypeFromInterpType[InterpTypeO], NULL);
82588258
m_ip += 5;
82598259
break;
82608260
}

0 commit comments

Comments
 (0)