From 99c20c4b35773b45182b91d9fee764ddab6c708e Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 19 Sep 2023 14:55:40 +0300 Subject: [PATCH] fix: handle missing `Instruction::Switch` in jump destination changes Add `Instruction::Switch` in destination branch argument appending with panic since we don't support block arguments in `Switch` instruction. --- frontend-wasm/src/function_builder_ext.rs | 15 +++++++++++++++ hir/src/dataflow.rs | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/frontend-wasm/src/function_builder_ext.rs b/frontend-wasm/src/function_builder_ext.rs index 2ad61c0b..f3df9a0f 100644 --- a/frontend-wasm/src/function_builder_ext.rs +++ b/frontend-wasm/src/function_builder_ext.rs @@ -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); diff --git a/hir/src/dataflow.rs b/hir/src/dataflow.rs index d5b8e605..2ece7c30 100644 --- a/hir/src/dataflow.rs +++ b/hir/src/dataflow.rs @@ -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), } }