]> git.proxmox.com Git - rustc.git/blobdiff - src/tools/compiletest/src/util.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / src / tools / compiletest / src / util.rs
index 50dce4b55ae8609e380ed4e2751ad1779dcae83c..bed509d77be77f32be5d95cebc58c214b49c3937 100644 (file)
@@ -1,14 +1,17 @@
-use std::ffi::OsStr;
+use crate::common::Config;
 use std::env;
+use std::ffi::OsStr;
 use std::path::PathBuf;
-use crate::common::Config;
+
+use tracing::*;
+
+#[cfg(test)]
+mod tests;
 
 /// Conversion table from triple OS name to Rust SYSNAME
-const OS_TABLE: &'static [(&'static str, &'static str)] = &[
+const OS_TABLE: &[(&str, &str)] = &[
     ("android", "android"),
     ("androideabi", "android"),
-    ("bitrig", "bitrig"),
-    ("cloudabi", "cloudabi"),
     ("cuda", "cuda"),
     ("darwin", "macos"),
     ("dragonfly", "dragonfly"),
@@ -17,6 +20,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[
     ("fuchsia", "fuchsia"),
     ("haiku", "haiku"),
     ("hermit", "hermit"),
+    ("illumos", "illumos"),
     ("ios", "ios"),
     ("l4re", "l4re"),
     ("linux", "linux"),
@@ -29,10 +33,12 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[
     ("solaris", "solaris"),
     ("win32", "windows"),
     ("windows", "windows"),
+    ("vxworks", "vxworks"),
 ];
 
-const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
+const ARCH_TABLE: &[(&str, &str)] = &[
     ("aarch64", "aarch64"),
+    ("aarch64_be", "aarch64"),
     ("amd64", "x86_64"),
     ("arm", "arm"),
     ("arm64", "aarch64"),
@@ -41,10 +47,14 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
     ("armv7", "arm"),
     ("armv7s", "arm"),
     ("asmjs", "asmjs"),
+    ("avr", "avr"),
+    ("bpfeb", "bpf"),
+    ("bpfel", "bpf"),
     ("hexagon", "hexagon"),
     ("i386", "x86"),
     ("i586", "x86"),
     ("i686", "x86"),
+    ("m68k", "m68k"),
     ("mips", "mips"),
     ("mips64", "mips64"),
     ("mips64el", "mips64"),
@@ -62,6 +72,7 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
     ("powerpc", "powerpc"),
     ("powerpc64", "powerpc64"),
     ("powerpc64le", "powerpc64"),
+    ("riscv64gc", "riscv64"),
     ("s390x", "s390x"),
     ("sparc", "sparc"),
     ("sparc64", "sparc64"),
@@ -74,6 +85,67 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
     ("xcore", "xcore"),
 ];
 
+pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
+    "aarch64-apple-darwin",
+    "aarch64-fuchsia",
+    "aarch64-unknown-linux-gnu",
+    "x86_64-apple-darwin",
+    "x86_64-fuchsia",
+    "x86_64-unknown-freebsd",
+    "x86_64-unknown-linux-gnu",
+];
+
+pub const LSAN_SUPPORTED_TARGETS: &[&str] = &[
+    // FIXME: currently broken, see #88132
+    // "aarch64-apple-darwin",
+    "aarch64-unknown-linux-gnu",
+    "x86_64-apple-darwin",
+    "x86_64-unknown-linux-gnu",
+];
+
+pub const MSAN_SUPPORTED_TARGETS: &[&str] =
+    &["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"];
+
+pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
+    "aarch64-apple-darwin",
+    "aarch64-unknown-linux-gnu",
+    "x86_64-apple-darwin",
+    "x86_64-unknown-freebsd",
+    "x86_64-unknown-linux-gnu",
+];
+
+pub const HWASAN_SUPPORTED_TARGETS: &[&str] =
+    &["aarch64-linux-android", "aarch64-unknown-linux-gnu"];
+
+pub const MEMTAG_SUPPORTED_TARGETS: &[&str] =
+    &["aarch64-linux-android", "aarch64-unknown-linux-gnu"];
+
+const BIG_ENDIAN: &[&str] = &[
+    "aarch64_be",
+    "armebv7r",
+    "mips",
+    "mips64",
+    "mipsisa32r6",
+    "mipsisa64r6",
+    "powerpc",
+    "powerpc64",
+    "s390x",
+    "sparc",
+    "sparc64",
+    "sparcv9",
+];
+
+static ASM_SUPPORTED_ARCHS: &[&str] = &[
+    "x86", "x86_64", "arm", "aarch64", "riscv32",
+    "riscv64",
+    // These targets require an additional asm_experimental_arch feature.
+    // "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
@@ -100,13 +172,23 @@ pub fn get_arch(triple: &str) -> &'static str {
     panic!("Cannot determine Architecture from triple");
 }
 
-pub fn get_env(triple: &str) -> Option<&str> {
-    triple.split('-').nth(3)
+/// Determine the endianness from `triple`
+pub fn is_big_endian(triple: &str) -> bool {
+    let triple_arch = triple.split('-').next().unwrap();
+    BIG_ENDIAN.contains(&triple_arch)
+}
+
+pub fn matches_env(triple: &str, name: &str) -> bool {
+    if let Some(env) = triple.split('-').nth(3) { env.starts_with(name) } else { false }
 }
 
 pub fn get_pointer_width(triple: &str) -> &'static str {
-    if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
+    if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32"))
+        || triple.starts_with("s390x")
+    {
         "64bit"
+    } else if triple.starts_with("avr") {
+        "16bit"
     } else {
         "32bit"
     }
@@ -143,11 +225,11 @@ pub trait PathBufExt {
 
 impl PathBufExt for PathBuf {
     fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
-        if extension.as_ref().len() == 0 {
+        if extension.as_ref().is_empty() {
             self.clone()
         } else {
             let mut fname = self.file_name().unwrap().to_os_string();
-            if !extension.as_ref().to_str().unwrap().starts_with(".") {
+            if !extension.as_ref().to_str().unwrap().starts_with('.') {
                 fname.push(".");
             }
             fname.push(extension);
@@ -155,34 +237,3 @@ impl PathBufExt for PathBuf {
         }
     }
 }
-
-#[test]
-#[should_panic(expected = "Cannot determine Architecture from triple")]
-fn test_get_arch_failure() {
-    get_arch("abc");
-}
-
-#[test]
-fn test_get_arch() {
-    assert_eq!("x86_64", get_arch("x86_64-unknown-linux-gnu"));
-    assert_eq!("x86_64", get_arch("amd64"));
-    assert_eq!("nvptx64", get_arch("nvptx64-nvidia-cuda"));
-}
-
-#[test]
-#[should_panic(expected = "Cannot determine OS from triple")]
-fn test_matches_os_failure() {
-    matches_os("abc", "abc");
-}
-
-#[test]
-fn test_matches_os() {
-    assert!(matches_os("x86_64-unknown-linux-gnu", "linux"));
-    assert!(matches_os("wasm32-unknown-unknown", "emscripten"));
-    assert!(matches_os("wasm32-unknown-unknown", "wasm32-bare"));
-    assert!(!matches_os("wasm32-unknown-unknown", "windows"));
-    assert!(matches_os("thumbv6m0-none-eabi", "none"));
-    assert!(matches_os("riscv32imc-unknown-none-elf", "none"));
-    assert!(matches_os("nvptx64-nvidia-cuda", "cuda"));
-    assert!(matches_os("x86_64-fortanix-unknown-sgx", "sgx"));
-}