]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/union-abi.rs
Enable emission of alignment attrs for pointer params
[rust.git] / src / test / codegen / union-abi.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // compile-flags: -C no-prepopulate-passes
12
13 // This test that using union forward the abi of the inner type, as
14 // discussed in #54668
15
16 #![crate_type="lib"]
17 #![feature(repr_simd)]
18
19 #[derive(Copy, Clone)]
20 pub enum Unhab {}
21
22 #[repr(simd)]
23 #[derive(Copy, Clone)]
24 pub struct i64x4(i64, i64, i64, i64);
25
26 #[derive(Copy, Clone)]
27 pub union UnionI64x4{ a:(), b: i64x4 }
28
29 // CHECK: define void @test_UnionI64x4(<4 x i64>* {{.*}} %arg0)
30 #[no_mangle]
31 pub fn test_UnionI64x4(_: UnionI64x4) { loop {} }
32
33 pub union UnionI64x4_{ a: i64x4, b: (), c:i64x4, d: Unhab, e: ((),()), f: UnionI64x4 }
34
35 // CHECK: define void @test_UnionI64x4_(<4 x i64>* {{.*}} %arg0)
36 #[no_mangle]
37 pub fn test_UnionI64x4_(_: UnionI64x4_) { loop {} }
38
39 pub union UnionI64x4I64{ a: i64x4, b: i64 }
40
41 // CHECK: define void @test_UnionI64x4I64(%UnionI64x4I64* {{.*}} %arg0)
42 #[no_mangle]
43 pub fn test_UnionI64x4I64(_: UnionI64x4I64) { loop {} }
44
45 pub union UnionI64x4Tuple{ a: i64x4, b: (i64, i64, i64, i64) }
46
47 // CHECK: define void @test_UnionI64x4Tuple(%UnionI64x4Tuple* {{.*}} %arg0)
48 #[no_mangle]
49 pub fn test_UnionI64x4Tuple(_: UnionI64x4Tuple) { loop {} }
50
51
52 pub union UnionF32{a:f32}
53
54 // CHECK: define float @test_UnionF32(float %arg0)
55 #[no_mangle]
56 pub fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
57
58 pub union UnionF32F32{a:f32, b:f32}
59
60 // CHECK: define float @test_UnionF32F32(float %arg0)
61 #[no_mangle]
62 pub fn test_UnionF32F32(_: UnionF32F32) -> UnionF32F32 { loop {} }
63
64 pub union UnionF32U32{a:f32, b:u32}
65
66 // CHECK: define i32 @test_UnionF32U32(i32)
67 #[no_mangle]
68 pub fn test_UnionF32U32(_: UnionF32U32) -> UnionF32U32 { loop {} }
69
70 pub union UnionU128{a:u128}
71 // CHECK: define i128 @test_UnionU128(i128 %arg0)
72 #[no_mangle]
73 pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }
74
75 #[repr(C)]
76 pub union CUnionU128{a:u128}
77 // CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %arg0)
78 #[no_mangle]
79 pub fn test_CUnionU128(_: CUnionU128) { loop {} }
80
81 pub union UnionBool { b:bool }
82 // CHECK: define zeroext i1 @test_UnionBool(i8 %b)
83 #[no_mangle]
84 pub fn test_UnionBool(b: UnionBool) -> bool { unsafe { b.b }  }
85 // CHECK: %0 = trunc i8 %b to i1
86