Skip to content

Commit 03f350f

Browse files
committed
Clarify some cleanup stuff.
- Rearrange the match in `llbb_with_landing_pad` so the `(Some,Some)` cases are together. - Add assertions to indicate two MSVC-only paths.
1 parent a5bd5da commit 03f350f

File tree

1 file changed

+10
-6
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+10
-6
lines changed

Diff for: compiler/rustc_codegen_ssa/src/mir/block.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
7575
let target_funclet = fx.cleanup_kinds[target].funclet_bb(target);
7676
match (self.funclet_bb, target_funclet) {
7777
(None, None) => (lltarget, false),
78-
(Some(f), Some(t_f)) if f == t_f || !base::wants_msvc_seh(fx.cx.tcx().sess) => {
79-
(lltarget, false)
80-
}
8178
// jump *into* cleanup - need a landing pad if GNU, cleanup pad if MSVC
8279
(None, Some(_)) => (fx.landing_pad_for(target), false),
8380
(Some(_), None) => span_bug!(span, "{:?} - jump out of cleanup?", self.terminator),
84-
(Some(_), Some(_)) => (fx.landing_pad_for(target), true),
81+
(Some(f), Some(t_f)) => {
82+
if f == t_f || !base::wants_msvc_seh(fx.cx.tcx().sess) {
83+
(lltarget, false)
84+
} else {
85+
(fx.landing_pad_for(target), true)
86+
}
87+
}
8588
}
8689
}
8790

@@ -95,7 +98,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
9598
let (lltarget, is_cleanupret) = self.llbb_with_landing_pad(fx, target);
9699
if is_cleanupret {
97100
// MSVC cross-funclet jump - need a trampoline
98-
101+
debug_assert!(base::wants_msvc_seh(fx.cx.tcx().sess));
99102
debug!("llbb_with_cleanup: creating cleanup trampoline for {:?}", target);
100103
let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
101104
let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);
@@ -115,8 +118,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
115118
) {
116119
let (lltarget, is_cleanupret) = self.llbb_with_landing_pad(fx, target);
117120
if is_cleanupret {
118-
// micro-optimization: generate a `ret` rather than a jump
121+
// MSVC micro-optimization: generate a `ret` rather than a jump
119122
// to a trampoline.
123+
debug_assert!(base::wants_msvc_seh(fx.cx.tcx().sess));
120124
bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
121125
} else {
122126
bx.br(lltarget);

0 commit comments

Comments
 (0)