mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-02 17:44:28 +00:00
For AVR, AMDGCN, and NVPTX, crates built with different target CPU values are not generally link-compatible. Add a `requires_consistent_cpu` flag to the target spec and enable it for these targets. When the flag is set, treat `-Ctarget-cpu` as a target modifier and require all linked crates to agree on its value. Reject `-Ctarget-cpu=native` before codegen for targets that set `requires_consistent_cpu` to true. Also do not include `native` in the printed `target-cpus` list for such targets. Add tests covering: - which built-in targets set `requires-consistent-cpu` - cross-crate behavior with and without `requires-consistent-cpu` - that an omitted `-Ctarget-cpu` compares equal to an explicitly specified default CPU - rejection and printing behavior for `native` - precedence of repeated `-Ctarget-cpu` flags in metadata comparison and LLVM IR
39 lines
1.5 KiB
Rust
39 lines
1.5 KiB
Rust
// Check that an implicit default `-Ctarget-cpu` and an explicit default
|
|
// `-Ctarget-cpu` compare equal.
|
|
//
|
|
// NVPTX requires consistent `-Ctarget-cpu` values across crates, but it does
|
|
// not require the CPU to be specified explicitly. Therefore, compiling one crate
|
|
// without `-Ctarget-cpu` and another crate with the target's default CPU
|
|
// explicitly specified must be accepted.
|
|
//
|
|
// The mismatch revisions additionally check that an implicit or explicit default
|
|
// CPU must not match a different explicitly specified CPU.
|
|
|
|
//@ aux-build:target_cpu_default_implicit.rs
|
|
//@ aux-build:target_cpu_default_explicit.rs
|
|
//@ aux-build:target_cpu_non_default.rs
|
|
//@ compile-flags: --target nvptx64-nvidia-cuda
|
|
//@ needs-llvm-components: nvptx
|
|
//@ ignore-backends: gcc
|
|
|
|
//@ revisions: implicit_default explicit_default implicit_mismatch explicit_mismatch
|
|
//@[implicit_default] check-pass
|
|
//@[explicit_default] compile-flags: -Ctarget-cpu=sm_70
|
|
//@[explicit_default] check-pass
|
|
//@[explicit_mismatch] compile-flags: -Ctarget-cpu=sm_70
|
|
|
|
#![feature(no_core)]
|
|
//[implicit_mismatch]~^ ERROR mixing `-Ctarget-cpu` will cause an ABI mismatch
|
|
//[explicit_mismatch]~^^ ERROR mixing `-Ctarget-cpu` will cause an ABI mismatch
|
|
#![crate_type = "rlib"]
|
|
#![no_core]
|
|
|
|
#[cfg(any(implicit_default, explicit_default))]
|
|
extern crate target_cpu_default_implicit;
|
|
|
|
#[cfg(any(implicit_default, explicit_default))]
|
|
extern crate target_cpu_default_explicit;
|
|
|
|
#[cfg(any(implicit_mismatch, explicit_mismatch))]
|
|
extern crate target_cpu_non_default;
|