@@ -168,10 +168,11 @@ fn validate_intrablock_jump_and_generate_sidetable_entry(
168168 label_idx : usize ,
169169 stack : & mut ValidationStack ,
170170 sidetable : & mut Sidetable ,
171+ unify_to_expected_types : bool ,
171172) -> Result < ( ) > {
172173 let ctrl_stack_len = stack. ctrl_stack . len ( ) ;
173174
174- stack. assert_val_types_of_label_jump_types_on_top ( label_idx) ?;
175+ stack. assert_val_types_of_label_jump_types_on_top ( label_idx, unify_to_expected_types ) ?;
175176
176177 let targeted_ctrl_block_entry = stack
177178 . ctrl_stack
@@ -228,15 +229,15 @@ fn read_instructions(
228229 let label_info = LabelInfo :: Block {
229230 stps_to_backpatch : Vec :: new ( ) ,
230231 } ;
231- stack. assert_push_ctrl ( label_info, block_ty) ?;
232+ stack. assert_push_ctrl ( label_info, block_ty, true ) ?;
232233 }
233234 LOOP => {
234235 let block_ty = BlockType :: read ( wasm) ?. as_func_type ( fn_types) ?;
235236 let label_info = LabelInfo :: Loop {
236237 ip : wasm. pc ,
237238 stp : sidetable. len ( ) ,
238239 } ;
239- stack. assert_push_ctrl ( label_info, block_ty) ?;
240+ stack. assert_push_ctrl ( label_info, block_ty, true ) ?;
240241 }
241242 IF => {
242243 let block_ty = BlockType :: read ( wasm) ?. as_func_type ( fn_types) ?;
@@ -255,10 +256,10 @@ fn read_instructions(
255256 stp : stp_here,
256257 stps_to_backpatch : Vec :: new ( ) ,
257258 } ;
258- stack. assert_push_ctrl ( label_info, block_ty) ?;
259+ stack. assert_push_ctrl ( label_info, block_ty, true ) ?;
259260 }
260261 ELSE => {
261- let ( mut label_info, block_ty) = stack. assert_pop_ctrl ( ) ?;
262+ let ( mut label_info, block_ty) = stack. assert_pop_ctrl ( true ) ?;
262263 if let LabelInfo :: If {
263264 stp,
264265 stps_to_backpatch,
@@ -291,23 +292,23 @@ fn read_instructions(
291292 stack. push_valtype ( * valtype) ;
292293 }
293294
294- stack. assert_push_ctrl ( label_info, block_ty) ?;
295+ stack. assert_push_ctrl ( label_info, block_ty, true ) ?;
295296 } else {
296297 return Err ( Error :: ElseWithoutMatchingIf ) ;
297298 }
298299 }
299300 BR => {
300301 let label_idx = wasm. read_var_u32 ( ) ? as LabelIdx ;
301302 validate_intrablock_jump_and_generate_sidetable_entry (
302- wasm, label_idx, stack, sidetable,
303+ wasm, label_idx, stack, sidetable, false ,
303304 ) ?;
304305 stack. make_unspecified ( ) ?;
305306 }
306307 BR_IF => {
307308 let label_idx = wasm. read_var_u32 ( ) ? as LabelIdx ;
308309 stack. assert_pop_val_type ( ValType :: NumType ( NumType :: I32 ) ) ?;
309310 validate_intrablock_jump_and_generate_sidetable_entry (
310- wasm, label_idx, stack, sidetable,
311+ wasm, label_idx, stack, sidetable, true ,
311312 ) ?;
312313 }
313314 BR_TABLE => {
@@ -316,7 +317,7 @@ fn read_instructions(
316317 stack. assert_pop_val_type ( ValType :: NumType ( NumType :: I32 ) ) ?;
317318 for label_idx in & label_vec {
318319 validate_intrablock_jump_and_generate_sidetable_entry (
319- wasm, * label_idx, stack, sidetable,
320+ wasm, * label_idx, stack, sidetable, false ,
320321 ) ?;
321322 }
322323
@@ -325,6 +326,7 @@ fn read_instructions(
325326 max_label_idx,
326327 stack,
327328 sidetable,
329+ false ,
328330 ) ?;
329331
330332 // The label arity of the branches must be explicitly checked against each other further
@@ -354,7 +356,7 @@ fn read_instructions(
354356 stack. make_unspecified ( ) ?;
355357 }
356358 END => {
357- let ( label_info, block_ty) = stack. assert_pop_ctrl ( ) ?;
359+ let ( label_info, block_ty) = stack. assert_pop_ctrl ( true ) ?;
358360 let stp_here = sidetable. len ( ) ;
359361
360362 match label_info {
@@ -408,7 +410,7 @@ fn read_instructions(
408410 RETURN => {
409411 let label_idx = stack. ctrl_stack . len ( ) - 1 ; // return behaves the same as br <most_outer>
410412 validate_intrablock_jump_and_generate_sidetable_entry (
411- wasm, label_idx, stack, sidetable,
413+ wasm, label_idx, stack, sidetable, false ,
412414 ) ?;
413415 stack. make_unspecified ( ) ?;
414416 }
@@ -492,7 +494,7 @@ fn read_instructions(
492494 LOCAL_TEE => {
493495 let local_idx = wasm. read_var_u32 ( ) ? as LocalIdx ;
494496 let local_ty = locals. get ( local_idx) . ok_or ( Error :: InvalidLocalIdx ) ?;
495- stack. assert_val_types_on_top ( & [ * local_ty] ) ?;
497+ stack. assert_val_types_on_top ( & [ * local_ty] , true ) ?;
496498 }
497499 // global.get [] -> [t]
498500 GLOBAL_GET => {
0 commit comments