Reduce rightward drift.
This commit is contained in:
parent
dd452ae70e
commit
dd78b997b5
1 changed files with 35 additions and 37 deletions
|
@ -110,48 +110,46 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
||||||
// we must make sure that all `target as Variant#i` are `Top`.
|
// we must make sure that all `target as Variant#i` are `Top`.
|
||||||
state.flood(target.as_ref(), self.map());
|
state.flood(target.as_ref(), self.map());
|
||||||
|
|
||||||
if let Some(target_idx) = self.map().find(target.as_ref()) {
|
let Some(target_idx) = self.map().find(target.as_ref()) else { return };
|
||||||
let (variant_target, variant_index) = match **kind {
|
|
||||||
AggregateKind::Tuple | AggregateKind::Closure(..) => {
|
let (variant_target, variant_index) = match **kind {
|
||||||
(Some(target_idx), None)
|
AggregateKind::Tuple | AggregateKind::Closure(..) => (Some(target_idx), None),
|
||||||
}
|
AggregateKind::Adt(def_id, variant_index, ..) => {
|
||||||
AggregateKind::Adt(def_id, variant_index, ..) => {
|
match self.tcx.def_kind(def_id) {
|
||||||
match self.tcx.def_kind(def_id) {
|
DefKind::Struct => (Some(target_idx), None),
|
||||||
DefKind::Struct => (Some(target_idx), None),
|
DefKind::Enum => (
|
||||||
DefKind::Enum => (
|
self.map.apply(target_idx, TrackElem::Variant(variant_index)),
|
||||||
self.map.apply(target_idx, TrackElem::Variant(variant_index)),
|
Some(variant_index),
|
||||||
Some(variant_index),
|
),
|
||||||
),
|
_ => return,
|
||||||
_ => (None, None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (None, None),
|
|
||||||
};
|
|
||||||
if let Some(variant_target_idx) = variant_target {
|
|
||||||
for (field_index, operand) in operands.iter().enumerate() {
|
|
||||||
if let Some(field) = self.map().apply(
|
|
||||||
variant_target_idx,
|
|
||||||
TrackElem::Field(FieldIdx::from_usize(field_index)),
|
|
||||||
) {
|
|
||||||
let result = self.handle_operand(operand, state);
|
|
||||||
state.insert_idx(field, result, self.map());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(variant_index) = variant_index
|
_ => return,
|
||||||
&& let Some(discr_idx) = self.map().apply(target_idx, TrackElem::Discriminant)
|
};
|
||||||
{
|
if let Some(variant_target_idx) = variant_target {
|
||||||
// We are assigning the discriminant as part of an aggregate.
|
for (field_index, operand) in operands.iter().enumerate() {
|
||||||
// This discriminant can only alias a variant field's value if the operand
|
if let Some(field) = self.map().apply(
|
||||||
// had an invalid value for that type.
|
variant_target_idx,
|
||||||
// Using invalid values is UB, so we are allowed to perform the assignment
|
TrackElem::Field(FieldIdx::from_usize(field_index)),
|
||||||
// without extra flooding.
|
) {
|
||||||
let enum_ty = target.ty(self.local_decls, self.tcx).ty;
|
let result = self.handle_operand(operand, state);
|
||||||
if let Some(discr_val) = self.eval_discriminant(enum_ty, variant_index) {
|
state.insert_idx(field, result, self.map());
|
||||||
state.insert_value_idx(discr_idx, FlatSet::Elem(discr_val), &self.map);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(variant_index) = variant_index
|
||||||
|
&& let Some(discr_idx) = self.map().apply(target_idx, TrackElem::Discriminant)
|
||||||
|
{
|
||||||
|
// We are assigning the discriminant as part of an aggregate.
|
||||||
|
// This discriminant can only alias a variant field's value if the operand
|
||||||
|
// had an invalid value for that type.
|
||||||
|
// Using invalid values is UB, so we are allowed to perform the assignment
|
||||||
|
// without extra flooding.
|
||||||
|
let enum_ty = target.ty(self.local_decls, self.tcx).ty;
|
||||||
|
if let Some(discr_val) = self.eval_discriminant(enum_ty, variant_index) {
|
||||||
|
state.insert_value_idx(discr_idx, FlatSet::Elem(discr_val), &self.map);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Rvalue::CheckedBinaryOp(op, box (left, right)) => {
|
Rvalue::CheckedBinaryOp(op, box (left, right)) => {
|
||||||
// Flood everything now, so we can use `insert_value_idx` directly later.
|
// Flood everything now, so we can use `insert_value_idx` directly later.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue