Auto merge of #97103 - luqmana:asm-unwind-cleanup, r=Amanieu,tmiasko

Update MIR passes to handle unwinding Inline Asm

Some more follow up fixes from https://github.com/rust-lang/rust/pull/95864#issuecomment-1094165398

r? `@Amanieu`
This commit is contained in:
bors 2022-05-19 06:57:59 +00:00
commit 67a9bcb31b
4 changed files with 49 additions and 2 deletions

View file

@ -1,4 +1,5 @@
use crate::MirPass;
use rustc_ast::InlineAsmOptions;
use rustc_hir::def::DefKind;
use rustc_middle::mir::*;
use rustc_middle::ty::layout;
@ -85,6 +86,12 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
TerminatorKind::Assert { .. } | TerminatorKind::FalseUnwind { .. } => {
layout::fn_can_unwind(tcx, None, Abi::Rust)
}
TerminatorKind::InlineAsm { options, .. } => {
options.contains(InlineAsmOptions::MAY_UNWIND)
}
_ if terminator.unwind().is_some() => {
span_bug!(span, "unexpected terminator that may unwind {:?}", terminator)
}
_ => continue,
};

View file

@ -1042,8 +1042,7 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool {
| TerminatorKind::Unreachable
| TerminatorKind::GeneratorDrop
| TerminatorKind::FalseEdge { .. }
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::InlineAsm { .. } => {}
| TerminatorKind::FalseUnwind { .. } => {}
// Resume will *continue* unwinding, but if there's no other unwinding terminator it
// will never be reached.
@ -1057,6 +1056,7 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool {
TerminatorKind::Drop { .. }
| TerminatorKind::DropAndReplace { .. }
| TerminatorKind::Call { .. }
| TerminatorKind::InlineAsm { .. }
| TerminatorKind::Assert { .. } => return true,
}
}