]> git.lizzy.rs Git - rust.git/commitdiff
compiletest: Add directives to detect sanitizer support
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Fri, 5 Jun 2020 00:00:00 +0000 (00:00 +0000)
committerTomasz Miąsko <tomasz.miasko@gmail.com>
Sat, 13 Jun 2020 12:24:30 +0000 (14:24 +0200)
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.

20 files changed:
src/test/codegen/sanitizer-memory-track-orgins.rs
src/test/codegen/sanitizer-no-sanitize-inlining.rs
src/test/codegen/sanitizer-no-sanitize.rs
src/test/codegen/sanitizer-recover.rs
src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile
src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile
src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile
src/test/rustdoc/sanitizer-option.rs
src/test/ui/sanitize/address.rs
src/test/ui/sanitize/badfree.rs
src/test/ui/sanitize/cfg.rs
src/test/ui/sanitize/issue-72154-lifetime-markers.rs
src/test/ui/sanitize/leak.rs
src/test/ui/sanitize/memory.rs
src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs
src/test/ui/sanitize/thread.rs
src/test/ui/sanitize/use-after-scope.rs
src/tools/compiletest/src/header.rs
src/tools/compiletest/src/header/tests.rs
src/tools/compiletest/src/util.rs

index 8ea41c5d44bb1fe410807d3324a003fc8504d2ca..4bd50508d152056e13f7ecc21d80055ab00a6a45 100644 (file)
@@ -1,9 +1,7 @@
 // Verifies that MemorySanitizer track-origins level can be controlled
 // with -Zsanitizer-memory-track-origins option.
 //
-// needs-sanitizer-support
-// only-linux
-// only-x86_64
+// needs-sanitizer-memory
 // revisions:MSAN-0 MSAN-1 MSAN-2 MSAN-1-LTO MSAN-2-LTO
 //
 //[MSAN-0] compile-flags: -Zsanitizer=memory
index d96e76618d32501e33f91ac03276b177563ddf8c..b00441e4fc5abb078fca340700039ea60da0a5fe 100644 (file)
@@ -1,11 +1,9 @@
 // Verifies that no_sanitize attribute prevents inlining when
 // given sanitizer is enabled, but has no effect on inlining otherwise.
 //
-// needs-sanitizer-support
-// only-x86_64
-//
+// needs-sanitizer-address
+// needs-sanitizer-leak
 // revisions: ASAN LSAN
-//
 //[ASAN] compile-flags: -Zsanitizer=address -C opt-level=3 -Z mir-opt-level=3
 //[LSAN] compile-flags: -Zsanitizer=leak    -C opt-level=3 -Z mir-opt-level=3
 
index dfceb28c8dd107eaaa01eb5c87021c5241c9fe85..1b2b18822e63e8a8c673166bcb92bd0fdb99ac2f 100644 (file)
@@ -1,7 +1,7 @@
 // Verifies that no_sanitze attribute can be used to
 // selectively disable sanitizer instrumentation.
 //
-// needs-sanitizer-support
+// needs-sanitizer-address
 // compile-flags: -Zsanitizer=address
 
 #![crate_type="lib"]
index 05b4ab5653cc843e897838430312200385829ccb..719f219ce4ef1b9fe8cc0c1830309d352b9f142b 100644 (file)
@@ -1,9 +1,8 @@
 // Verifies that AddressSanitizer and MemorySanitizer
 // recovery mode can be enabled with -Zsanitizer-recover.
 //
-// needs-sanitizer-support
-// only-linux
-// only-x86_64
+// needs-sanitizer-address
+// needs-sanitizer-memory
 // revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER MSAN-RECOVER-LTO
 // no-prefer-dynamic
 //
index 5d46be87eac6b2e3da1763e98461a606610ab412..b11d4c4cab7cf54c5f1f5de18a50cf3b15372149 100644 (file)
@@ -1,5 +1,5 @@
 # needs-sanitizer-support
-# only-x86_64
+# needs-sanitizer-address
 # only-linux
 
 -include ../tools.mk
index f62c3a6654ed414d36b74a7128b03555e0bca91a..c2ebd2a6d8cacbf49ad9c02f92ec1f3e8252b448 100644 (file)
@@ -1,5 +1,5 @@
 # needs-sanitizer-support
