Skip to content

Commit 577f1d0

Browse files
authored
Rollup merge of #84734 - tmandry:compiletest-needs-unwind, r=Mark-Simulacrum
Add `needs-unwind` and beginning of support for testing `panic=abort` std to compiletest For the Fuchsia platform we build libstd with `panic=abort` and would like a way to run tests with that enabled. This adds low-level support for this directly to compiletest. In the future I'd like to add high-level support in rustbuild, e.g. having target-specific flags that allow configuring a panic strategy. (Side note: It would be nice if we could also build multiple configurations for the same target, but I'm getting ahead of myself.) This plus #84500 have everything that's needed to get ui tests passing on fuchsia targets. Part of #84766. Note that this change only includes the header on tests which need an unwinder to _build_, not those which need it to _run_. r? ````@Mark-Simulacrum````
2 parents 3a0d6be + 947ad58 commit 577f1d0

17 files changed

+44
-8
lines changed

src/test/ui/cfg/cfg-panic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// build-pass
22
// compile-flags: -C panic=unwind
3+
// needs-unwind
34
// ignore-emscripten no panic_unwind implementation
45
// ignore-wasm32 no panic_unwind implementation
56
// ignore-wasm64 no panic_unwind implementation

src/test/ui/intrinsics/intrinsic-alignment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod rusti {
1414
target_os = "dragonfly",
1515
target_os = "emscripten",
1616
target_os = "freebsd",
17+
target_os = "fuchsia",
1718
target_os = "linux",
1819
target_os = "macos",
1920
target_os = "netbsd",

src/test/ui/issues/issue-70093.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22
// compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes
33
// ignore-windows - this will probably only work on unixish systems
4+
// ignore-fuchsia - missing __libc_start_main for some reason (#84733)
45

56
#[link(name = "some-random-non-existent-library", kind = "static")]
67
extern "C" {}

src/test/ui/panic-handler/weak-lang-item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// aux-build:weak-lang-items.rs
22
// error-pattern: `#[panic_handler]` function required, but not found
33
// error-pattern: language item required, but not found: `eh_personality`
4+
// needs-unwind since it affects the error output
45
// ignore-emscripten compiled with panic=abort, personality not required
56

67
#![no_std]

src/test/ui/panic-handler/weak-lang-item.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0259]: the name `core` is defined multiple times
2-
--> $DIR/weak-lang-item.rs:8:1
2+
--> $DIR/weak-lang-item.rs:9:1
33
|
44
LL | extern crate core;
55
| ^^^^^^^^^^^^^^^^^^ `core` reimported here

src/test/ui/panic-runtime/abort-link-to-unwind-dylib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// build-fail
22
// compile-flags:-C panic=abort -C prefer-dynamic
3+
// needs-unwind
34
// ignore-musl - no dylibs here
45
// ignore-emscripten
56
// ignore-sgx no dynamic lib support

src/test/ui/panic-runtime/lto-unwind.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(unused_variables)]
33

44
// compile-flags:-C lto -C panic=unwind
5+
// needs-unwind
56
// no-prefer-dynamic
67
// ignore-emscripten no processes
78
// ignore-sgx no processes

src/test/ui/panic-runtime/transitive-link-a-bunch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-fail
2+
// needs-unwind
23
// aux-build:panic-runtime-unwind.rs
34
// aux-build:panic-runtime-abort.rs
45
// aux-build:wants-panic-runtime-unwind.rs

src/test/ui/panic-runtime/want-unwind-got-abort.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-fail
2+
// needs-unwind
23
// error-pattern:is incompatible with this crate's strategy of `unwind`
34
// aux-build:panic-runtime-abort.rs
45
// aux-build:panic-runtime-lang-items.rs

src/test/ui/panic-runtime/want-unwind-got-abort2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-fail
2+
// needs-unwind
23
// error-pattern:is incompatible with this crate's strategy of `unwind`
34
// aux-build:panic-runtime-abort.rs
45
// aux-build:wants-panic-runtime-abort.rs

