]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/union-abi.rs
Rollup merge of #65389 - ecstatic-morse:zero-sized-array-no-drop, r=eddyb
[rust.git] / src / test / codegen / union-abi.rs
1 // compile-flags: -C no-prepopulate-passes
2
3 // This test that using union forward the abi of the inner type, as
4 // discussed in #54668
5
6 #![crate_type="lib"]
7 #![feature(repr_simd)]
8
9 #[derive(Copy, Clone)]
10 pub enum Unhab {}
11
12 #[repr(simd)]
13 #[derive(Copy, Clone)]
14 pub struct i64x4(i64, i64, i64, i64);
15
16 #[derive(Copy, Clone)]
17 pub union UnionI64x4{ a:(), b: i64x4 }
18
19 // CHECK: define void @test_UnionI64x4(<4 x i64>* {{.*}} %_1)
20 #[no_mangle]
21 pub fn test_UnionI64x4(_: UnionI64x4) { loop {} }
22
23 pub union UnionI64x4_{ a: i64x4, b: (), c:i64x4, d: Unhab, e: ((),()), f: UnionI64x4 }
24
25 // CHECK: define void @test_UnionI64x4_(<4 x i64>* {{.*}} %_1)
26 #[no_mangle]
27 pub fn test_UnionI64x4_(_: UnionI64x4_) { loop {} }
28
29 pub union UnionI64x4I64{ a: i64x4, b: i64 }
30
31 // CHECK: define void @test_UnionI64x4I64(%UnionI64x4I64* {{.*}} %_1)
32 #[no_mangle]
33 pub fn test_UnionI64x4I64(_: UnionI64x4I64) { loop {} }
34
35 pub union UnionI64x4Tuple{ a: i64x4, b: (i64, i64, i64, i64) }
36
37 // CHECK: define void @test_UnionI64x4Tuple(%UnionI64x4Tuple* {{.*}} %_1)
38 #[no_mangle]
39 pub fn test_UnionI64x4Tuple(_: UnionI64x4Tuple) { loop {} }
40
41
42 pub union UnionF32{a:f32}
43
44 // CHECK: define float @test_UnionF32(float %_1)
45 #[no_mangle]
46 pub fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
47
48 pub union UnionF32F32{a:f32, b:f32}
49
50 // CHECK: define float @test_UnionF32F32(float %_1)
51 #[no_mangle]
52 pub fn test_UnionF32F32(_: UnionF32F32) -> UnionF32F32 { loop {} }
53
54 pub union UnionF32U32{a:f32, b:u32}
55
56 // CHECK: define i32 @test_UnionF32U32(i32)
57 #[no_mangle]
58 pub fn test_UnionF32U32(_: UnionF32U32) -> UnionF32U32 { loop {} }
59
60 pub union UnionU128{a:u128}
61 // CHECK: define i128 @test_UnionU128(i128 %_1)
62 #[no_mangle]
63 pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }
64
65 #[repr(C)]
66 pub union CUnionU128{a:u128}
67 // CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %_1)
68 #[no_mangle]
69 pub fn test_CUnionU128(_: CUnionU128) { loop {} }
70
71 pub union UnionBool { b:bool }
72 // CHECK: define zeroext i1 @test_UnionBool(i8 %b)
73 #[no_mangle]
74 pub fn test_UnionBool(b: UnionBool) -> bool { unsafe { b.b }  }
75 // CHECK: %0 = trunc i8 %b to i1