From c8c964ad78da004d534a7e05d931a114f966fd77 Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Thu, 12 Mar 2020 11:54:19 +0000 Subject: [PATCH] Use the abort strategy when tracing. --- src/librustc_session/config.rs | 8 +++++++- src/test/run-make/yk-abort-strategy-std/Makefile | 7 +++++++ .../yk-abort-strategy-std/yk-abort-strategy-std.rs | 9 +++++++++ src/test/run-make/yk-abort-strategy/Makefile | 7 +++++++ src/test/run-make/yk-abort-strategy/yk-abort-strategy.rs | 9 +++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/test/run-make/yk-abort-strategy-std/Makefile create mode 100644 src/test/run-make/yk-abort-strategy-std/yk-abort-strategy-std.rs create mode 100644 src/test/run-make/yk-abort-strategy/Makefile create mode 100644 src/test/run-make/yk-abort-strategy/yk-abort-strategy.rs diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 34d79639dd3..47eb714a6b0 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -11,7 +11,7 @@ use crate::{early_error, early_warn, Session}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::impl_stable_hash_via_hash; -use rustc_target::spec::{Target, TargetTriple}; +use rustc_target::spec::{PanicStrategy, Target, TargetTriple}; use crate::parse::CrateConfig; use rustc_feature::UnstableFeatures; @@ -1754,6 +1754,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { early_error(error_format, &format!("optimisation cannot be enabled with a tracer")); } + // If a tracer is enabled, we use only the abort panic strategy. + if cg.tracer != TracerMode::Off { + cg.panic = Some(PanicStrategy::Abort); + debugging_opts.panic_abort_tests = true; + } + let cg = cg; // The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able diff --git a/src/test/run-make/yk-abort-strategy-std/Makefile b/src/test/run-make/yk-abort-strategy-std/Makefile new file mode 100644 index 00000000000..9f40bcb5fd0 --- /dev/null +++ b/src/test/run-make/yk-abort-strategy-std/Makefile @@ -0,0 +1,7 @@ +-include ../../run-make-fulldeps/tools.mk + +PROG=yk-abort-strategy-std + +all: + $(RUSTC) --emit mir ${PROG}.rs && grep 'resume;' ${TMPDIR}/${PROG}.mir + $(RUSTC) --emit mir -C tracer=hw ${PROG}.rs && grep 'resume;' ${TMPDIR}/${PROG}.mir; [ $$? -eq 1 ] diff --git a/src/test/run-make/yk-abort-strategy-std/yk-abort-strategy-std.rs b/src/test/run-make/yk-abort-strategy-std/yk-abort-strategy-std.rs new file mode 100644 index 00000000000..2498eb7cec9 --- /dev/null +++ b/src/test/run-make/yk-abort-strategy-std/yk-abort-strategy-std.rs @@ -0,0 +1,9 @@ +fn main() { + println!("{}", f(None)); +} + +#[inline(never)] +fn f(a: Option) -> String { + let s = String::from("hello"); + format!("{}{}", s, a.unwrap()) +} diff --git a/src/test/run-make/yk-abort-strategy/Makefile b/src/test/run-make/yk-abort-strategy/Makefile new file mode 100644 index 00000000000..b2c910f3d94 --- /dev/null +++ b/src/test/run-make/yk-abort-strategy/Makefile @@ -0,0 +1,7 @@ +-include ../../run-make-fulldeps/tools.mk + +PROG=yk-abort-strategy + +all: + $(RUSTC) --emit mir ${PROG}.rs && grep 'resume;' ${TMPDIR}/${PROG}.mir + $(RUSTC) --emit mir -C tracer=hw ${PROG}.rs && grep 'resume;' ${TMPDIR}/${PROG}.mir; [ $$? -eq 1 ] diff --git a/src/test/run-make/yk-abort-strategy/yk-abort-strategy.rs b/src/test/run-make/yk-abort-strategy/yk-abort-strategy.rs new file mode 100644 index 00000000000..5c9004f0881 --- /dev/null +++ b/src/test/run-make/yk-abort-strategy/yk-abort-strategy.rs @@ -0,0 +1,9 @@ +fn main() { + let s = String::from("hello"); + println!("{} {}", s, f(1)); +} + +#[inline(never)] +fn f(_a: usize) -> usize { + panic!(); +}