1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
// Test that structs aligned to 128 bits are passed with the correct ABI on aarch64.
//@ revisions: linux darwin win
//@[linux] compile-flags: --target aarch64-unknown-linux-gnu
//@[darwin] compile-flags: --target aarch64-apple-darwin
//@[win] compile-flags: --target aarch64-pc-windows-msvc
//@[linux] needs-llvm-components: aarch64
//@[darwin] needs-llvm-components: aarch64
//@[win] needs-llvm-components: aarch64
#![feature(no_core, lang_items)]
#![crate_type = "lib"]
#![no_core]
#[lang = "sized"]
trait Sized {}
#[lang = "freeze"]
trait Freeze {}
#[lang = "copy"]
trait Copy {}
// 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 {
a: Align8,
}
// 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" {
// 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])
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 {
a: Align16,
}
// 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" {
// 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)
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 {
a: I128,
}
// Passed as `i128`, since it's an aggregate with size <= 128 bits, align = 128 bits.
#[repr(C)]
pub struct WrappedI128 {
pub a: I128,
}
extern "C" {
// linux: declare void @test_i128(i128, i128, i128)
// darwin: declare void @test_i128(i128, i128, i128)
// win: declare void @test_i128(i128, i128, i128)
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 {
a: Packed,
}
// Passed as `[2 x i64]`, since it's an aggregate with size <= 128 bits, align < 128 bits.
#[repr(C)]
pub struct WrappedPacked {
pub a: Packed,
}
extern "C" {
// 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])
fn test_packed(a: Packed, b: TransparentPacked, c: WrappedPacked);
}
pub unsafe fn main(
a1: Align8,
a2: Transparent8,
a3: Wrapped8,
b1: Align16,
b2: Transparent16,
b3: Wrapped16,
c1: I128,
c2: TransparentI128,
c3: WrappedI128,
d1: Packed,
d2: TransparentPacked,
d3: WrappedPacked,
) {
test_8(a1, a2, a3);
test_16(b1, b2, b3);
test_i128(c1, c2, c3);
test_packed(d1, d2, d3);
}
|