Remove Unknown
state in favor of Value(Top)
This commit is contained in:
parent
1765587846
commit
7ab1ba95de
2 changed files with 21 additions and 20 deletions
|
@ -183,15 +183,15 @@ pub trait ValueAnalysis<'tcx> {
|
||||||
.map()
|
.map()
|
||||||
.find(place.as_ref())
|
.find(place.as_ref())
|
||||||
.map(ValueOrPlaceOrRef::Ref)
|
.map(ValueOrPlaceOrRef::Ref)
|
||||||
.unwrap_or(ValueOrPlaceOrRef::Unknown),
|
.unwrap_or(ValueOrPlaceOrRef::top()),
|
||||||
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
||||||
state.flood(place.as_ref(), self.map());
|
state.flood(place.as_ref(), self.map());
|
||||||
ValueOrPlaceOrRef::Unknown
|
ValueOrPlaceOrRef::top()
|
||||||
}
|
}
|
||||||
Rvalue::CopyForDeref(place) => {
|
Rvalue::CopyForDeref(place) => {
|
||||||
self.handle_operand(&Operand::Copy(*place), state).into()
|
self.handle_operand(&Operand::Copy(*place), state).into()
|
||||||
}
|
}
|
||||||
_ => ValueOrPlaceOrRef::Unknown,
|
_ => ValueOrPlaceOrRef::top(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ pub trait ValueAnalysis<'tcx> {
|
||||||
self.map()
|
self.map()
|
||||||
.find(place.as_ref())
|
.find(place.as_ref())
|
||||||
.map(ValueOrPlace::Place)
|
.map(ValueOrPlace::Place)
|
||||||
.unwrap_or(ValueOrPlace::Unknown)
|
.unwrap_or(ValueOrPlace::top())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -511,9 +511,6 @@ impl<V: Clone + HasTop> State<V> {
|
||||||
self.assign_place_idx(target_deref, source, map);
|
self.assign_place_idx(target_deref, source, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValueOrPlaceOrRef::Unknown => {
|
|
||||||
self.flood_idx(target, map);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,27 +753,35 @@ impl<'a> Iterator for Children<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: See if we can get rid of `Unknown`.
|
|
||||||
pub enum ValueOrPlace<V> {
|
pub enum ValueOrPlace<V> {
|
||||||
Value(V),
|
Value(V),
|
||||||
Place(PlaceIndex),
|
Place(PlaceIndex),
|
||||||
Unknown,
|
}
|
||||||
|
|
||||||
|
impl<V: HasTop> ValueOrPlace<V> {
|
||||||
|
pub fn top() -> Self {
|
||||||
|
ValueOrPlace::Value(V::top())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ValueOrPlaceOrRef<V> {
|
pub enum ValueOrPlaceOrRef<V> {
|
||||||
Value(V),
|
Value(V),
|
||||||
Place(PlaceIndex),
|
Place(PlaceIndex),
|
||||||
Ref(PlaceIndex),
|
Ref(PlaceIndex)
|
||||||
Unknown,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<V: HasTop> ValueOrPlaceOrRef<V> {
|
||||||
|
pub fn top() -> Self {
|
||||||
|
ValueOrPlaceOrRef::Value(V::top())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<V> From<ValueOrPlace<V>> for ValueOrPlaceOrRef<V> {
|
impl<V> From<ValueOrPlace<V>> for ValueOrPlaceOrRef<V> {
|
||||||
fn from(x: ValueOrPlace<V>) -> Self {
|
fn from(x: ValueOrPlace<V>) -> Self {
|
||||||
match x {
|
match x {
|
||||||
ValueOrPlace::Value(value) => ValueOrPlaceOrRef::Value(value),
|
ValueOrPlace::Value(value) => ValueOrPlaceOrRef::Value(value),
|
||||||
ValueOrPlace::Place(place) => ValueOrPlaceOrRef::Place(place),
|
ValueOrPlace::Place(place) => ValueOrPlaceOrRef::Place(place),
|
||||||
ValueOrPlace::Unknown => ValueOrPlaceOrRef::Unknown,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,8 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
|
||||||
.ecx
|
.ecx
|
||||||
.misc_cast(&operand, *ty)
|
.misc_cast(&operand, *ty)
|
||||||
.map(|result| ValueOrPlaceOrRef::Value(self.wrap_immediate(result, *ty)))
|
.map(|result| ValueOrPlaceOrRef::Value(self.wrap_immediate(result, *ty)))
|
||||||
.unwrap_or(ValueOrPlaceOrRef::Unknown),
|
.unwrap_or(ValueOrPlaceOrRef::top()),
|
||||||
_ => ValueOrPlaceOrRef::Unknown,
|
_ => ValueOrPlaceOrRef::top(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rvalue::BinaryOp(op, box (left, right)) => {
|
Rvalue::BinaryOp(op, box (left, right)) => {
|
||||||
|
@ -156,7 +156,6 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
|
||||||
let value = match self.handle_operand(discr, state) {
|
let value = match self.handle_operand(discr, state) {
|
||||||
ValueOrPlace::Value(value) => value,
|
ValueOrPlace::Value(value) => value,
|
||||||
ValueOrPlace::Place(place) => state.get_idx(place, self.map()),
|
ValueOrPlace::Place(place) => state.get_idx(place, self.map()),
|
||||||
ValueOrPlace::Unknown => FlatSet::Top,
|
|
||||||
};
|
};
|
||||||
let result = match value {
|
let result = match value {
|
||||||
FlatSet::Top => FlatSet::Top,
|
FlatSet::Top => FlatSet::Top,
|
||||||
|
@ -241,7 +240,6 @@ impl<'tcx> ConstAnalysis<'tcx> {
|
||||||
let value = match self.handle_operand(op, state) {
|
let value = match self.handle_operand(op, state) {
|
||||||
ValueOrPlace::Value(value) => value,
|
ValueOrPlace::Value(value) => value,
|
||||||
ValueOrPlace::Place(place) => state.get_idx(place, &self.map),
|
ValueOrPlace::Place(place) => state.get_idx(place, &self.map),
|
||||||
ValueOrPlace::Unknown => FlatSet::Top,
|
|
||||||
};
|
};
|
||||||
match value {
|
match value {
|
||||||
FlatSet::Top => FlatSet::Top,
|
FlatSet::Top => FlatSet::Top,
|
||||||
|
@ -384,9 +382,7 @@ impl<'tcx, 'map, 'a> Visitor<'tcx> for OperandCollector<'tcx, 'map, 'a> {
|
||||||
FlatSet::Elem(value) => {
|
FlatSet::Elem(value) => {
|
||||||
self.visitor.before_effect.insert((location, *place), value);
|
self.visitor.before_effect.insert((location, *place), value);
|
||||||
}
|
}
|
||||||
FlatSet::Bottom => {
|
FlatSet::Bottom => (),
|
||||||
// This only happens if this location is unreachable.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue