From 12fd8611b380d576956cc37c216e2c5265dca8f1 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 24 Mar 2026 10:44:57 +0100 Subject: [PATCH] Fix interpreter crash on empty switch instruction The CEE_SWITCH handler called allocate(n) with n=0 for switch instructions with zero targets, triggering an assert in the arena allocator. Bail out early when n=0 since an empty switch is a no-op that just consumes the stack value. Fixes crash in JIT/Regression/CLR-x86-JIT/V1-M11-Beta1/b44946/b44946.il which contains a switch() with zero targets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/interpreter/compiler.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index 0d318fe6b9cb42..2e90db063fc08d 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -9478,6 +9478,11 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) m_ip += 4; const uint8_t *nextIp = m_ip + n * 4; m_pStackPointer--; + + // Empty switch (n=0) is a no-op that just consumes the stack value. + if (n == 0) + break; + InterpBasicBlock **targetBBTable = getAllocator(IMK_SwitchTable).allocate(n); uint32_t *targetOffsets = getAllocator(IMK_SwitchTable).allocate(n);