cranelift-wasm: Jump to the destination block at end of consequent

This commit fixes a bug where at the end of an `if..else..end`'s consequent
block, we would sometimes erroneously jump to the `else` block instead of to the
following destination block. Not good!
This commit is contained in:
Nick Fitzgerald
2019-10-02 16:28:46 -07:00
committed by Dan Gohman
parent b3cf7f911b
commit 913d26841a
2 changed files with 11 additions and 1 deletions

View File

@@ -203,6 +203,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
else_data: ElseData::NoElse { branch_inst }, else_data: ElseData::NoElse { branch_inst },
ref mut reachable_from_top, ref mut reachable_from_top,
blocktype, blocktype,
destination,
.. ..
} => { } => {
// We take the control frame pushed by the if, use its ebb // We take the control frame pushed by the if, use its ebb
@@ -215,7 +216,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let (params, _results) = blocktype_params_results(wasm_types, blocktype)?; let (params, _results) = blocktype_params_results(wasm_types, blocktype)?;
let else_ebb = ebb_with_params(builder, params)?; let else_ebb = ebb_with_params(builder, params)?;
builder.ins().jump(else_ebb, state.peekn(params.len())); builder.ins().jump(destination, state.peekn(params.len()));
state.popn(params.len()); state.popn(params.len());
// You might be expecting that we push the parameters for this // You might be expecting that we push the parameters for this

View File

@@ -0,0 +1,9 @@
(module
(func (export "param") (param i32) (result i32)
(i32.const 1)
(if (param i32) (result i32) (local.get 0)
(then (i32.const 2) (i32.add))
(else (i32.const -2) (i32.add))
)
)
)