Skip to content

Commit 0851036

Browse files
authoredJun 19, 2020
Rollup merge of #73044 - tmiasko:compiletest-san, r=nikomatsakis
compiletest: Add directives to detect sanitizer support Add needs-sanitizer-{address,leak,memory,thread} directive indicating that test requires target with support for specific sanitizer. This is an addition to the existing needs-sanitizer-support directive indicating that test requires a sanitizer runtime library. The existing needs-sanitizer-support directive could be incorporated into the new ones, but I decided to retain it, since it enables running sanitizer codegen tests even when building of sanitizer runtime libraries is disabled.
2 parents 1dc6c3c + d40e624 commit 0851036

20 files changed

+75
-30
lines changed
 

‎src/test/codegen/sanitizer-memory-track-orgins.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Verifies that MemorySanitizer track-origins level can be controlled
22
// with -Zsanitizer-memory-track-origins option.
33
//
4-
// needs-sanitizer-support
5-
// only-linux
6-
// only-x86_64
4+
// needs-sanitizer-memory
75
// revisions:MSAN-0 MSAN-1 MSAN-2 MSAN-1-LTO MSAN-2-LTO
86
//
97
//[MSAN-0] compile-flags: -Zsanitizer=memory

‎src/test/codegen/sanitizer-no-sanitize-inlining.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Verifies that no_sanitize attribute prevents inlining when
22
// given sanitizer is enabled, but has no effect on inlining otherwise.
33
//
4-
// needs-sanitizer-support
5-
// only-x86_64
6-
//
4+
// needs-sanitizer-address
5+
// needs-sanitizer-leak
76
// revisions: ASAN LSAN
8-
//
97
//[ASAN] compile-flags: -Zsanitizer=address -C opt-level=3 -Z mir-opt-level=3
108
//[LSAN] compile-flags: -Zsanitizer=leak -C opt-level=3 -Z mir-opt-level=3
119

‎src/test/codegen/sanitizer-no-sanitize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Verifies that no_sanitze attribute can be used to
22
// selectively disable sanitizer instrumentation.
33
//
4-
// needs-sanitizer-support
4+
// needs-sanitizer-address
55
// compile-flags: -Zsanitizer=address
66

77
#![crate_type="lib"]

‎src/test/codegen/sanitizer-recover.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Verifies that AddressSanitizer and MemorySanitizer
22
// recovery mode can be enabled with -Zsanitizer-recover.
33
//
4-
// needs-sanitizer-support
5-
// only-linux
6-
// only-x86_64
4+
// needs-sanitizer-address
5+
// needs-sanitizer-memory
76
// revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER MSAN-RECOVER-LTO
87
// no-prefer-dynamic
98
//

‎src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# needs-sanitizer-support
2-
# only-x86_64
2+
# needs-sanitizer-address
33
# only-linux
44

55
-include ../tools.mk

‎src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# needs-sanitizer-support
2-
# only-x86_64
2+
# needs-sanitizer-address
33
# only-linux
44

55
-include ../tools.mk

‎src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# needs-sanitizer-support
2-
# only-x86_64
2+
# needs-sanitizer-address
33
# only-linux
44

55
-include ../tools.mk

‎src/test/rustdoc/sanitizer-option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// needs-sanitizer-support
2+
// needs-sanitizer-address
23
// compile-flags: --test -Z sanitizer=address
34
//
45
// #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern

‎src/test/ui/sanitize/address.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// needs-sanitizer-support
2-
// only-x86_64
2+
// needs-sanitizer-address
33
//
44
// compile-flags: -Z sanitizer=address -O -g
55
//

‎src/test/ui/sanitize/badfree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// needs-sanitizer-support
2-
// only-x86_64
2+
// needs-sanitizer-address
33
//
44
// compile-flags: -Z sanitizer=address -O
55
//

‎src/test/ui/sanitize/cfg.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// the `#[cfg(sanitize = "option")]` attribute is configured.
33

44
// needs-sanitizer-support
5-
// only-linux
6-
// only-x86_64
5+
// needs-sanitizer-address
6+
// needs-sanitizer-leak
7+
// needs-sanitizer-memory
8+
// needs-sanitizer-thread
79
// check-pass
810
// revisions: address leak memory thread
911
//[address]compile-flags: -Zsanitizer=address --cfg address

‎src/test/ui/sanitize/issue-72154-lifetime-markers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// miscompilation which was subsequently detected by AddressSanitizer as UB.
55
//
66
// needs-sanitizer-support
7-
// only-x86_64
7+
// needs-sanitizer-address
88
//
99
// compile-flags: -Copt-level=0 -Zsanitizer=address
1010
// run-pass

‎src/test/ui/sanitize/leak.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// needs-sanitizer-support
2-
// only-x86_64
2+
// needs-sanitizer-leak
33
//
44
// compile-flags: -Z sanitizer=leak -O
55
//

