From 0b9d1eb889e8ceaea6af4f614e747b746a68822e Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 29 Oct 2024 23:22:36 -0700 Subject: [PATCH] tests: cross-compile multi-platform ZST ABI tests This allows them to be blessed, regardless of platform. --- ...nux.stderr => c-zst.aarch64-darwin.stderr} | 0 tests/ui/abi/c-zst.rs | 74 ++++++++++++++----- ...other.stderr => c-zst.x86_64-linux.stderr} | 0 tests/ui/abi/win64-zst.rs | 23 ++++-- ...r.stderr => win64-zst.x86_64-linux.stderr} | 0 ...rr => win64-zst.x86_64-windows-gnu.stderr} | 0 6 files changed, 73 insertions(+), 24 deletions(-) rename tests/ui/abi/{c-zst.other-linux.stderr => c-zst.aarch64-darwin.stderr} (100%) rename tests/ui/abi/{c-zst.other.stderr => c-zst.x86_64-linux.stderr} (100%) rename tests/ui/abi/{win64-zst.other.stderr => win64-zst.x86_64-linux.stderr} (100%) rename tests/ui/abi/{win64-zst.windows-gnu.stderr => win64-zst.x86_64-windows-gnu.stderr} (100%) diff --git a/tests/ui/abi/c-zst.other-linux.stderr b/tests/ui/abi/c-zst.aarch64-darwin.stderr similarity index 100% rename from tests/ui/abi/c-zst.other-linux.stderr rename to tests/ui/abi/c-zst.aarch64-darwin.stderr diff --git a/tests/ui/abi/c-zst.rs b/tests/ui/abi/c-zst.rs index 0cfd653b37e..69ebefa09ac 100644 --- a/tests/ui/abi/c-zst.rs +++ b/tests/ui/abi/c-zst.rs @@ -1,27 +1,63 @@ -//@ revisions: other other-linux x86_64-pc-windows-gnu s390x-linux sparc64-linux powerpc-linux //@ normalize-stderr-test: "(abi|pref|unadjusted_abi_align): Align\([1-8] bytes\)" -> "$1: $$SOME_ALIGN" -// ZSTs are only not ignored when the target_env is "gnu", "musl" or "uclibc". However, Rust does -// not currently support any other target_env on these architectures. +/*! +C doesn't have zero-sized types... except it does. -// Ignore the ZST revisions -//@[other] ignore-x86_64-pc-windows-gnu -//@[other] ignore-linux -//@[other-linux] only-linux -//@[other-linux] ignore-s390x -//@[other-linux] ignore-sparc64 -//@[other-linux] ignore-powerpc +Standard C doesn't, but some C compilers, like GCC, implement ZSTs as a compiler extension. +This historically has wound up interacting with processor-specific ABIs in fairly ad-hoc ways. +e.g. despite being "zero-sized", sometimes C compilers decide ZSTs consume registers. -// Pass the ZST indirectly revisions -//@[x86_64-pc-windows-gnu] only-x86_64-pc-windows-gnu -//@[s390x-linux] only-s390x -//@[s390x-linux] only-linux -//@[sparc64-linux] only-sparc64 -//@[sparc64-linux] only-linux -//@[powerpc-linux] only-powerpc -//@[powerpc-linux] only-linux +That means these two function signatures may not be compatible: -#![feature(rustc_attrs)] +``` +extern "C" fn((), i32, i32); +extern "C" fn(i32, (), i32); +``` +*/ + +/* + * ZST IN "C" IS ZERO-SIZED + */ + +//@ revisions: aarch64-darwin +//@[aarch64-darwin] compile-flags: --target aarch64-apple-darwin +//@[aarch64-darwin] needs-llvm-components: aarch64 + +//@ revisions: x86_64-linux +//@[x86_64-linux] compile-flags: --target x86_64-unknown-linux-gnu +//@[x86_64-linux] needs-llvm-components: x86 + + +/* + * ZST IN "C" IS PASS-BY-POINTER + */ + +// according to the SRV4 ABI, an aggregate is always passed in registers, +// and it so happens the GCC extension for ZSTs considers them as structs. +//@ revisions: powerpc-linux +//@[powerpc-linux] compile-flags: --target powerpc-unknown-linux-gnu +//@[powerpc-linux] needs-llvm-components: powerpc + +//@ revisions: s390x-linux +//@[s390x-linux] compile-flags: --target s390x-unknown-linux-gnu +//@[s390x-linux] needs-llvm-components: systemz + +//@ revisions: sparc64-linux +//@[sparc64-linux] compile-flags: --target sparc64-unknown-linux-gnu +//@[sparc64-linux] needs-llvm-components: sparc + +// The Win64 ABI uses slightly different handling for power-of-2 sizes in the ABI, +// so GCC decided that ZSTs are pass-by-pointer, as `0.is_power_of_two() == false` +//@ revisions: x86_64-pc-windows-gnu +//@[x86_64-pc-windows-gnu] compile-flags: --target x86_64-pc-windows-gnu +//@[x86_64-pc-windows-gnu] needs-llvm-components: x86 + + +#![feature(lang_items, no_core, rustc_attrs)] +#![no_core] #![crate_type = "lib"] +#[lang = "sized"] +trait Sized {} + #[rustc_abi(debug)] extern "C" fn pass_zst(_: ()) {} //~ ERROR: fn_abi diff --git a/tests/ui/abi/c-zst.other.stderr b/tests/ui/abi/c-zst.x86_64-linux.stderr similarity index 100% rename from tests/ui/abi/c-zst.other.stderr rename to tests/ui/abi/c-zst.x86_64-linux.stderr diff --git a/tests/ui/abi/win64-zst.rs b/tests/ui/abi/win64-zst.rs index cae32795e16..a2f7d19eb45 100644 --- a/tests/ui/abi/win64-zst.rs +++ b/tests/ui/abi/win64-zst.rs @@ -1,11 +1,24 @@ -//@ only-x86_64 -//@ revisions: other windows-gnu //@ normalize-stderr-test: "(abi|pref|unadjusted_abi_align): Align\([1-8] bytes\)" -> "$1: $$SOME_ALIGN" -//@[other] ignore-windows-gnu -//@[windows-gnu] only-windows-gnu +//@ only-x86_64 -#![feature(rustc_attrs)] +//@ revisions: x86_64-linux +//@[x86_64-linux] compile-flags: --target x86_64-unknown-linux-gnu +//@[x86_64-linux] needs-llvm-components: x86 + +//@ revisions: x86_64-windows-gnu +//@[x86_64-windows-gnu] compile-flags: --target x86_64-pc-windows-gnu +//@[x86_64-windows-gnu] needs-llvm-components: x86 + +//@ revisions: x86_64-windows-msvc +//@[x86_64-windows-msvc] compile-flags: --target x86_64-pc-windows-msvc +//@[x86_64-windows-msvc] needs-llvm-components: x86 + +#![feature(no_core, lang_items, rustc_attrs)] +#![no_core] #![crate_type = "lib"] +#[lang = "sized"] +trait Sized {} + #[rustc_abi(debug)] extern "win64" fn pass_zst(_: ()) {} //~ ERROR: fn_abi diff --git a/tests/ui/abi/win64-zst.other.stderr b/tests/ui/abi/win64-zst.x86_64-linux.stderr similarity index 100% rename from tests/ui/abi/win64-zst.other.stderr rename to tests/ui/abi/win64-zst.x86_64-linux.stderr diff --git a/tests/ui/abi/win64-zst.windows-gnu.stderr b/tests/ui/abi/win64-zst.x86_64-windows-gnu.stderr similarity index 100% rename from tests/ui/abi/win64-zst.windows-gnu.stderr rename to tests/ui/abi/win64-zst.x86_64-windows-gnu.stderr