diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index d11d1fb442..df6eda1760 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -361,7 +361,7 @@ pub fn translate_operator( // We signal that all the code that follows until the next End is unreachable frame.set_branched_to_exit(); let return_count = if frame.is_loop() { - 0 + frame.num_param_values() } else { frame.num_return_values() }; diff --git a/tests/wasm/loop-params.wat b/tests/wasm/loop-params.wat new file mode 100644 index 0000000000..eb1499d84d --- /dev/null +++ b/tests/wasm/loop-params.wat @@ -0,0 +1,13 @@ + (module + (func (export "run") (result i32) + (local $i i32) + (i32.const 0) ;; sum + (i32.const 10) ;; i + (loop $loop (param i32 i32) (result i32) + (local.tee $i) + (i32.add) ;; sum = i + sum + (i32.sub (local.get $i) (i32.const 1)) + (i32.eqz (local.tee $i)) + (if (param i32) (result i32) + (then) + (else (local.get $i) (br $loop))))))