Debian Codegraph @

clang/test/CIR/CodeGen/align-store.c

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2 // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4 // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6 // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7
8 // PR5279 - Reduced alignment on typedef.
9 typedef int myint __attribute__((aligned(1)));
10
11 void test1(myint *p) {
12 *p = 0;
13 }
14
15 // CIR: cir.func{{.*}} @test1
16 // CIR: cir.store align(1)
17
18 // LLVM: @test1
19 // LLVM: store i32 0, ptr {{.*}}, align 1
20 // LLVM: ret void
21
22 // OGCG: @test1
23 // OGCG: store i32 0, ptr {{.*}}, align 1
24 // OGCG: ret void
25
26 typedef unsigned char uint8_t;
27 typedef unsigned short uint16_t;
28 typedef unsigned int uint32_t;
29 typedef unsigned long long uint64_t;
30 typedef struct
31 {
32 uint16_t i16;
33 uint32_t i32;
34 uint16_t i16_2;
35 uint32_t i32_2;
36 } StructA;
37
38 void test2(StructA* p) {
39 p->i16 = 1;
40 p->i32 = 2;
41 p->i16_2 = 3;
42 p->i32_2 = 4;
43 }
44
45 // CIR-LABEL: @test2
46 // CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u16i, !cir.ptr<!u16i>
47 // CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u32i, !cir.ptr<!u32i>
48 // CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u16i, !cir.ptr<!u16i>
49 // CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u32i, !cir.ptr<!u32i>
50
51 // LLVM: @test2
52 // LLVM: store i16 1, ptr {{.*}}, align 4
53 // LLVM: store i32 2, ptr {{.*}}, align 4
54 // LLVM: store i16 3, ptr {{.*}}, align 4
55 // LLVM: store i32 4, ptr {{.*}}, align 4
56
57 // OGCG: @test2
58 // OGCG: store i16 1, ptr {{.*}}, align 4
59 // OGCG: store i32 2, ptr {{.*}}, align 4
60 // OGCG: store i16 3, ptr {{.*}}, align 4
61 // OGCG: store i32 4, ptr {{.*}}, align 4
62
63 typedef struct {
64 short a;
65 short b;
66 short c;
67 short d;
68 long e; // Make the struct 8-byte aligned
69 } StructB;
70
71 void test3(StructB *ptr) {
72 ptr->a = 1; // align 8
73 ptr->b = 2; // align 2
74 ptr->c = 3; // align 4
75 ptr->d = 4; // align 2
76 }
77
78 // CIR-LABEL: @test3
79 // CIR: cir.store align(8) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>
80 // CIR: cir.store align(2) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>
81 // CIR: cir.store align(4) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>
82 // CIR: cir.store align(2) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>
83
84 // LLVM: @test3
85 // LLVM: store i16 1, ptr {{.*}}, align 8
86 // LLVM: store i16 2, ptr {{.*}}, align 2
87 // LLVM: store i16 3, ptr {{.*}}, align 4
88 // LLVM: store i16 4, ptr {{.*}}, align 2
89
90 // OGCG: @test3
91 // OGCG: store i16 1, ptr {{.*}}, align 8
92 // OGCG: store i16 2, ptr {{.*}}, align 2
93 // OGCG: store i16 3, ptr {{.*}}, align 4
94 // OGCG: store i16 4, ptr {{.*}}, align 2