Skip to content

Commit 54689bc

Browse files
[clr-interp] Fix more IL_Conformance test issues (#120993)
- Compare operations between I4 and I need to work - Storing a floating point value in an array may need conversions - Storing an I4 into an I with stelem is a supported operation --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a9deee8 commit 54689bc

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,14 @@ void InterpCompiler::EmitCompareOp(int32_t opBase)
27152715
EmitConv(m_pStackPointer - 1, StackTypeR8, INTOP_CONV_R8_R4);
27162716
if (m_pStackPointer[-1].type == StackTypeR8 && m_pStackPointer[-2].type == StackTypeR4)
27172717
EmitConv(m_pStackPointer - 2, StackTypeR8, INTOP_CONV_R8_R4);
2718+
2719+
#ifdef TARGET_64BIT
2720+
// Support comparisons between I and I4 by inserting an implicit conversion to I8
2721+
if (m_pStackPointer[-1].type == StackTypeI4 && m_pStackPointer[-2].type == StackTypeI8)
2722+
EmitConv(m_pStackPointer - 1, StackTypeI8, INTOP_CONV_I8_I4);
2723+
if (m_pStackPointer[-1].type == StackTypeI8 && m_pStackPointer[-2].type == StackTypeI4)
2724+
EmitConv(m_pStackPointer - 2, StackTypeI8, INTOP_CONV_I8_I4);
2725+
#endif
27182726
AddIns(opBase + m_pStackPointer[-1].type - StackTypeI4);
27192727
}
27202728
m_pStackPointer -= 2;
@@ -4581,7 +4589,20 @@ void InterpCompiler::EmitLdelem(int32_t opcode, InterpType interpType)
45814589

45824590
void InterpCompiler::EmitStelem(InterpType interpType)
45834591
{
4592+
#ifdef TARGET_64BIT
4593+
// nint and int32 can be used interchangeably. Add implicit conversions.
4594+
if (m_pStackPointer[-1].type == StackTypeI4 && g_stackTypeFromInterpType[interpType] == StackTypeI8)
4595+
EmitConv(m_pStackPointer - 1, StackTypeI8, INTOP_CONV_I8_I4);
4596+
#endif
4597+
4598+
// Handle floating point conversions
4599+
if (m_pStackPointer[-1].type == StackTypeR4 && g_stackTypeFromInterpType[interpType] == StackTypeR8)
4600+
EmitConv(m_pStackPointer - 1, StackTypeR8, INTOP_CONV_R8_R4);
4601+
else if (m_pStackPointer[-1].type == StackTypeR8 && g_stackTypeFromInterpType[interpType] == StackTypeR4)
4602+
EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_R8);
4603+
45844604
m_pStackPointer -= 3;
4605+
45854606
int32_t opcode = GetStelemForType(interpType);
45864607
AddIns(opcode);
45874608
m_pLastNewIns->SetSVars3(m_pStackPointer[0].var, m_pStackPointer[1].var, m_pStackPointer[2].var);
@@ -5831,6 +5852,36 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
58315852
else
58325853
{
58335854
CheckStackExact(1);
5855+
5856+
#ifdef TARGET_64BIT
5857+
// nint and int32 can be used interchangeably. Add implicit conversions.
5858+
if (m_pStackPointer[-1].type == StackTypeI4 && g_stackTypeFromInterpType[retType] == StackTypeI8)
5859+
EmitConv(m_pStackPointer - 1, StackTypeI8, INTOP_CONV_I8_I4);
5860+
#endif
5861+
if (m_pStackPointer[-1].type == StackTypeR4 && g_stackTypeFromInterpType[retType] == StackTypeR8)
5862+
EmitConv(m_pStackPointer - 1, StackTypeR8, INTOP_CONV_R8_R4);
5863+
else if (m_pStackPointer[-1].type == StackTypeR8 && g_stackTypeFromInterpType[retType] == StackTypeR4)
5864+
EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_R8);
5865+
5866+
if (m_pStackPointer[-1].type != g_stackTypeFromInterpType[retType])
5867+
{
5868+
StackType retStackType = g_stackTypeFromInterpType[retType];
5869+
StackType stackType = m_pStackPointer[-1].type;
5870+
5871+
if (stackType == StackTypeI && (retStackType == StackTypeO || retStackType == StackTypeByRef))
5872+
{
5873+
// Allow implicit conversion from nint to ref or byref
5874+
}
5875+
else if (retStackType == StackTypeI && (stackType == StackTypeO || stackType == StackTypeByRef))
5876+
{
5877+
// Allow implicit conversion from ref or byref to nint
5878+
}
5879+
else
5880+
{
5881+
BADCODE("return type mismatch");
5882+
}
5883+
}
5884+
58345885
AddIns(INTOP_RET);
58355886
m_pStackPointer--;
58365887
m_pLastNewIns->SetSVar(m_pStackPointer[0].var);

0 commit comments

Comments
 (0)