fuzzbug fix

This commit is contained in:
Chris Fallin 2021-12-24 14:50:23 -08:00
parent 110fe11fa8
commit d6c6c70965
4 changed files with 25 additions and 3 deletions

View file

@ -27,6 +27,7 @@ impl<'a, FT: FuncTypeSink> WasmContext<'a, FT> {
}
fn translate(&mut self, op: &SerializedOperator, locations: &Locations) {
log::trace!("translate: {:?}", op);
match op {
SerializedOperator::StartBlock {
ref params,
@ -129,6 +130,7 @@ impl<'a, FT: FuncTypeSink> WasmContext<'a, FT> {
target: &SerializedBlockTarget,
locations: &Locations,
) {
log::trace!("translate_target: {:?}", target);
match target {
&SerializedBlockTarget::Fallthrough(ref ops) => {
for op in ops {

View file

@ -246,12 +246,14 @@ impl<'a> SerializedBodyContext<'a> {
let targets = targets
.iter()
.map(|target| {
log::trace!("target: {:?}", target);
let mut rev_ops = vec![];
for &value in target.args.iter().rev() {
let value = self.f.resolve_alias(value);
self.push_value(value, &mut rev_ops);
}
rev_ops.reverse();
log::trace!(" -> ops: {:?}", rev_ops);
match target.relative_branch {
Some(branch) => SerializedBlockTarget::Branch(branch, rev_ops),
None => SerializedBlockTarget::Fallthrough(rev_ops),

View file

@ -310,7 +310,15 @@ impl BlockOrder {
pub fn compute(f: &FunctionBody, cfg: &CFGInfo, wasm_region: &WasmRegion) -> BlockOrder {
let mut target_stack = vec![];
let mut entries = vec![];
Self::generate_region(f, cfg, &mut target_stack, &mut entries, wasm_region, None);
Self::generate_region(
f,
cfg,
&mut target_stack,
&mut entries,
wasm_region,
None,
true,
);
log::trace!("entries: {:?}", entries);
BlockOrder { entries }
}
@ -322,6 +330,7 @@ impl BlockOrder {
entries: &mut Vec<BlockOrderEntry>,
region: &WasmRegion,
fallthrough: Option<BlockId>,
toplevel: bool,
) {
log::trace!(
"BlockOrder::generate_region: stack {:?} region {:?} fallthrough {:?}",
@ -345,7 +354,7 @@ impl BlockOrder {
target_stack.push(target);
}
let params = f.blocks[header].params.clone();
let results = if header == 0 {
let results = if toplevel {
f.rets.clone()
} else {
match fallthrough {
@ -370,7 +379,15 @@ impl BlockOrder {
} else {
Some(subregions[i + 1].header())
};
Self::generate_region(f, cfg, target_stack, entries, subregion, fallthrough);
Self::generate_region(
f,
cfg,
target_stack,
entries,
subregion,
fallthrough,
false,
);
}
entries.push(BlockOrderEntry::End);

View file

@ -945,6 +945,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
};
// Get the frame we're branching to.
let frame = self.relative_frame(*relative_depth).clone();
log::trace!("Br/BrIf: dest frame {:?}", frame);
// Finally, generate the branch itself.
match cond {
None => {