2023-06-14 21:39:11 -05:00
|
|
|
// Test that structs aligned to 128 bits are passed with the correct ABI on aarch64.
|
|
|
|
|
2024-06-08 06:26:37 -05:00
|
|
|
//@ revisions: linux darwin win
|
2023-06-14 21:39:11 -05:00
|
|
|
//@[linux] compile-flags: --target aarch64-unknown-linux-gnu
|
|
|
|
//@[darwin] compile-flags: --target aarch64-apple-darwin
|
2024-06-08 06:26:37 -05:00
|
|
|
//@[win] compile-flags: --target aarch64-pc-windows-msvc
|
2023-06-14 21:39:11 -05:00
|
|
|
//@[linux] needs-llvm-components: aarch64
|
|
|
|
//@[darwin] needs-llvm-components: aarch64
|
2024-06-08 06:26:37 -05:00
|
|
|
//@[win] needs-llvm-components: aarch64
|
2023-06-14 21:39:11 -05:00
|
|
|
|
|
|
|
#![feature(no_core, lang_items)]
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
#![no_core]
|
|
|
|
|
2024-05-28 23:11:20 -05:00
|
|
|
#[lang = "sized"]
|
|
|
|
trait Sized {}
|
|
|
|
#[lang = "freeze"]
|
|
|
|
trait Freeze {}
|
|
|
|
#[lang = "copy"]
|
|
|
|
trait Copy {}
|
2023-06-14 21:39:11 -05:00
|
|
|
|
|
|
|
// Passed as `[i64 x 2]`, since it's an aggregate with size <= 128 bits, align < 128 bits.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Align8 {
|
|
|
|
pub a: u64,
|
|
|
|
pub b: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
// repr(transparent), so same as above.
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Transparent8 {
|
2024-05-28 23:11:20 -05:00
|
|
|
a: Align8,
|
2023-06-14 21:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `[i64 x 2]`, since it's an aggregate with size <= 128 bits, align < 128 bits.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Wrapped8 {
|
|
|
|
a: Align8,
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2024-06-08 06:26:37 -05:00
|
|
|
// linux: declare void @test_8([2 x i64], [2 x i64], [2 x i64])
|
|
|
|
// darwin: declare void @test_8([2 x i64], [2 x i64], [2 x i64])
|
|
|
|
// win: declare void @test_8([2 x i64], [2 x i64], [2 x i64])
|
2023-06-14 21:39:11 -05:00
|
|
|
fn test_8(a: Align8, b: Transparent8, c: Wrapped8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `i128`, since it's an aggregate with size <= 128 bits, align = 128 bits.
|
|
|
|
// EXCEPT on Linux, where there's a special case to use its unadjusted alignment,
|
|
|
|
// making it the same as `Align8`, so it's be passed as `[i64 x 2]`.
|
|
|
|
#[repr(C)]
|
|
|
|
#[repr(align(16))]
|
|
|
|
pub struct Align16 {
|
|
|
|
pub a: u64,
|
|
|
|
pub b: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
// repr(transparent), so same as above.
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Transparent16 {
|
2024-05-28 23:11:20 -05:00
|
|
|
a: Align16,
|
2023-06-14 21:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `i128`, since it's an aggregate with size <= 128 bits, align = 128 bits.
|
|
|
|
// On Linux, the "unadjustedness" doesn't recurse into fields, so this is passed as `i128`.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Wrapped16 {
|
|
|
|
pub a: Align16,
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2024-06-08 06:26:37 -05:00
|
|
|
// linux: declare void @test_16([2 x i64], [2 x i64], i128)
|
|
|
|
// darwin: declare void @test_16(i128, i128, i128)
|
|
|
|
// win: declare void @test_16(i128, i128, i128)
|
2023-06-14 21:39:11 -05:00
|
|
|
fn test_16(a: Align16, b: Transparent16, c: Wrapped16);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `i128`, since it's an aggregate with size <= 128 bits, align = 128 bits.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct I128 {
|
|
|
|
pub a: i128,
|
|
|
|
}
|
|
|
|
|
|
|
|
// repr(transparent), so same as above.
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct TransparentI128 {
|
2024-05-28 23:11:20 -05:00
|
|
|
a: I128,
|
2023-06-14 21:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `i128`, since it's an aggregate with size <= 128 bits, align = 128 bits.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct WrappedI128 {
|
2024-05-28 23:11:20 -05:00
|
|
|
pub a: I128,
|
2023-06-14 21:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2024-06-08 06:26:37 -05:00
|
|
|
// linux: declare void @test_i128(i128, i128, i128)
|
|
|
|
// darwin: declare void @test_i128(i128, i128, i128)
|
|
|
|
// win: declare void @test_i128(i128, i128, i128)
|
2023-06-14 21:39:11 -05:00
|
|
|
fn test_i128(a: I128, b: TransparentI128, c: WrappedI128);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `[2 x i64]`, since it's an aggregate with size <= 128 bits, align < 128 bits.
|
|
|
|
// Note that the Linux special case does not apply, because packing is not considered "adjustment".
|
|
|
|
#[repr(C)]
|
|
|
|
#[repr(packed)]
|
|
|
|
pub struct Packed {
|
|
|
|
pub a: i128,
|
|
|
|
}
|
|
|
|
|
|
|
|
// repr(transparent), so same as above.
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct TransparentPacked {
|
2024-05-28 23:11:20 -05:00
|
|
|
a: Packed,
|
2023-06-14 21:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Passed as `[2 x i64]`, since it's an aggregate with size <= 128 bits, align < 128 bits.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct WrappedPacked {
|
2024-05-28 23:11:20 -05:00
|
|
|
pub a: Packed,
|
2023-06-14 21:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2024-06-08 06:26:37 -05:00
|
|
|
// linux: declare void @test_packed([2 x i64], [2 x i64], [2 x i64])
|
|
|
|
// darwin: declare void @test_packed([2 x i64], [2 x i64], [2 x i64])
|
|
|
|
// win: declare void @test_packed([2 x i64], [2 x i64], [2 x i64])
|
2023-06-14 21:39:11 -05:00
|
|
|
fn test_packed(a: Packed, b: TransparentPacked, c: WrappedPacked);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn main(
|
2024-05-28 23:11:20 -05:00
|
|
|
a1: Align8,
|
|
|
|
a2: Transparent8,
|
|
|
|
a3: Wrapped8,
|
|
|
|
b1: Align16,
|
|
|
|
b2: Transparent16,
|
|
|
|
b3: Wrapped16,
|
|
|
|
c1: I128,
|
|
|
|
c2: TransparentI128,
|
|
|
|
c3: WrappedI128,
|
|
|
|
d1: Packed,
|
|
|
|
d2: TransparentPacked,
|
|
|
|
d3: WrappedPacked,
|
2023-06-14 21:39:11 -05:00
|
|
|
) {
|
|
|
|
test_8(a1, a2, a3);
|
|
|
|
test_16(b1, b2, b3);
|
|
|
|
test_i128(c1, c2, c3);
|
|
|
|
test_packed(d1, d2, d3);
|
|
|
|
}
|