Skip to content

Commit aa81ad5

Browse files
committed
Fix incorrect promotion opcode used for CEE_LOCALLOC
Fix contract violations in getClassAlignmentRequirement Basic implementation of CPOBJ in the interpreter Implement initblk in the interpreter
1 parent 6d9cd59 commit aa81ad5

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,18 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
39383938
break;
39393939
}
39403940

3941+
case CEE_CPOBJ:
3942+
{
3943+
CHECK_STACK(2);
3944+
CORINFO_RESOLVED_TOKEN resolvedToken;
3945+
ResolveToken(getU4LittleEndian(m_ip + 1), CORINFO_TOKENKIND_Class, &resolvedToken);
3946+
InterpType interpType = GetInterpType(m_compHnd->asCorInfoType(resolvedToken.hClass));
3947+
EmitLdind(interpType, resolvedToken.hClass, 0);
3948+
EmitStind(interpType, resolvedToken.hClass, 0, false);
3949+
m_ip += 5;
3950+
break;
3951+
}
3952+
39413953
case CEE_RET:
39423954
{
39433955
CORINFO_SIG_INFO sig = methodInfo->args;
@@ -5500,7 +5512,9 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
55005512
// Length is natural unsigned int
55015513
if (m_pStackPointer[-1].type == StackTypeI4)
55025514
{
5503-
EmitConv(m_pStackPointer - 1, StackTypeI8, INTOP_MOV_8);
5515+
// The localloc instruction allocates size (type native unsigned int or U4) bytes from the local dynamic memory pool ...
5516+
// So the size is currently U4 and needs to be promoted to I8
5517+
EmitConv(m_pStackPointer - 1, StackTypeI8, INTOP_CONV_I8_U4);
55045518
m_pStackPointer[-1].type = StackTypeI8;
55055519
}
55065520
#endif
@@ -5615,6 +5629,21 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
56155629
m_ip += 5;
56165630
break;
56175631
}
5632+
case CEE_INITBLK:
5633+
{
5634+
if (volatile_)
5635+
{
5636+
AddIns(INTOP_MEMBAR);
5637+
volatile_ = false;
5638+
}
5639+
5640+
CHECK_STACK(3);
5641+
AddIns(INTOP_INITBLK);
5642+
m_pStackPointer -= 3;
5643+
m_pLastNewIns->SetSVars3(m_pStackPointer[0].var, m_pStackPointer[1].var, m_pStackPointer[2].var);
5644+
m_ip++;
5645+
break;
5646+
}
56185647
case CEE_CPBLK:
56195648
CHECK_STACK(3);
56205649
if (volatile_)

src/coreclr/interpreter/intops.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ OPDEF(INTOP_GENERICLOOKUP, "generic", 4, 1, 1, InterpOpGenericLookup)
397397
OPDEF(INTOP_CALL_FINALLY, "call.finally", 2, 0, 0, InterpOpBranch)
398398

399399
OPDEF(INTOP_ZEROBLK_IMM, "zeroblk.imm", 3, 0, 1, InterpOpInt)
400+
OPDEF(INTOP_INITBLK, "initblk", 4, 0, 3, InterpOpNoArgs)
400401
OPDEF(INTOP_CPBLK, "cpblk", 4, 0, 3, InterpOpNoArgs)
401402
OPDEF(INTOP_LOCALLOC, "localloc", 3, 1, 1, InterpOpNoArgs)
402403
OPDEF(INTOP_BREAKPOINT, "breakpoint", 1, 0, 0, InterpOpNoArgs)

src/coreclr/vm/interpexec.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,18 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
21722172
ip += 4;
21732173
break;
21742174
}
2175+
case INTOP_INITBLK:
2176+
{
2177+
void* dst = LOCAL_VAR(ip[1], void*);
2178+
uint8_t value = LOCAL_VAR(ip[2], uint8_t);
2179+
uint32_t size = LOCAL_VAR(ip[3], uint32_t);
2180+
if (size && !dst)
2181+
COMPlusThrow(kNullReferenceException);
2182+
else
2183+
memset(dst, value, size);
2184+
ip += 4;
2185+
break;
2186+
}
21752187
case INTOP_LOCALLOC:
21762188
{
21772189
size_t len = LOCAL_VAR(ip[2], size_t);

src/coreclr/vm/jitinterface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,15 +1920,15 @@ bool CEEInfo::canAllocateOnStack(CORINFO_CLASS_HANDLE clsHnd)
19201920
unsigned CEEInfo::getClassAlignmentRequirement(CORINFO_CLASS_HANDLE type, bool fDoubleAlignHint)
19211921
{
19221922
CONTRACTL {
1923-
NOTHROW;
1924-
GC_NOTRIGGER;
1923+
THROWS; // Due to GetNativeLayoutInfo() call in getClassAlignmentRequirementStatic
1924+
GC_TRIGGERS; // Due to InitializeNativeLayoutFieldMetadataThrowing() call in GetNativeLayoutInfo
19251925
MODE_PREEMPTIVE;
19261926
} CONTRACTL_END;
19271927

19281928
// Default alignment is sizeof(void*)
19291929
unsigned result = TARGET_POINTER_SIZE;
19301930

1931-
JIT_TO_EE_TRANSITION_LEAF();
1931+
JIT_TO_EE_TRANSITION();
19321932

19331933
TypeHandle clsHnd(type);
19341934

@@ -1950,7 +1950,7 @@ unsigned CEEInfo::getClassAlignmentRequirement(CORINFO_CLASS_HANDLE type, bool f
19501950
result = getClassAlignmentRequirementStatic(clsHnd);
19511951
}
19521952

1953-
EE_TO_JIT_TRANSITION_LEAF();
1953+
EE_TO_JIT_TRANSITION();
19541954

19551955
return result;
19561956
}

0 commit comments

Comments
 (0)