Skip to content

Commit

Permalink
fix: handle missing Instruction::Switch in jump destination changes
Browse files Browse the repository at this point in the history
Add `Instruction::Switch` in destination branch argument appending with
panic since we don't support block arguments in `Switch` instruction.
  • Loading branch information
greenhat committed Sep 19, 2023
1 parent 917c440 commit 99c20c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions frontend-wasm/src/function_builder_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ impl<'a> FunctionBuilderExt<'a> {
*else_dest = new_block;
}
}
Instruction::Switch(Switch {
op: _,
arg: _,
ref mut arms,
ref mut default,
}) => {
for (_, ref mut dest_block) in arms {
if dest_block == &old_block {
*dest_block = new_block;
}
}
if default == &old_block {
*default = new_block;
}
}
_ => panic!("{} must be a branch instruction", inst),
}
self.func_ctx.ssa.declare_block_predecessor(new_block, inst);
Expand Down
8 changes: 8 additions & 0 deletions hir/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,14 @@ impl DataFlowGraph {
else_args.push(value, &mut self.value_lists);
}
}
Instruction::Switch(Switch {
op: _,
arg: _,
arms: _,
default: _,
}) => {
panic!("cannot append argument {value} to Switch destination block {dest}, since it has no block arguments support");
}
_ => panic!("{} must be a branch instruction", branch_inst),
}
}
Expand Down

0 comments on commit 99c20c4

Please sign in to comment.