]> git.proxmox.com Git - rustc.git/blob - src/test/codegen/align-struct.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / src / test / 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 { [0 x i32], 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 { [0 x i64], %Align64, [0 x i32], i32, [0 x i32], i32, [0 x i8], i8, [55 x i8] }
17
18 pub enum Enum4 {
19 A(i32),
20 B(i32),
21 }
22 // CHECK: %"Enum4::A" = type { [1 x i32], i32, [0 x i32] }
23
24 pub enum Enum64 {
25 A(Align64),
26 B(i32),
27 }
28 // CHECK: %Enum64 = type { [0 x i32], i32, [31 x i32] }
29 // CHECK: %"Enum64::A" = type { [8 x i64], %Align64, [0 x i64] }
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* align 64 %{{.*}}, i8* 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: [[FIELD:%.*]] = bitcast %Align64* %{{.*}} to i32*
46 // CHECK: {{%.*}} = load i32, i32* [[FIELD]], align 64
47 a.0
48 }
49
50 // CHECK-LABEL: @nested64
51 #[no_mangle]
52 pub fn nested64(a: Align64, b: i32, c: i32, d: i8) -> Nested64 {
53 // CHECK: %n64 = alloca %Nested64, align 64
54 let n64 = Nested64 { a, b, c, d };
55 n64
56 }
57
58 // CHECK-LABEL: @enum4
59 #[no_mangle]
60 pub fn enum4(a: i32) -> Enum4 {
61 // CHECK: %e4 = alloca { i32, i32 }, align 4
62 let e4 = Enum4::A(a);
63 e4
64 }
65
66 // CHECK-LABEL: @enum64
67 #[no_mangle]
68 pub fn enum64(a: Align64) -> Enum64 {
69 // CHECK: %e64 = alloca %Enum64, align 64
70 let e64 = Enum64::A(a);
71 e64
72 }