From aa724846f6a5947864ed49f00219f260def1f757 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 1 Nov 2017 11:25:22 -0700 Subject: [PATCH] Clear the wasm operand stack at the end of a function. This preserves an invariant that the stack is empty between function body translations. --- lib/wasm/src/func_translator.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/wasm/src/func_translator.rs b/lib/wasm/src/func_translator.rs index 9723f22ca5..aad791c9ac 100644 --- a/lib/wasm/src/func_translator.rs +++ b/lib/wasm/src/func_translator.rs @@ -215,6 +215,10 @@ fn parse_function_body( builder.ins().return_(&state.stack); } + // Discard any remaining values on the stack. Either we just returned them, + // or the end of the function is unreachable. + state.stack.clear(); + debug_assert!(reader.eof()); Ok(())