Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,19 @@ void InterpCompiler::CheckStackHelper(int n)
}
}

void InterpCompiler::CheckStackExact(int n)
{
int32_t currentSize = (int32_t)(m_pStackPointer - m_pStackBase);
if (currentSize < n)
{
BADCODE("Stack underflow");
}
else if (currentSize > n)
{
BADCODE("Stack contains extra data");
}
}

void InterpCompiler::PushTypeExplicit(StackType stackType, CORINFO_CLASS_HANDLE clsHnd, int size)
{
EnsureStack(1);
Expand Down Expand Up @@ -3908,11 +3921,12 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)

if (retType == InterpTypeVoid)
{
CheckStackExact(0);
AddIns(INTOP_RET_VOID);
}
else if (retType == InterpTypeVT)
{
CHECK_STACK(1);
CheckStackExact(1);
AddIns(INTOP_RET_VT);
m_pStackPointer--;
int32_t retVar = m_pStackPointer[0].var;
Expand All @@ -3921,7 +3935,7 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
}
else
{
CHECK_STACK(1);
CheckStackExact(1);
AddIns(INTOP_RET);
m_pStackPointer--;
m_pLastNewIns->SetSVar(m_pStackPointer[0].var);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/interpreter/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ class InterpCompiler
int32_t m_stackCapacity;

void CheckStackHelper(int n);
void CheckStackExact(int n);
void EnsureStack(int additional);
void PushTypeExplicit(StackType stackType, CORINFO_CLASS_HANDLE clsHnd, int size);
void PushStackType(StackType stackType, CORINFO_CLASS_HANDLE clsHnd);
Expand Down
Loading