Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,7 @@ void InterpCompiler::EmitStind(InterpType interpType, CORINFO_CLASS_HANDLE clsHn

void InterpCompiler::EmitStaticFieldAddress(CORINFO_FIELD_INFO *pFieldInfo, CORINFO_RESOLVED_TOKEN *pResolvedToken)
{
bool isBoxedStatic = (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_STATIC_IN_HEAP) != 0;
switch (pFieldInfo->fieldAccessor)
{
case CORINFO_FIELD_STATIC_ADDRESS:
Expand Down Expand Up @@ -1861,6 +1862,25 @@ void InterpCompiler::EmitStaticFieldAddress(CORINFO_FIELD_INFO *pFieldInfo, CORI
assert(0);
break;
}

if (isBoxedStatic)
Copy link

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refactoring the pointer arithmetic logic within the isBoxedStatic block. Extracting intermediate values using temporary variables or a helper function could improve clarity and reduce potential errors.

Copilot uses AI. Check for mistakes.

{
// Obtain boxed instance ref
m_pStackPointer--;
AddIns(INTOP_LDIND_I);
m_pLastNewIns->data[0] = 0;
m_pLastNewIns->SetSVar(m_pStackPointer[0].var);
PushInterpType(InterpTypeO, NULL);
m_pLastNewIns->SetDVar(m_pStackPointer[-1].var);

// Skip method table word
m_pStackPointer--;
AddIns(INTOP_ADD_P_IMM);
m_pLastNewIns->data[0] = sizeof(void*);
Copy link

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using sizeof(void*) as a magic value can be unclear; consider defining a named constant to document its purpose.

Suggested change
m_pLastNewIns->data[0] = sizeof(void*);
m_pLastNewIns->data[0] = POINTER_SIZE;

Copilot uses AI. Check for mistakes.

m_pLastNewIns->SetSVar(m_pStackPointer[0].var);
PushInterpType(InterpTypeByRef, NULL);
m_pLastNewIns->SetDVar(m_pStackPointer[-1].var);
}
}

void InterpCompiler::EmitStaticFieldAccess(InterpType interpFieldType, CORINFO_FIELD_INFO *pFieldInfo, CORINFO_RESOLVED_TOKEN *pResolvedToken, bool isLoad)
Expand Down
Loading