src/test/ui/structs-enums/rec-align-u64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct Outer {
3535
target_os = "dragonfly",
3636
target_os = "emscripten",
3737
target_os = "freebsd",
38+
target_os = "fuchsia",
3839
target_os = "linux",
3940
target_os = "macos",
4041
target_os = "netbsd",

src/test/ui/test-panic-abort-disabled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// error-pattern:building tests with panic=abort is not supported
22
// no-prefer-dynamic
3-
// compile-flags: --test -Cpanic=abort
3+
// compile-flags: --test -Cpanic=abort -Zpanic-abort-tests=no
44
// run-flags: --test-threads=1
55

66
// ignore-wasm no panic or subprocess support

src/test/ui/unwind-no-uwtable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-pass
2+
// needs-unwind
23
// ignore-windows target requires uwtable
34
// ignore-wasm32-bare no proper panic=unwind support
45
// compile-flags: -C panic=unwind -C force-unwind-tables=n

src/test/ui/x86stdcall.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn main() {
2727
target_os = "dragonfly",
2828
target_os = "emscripten",
2929
target_os = "freebsd",
30+
target_os = "fuchsia",
3031
target_os = "linux",
3132
target_os = "macos",
3233
target_os = "netbsd",

src/tools/compiletest/src/common.rs

+10
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ impl fmt::Display for Debugger {
171171
}
172172
}
173173

174+
#[derive(Clone, Copy, Debug, PartialEq)]
175+
pub enum PanicStrategy {
176+
Unwind,
177+
Abort,
178+
}
179+
174180
/// Configuration for compiletest
175181
#[derive(Debug, Clone)]
176182
pub struct Config {
@@ -265,6 +271,10 @@ pub struct Config {
265271
/// Flags to pass to the compiler when building for the target
266272
pub target_rustcflags: Option<String>,
267273

274+
/// What panic strategy the target is built with. Unwind supports Abort, but
275+
/// not vice versa.
276+
pub target_panic: PanicStrategy,
277+
268278
/// Target system to be tested
269279
pub target: String,
270280

src/tools/compiletest/src/header.rs

+7-1
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, PassMode};
10+
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PanicStrategy, PassMode};
1111
use crate::util;
1212
use crate::{extract_cdb_version, extract_gdb_version};
1313

@@ -115,6 +115,12 @@ impl EarlyProps {
115115
props.ignore = true;
116116
}
117117

118+
if config.target_panic == PanicStrategy::Abort
119+
&& config.parse_name_directive(ln, "needs-unwind")
120+
{
121+
props.ignore = true;
122+
}
123+
118124
if config.target == "wasm32-unknown-unknown" && config.parse_check_run_results(ln) {
119125
props.ignore = true;
120126
}

src/tools/compiletest/src/main.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
extern crate test;
77

8-
use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
8+
use crate::common::{
9+
expected_output_path, output_base_dir, output_relative_path, PanicStrategy, UI_EXTENSIONS,
10+
};
911
use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, Pretty, TestPaths};
1012
use crate::util::logv;
1113
use getopts::Options;
@@ -97,8 +99,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
9799
(eg. emulator, valgrind)",
98100
"PROGRAM",
99101
)
100-
.optopt("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
101-
.optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
102+
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
103+
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
104+
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
102105
.optflag("", "verbose", "run tests verbosely, showing all output")
103106
.optflag(
104107
"",
@@ -243,8 +246,13 @@ pub fn parse_config(args: Vec<String>) -> Config {
243246
}),
244247
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
245248
runtool: matches.opt_str("runtool"),
246-
host_rustcflags: matches.opt_str("host-rustcflags"),
247-
target_rustcflags: matches.opt_str("target-rustcflags"),
249+
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
250+
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
251+
target_panic: match matches.opt_str("target-panic").as_deref() {
252+
Some("unwind") | None => PanicStrategy::Unwind,
253+
Some("abort") => PanicStrategy::Abort,
254+
_ => panic!("unknown `--target-panic` option `{}` given", mode),
255+
},
248256
target,
249257
host: opt_str2(matches.opt_str("host")),
250258
cdb,

0 commit comments

Comments
 (0)