]> git.proxmox.com Git - rustc.git/blob - src/test/codegen/align-struct.rs
New upstream version 1.25.0+dfsg1
[rustc.git] / src / test / codegen / align-struct.rs
1 // Copyright 2016 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 // ignore-tidy-linelength
13
14 #![crate_type = "lib"]
15
16 #[repr(align(64))]
17 pub struct Align64(i32);
18 // CHECK: %Align64 = type { [0 x i32], i32, [15 x i32] }
19
20 pub struct Nested64 {
21 a: Align64,
22 b: i32,
23 c: i32,
24 d: i8,
25 }
26 // CHECK: %Nested64 = type { [0 x i64], %Align64, [0 x i32], i32, [0 x i32], i32, [0 x i8], i8, [55 x i8] }
27
28 pub enum Enum4 {
29 A(i32),
30 B(i32),
31 }
32 // CHECK: %Enum4 = type { [0 x i32], i32, [1 x i32] }
33 // CHECK: %"Enum4::A" = type { [1 x i32], i32, [0 x i32] }
34
35 pub enum Enum64 {
36 A(Align64),
37 B(i32),
38 }
39 // CHECK: %Enum64 = type { [0 x i32], i32, [31 x i32] }
40 // CHECK: %"Enum64::A" = type { [8 x i64], %Align64, [0 x i64] }
41
42 // CHECK-LABEL: @align64
43 #[no_mangle]
44 pub fn align64(i : i32) -> Align64 {
45 // CHECK: %a64 = alloca %Align64, align 64
46 // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 64, i32 64, i1 false)
47 let a64 = Align64(i);
48 a64
49 }
50
51 // CHECK-LABEL: @nested64
52 #[no_mangle]
53 pub fn nested64(a: Align64, b: i32, c: i32, d: i8) -> Nested64 {
54 // CHECK: %n64 = alloca %Nested64, align 64
55 let n64 = Nested64 { a, b, c, d };
56 n64
57 }
58
59 // CHECK-LABEL: @enum4
60 #[no_mangle]
61 pub fn enum4(a: i32) -> Enum4 {
62 // CHECK: %e4 = alloca %Enum4, align 4
63 let e4 = Enum4::A(a);
64 e4
65 }
66
67 // CHECK-LABEL: @enum64
68 #[no_mangle]
69 pub fn enum64(a: Align64) -> Enum64 {
70 // CHECK: %e64 = alloca %Enum64, align 64
71 let e64 = Enum64::A(a);
72 e64
73 }