From 699e26e0fc295341f7618adb2441eaba5f5c8677 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 19 Oct 2023 12:53:52 +0300 Subject: [PATCH] chore: add a debug assert to not allow declaring a block predecessor twice --- frontend-wasm/src/ssa.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend-wasm/src/ssa.rs b/frontend-wasm/src/ssa.rs index c83dc5c3..ee769f28 100644 --- a/frontend-wasm/src/ssa.rs +++ b/frontend-wasm/src/ssa.rs @@ -324,7 +324,18 @@ impl SSABuilder { /// Callers are expected to avoid adding the same predecessor more than once in the case /// of a jump table. pub fn declare_block_predecessor(&mut self, block: Block, inst: Inst) { - debug_assert!(!self.is_sealed(block)); + debug_assert!( + !self.is_sealed(block), + "you cannot add a predecessor to a sealed block" + ); + debug_assert!( + self.ssa_blocks[block] + .predecessors + .as_slice(&self.inst_pool) + .iter() + .all(|&branch| branch != inst), + "you have declared the same predecessor twice!" + ); self.ssa_blocks[block] .predecessors .push(inst, &mut self.inst_pool);