1
Fork 0

Address review feedback

This commit is contained in:
Gary Guo 2022-11-15 17:00:40 +00:00
parent e3f2edc75b
commit 3af45d6c57
7 changed files with 40 additions and 31 deletions

View file

@ -13,7 +13,7 @@ pub struct MirPatch<'tcx> {
new_locals: Vec<LocalDecl<'tcx>>,
resume_block: Option<BasicBlock>,
// Only for unreachable in cleanup path.
unreachable_block: Option<BasicBlock>,
unreachable_cleanup_block: Option<BasicBlock>,
terminate_block: Option<BasicBlock>,
body_span: Span,
next_local: usize,
@ -28,7 +28,7 @@ impl<'tcx> MirPatch<'tcx> {
new_locals: vec![],
next_local: body.local_decls.len(),
resume_block: None,
unreachable_block: None,
unreachable_cleanup_block: None,
terminate_block: None,
body_span: body.span,
};
@ -41,8 +41,11 @@ impl<'tcx> MirPatch<'tcx> {
}
// Check if we already have an unreachable block
if let TerminatorKind::Unreachable = block.terminator().kind && block.statements.is_empty() {
result.unreachable_block = Some(bb);
if let TerminatorKind::Unreachable = block.terminator().kind
&& block.statements.is_empty()
&& block.is_cleanup
{
result.unreachable_cleanup_block = Some(bb);
continue;
}
@ -73,8 +76,8 @@ impl<'tcx> MirPatch<'tcx> {
bb
}
pub fn unreachable_block(&mut self) -> BasicBlock {
if let Some(bb) = self.unreachable_block {
pub fn unreachable_cleanup_block(&mut self) -> BasicBlock {
if let Some(bb) = self.unreachable_cleanup_block {
return bb;
}
@ -86,7 +89,7 @@ impl<'tcx> MirPatch<'tcx> {
}),
is_cleanup: true,
});
self.unreachable_block = Some(bb);
self.unreachable_cleanup_block = Some(bb);
bb
}

View file

@ -523,7 +523,7 @@ pub struct CopyNonOverlapping<'tcx> {
/// The basic block pointed to by a `Cleanup` unwind action must have its `cleanup` flag set.
/// `cleanup` basic blocks have a couple restrictions:
/// 1. All `unwind` fields in them must be `UnwindAction::Terminate` or `UnwindAction::Unreachable`.
/// 2. `Return` terminators are not allowed in them. `Terminate` and `Unwind` terminators are.
/// 2. `Return` terminators are not allowed in them. `Terminate` and `Resume` terminators are.
/// 3. All other basic blocks (in the current body) that are reachable from `cleanup` basic blocks
/// must also be `cleanup`. This is a part of the type system and checked statically, so it is
/// still an error to have such an edge in the CFG even if it's known that it won't be taken at
@ -721,8 +721,6 @@ pub enum TerminatorKind<'tcx> {
/// consider it in borrowck. We don't want to accept programs which
/// pass borrowck only when `panic=abort` or some assertions are disabled
/// due to release vs. debug mode builds.
/// This field does not necessary have to be `UnwindAction::Cleanup` because
/// of the `remove_noop_landing_pads` and `abort_unwinding_calls` passes.
unwind: UnwindAction,
},