-# only-x86_64
+# needs-sanitizer-address
 # only-linux
 
 -include ../tools.mk
index f56475b441f1a0aa0731c950f2a7757cc990891e..5ceff16471cee99fde034adabf0d53e8fadd9eeb 100644 (file)
@@ -1,5 +1,5 @@
 # needs-sanitizer-support
-# only-x86_64
+# needs-sanitizer-address
 # only-linux
 
 -include ../tools.mk
index 6af9ed3e33f661e44c0105494b858ec88c3e717a..a79b37ee08210717c27c9f278f7aac0402992e09 100644 (file)
@@ -1,4 +1,5 @@
 // needs-sanitizer-support
+// needs-sanitizer-address
 // compile-flags: --test -Z sanitizer=address
 //
 // #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern
index f8650cd86d51e8bf80942d0e32d21e0ba5cba970..cee73b0425ad52210f7032b7e6b9262babad2b51 100644 (file)
@@ -1,5 +1,5 @@
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-address
 //
 // compile-flags: -Z sanitizer=address -O -g
 //
index 1ca082c8b47042f8444a34801e2ca12c0515b34b..095a6f4697b1c15a35a1e5139531b3ec5b4bfa46 100644 (file)
@@ -1,5 +1,5 @@
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-address
 //
 // compile-flags: -Z sanitizer=address -O
 //
index 9c198543a86649572cd42aa4fc6105d4231b985b..79dfe58f04d0b48274bac1512000aec19a327098 100644 (file)
@@ -2,8 +2,10 @@
 // the `#[cfg(sanitize = "option")]` attribute is configured.
 
 // needs-sanitizer-support
-// only-linux
-// only-x86_64
+// needs-sanitizer-address
+// needs-sanitizer-leak
+// needs-sanitizer-memory
+// needs-sanitizer-thread
 // check-pass
 // revisions: address leak memory thread
 //[address]compile-flags: -Zsanitizer=address --cfg address
index 458f99143b6488ada45e038b0ba973d7f260ca15..b2e182238ce288803b0cd9116c8be6d8fb939d01 100644 (file)
@@ -4,7 +4,7 @@
 // miscompilation which was subsequently detected by AddressSanitizer as UB.
 //
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-address
 //
 // compile-flags: -Copt-level=0 -Zsanitizer=address
 // run-pass
index 5c2f2cb4e868bb0012a960f21a61e7f85f044017..c9f10fe4f467ed73c8bdc7a4a92944bcf49c788e 100644 (file)
@@ -1,5 +1,5 @@
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-leak
 //
 // compile-flags: -Z sanitizer=leak -O
 //
index 3e1cf4509a31ff953cc9a914b9caef79083e729b..a26649a5800131e20a6820ec72a123263552a84a 100644 (file)
@@ -1,6 +1,5 @@
 // needs-sanitizer-support
-// only-linux
-// only-x86_64
+// needs-sanitizer-memory
 //
 // compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
 //
index d0984bbe65fd58a745954e32cec4663988734dcd..64d6ccf34091681d386c7c3f746c7e529e2d15fb 100644 (file)
@@ -4,7 +4,7 @@
 //
 // min-llvm-version 9.0
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-address
 //
 // no-prefer-dynamic
 // revisions: opt0 opt1
index 26590be8b1870f5155534a920ddc318721b172b3..c70cf5accc0776611cf557a43178b708e002708e 100644 (file)
@@ -11,7 +11,7 @@
 // would occasionally fail, making test flaky.
 //
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-thread
 //
 // compile-flags: -Z sanitizer=thread -O
 //
index 6a2067e157af56c7e2b76ad53831acc510e65c95..30be2ae6f090641e4bdacb7374f0940b521370fd 100644 (file)
@@ -1,5 +1,5 @@
 // needs-sanitizer-support
-// only-x86_64
+// needs-sanitizer-address
 //
 // compile-flags: -Zsanitizer=address
 // run-fail
