Skip to content

Commit fdd15b1

Browse files
committed
Detect panic strategy using rustc --print cfg
Instead of relying on a command line parameter, detect if a target is able to unwind or not. Ignore tests that require unwinding on targets that don't support it.
1 parent 3e50038 commit fdd15b1

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@ pub struct Config {
278278
/// override this setting.
279279
pub optimize_tests: bool,
280280

281-
/// What panic strategy the target is built with. Unwind supports Abort, but
282-
/// not vice versa.
283-
pub target_panic: PanicStrategy,
284-
285281
/// Target system to be tested
286282
pub target: String,
287283

@@ -426,6 +422,10 @@ impl Config {
426422
*&self.target_cfg().pointer_width
427423
}
428424

425+
pub fn can_unwind(&self) -> bool {
426+
self.target_cfg().panic == PanicStrategy::Unwind
427+
}
428+
429429
pub fn has_asm_support(&self) -> bool {
430430
static ASM_SUPPORTED_ARCHS: &[&str] = &[
431431
"x86", "x86_64", "arm", "aarch64", "riscv32",
@@ -446,6 +446,7 @@ pub struct TargetCfg {
446446
families: Vec<String>,
447447
pointer_width: u32,
448448
endian: Endian,
449+
panic: PanicStrategy,
449450
}
450451

451452
#[derive(Eq, PartialEq, Clone, Debug)]
@@ -481,6 +482,7 @@ impl TargetCfg {
481482
let mut families = Vec::new();
482483
let mut pointer_width = None;
483484
let mut endian = None;
485+
let mut panic = None;
484486
for line in print_cfg.lines() {
485487
if let Some((name, value)) = line.split_once('=') {
486488
let value = value.trim_matches('"');
@@ -498,6 +500,13 @@ impl TargetCfg {
498500
s => panic!("unexpected {s}"),
499501
})
500502
}
503+
"panic" => {
504+
panic = match value {
505+
"abort" => Some(PanicStrategy::Abort),
506+
"unwind" => Some(PanicStrategy::Unwind),
507+
s => panic!("unexpected {s}"),
508+
}
509+
}
501510
_ => {}
502511
}
503512
}
@@ -510,6 +519,7 @@ impl TargetCfg {
510519
families,
511520
pointer_width: pointer_width.unwrap(),
512521
endian: endian.unwrap(),
522+
panic: panic.unwrap(),
513523
}
514524
}
515525
}

src/tools/compiletest/src/header.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
77

88
use tracing::*;
99

10-
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PanicStrategy, PassMode};
10+
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
1111
use crate::util;
1212
use crate::{extract_cdb_version, extract_gdb_version};
1313

@@ -949,8 +949,7 @@ pub fn make_test_description<R: Read>(
949949
ignore |= !has_memtag && config.parse_name_directive(ln, "needs-sanitizer-memtag");
950950
ignore |= !has_shadow_call_stack
951951
&& config.parse_name_directive(ln, "needs-sanitizer-shadow-call-stack");
952-
ignore |= config.target_panic == PanicStrategy::Abort
953-
&& config.parse_name_directive(ln, "needs-unwind");
952+
ignore |= !config.can_unwind() && config.parse_name_directive(ln, "needs-unwind");
954953
ignore |= config.target == "wasm32-unknown-unknown"
955954
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS);
956955
ignore |= config.debugger == Some(Debugger::Cdb) && ignore_cdb(config, ln);

src/tools/compiletest/src/main.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
extern crate test;
77

8-
use crate::common::{
9-
expected_output_path, output_base_dir, output_relative_path, PanicStrategy, UI_EXTENSIONS,
10-
};
8+
use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
119
use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, TestPaths};
1210
use crate::util::logv;
1311
use getopts::Options;
@@ -105,7 +103,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
105103
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
106104
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
107105
.optflag("", "optimize-tests", "run tests with optimizations enabled")
108-
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
109106
.optflag("", "verbose", "run tests verbosely, showing all output")
110107
.optflag(
111108
"",
@@ -258,11 +255,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
258255
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
259256
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
260257
optimize_tests: matches.opt_present("optimize-tests"),
261-
target_panic: match matches.opt_str("target-panic").as_deref() {
262-
Some("unwind") | None => PanicStrategy::Unwind,
263-
Some("abort") => PanicStrategy::Abort,
264-
_ => panic!("unknown `--target-panic` option `{}` given", mode),
265-
},
266258
target,
267259
host: opt_str2(matches.opt_str("host")),
268260
cdb,

0 commit comments

Comments
 (0)