diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index c8aa7c04585c8..b633d0c35180e 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -685,7 +685,8 @@ pub fn codegen_crate( tcx: TyCtxt<'_>, target_cpu: String, ) -> OngoingCodegen { - if tcx.sess.target.need_explicit_cpu && tcx.sess.opts.cg.target_cpu.is_none() { + if tcx.sess.target.requires_explicit_and_consistent_cpu && tcx.sess.opts.cg.target_cpu.is_none() + { // The target has no default cpu, but none is set explicitly tcx.dcx().emit_fatal(errors::CpuRequired); } diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index fac7b6c21f60c..8df7d19835621 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -112,17 +112,29 @@ metadata_incompatible_target_modifiers = metadata_incompatible_target_modifiers_help_allow = if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error metadata_incompatible_target_modifiers_help_fix = set `{$flag_name_prefixed}={$extern_value}` in this crate or `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}` -metadata_incompatible_target_modifiers_help_fix_l_missed = set `{$flag_name_prefixed}={$extern_value}` in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}` +metadata_incompatible_target_modifiers_help_fix_l_missed = set {$value_len -> + [0] `{$flag_name_prefixed}` + *[other] `{$flag_name_prefixed}={$extern_value}` + } in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}` -metadata_incompatible_target_modifiers_help_fix_r_missed = unset `{$flag_name_prefixed}` in this crate or set `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}` +metadata_incompatible_target_modifiers_help_fix_r_missed = unset `{$flag_name_prefixed}` in this crate or set {$value_len -> + [0] `{$flag_name_prefixed}` + *[other] `{$flag_name_prefixed}={$local_value}` + } in `{$extern_crate}` metadata_incompatible_target_modifiers_l_missed = mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}` - .note = unset `{$flag_name_prefixed}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}` + .note = `{$flag_name_prefixed}` is unset in this crate which is incompatible with {$value_len -> + [0] `{$flag_name_prefixed}` being set + *[other] `{$flag_name_prefixed}={$extern_value}` + } in dependency `{$extern_crate}` .help = the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely metadata_incompatible_target_modifiers_r_missed = mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}` - .note = `{$flag_name_prefixed}={$local_value}` in this crate is incompatible with unset `{$flag_name_prefixed}` in dependency `{$extern_crate}` + .note = {$value_len -> + [0] `{$flag_name_prefixed}` being set + *[other] `{$flag_name_prefixed}={$local_value}` + } in this crate is incompatible with `{$flag_name_prefixed}` being unset in dependency `{$extern_crate}` .help = the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely metadata_incompatible_with_immediate_abort = diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 4000f12459a90..b8407ebe869f7 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -391,6 +391,7 @@ impl CStore { flag_name, flag_name_prefixed, extern_value: extern_value.to_string(), + value_len: extern_value.len(), }) } (Some(local_value), None) => { @@ -401,6 +402,7 @@ impl CStore { flag_name, flag_name_prefixed, local_value: local_value.to_string(), + value_len: local_value.len(), }) } (None, None) => panic!("Incorrect target modifiers report_diff(None, None)"), diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 2702c4498df6f..036c7db9db28a 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -576,6 +576,7 @@ pub struct IncompatibleTargetModifiersLMissed { pub flag_name: String, pub flag_name_prefixed: String, pub extern_value: String, + pub value_len: usize, } #[derive(Diagnostic)] @@ -592,6 +593,7 @@ pub struct IncompatibleTargetModifiersRMissed { pub flag_name: String, pub flag_name_prefixed: String, pub local_value: String, + pub value_len: usize, } #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 21fa3321a30ad..69fcf2beb687b 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -125,6 +125,20 @@ mod target_modifier_consistency_check { } true } + pub(super) fn target_cpu( + sess: &Session, + l: &TargetModifier, + r: Option<&TargetModifier>, + ) -> bool { + if sess.target.requires_explicit_and_consistent_cpu { + if let Some(r) = r { + return l.extend().tech_value == r.extend().tech_value; + } else { + return false; + } + } + true + } } impl TargetModifier { @@ -147,7 +161,11 @@ impl TargetModifier { } _ => {} }, - _ => {} + OptionsTargetModifiers::CodegenOptions(codegen) => match codegen { + CodegenOptionsTargetModifiers::target_cpu => { + return target_modifier_consistency_check::target_cpu(sess, self, other); + } + }, }; match other { Some(other) => self.extend().tech_value == other.extend().tech_value, @@ -2216,7 +2234,7 @@ options! { symbol_mangling_version: Option = (None, parse_symbol_mangling_version, [TRACKED], "which mangling version to use for symbol names ('legacy' (default), 'v0', or 'hashed')"), - target_cpu: Option = (None, parse_opt_string, [TRACKED], + target_cpu: Option = (None, parse_opt_string, [TRACKED TARGET_MODIFIER], "select target processor (`rustc --print target-cpus` for details)"), target_feature: String = (String::new(), parse_target_feature, [TRACKED], "target specific attributes. (`rustc --print target-features` for details). \ diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs index 20fbb687b3080..0248d2f4c1303 100644 --- a/compiler/rustc_target/src/spec/json.rs +++ b/compiler/rustc_target/src/spec/json.rs @@ -117,7 +117,7 @@ impl Target { forward!(link_env_remove); forward!(asm_args); forward!(cpu); - forward!(need_explicit_cpu); + forward!(requires_explicit_and_consistent_cpu); forward!(features); forward!(dynamic_linking); forward_opt!(direct_access_external_data); @@ -321,7 +321,7 @@ impl ToJson for Target { target_option_val!(link_env_remove); target_option_val!(asm_args); target_option_val!(cpu); - target_option_val!(need_explicit_cpu); + target_option_val!(requires_explicit_and_consistent_cpu); target_option_val!(features); target_option_val!(dynamic_linking); target_option_val!(direct_access_external_data); @@ -544,7 +544,7 @@ struct TargetSpecJson { link_env_remove: Option]>>, asm_args: Option]>>, cpu: Option>, - need_explicit_cpu: Option, + requires_explicit_and_consistent_cpu: Option, features: Option>, dynamic_linking: Option, direct_access_external_data: Option, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 89c9fdc935cc5..1263d51fb0a8b 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2262,9 +2262,10 @@ pub struct TargetOptions { /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults /// to "generic". pub cpu: StaticCow, - /// Whether a cpu needs to be explicitly set. - /// Set to true if there is no default cpu. Defaults to false. - pub need_explicit_cpu: bool, + /// Signals that the cpu needs to be explicitly set and be consistent when + /// multiple crates are linked together. Internally modifies `-Ctarget-cpu` + /// to act as a target modifier. Defaults to false. + pub requires_explicit_and_consistent_cpu: bool, /// Default (Rust) target features to enable for this target. These features /// overwrite `-Ctarget-cpu` but can be overwritten with `-Ctarget-features`. /// Corresponds to `llc -mattr=$llvm_features` where `$llvm_features` is the @@ -2722,7 +2723,7 @@ impl Default for TargetOptions { link_script: None, asm_args: cvs![], cpu: "generic".into(), - need_explicit_cpu: false, + requires_explicit_and_consistent_cpu: false, features: "".into(), direct_access_external_data: None, dynamic_linking: false, diff --git a/compiler/rustc_target/src/spec/targets/amdgcn_amd_amdhsa.rs b/compiler/rustc_target/src/spec/targets/amdgcn_amd_amdhsa.rs index 828d853ac65ec..e00321e5a0da7 100644 --- a/compiler/rustc_target/src/spec/targets/amdgcn_amd_amdhsa.rs +++ b/compiler/rustc_target/src/spec/targets/amdgcn_amd_amdhsa.rs @@ -23,7 +23,7 @@ pub(crate) fn target() -> Target { // There are many CPUs, one for each hardware generation. // Require to set one explicitly as there is no good default. - need_explicit_cpu: true, + requires_explicit_and_consistent_cpu: true, max_atomic_width: Some(64), diff --git a/compiler/rustc_target/src/spec/targets/avr_none.rs b/compiler/rustc_target/src/spec/targets/avr_none.rs index eaf4e956f55ec..aacc4fc82e141 100644 --- a/compiler/rustc_target/src/spec/targets/avr_none.rs +++ b/compiler/rustc_target/src/spec/targets/avr_none.rs @@ -25,7 +25,7 @@ pub(crate) fn target() -> Target { max_atomic_width: Some(16), atomic_cas: false, relocation_model: RelocModel::Static, - need_explicit_cpu: true, + requires_explicit_and_consistent_cpu: true, ..TargetOptions::default() }, } diff --git a/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs b/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs index 87c2693e9877f..5c0d9a81b25c1 100644 --- a/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs +++ b/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs @@ -23,6 +23,9 @@ pub(crate) fn target() -> Target { // With `ptx-linker` approach, it can be later overridden via link flags. cpu: "sm_30".into(), + // The target cpu for NVPTX must be set manually and be consistent + // across crates linked together. + requires_explicit_and_consistent_cpu: true, // FIXME: create tests for the atomics. max_atomic_width: Some(64), diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index 90f46b5376e01..462dfd51eb312 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -115,7 +115,6 @@ ENV TARGETS=$TARGETS,wasm32-wasip2 ENV TARGETS=$TARGETS,wasm32v1-none ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32 ENV TARGETS=$TARGETS,x86_64-fortanix-unknown-sgx -ENV TARGETS=$TARGETS,nvptx64-nvidia-cuda ENV TARGETS=$TARGETS,armv7-unknown-linux-gnueabi ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabi ENV TARGETS=$TARGETS,i686-unknown-freebsd diff --git a/src/ci/docker/host-x86_64/test-various/Dockerfile b/src/ci/docker/host-x86_64/test-various/Dockerfile index 9b1bf6c0df99d..eab99f9ebaf08 100644 --- a/src/ci/docker/host-x86_64/test-various/Dockerfile +++ b/src/ci/docker/host-x86_64/test-various/Dockerfile @@ -71,12 +71,6 @@ ENV WASM_WASIP_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $ tests/assembly-llvm \ library/core -ENV NVPTX_TARGETS=nvptx64-nvidia-cuda -ENV NVPTX_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $NVPTX_TARGETS \ - tests/run-make \ - tests/run-make-cargo \ - tests/assembly-llvm - ENV MUSL_TARGETS=x86_64-unknown-linux-musl \ CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc \ CXX_x86_64_unknown_linux_musl=x86_64-linux-musl-g++ diff --git a/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md b/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md index 2d9fc85dad33d..e37e1abae41f7 100644 --- a/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md +++ b/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md @@ -29,7 +29,8 @@ It is generally necessary to specify the target, such as `-C target-cpu=sm_89`, One can use `-C target-feature=+ptx80` to choose a later PTX version without changing the target (the default in this case, `ptx78`, requires CUDA driver version 11.8, while `ptx80` would require driver version 12.0). Later PTX versions may allow more efficient code generation. -Although Rust follows LLVM in representing `ptx*` and `sm_*` as target features, they should be thought of as having crate granularity, set via (either via `-Ctarget-cpu` and optionally `-Ctarget-feature`). +For this target, the compiler enforces that all crates built into a binary use the same value for `-C target-cpu`. Therefore, it is necessary to manually build `core` every time a crate is compiled. This can be done by adding the flag `-Z build-std=core` when invoking cargo. +Although Rust follows LLVM in representing `ptx*` and `sm_*` as target features, they should also be thought of as having binary granularity. However, this is not enforced by the compiler. When building crates together, the same value for all crates should be set via `-C target-feature`. While the compiler accepts `#[target_feature(enable = "ptx80", enable = "sm_89")]`, it is not supported, may not behave as intended, and may become erroneous in the future. ## Building Rust kernels diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index b461a24a06168..51a08b2fe06b5 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -426,3 +426,10 @@ pub fn sysroot() -> PathBuf { let path = rustc().print("sysroot").run().stdout_utf8(); PathBuf::from_str(path.trim()).unwrap() } + +// Get the inner Command +impl AsRef for Rustc { + fn as_ref(&self) -> &Command { + &self.cmd + } +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5253dc04a93e2..0f48c2e1e6d53 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -8,7 +8,6 @@ mod command; mod macros; -mod util; pub mod artifact_names; pub mod assertion_helpers; @@ -22,6 +21,7 @@ pub mod scoped_run; pub mod string; pub mod symbols; pub mod targets; +pub mod util; // Internally we call our fs-related support module as `fs`, but re-export its content as `rfs` // to tests to avoid colliding with commonly used `use std::fs;`. diff --git a/src/tools/run-make-support/src/util.rs b/src/tools/run-make-support/src/util.rs index af01758447b93..c6dfa859d1167 100644 --- a/src/tools/run-make-support/src/util.rs +++ b/src/tools/run-make-support/src/util.rs @@ -7,11 +7,7 @@ use crate::path_helpers::cwd; /// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the /// executed command, failure location, output status and stdout/stderr, and abort the process with /// exit code `1`. -pub(crate) fn handle_failed_output( - cmd: &Command, - output: CompletedProcess, - caller_line_number: u32, -) -> ! { +pub fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! { if output.status().success() { eprintln!("command unexpectedly succeeded at line {caller_line_number}"); } else { diff --git a/tests/assembly-llvm/asm/nvptx-types.rs b/tests/assembly-llvm/asm/nvptx-types.rs index 1cb176cf5148a..21314392a7a9a 100644 --- a/tests/assembly-llvm/asm/nvptx-types.rs +++ b/tests/assembly-llvm/asm/nvptx-types.rs @@ -1,7 +1,8 @@ //@ add-minicore //@ assembly-output: emit-asm -//@ compile-flags: --target nvptx64-nvidia-cuda +//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@ needs-llvm-components: nvptx +//@ ignore-backends: gcc #![feature(no_core, asm_experimental_arch)] #![crate_type = "rlib"] diff --git a/tests/assembly-llvm/auxiliary/non-inline-dependency.rs b/tests/assembly-llvm/auxiliary/non-inline-dependency.rs index 57f3ee87cdb9d..99ea46eb70a50 100644 --- a/tests/assembly-llvm/auxiliary/non-inline-dependency.rs +++ b/tests/assembly-llvm/auxiliary/non-inline-dependency.rs @@ -1,14 +1,29 @@ -#![no_std] -#![deny(warnings)] +//@ add-minicore +//@ no-prefer-dynamic +//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc +#![feature(no_core, intrinsics)] +#![crate_type = "rlib"] +#![no_core] + +extern crate minicore; +use minicore::*; + +#[rustc_intrinsic] +pub const fn wrapping_mul(a: T, b: T) -> T; + +#[rustc_intrinsic] +pub const fn mul_with_overflow(x: T, y: T) -> (T, bool); #[inline(never)] #[no_mangle] pub fn wrapping_external_fn(a: u32) -> u32 { - a.wrapping_mul(a) + wrapping_mul(a, a) } #[inline(never)] #[no_mangle] -pub fn panicking_external_fn(a: u32) -> u32 { - a * a +pub fn overflowing_external_fn(a: u32) -> u32 { + mul_with_overflow(a, a).0 } diff --git a/tests/assembly-llvm/nvptx-arch-default.rs b/tests/assembly-llvm/nvptx-arch-default.rs index 22b4a680e322c..9d06a7ce23d77 100644 --- a/tests/assembly-llvm/nvptx-arch-default.rs +++ b/tests/assembly-llvm/nvptx-arch-default.rs @@ -1,11 +1,9 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -//@ only-nvptx64 - -#![no_std] - -//@ aux-build: breakpoint-panic-handler.rs -extern crate breakpoint_panic_handler; +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type cdylib -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc +#![feature(no_core)] +#![no_core] // Verify default target arch with ptx-linker. // CHECK: .target sm_30 diff --git a/tests/assembly-llvm/nvptx-arch-emit-asm.rs b/tests/assembly-llvm/nvptx-arch-emit-asm.rs index e47f8e78e3679..855b5be085930 100644 --- a/tests/assembly-llvm/nvptx-arch-emit-asm.rs +++ b/tests/assembly-llvm/nvptx-arch-emit-asm.rs @@ -1,8 +1,9 @@ //@ assembly-output: emit-asm -//@ compile-flags: --crate-type rlib -//@ only-nvptx64 - -#![no_std] +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type rlib -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc +#![feature(no_core)] +#![no_core] // Verify default arch without ptx-linker involved. // CHECK: .target sm_30 diff --git a/tests/assembly-llvm/nvptx-arch-link-arg.rs b/tests/assembly-llvm/nvptx-arch-link-arg.rs index 3432e6161bf14..e2055d0d37ca6 100644 --- a/tests/assembly-llvm/nvptx-arch-link-arg.rs +++ b/tests/assembly-llvm/nvptx-arch-link-arg.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C link-arg=--arch=sm_60 +//@ compile-flags: --crate-type cdylib -Ctarget-cpu=sm_60 -C link-arg=--arch=sm_60 //@ only-nvptx64 //@ ignore-nvptx64 diff --git a/tests/assembly-llvm/nvptx-arch-target-cpu.rs b/tests/assembly-llvm/nvptx-arch-target-cpu.rs index e02ad0d558a96..7226bb6e4c173 100644 --- a/tests/assembly-llvm/nvptx-arch-target-cpu.rs +++ b/tests/assembly-llvm/nvptx-arch-target-cpu.rs @@ -1,11 +1,9 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_50 -//@ only-nvptx64 - -#![no_std] - -//@ aux-build: breakpoint-panic-handler.rs -extern crate breakpoint_panic_handler; +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type cdylib -C target-cpu=sm_50 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc +#![feature(no_core)] +#![no_core] // Verify target arch override via `target-cpu`. // CHECK: .target sm_50 diff --git a/tests/assembly-llvm/nvptx-atomics.rs b/tests/assembly-llvm/nvptx-atomics.rs index 52b8c86d8a9c1..437dbe00300ad 100644 --- a/tests/assembly-llvm/nvptx-atomics.rs +++ b/tests/assembly-llvm/nvptx-atomics.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib +//@ compile-flags: --crate-type cdylib -Ctarget-cpu=sm_30 //@ only-nvptx64 //@ ignore-nvptx64 diff --git a/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs b/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs index 6f5ef792e9b34..924540f40b06d 100644 --- a/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs +++ b/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs @@ -1,6 +1,7 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -//@ only-nvptx64 +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type cdylib -C target-cpu=sm_86 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc // The PTX ABI stability is tied to major versions of the PTX ISA // These tests assume major version 7 diff --git a/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs b/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs index 02ec9facee7a8..36b481e3ee338 100644 --- a/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs +++ b/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs @@ -1,6 +1,7 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -//@ only-nvptx64 +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type cdylib -C target-cpu=sm_86 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc // The PTX ABI stability is tied to major versions of the PTX ISA // These tests assume major version 7 diff --git a/tests/assembly-llvm/nvptx-internalizing.rs b/tests/assembly-llvm/nvptx-internalizing.rs index 0acfd5c244319..734218a24b4b0 100644 --- a/tests/assembly-llvm/nvptx-internalizing.rs +++ b/tests/assembly-llvm/nvptx-internalizing.rs @@ -1,16 +1,17 @@ +//@ add-minicore //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -//@ only-nvptx64 -//@ ignore-nvptx64 +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type cdylib -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc -#![feature(abi_ptx)] -#![no_std] +#![feature(abi_ptx, no_core, intrinsics)] +#![no_core] -//@ aux-build: breakpoint-panic-handler.rs -extern crate breakpoint_panic_handler; +extern crate minicore; +use minicore::*; -//@ aux-build: non-inline-dependency.rs -extern crate non_inline_dependency as dep; +#[rustc_intrinsic] +pub const unsafe fn unchecked_add(x: T, y: T) -> T; // Verify that no extra function declarations are present. // CHECK-NOT: .func @@ -19,7 +20,7 @@ extern crate non_inline_dependency as dep; #[no_mangle] pub unsafe extern "ptx-kernel" fn top_kernel(a: *const u32, b: *mut u32) { // CHECK: add.s32 %{{r[0-9]+}}, %{{r[0-9]+}}, 5; - *b = *a + 5; + *b = unchecked_add(*a, 5); } // Verify that no extra function definitions are here. diff --git a/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs b/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs index 00f6fe9332d94..b369d672e5522 100644 --- a/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs +++ b/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs @@ -1,6 +1,7 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -//@ only-nvptx64 +//@ compile-flags: --target=nvptx64-nvidia-cuda --crate-type cdylib -C target-cpu=sm_86 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc // The following ABI tests are made with nvcc 11.6 does. // diff --git a/tests/assembly-llvm/nvptx-linking-binary.rs b/tests/assembly-llvm/nvptx-linking-binary.rs index 3b50b472ab10e..a3aea32a4400a 100644 --- a/tests/assembly-llvm/nvptx-linking-binary.rs +++ b/tests/assembly-llvm/nvptx-linking-binary.rs @@ -1,21 +1,23 @@ +//@ add-minicore //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type bin +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type bin -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx //@ only-nvptx64 //@ ignore-nvptx64 -#![feature(abi_ptx)] +#![feature(abi_ptx, no_core)] #![no_main] -#![no_std] +#![no_core] -//@ aux-build: breakpoint-panic-handler.rs -extern crate breakpoint_panic_handler; +extern crate minicore; +use minicore::*; //@ aux-build: non-inline-dependency.rs extern crate non_inline_dependency as dep; // Make sure declarations are there. // CHECK: .func (.param .b32 func_retval0) wrapping_external_fn -// CHECK: .func (.param .b32 func_retval0) panicking_external_fn +// CHECK: .func (.param .b32 func_retval0) overflowing_external_fn // CHECK-LABEL: .visible .entry top_kernel( #[no_mangle] @@ -26,9 +28,9 @@ pub unsafe extern "ptx-kernel" fn top_kernel(a: *const u32, b: *mut u32) { let lhs = dep::wrapping_external_fn(*a); // CHECK: call.uni (retval0), - // CHECK-NEXT: panicking_external_fn + // CHECK-NEXT: overflowing_external_fn // CHECK: ld.param.b32 %[[RHS:r[0-9]+]], [retval0+0]; - let rhs = dep::panicking_external_fn(*a); + let rhs = dep::overflowing_external_fn(*a); // CHECK: add.s32 %[[RES:r[0-9]+]], %[[RHS]], %[[LHS]]; // CHECK: st.global.u32 [%{{rd[0-9]+}}], %[[RES]]; @@ -37,4 +39,4 @@ pub unsafe extern "ptx-kernel" fn top_kernel(a: *const u32, b: *mut u32) { // Verify that external function bodies are available. // CHECK: .func (.param .b32 func_retval0) wrapping_external_fn -// CHECK: .func (.param .b32 func_retval0) panicking_external_fn +// CHECK: .func (.param .b32 func_retval0) overflowing_external_fn diff --git a/tests/assembly-llvm/nvptx-linking-cdylib.rs b/tests/assembly-llvm/nvptx-linking-cdylib.rs index 9742e26fb31a9..0dbf92ada8435 100644 --- a/tests/assembly-llvm/nvptx-linking-cdylib.rs +++ b/tests/assembly-llvm/nvptx-linking-cdylib.rs @@ -1,39 +1,44 @@ +//@ add-minicore //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -//@ only-nvptx64 -//@ ignore-nvptx64 +//@ compile-flags: --target nvptx64-nvidia-cuda --crate-type cdylib -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc -#![feature(abi_ptx)] -#![no_std] +#![feature(abi_ptx, no_core, intrinsics)] +#![no_main] +#![no_core] -//@ aux-build: breakpoint-panic-handler.rs -extern crate breakpoint_panic_handler; +extern crate minicore; +use minicore::*; //@ aux-build: non-inline-dependency.rs extern crate non_inline_dependency as dep; +#[rustc_intrinsic] +pub const unsafe fn unchecked_add(x: T, y: T) -> T; + // Make sure declarations are there. -// CHECK: .func (.param .b32 func_retval0) wrapping_external_fn -// CHECK: .func (.param .b32 func_retval0) panicking_external_fn +// CHECK: .func (.param .{{[ubs]}}32 func_retval0) wrapping_external_fn +// CHECK: .func (.param .{{[ubs]}}32 func_retval0) overflowing_external_fn // CHECK-LABEL: .visible .entry top_kernel( #[no_mangle] pub unsafe extern "ptx-kernel" fn top_kernel(a: *const u32, b: *mut u32) { // CHECK: call.uni (retval0), - // CHECK-NEXT: wrapping_external_fn - // CHECK: ld.param.b32 %[[LHS:r[0-9]+]], [retval0+0]; + // CHECK: wrapping_external_fn + // CHECK: ld.param.{{[ubs]}}32 %[[LHS:r[0-9]+]], [retval0]; let lhs = dep::wrapping_external_fn(*a); // CHECK: call.uni (retval0), - // CHECK-NEXT: panicking_external_fn - // CHECK: ld.param.b32 %[[RHS:r[0-9]+]], [retval0+0]; - let rhs = dep::panicking_external_fn(*a); + // CHECK: overflowing_external_fn + // CHECK: ld.param.{{[ubs]}}32 %[[RHS:r[0-9]+]], [retval0]; + let rhs = dep::overflowing_external_fn(*a); - // CHECK: add.s32 %[[RES:r[0-9]+]], %[[RHS]], %[[LHS]]; - // CHECK: st.global.u32 [%{{rd[0-9]+}}], %[[RES]]; - *b = lhs + rhs; + // CHECK: add.{{[us]}}32 %[[RES:r[0-9]+]], %[[RHS]], %[[LHS]]; + // CHECK: st.global.{{[ubs]}}32 [%{{rd[0-9]+}}], %[[RES]]; + *b = unchecked_add(lhs, rhs); } // Verify that external function bodies are available. -// CHECK: .func (.param .b32 func_retval0) wrapping_external_fn -// CHECK: .func (.param .b32 func_retval0) panicking_external_fn +// CHECK: .func (.param .{{[ubs]}}32 func_retval0) wrapping_external_fn +// CHECK: .func (.param .{{[ubs]}}32 func_retval0) overflowing_external_fn diff --git a/tests/assembly-llvm/nvptx-safe-naming.rs b/tests/assembly-llvm/nvptx-safe-naming.rs index 85415b6ca5b5a..9b413cc870da7 100644 --- a/tests/assembly-llvm/nvptx-safe-naming.rs +++ b/tests/assembly-llvm/nvptx-safe-naming.rs @@ -1,15 +1,20 @@ +//@ add-minicore //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -//@ only-nvptx64 +//@ compile-flags: --target=nvptx64-nvidia-cuda --crate-type cdylib -Ctarget-cpu=sm_30 +//@ needs-llvm-components: nvptx //@ revisions: LLVM20 LLVM21 //@ [LLVM21] min-llvm-version: 21 //@ [LLVM20] max-llvm-major-version: 20 +//@ ignore-backends: gcc -#![feature(abi_ptx)] -#![no_std] +#![feature(abi_ptx, no_core, intrinsics)] +#![no_core] -//@ aux-build: breakpoint-panic-handler.rs -extern crate breakpoint_panic_handler; +extern crate minicore; +use minicore::*; + +#[rustc_intrinsic] +pub const fn wrapping_mul(a: T, b: T) -> T; // Verify function name doesn't contain unacceaptable characters. // CHECK: .func (.param .b32 func_retval0) [[IMPL_FN:[a-zA-Z0-9$_]+square]] @@ -25,6 +30,7 @@ pub unsafe extern "ptx-kernel" fn top_kernel(a: *const u32, b: *mut u32) { pub mod deep { pub mod private { + use crate::wrapping_mul; pub struct MyStruct(T); impl MyStruct { @@ -34,7 +40,7 @@ pub mod deep { #[inline(never)] pub fn square(&self) -> u32 { - self.0.wrapping_mul(self.0) + wrapping_mul(self.0, self.0) } } } diff --git a/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs b/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs index 9f182985d1573..7d67b3cb64bea 100644 --- a/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs +++ b/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs @@ -99,7 +99,7 @@ //@ [r47] needs-llvm-components: mips //@ [r48] compile-flags: --target mipsel-unknown-linux-musl //@ [r48] needs-llvm-components: mips -//@ [r49] compile-flags: --target nvptx64-nvidia-cuda +//@ [r49] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@ [r49] needs-llvm-components: nvptx //@ [r50] compile-flags: --target powerpc-unknown-linux-gnu //@ [r50] needs-llvm-components: powerpc diff --git a/tests/assembly-llvm/targets/targets-nvptx.rs b/tests/assembly-llvm/targets/targets-nvptx.rs index 69d576de696c3..5b2910b37f6e8 100644 --- a/tests/assembly-llvm/targets/targets-nvptx.rs +++ b/tests/assembly-llvm/targets/targets-nvptx.rs @@ -2,9 +2,9 @@ //@ assembly-output: emit-asm // ignore-tidy-linelength //@ revisions: nvptx64_nvidia_cuda -//@ [nvptx64_nvidia_cuda] compile-flags: --target nvptx64-nvidia-cuda +//@ [nvptx64_nvidia_cuda] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@ [nvptx64_nvidia_cuda] needs-llvm-components: nvptx - +//@ ignore-backends: gcc // Sanity-check that each target can produce assembly code. #![feature(no_core, lang_items)] diff --git a/tests/codegen-llvm/gpu-kernel-abi.rs b/tests/codegen-llvm/gpu-kernel-abi.rs index 828b10c37880d..bc750f2f1b103 100644 --- a/tests/codegen-llvm/gpu-kernel-abi.rs +++ b/tests/codegen-llvm/gpu-kernel-abi.rs @@ -4,8 +4,9 @@ //@ revisions: amdgpu nvptx //@ [amdgpu] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 //@ [amdgpu] needs-llvm-components: amdgpu -//@ [nvptx] compile-flags: --crate-type=rlib --target=nvptx64-nvidia-cuda +//@ [nvptx] compile-flags: --crate-type=rlib --target=nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@ [nvptx] needs-llvm-components: nvptx +//@ ignore-backends: gcc #![feature(no_core, lang_items, abi_gpu_kernel)] #![no_core] diff --git a/tests/run-make/target-cpu-is-target-modifier/amdgcn-amd-amdhsa b/tests/run-make/target-cpu-is-target-modifier/amdgcn-amd-amdhsa new file mode 100644 index 0000000000000..5b771264c5935 --- /dev/null +++ b/tests/run-make/target-cpu-is-target-modifier/amdgcn-amd-amdhsa @@ -0,0 +1,3 @@ +CHECK-LABEL: target triple = "amdgcn-amd-amdhsa" +CHECK-LABEL: define {{.*}} @foo() {{.*}} #0 +CHECK-LABEL: attributes #0 = {{.*}} "target-cpu"="gfx1100" {{.*}} diff --git a/tests/run-make/target-cpu-is-target-modifier/avr-none b/tests/run-make/target-cpu-is-target-modifier/avr-none new file mode 100644 index 0000000000000..06e5a2daf78db --- /dev/null +++ b/tests/run-make/target-cpu-is-target-modifier/avr-none @@ -0,0 +1,3 @@ +CHECK-LABEL: target triple = "avr-unknown-unknown" +CHECK-LABEL: define {{.*}} @foo() {{.*}} #0 +CHECK-LABEL: attributes #0 = {{.*}} "target-cpu"="atmega328p" {{.*}} diff --git a/tests/run-make/target-cpu-is-target-modifier/bar.rs b/tests/run-make/target-cpu-is-target-modifier/bar.rs new file mode 100644 index 0000000000000..dcbedcd9b5dff --- /dev/null +++ b/tests/run-make/target-cpu-is-target-modifier/bar.rs @@ -0,0 +1,5 @@ +#![feature(no_core)] +#![crate_type = "rlib"] +#![no_core] + +extern crate foo; diff --git a/tests/run-make/target-cpu-is-target-modifier/foo.rs b/tests/run-make/target-cpu-is-target-modifier/foo.rs new file mode 100644 index 0000000000000..a0fa55361fdca --- /dev/null +++ b/tests/run-make/target-cpu-is-target-modifier/foo.rs @@ -0,0 +1,29 @@ +#![feature(no_core, lang_items)] +#![no_core] +#![crate_type = "rlib"] + +#[lang = "pointee_sized"] +#[diagnostic::on_unimplemented( + message = "values of type `{Self}` may or may not have a size", + label = "may or may not have a known size" +)] +pub trait PointeeSized {} + +#[lang = "meta_sized"] +#[diagnostic::on_unimplemented( + message = "the size for values of type `{Self}` cannot be known", + label = "doesn't have a known size" +)] +pub trait MetaSized: PointeeSized {} + +#[lang = "sized"] +#[diagnostic::on_unimplemented( + message = "the size for values of type `{Self}` cannot be known at compilation time", + label = "doesn't have a size known at compile-time" +)] +pub trait Sized: MetaSized {} + +#[no_mangle] +pub fn foo() { + () +} diff --git a/tests/run-make/target-cpu-is-target-modifier/nvptx64-nvidia-cuda b/tests/run-make/target-cpu-is-target-modifier/nvptx64-nvidia-cuda new file mode 100644 index 0000000000000..0888d521a7e27 --- /dev/null +++ b/tests/run-make/target-cpu-is-target-modifier/nvptx64-nvidia-cuda @@ -0,0 +1,3 @@ +CHECK-LABEL: target triple = "nvptx64-nvidia-cuda" +CHECK-LABEL: define {{.*}} @foo() {{.*}} #0 +CHECK-LABEL: attributes #0 = {{.*}} "target-cpu"="sm_70" {{.*}} diff --git a/tests/run-make/target-cpu-is-target-modifier/rmake.rs b/tests/run-make/target-cpu-is-target-modifier/rmake.rs new file mode 100644 index 0000000000000..686117dd5525e --- /dev/null +++ b/tests/run-make/target-cpu-is-target-modifier/rmake.rs @@ -0,0 +1,90 @@ +//! This checks that the target-cpu set when compiling foo is correctly set as a target-modifier +//! and also correctly set as the target-cpu. +//! It does this for two scenarios: +//! `-Ctarget-cpu is only specified one time when compiling `foo` +//! `-Ctarget-cpu` is specified twice when compiling `foo` +//! In both cases the last `-Ctarget-cpu` argument must be set as target-cpu and target-modifier. +//! The `-Ctarget-cpu` target-modifier-value is checked by compiling `bar` which has `foo` as +//! a dependency. +//! The error message tells us the `-Ctarget-cpu` target-modifier-value. +//! The target-cpu value is checked by filechecking foo.ll. + +//@ ignore-backends: gcc + +use std::collections::BTreeMap; + +use run_make_support::*; + +fn main() { + let targets = BTreeMap::from([ + ("avr-none", ["at43usb320", "atmega328p"]), + ("amdgcn-amd-amdhsa", ["gfx900", "gfx1100"]), + ("nvptx64-nvidia-cuda", ["sm_60", "sm_70"]), + ]); + + for (target, target_cpus) in targets { + // compile foo with target_cpu[1] + let mut foo_rustc = rustc(); + foo_rustc + .target(target) + .target_cpu(target_cpus[1]) + .input("foo.rs") + .panic("abort") + .emit("llvm-ir,link") + .inspect(|cmd| { + assert_eq!( + cmd.get_args() + .filter(|arg| arg.to_str().is_some_and(|arg| arg.contains("-Ctarget-cpu"))) + .count(), + 1 + ); + }) + .run(); + verify(target, &target_cpus); + // compile foo with target_cpu[0] and target_cpu[1] + let mut foo_rustc = rustc(); + let cmd = foo_rustc + .target(target) + .target_cpu(target_cpus[0]) + .target_cpu(target_cpus[1]) + .input("foo.rs") + .panic("abort") + .emit("llvm-ir,link") + .inspect(|cmd| { + assert_eq!( + cmd.get_args() + .filter(|arg| arg.to_str().is_some_and(|arg| arg.contains("-Ctarget-cpu"))) + .count(), + 2 + ); + }) + .run(); + verify(target, &target_cpus); + } +} + +fn verify(target: &str, target_cpus: &[&str]) { + // verify that foo has target_cpu[1] set as modifier by compiling bar with target_cpu[0] + // FIXME: This is a little hacky, to query the target modifier by an error + // message. A way to read the value in the metadata would be preferrable. + // Also this test would then be usable with other targets than the ones above. + let mut bar_rustc = rustc(); + bar_rustc + .target(target) + .target_cpu(target_cpus[0]) + .input("bar.rs") + .panic("abort") + .run_fail() + .assert_stderr_contains( + "error: mixing `-Ctarget-cpu` will cause \ + an ABI mismatch in crate `bar`", + ) + .assert_stderr_contains(format!( + "`-Ctarget-cpu={}` in this crate is incompatible with \ + `-Ctarget-cpu={}` in dependency `foo`", + target_cpus[0], target_cpus[1] + )); + // verify that foo has target_cpu[1] set as target cpu by filechecking foo with llvm filecheck + let mut filecheck = llvm_filecheck(); + filecheck.patterns(target).input_file("foo.ll").run(); +} diff --git a/tests/run-make/target-specs/require-explicit-cpu.json b/tests/run-make/target-specs/require-explicit-cpu.json index 4f23b644d8cf6..2fddabb0dcc58 100644 --- a/tests/run-make/target-specs/require-explicit-cpu.json +++ b/tests/run-make/target-specs/require-explicit-cpu.json @@ -6,5 +6,5 @@ "target-pointer-width": 32, "arch": "x86", "os": "linux", - "need-explicit-cpu": true + "requires-explicit-and-consistent-cpu": true } diff --git a/tests/run-make/verify-requires-consistent-cpu/dependency.rs b/tests/run-make/verify-requires-consistent-cpu/dependency.rs new file mode 100644 index 0000000000000..c12c35de302a1 --- /dev/null +++ b/tests/run-make/verify-requires-consistent-cpu/dependency.rs @@ -0,0 +1,3 @@ +#![feature(no_core)] +#![crate_type = "rlib"] +#![no_core] diff --git a/tests/run-make/verify-requires-consistent-cpu/incompatible_target_cpu.rs b/tests/run-make/verify-requires-consistent-cpu/incompatible_target_cpu.rs new file mode 100644 index 0000000000000..bc32fc9c304b7 --- /dev/null +++ b/tests/run-make/verify-requires-consistent-cpu/incompatible_target_cpu.rs @@ -0,0 +1,5 @@ +#![feature(no_core)] +#![crate_type = "rlib"] +#![no_core] + +extern crate dependency; diff --git a/tests/run-make/verify-requires-consistent-cpu/rmake.rs b/tests/run-make/verify-requires-consistent-cpu/rmake.rs new file mode 100644 index 0000000000000..57a10630df089 --- /dev/null +++ b/tests/run-make/verify-requires-consistent-cpu/rmake.rs @@ -0,0 +1,107 @@ +//! Verifies that only for the targets mentioned in `must_fail` `-Ctarget-cpu` acts as a +//! target-modifier and for all others it does not. + +//@ ignore-backends: gcc + +use std::collections::BTreeSet; +use std::panic; + +use run_make_support::{llvm_components_contain, rustc, util}; + +fn main() { + let must_fail = BTreeSet::from(["avr-none", "amdgcn-amd-amdhsa", "nvptx64-nvidia-cuda"]); + let target_list = rustc().print("target-list").run().stdout_utf8(); + let targets: Vec<&str> = target_list.lines().collect(); + + // FIXME: We need to filter xtensa because of a data-layout mismatch + for target in targets.iter().filter(|&str| !str.contains("xtensa")) { + // FIXME: riscv targets list incompatible CPUs, so we hard-code the used + // target-cpus for them + let (first_target_cpu, second_target_cpu) = if target.contains("riscv32") { + if !llvm_components_contain("riscv") { + continue; + } + ("generic-rv32".to_string(), "rocket-rv32".to_string()) + } else if target.contains("riscv64") { + if !llvm_components_contain("riscv") { + continue; + } + ("generic-rv64".to_string(), "rocket-rv64".to_string()) + } else { + let mut cmd = rustc(); + let completed = cmd.target(target).print("target-cpus").run_unchecked(); + // We guard against missing LLVM components + if completed + .stderr_utf8() + .contains("error: could not create LLVM TargetMachine for triple") + { + continue; + } else if !completed.status().success() { + util::handle_failed_output( + cmd.as_ref(), + completed, + panic::Location::caller().line(), + ); + } + let output = completed.stdout_utf8(); + // Take the first two cpus which are not "native" + let mut cpus = output + .lines() + .skip(1) + .filter_map(|str| str.split_whitespace().next()) + .filter(|&str| str != "native") + .take(2); + ( + cpus.next() + .expect(format!("First target cpu was not found for {target}").as_str()) + .to_string(), + cpus.next() + .expect(format!("Second target cpu was not found for {target}").as_str()) + .to_string(), + ) + }; + + // Build depedency.rs the first target-cpu + let mut dep_cmd = rustc(); + dep_cmd.target(target).target_cpu(&first_target_cpu).input("dependency.rs").run(); + + if must_fail.contains(target) { + // Test targets where `-Ctarget-cpu` acts as a target modifier. + let mut allow_match = rustc(); + allow_match + .target(target) + .target_cpu(&first_target_cpu) + .input("incompatible_target_cpu.rs") + .panic("abort") + .run(); + let mut allow_mismatch = rustc(); + allow_mismatch + .target(target) + .target_cpu(&second_target_cpu) + .arg("-Cunsafe-allow-abi-mismatch=target-cpu") + .input("incompatible_target_cpu.rs") + .panic("abort") + .run(); + let mut error_generated = rustc(); + error_generated + .target(target) + .target_cpu(&second_target_cpu) + .input("incompatible_target_cpu.rs") + .panic("abort") + .run_fail() + .assert_stderr_contains( + "error: mixing `-Ctarget-cpu` will cause \ + an ABI mismatch in crate `incompatible_target_cpu`", + ); + } else { + // Test targets where `-Ctarget-cpu` does not act as a target modifier + // by testing that linking different target-cpus does not lead to an error. + let mut cmd = rustc(); + cmd.target(target) + .target_cpu(&second_target_cpu) + .input("incompatible_target_cpu.rs") + .panic("abort") + .run(); + } + } +} diff --git a/tests/ui/abi/cannot-be-called.rs b/tests/ui/abi/cannot-be-called.rs index 8d1a4ae0b557f..7c6e191a84ac6 100644 --- a/tests/ui/abi/cannot-be-called.rs +++ b/tests/ui/abi/cannot-be-called.rs @@ -23,7 +23,7 @@ So we test that they error in essentially all of the same places. //@ [amdgpu] needs-llvm-components: amdgpu //@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 --crate-type=rlib //@ [nvptx] needs-llvm-components: nvptx -//@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda --crate-type=rlib +//@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 --crate-type=rlib //@ ignore-backends: gcc #![no_core] #![feature( diff --git a/tests/ui/abi/cannot-be-coroutine.amdgpu.stderr b/tests/ui/abi/cannot-be-coroutine.amdgpu.stderr index a36ea0caa19eb..3aec8b33814df 100644 --- a/tests/ui/abi/cannot-be-coroutine.amdgpu.stderr +++ b/tests/ui/abi/cannot-be-coroutine.amdgpu.stderr @@ -11,10 +11,10 @@ LL + extern "gpu-kernel" fn async_kernel() { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.avr.stderr b/tests/ui/abi/cannot-be-coroutine.avr.stderr index 643a575bece15..777b82046e66b 100644 --- a/tests/ui/abi/cannot-be-coroutine.avr.stderr +++ b/tests/ui/abi/cannot-be-coroutine.avr.stderr @@ -11,10 +11,10 @@ LL + extern "avr-interrupt" fn avr() { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.i686.stderr b/tests/ui/abi/cannot-be-coroutine.i686.stderr index f618507df47d2..0db9cf86b908a 100644 --- a/tests/ui/abi/cannot-be-coroutine.i686.stderr +++ b/tests/ui/abi/cannot-be-coroutine.i686.stderr @@ -11,10 +11,10 @@ LL + extern "x86-interrupt" fn x86(_p: *mut ()) { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.msp430.stderr b/tests/ui/abi/cannot-be-coroutine.msp430.stderr index f2586c8cd9755..eba5ac212c736 100644 --- a/tests/ui/abi/cannot-be-coroutine.msp430.stderr +++ b/tests/ui/abi/cannot-be-coroutine.msp430.stderr @@ -11,10 +11,10 @@ LL + extern "msp430-interrupt" fn msp430() { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.nvptx.stderr b/tests/ui/abi/cannot-be-coroutine.nvptx.stderr index a36ea0caa19eb..3aec8b33814df 100644 --- a/tests/ui/abi/cannot-be-coroutine.nvptx.stderr +++ b/tests/ui/abi/cannot-be-coroutine.nvptx.stderr @@ -11,10 +11,10 @@ LL + extern "gpu-kernel" fn async_kernel() { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.riscv32.stderr b/tests/ui/abi/cannot-be-coroutine.riscv32.stderr index c5a8c3f60a382..03a96b8acc306 100644 --- a/tests/ui/abi/cannot-be-coroutine.riscv32.stderr +++ b/tests/ui/abi/cannot-be-coroutine.riscv32.stderr @@ -23,10 +23,10 @@ LL + extern "riscv-interrupt-s" fn riscv_s() { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.riscv64.stderr b/tests/ui/abi/cannot-be-coroutine.riscv64.stderr index c5a8c3f60a382..03a96b8acc306 100644 --- a/tests/ui/abi/cannot-be-coroutine.riscv64.stderr +++ b/tests/ui/abi/cannot-be-coroutine.riscv64.stderr @@ -23,10 +23,10 @@ LL + extern "riscv-interrupt-s" fn riscv_s() { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.rs b/tests/ui/abi/cannot-be-coroutine.rs index 239f5aa5c31fe..9ab72a1805ccb 100644 --- a/tests/ui/abi/cannot-be-coroutine.rs +++ b/tests/ui/abi/cannot-be-coroutine.rs @@ -19,7 +19,7 @@ //@ [amdgpu] needs-llvm-components: amdgpu //@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 --crate-type=rlib //@ [nvptx] needs-llvm-components: nvptx -//@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda --crate-type=rlib +//@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 --crate-type=rlib //@ ignore-backends: gcc #![no_core] #![feature( @@ -35,7 +35,7 @@ extern crate minicore; use minicore::*; // We ignore this error; implementing all of the async-related lang items is not worth it. -async fn vanilla(){ +async fn vanilla() { //~^ ERROR requires `ResumeTy` lang_item } diff --git a/tests/ui/abi/cannot-be-coroutine.x64.stderr b/tests/ui/abi/cannot-be-coroutine.x64.stderr index f618507df47d2..0db9cf86b908a 100644 --- a/tests/ui/abi/cannot-be-coroutine.x64.stderr +++ b/tests/ui/abi/cannot-be-coroutine.x64.stderr @@ -11,10 +11,10 @@ LL + extern "x86-interrupt" fn x86(_p: *mut ()) { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-be-coroutine.x64_win.stderr b/tests/ui/abi/cannot-be-coroutine.x64_win.stderr index f618507df47d2..0db9cf86b908a 100644 --- a/tests/ui/abi/cannot-be-coroutine.x64_win.stderr +++ b/tests/ui/abi/cannot-be-coroutine.x64_win.stderr @@ -11,10 +11,10 @@ LL + extern "x86-interrupt" fn x86(_p: *mut ()) { | error: requires `ResumeTy` lang_item - --> $DIR/cannot-be-coroutine.rs:38:19 + --> $DIR/cannot-be-coroutine.rs:38:20 | -LL | async fn vanilla(){ - | ___________________^ +LL | async fn vanilla() { + | ____________________^ LL | | LL | | } | |_^ diff --git a/tests/ui/abi/cannot-return.rs b/tests/ui/abi/cannot-return.rs index 9a5db30431b9f..a4562c82b4082 100644 --- a/tests/ui/abi/cannot-return.rs +++ b/tests/ui/abi/cannot-return.rs @@ -6,7 +6,7 @@ //@ [amdgpu] needs-llvm-components: amdgpu //@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 --crate-type=rlib //@ [nvptx] needs-llvm-components: nvptx -//@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda --crate-type=rlib +//@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 --crate-type=rlib #![no_core] #![feature(no_core, abi_gpu_kernel)] diff --git a/tests/ui/abi/compatibility.rs b/tests/ui/abi/compatibility.rs index 84294ab343111..9d90a442848ad 100644 --- a/tests/ui/abi/compatibility.rs +++ b/tests/ui/abi/compatibility.rs @@ -68,7 +68,7 @@ //@[csky] compile-flags: --target csky-unknown-linux-gnuabiv2 //@[csky] needs-llvm-components: csky //@ revisions: nvptx64 -//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda +//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@[nvptx64] needs-llvm-components: nvptx //@ ignore-backends: gcc #![feature(no_core, rustc_attrs, lang_items)] diff --git a/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs b/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs index d442c9317f64e..bcd1105861124 100644 --- a/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs +++ b/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs @@ -3,7 +3,7 @@ //@ compile-flags: --crate-type=rlib //@[AMDGPU] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx1100 //@[AMDGPU] needs-llvm-components: amdgpu -//@[NVPTX] compile-flags: --target nvptx64-nvidia-cuda +//@[NVPTX] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@[NVPTX] needs-llvm-components: nvptx //@ ignore-backends: gcc diff --git a/tests/ui/feature-gates/feature-gate-abi_ptx.rs b/tests/ui/feature-gates/feature-gate-abi_ptx.rs index 7f5935a54683c..a1e0e708a480b 100644 --- a/tests/ui/feature-gates/feature-gate-abi_ptx.rs +++ b/tests/ui/feature-gates/feature-gate-abi_ptx.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ needs-llvm-components: nvptx -//@ compile-flags: --target=nvptx64-nvidia-cuda --crate-type=rlib +//@ compile-flags: --target=nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 --crate-type=rlib //@ ignore-backends: gcc #![no_core] #![feature(no_core, lang_items)] diff --git a/tests/ui/linkage-attr/unstable-flavor.rs b/tests/ui/linkage-attr/unstable-flavor.rs index 5412e248f341f..5fc780528354b 100644 --- a/tests/ui/linkage-attr/unstable-flavor.rs +++ b/tests/ui/linkage-attr/unstable-flavor.rs @@ -5,8 +5,10 @@ //@ revisions: bpf ptx //@ [bpf] compile-flags: --target=bpfel-unknown-none -C linker-flavor=bpf --crate-type=rlib //@ [bpf] needs-llvm-components: bpf -//@ [ptx] compile-flags: --target=nvptx64-nvidia-cuda -C linker-flavor=ptx --crate-type=rlib +//@ [ptx] compile-flags: --target=nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 -Clinker-flavor=ptx +//@ [ptx] compile-flags: --crate-type=rlib //@ [ptx] needs-llvm-components: nvptx +//@ ignore-backends: gcc #![feature(no_core)] #![no_core] diff --git a/tests/ui/lint/lint-gpu-kernel.amdgpu.stderr b/tests/ui/lint/lint-gpu-kernel.amdgpu.stderr index 21eebe42f8b1d..42a01bd604b6b 100644 --- a/tests/ui/lint/lint-gpu-kernel.amdgpu.stderr +++ b/tests/ui/lint/lint-gpu-kernel.amdgpu.stderr @@ -1,7 +1,7 @@ warning: `extern` fn uses type `()`, which is not FFI-safe - --> $DIR/lint-gpu-kernel.rs:36:35 + --> $DIR/lint-gpu-kernel.rs:38:35 | -LL | extern "gpu-kernel" fn arg_zst(_: ()) { } +LL | extern "gpu-kernel" fn arg_zst(_: ()) {} | ^^ not FFI-safe | = help: consider using a struct instead @@ -9,74 +9,74 @@ LL | extern "gpu-kernel" fn arg_zst(_: ()) { } = note: `#[warn(improper_ctypes_definitions)]` on by default warning: passing type `()` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:36:35 + --> $DIR/lint-gpu-kernel.rs:38:35 | -LL | extern "gpu-kernel" fn arg_zst(_: ()) { } +LL | extern "gpu-kernel" fn arg_zst(_: ()) {} | ^^ | = help: use primitive types and raw pointers to get reliable behavior = note: `#[warn(improper_gpu_kernel_arg)]` on by default warning: passing type `&i32` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:41:35 + --> $DIR/lint-gpu-kernel.rs:43:35 | -LL | extern "gpu-kernel" fn arg_ref(_: &i32) { } +LL | extern "gpu-kernel" fn arg_ref(_: &i32) {} | ^^^^ | = help: use primitive types and raw pointers to get reliable behavior warning: passing type `&mut i32` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:44:39 + --> $DIR/lint-gpu-kernel.rs:46:39 | -LL | extern "gpu-kernel" fn arg_ref_mut(_: &mut i32) { } +LL | extern "gpu-kernel" fn arg_ref_mut(_: &mut i32) {} | ^^^^^^^^ | = help: use primitive types and raw pointers to get reliable behavior warning: `extern` fn uses type `S`, which is not FFI-safe - --> $DIR/lint-gpu-kernel.rs:49:38 + --> $DIR/lint-gpu-kernel.rs:54:38 | -LL | extern "gpu-kernel" fn arg_struct(_: S) { } +LL | extern "gpu-kernel" fn arg_struct(_: S) {} | ^ not FFI-safe | = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here - --> $DIR/lint-gpu-kernel.rs:47:1 + --> $DIR/lint-gpu-kernel.rs:49:1 | -LL | struct S { a: i32, b: i32 } +LL | struct S { | ^^^^^^^^ warning: passing type `S` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:49:38 + --> $DIR/lint-gpu-kernel.rs:54:38 | -LL | extern "gpu-kernel" fn arg_struct(_: S) { } +LL | extern "gpu-kernel" fn arg_struct(_: S) {} | ^ | = help: use primitive types and raw pointers to get reliable behavior warning: `extern` fn uses type `(i32, i32)`, which is not FFI-safe - --> $DIR/lint-gpu-kernel.rs:54:35 + --> $DIR/lint-gpu-kernel.rs:59:35 | -LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) { } +LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) {} | ^^^^^^^^^^ not FFI-safe | = help: consider using a struct instead = note: tuples have unspecified layout warning: passing type `(i32, i32)` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:54:35 + --> $DIR/lint-gpu-kernel.rs:59:35 | -LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) { } +LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) {} | ^^^^^^^^^^ | = help: use primitive types and raw pointers to get reliable behavior warning: function with the "gpu-kernel" ABI has a mangled name - --> $DIR/lint-gpu-kernel.rs:61:1 + --> $DIR/lint-gpu-kernel.rs:66:1 | -LL | pub extern "gpu-kernel" fn mangled_kernel() { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | pub extern "gpu-kernel" fn mangled_kernel() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `unsafe(no_mangle)` or `unsafe(export_name = "")` = note: mangled names make it hard to find the kernel, this is usually not intended diff --git a/tests/ui/lint/lint-gpu-kernel.nvptx.stderr b/tests/ui/lint/lint-gpu-kernel.nvptx.stderr index 21eebe42f8b1d..42a01bd604b6b 100644 --- a/tests/ui/lint/lint-gpu-kernel.nvptx.stderr +++ b/tests/ui/lint/lint-gpu-kernel.nvptx.stderr @@ -1,7 +1,7 @@ warning: `extern` fn uses type `()`, which is not FFI-safe - --> $DIR/lint-gpu-kernel.rs:36:35 + --> $DIR/lint-gpu-kernel.rs:38:35 | -LL | extern "gpu-kernel" fn arg_zst(_: ()) { } +LL | extern "gpu-kernel" fn arg_zst(_: ()) {} | ^^ not FFI-safe | = help: consider using a struct instead @@ -9,74 +9,74 @@ LL | extern "gpu-kernel" fn arg_zst(_: ()) { } = note: `#[warn(improper_ctypes_definitions)]` on by default warning: passing type `()` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:36:35 + --> $DIR/lint-gpu-kernel.rs:38:35 | -LL | extern "gpu-kernel" fn arg_zst(_: ()) { } +LL | extern "gpu-kernel" fn arg_zst(_: ()) {} | ^^ | = help: use primitive types and raw pointers to get reliable behavior = note: `#[warn(improper_gpu_kernel_arg)]` on by default warning: passing type `&i32` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:41:35 + --> $DIR/lint-gpu-kernel.rs:43:35 | -LL | extern "gpu-kernel" fn arg_ref(_: &i32) { } +LL | extern "gpu-kernel" fn arg_ref(_: &i32) {} | ^^^^ | = help: use primitive types and raw pointers to get reliable behavior warning: passing type `&mut i32` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:44:39 + --> $DIR/lint-gpu-kernel.rs:46:39 | -LL | extern "gpu-kernel" fn arg_ref_mut(_: &mut i32) { } +LL | extern "gpu-kernel" fn arg_ref_mut(_: &mut i32) {} | ^^^^^^^^ | = help: use primitive types and raw pointers to get reliable behavior warning: `extern` fn uses type `S`, which is not FFI-safe - --> $DIR/lint-gpu-kernel.rs:49:38 + --> $DIR/lint-gpu-kernel.rs:54:38 | -LL | extern "gpu-kernel" fn arg_struct(_: S) { } +LL | extern "gpu-kernel" fn arg_struct(_: S) {} | ^ not FFI-safe | = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here - --> $DIR/lint-gpu-kernel.rs:47:1 + --> $DIR/lint-gpu-kernel.rs:49:1 | -LL | struct S { a: i32, b: i32 } +LL | struct S { | ^^^^^^^^ warning: passing type `S` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:49:38 + --> $DIR/lint-gpu-kernel.rs:54:38 | -LL | extern "gpu-kernel" fn arg_struct(_: S) { } +LL | extern "gpu-kernel" fn arg_struct(_: S) {} | ^ | = help: use primitive types and raw pointers to get reliable behavior warning: `extern` fn uses type `(i32, i32)`, which is not FFI-safe - --> $DIR/lint-gpu-kernel.rs:54:35 + --> $DIR/lint-gpu-kernel.rs:59:35 | -LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) { } +LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) {} | ^^^^^^^^^^ not FFI-safe | = help: consider using a struct instead = note: tuples have unspecified layout warning: passing type `(i32, i32)` to a function with "gpu-kernel" ABI may have unexpected behavior - --> $DIR/lint-gpu-kernel.rs:54:35 + --> $DIR/lint-gpu-kernel.rs:59:35 | -LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) { } +LL | extern "gpu-kernel" fn arg_tup(_: (i32, i32)) {} | ^^^^^^^^^^ | = help: use primitive types and raw pointers to get reliable behavior warning: function with the "gpu-kernel" ABI has a mangled name - --> $DIR/lint-gpu-kernel.rs:61:1 + --> $DIR/lint-gpu-kernel.rs:66:1 | -LL | pub extern "gpu-kernel" fn mangled_kernel() { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | pub extern "gpu-kernel" fn mangled_kernel() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `unsafe(no_mangle)` or `unsafe(export_name = "")` = note: mangled names make it hard to find the kernel, this is usually not intended diff --git a/tests/ui/lint/lint-gpu-kernel.rs b/tests/ui/lint/lint-gpu-kernel.rs index 9b3ed0d14d8ad..debb1e2c0619c 100644 --- a/tests/ui/lint/lint-gpu-kernel.rs +++ b/tests/ui/lint/lint-gpu-kernel.rs @@ -8,7 +8,7 @@ //@ edition: 2024 //@[amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 //@[amdgpu] needs-llvm-components: amdgpu -//@[nvptx] compile-flags: --target nvptx64-nvidia-cuda +//@[nvptx] compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@[nvptx] needs-llvm-components: nvptx #![feature(no_core, abi_gpu_kernel)] @@ -22,41 +22,46 @@ use minicore::*; #[unsafe(no_mangle)] extern "gpu-kernel" fn ret_empty() {} #[unsafe(no_mangle)] -extern "gpu-kernel" fn ret_never() -> ! { loop {} } +extern "gpu-kernel" fn ret_never() -> ! { + loop {} +} // Arguments can be scalars or pointers #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_i32(_: i32) { } +extern "gpu-kernel" fn arg_i32(_: i32) {} #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_ptr(_: *const i32) { } +extern "gpu-kernel" fn arg_ptr(_: *const i32) {} #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_ptr_mut(_: *mut i32) { } +extern "gpu-kernel" fn arg_ptr_mut(_: *mut i32) {} #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_zst(_: ()) { } +extern "gpu-kernel" fn arg_zst(_: ()) {} //~^ WARN passing type `()` to a function with "gpu-kernel" ABI may have unexpected behavior //~^^ WARN `extern` fn uses type `()`, which is not FFI-safe #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_ref(_: &i32) { } +extern "gpu-kernel" fn arg_ref(_: &i32) {} //~^ WARN passing type `&i32` to a function with "gpu-kernel" ABI may have unexpected behavior #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_ref_mut(_: &mut i32) { } +extern "gpu-kernel" fn arg_ref_mut(_: &mut i32) {} //~^ WARN passing type `&mut i32` to a function with "gpu-kernel" ABI may have unexpected behavior -struct S { a: i32, b: i32 } +struct S { + a: i32, + b: i32, +} #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_struct(_: S) { } +extern "gpu-kernel" fn arg_struct(_: S) {} //~^ WARN passing type `S` to a function with "gpu-kernel" ABI may have unexpected behavior //~^^ WARN `extern` fn uses type `S`, which is not FFI-safe #[unsafe(no_mangle)] -extern "gpu-kernel" fn arg_tup(_: (i32, i32)) { } +extern "gpu-kernel" fn arg_tup(_: (i32, i32)) {} //~^ WARN passing type `(i32, i32)` to a function with "gpu-kernel" ABI may have unexpected behavior //~^^ WARN `extern` fn uses type `(i32, i32)`, which is not FFI-safe #[unsafe(export_name = "kernel")] pub extern "gpu-kernel" fn allowed_kernel_name() {} -pub extern "gpu-kernel" fn mangled_kernel() { } +pub extern "gpu-kernel" fn mangled_kernel() {} //~^ WARN function with the "gpu-kernel" ABI has a mangled name diff --git a/tests/ui/stack-protector/warn-stack-protector-unsupported.rs b/tests/ui/stack-protector/warn-stack-protector-unsupported.rs index 9e0e126dabe66..9e5f0d3ee3ca9 100644 --- a/tests/ui/stack-protector/warn-stack-protector-unsupported.rs +++ b/tests/ui/stack-protector/warn-stack-protector-unsupported.rs @@ -1,6 +1,6 @@ //@ build-pass //@ revisions: all strong basic -//@ compile-flags: --target nvptx64-nvidia-cuda +//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 //@ needs-llvm-components: nvptx //@ [all] compile-flags: -Z stack-protector=all //@ [strong] compile-flags: -Z stack-protector=strong @@ -24,7 +24,7 @@ trait Sized: MetaSized {} #[lang = "copy"] trait Copy {} -pub fn main(){} +pub fn main() {} //[all]~? WARN `-Z stack-protector=all` is not supported for target nvptx64-nvidia-cuda and will be ignored //[strong]~? WARN `-Z stack-protector=strong` is not supported for target nvptx64-nvidia-cuda and will be ignored diff --git a/tests/ui/static/static-initializer-acyclic-issue-146787.rs b/tests/ui/static/static-initializer-acyclic-issue-146787.rs index 715133bd5d3c0..6d13604a4731c 100644 --- a/tests/ui/static/static-initializer-acyclic-issue-146787.rs +++ b/tests/ui/static/static-initializer-acyclic-issue-146787.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ needs-llvm-components: nvptx -//@ compile-flags: --target nvptx64-nvidia-cuda --emit link +//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_30 --emit link //@ ignore-backends: gcc #![crate_type = "rlib"] #![feature(no_core)] diff --git a/tests/ui/target-cpu/explicit-target-cpu.nvptx_nocpu.stderr b/tests/ui/target-cpu/explicit-target-cpu.nvptx_nocpu.stderr new file mode 100644 index 0000000000000..7480a8ed38f15 --- /dev/null +++ b/tests/ui/target-cpu/explicit-target-cpu.nvptx_nocpu.stderr @@ -0,0 +1,4 @@ +error: target requires explicitly specifying a cpu with `-C target-cpu` + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-cpu/explicit-target-cpu.rs b/tests/ui/target-cpu/explicit-target-cpu.rs index cfec444372728..09e0c59ebd62c 100644 --- a/tests/ui/target-cpu/explicit-target-cpu.rs +++ b/tests/ui/target-cpu/explicit-target-cpu.rs @@ -21,24 +21,25 @@ //@[avr_cpu] needs-llvm-components: avr //@[avr_cpu] compile-flags: -Ctarget-cpu=atmega328p //@[avr_cpu] build-pass -//@ ignore-backends: gcc - -#![crate_type = "rlib"] -// FIXME(#140038): this can't use `minicore` yet because `minicore` doesn't currently propagate the -// `-C target-cpu` for targets that *require* a `target-cpu` being specified. -#![feature(no_core, lang_items)] -#![no_core] +//@ revisions: nvptx_nocpu nvptx_cpu -#[lang = "pointee_sized"] -pub trait PointeeSized {} +//@[nvptx_nocpu] compile-flags: --target=nvptx64-nvidia-cuda +//@[nvptx_nocpu] needs-llvm-components: nvptx +//@[nvptx_nocpu] build-fail -#[lang = "meta_sized"] -pub trait MetaSized: PointeeSized {} +//@[nvptx_cpu] compile-flags: --target=nvptx64-nvidia-cuda +//@[nvptx_cpu] needs-llvm-components: nvptx +//@[nvptx_cpu] compile-flags: -Ctarget-cpu=sm_30 +//@[nvptx_cpu] build-pass -#[lang="sized"] -trait Sized {} +//@ ignore-backends: gcc -pub fn foo() {} +#![crate_type = "rlib"] +// We don't want to link in any other crate as this would make it necessary to specify +// a `-Ctarget-cpu` for them resulting in a *target-modifier* disagreement error instead of the +// error mentioned below. +#![feature(no_core)] +#![no_core] -//[amdgcn_nocpu,avr_nocpu]~? ERROR target requires explicitly specifying a cpu with `-C target-cpu` +//[amdgcn_nocpu,avr_nocpu,nvptx_nocpu]~? ERROR target requires explicitly specifying a cpu with `-C target-cpu` diff --git a/tests/ui/target-feature/implied-features-nvptx.rs b/tests/ui/target-feature/implied-features-nvptx.rs index 1550c99f67a8d..bdcaf06f156a9 100644 --- a/tests/ui/target-feature/implied-features-nvptx.rs +++ b/tests/ui/target-feature/implied-features-nvptx.rs @@ -1,13 +1,16 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_80 -Z unstable-options -Clinker-flavor=llbc -//@ only-nvptx64 +//@ compile-flags: --target=nvptx64-nvidia-cuda --crate-type cdylib -C target-cpu=sm_80 +//@ needs-llvm-components: nvptx //@ build-pass -#![no_std] +//@ ignore-backends: gcc +#![feature(no_core, rustc_attrs)] +#![no_core] #![allow(dead_code)] -#[panic_handler] -pub fn panic(_info: &core::panic::PanicInfo) -> ! { - loop {} +#[rustc_builtin_macro] +#[macro_export] +macro_rules! compile_error { + ($msg:expr $(,)?) => {{ /* compiler built-in */ }}; } // -Ctarget-cpu=sm_80 directly enables sm_80 and ptx70 diff --git a/tests/ui/target_modifiers/auxiliary/target_cpu_is_target_modifier.rs b/tests/ui/target_modifiers/auxiliary/target_cpu_is_target_modifier.rs new file mode 100644 index 0000000000000..aca3edf9f76f4 --- /dev/null +++ b/tests/ui/target_modifiers/auxiliary/target_cpu_is_target_modifier.rs @@ -0,0 +1,8 @@ +//@ no-prefer-dynamic +//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_60 +//@ needs-llvm-components: nvptx +//@ ignore-backends: gcc + +#![feature(no_core)] +#![crate_type = "rlib"] +#![no_core] diff --git a/tests/ui/target_modifiers/defaults_check.error.stderr b/tests/ui/target_modifiers/defaults_check.error.stderr index 644ec079ee3c7..106e64ff29356 100644 --- a/tests/ui/target_modifiers/defaults_check.error.stderr +++ b/tests/ui/target_modifiers/defaults_check.error.stderr @@ -5,7 +5,7 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zreg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zreg-struct-return=true` in this crate is incompatible with unset `-Zreg-struct-return` in dependency `default_reg_struct_return` + = note: `-Zreg-struct-return=true` in this crate is incompatible with `-Zreg-struct-return` being unset in dependency `default_reg_struct_return` = help: unset `-Zreg-struct-return` in this crate or set `-Zreg-struct-return=true` in `default_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error diff --git a/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr b/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr index a8c13e0ed896d..bcdee625830a7 100644 --- a/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr +++ b/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zfixed-x18` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Zfixed-x18` in this crate is incompatible with `-Zfixed-x18=` in dependency `fixed_x18` - = help: set `-Zfixed-x18=` in this crate or unset `-Zfixed-x18` in `fixed_x18` + = note: `-Zfixed-x18` is unset in this crate which is incompatible with `-Zfixed-x18` being set in dependency `fixed_x18` + = help: set `-Zfixed-x18` in this crate or unset `-Zfixed-x18` in `fixed_x18` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=fixed-x18` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/no_value_bool.error.stderr b/tests/ui/target_modifiers/no_value_bool.error.stderr index 479f7fb47cb72..c0e3178b89cf2 100644 --- a/tests/ui/target_modifiers/no_value_bool.error.stderr +++ b/tests/ui/target_modifiers/no_value_bool.error.stderr @@ -5,7 +5,7 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zreg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Zreg-struct-return` in this crate is incompatible with `-Zreg-struct-return=true` in dependency `enabled_reg_struct_return` + = note: `-Zreg-struct-return` is unset in this crate which is incompatible with `-Zreg-struct-return=true` in dependency `enabled_reg_struct_return` = help: set `-Zreg-struct-return=true` in this crate or unset `-Zreg-struct-return` in `enabled_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error diff --git a/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr b/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr index 479f7fb47cb72..c0e3178b89cf2 100644 --- a/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr +++ b/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr @@ -5,7 +5,7 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zreg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Zreg-struct-return` in this crate is incompatible with `-Zreg-struct-return=true` in dependency `enabled_reg_struct_return` + = note: `-Zreg-struct-return` is unset in this crate which is incompatible with `-Zreg-struct-return=true` in dependency `enabled_reg_struct_return` = help: set `-Zreg-struct-return=true` in this crate or unset `-Zreg-struct-return` in `enabled_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr index 1db79b025e9c9..c6abc4b574322 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zsanitizer-cfi-normalize-integers` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Zsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Zsanitizer-cfi-normalize-integers=` in dependency `kcfi_normalize_ints` - = help: set `-Zsanitizer-cfi-normalize-integers=` in this crate or unset `-Zsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` + = note: `-Zsanitizer-cfi-normalize-integers` is unset in this crate which is incompatible with `-Zsanitizer-cfi-normalize-integers` being set in dependency `kcfi_normalize_ints` + = help: set `-Zsanitizer-cfi-normalize-integers` in this crate or unset `-Zsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer-cfi-normalize-integers` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr index 5b949c87350b9..79e8ffbf04a5b 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr @@ -5,7 +5,7 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zsanitizer` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Zsanitizer` in this crate is incompatible with `-Zsanitizer=kcfi` in dependency `kcfi_normalize_ints` + = note: `-Zsanitizer` is unset in this crate which is incompatible with `-Zsanitizer=kcfi` in dependency `kcfi_normalize_ints` = help: set `-Zsanitizer=kcfi` in this crate or unset `-Zsanitizer` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer` to silence this error diff --git a/tests/ui/target_modifiers/sanitizers-safestack-and-kcfi.missed_both.stderr b/tests/ui/target_modifiers/sanitizers-safestack-and-kcfi.missed_both.stderr index 440a91c7707f8..cb66f56ae373f 100644 --- a/tests/ui/target_modifiers/sanitizers-safestack-and-kcfi.missed_both.stderr +++ b/tests/ui/target_modifiers/sanitizers-safestack-and-kcfi.missed_both.stderr @@ -5,7 +5,7 @@ LL | #![feature(no_core)] | ^ | = help: the `-Zsanitizer` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Zsanitizer` in this crate is incompatible with `-Zsanitizer=safestack,kcfi` in dependency `safestack_and_kcfi` + = note: `-Zsanitizer` is unset in this crate which is incompatible with `-Zsanitizer=safestack,kcfi` in dependency `safestack_and_kcfi` = help: set `-Zsanitizer=safestack,kcfi` in this crate or unset `-Zsanitizer` in `safestack_and_kcfi` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer` to silence this error diff --git a/tests/ui/target_modifiers/target_cpu_specified_twice.error_generated.stderr b/tests/ui/target_modifiers/target_cpu_specified_twice.error_generated.stderr new file mode 100644 index 0000000000000..495996dd0af60 --- /dev/null +++ b/tests/ui/target_modifiers/target_cpu_specified_twice.error_generated.stderr @@ -0,0 +1,13 @@ +error: mixing `-Ctarget-cpu` will cause an ABI mismatch in crate `target_cpu_specified_twice` + --> $DIR/target_cpu_specified_twice.rs:14:1 + | +LL | #![feature(no_core)] + | ^ + | + = help: the `-Ctarget-cpu` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: `-Ctarget-cpu=sm_70` in this crate is incompatible with `-Ctarget-cpu=sm_60` in dependency `target_cpu_is_target_modifier` + = help: set `-Ctarget-cpu=sm_60` in this crate or `-Ctarget-cpu=sm_70` in `target_cpu_is_target_modifier` + = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=target-cpu` to silence this error + +error: aborting due to 1 previous error + diff --git a/tests/ui/target_modifiers/target_cpu_specified_twice.rs b/tests/ui/target_modifiers/target_cpu_specified_twice.rs new file mode 100644 index 0000000000000..90196f04a41d2 --- /dev/null +++ b/tests/ui/target_modifiers/target_cpu_specified_twice.rs @@ -0,0 +1,20 @@ +//@ aux-build:target_cpu_is_target_modifier.rs +//@ compile-flags: --target nvptx64-nvidia-cuda +//@ needs-llvm-components: nvptx + +//@ revisions:last_correct last_incorrect_allow error_generated +//@[last_correct] compile-flags: -Ctarget-cpu=sm_70 -Ctarget-cpu=sm_60 +//@[last_incorrect_allow] compile-flags: -Ctarget-cpu=sm_60 -Ctarget-cpu=sm_70 +//@[last_incorrect_allow] compile-flags: -Cunsafe-allow-abi-mismatch=target-cpu +//@[error_generated] compile-flags: -Ctarget-cpu=sm_60 -Ctarget-cpu=sm_70 +//@[last_correct] check-pass +//@[last_incorrect_allow] check-pass +//@ ignore-backends: gcc + +#![feature(no_core)] +//[error_generated]~^ ERROR mixing `-Ctarget-cpu` will cause an ABI mismatch in crate +// `target_cpu_specified_twice` +#![crate_type = "rlib"] +#![no_core] + +extern crate target_cpu_is_target_modifier;