‎src/test/ui/sanitize/memory.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// needs-sanitizer-support
2-
// only-linux
3-
// only-x86_64
2+
// needs-sanitizer-memory
43
//
54
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
65
//

‎src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// min-llvm-version 9.0
66
// needs-sanitizer-support
7-
// only-x86_64
7+
// needs-sanitizer-address
88
//
99
// no-prefer-dynamic
1010
// revisions: opt0 opt1

‎src/test/ui/sanitize/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// would occasionally fail, making test flaky.
1212
//
1313
// needs-sanitizer-support
14-
// only-x86_64
14+
// needs-sanitizer-thread
1515
//
1616
// compile-flags: -Z sanitizer=thread -O
1717
//

‎src/test/ui/sanitize/use-after-scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// needs-sanitizer-support
2-
// only-x86_64
2+
// needs-sanitizer-address
33
//
44
// compile-flags: -Zsanitizer=address
55
// run-fail

‎src/tools/compiletest/src/header.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl EarlyProps {
4343
let mut props = EarlyProps::default();
4444
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
4545
let rustc_has_sanitizer_support = env::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
46+
let has_asan = util::ASAN_SUPPORTED_TARGETS.contains(&&*config.target);
47+
let has_lsan = util::LSAN_SUPPORTED_TARGETS.contains(&&*config.target);
48+
let has_msan = util::MSAN_SUPPORTED_TARGETS.contains(&&*config.target);
49+
let has_tsan = util::TSAN_SUPPORTED_TARGETS.contains(&&*config.target);
4650

4751
iter_header(testfile, None, rdr, &mut |ln| {
4852
// we should check if any only-<platform> exists and if it exists
@@ -74,7 +78,25 @@ impl EarlyProps {
7478
props.ignore = true;
7579
}
7680

77-
if !rustc_has_sanitizer_support && config.parse_needs_sanitizer_support(ln) {
81+
if !rustc_has_sanitizer_support
82+
&& config.parse_name_directive(ln, "needs-sanitizer-support")
83+
{
84+
props.ignore = true;
85+
}
86+
87+
if !has_asan && config.parse_name_directive(ln, "needs-sanitizer-address") {
88+
props.ignore = true;
89+
}
90+
91+
if !has_lsan && config.parse_name_directive(ln, "needs-sanitizer-leak") {
92+
props.ignore = true;
93+
}
94+
95+
if !has_msan && config.parse_name_directive(ln, "needs-sanitizer-memory") {
96+
props.ignore = true;
97+
}
98+
99+
if !has_tsan && config.parse_name_directive(ln, "needs-sanitizer-thread") {
78100
props.ignore = true;
79101
}
80102

@@ -829,10 +851,6 @@ impl Config {
829851
self.parse_name_directive(line, "needs-profiler-support")
830852
}
831853

832-
fn parse_needs_sanitizer_support(&self, line: &str) -> bool {
833-
self.parse_name_directive(line, "needs-sanitizer-support")
834-
}
835-
836854
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
837855
/// or `normalize-stderr-32bit`.
838856
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {

‎src/tools/compiletest/src/header/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,22 @@ fn debugger() {
201201
config.debugger = Some(Debugger::Lldb);
202202
assert!(parse_rs(&config, "// ignore-lldb").ignore);
203203
}
204+
205+
#[test]
206+
fn sanitizers() {
207+
let mut config = config();
208+
209+
// Target that supports all sanitizers:
210+
config.target = "x86_64-unknown-linux-gnu".to_owned();
211+
assert!(!parse_rs(&config, "// needs-sanitizer-address").ignore);
212+
assert!(!parse_rs(&config, "// needs-sanitizer-leak").ignore);
213+
assert!(!parse_rs(&config, "// needs-sanitizer-memory").ignore);
214+
assert!(!parse_rs(&config, "// needs-sanitizer-thread").ignore);
215+
216+
// Target that doesn't support sanitizers:
217+
config.target = "wasm32-unknown-emscripten".to_owned();
218+
assert!(parse_rs(&config, "// needs-sanitizer-address").ignore);
219+
assert!(parse_rs(&config, "// needs-sanitizer-leak").ignore);
220+
assert!(parse_rs(&config, "// needs-sanitizer-memory").ignore);
221+
assert!(parse_rs(&config, "// needs-sanitizer-thread").ignore);
222+
}

‎src/tools/compiletest/src/util.rs

+11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
8282
("xcore", "xcore"),
8383
];
8484

85+
pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] =
86+
&["aarch64-fuchsia", "x86_64-apple-darwin", "x86_64-fuchsia", "x86_64-unknown-linux-gnu"];
87+
88+
pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] =
89+
&["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
90+
91+
pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] = &["x86_64-unknown-linux-gnu"];
92+
93+
pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] =
94+
&["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
95+
8596
pub fn matches_os(triple: &str, name: &str) -> bool {
8697
// For the wasm32 bare target we ignore anything also ignored on emscripten
8798
// and then we also recognize `wasm32-bare` as the os for the target

0 commit comments

Comments
 (0)
Please sign in to comment.