blob: a02bf9990ea5f17dcc9782e5605362c67ccb2ce2 [file] [log] [blame]
Manman Renc7d77b22013-04-30 17:38:09 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-optzns %s -emit-llvm -o - | FileCheck %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -struct-path-tbaa -disable-llvm-optzns %s -emit-llvm -o - | FileCheck %s -check-prefix=PATH
3// Test TBAA metadata generated by front-end.
4
5typedef unsigned char uint8_t;
6typedef unsigned short uint16_t;
7typedef unsigned int uint32_t;
8typedef unsigned long long uint64_t;
9class StructA
10{
11public:
12 uint16_t f16;
13 uint32_t f32;
14 uint16_t f16_2;
15 uint32_t f32_2;
16};
17class StructB
18{
19public:
20 uint16_t f16;
21 StructA a;
22 uint32_t f32;
23};
24class StructC
25{
26public:
27 uint16_t f16;
28 StructB b;
29 uint32_t f32;
30};
31class StructD
32{
33public:
34 uint16_t f16;
35 StructB b;
36 uint32_t f32;
37 uint8_t f8;
38};
39
40class StructS
41{
42public:
43 uint16_t f16;
44 uint32_t f32;
45};
46class StructS2 : public StructS
47{
48public:
49 uint16_t f16_2;
50 uint32_t f32_2;
51};
52
53uint32_t g(uint32_t *s, StructA *A, uint64_t count) {
54// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000055// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
56// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +000057// PATH: define i32 @{{.*}}(
58// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
59// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32:!.*]]
60 *s = 1;
61 A->f32 = 4;
62 return *s;
63}
64
65uint32_t g2(uint32_t *s, StructA *A, uint64_t count) {
66// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000067// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
68// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16:!.*]]
Manman Renc7d77b22013-04-30 17:38:09 +000069// PATH: define i32 @{{.*}}(
70// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
71// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_A_f16:!.*]]
72 *s = 1;
73 A->f16 = 4;
74 return *s;
75}
76
77uint32_t g3(StructA *A, StructB *B, uint64_t count) {
78// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000079// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
80// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +000081// PATH: define i32 @{{.*}}(
82// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
83// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32:!.*]]
84 A->f32 = 1;
85 B->a.f32 = 4;
86 return A->f32;
87}
88
89uint32_t g4(StructA *A, StructB *B, uint64_t count) {
90// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000091// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
92// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16]]
Manman Renc7d77b22013-04-30 17:38:09 +000093// PATH: define i32 @{{.*}}(
94// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
95// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_B_a_f16:!.*]]
96 A->f32 = 1;
97 B->a.f16 = 4;
98 return A->f32;
99}
100
101uint32_t g5(StructA *A, StructB *B, uint64_t count) {
102// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000103// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
104// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000105// PATH: define i32 @{{.*}}(
106// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
107// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_f32:!.*]]
108 A->f32 = 1;
109 B->f32 = 4;
110 return A->f32;
111}
112
113uint32_t g6(StructA *A, StructB *B, uint64_t count) {
114// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000115// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
116// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000117// PATH: define i32 @{{.*}}(
118// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
119// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32_2:!.*]]
120 A->f32 = 1;
121 B->a.f32_2 = 4;
122 return A->f32;
123}
124
125uint32_t g7(StructA *A, StructS *S, uint64_t count) {
126// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000127// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
128// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000129// PATH: define i32 @{{.*}}(
130// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
131// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32:!.*]]
132 A->f32 = 1;
133 S->f32 = 4;
134 return A->f32;
135}
136
137uint32_t g8(StructA *A, StructS *S, uint64_t count) {
138// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000139// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
140// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16]]
Manman Renc7d77b22013-04-30 17:38:09 +0000141// PATH: define i32 @{{.*}}(
142// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
143// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_S_f16:!.*]]
144 A->f32 = 1;
145 S->f16 = 4;
146 return A->f32;
147}
148
149uint32_t g9(StructS *S, StructS2 *S2, uint64_t count) {
150// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000151// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
152// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000153// PATH: define i32 @{{.*}}(
154// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
155// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32:!.*]]
156 S->f32 = 1;
157 S2->f32 = 4;
158 return S->f32;
159}
160
161uint32_t g10(StructS *S, StructS2 *S2, uint64_t count) {
162// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000163// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
164// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000165// PATH: define i32 @{{.*}}(
166// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
167// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_S2_f32_2:!.*]]
168 S->f32 = 1;
169 S2->f32_2 = 4;
170 return S->f32;
171}
172
173uint32_t g11(StructC *C, StructD *D, uint64_t count) {
174// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000175// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
176// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000177// PATH: define i32 @{{.*}}(
178// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_C_b_a_f32:!.*]]
179// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_D_b_a_f32:!.*]]
180 C->b.a.f32 = 1;
181 D->b.a.f32 = 4;
182 return C->b.a.f32;
183}
184
185uint32_t g12(StructC *C, StructD *D, uint64_t count) {
186// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000187// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
188// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renc7d77b22013-04-30 17:38:09 +0000189// TODO: differentiate the two accesses.
190// PATH: define i32 @{{.*}}(
191// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32]]
192// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32]]
193 StructB *b1 = &(C->b);
194 StructB *b2 = &(D->b);
195 // b1, b2 have different context.
196 b1->a.f32 = 1;
197 b2->a.f32 = 4;
198 return b1->a.f32;
199}
200
Richard Smitheb54d422013-07-14 06:18:38 +0000201// CHECK: [[TAG_char:!.*]] = metadata !{metadata !"omnipotent char", metadata [[TAG_cxx_tbaa:!.*]]}
202// CHECK: [[TAG_cxx_tbaa]] = metadata !{metadata !"Simple C/C++ TBAA"}
203// CHECK: [[TAG_i32]] = metadata !{metadata !"int", metadata [[TAG_char]]}
204// CHECK: [[TAG_i16]] = metadata !{metadata !"short", metadata [[TAG_char]]}
Manman Renc7d77b22013-04-30 17:38:09 +0000205
Richard Smitheb54d422013-07-14 06:18:38 +0000206// PATH: [[TYPE_CHAR:!.*]] = metadata !{metadata !"omnipotent char", metadata
Manman Renc7d77b22013-04-30 17:38:09 +0000207// PATH: [[TAG_i32]] = metadata !{metadata [[TYPE_INT:!.*]], metadata [[TYPE_INT]], i64 0}
208// PATH: [[TYPE_INT]] = metadata !{metadata !"int", metadata [[TYPE_CHAR]]
209// PATH: [[TAG_A_f32]] = metadata !{metadata [[TYPE_A:!.*]], metadata [[TYPE_INT]], i64 4}
210// PATH: [[TYPE_A]] = metadata !{metadata !"_ZTS7StructA", metadata [[TYPE_SHORT:!.*]], i64 0, metadata [[TYPE_INT]], i64 4, metadata [[TYPE_SHORT]], i64 8, metadata [[TYPE_INT]], i64 12}
211// PATH: [[TYPE_SHORT:!.*]] = metadata !{metadata !"short", metadata [[TYPE_CHAR]]
212// PATH: [[TAG_A_f16]] = metadata !{metadata [[TYPE_A]], metadata [[TYPE_SHORT]], i64 0}
213// PATH: [[TAG_B_a_f32]] = metadata !{metadata [[TYPE_B:!.*]], metadata [[TYPE_INT]], i64 8}
214// PATH: [[TYPE_B]] = metadata !{metadata !"_ZTS7StructB", metadata [[TYPE_SHORT]], i64 0, metadata [[TYPE_A]], i64 4, metadata [[TYPE_INT]], i64 20}
215// PATH: [[TAG_B_a_f16]] = metadata !{metadata [[TYPE_B]], metadata [[TYPE_SHORT]], i64 4}
216// PATH: [[TAG_B_f32]] = metadata !{metadata [[TYPE_B]], metadata [[TYPE_INT]], i64 20}
217// PATH: [[TAG_B_a_f32_2]] = metadata !{metadata [[TYPE_B]], metadata [[TYPE_INT]], i64 16}
218// PATH: [[TAG_S_f32]] = metadata !{metadata [[TYPE_S:!.*]], metadata [[TYPE_INT]], i64 4}
219// PATH: [[TYPE_S]] = metadata !{metadata !"_ZTS7StructS", metadata [[TYPE_SHORT]], i64 0, metadata [[TYPE_INT]], i64 4}
220// PATH: [[TAG_S_f16]] = metadata !{metadata [[TYPE_S]], metadata [[TYPE_SHORT]], i64 0}
221// PATH: [[TAG_S2_f32_2]] = metadata !{metadata [[TYPE_S2:!.*]], metadata [[TYPE_INT]], i64 12}
222// PATH: [[TYPE_S2]] = metadata !{metadata !"_ZTS8StructS2", metadata [[TYPE_SHORT]], i64 8, metadata [[TYPE_INT]], i64 12}
223// PATH: [[TAG_C_b_a_f32]] = metadata !{metadata [[TYPE_C:!.*]], metadata [[TYPE_INT]], i64 12}
224// PATH: [[TYPE_C]] = metadata !{metadata !"_ZTS7StructC", metadata [[TYPE_SHORT]], i64 0, metadata [[TYPE_B]], i64 4, metadata [[TYPE_INT]], i64 28}
225// PATH: [[TAG_D_b_a_f32]] = metadata !{metadata [[TYPE_D:!.*]], metadata [[TYPE_INT]], i64 12}
226// PATH: [[TYPE_D]] = metadata !{metadata !"_ZTS7StructD", metadata [[TYPE_SHORT]], i64 0, metadata [[TYPE_B]], i64 4, metadata [[TYPE_INT]], i64 28, metadata [[TYPE_CHAR]], i64 32}