2022-02-12 00:38:24 -06:00
|
|
|
// compile-flags: -O -C no-prepopulate-passes
|
2020-05-20 11:53:22 -05:00
|
|
|
// ignore-riscv64 riscv64 has an i128 type used with test_Vector
|
2022-12-06 11:12:46 -06:00
|
|
|
// ignore-s390x s390x with default march passes vector types per reference
|
2023-04-14 04:42:08 -05:00
|
|
|
// ignore-loongarch64 see codegen/loongarch-abi for loongarch function call tests
|
2020-05-20 11:53:22 -05:00
|
|
|
|
2023-07-29 16:57:53 -05:00
|
|
|
// This codegen test embeds assumptions about how certain "C" psABIs are handled
|
|
|
|
// so it doesn't apply to all architectures or even all OS
|
|
|
|
// For RISCV: see codegen/riscv-abi
|
|
|
|
// For LoongArch: see codegen/loongarch-abi
|
|
|
|
|
2018-01-03 10:43:30 -06:00
|
|
|
#![crate_type="lib"]
|
2020-01-10 17:53:54 -06:00
|
|
|
#![feature(repr_simd, transparent_unions)]
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
2019-05-22 09:31:09 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2018-01-03 10:43:30 -06:00
|
|
|
pub struct Zst1;
|
2019-05-22 09:31:09 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2018-01-03 10:43:30 -06:00
|
|
|
pub struct Zst2(());
|
|
|
|
|
2019-05-22 09:31:09 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2018-01-03 10:43:30 -06:00
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct F32(f32);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}float @test_F32(float noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_F32(_: F32) -> F32 { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Ptr(*mut u8);
|
|
|
|
|
2023-07-27 16:44:13 -05:00
|
|
|
// CHECK: define{{.*}}ptr @test_Ptr(ptr noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Ptr(_: Ptr) -> Ptr { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct WithZst(u64, Zst1);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}i64 @test_WithZst(i64 noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_WithZst(_: WithZst) -> WithZst { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct WithZeroSizedArray(*const f32, [i8; 0]);
|
|
|
|
|
|
|
|
// Apparently we use i32* when newtype-unwrapping f32 pointers. Whatever.
|
2023-07-27 16:44:13 -05:00
|
|
|
// CHECK: define{{.*}}ptr @test_WithZeroSizedArray(ptr noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_WithZeroSizedArray(_: WithZeroSizedArray) -> WithZeroSizedArray { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Generic<T>(T);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}double @test_Generic(double noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Generic(_: Generic<f64>) -> Generic<f64> { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct GenericPlusZst<T>(T, Zst2);
|
|
|
|
|
|
|
|
#[repr(u8)]
|
|
|
|
pub enum Bool { True, False, FileNotFound }
|
|
|
|
|
2022-02-12 00:38:24 -06:00
|
|
|
// CHECK: define{{( dso_local)?}} noundef{{( zeroext)?}} i8 @test_Gpz(i8 noundef{{( zeroext)?}} %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Gpz(_: GenericPlusZst<Bool>) -> GenericPlusZst<Bool> { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct LifetimePhantom<'a, T: 'a>(*const T, PhantomData<&'a T>);
|
|
|
|
|
2023-07-27 16:44:13 -05:00
|
|
|
// CHECK: define{{.*}}ptr @test_LifetimePhantom(ptr noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_LifetimePhantom(_: LifetimePhantom<i16>) -> LifetimePhantom<i16> { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
// This works despite current alignment resrictions because PhantomData is always align(1)
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct UnitPhantom<T, U> { val: T, unit: PhantomData<U> }
|
|
|
|
|
|
|
|
pub struct Px;
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}float @test_UnitPhantom(float noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_UnitPhantom(_: UnitPhantom<f32, Px>) -> UnitPhantom<f32, Px> { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct TwoZsts(Zst1, i8, Zst2);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{( dso_local)?}} noundef{{( signext)?}} i8 @test_TwoZsts(i8 noundef{{( signext)?}} %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_TwoZsts(_: TwoZsts) -> TwoZsts { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Nested1(Zst2, Generic<f64>);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}double @test_Nested1(double noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Nested1(_: Nested1) -> Nested1 { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Nested2(Nested1, Zst1);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}double @test_Nested2(double noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Nested2(_: Nested2) -> Nested2 { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
#[repr(simd)]
|
|
|
|
struct f32x4(f32, f32, f32, f32);
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct Vector(f32x4);
|
|
|
|
|
2021-03-27 17:11:24 -05:00
|
|
|
// CHECK: define{{.*}}<4 x float> @test_Vector(<4 x float> %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Vector(_: Vector) -> Vector { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
|
|
|
trait Mirror { type It: ?Sized; }
|
|
|
|
impl<T: ?Sized> Mirror for T { type It = Self; }
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct StructWithProjection(<f32 as Mirror>::It);
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}float @test_Projection(float noundef %_1)
|
2018-01-03 10:43:30 -06:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_Projection(_: StructWithProjection) -> StructWithProjection { loop {} }
|
2018-01-03 10:43:30 -06:00
|
|
|
|
2019-05-22 09:31:09 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
pub enum EnumF32 {
|
|
|
|
Variant(F32)
|
|
|
|
}
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}float @test_EnumF32(float noundef %_1)
|
2019-05-22 09:31:09 -05:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_EnumF32(_: EnumF32) -> EnumF32 { loop {} }
|
2019-05-22 09:31:09 -05:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub enum EnumF32WithZsts {
|
|
|
|
Variant(Zst1, F32, Zst2)
|
|
|
|
}
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}}float @test_EnumF32WithZsts(float noundef %_1)
|
2019-05-22 09:31:09 -05:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_EnumF32WithZsts(_: EnumF32WithZsts) -> EnumF32WithZsts { loop {} }
|
2019-05-22 09:31:09 -05:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub union UnionF32 {
|
|
|
|
field: F32,
|
|
|
|
}
|
|
|
|
|
2022-12-30 08:55:05 -06:00
|
|
|
// CHECK: define{{.*}} float @test_UnionF32(float %_1)
|
2019-05-22 09:31:09 -05:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
|
2019-05-22 09:31:09 -05:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub union UnionF32WithZsts {
|
|
|
|
zst1: Zst1,
|
|
|
|
field: F32,
|
|
|
|
zst2: Zst2,
|
|
|
|
}
|
|
|
|
|
2021-03-27 17:11:24 -05:00
|
|
|
// CHECK: define{{.*}}float @test_UnionF32WithZsts(float %_1)
|
2019-05-22 09:31:09 -05:00
|
|
|
#[no_mangle]
|
2020-09-01 16:28:11 -05:00
|
|
|
pub extern "C" fn test_UnionF32WithZsts(_: UnionF32WithZsts) -> UnionF32WithZsts { loop {} }
|
2019-05-22 09:31:09 -05:00
|
|
|
|
2018-01-03 10:43:30 -06:00
|
|
|
|
2023-07-29 16:57:53 -05:00
|
|
|
// All that remains to be tested are aggregates. They are tested in separate files called
|
2018-01-20 10:09:55 -06:00
|
|
|
// transparent-*.rs with `only-*` or `ignore-*` directives, because the expected LLVM IR
|
|
|
|
// function signatures vary so much that it's not reasonably possible to cover all of them with a
|
|
|
|
// single CHECK line.
|
2018-01-03 10:43:30 -06:00
|
|
|
//
|
2018-01-20 10:09:55 -06:00
|
|
|
// You may be wondering why we don't just compare the return types and argument types for equality
|
|
|
|
// with FileCheck regex captures. Well, rustc doesn't perform newtype unwrapping on newtypes
|
|
|
|
// containing aggregates. This is OK on all ABIs we support, but because LLVM has not gotten rid of
|
|
|
|
// pointee types yet, the IR function signature will be syntactically different (%Foo* vs
|
|
|
|
// %FooWrapper*).
|