This commit is contained in:
Chris Fallin 2022-11-29 18:40:57 -08:00
parent 2ec2de1dfc
commit 4e3fb51aa9
No known key found for this signature in database
GPG key ID: 31649E4FE65EB465

View file

@ -621,6 +621,7 @@ enum Frame {
params: Vec<Type>, params: Vec<Type>,
results: Vec<Type>, results: Vec<Type>,
head_reachable: bool, head_reachable: bool,
merge_reachable: bool,
}, },
Else { Else {
start_depth: usize, start_depth: usize,
@ -688,6 +689,12 @@ impl Frame {
fn set_reachable(&mut self) { fn set_reachable(&mut self) {
match self { match self {
Frame::Block { out_reachable, .. } => *out_reachable = true, Frame::Block { out_reachable, .. } => *out_reachable = true,
Frame::If {
merge_reachable, ..
}
| Frame::Else {
merge_reachable, ..
} => *merge_reachable = true,
_ => {} _ => {}
} }
} }
@ -1027,6 +1034,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
term_targets.push(block); term_targets.push(block);
} }
self.emit_br_table(index, default_term_target, &term_targets[..], &args[..]); self.emit_br_table(index, default_term_target, &term_targets[..], &args[..]);
self.reachable = false;
} }
wasmparser::Operator::Return => { wasmparser::Operator::Return => {
@ -1123,6 +1131,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
ref param_values, ref param_values,
ref results, ref results,
head_reachable, head_reachable,
merge_reachable,
.. ..
}) => { }) => {
// Generate a branch to the out-block with // Generate a branch to the out-block with
@ -1151,7 +1160,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
assert_eq!(self.op_stack.len(), *start_depth); assert_eq!(self.op_stack.len(), *start_depth);
} }
self.cur_block = *out; self.cur_block = *out;
self.reachable = *head_reachable || self.reachable; self.reachable = *head_reachable || self.reachable || *merge_reachable;
self.locals.seal_block_preds(*out, &mut self.body); self.locals.seal_block_preds(*out, &mut self.body);
self.locals.start_block(*out, was_reachable); self.locals.start_block(*out, was_reachable);
self.push_block_params(results.len()); self.push_block_params(results.len());
@ -1253,6 +1262,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
params, params,
results, results,
head_reachable: self.reachable, head_reachable: self.reachable,
merge_reachable: false,
}); });
self.emit_cond_branch(cond, if_true, &[], if_false, &[]); self.emit_cond_branch(cond, if_true, &[], if_false, &[]);
self.locals.seal_block_preds(if_true, &mut self.body); self.locals.seal_block_preds(if_true, &mut self.body);
@ -1270,6 +1280,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
params, params,
results, results,
head_reachable, head_reachable,
merge_reachable,
} = self.ctrl_stack.pop().unwrap() } = self.ctrl_stack.pop().unwrap()
{ {
if self.reachable { if self.reachable {
@ -1284,7 +1295,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
out, out,
params, params,
results, results,
merge_reachable: head_reachable, merge_reachable,
}); });
self.cur_block = el; self.cur_block = el;
self.locals.start_block(el, self.reachable); self.locals.start_block(el, self.reachable);
@ -1380,7 +1391,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
}, },
}, },
); );
self.reachable = false;
self.locals.finish_block(true); self.locals.finish_block(true);
} }
} }
@ -1425,7 +1435,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
}, },
); );
self.locals.finish_block(true); self.locals.finish_block(true);
self.reachable = false;
} }
} }