Skip to content

Commit 67d476a

Browse files
committed
Verify llvm-needs-components are not empty and match the --target value
1 parent e9182f1 commit 67d476a

17 files changed

+245
-78
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 137 additions & 41 deletions
Large diffs are not rendered by default.

src/tools/compiletest/src/directives/auxiliary.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
use std::iter;
55

6+
use camino::Utf8Path;
7+
68
use super::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
79
use crate::common::Config;
810

@@ -41,17 +43,42 @@ impl AuxProps {
4143

4244
/// If the given test directive line contains an `aux-*` directive, parse it
4345
/// and update [`AuxProps`] accordingly.
44-
pub(super) fn parse_and_update_aux(config: &Config, ln: &str, aux: &mut AuxProps) {
46+
pub(super) fn parse_and_update_aux(
47+
config: &Config,
48+
ln: &str,
49+
testfile: &Utf8Path,
50+
line_number: usize,
51+
aux: &mut AuxProps,
52+
) {
4553
if !(ln.starts_with("aux-") || ln.starts_with("proc-macro")) {
4654
return;
4755
}
4856

49-
config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string());
50-
config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string());
51-
config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate);
52-
config
53-
.push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, |r| r.trim().to_string());
54-
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
57+
config.push_name_value_directive(ln, AUX_BUILD, testfile, line_number, &mut aux.builds, |r| {
58+
r.trim().to_string()
59+
});
60+
config.push_name_value_directive(ln, AUX_BIN, testfile, line_number, &mut aux.bins, |r| {
61+
r.trim().to_string()
62+
});
63+
config.push_name_value_directive(
64+
ln,
65+
AUX_CRATE,
66+
testfile,
67+
line_number,
68+
&mut aux.crates,
69+
parse_aux_crate,
70+
);
71+
config.push_name_value_directive(
72+
ln,
73+
PROC_MACRO,
74+
testfile,
75+
line_number,
76+
&mut aux.proc_macros,
77+
|r| r.trim().to_string(),
78+
);
79+
if let Some(r) =
80+
config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND, testfile, line_number)
81+
{
5582
aux.codegen_backend = Some(r.trim().to_owned());
5683
}
5784
}

src/tools/compiletest/src/runtest/debugger.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ impl DebuggerCommands {
4747
continue;
4848
};
4949

50-
if let Some(command) = config.parse_name_value_directive(&line, &command_directive) {
50+
if let Some(command) =
51+
config.parse_name_value_directive(&line, &command_directive, file, line_no)
52+
{
5153
commands.push(command);
5254
}
53-
if let Some(pattern) = config.parse_name_value_directive(&line, &check_directive) {
55+
if let Some(pattern) =
56+
config.parse_name_value_directive(&line, &check_directive, file, line_no)
57+
{
5458
check_lines.push((line_no, pattern));
5559
}
5660
}

src/tools/tidy/src/target_specific_tests.rs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ const COMPILE_FLAGS_HEADER: &str = "compile-flags:";
1212

1313
#[derive(Default, Debug)]
1414
struct RevisionInfo<'a> {
15-
target_arch: Option<&'a str>,
15+
target_arch: Option<Option<&'a str>>,
1616
llvm_components: Option<Vec<&'a str>>,
1717
}
1818