index 9d1940dd4d6c20c0cc5e413ced2df891fa6232e8..9614707433e13af4a0111db8a271c7aa8f9547c7 100644 (file)
@@ -43,6 +43,10 @@ pub fn from_reader<R: Read>(config: &Config, testfile: &Path, rdr: R) -> Self {
         let mut props = EarlyProps::default();
         let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
         let rustc_has_sanitizer_support = env::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
+        let has_asan = util::ASAN_SUPPORTED_TARGETS.contains(&&*config.target);
+        let has_lsan = util::LSAN_SUPPORTED_TARGETS.contains(&&*config.target);
+        let has_msan = util::MSAN_SUPPORTED_TARGETS.contains(&&*config.target);
+        let has_tsan = util::TSAN_SUPPORTED_TARGETS.contains(&&*config.target);
 
         iter_header(testfile, None, rdr, &mut |ln| {
             // we should check if any only-<platform> exists and if it exists
@@ -74,7 +78,25 @@ pub fn from_reader<R: Read>(config: &Config, testfile: &Path, rdr: R) -> Self {
                     props.ignore = true;
                 }
 
-                if !rustc_has_sanitizer_support && config.parse_needs_sanitizer_support(ln) {
+                if !rustc_has_sanitizer_support
+                    && config.parse_name_directive(ln, "needs-sanitizer-support")
+                {
+                    props.ignore = true;
+                }
+
+                if !has_asan && config.parse_name_directive(ln, "needs-sanitizer-address") {
+                    props.ignore = true;
+                }
+
+                if !has_lsan && config.parse_name_directive(ln, "needs-sanitizer-leak") {
+                    props.ignore = true;
+                }
+
+                if !has_msan && config.parse_name_directive(ln, "needs-sanitizer-memory") {
+                    props.ignore = true;
+                }
+
+                if !has_tsan && config.parse_name_directive(ln, "needs-sanitizer-thread") {
                     props.ignore = true;
                 }
 
@@ -829,10 +851,6 @@ fn parse_needs_profiler_support(&self, line: &str) -> bool {
         self.parse_name_directive(line, "needs-profiler-support")
     }
 
-    fn parse_needs_sanitizer_support(&self, line: &str) -> bool {
-        self.parse_name_directive(line, "needs-sanitizer-support")
-    }
-
     /// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
     /// or `normalize-stderr-32bit`.
     fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
index 31d991e0c2f87c9ad0a2e3efe40c3f7bda103ca3..036409fbf070f7178e62d63126ae32b74314122c 100644 (file)
@@ -195,3 +195,22 @@ fn debugger() {
     config.debugger = Some(Debugger::Lldb);
     assert!(parse_rs(&config, "// ignore-lldb").ignore);
 }
+
+#[test]
+fn sanitizers() {
+    let mut config = config();
+
+    // Target that supports all sanitizers:
+    config.target = "x86_64-unknown-linux-gnu".to_owned();
+    assert!(!parse_rs(&config, "// needs-sanitizer-address").ignore);
+    assert!(!parse_rs(&config, "// needs-sanitizer-leak").ignore);
+    assert!(!parse_rs(&config, "// needs-sanitizer-memory").ignore);
+    assert!(!parse_rs(&config, "// needs-sanitizer-thread").ignore);
+
+    // Target that doesn't support sanitizers:
+    config.target = "wasm32-unknown-emscripten".to_owned();
+    assert!(parse_rs(&config, "// needs-sanitizer-address").ignore);
+    assert!(parse_rs(&config, "// needs-sanitizer-leak").ignore);
+    assert!(parse_rs(&config, "// needs-sanitizer-memory").ignore);
+    assert!(parse_rs(&config, "// needs-sanitizer-thread").ignore);
+}
index c61bee0f8d9eacf67b12cfc1a204fd5f7e33c66c..b9087dee6174cf0db09d7d530c8fd09f7426caba 100644 (file)
     ("xcore", "xcore"),
 ];
 
+pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] =
+    &["aarch64-fuchsia", "x86_64-apple-darwin", "x86_64-fuchsia", "x86_64-unknown-linux-gnu"];
+
+pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] =
+    &["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
+
+pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] = &["x86_64-unknown-linux-gnu"];
+
+pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] =
+    &["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
+
 pub fn matches_os(triple: &str, name: &str) -> bool {
     // For the wasm32 bare target we ignore anything also ignored on emscripten
     // and then we also recognize `wasm32-bare` as the os for the target