From c15a4b3ec73ce24cb387cefd25c912ae61f3314f Mon Sep 17 00:00:00 2001 From: Rerumu Date: Sun, 12 Jun 2022 04:38:28 -0400 Subject: [PATCH] Fix unreachable code heuristic for conditionals --- wasm-ast/src/builder.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wasm-ast/src/builder.rs b/wasm-ast/src/builder.rs index f1dc07e..adf38f8 100644 --- a/wasm-ast/src/builder.rs +++ b/wasm-ast/src/builder.rs @@ -515,12 +515,18 @@ impl<'a> Builder<'a> { Instruction::Block(_) | Instruction::Loop(_) | Instruction::If(_) => { self.nested_unreachable += 1; } - Instruction::End => { + Instruction::Else if self.nested_unreachable == 1 => { self.nested_unreachable -= 1; - if self.nested_unreachable == 0 { - self.end_block(); - } + self.start_else(); + } + Instruction::End if self.nested_unreachable == 1 => { + self.nested_unreachable -= 1; + + self.end_block(); + } + Instruction::End => { + self.nested_unreachable -= 1; } _ => {} }