Skip to content

Commit cedd098

Browse files
committed
llvm-target use and additional misallignment catches
1 parent 7edcddd commit cedd098

File tree

2 files changed

+37
-66
lines changed

2 files changed

+37
-66
lines changed

tests/run-make/core-ffi-typecheck-clang/rmake.rs

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// If this test fails because Rust adds a target that Clang does not support, this target should be
77
// added to SKIPPED_TARGETS.
88

9-
use run_make_support::{clang, llvm_components_contain, regex, rfs, rustc};
9+
use run_make_support::{clang, regex, rfs, rustc, serde_json};
10+
use serde_json::Value;
1011

1112
// It is not possible to run the Rust test-suite on these targets.
1213
const SKIPPED_TARGETS: &[&str] = &[
@@ -21,81 +22,27 @@ const SKIPPED_TARGETS: &[&str] = &[
2122
"csky-unknown-linux-gnuabiv2hf",
2223
];
2324

24-
/// Map from a Rust target to the Clang target if they are not the same.
25-
const MAPPED_TARGETS: &[(&str, &str)] = &[
26-
("aarch64-apple-ios-sim", "aarch64-apple-ios"),
27-
("aarch64-apple-tvos-sim", "aarch64-apple-tvos"),
28-
("aarch64-apple-visionos-sim", "aarch64-apple-visionos"),
29-
("aarch64-apple-watchos-sim", "aarch64-apple-watchos"),
30-
("x86_64-apple-watchos-sim", "x86_64-apple-watchos"),
31-
("aarch64-pc-windows-gnullvm", "aarch64-pc-windows-gnu"),
32-
("aarch64-unknown-linux-gnu_ilp32", "aarch64-unknown-linux-gnu"),
33-
("aarch64-unknown-none-softfloat", "aarch64-unknown-none"),
34-
("aarch64-unknown-nto-qnx700", "aarch64-unknown-nto-700"),
35-
("aarch64-unknown-nto-qnx710", "aarch64-unknown-nto-710"),
36-
("aarch64-unknown-uefi", "aarch64-unknown"),
37-
("aarch64_be-unknown-linux-gnu_ilp32", "aarch64_be-unknown-linux-gnu"),
38-
("armv5te-unknown-linux-uclibceabi", "armv5te-unknown-linux"),
39-
("armv7-sony-vita-newlibeabihf", "armv7-sony-vita"),
40-
("armv7-unknown-linux-uclibceabi", "armv7-unknown-linux"),
41-
("armv7-unknown-linux-uclibceabihf", "armv7-unknown-linux"),
42-
("avr-unknown-gnu-atmega328", "avr-unknown-gnu"),
43-
("csky-unknown-linux-gnuabiv2", "csky-unknown-linux-gnu"),
44-
("i586-pc-nto-qnx700", "i586-pc-nto-700"),
45-
("i686-pc-windows-gnullvm", "i686-pc-windows-gnu"),
46-
("i686-unknown-uefi", "i686-unknown"),
47-
("loongarch64-unknown-none-softfloat", "loongarch64-unknown-none"),
48-
("mips-unknown-linux-uclibc", "mips-unknown-linux"),
49-
("mipsel-unknown-linux-uclibc", "mipsel-unknown-linux"),
50-
("powerpc-unknown-linux-gnuspe", "powerpc-unknown-linux-gnu"),
51-
("powerpc-unknown-linux-muslspe", "powerpc-unknown-linux-musl"),
52-
("powerpc-wrs-vxworks-spe", "powerpc-wrs-vxworks"),
53-
("x86_64-fortanix-unknown-sgx", "x86_64-fortanix-unknown"),
54-
("x86_64-pc-nto-qnx710", "x86_64-pc-nto-710"),
55-
("x86_64-pc-windows-gnullvm", "x86_64-pc-windows-gnu"),
56-
("x86_64-unknown-l4re-uclibc", "x86_64-unknown-l4re"),
57-
];
58-
5925
fn main() {
60-
let targets = get_target_list();
61-
6226
let minicore_path = run_make_support::source_root().join("tests/auxiliary/minicore.rs");
6327

6428
preprocess_core_ffi();
6529

66-
for target in targets.lines() {
30+
let targets_json =
31+
rustc().arg("--print").arg("all-target-specs-json").arg("-Z").arg("unstable-options").run();
32+
let targets_json_str =
33+
String::from_utf8(targets_json.stdout().to_vec()).expect("error not a string");
34+
35+
let j: Value = serde_json::from_str(&targets_json_str).unwrap();
36+
for (target, v) in j.as_object().unwrap() {
37+
let llvm_target = &v["llvm-target"].as_str().unwrap();
38+
6739
if SKIPPED_TARGETS.iter().any(|&to_skip_target| target == to_skip_target) {
6840
continue;
6941
}
7042

71-
// Map the Rust target string to a Clang target string if needed
72-
// Also replace riscv with necessary replacements to match clang
73-
// If neither just use target string
74-
let ctarget = MAPPED_TARGETS
75-
.iter()
76-
.find(|(rtarget, _)| *rtarget == target)
77-
.map(|(_, ctarget)| ctarget.to_string())
78-
.unwrap_or_else(|| {
79-
if target.starts_with("riscv") {
80-
target
81-
.replace("imac-", "-")
82-
.replace("gc-", "-")
83-
.replace("imafc-", "-")
84-
.replace("imc-", "-")
85-
.replace("ima-", "-")
86-
.replace("im-", "-")
87-
.replace("emc-", "-")
88-
.replace("em-", "-")
89-
.replace("e-", "-")
90-
.replace("i-", "-")
91-
} else {
92-
target.to_string()
93-
}
94-
});
95-
9643
// Run Clang's preprocessor for the relevant target, printing default macro definitions.
9744
let clang_output =
98-
clang().args(&["-E", "-dM", "-x", "c", "/dev/null", "-target", &ctarget]).run();
45+
clang().args(&["-E", "-dM", "-x", "c", "/dev/null", "-target", &llvm_target]).run();
9946

10047
let defines = String::from_utf8(clang_output.stdout()).expect("Invalid UTF-8");
10148

tests/run-make/core-ffi-typecheck-clang/tests.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ cfg_if! {
1313
// FIXME: long is not long enough on aarch64 ilp32, should be 8, defaulting to 4
1414
const XFAIL_C_LONG_SIZE: usize = 4;
1515
pub const TEST_C_LONG_SIZE: () = if size_of::<ffi::c_long>() != XFAIL_C_LONG_SIZE {
16-
panic!("wrong c_long size test ilp32");
16+
panic!("mismatched c_long size, target_abi: ilp32");
17+
};
18+
}
19+
else if #[cfg(all(target_arch = "aarch64", target_os = "uefi"))] {
20+
// FIXME: c_long misallignment llvm target is aarch64-unknown-windows,
21+
// discrepencies between Rust target configuration and LLVM alias.
22+
const XFAIL_C_LONG_SIZE: usize = 8;
23+
pub const TEST_C_LONG_SIZE: () = if size_of::<ffi::c_long>() != XFAIL_C_LONG_SIZE {
24+
panic!("mismatched c_long size, target_os: uefi");
25+
};
26+
}
27+
else if #[cfg(all(target_arch = "x86_64", target_os = "uefi"))] {
28+
// FIXME: c_long misallignment llvm target is x86_64-unknown-windows,
29+
// discrepencies between Rust target configuration and LLVM alias.
30+
const XFAIL_C_LONG_SIZE: usize = 8;
31+
pub const TEST_C_LONG_SIZE: () = if size_of::<ffi::c_long>() != XFAIL_C_LONG_SIZE {
32+
panic!("mismatched c_long size, target_os: uefi");
1733
};
1834
}
1935
else {
@@ -33,6 +49,14 @@ cfg_if! {
3349
panic!("mismatched c_char signed, target_arch: msp430");
3450
};
3551
}
52+
else if #[cfg(all(target_arch = "aarch64", target_os = "uefi"))] {
53+
// FIXME: c_char signedness misallignment llvm target is aarch64-unknown-windows,
54+
// discrepencies between Rust target configuration and LLVM alias.
55+
const XFAIL_C_CHAR_SIGNED: bool = false;
56+
pub const TEST_C_CHAR_UNSIGNED: () = if ffi::c_char::SIGNED != XFAIL_C_CHAR_SIGNED {
57+
panic!("mismatched c_char signed, target_os: uefi");
58+
};
59+
}
3660
else {
3761
pub const TEST_C_CHAR_UNSIGNED: () = if ffi::c_char::SIGNED != CLANG_C_CHAR_SIGNED {
3862
panic!("mismatched c_char sign");

0 commit comments

Comments
 (0)