Skip to content

Verify llvm-needs-components are not empty and match the --target value #144042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 137 additions & 41 deletions src/tools/compiletest/src/directives.rs

Large diffs are not rendered by default.

41 changes: 34 additions & 7 deletions src/tools/compiletest/src/directives/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use std::iter;

use camino::Utf8Path;

use super::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
use crate::common::Config;

Expand Down Expand Up @@ -41,17 +43,42 @@ impl AuxProps {

/// If the given test directive line contains an `aux-*` directive, parse it
/// and update [`AuxProps`] accordingly.
pub(super) fn parse_and_update_aux(config: &Config, ln: &str, aux: &mut AuxProps) {
pub(super) fn parse_and_update_aux(
config: &Config,
ln: &str,
testfile: &Utf8Path,
line_number: usize,
aux: &mut AuxProps,
) {
if !(ln.starts_with("aux-") || ln.starts_with("proc-macro")) {
return;
}

config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string());
config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string());
config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate);
config
.push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, |r| r.trim().to_string());
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
config.push_name_value_directive(ln, AUX_BUILD, testfile, line_number, &mut aux.builds, |r| {
r.trim().to_string()
});
config.push_name_value_directive(ln, AUX_BIN, testfile, line_number, &mut aux.bins, |r| {
r.trim().to_string()
});
config.push_name_value_directive(
ln,
AUX_CRATE,
testfile,
line_number,
&mut aux.crates,
parse_aux_crate,
);
config.push_name_value_directive(
ln,
PROC_MACRO,
testfile,
line_number,
&mut aux.proc_macros,
|r| r.trim().to_string(),
);
if let Some(r) =
config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND, testfile, line_number)
{
aux.codegen_backend = Some(r.trim().to_owned());
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/tools/compiletest/src/runtest/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ impl DebuggerCommands {
continue;
};

if let Some(command) = config.parse_name_value_directive(&line, &command_directive) {
if let Some(command) =
config.parse_name_value_directive(&line, &command_directive, file, line_no)
{
commands.push(command);
}
if let Some(pattern) = config.parse_name_value_directive(&line, &check_directive) {
if let Some(pattern) =
config.parse_name_value_directive(&line, &check_directive, file, line_no)
{
check_lines.push((line_no, pattern));
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,11 @@ pub fn check(path: &Path, bad: &mut bool) {
.any(|directive| matches!(directive, Directive::Ignore(_)));
let has_alphabetical_directive = line.contains("tidy-alphabetical-start")
|| line.contains("tidy-alphabetical-end");
let has_recognized_directive =
has_recognized_ignore_directive || has_alphabetical_directive;
let has_other_tidy_ignore_directive =
line.contains("ignore-tidy-target-specific-tests");
let has_recognized_directive = has_recognized_ignore_directive
|| has_alphabetical_directive
|| has_other_tidy_ignore_directive;
if contains_potential_directive && (!has_recognized_directive) {
err("Unrecognized tidy directive")
}
Expand Down
61 changes: 51 additions & 10 deletions src/tools/tidy/src/target_specific_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ const COMPILE_FLAGS_HEADER: &str = "compile-flags:";

#[derive(Default, Debug)]
struct RevisionInfo<'a> {
target_arch: Option<&'a str>,
target_arch: Option<Option<&'a str>>,
llvm_components: Option<Vec<&'a str>>,
}

pub fn check(tests_path: &Path, bad: &mut bool) {
crate::walk::walk(tests_path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
if content.contains("// ignore-tidy-target-specific-tests") {
return;
}

let file = entry.path().display();
let mut header_map = BTreeMap::new();
iter_header(content, &mut |HeaderLine { revision, directive, .. }| {
Expand All @@ -33,10 +37,11 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
} else if let Some(compile_flags) = directive.strip_prefix(COMPILE_FLAGS_HEADER) {
if let Some((_, v)) = compile_flags.split_once("--target") {
let v = v.trim_start_matches([' ', '=']);
let v = if v == "{{target}}" { Some((v, v)) } else { v.split_once("-") };
if let Some((arch, _)) = v {
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
info.target_arch.replace(arch);
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
if v.starts_with("{{") {
info.target_arch.replace(None);
} else if let Some((arch, _)) = v.split_once("-") {
info.target_arch.replace(Some(arch));
} else {
eprintln!("{file}: seems to have a malformed --target value");
*bad = true;
Expand All @@ -54,9 +59,11 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
let rev = rev.unwrap_or("[unspecified]");
match (target_arch, llvm_components) {
(None, None) => {}
(Some(_), None) => {
(Some(target_arch), None) => {
let llvm_component =
target_arch.map_or_else(|| "<arch>".to_string(), arch_to_llvm_component);
eprintln!(
"{file}: revision {rev} should specify `{LLVM_COMPONENTS_HEADER}` as it has `--target` set"
"{file}: revision {rev} should specify `{LLVM_COMPONENTS_HEADER} {llvm_component}` as it has `--target` set"
);
*bad = true;
}
Expand All @@ -66,11 +73,45 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
);
*bad = true;
}
(Some(_), Some(_)) => {
// FIXME: check specified components against the target architectures we
// gathered.
(Some(target_arch), Some(llvm_components)) => {
if let Some(target_arch) = target_arch {
let llvm_component = arch_to_llvm_component(target_arch);
if !llvm_components.contains(&llvm_component.as_str()) {
eprintln!(
"{file}: revision {rev} should specify `{LLVM_COMPONENTS_HEADER} {llvm_component}` as it has `--target` set"
);
*bad = true;
}
}
}
}
}
});
}

fn arch_to_llvm_component(arch: &str) -> String {
// NOTE: This is an *approximate* mapping of Rust's `--target` architecture to LLVM component
// names. It is not intended to be an authoritative source, but rather a best-effort that's good
// enough for the purpose of this tidy check.
match arch {
"amdgcn" => "amdgpu".into(),
"aarch64_be" | "arm64_32" | "arm64e" | "arm64ec" => "aarch64".into(),
"i386" | "i586" | "i686" | "x86" | "x86_64" | "x86_64h" => "x86".into(),
"loongarch32" | "loongarch64" => "loongarch".into(),
"nvptx64" => "nvptx".into(),
"s390x" => "systemz".into(),
"sparc64" | "sparcv9" => "sparc".into(),
"wasm32" | "wasm32v1" | "wasm64" => "webassembly".into(),
_ if arch.starts_with("armeb")
|| arch.starts_with("armv")
|| arch.starts_with("thumbv") =>
{
"arm".into()
}
_ if arch.starts_with("bpfe") => "bpf".into(),
_ if arch.starts_with("mips") => "mips".into(),
_ if arch.starts_with("powerpc") => "powerpc".into(),
_ if arch.starts_with("riscv") => "riscv".into(),
_ => arch.to_ascii_lowercase(),
}
}
10 changes: 5 additions & 5 deletions tests/codegen/abi-efiapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
//@ add-core-stubs
//@ revisions:x86_64 i686 aarch64 arm riscv
//@[x86_64] compile-flags: --target x86_64-unknown-uefi
//@[x86_64] needs-llvm-components: aarch64 arm riscv
//@[x86_64] needs-llvm-components: x86
//@[i686] compile-flags: --target i686-unknown-linux-musl
//@[i686] needs-llvm-components: aarch64 arm riscv
//@[i686] needs-llvm-components: x86
//@[aarch64] compile-flags: --target aarch64-unknown-none
//@[aarch64] needs-llvm-components: aarch64 arm riscv
//@[aarch64] needs-llvm-components: aarch64
//@[arm] compile-flags: --target armv7r-none-eabi
//@[arm] needs-llvm-components: aarch64 arm riscv
//@[arm] needs-llvm-components: arm
//@[riscv] compile-flags: --target riscv64gc-unknown-none-elf
//@[riscv] needs-llvm-components: aarch64 arm riscv
//@[riscv] needs-llvm-components: riscv
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cast-target-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes -Zlint-llvm-ir

//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
//@[aarch64] needs-llvm-components: arm
//@[aarch64] needs-llvm-components: aarch64
//@[loongarch64] compile-flags: --target loongarch64-unknown-linux-gnu
//@[loongarch64] needs-llvm-components: loongarch
//@[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cf-protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ add-core-stubs
//@ revisions: undefined none branch return full
//@ needs-llvm-components: x86
//@ [undefined] compile-flags:
// [undefined] no extra compile-flags
//@ [none] compile-flags: -Z cf-protection=none
//@ [branch] compile-flags: -Z cf-protection=branch
//@ [return] compile-flags: -Z cf-protection=return
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/codemodels.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ only-x86_64

//@ revisions: NOMODEL MODEL-SMALL MODEL-KERNEL MODEL-MEDIUM MODEL-LARGE
//@[NOMODEL] compile-flags:
// [NOMODEL] no compile-flags
//@[MODEL-SMALL] compile-flags: -C code-model=small
//@[MODEL-KERNEL] compile-flags: -C code-model=kernel
//@[MODEL-MEDIUM] compile-flags: -C code-model=medium
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen/ehcontguard_disabled.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ compile-flags:

#![crate_type = "lib"]

// A basic test function.
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/naked-fn/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//@[win_i686] compile-flags: --target i686-pc-windows-gnu
//@[win_i686] needs-llvm-components: x86
//@[macos] compile-flags: --target aarch64-apple-darwin
//@[macos] needs-llvm-components: arm
//@[macos] needs-llvm-components: aarch64
//@[thumb] compile-flags: --target thumbv7em-none-eabi
//@[thumb] needs-llvm-components: arm

Expand Down
6 changes: 3 additions & 3 deletions tests/codegen/sanitizer/address-sanitizer-globals-tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
//@ only-linux
//
//@ revisions:ASAN ASAN-FAT-LTO
//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static
//@[ASAN] compile-flags:
//@[ASAN-FAT-LTO] compile-flags: -Cprefer-dynamic=false -Clto=fat
//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static
// [ASAN] no extra compile-flags
//@[ASAN-FAT-LTO] compile-flags: -Cprefer-dynamic=false -Clto=fat

#![crate_type = "staticlib"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0

#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-generalize-pointers

#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zsanitizer-cfi-generalize-pointers

#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers

#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0

#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components:
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/sanitizer/memory-track-origins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ revisions:MSAN-0 MSAN-1 MSAN-2 MSAN-1-LTO MSAN-2-LTO
//
//@ compile-flags: -Zsanitizer=memory -Ctarget-feature=-crt-static
//@[MSAN-0] compile-flags:
// [MSAN-0] no extra compile-flags
//@[MSAN-1] compile-flags: -Zsanitizer-memory-track-origins=1
//@[MSAN-2] compile-flags: -Zsanitizer-memory-track-origins
//@[MSAN-1-LTO] compile-flags: -Zsanitizer-memory-track-origins=1 -C lto=fat
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/ub-checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// but ub-checks are explicitly disabled.

//@ revisions: DEBUG NOCHECKS
//@ [DEBUG] compile-flags:
// [DEBUG] no extra compile-flags
//@ [NOCHECKS] compile-flags: -Zub-checks=no
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=yes

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/errors/remap-path-prefix-sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ compile-flags: -g -Ztranslate-remapped-path-to-local-path=yes
//@ [with-remap]compile-flags: --remap-path-prefix={{rust-src-base}}=remapped
//@ [with-remap]compile-flags: --remap-path-prefix={{src-base}}=remapped-tests-ui
//@ [without-remap]compile-flags:
// [without-remap] no extra compile-flags

// The $SRC_DIR*.rs:LL:COL normalisation doesn't kick in automatically
// as the remapped revision will not begin with $SRC_DIR_REAL,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/errors/wrong-target-spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// checks that such invalid target specs are rejected by the compiler.
// See https://github.com/rust-lang/rust/issues/33329

// ignore-tidy-target-specific-tests
//@ needs-llvm-components: x86
//@ compile-flags: --target x86_64_unknown-linux-musl

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/linkage-attr/incompatible-flavor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: --target=x86_64-unknown-linux-gnu -C linker-flavor=msvc --crate-type=rlib
//@ needs-llvm-components:
//@ needs-llvm-components: x86

#![feature(no_core)]
#![no_core]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/linkage-attr/unstable-flavor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//
//@ revisions: bpf ptx
//@ [bpf] compile-flags: --target=bpfel-unknown-none -C linker-flavor=bpf --crate-type=rlib
//@ [bpf] needs-llvm-components:
//@ [bpf] needs-llvm-components: bpf
//@ [ptx] compile-flags: --target=nvptx64-nvidia-cuda -C linker-flavor=ptx --crate-type=rlib
//@ [ptx] needs-llvm-components:
//@ [ptx] needs-llvm-components: nvptx

#![feature(no_core)]
#![no_core]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/target_modifiers/defaults_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//@ needs-llvm-components: x86

//@ revisions: ok ok_explicit error
//@[ok] compile-flags:
// [ok] no extra compile-flags
//@[ok_explicit] compile-flags: -Zreg-struct-return=false
//@[error] compile-flags: -Zreg-struct-return=true
//@[ok] check-pass
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/target_modifiers/incompatible_fixedx18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ revisions:allow_match allow_mismatch error_generated
//@[allow_match] compile-flags: -Zfixed-x18
//@[allow_mismatch] compile-flags: -Cunsafe-allow-abi-mismatch=fixed-x18
//@[error_generated] compile-flags:
// [error_generated] no extra compile-flags
//@[allow_mismatch] check-pass
//@[allow_match] check-pass

Expand Down
Loading
Loading