1 // compile-flags: -O -C no-prepopulate-passes
3 // ignore-riscv64 riscv64 has an i128 type used with test_Vector
4 // see codegen/riscv-abi for riscv functiona call tests
5 // ignore-s390x s390x with default march passes vector types per reference
8 #![feature(repr_simd, transparent_unions)]
10 use std::marker::PhantomData;
12 #[derive(Copy, Clone)]
14 #[derive(Copy, Clone)]
17 #[derive(Copy, Clone)]
21 // CHECK: define{{.*}}float @test_F32(float %_1)
23 pub extern "C" fn test_F32(_: F32) -> F32 { loop {} }
26 pub struct Ptr(*mut u8);
28 // CHECK: define{{.*}}{{i8\*|ptr}} @test_Ptr({{i8\*|ptr}} %_1)
30 pub extern "C" fn test_Ptr(_: Ptr) -> Ptr { loop {} }
33 pub struct WithZst(u64, Zst1);
35 // CHECK: define{{.*}}i64 @test_WithZst(i64 %_1)
37 pub extern "C" fn test_WithZst(_: WithZst) -> WithZst { loop {} }
40 pub struct WithZeroSizedArray(*const f32, [i8; 0]);
42 // Apparently we use i32* when newtype-unwrapping f32 pointers. Whatever.
43 // CHECK: define{{.*}}{{i32\*|ptr}} @test_WithZeroSizedArray({{i32\*|ptr}} %_1)
45 pub extern "C" fn test_WithZeroSizedArray(_: WithZeroSizedArray) -> WithZeroSizedArray { loop {} }
48 pub struct Generic<T>(T);
50 // CHECK: define{{.*}}double @test_Generic(double %_1)
52 pub extern "C" fn test_Generic(_: Generic<f64>) -> Generic<f64> { loop {} }
55 pub struct GenericPlusZst<T>(T, Zst2);
58 pub enum Bool { True, False, FileNotFound }
60 // CHECK: define{{( dso_local)?}} noundef{{( zeroext)?}} i8 @test_Gpz(i8 noundef{{( zeroext)?}} %_1)
62 pub extern "C" fn test_Gpz(_: GenericPlusZst<Bool>) -> GenericPlusZst<Bool> { loop {} }
65 pub struct LifetimePhantom<'a, T: 'a>(*const T, PhantomData<&'a T>);
67 // CHECK: define{{.*}}{{i16\*|ptr}} @test_LifetimePhantom({{i16\*|ptr}} %_1)
69 pub extern "C" fn test_LifetimePhantom(_: LifetimePhantom<i16>) -> LifetimePhantom<i16> { loop {} }
71 // This works despite current alignment resrictions because PhantomData is always align(1)
73 pub struct UnitPhantom<T, U> { val: T, unit: PhantomData<U> }
77 // CHECK: define{{.*}}float @test_UnitPhantom(float %_1)
79 pub extern "C" fn test_UnitPhantom(_: UnitPhantom<f32, Px>) -> UnitPhantom<f32, Px> { loop {} }
82 pub struct TwoZsts(Zst1, i8, Zst2);
84 // CHECK: define{{( dso_local)?}}{{( signext)?}} i8 @test_TwoZsts(i8{{( signext)?}} %_1)
86 pub extern "C" fn test_TwoZsts(_: TwoZsts) -> TwoZsts { loop {} }
89 pub struct Nested1(Zst2, Generic<f64>);
91 // CHECK: define{{.*}}double @test_Nested1(double %_1)
93 pub extern "C" fn test_Nested1(_: Nested1) -> Nested1 { loop {} }
96 pub struct Nested2(Nested1, Zst1);
98 // CHECK: define{{.*}}double @test_Nested2(double %_1)
100 pub extern "C" fn test_Nested2(_: Nested2) -> Nested2 { loop {} }
103 struct f32x4(f32, f32, f32, f32);
106 pub struct Vector(f32x4);
108 // CHECK: define{{.*}}<4 x float> @test_Vector(<4 x float> %_1)
110 pub extern "C" fn test_Vector(_: Vector) -> Vector { loop {} }
112 trait Mirror { type It: ?Sized; }
113 impl<T: ?Sized> Mirror for T { type It = Self; }
116 pub struct StructWithProjection(<f32 as Mirror>::It);
118 // CHECK: define{{.*}}float @test_Projection(float %_1)
120 pub extern "C" fn test_Projection(_: StructWithProjection) -> StructWithProjection { loop {} }
127 // CHECK: define{{.*}}float @test_EnumF32(float %_1)
129 pub extern "C" fn test_EnumF32(_: EnumF32) -> EnumF32 { loop {} }
132 pub enum EnumF32WithZsts {
133 Variant(Zst1, F32, Zst2)
136 // CHECK: define{{.*}}float @test_EnumF32WithZsts(float %_1)
138 pub extern "C" fn test_EnumF32WithZsts(_: EnumF32WithZsts) -> EnumF32WithZsts { loop {} }
145 // CHECK: define{{.*}}float @test_UnionF32(float %_1)
147 pub extern "C" fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
150 pub union UnionF32WithZsts {
156 // CHECK: define{{.*}}float @test_UnionF32WithZsts(float %_1)
158 pub extern "C" fn test_UnionF32WithZsts(_: UnionF32WithZsts) -> UnionF32WithZsts { loop {} }
161 // All that remains to be tested are aggregates. They are tested in separate files called repr-
162 // transparent-*.rs with `only-*` or `ignore-*` directives, because the expected LLVM IR
163 // function signatures vary so much that it's not reasonably possible to cover all of them with a
164 // single CHECK line.
166 // You may be wondering why we don't just compare the return types and argument types for equality
167 // with FileCheck regex captures. Well, rustc doesn't perform newtype unwrapping on newtypes
168 // containing aggregates. This is OK on all ABIs we support, but because LLVM has not gotten rid of
169 // pointee types yet, the IR function signature will be syntactically different (%Foo* vs