Skip to content

Commit 3eae123

Browse files
authored
Unrolled build for rust-lang#118422
Rollup merge of rust-lang#118422 - tmiasko:mix, r=compiler-errors Fix coroutine validation for mixed panic strategy Validation introduced in rust-lang#113124 allows `UnwindAction::Continue` and `TerminatorKind::Resume` to occur only in functions with ABI that can unwind. The function ABI depends on the panic strategy, which can vary across crates. Usually MIR is built and validated in the same crate. The coroutine drop glue thus far was an exception. As a result validation could fail when mixing different panic strategies. Avoid the problem by executing `AbortUnwindingCalls` along with the validation. Fixes rust-lang#116953.
2 parents e9b7bf0 + 5161b22 commit 3eae123

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
//! Otherwise it drops all the values in scope at the last suspension point.
5252
5353
use crate::abort_unwinding_calls;
54-
use crate::add_call_guards;
5554
use crate::deref_separator::deref_finder;
5655
use crate::errors;
5756
use crate::pass_manager as pm;
@@ -1168,18 +1167,9 @@ fn create_coroutine_drop_shim<'tcx>(
11681167
simplify::remove_dead_blocks(&mut body);
11691168

11701169
// Update the body's def to become the drop glue.
1171-
// This needs to be updated before the AbortUnwindingCalls pass.
11721170
let coroutine_instance = body.source.instance;
11731171
let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, None);
11741172
let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(coroutine_ty));
1175-
body.source.instance = drop_instance;
1176-
1177-
pm::run_passes_no_validate(
1178-
tcx,
1179-
&mut body,
1180-
&[&abort_unwinding_calls::AbortUnwindingCalls, &add_call_guards::CriticalCallEdges],
1181-
None,
1182-
);
11831173

11841174
// Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible
11851175
// filename.

compiler/rustc_mir_transform/src/shim.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
7474
let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args);
7575
debug!("make_shim({:?}) = {:?}", instance, body);
7676

77-
// Run empty passes to mark phase change and perform validation.
7877
pm::run_passes(
7978
tcx,
8079
&mut body,
81-
&[],
80+
&[
81+
&abort_unwinding_calls::AbortUnwindingCalls,
82+
&add_call_guards::CriticalCallEdges,
83+
],
8284
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
8385
);
8486

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: -Cpanic=unwind --crate-type=lib
2+
// no-prefer-dynamic
3+
// edition:2021
4+
5+
#![feature(coroutines)]
6+
pub fn run<T>(a: T) {
7+
let _ = move || {
8+
drop(a);
9+
yield;
10+
};
11+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Ensure that coroutine drop glue is valid when mixing different panic
2+
// strategies. Regression test for #116953.
3+
//
4+
// no-prefer-dynamic
5+
// build-pass
6+
// aux-build:unwind-aux.rs
7+
// compile-flags: -Cpanic=abort
8+
// needs-unwind
9+
extern crate unwind_aux;
10+
11+
pub fn main() {
12+
unwind_aux::run(String::new());
13+
}

0 commit comments

Comments
 (0)