Skip to content

Commit

Permalink
tests: cross-compile multi-platform ZST ABI tests
Browse files Browse the repository at this point in the history
This allows them to be blessed, regardless of platform.
  • Loading branch information
workingjubilee committed Oct 30, 2024
1 parent 11f9217 commit 9bd64a1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 27 deletions.
File renamed without changes.
80 changes: 58 additions & 22 deletions tests/ui/abi/c-zst.rs
Original file line number Diff line number Diff line change
@@ -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.

// 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

// 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

#![feature(rustc_attrs)]
/*!
C doesn't have zero-sized types... except it does.
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.
That means these two function signatures may not be compatible:
```
extern "C" fn((), i32, i32);
extern "C" fn(i32, (), i32);
```
*/

/*
* NO ZST IN "C"
*/

//@ 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
File renamed without changes.
23 changes: 18 additions & 5 deletions tests/ui/abi/win64-zst.rs
Original file line number Diff line number Diff line change
@@ -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

//@ revisions: x86_64-linux
//@[x86_64-linux] compile-flags: --target x86_64-unknown-linux-gnu
//@[x86_64-linux] needs-llvm-components: x86

#![feature(rustc_attrs)]
//@ 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
File renamed without changes.
File renamed without changes.

0 comments on commit 9bd64a1

Please sign in to comment.