Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae0b24f

Browse files
tmiaskocuviper
authored andcommittedDec 1, 2023
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. (cherry picked from commit 5161b22)
1 parent 20b2dbf commit ae0b24f

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed
 

‎compiler/rustc_mir_transform/src/coroutine.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1153,18 +1153,9 @@ fn create_coroutine_drop_shim<'tcx>(
11531153
simplify::remove_dead_blocks(&mut body);
11541154

11551155
// Update the body's def to become the drop glue.
1156-
// This needs to be updated before the AbortUnwindingCalls pass.
11571156
let coroutine_instance = body.source.instance;
11581157
let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, None);
11591158
let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(coroutine_ty));
1160-
body.source.instance = drop_instance;
1161-
1162-
pm::run_passes_no_validate(
1163-
tcx,
1164-
&mut body,
1165-
&[&abort_unwinding_calls::AbortUnwindingCalls],
1166-
None,
1167-
);
11681159

11691160
// Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible
11701161
// 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)
Failed to load comments.