@@ -949,13 +949,19 @@ impl FuncTranslator {
949
949
if self . reachable && self . stack . is_control_empty ( ) {
950
950
self . encode_return ( consume_fuel_instr) ?;
951
951
}
952
+ if frame. is_branched_to ( ) {
953
+ // No need to reset `last_instr` if there was no branch to the end of a Wasm `block`.
954
+ self . instrs . reset_last_instr ( ) ;
955
+ }
952
956
Ok ( ( ) )
953
957
}
954
958
955
959
/// Translates the end of a Wasm `loop` control frame.
956
960
fn translate_end_loop ( & mut self , _frame : LoopControlFrame ) -> Result < ( ) , Error > {
957
961
debug_assert ! ( !self . stack. is_control_empty( ) ) ;
958
962
// Nothing needs to be done since Wasm `loop` control frames always only have a single exit.
963
+ //
964
+ // Note: no need to reset `last_instr` since end of `loop` is not a control flow boundary.
959
965
Ok ( ( ) )
960
966
}
961
967
@@ -1003,6 +1009,8 @@ impl FuncTranslator {
1003
1009
. pin_label ( frame. label ( ) , self . instrs . next_instr ( ) )
1004
1010
. unwrap ( ) ;
1005
1011
self . reachable = true ;
1012
+ // Need to reset `last_instr` since end of `if` is a control flow boundary.
1013
+ self . instrs . reset_last_instr ( ) ;
1006
1014
Ok ( ( ) )
1007
1015
}
1008
1016
@@ -1035,6 +1043,8 @@ impl FuncTranslator {
1035
1043
. pin_label ( frame. label ( ) , self . instrs . next_instr ( ) )
1036
1044
. unwrap ( ) ;
1037
1045
self . reachable = reachable;
1046
+ // Need to reset `last_instr` since end of `else` is a control flow boundary.
1047
+ self . instrs . reset_last_instr ( ) ;
1038
1048
Ok ( ( ) )
1039
1049
}
1040
1050
@@ -1055,12 +1065,19 @@ impl FuncTranslator {
1055
1065
. pin_label ( frame. label ( ) , self . instrs . next_instr ( ) )
1056
1066
. unwrap ( ) ;
1057
1067
self . reachable = end_is_reachable || frame. is_branched_to ( ) ;
1068
+ if frame. is_branched_to ( ) {
1069
+ // No need to reset `last_instr` if there was no branch to the
1070
+ // end of a Wasm `if` where only `then` or `else` is reachable.
1071
+ self . instrs . reset_last_instr ( ) ;
1072
+ }
1058
1073
Ok ( ( ) )
1059
1074
}
1060
1075
1061
1076
/// Translates the end of an unreachable Wasm control frame.
1062
1077
fn translate_end_unreachable ( & mut self , _frame : ControlFrameKind ) -> Result < ( ) , Error > {
1063
1078
debug_assert ! ( !self . stack. is_control_empty( ) ) ;
1079
+ // We reset `last_instr` out of caution in case there is a control flow boundary.
1080
+ self . instrs . reset_last_instr ( ) ;
1064
1081
Ok ( ( ) )
1065
1082
}
1066
1083
0 commit comments