2020-05-23 22:55:44 +00:00
|
|
|
//! Validates the MIR to ensure that invariants are upheld.
|
|
|
|
|
|
|
|
use super::{MirPass, MirSource};
|
|
|
|
use rustc_middle::mir::visit::Visitor;
|
|
|
|
use rustc_middle::{
|
2020-05-31 07:52:51 +00:00
|
|
|
mir::{
|
2020-09-10 00:00:00 +00:00
|
|
|
AggregateKind, BasicBlock, Body, BorrowKind, Location, MirPhase, Operand, Rvalue,
|
|
|
|
Statement, StatementKind, Terminator, TerminatorKind,
|
2020-05-31 07:52:51 +00:00
|
|
|
},
|
2020-06-21 11:49:53 +00:00
|
|
|
ty::{
|
|
|
|
self,
|
|
|
|
relate::{Relate, RelateResult, TypeRelation},
|
|
|
|
ParamEnv, Ty, TyCtxt,
|
|
|
|
},
|
2020-05-23 22:55:44 +00:00
|
|
|
};
|
|
|
|
|
2020-06-09 10:21:36 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2020-06-08 12:54:20 +00:00
|
|
|
enum EdgeKind {
|
|
|
|
Unwind,
|
2020-06-08 15:04:41 +00:00
|
|
|
Normal,
|
2020-06-08 12:54:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 22:55:44 +00:00
|
|
|
pub struct Validator {
|
|
|
|
/// Describes at which point in the pipeline this validation is happening.
|
|
|
|
pub when: String,
|
2020-08-14 16:01:14 +00:00
|
|
|
/// The phase for which we are upholding the dialect. If the given phase forbids a specific
|
|
|
|
/// element, this validator will now emit errors if that specific element is encountered.
|
|
|
|
/// Note that phases that change the dialect cause all *following* phases to check the
|
|
|
|
/// invariants of the new dialect. A phase that changes dialects never checks the new invariants
|
|
|
|
/// itself.
|
|
|
|
pub mir_phase: MirPhase,
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> MirPass<'tcx> for Validator {
|
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
|
2020-06-14 18:22:13 +00:00
|
|
|
let param_env = tcx.param_env(source.def_id());
|
2020-08-14 16:01:14 +00:00
|
|
|
let mir_phase = self.mir_phase;
|
|
|
|
TypeChecker { when: &self.when, source, body, tcx, param_env, mir_phase }.visit_body(body);
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 07:17:33 +00:00
|
|
|
/// Returns whether the two types are equal up to lifetimes.
|
|
|
|
/// All lifetimes, including higher-ranked ones, get ignored for this comparison.
|
|
|
|
/// (This is unlike the `erasing_regions` methods, which keep higher-ranked lifetimes for soundness reasons.)
|
|
|
|
///
|
|
|
|
/// The point of this function is to approximate "equal up to subtyping". However,
|
|
|
|
/// the approximation is incorrect as variance is ignored.
|
|
|
|
pub fn equal_up_to_regions(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
param_env: ParamEnv<'tcx>,
|
|
|
|
src: Ty<'tcx>,
|
|
|
|
dest: Ty<'tcx>,
|
|
|
|
) -> bool {
|
2020-06-22 09:07:39 +00:00
|
|
|
// Fast path.
|
|
|
|
if src == dest {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-22 07:17:33 +00:00
|
|
|
struct LifetimeIgnoreRelation<'tcx> {
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TypeRelation<'tcx> for LifetimeIgnoreRelation<'tcx> {
|
|
|
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
|
|
|
self.tcx
|
|
|
|
}
|
|
|
|
|
|
|
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
|
|
|
self.param_env
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tag(&self) -> &'static str {
|
|
|
|
"librustc_mir::transform::validate"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn a_is_expected(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn relate_with_variance<T: Relate<'tcx>>(
|
|
|
|
&mut self,
|
|
|
|
_: ty::Variance,
|
2020-06-30 07:20:08 +00:00
|
|
|
a: T,
|
|
|
|
b: T,
|
2020-06-22 07:17:33 +00:00
|
|
|
) -> RelateResult<'tcx, T> {
|
|
|
|
// Ignore variance, require types to be exactly the same.
|
|
|
|
self.relate(a, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
|
|
|
|
if a == b {
|
|
|
|
// Short-circuit.
|
|
|
|
return Ok(a);
|
|
|
|
}
|
|
|
|
ty::relate::super_relate_tys(self, a, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn regions(
|
|
|
|
&mut self,
|
|
|
|
a: ty::Region<'tcx>,
|
|
|
|
_b: ty::Region<'tcx>,
|
|
|
|
) -> RelateResult<'tcx, ty::Region<'tcx>> {
|
|
|
|
// Ignore regions.
|
|
|
|
Ok(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn consts(
|
|
|
|
&mut self,
|
|
|
|
a: &'tcx ty::Const<'tcx>,
|
|
|
|
b: &'tcx ty::Const<'tcx>,
|
|
|
|
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
|
|
|
|
ty::relate::super_relate_consts(self, a, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn binders<T>(
|
|
|
|
&mut self,
|
2020-06-30 07:20:08 +00:00
|
|
|
a: ty::Binder<T>,
|
|
|
|
b: ty::Binder<T>,
|
2020-06-22 07:17:33 +00:00
|
|
|
) -> RelateResult<'tcx, ty::Binder<T>>
|
|
|
|
where
|
|
|
|
T: Relate<'tcx>,
|
|
|
|
{
|
|
|
|
self.relate(a.skip_binder(), b.skip_binder())?;
|
2020-08-07 22:27:46 +00:00
|
|
|
Ok(a)
|
2020-06-22 07:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate and run relation.
|
|
|
|
let mut relator: LifetimeIgnoreRelation<'tcx> = LifetimeIgnoreRelation { tcx: tcx, param_env };
|
2020-06-30 07:20:08 +00:00
|
|
|
relator.relate(src, dest).is_ok()
|
2020-06-22 07:17:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 22:55:44 +00:00
|
|
|
struct TypeChecker<'a, 'tcx> {
|
|
|
|
when: &'a str,
|
2020-06-14 18:22:13 +00:00
|
|
|
source: MirSource<'tcx>,
|
2020-05-23 22:55:44 +00:00
|
|
|
body: &'a Body<'tcx>,
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
param_env: ParamEnv<'tcx>,
|
2020-08-14 16:01:14 +00:00
|
|
|
mir_phase: MirPhase,
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
2020-05-31 13:21:09 +00:00
|
|
|
fn fail(&self, location: Location, msg: impl AsRef<str>) {
|
|
|
|
let span = self.body.source_info(location).span;
|
2020-05-23 22:55:44 +00:00
|
|
|
// We use `delay_span_bug` as we might see broken MIR when other errors have already
|
|
|
|
// occurred.
|
|
|
|
self.tcx.sess.diagnostic().delay_span_bug(
|
|
|
|
span,
|
2020-05-31 13:21:09 +00:00
|
|
|
&format!(
|
|
|
|
"broken MIR in {:?} ({}) at {:?}:\n{}",
|
2020-06-14 18:22:13 +00:00
|
|
|
self.source.instance,
|
2020-05-31 13:21:09 +00:00
|
|
|
self.when,
|
|
|
|
location,
|
|
|
|
msg.as_ref()
|
|
|
|
),
|
2020-05-23 22:55:44 +00:00
|
|
|
);
|
|
|
|
}
|
2020-05-31 07:52:51 +00:00
|
|
|
|
2020-06-09 10:21:36 +00:00
|
|
|
fn check_edge(&self, location: Location, bb: BasicBlock, edge_kind: EdgeKind) {
|
2020-06-08 12:54:20 +00:00
|
|
|
if let Some(bb) = self.body.basic_blocks().get(bb) {
|
|
|
|
let src = self.body.basic_blocks().get(location.block).unwrap();
|
|
|
|
match (src.is_cleanup, bb.is_cleanup, edge_kind) {
|
|
|
|
// Non-cleanup blocks can jump to non-cleanup blocks along non-unwind edges
|
2020-06-08 15:04:41 +00:00
|
|
|
(false, false, EdgeKind::Normal)
|
2020-06-08 12:54:20 +00:00
|
|
|
// Non-cleanup blocks can jump to cleanup blocks along unwind edges
|
|
|
|
| (false, true, EdgeKind::Unwind)
|
2020-06-08 15:04:41 +00:00
|
|
|
// Cleanup blocks can jump to cleanup blocks along non-unwind edges
|
|
|
|
| (true, true, EdgeKind::Normal) => {}
|
2020-06-08 12:54:20 +00:00
|
|
|
// All other jumps are invalid
|
|
|
|
_ => {
|
|
|
|
self.fail(
|
|
|
|
location,
|
2020-06-09 10:21:36 +00:00
|
|
|
format!(
|
|
|
|
"{:?} edge to {:?} violates unwind invariants (cleanup {:?} -> {:?})",
|
|
|
|
edge_kind,
|
|
|
|
bb,
|
|
|
|
src.is_cleanup,
|
|
|
|
bb.is_cleanup,
|
|
|
|
)
|
2020-06-08 12:54:20 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-31 13:21:09 +00:00
|
|
|
self.fail(location, format!("encountered jump to invalid basic block {:?}", bb))
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-23 22:55:44 +00:00
|
|
|
|
2020-05-31 13:02:33 +00:00
|
|
|
/// Check if src can be assigned into dest.
|
|
|
|
/// This is not precise, it will accept some incorrect assignments.
|
|
|
|
fn mir_assign_valid_types(&self, src: Ty<'tcx>, dest: Ty<'tcx>) -> bool {
|
2020-06-22 09:07:39 +00:00
|
|
|
// Fast path before we normalize.
|
2020-05-31 13:02:33 +00:00
|
|
|
if src == dest {
|
|
|
|
// Equal types, all is good.
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-01 19:04:11 +00:00
|
|
|
// Normalize projections and things like that.
|
2020-06-06 09:45:19 +00:00
|
|
|
// FIXME: We need to reveal_all, as some optimizations change types in ways
|
2020-06-22 07:00:40 +00:00
|
|
|
// that require unfolding opaque types.
|
2020-07-22 05:13:42 +00:00
|
|
|
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
|
2020-06-06 09:45:19 +00:00
|
|
|
let src = self.tcx.normalize_erasing_regions(param_env, src);
|
|
|
|
let dest = self.tcx.normalize_erasing_regions(param_env, dest);
|
2020-05-30 21:46:21 +00:00
|
|
|
|
2020-06-21 08:04:12 +00:00
|
|
|
// Type-changing assignments can happen when subtyping is used. While
|
|
|
|
// all normal lifetimes are erased, higher-ranked types with their
|
|
|
|
// late-bound lifetimes are still around and can lead to type
|
2020-06-21 11:49:53 +00:00
|
|
|
// differences. So we compare ignoring lifetimes.
|
2020-06-22 07:17:33 +00:00
|
|
|
equal_up_to_regions(self.tcx, param_env, src, dest)
|
2020-05-31 13:02:33 +00:00
|
|
|
}
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|
|
|
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
|
|
|
|
// `Operand::Copy` is only supposed to be used with `Copy` types.
|
|
|
|
if let Operand::Copy(place) = operand {
|
|
|
|
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
|
2020-05-31 12:26:41 +00:00
|
|
|
let span = self.body.source_info(location).span;
|
2020-05-23 22:55:44 +00:00
|
|
|
|
2020-06-21 09:20:48 +00:00
|
|
|
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
|
2020-05-31 13:21:09 +00:00
|
|
|
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.super_operand(operand, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
2020-05-31 07:54:25 +00:00
|
|
|
match &statement.kind {
|
|
|
|
StatementKind::Assign(box (dest, rvalue)) => {
|
|
|
|
// LHS and RHS of the assignment must have the same type.
|
|
|
|
let left_ty = dest.ty(&self.body.local_decls, self.tcx).ty;
|
|
|
|
let right_ty = rvalue.ty(&self.body.local_decls, self.tcx);
|
2020-05-31 13:02:33 +00:00
|
|
|
if !self.mir_assign_valid_types(right_ty, left_ty) {
|
2020-05-31 07:54:25 +00:00
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
format!(
|
2020-08-14 16:01:14 +00:00
|
|
|
"encountered `{:?}` with incompatible types:\n\
|
2020-05-31 07:54:25 +00:00
|
|
|
left-hand side has type: {}\n\
|
|
|
|
right-hand side has type: {}",
|
2020-08-14 16:01:14 +00:00
|
|
|
statement.kind, left_ty, right_ty,
|
2020-05-31 07:54:25 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
match rvalue {
|
2020-08-14 16:01:14 +00:00
|
|
|
// The sides of an assignment must not alias. Currently this just checks whether the places
|
|
|
|
// are identical.
|
2020-05-31 07:54:25 +00:00
|
|
|
Rvalue::Use(Operand::Copy(src) | Operand::Move(src)) => {
|
|
|
|
if dest == src {
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
"encountered `Assign` statement with overlapping memory",
|
|
|
|
);
|
|
|
|
}
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
2020-08-14 16:01:14 +00:00
|
|
|
// The deaggregator currently does not deaggreagate arrays.
|
|
|
|
// So for now, we ignore them here.
|
|
|
|
Rvalue::Aggregate(box AggregateKind::Array { .. }, _) => {}
|
|
|
|
// All other aggregates must be gone after some phases.
|
|
|
|
Rvalue::Aggregate(box kind, _) => {
|
|
|
|
if self.mir_phase > MirPhase::DropLowering
|
|
|
|
&& !matches!(kind, AggregateKind::Generator(..))
|
|
|
|
{
|
|
|
|
// Generators persist until the state machine transformation, but all
|
|
|
|
// other aggregates must have been lowered.
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
format!("{:?} have been lowered to field assignments", rvalue),
|
|
|
|
)
|
|
|
|
} else if self.mir_phase > MirPhase::GeneratorLowering {
|
|
|
|
// No more aggregates after drop and generator lowering.
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
format!("{:?} have been lowered to field assignments", rvalue),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-09-10 00:00:00 +00:00
|
|
|
Rvalue::Ref(_, BorrowKind::Shallow, _) => {
|
|
|
|
if self.mir_phase > MirPhase::DropLowering {
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
"`Assign` statement with a `Shallow` borrow should have been removed after drop lowering phase",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 07:54:25 +00:00
|
|
|
_ => {}
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-10 00:00:00 +00:00
|
|
|
StatementKind::AscribeUserType(..) => {
|
|
|
|
if self.mir_phase > MirPhase::DropLowering {
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
"`AscribeUserType` should have been removed after drop lowering phase",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatementKind::FakeRead(..) => {
|
|
|
|
if self.mir_phase > MirPhase::DropLowering {
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
"`FakeRead` should have been removed after drop lowering phase",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 07:54:25 +00:00
|
|
|
_ => {}
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-31 07:52:51 +00:00
|
|
|
|
2020-05-31 13:21:09 +00:00
|
|
|
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
|
2020-05-31 07:52:51 +00:00
|
|
|
match &terminator.kind {
|
|
|
|
TerminatorKind::Goto { target } => {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
2020-06-21 16:24:51 +00:00
|
|
|
TerminatorKind::SwitchInt { targets, values, switch_ty, discr } => {
|
|
|
|
let ty = discr.ty(&self.body.local_decls, self.tcx);
|
|
|
|
if ty != *switch_ty {
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
format!(
|
|
|
|
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
|
2020-06-21 17:35:57 +00:00
|
|
|
ty, switch_ty,
|
2020-06-21 16:24:51 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-05-31 13:07:16 +00:00
|
|
|
if targets.len() != values.len() + 1 {
|
2020-05-31 07:52:51 +00:00
|
|
|
self.fail(
|
2020-05-31 13:21:09 +00:00
|
|
|
location,
|
2020-05-31 13:07:16 +00:00
|
|
|
format!(
|
|
|
|
"encountered `SwitchInt` terminator with {} values, but {} targets (should be values+1)",
|
|
|
|
values.len(),
|
|
|
|
targets.len(),
|
|
|
|
),
|
2020-05-31 07:52:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
for target in targets {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::Drop { target, unwind, .. } => {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
if let Some(unwind) = unwind {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *unwind, EdgeKind::Unwind);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::DropAndReplace { target, unwind, .. } => {
|
2020-08-14 16:01:14 +00:00
|
|
|
if self.mir_phase > MirPhase::DropLowering {
|
|
|
|
self.fail(
|
|
|
|
location,
|
|
|
|
"`DropAndReplace` is not permitted to exist after drop elaboration",
|
|
|
|
);
|
|
|
|
}
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
if let Some(unwind) = unwind {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *unwind, EdgeKind::Unwind);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::Call { func, destination, cleanup, .. } => {
|
|
|
|
let func_ty = func.ty(&self.body.local_decls, self.tcx);
|
2020-08-02 22:49:11 +00:00
|
|
|
match func_ty.kind() {
|
2020-05-31 07:52:51 +00:00
|
|
|
ty::FnPtr(..) | ty::FnDef(..) => {}
|
|
|
|
_ => self.fail(
|
2020-05-31 13:21:09 +00:00
|
|
|
location,
|
2020-05-31 07:52:51 +00:00
|
|
|
format!("encountered non-callable type {} in `Call` terminator", func_ty),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
if let Some((_, target)) = destination {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
if let Some(cleanup) = cleanup {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *cleanup, EdgeKind::Unwind);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::Assert { cond, target, cleanup, .. } => {
|
|
|
|
let cond_ty = cond.ty(&self.body.local_decls, self.tcx);
|
|
|
|
if cond_ty != self.tcx.types.bool {
|
|
|
|
self.fail(
|
2020-05-31 13:21:09 +00:00
|
|
|
location,
|
2020-05-31 07:52:51 +00:00
|
|
|
format!(
|
|
|
|
"encountered non-boolean condition of type {} in `Assert` terminator",
|
|
|
|
cond_ty
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
if let Some(cleanup) = cleanup {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *cleanup, EdgeKind::Unwind);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::Yield { resume, drop, .. } => {
|
2020-08-14 16:01:14 +00:00
|
|
|
if self.mir_phase > MirPhase::GeneratorLowering {
|
|
|
|
self.fail(location, "`Yield` should have been replaced by generator lowering");
|
|
|
|
}
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *resume, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
if let Some(drop) = drop {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *drop, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-02 07:15:24 +00:00
|
|
|
TerminatorKind::FalseEdge { real_target, imaginary_target } => {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *real_target, EdgeKind::Normal);
|
|
|
|
self.check_edge(location, *imaginary_target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
TerminatorKind::FalseUnwind { real_target, unwind } => {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *real_target, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
if let Some(unwind) = unwind {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *unwind, EdgeKind::Unwind);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::InlineAsm { destination, .. } => {
|
|
|
|
if let Some(destination) = destination {
|
2020-06-09 10:21:36 +00:00
|
|
|
self.check_edge(location, *destination, EdgeKind::Normal);
|
2020-05-31 07:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Nothing to validate for these.
|
|
|
|
TerminatorKind::Resume
|
|
|
|
| TerminatorKind::Abort
|
|
|
|
| TerminatorKind::Return
|
|
|
|
| TerminatorKind::Unreachable
|
|
|
|
| TerminatorKind::GeneratorDrop => {}
|
|
|
|
}
|
|
|
|
}
|
2020-05-23 22:55:44 +00:00
|
|
|
}
|