From 22c108b5e7c87bf7318641e170df0bfc3dd96870 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Mon, 27 Oct 2025 14:12:17 +0100 Subject: [PATCH] Report bad code when localloc is in a funclet The interpreter didn't check that localloc is not valid in funclets. Couple of coreclr tests were failing due to that. To make this work properly, I've removed marking blocks with BBClauseTry as it was not used for anything and preventing the check for code being in funclet working properly. --- src/coreclr/interpreter/compiler.cpp | 15 +++++---------- src/coreclr/interpreter/compiler.h | 1 - 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index 96fb5630c9cbd2..8c6ba6b0e5094e 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -2258,16 +2258,6 @@ void InterpCompiler::InitializeClauseBuildingBlocks(CORINFO_METHOD_INFO* methodI BADCODE("Invalid handler region in EH clause"); } - // Find and mark all basic blocks that are part of the try region. - for (uint32_t j = clause.TryOffset; j < (clause.TryOffset + clause.TryLength); j++) - { - InterpBasicBlock* pBB = m_ppOffsetToBB[j]; - if (pBB != NULL && pBB->clauseType == BBClauseNone) - { - pBB->clauseType = BBClauseTry; - } - } - InterpBasicBlock* pHandlerBB = GetBB(clause.HandlerOffset); // Find and mark all basic blocks that are part of the handler region. @@ -7474,6 +7464,11 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) } case CEE_LOCALLOC: CHECK_STACK(1); + if (m_pCBB->clauseType != BBClauseNone) + { + // Localloc inside a funclet is not allowed + BADCODE("CEE_LOCALLOC inside funclet"); + } #if TARGET_64BIT // Length is natural unsigned int if (m_pStackPointer[-1].type == StackTypeI4) diff --git a/src/coreclr/interpreter/compiler.h b/src/coreclr/interpreter/compiler.h index e0b3addb69bc86..d25181ae6ff027 100644 --- a/src/coreclr/interpreter/compiler.h +++ b/src/coreclr/interpreter/compiler.h @@ -293,7 +293,6 @@ enum InterpBBState enum InterpBBClauseType { BBClauseNone, - BBClauseTry, BBClauseCatch, BBClauseFinally, BBClauseFilter,