Skip to content

Commit 32cae38

Browse files
authored
[RyuJit Wasm] fix off by one error for br_table (#123565)
The count of switch targets does not include the default.
1 parent adcc379 commit 32cae38

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/coreclr/jit/codegenwasm.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,14 @@ void CodeGen::genTableBasedSwitch(GenTree* treeNode)
570570
assert(caseCount > 0);
571571
assert(desc->HasDefaultCase());
572572

573-
GetEmitter()->emitIns_I(INS_br_table, EA_4BYTE, caseCount);
573+
// br_table list (labelidx*) labelidx
574+
// list is prefixed with length, which is caseCount - 1
575+
//
576+
GetEmitter()->emitIns_I(INS_br_table, EA_4BYTE, caseCount - 1);
574577

578+
// Emit the list case targets, then default case target
579+
// (which is always the last case in the desc).
580+
//
575581
for (unsigned caseNum = 0; caseNum < caseCount; caseNum++)
576582
{
577583
BasicBlock* const caseTarget = desc->GetCase(caseNum)->getDestinationBlock();

0 commit comments

Comments
 (0)