]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/align-struct.rs
Enable emission of alignment attrs for pointer params
[rust.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 // min-llvm-version 7.0
14
15 #![crate_type = "lib"]
16
17 #[repr(align(64))]
18 pub struct Align64(i32);
19 // CHECK: %Align64 = type { [0 x i32], i32, [15 x i32] }
20
21 pub struct Nested64 {
22     a: Align64,
23     b: i32,
24     c: i32,
25     d: i8,
26 }
27 // CHECK: %Nested64 = type { [0 x i64], %Align64, [0 x i32], i32, [0 x i32], i32, [0 x i8], i8, [55 x i8] }
28
29 pub enum Enum4 {
30     A(i32),
31     B(i32),
32 }
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* align 64 %{{.*}}, i8* align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
47     let a64 = Align64(i);
48     a64
49 }
50
51 // For issue 54028: make sure that we are specifying the correct alignment for fields of aligned
52 // structs
53 // CHECK-LABEL: @align64_load
54 #[no_mangle]
55 pub fn align64_load(a: Align64) -> i32 {
56 // CHECK: [[FIELD:%.*]] = bitcast %Align64* %{{.*}} to i32*
57 // CHECK: {{%.*}} = load i32, i32* [[FIELD]], align 64
58     a.0
59 }
60
61 // CHECK-LABEL: @nested64
62 #[no_mangle]
63 pub fn nested64(a: Align64, b: i32, c: i32, d: i8) -> Nested64 {
64 // CHECK: %n64 = alloca %Nested64, align 64
65     let n64 = Nested64 { a, b, c, d };
66     n64
67 }
68
69 // CHECK-LABEL: @enum4
70 #[no_mangle]
71 pub fn enum4(a: i32) -> Enum4 {
72 // CHECK: %e4 = alloca { i32, i32 }, align 4
73     let e4 = Enum4::A(a);
74     e4
75 }
76
77 // CHECK-LABEL: @enum64
78 #[no_mangle]
79 pub fn enum64(a: Align64) -> Enum64 {
80 // CHECK: %e64 = alloca %Enum64, align 64
81     let e64 = Enum64::A(a);
82     e64
83 }