Strengthen cleanup to cleanup check

This commit is contained in:
Nathan Corbyn 2020-06-08 16:04:41 +01:00
parent 4158bb0f0b
commit 1c4fd22618

View File

@ -13,7 +13,7 @@
enum EdgeKind {
Unwind,
Other,
Normal,
}
pub struct Validator {
@ -59,11 +59,11 @@ fn check_bb(&self, location: Location, bb: BasicBlock, edge_kind: EdgeKind) {
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
(false, false, EdgeKind::Other)
(false, false, EdgeKind::Normal)
// Non-cleanup blocks can jump to cleanup blocks along unwind edges
| (false, true, EdgeKind::Unwind)
// Cleanup blocks can jump to cleanup blocks along any edges
| (true, true, _) => {}
// Cleanup blocks can jump to cleanup blocks along non-unwind edges
| (true, true, EdgeKind::Normal) => {}
// All other jumps are invalid
_ => {
self.fail(
@ -114,7 +114,7 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
match &terminator.kind {
TerminatorKind::Goto { target } => {
self.check_bb(location, *target, EdgeKind::Other);
self.check_bb(location, *target, EdgeKind::Normal);
}
TerminatorKind::SwitchInt { targets, values, .. } => {
if targets.len() != values.len() + 1 {
@ -128,17 +128,17 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
);
}
for target in targets {
self.check_bb(location, *target, EdgeKind::Other);
self.check_bb(location, *target, EdgeKind::Normal);
}
}
TerminatorKind::Drop { target, unwind, .. } => {
self.check_bb(location, *target, EdgeKind::Other);
self.check_bb(location, *target, EdgeKind::Normal);
if let Some(unwind) = unwind {
self.check_bb(location, *unwind, EdgeKind::Unwind);
}
}
TerminatorKind::DropAndReplace { target, unwind, .. } => {
self.check_bb(location, *target, EdgeKind::Other);
self.check_bb(location, *target, EdgeKind::Normal);
if let Some(unwind) = unwind {
self.check_bb(location, *unwind, EdgeKind::Unwind);
}
@ -153,7 +153,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
),
}
if let Some((_, target)) = destination {
self.check_bb(location, *target, EdgeKind::Other);
self.check_bb(location, *target, EdgeKind::Normal);
}
if let Some(cleanup) = cleanup {
self.check_bb(location, *cleanup, EdgeKind::Unwind);
@ -170,30 +170,30 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
),
);
}
self.check_bb(location, *target, EdgeKind::Other);
self.check_bb(location, *target, EdgeKind::Normal);
if let Some(cleanup) = cleanup {
self.check_bb(location, *cleanup, EdgeKind::Unwind);
}
}
TerminatorKind::Yield { resume, drop, .. } => {
self.check_bb(location, *resume, EdgeKind::Other);
self.check_bb(location, *resume, EdgeKind::Normal);
if let Some(drop) = drop {
self.check_bb(location, *drop, EdgeKind::Other);
self.check_bb(location, *drop, EdgeKind::Normal);
}
}
TerminatorKind::FalseEdge { real_target, imaginary_target } => {
self.check_bb(location, *real_target, EdgeKind::Other);
self.check_bb(location, *imaginary_target, EdgeKind::Other);
self.check_bb(location, *real_target, EdgeKind::Normal);
self.check_bb(location, *imaginary_target, EdgeKind::Normal);
}
TerminatorKind::FalseUnwind { real_target, unwind } => {
self.check_bb(location, *real_target, EdgeKind::Other);
self.check_bb(location, *real_target, EdgeKind::Normal);
if let Some(unwind) = unwind {
self.check_bb(location, *unwind, EdgeKind::Unwind);
}
}
TerminatorKind::InlineAsm { destination, .. } => {
if let Some(destination) = destination {
self.check_bb(location, *destination, EdgeKind::Other);
self.check_bb(location, *destination, EdgeKind::Normal);
}
}
// Nothing to validate for these.