1919
pub fn check(tests_path: &Path, bad: &mut bool) {
2020
crate::walk::walk(tests_path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
21+
if content.contains("// ignore-tidy-target-specific-tests") {
22+
return;
23+
}
24+
2125
let file = entry.path().display();
2226
let mut header_map = BTreeMap::new();
2327
iter_header(content, &mut |HeaderLine { revision, directive, .. }| {
@@ -34,10 +38,11 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
3438
let compile_flags = &directive[COMPILE_FLAGS_HEADER.len()..];
3539
if let Some((_, v)) = compile_flags.split_once("--target") {
3640
let v = v.trim_start_matches(|c| c == ' ' || c == '=');
37-
let v = if v == "{{target}}" { Some((v, v)) } else { v.split_once("-") };
38-
if let Some((arch, _)) = v {
39-
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
40-
info.target_arch.replace(arch);
41+
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
42+
if v.starts_with("{{") {
43+
info.target_arch.replace(None);
44+
} else if let Some((arch, _)) = v.split_once("-") {
45+
info.target_arch.replace(Some(arch));
4146
} else {
4247
eprintln!("{file}: seems to have a malformed --target value");
4348
*bad = true;
@@ -55,10 +60,12 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
5560
let rev = rev.unwrap_or("[unspecified]");
5661
match (target_arch, llvm_components) {
5762
(None, None) => {}
58-
(Some(_), None) => {
63+
(Some(target_arch), None) => {
64+
let llvm_component =
65+
target_arch.map_or_else(|| "<arch>".to_string(), arch_to_llvm_component);
5966
eprintln!(
60-
"{}: revision {} should specify `{}` as it has `--target` set",
61-
file, rev, LLVM_COMPONENTS_HEADER
67+
"{}: revision {} should specify `{} {}` as it has `--target` set",
68+
file, rev, LLVM_COMPONENTS_HEADER, llvm_component
6269
);
6370
*bad = true;
6471
}
@@ -69,11 +76,43 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
6976
);
7077
*bad = true;
7178
}
72-
(Some(_), Some(_)) => {
73-
// FIXME: check specified components against the target architectures we
74-
// gathered.
79+
(Some(target_arch), Some(llvm_components)) => {
80+
if let Some(target_arch) = target_arch {
81+
let llvm_component = arch_to_llvm_component(target_arch);
82+
if !llvm_components.contains(&llvm_component.as_str()) {
83+
eprintln!(
84+
"{}: revision {} should specify `{} {}` as it has `--target` set",
85+
file, rev, LLVM_COMPONENTS_HEADER, llvm_component
86+
);
87+
*bad = true;
88+
}
89+
}
7590
}
7691
}
7792
}
7893
});
7994
}
95+
96+
fn arch_to_llvm_component(arch: &str) -> String {
97+
match arch {
98+
"amdgcn" => "amdgpu".into(),
99+
"aarch64_be" | "arm64_32" | "arm64e" | "arm64ec" => "aarch64".into(),
100+
"i386" | "i586" | "i686" | "x86" | "x86_64" | "x86_64h" => "x86".into(),
101+
"loongarch32" | "loongarch64" => "loongarch".into(),
102+
"nvptx64" => "nvptx".into(),
103+
"s390x" => "systemz".into(),
104+
"sparc64" | "sparcv9" => "sparc".into(),
105+
"wasm32" | "wasm32v1" | "wasm64" => "webassembly".into(),
106+
_ if arch.starts_with("armeb")
107+
|| arch.starts_with("armv")
108+
|| arch.starts_with("thumbv") =>
109+
{
110+
"arm".into()
111+
}
112+
_ if arch.starts_with("bpfe") => "bpf".into(),
113+
_ if arch.starts_with("mips") => "mips".into(),
114+
_ if arch.starts_with("powerpc") => "powerpc".into(),
115+
_ if arch.starts_with("riscv") => "riscv".into(),
116+
_ => arch.to_ascii_lowercase(),
117+
}
118+
}

tests/codegen/abi-efiapi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
//@ add-core-stubs
44
//@ revisions:x86_64 i686 aarch64 arm riscv
55
//@[x86_64] compile-flags: --target x86_64-unknown-uefi
6-
//@[x86_64] needs-llvm-components: aarch64 arm riscv
6+
//@[x86_64] needs-llvm-components: x86
77
//@[i686] compile-flags: --target i686-unknown-linux-musl
8-
//@[i686] needs-llvm-components: aarch64 arm riscv
8+
//@[i686] needs-llvm-components: x86
99
//@[aarch64] compile-flags: --target aarch64-unknown-none
10-
//@[aarch64] needs-llvm-components: aarch64 arm riscv
10+
//@[aarch64] needs-llvm-components: aarch64
1111
//@[arm] compile-flags: --target armv7r-none-eabi
12-
//@[arm] needs-llvm-components: aarch64 arm riscv
12+
//@[arm] needs-llvm-components: arm
1313
//@[riscv] compile-flags: --target riscv64gc-unknown-none-elf
14-
//@[riscv] needs-llvm-components: aarch64 arm riscv
14+
//@[riscv] needs-llvm-components: riscv
1515
//@ compile-flags: -C no-prepopulate-passes
1616

1717
#![crate_type = "lib"]

tests/codegen/cast-target-abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes -Zlint-llvm-ir
55

66
//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
7-
//@[aarch64] needs-llvm-components: arm
7+
//@[aarch64] needs-llvm-components: aarch64
88
//@[loongarch64] compile-flags: --target loongarch64-unknown-linux-gnu
99
//@[loongarch64] needs-llvm-components: loongarch
1010
//@[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu

tests/codegen/naked-fn/naked-functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//@[win_i686] compile-flags: --target i686-pc-windows-gnu
99
//@[win_i686] needs-llvm-components: x86
1010
//@[macos] compile-flags: --target aarch64-apple-darwin
11-
//@[macos] needs-llvm-components: arm
11+
//@[macos] needs-llvm-components: aarch64
1212
//@[thumb] compile-flags: --target thumbv7em-none-eabi
1313
//@[thumb] needs-llvm-components: arm
1414

tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-no-sanitize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ [aarch64] compile-flags: --target aarch64-unknown-none
66
//@ [aarch64] needs-llvm-components: aarch64
77
//@ [x86_64] compile-flags: --target x86_64-unknown-none
8-
//@ [x86_64] needs-llvm-components:
8+
//@ [x86_64] needs-llvm-components: x86
99
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0
1010

1111
#![crate_type = "lib"]

tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ [aarch64] compile-flags: --target aarch64-unknown-none
66
//@ [aarch64] needs-llvm-components: aarch64
77
//@ [x86_64] compile-flags: --target x86_64-unknown-none
8-
//@ [x86_64] needs-llvm-components:
8+
//@ [x86_64] needs-llvm-components: x86
99
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-generalize-pointers
1010

1111
#![crate_type = "lib"]

tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ [aarch64] compile-flags: --target aarch64-unknown-none
66
//@ [aarch64] needs-llvm-components: aarch64
77
//@ [x86_64] compile-flags: --target x86_64-unknown-none
8-
//@ [x86_64] needs-llvm-components:
8+
//@ [x86_64] needs-llvm-components: x86
99
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zsanitizer-cfi-generalize-pointers
1010

1111
#![crate_type = "lib"]

0 commit comments

Comments
 (0)