From eb946642856e8a5ba7fcf1f3e41e090de116db78 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 5 Jun 2018 09:19:08 -0700 Subject: [PATCH] Add assertions to check translate_call and translate_call_indirect. Assert that the results produced by translate_call and translate_call_indirect match the results of the call signatures. --- lib/wasm/src/code_translator.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index 7aae3d6678..1d5386184e 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -361,8 +361,16 @@ pub fn translate_operator( fref, state.peekn(num_args), )?; + let inst_results = builder.inst_results(call); + debug_assert_eq!( + inst_results.len(), + builder.func.dfg.signatures[builder.func.dfg.ext_funcs[fref].signature] + .returns + .len(), + "translate_call results should match the call signature" + ); state.popn(num_args); - state.pushn(builder.inst_results(call)); + state.pushn(inst_results); } Operator::CallIndirect { index, table_index } => { // `index` is the index of the function's signature and `table_index` is the index of @@ -377,8 +385,14 @@ pub fn translate_operator( callee, state.peekn(num_args), )?; + let inst_results = builder.inst_results(call); + debug_assert_eq!( + inst_results.len(), + builder.func.dfg.signatures[sigref].returns.len(), + "translate_call_indirect results should match the call signature" + ); state.popn(num_args); - state.pushn(builder.inst_results(call)); + state.pushn(inst_results); } /******************************* Memory management *********************************** * Memory management is handled by environment. It is usually translated into calls to