1
Fork 0

Handle panic runtime specially

This commit is contained in:
Gary Guo 2022-05-19 17:38:54 +01:00
parent 6ef2033884
commit 77fd0cc566
6 changed files with 20 additions and 17 deletions

View file

@ -366,14 +366,19 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
prev_name, cur_name prev_name, cur_name
)); ));
} }
panic_runtime = Some((cnum, tcx.panic_strategy(cnum).unwrap())); panic_runtime = Some((
cnum,
tcx.panic_strategy(cnum).unwrap_or_else(|| {
bug!("cannot determine panic strategy of a panic runtime");
}),
));
} }
} }
// If we found a panic runtime, then we know by this point that it's the // If we found a panic runtime, then we know by this point that it's the
// only one, but we perform validation here that all the panic strategy // only one, but we perform validation here that all the panic strategy
// compilation modes for the whole DAG are valid. // compilation modes for the whole DAG are valid.
if let Some((cnum, found_strategy)) = panic_runtime { if let Some((runtime_cnum, found_strategy)) = panic_runtime {
let desired_strategy = sess.panic_strategy(); let desired_strategy = sess.panic_strategy();
// First up, validate that our selected panic runtime is indeed exactly // First up, validate that our selected panic runtime is indeed exactly
@ -383,7 +388,7 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
"the linked panic runtime `{}` is \ "the linked panic runtime `{}` is \
not compiled with this crate's \ not compiled with this crate's \
panic strategy `{}`", panic strategy `{}`",
tcx.crate_name(cnum), tcx.crate_name(runtime_cnum),
desired_strategy.desc() desired_strategy.desc()
)); ));
} }
@ -397,7 +402,7 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
continue; continue;
} }
let cnum = CrateNum::new(i + 1); let cnum = CrateNum::new(i + 1);
if tcx.is_compiler_builtins(cnum) { if cnum == runtime_cnum || tcx.is_compiler_builtins(cnum) {
continue; continue;
} }

View file

@ -1,5 +1,5 @@
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::layout; use rustc_middle::ty::layout;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
@ -129,6 +129,10 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
} }
fn required_panic_strategy(tcx: TyCtxt<'_>, (): ()) -> Option<PanicStrategy> { fn required_panic_strategy(tcx: TyCtxt<'_>, (): ()) -> Option<PanicStrategy> {
if tcx.is_panic_runtime(LOCAL_CRATE) {
return Some(tcx.sess.panic_strategy());
}
if tcx.sess.panic_strategy() == PanicStrategy::Abort { if tcx.sess.panic_strategy() == PanicStrategy::Abort {
return Some(PanicStrategy::Abort); return Some(PanicStrategy::Abort);
} }

View file

@ -2,9 +2,7 @@ error: cannot link together two panic runtimes: panic_runtime_unwind and panic_r
error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind` error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind`
error: the crate `wants_panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind` error: the crate `wants_panic_runtime_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
error: the crate `panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind` error: aborting due to 3 previous errors
error: aborting due to 4 previous errors

View file

@ -1,6 +1,6 @@
// build-fail // build-fail
// needs-unwind // needs-unwind
// error-pattern:is incompatible with this crate's strategy of `unwind` // error-pattern:is not compiled with this crate's panic strategy `unwind`
// aux-build:panic-runtime-abort.rs // aux-build:panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs // aux-build:panic-runtime-lang-items.rs
// ignore-wasm32-bare compiled with panic=abort by default // ignore-wasm32-bare compiled with panic=abort by default

View file

@ -1,6 +1,4 @@
error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind` error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind`
error: the crate `panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind` error: aborting due to previous error
error: aborting due to 2 previous errors

View file

@ -1,8 +1,6 @@
error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind` error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind`
error: the crate `wants_panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind` error: the crate `wants_panic_runtime_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
error: the crate `panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind` error: aborting due to 2 previous errors
error: aborting due to 3 previous errors