Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/coreclr/jit/codegenwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,14 @@ void CodeGen::genTableBasedSwitch(GenTree* treeNode)
assert(caseCount > 0);
assert(desc->HasDefaultCase());

GetEmitter()->emitIns_I(INS_br_table, EA_4BYTE, caseCount);
// br_table list (labelidx*) labelidx
// list is prefixed with length, which is caseCount - 1
//
GetEmitter()->emitIns_I(INS_br_table, EA_4BYTE, caseCount - 1);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you potentially add a comment here explaining that this loop will handle emitting all the targets, including the default, even though in the above count we excluded it because of Wasm's convention? We could also consider pulling emitting the default out of the loop just to be extra clear here, though I know we also have the assert above to ensure we do have a default case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Take another look.

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