]> git.lizzy.rs Git - rust.git/blob - tests/codegen/align-struct.rs
Rollup merge of #106958 - jyn514:labels, r=m-ou-se
[rust.git] / tests / codegen / align-struct.rs
1 // compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
2 //
3
4 #![crate_type = "lib"]
5
6 #[repr(align(64))]
7 pub struct Align64(i32);
8 // CHECK: %Align64 = type { i32, [15 x i32] }
9
10 pub struct Nested64 {
11     a: Align64,
12     b: i32,
13     c: i32,
14     d: i8,
15 }
16 // CHECK: %Nested64 = type { %Align64, i32, i32, i8, [55 x i8] }
17
18 pub enum Enum4 {
19     A(i32),
20     B(i32),
21 }
22 // No Aggregate type, and hence nothing in LLVM IR.
23
24 pub enum Enum64 {
25     A(Align64),
26     B(i32),
27 }
28 // CHECK: %Enum64 = type { i32, [31 x i32] }
29 // CHECK: %"Enum64::A" = type { [8 x i64], %Align64 }
30
31 // CHECK-LABEL: @align64
32 #[no_mangle]
33 pub fn align64(i : i32) -> Align64 {
34 // CHECK: %a64 = alloca %Align64, align 64
35 // CHECK: call void @llvm.memcpy.{{.*}}({{i8\*|ptr}} align 64 %{{.*}}, {{i8\*|ptr}} align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
36     let a64 = Align64(i);
37     a64
38 }
39
40 // For issue 54028: make sure that we are specifying the correct alignment for fields of aligned
41 // structs
42 // CHECK-LABEL: @align64_load
43 #[no_mangle]
44 pub fn align64_load(a: Align64) -> i32 {
45 // CHECK: {{%.*}} = load i32, {{i32\*|ptr}} {{%.*}}, align 64
46     a.0
47 }
48
49 // CHECK-LABEL: @nested64
50 #[no_mangle]
51 pub fn nested64(a: Align64, b: i32, c: i32, d: i8) -> Nested64 {
52 // CHECK: %n64 = alloca %Nested64, align 64
53     let n64 = Nested64 { a, b, c, d };
54     n64
55 }
56
57 // CHECK-LABEL: @enum4
58 #[no_mangle]
59 pub fn enum4(a: i32) -> Enum4 {
60 // CHECK: %e4 = alloca { i32, i32 }, align 4
61     let e4 = Enum4::A(a);
62     e4
63 }
64
65 // CHECK-LABEL: @enum64
66 #[no_mangle]
67 pub fn enum64(a: Align64) -> Enum64 {
68 // CHECK: %e64 = alloca %Enum64, align 64
69     let e64 = Enum64::A(a);
70     e64
71 }