[PATCH] Check for asm support in UI tests that require it
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Sun, 11 Apr 2021 00:00:00 +0000 (00:00 +0000)
committerXimin Luo <infinity0@debian.org>
Sun, 19 Sep 2021 18:48:33 +0000 (19:48 +0100)
Add `needs-asm-support` compiletest directive, and use it in asm tests
that require asm support without relying on any architecture specific
features.

Gbp-Pq: Name u-84099.patch

src/test/ui/asm/bad-options.rs
src/test/ui/asm/naked-invalid-attr.rs
src/test/ui/feature-gates/feature-gate-naked_functions.rs
src/test/ui/feature-gates/feature-gate-naked_functions.stderr
src/test/ui/rfc-2091-track-caller/error-with-naked.rs
src/test/ui/rfc-2091-track-caller/error-with-naked.stderr
src/tools/compiletest/src/header.rs
src/tools/compiletest/src/header/tests.rs
src/tools/compiletest/src/util.rs

index 755fc2ca238aa8e7feebfcf0023006764e3ffb2c..a60478f62154f5d47f3f9de361feab27dd2169cd 100644 (file)
@@ -1,4 +1,4 @@
-// only-x86_64
+// needs-asm-support
 
 #![feature(asm)]
 
index cdb6c17454b733863afb8f54a5903b2efa03ea74..2576d1124c85c8bcbbc2a86b0b7538aac17ff721 100644 (file)
@@ -1,6 +1,6 @@
 // Checks that #[naked] attribute can be placed on function definitions only.
 //
-// ignore-wasm32 asm unsupported
+// needs-asm-support
 #![feature(asm)]
 #![feature(naked_functions)]
 #![naked] //~ ERROR should be applied to a function definition
index 06bddc422cf80847318e87d4cd761af49f890172..71ca5b9373a68cec00246844f6d6ba954100c936 100644 (file)
@@ -1,3 +1,4 @@
+// needs-asm-support
 #![feature(asm)]
 
 #[naked]
index d95561d20133e8768f8f3c65b91c8cbd6733e410..653d7b738da1a21250423c237454fb0f48e4c8e7 100644 (file)
@@ -1,5 +1,5 @@
 error[E0658]: the `#[naked]` attribute is an experimental feature
-  --> $DIR/feature-gate-naked_functions.rs:3:1
+  --> $DIR/feature-gate-naked_functions.rs:4:1
    |
 LL | #[naked]
    | ^^^^^^^^
@@ -8,7 +8,7 @@ LL | #[naked]
    = help: add `#![feature(naked_functions)]` to the crate attributes to enable
 
 error[E0658]: the `#[naked]` attribute is an experimental feature
-  --> $DIR/feature-gate-naked_functions.rs:9:1
+  --> $DIR/feature-gate-naked_functions.rs:10:1
    |
 LL | #[naked]
    | ^^^^^^^^
index 70ec0e3033c6f71b8d96eb78707027e5cf7d4fd6..9464ffe8722825bfef725b4706c8667fcbc29754 100644 (file)
@@ -1,3 +1,4 @@
+// needs-asm-support
 #![feature(asm, naked_functions)]
 
 #[track_caller] //~ ERROR cannot use `#[track_caller]` with `#[naked]`
index 1b49148d629b2321f45c1eaae4ee8904eef71e82..5f17d6b2b5173b5f68caaefdb3a58c3fdc4480f6 100644 (file)
@@ -1,11 +1,11 @@
 error[E0736]: cannot use `#[track_caller]` with `#[naked]`
-  --> $DIR/error-with-naked.rs:3:1
+  --> $DIR/error-with-naked.rs:4:1
    |
 LL | #[track_caller]
    | ^^^^^^^^^^^^^^^
 
 error[E0736]: cannot use `#[track_caller]` with `#[naked]`
-  --> $DIR/error-with-naked.rs:12:5
+  --> $DIR/error-with-naked.rs:13:5
    |
 LL |     #[track_caller]
    |     ^^^^^^^^^^^^^^^
index 2eba91fd1f4cf6ef72e191d78398db2c66105212..5d148c29f7e81d1ee68f60ad17239724bceebb23 100644 (file)
@@ -44,6 +44,7 @@ impl EarlyProps {
         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_asm_support = util::has_asm_support(&config.target);
         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);
@@ -75,6 +76,10 @@ impl EarlyProps {
                     props.ignore = true;
                 }
 
+                if !has_asm_support && config.parse_name_directive(ln, "needs-asm-support") {
+                    props.ignore = true;
+                }
+
                 if !rustc_has_profiler_support && config.parse_needs_profiler_support(ln) {
                     props.ignore = true;
                 }
index ec99fde0df9c2f03e3f2955bb03d9375cf05a8c4..c41b43cdd0b53c34283c0226dd5c48788cadf9ee 100644 (file)
@@ -223,6 +223,17 @@ fn sanitizers() {
     assert!(parse_rs(&config, "// needs-sanitizer-thread").ignore);
 }
 
+#[test]
+fn asm_support() {
+    let mut config = config();
+
+    config.target = "avr-unknown-gnu-atmega328".to_owned();
+    assert!(parse_rs(&config, "// needs-asm-support").ignore);
+
+    config.target = "i686-unknown-netbsd".to_owned();
+    assert!(!parse_rs(&config, "// needs-asm-support").ignore);
+}
+
 #[test]
 fn test_extract_version_range() {
     use super::{extract_llvm_version, extract_version_range};
index 292850bd9e277f55771afbe6e90428ac42ffd437..fd2c5f7102999b669cb297650bdf8de2c825c996 100644 (file)
@@ -125,6 +125,15 @@ const BIG_ENDIAN: &[&str] = &[
     "sparcv9",
 ];
 
+static ASM_SUPPORTED_ARCHS: &[&str] = &[
+    "x86", "x86_64", "arm", "aarch64", "riscv32", "riscv64", "nvptx64", "hexagon", "mips",
+    "mips64", "spirv", "wasm32",
+];
+
+pub fn has_asm_support(triple: &str) -> bool {
+    ASM_SUPPORTED_ARCHS.contains(&get_arch(triple))
+}
+
 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