Skip to content

Commit 8c78b43

Browse files
authored
Fix generic argument access in filter funclets (#121332)
In funclets of generic methods, access to the generic argument may be needed. It doesn't work correctly, because the filter funclet has its own locals and various IR instructions that use that argument cannot access it. This change adds copying of that argument from the parent frame to the funclet frame at the same offset so that the access to it just works.
1 parent 0769ce2 commit 8c78b43

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5756,6 +5756,23 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
57565756
{
57575757
AddIns(INTOP_LOAD_EXCEPTION);
57585758
m_pLastNewIns->SetDVar(m_pCBB->clauseVarIndex);
5759+
5760+
// To allow filter clauses in generic methods to access the generic argument,
5761+
// we copy that argument variable from the parent frame to the filter's frame.
5762+
// The target variable offset is the same as the one in the parent frame.
5763+
if ((m_pCBB->clauseType == BBClauseFilter) && (m_paramArgIndex != -1))
5764+
{
5765+
AddIns(INTOP_LOAD_FRAMEVAR);
5766+
PushInterpType(InterpTypeI, NULL);
5767+
m_pLastNewIns->SetDVar(m_pStackPointer[-1].var);
5768+
5769+
m_pStackPointer--;
5770+
int32_t opcode = GetLdindForType(m_pVars[m_paramArgIndex].interpType);
5771+
AddIns(opcode);
5772+
m_pLastNewIns->SetSVar(m_pStackPointer[0].var);
5773+
m_pLastNewIns->SetDVar(m_paramArgIndex);
5774+
m_pLastNewIns->data[0] = m_pVars[m_paramArgIndex].offset;
5775+
}
57595776
}
57605777
}
57615778

src/coreclr/interpreter/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ class InterpCompiler
756756
int32_t m_varsSize = 0;
757757
int32_t m_varsCapacity = 0;
758758
int32_t m_numILVars = 0;
759-
int32_t m_paramArgIndex = 0; // Index of the type parameter argument in the m_pVars array.
759+
int32_t m_paramArgIndex = -1; // Index of the type parameter argument in the m_pVars array.
760760
// For each catch or filter clause, we create a variable that holds the exception object.
761761
// This is the index of the first such variable.
762762
int32_t m_clauseVarsIndex = 0;

0 commit comments

Comments
 (0)