From 635befa21043c7b6b0a2d9f96f3182e5d0cbaeca Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Thu, 23 Dec 2021 20:34:50 -0800 Subject: [PATCH] fuzzbug fixes --- src/backend/schedule.rs | 3 +++ src/backend/use_count.rs | 26 ++++++++++++++++++-------- src/ir.rs | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/backend/schedule.rs b/src/backend/schedule.rs index bc44cf7..e932981 100644 --- a/src/backend/schedule.rs +++ b/src/backend/schedule.rs @@ -91,6 +91,9 @@ impl Schedule { log::trace!("v{} waiting on {:?}", value.index(), operands); ctx.remaining_inputs.insert(value, operands.len()); for &input in operands { + if input == Value::undef() { + continue; + } let input = f.resolve_alias(input); ctx.waiting_on_value .entry(input) diff --git a/src/backend/use_count.rs b/src/backend/use_count.rs index f5ecf9e..832b21f 100644 --- a/src/backend/use_count.rs +++ b/src/backend/use_count.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; -use crate::{Value, FunctionBody, ValueDef}; +use crate::{FunctionBody, Value, ValueDef}; use fxhash::FxHashSet; #[derive(Clone, Debug)] @@ -23,16 +23,20 @@ impl UseCountAnalysis { let mut workqueue_set = FxHashSet::default(); for block in 0..f.blocks.len() { for &value in &f.blocks[block].insts { - let value = f.resolve_alias(value); - if workqueue_set.insert(value) { - workqueue.push_back(value); + if value != Value::undef() { + let value = f.resolve_alias(value); + if workqueue_set.insert(value) { + workqueue.push_back(value); + } + counts.toplevel.insert(value); } - counts.toplevel.insert(value); } f.blocks[block].terminator.visit_uses(|value| { - let value = f.resolve_alias(value); - if workqueue_set.insert(value) { - workqueue.push_back(value); + if value != Value::undef() { + let value = f.resolve_alias(value); + if workqueue_set.insert(value) { + workqueue.push_back(value); + } } }); @@ -43,6 +47,9 @@ impl UseCountAnalysis { &ValueDef::Alias(..) | &ValueDef::Arg(..) | &ValueDef::BlockParam(..) => {} &ValueDef::Operator(_op, ref args) => { for &arg in args { + if arg == Value::undef() { + continue; + } let arg = f.resolve_alias(arg); if counts.use_count[arg.index()] == 0 { if workqueue_set.insert(arg) { @@ -52,6 +59,9 @@ impl UseCountAnalysis { } } &ValueDef::PickOutput(value, _) => { + if value == Value::undef() { + continue; + } let value = f.resolve_alias(value); if counts.use_count[value.index()] == 0 { if workqueue_set.insert(value) { diff --git a/src/ir.rs b/src/ir.rs index 9100280..eea694e 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -106,6 +106,7 @@ impl FunctionBody { } pub fn resolve_alias(&self, value: Value) -> Value { + assert_ne!(value, Value::undef()); let mut result = value; loop { if let &ValueDef::Alias(to) = &self.values[result.index()] {