Add SwitchTargetValue
.
This is much clearer than `Option<u128>`.
This commit is contained in:
parent
23dbff88f6
commit
8403d39dce
5 changed files with 33 additions and 12 deletions
|
@ -27,7 +27,15 @@ type Predecessors = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>;
|
||||||
/// `BasicBlocks::switch_sources`, which is only called by backwards analyses
|
/// `BasicBlocks::switch_sources`, which is only called by backwards analyses
|
||||||
/// that do `SwitchInt` handling, and we don't have any of those, not even in
|
/// that do `SwitchInt` handling, and we don't have any of those, not even in
|
||||||
/// tests. See #95120 and #94576.
|
/// tests. See #95120 and #94576.
|
||||||
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option<u128>; 1]>>;
|
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[SwitchTargetValue; 1]>>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum SwitchTargetValue {
|
||||||
|
// A normal switch value.
|
||||||
|
Normal(u128),
|
||||||
|
// The final "otherwise" fallback value.
|
||||||
|
Otherwise,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Default, Debug)]
|
||||||
struct Cache {
|
struct Cache {
|
||||||
|
@ -89,9 +97,15 @@ impl<'tcx> BasicBlocks<'tcx> {
|
||||||
}) = &data.terminator
|
}) = &data.terminator
|
||||||
{
|
{
|
||||||
for (value, target) in targets.iter() {
|
for (value, target) in targets.iter() {
|
||||||
switch_sources.entry((target, bb)).or_default().push(Some(value));
|
switch_sources
|
||||||
|
.entry((target, bb))
|
||||||
|
.or_default()
|
||||||
|
.push(SwitchTargetValue::Normal(value));
|
||||||
}
|
}
|
||||||
switch_sources.entry((targets.otherwise(), bb)).or_default().push(None);
|
switch_sources
|
||||||
|
.entry((targets.otherwise(), bb))
|
||||||
|
.or_default()
|
||||||
|
.push(SwitchTargetValue::Otherwise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch_sources
|
switch_sources
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::fmt::{self, Debug, Formatter};
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
use std::{iter, mem};
|
use std::{iter, mem};
|
||||||
|
|
||||||
pub use basic_blocks::BasicBlocks;
|
pub use basic_blocks::{BasicBlocks, SwitchTargetValue};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use polonius_engine::Atom;
|
use polonius_engine::Atom;
|
||||||
use rustc_abi::{FieldIdx, VariantIdx};
|
use rustc_abi::{FieldIdx, VariantIdx};
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges};
|
use rustc_middle::mir::{
|
||||||
|
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
|
||||||
|
};
|
||||||
|
|
||||||
use super::visitor::ResultsVisitor;
|
use super::visitor::ResultsVisitor;
|
||||||
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
|
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
|
||||||
|
@ -290,7 +292,8 @@ impl Direction for Forward {
|
||||||
let mut tmp = analysis.bottom_value(body);
|
let mut tmp = analysis.bottom_value(body);
|
||||||
for (value, target) in targets.iter() {
|
for (value, target) in targets.iter() {
|
||||||
tmp.clone_from(exit_state);
|
tmp.clone_from(exit_state);
|
||||||
let si_target = SwitchIntTarget { value: Some(value), target };
|
let si_target =
|
||||||
|
SwitchIntTarget { value: SwitchTargetValue::Normal(value), target };
|
||||||
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
|
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
|
||||||
propagate(target, &tmp);
|
propagate(target, &tmp);
|
||||||
}
|
}
|
||||||
|
@ -302,7 +305,7 @@ impl Direction for Forward {
|
||||||
analysis.apply_switch_int_edge_effect(
|
analysis.apply_switch_int_edge_effect(
|
||||||
&mut data,
|
&mut data,
|
||||||
exit_state,
|
exit_state,
|
||||||
SwitchIntTarget { value: None, target: otherwise },
|
SwitchIntTarget { value: SwitchTargetValue::Otherwise, target: otherwise },
|
||||||
);
|
);
|
||||||
propagate(otherwise, exit_state);
|
propagate(otherwise, exit_state);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -38,7 +38,9 @@ use rustc_data_structures::work_queue::WorkQueue;
|
||||||
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
|
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
|
||||||
use rustc_index::{Idx, IndexVec};
|
use rustc_index::{Idx, IndexVec};
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges, traversal};
|
use rustc_middle::mir::{
|
||||||
|
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges, traversal,
|
||||||
|
};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
|
@ -431,7 +433,7 @@ impl EffectIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SwitchIntTarget {
|
pub struct SwitchIntTarget {
|
||||||
pub value: Option<u128>,
|
pub value: SwitchTargetValue,
|
||||||
pub target: BasicBlock,
|
pub target: BasicBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ use rustc_abi::VariantIdx;
|
||||||
use rustc_index::Idx;
|
use rustc_index::Idx;
|
||||||
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
|
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
|
use rustc_middle::mir::{
|
||||||
|
self, Body, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
|
||||||
|
};
|
||||||
use rustc_middle::ty::util::Discr;
|
use rustc_middle::ty::util::Discr;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
|
@ -424,7 +426,7 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
|
||||||
state: &mut Self::Domain,
|
state: &mut Self::Domain,
|
||||||
edge: SwitchIntTarget,
|
edge: SwitchIntTarget,
|
||||||
) {
|
) {
|
||||||
if let Some(value) = edge.value {
|
if let SwitchTargetValue::Normal(value) = edge.value {
|
||||||
// Kill all move paths that correspond to variants we know to be inactive along this
|
// Kill all move paths that correspond to variants we know to be inactive along this
|
||||||
// particular outgoing edge of a `SwitchInt`.
|
// particular outgoing edge of a `SwitchInt`.
|
||||||
drop_flag_effects::on_all_inactive_variants(
|
drop_flag_effects::on_all_inactive_variants(
|
||||||
|
@ -537,7 +539,7 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
|
||||||
state: &mut Self::Domain,
|
state: &mut Self::Domain,
|
||||||
edge: SwitchIntTarget,
|
edge: SwitchIntTarget,
|
||||||
) {
|
) {
|
||||||
if let Some(value) = edge.value {
|
if let SwitchTargetValue::Normal(value) = edge.value {
|
||||||
// Mark all move paths that correspond to variants other than this one as maybe
|
// Mark all move paths that correspond to variants other than this one as maybe
|
||||||
// uninitialized (in reality, they are *definitely* uninitialized).
|
// uninitialized (in reality, they are *definitely* uninitialized).
|
||||||
drop_flag_effects::on_all_inactive_variants(
|
drop_flag_effects::on_all_inactive_variants(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue