Skip to content

Commit 1c4fd22

Browse files
committed
Strengthen cleanup to cleanup check
1 parent 4158bb0 commit 1c4fd22

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/librustc_mir/transform/validate.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::def_id::DefId;
1313

1414
enum EdgeKind {
1515
Unwind,
16-
Other,
16+
Normal,
1717
}
1818

1919
pub struct Validator {
@@ -59,11 +59,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5959
let src = self.body.basic_blocks().get(location.block).unwrap();
6060
match (src.is_cleanup, bb.is_cleanup, edge_kind) {
6161
// Non-cleanup blocks can jump to non-cleanup blocks along non-unwind edges
62-
(false, false, EdgeKind::Other)
62+
(false, false, EdgeKind::Normal)
6363
// Non-cleanup blocks can jump to cleanup blocks along unwind edges
6464
| (false, true, EdgeKind::Unwind)
65-
// Cleanup blocks can jump to cleanup blocks along any edges
66-
| (true, true, _) => {}
65+
// Cleanup blocks can jump to cleanup blocks along non-unwind edges
66+
| (true, true, EdgeKind::Normal) => {}
6767
// All other jumps are invalid
6868
_ => {
6969
self.fail(
@@ -114,7 +114,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
114114
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
115115
match &terminator.kind {
116116
TerminatorKind::Goto { target } => {
117-
self.check_bb(location, *target, EdgeKind::Other);
117+
self.check_bb(location, *target, EdgeKind::Normal);
118118
}
119119
TerminatorKind::SwitchInt { targets, values, .. } => {
120120
if targets.len() != values.len() + 1 {
@@ -128,17 +128,17 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
128128
);
129129
}
130130
for target in targets {
131-
self.check_bb(location, *target, EdgeKind::Other);
131+
self.check_bb(location, *target, EdgeKind::Normal);
132132
}
133133
}
134134
TerminatorKind::Drop { target, unwind, .. } => {
135-
self.check_bb(location, *target, EdgeKind::Other);
135+
self.check_bb(location, *target, EdgeKind::Normal);
136136
if let Some(unwind) = unwind {
137137
self.check_bb(location, *unwind, EdgeKind::Unwind);
138138
}
139139
}
140140
TerminatorKind::DropAndReplace { target, unwind, .. } => {
141-
self.check_bb(location, *target, EdgeKind::Other);
141+
self.check_bb(location, *target, EdgeKind::Normal);
142142
if let Some(unwind) = unwind {
143143
self.check_bb(location, *unwind, EdgeKind::Unwind);
144144
}
@@ -153,7 +153,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
153153
),
154154
}
155155
if let Some((_, target)) = destination {
156-
self.check_bb(location, *target, EdgeKind::Other);
156+
self.check_bb(location, *target, EdgeKind::Normal);
157157
}
158158
if let Some(cleanup) = cleanup {
159159
self.check_bb(location, *cleanup, EdgeKind::Unwind);
@@ -170,30 +170,30 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
170170
),
171171
);
172172
}
173-
self.check_bb(location, *target, EdgeKind::Other);
173+
self.check_bb(location, *target, EdgeKind::Normal);
174174
if let Some(cleanup) = cleanup {
175175
self.check_bb(location, *cleanup, EdgeKind::Unwind);
176176
}
177177
}
178178
TerminatorKind::Yield { resume, drop, .. } => {
179-
self.check_bb(location, *resume, EdgeKind::Other);
179+
self.check_bb(location, *resume, EdgeKind::Normal);
180180
if let Some(drop) = drop {
181-
self.check_bb(location, *drop, EdgeKind::Other);
181+
self.check_bb(location, *drop, EdgeKind::Normal);
182182
}
183183
}
184184
TerminatorKind::FalseEdge { real_target, imaginary_target } => {
185-
self.check_bb(location, *real_target, EdgeKind::Other);
186-
self.check_bb(location, *imaginary_target, EdgeKind::Other);
185+
self.check_bb(location, *real_target, EdgeKind::Normal);
186+
self.check_bb(location, *imaginary_target, EdgeKind::Normal);
187187
}
188188
TerminatorKind::FalseUnwind { real_target, unwind } => {
189-
self.check_bb(location, *real_target, EdgeKind::Other);
189+
self.check_bb(location, *real_target, EdgeKind::Normal);
190190
if let Some(unwind) = unwind {
191191
self.check_bb(location, *unwind, EdgeKind::Unwind);
192192
}
193193
}
194194
TerminatorKind::InlineAsm { destination, .. } => {
195195
if let Some(destination) = destination {
196-
self.check_bb(location, *destination, EdgeKind::Other);
196+
self.check_bb(location, *destination, EdgeKind::Normal);
197197
}
198198
}
199199
// Nothing to validate for these.

0 commit comments

Comments
 (0)