4
4
5
5
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir -O1
6
6
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
7
+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll -O1 -disable-llvm-passes -no-struct-path-tbaa
8
+ // RUN: FileCheck --check-prefix=CHECK --input-file=%t.ll %s
9
+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll -O1 -disable-llvm-passes
10
+ // RUN: FileCheck --check-prefixes=PATH,OLD-PATH --input-file=%t.ll %s
11
+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll -O1 -disable-llvm-passes -relaxed-aliasing
12
+ // RUN: FileCheck --check-prefix=NO-TBAA --input-file=%t.ll %s
13
+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll -O0 -disable-llvm-passes
14
+ // RUN: FileCheck --check-prefix=NO-TBAA --input-file=%t.ll %s
7
15
16
+ // NO-TBAA-NOT: !tbaa
8
17
// CIR: #tbaa[[NYI:.*]] = #cir.tbaa
9
18
// CIR: #tbaa[[CHAR:.*]] = #cir.tbaa_omnipotent_char
10
19
// CIR: #tbaa[[INT:.*]] = #cir.tbaa_scalar<id = "int", type = !s32i>
@@ -81,6 +90,14 @@ uint32_t g(uint32_t *s, StructA *A, uint64_t count) {
81
90
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
82
91
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
83
92
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructA_f32]])
93
+
94
+
95
+ // CHECK-LABEL: define{{.*}} i32 @_Z1g
96
+ // CHECK: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
97
+ // CHECK: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
98
+ // PATH-LABEL: define{{.*}} i32 @_Z1g
99
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
100
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32:!.*]]
84
101
*s = 1 ;
85
102
A->f32 = 4 ;
86
103
return *s;
@@ -94,6 +111,13 @@ uint32_t g2(uint32_t *s, StructA *A, uint64_t count) {
94
111
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
95
112
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u16i
96
113
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u16i, !cir.ptr<!u16i> tbaa(#tbaa[[TAG_StructA_f16]])
114
+
115
+ // CHECK-LABEL: define{{.*}} i32 @_Z2g2
116
+ // CHECK: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
117
+ // CHECK: store i16 4, ptr %{{.*}}, align {{4|2}}, !tbaa [[TAG_i16:!.*]]
118
+ // PATH-LABEL: define{{.*}} i32 @_Z2g2
119
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
120
+ // PATH: store i16 4, ptr %{{.*}}, align {{4|2}}, !tbaa [[TAG_A_f16:!.*]]
97
121
*s = 1 ;
98
122
A->f16 = 4 ;
99
123
return *s;
@@ -107,6 +131,13 @@ uint32_t g3(StructA *A, StructB *B, uint64_t count) {
107
131
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
108
132
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
109
133
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructB_a_f32]])
134
+
135
+ // CHECK-LABEL: define{{.*}} i32 @_Z2g3
136
+ // CHECK: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
137
+ // CHECK: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
138
+ // PATH-LABEL: define{{.*}} i32 @_Z2g3
139
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
140
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_B_a_f32:!.*]]
110
141
A->f32 = 1 ;
111
142
B->a .f32 = 4 ;
112
143
return A->f32 ;
@@ -120,6 +151,13 @@ uint32_t g4(StructA *A, StructB *B, uint64_t count) {
120
151
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
121
152
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u16i
122
153
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u16i, !cir.ptr<!u16i> tbaa(#tbaa[[TAG_StructB_a_f16]])
154
+
155
+ // LLVM-LABEL: define{{.*}} i32 @_Z2g4
156
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
157
+ // LLVM: store i16 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i16]]
158
+ // PATH-LABEL: define{{.*}} i32 @_Z2g4
159
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
160
+ // PATH: store i16 4, ptr %{{.*}}, align {{4|2}}, !tbaa [[TAG_B_a_f16:!.*]]
123
161
A->f32 = 1 ;
124
162
B->a .f16 = 4 ;
125
163
return A->f32 ;
@@ -133,6 +171,13 @@ uint32_t g5(StructA *A, StructB *B, uint64_t count) {
133
171
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
134
172
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
135
173
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructB_f32]])
174
+
175
+ // LLVM-LABEL: define{{.*}} i32 @_Z2g5
176
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
177
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
178
+ // PATH-LABEL: define{{.*}} i32 @_Z2g5
179
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
180
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_B_f32:!.*]]
136
181
A->f32 = 1 ;
137
182
B->f32 = 4 ;
138
183
return A->f32 ;
@@ -146,6 +191,13 @@ uint32_t g6(StructA *A, StructB *B, uint64_t count) {
146
191
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
147
192
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
148
193
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructB_a_f32_2]])
194
+
195
+ // LLVM-LABEL: define{{.*}} i32 @_Z2g6
196
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
197
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
198
+ // PATH-LABEL: define{{.*}} i32 @_Z2g6
199
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
200
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_B_a_f32_2:!.*]]
149
201
A->f32 = 1 ;
150
202
B->a .f32_2 = 4 ;
151
203
return A->f32 ;
@@ -159,6 +211,13 @@ uint32_t g7(StructA *A, StructS *S, uint64_t count) {
159
211
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
160
212
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
161
213
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructS_f32]])
214
+
215
+ // LLVM-LABEL: define{{.*}} i32 @_Z2g7
216
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
217
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
218
+ // PATH-LABEL: define{{.*}} i32 @_Z2g7
219
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
220
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_S_f32:!.*]]
162
221
A->f32 = 1 ;
163
222
S->f32 = 4 ;
164
223
return A->f32 ;
@@ -172,6 +231,13 @@ uint32_t g8(StructA *A, StructS *S, uint64_t count) {
172
231
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
173
232
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u16i
174
233
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u16i, !cir.ptr<!u16i> tbaa(#tbaa[[TAG_StructS_f16]])
234
+
235
+ // LLVM-LABEL: define{{.*}} i32 @_Z2g8
236
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
237
+ // LLVM: store i16 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i16]]
238
+ // PATH-LABEL: define{{.*}} i32 @_Z2g8
239
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
240
+ // PATH: store i16 4, ptr %{{.*}}, align {{4|2}}, !tbaa [[TAG_S_f16:!.*]]
175
241
A->f32 = 1 ;
176
242
S->f16 = 4 ;
177
243
return A->f32 ;
@@ -185,6 +251,13 @@ uint32_t g9(StructS *S, StructS2 *S2, uint64_t count) {
185
251
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
186
252
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
187
253
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructS2_f32]])
254
+
255
+ // LLVM-LABEL: define{{.*}} i32 @_Z2g9
256
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
257
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
258
+ // PATH-LABEL: define{{.*}} i32 @_Z2g9
259
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
260
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_S2_f32:!.*]]
188
261
S->f32 = 1 ;
189
262
S2->f32 = 4 ;
190
263
return S->f32 ;
@@ -198,6 +271,13 @@ uint32_t g10(StructS *S, StructS2 *S2, uint64_t count) {
198
271
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
199
272
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u16i
200
273
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u16i, !cir.ptr<!u16i> tbaa(#tbaa[[TAG_StructS2_f16]])
274
+
275
+ // LLVM-LABEL: define{{.*}} i32 @_Z3g10
276
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
277
+ // LLVM: store i16 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i16]]
278
+ // PATH-LABEL: define{{.*}} i32 @_Z3g10
279
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
280
+ // PATH: store i16 4, ptr %{{.*}}, align {{4|2}}, !tbaa [[TAG_S2_f16:!.*]]
201
281
S->f32 = 1 ;
202
282
S2->f16 = 4 ;
203
283
return S->f32 ;
@@ -211,6 +291,13 @@ uint32_t g11(StructC *C, StructD *D, uint64_t count) {
211
291
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
212
292
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
213
293
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructD_b_a_f32]])
294
+
295
+ // LLVM-LABEL: define{{.*}} i32 @_Z3g11
296
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
297
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
298
+ // PATH-LABEL: define{{.*}} i32 @_Z3g11
299
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_C_b_a_f32:!.*]]
300
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_D_b_a_f32:!.*]]
214
301
C->b .a .f32 = 1 ;
215
302
D->b .a .f32 = 4 ;
216
303
return C->b .a .f32 ;
@@ -224,6 +311,14 @@ uint32_t g12(StructC *C, StructD *D, uint64_t count) {
224
311
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
225
312
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
226
313
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructB_a_f32]])
314
+
315
+ // LLVM-LABEL: define{{.*}} i32 @_Z3g12
316
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
317
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
318
+ // TODO(cir): differentiate the two accesses.
319
+ // PATH-LABEL: define{{.*}} i32 @_Z3g12
320
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_B_a_f32]]
321
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_B_a_f32]]
227
322
StructB *b1 = &(C->b );
228
323
StructB *b2 = &(D->b );
229
324
// b1, b2 have different context.
@@ -243,6 +338,11 @@ char g14(struct six *a, struct six *b) {
243
338
// CIR: %[[TMP1:.*]] = cir.load %{{.*}} : !cir.ptr<!cir.ptr<!ty_six>>, !cir.ptr<!ty_six>
244
339
// CIR: %[[TMP2:.*]] = cir.get_member %[[TMP1]][2] {name = "b"} : !cir.ptr<!ty_six> -> !cir.ptr<!s8i>
245
340
// CIR: %[[TMP3:.*]] = cir.load %[[TMP2]] : !cir.ptr<!s8i>, !s8i tbaa(#tbaa[[TAG_six_b]])
341
+
342
+ // LLVM-LABEL: define{{.*}} i8 @_Z3g14
343
+ // LLVM: load i8, ptr %{{.*}}, align 1, !tbaa [[TAG_char]]
344
+ // PATH-LABEL: define{{.*}} i8 @_Z3g14
345
+ // PATH: load i8, ptr %{{.*}}, align 1, !tbaa [[TAG_six_b:!.*]]
246
346
return a->b ;
247
347
}
248
348
@@ -256,7 +356,49 @@ uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) {
256
356
// CIR: %[[INT_4:.*]] = cir.const #cir.int<4> : !s32i
257
357
// CIR: %[[UINT_4:.*]] = cir.cast(integral, %[[INT_4]] : !s32i), !u32i
258
358
// CIR: cir.store %[[UINT_4]], %{{.*}} : !u32i, !cir.ptr<!u32i> tbaa(#tbaa[[TAG_StructS_f32]])
359
+
360
+
361
+ // LLVM-LABEL: define{{.*}} i32 @_Z3g15
362
+ // LLVM: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
363
+ // LLVM: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
364
+ // PATH-LABEL: define{{.*}} i32 @_Z3g15
365
+ // PATH: store i32 1, ptr %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
366
+ // PATH: store i32 4, ptr %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
259
367
S->f32 = 1 ;
260
368
S3->f32 = 4 ;
261
369
return S->f32 ;
262
370
}
371
+
372
+ // LLVM: [[TYPE_char:!.*]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
373
+ // LLVM: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
374
+ // LLVM: [[TAG_i32]] = !{[[TYPE_i32:!.*]], [[TYPE_i32]], i64 0}
375
+ // LLVM: [[TYPE_i32]] = !{!"int", [[TYPE_char]],
376
+ // LLVM: [[TAG_i16]] = !{[[TYPE_i16:!.*]], [[TYPE_i16]], i64 0}
377
+ // LLVM: [[TYPE_i16]] = !{!"short", [[TYPE_char]],
378
+ // LLVM: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0}
379
+
380
+ // OLD-PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
381
+ // OLD-PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0}
382
+ // OLD-PATH: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
383
+ // OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
384
+ // OLD-PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
385
+ // OLD-PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
386
+ // OLD-PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]
387
+ // OLD-PATH: [[TAG_A_f16]] = !{[[TYPE_A]], [[TYPE_SHORT]], i64 0}
388
+ // OLD-PATH: [[TAG_B_a_f32]] = !{[[TYPE_B:!.*]], [[TYPE_INT]], i64 8}
389
+ // OLD-PATH: [[TYPE_B]] = !{!"_ZTS7StructB", [[TYPE_SHORT]], i64 0, [[TYPE_A]], i64 4, [[TYPE_INT]], i64 20}
390
+ // OLD-PATH: [[TAG_B_a_f16]] = !{[[TYPE_B]], [[TYPE_SHORT]], i64 4}
391
+ // OLD-PATH: [[TAG_B_f32]] = !{[[TYPE_B]], [[TYPE_INT]], i64 20}
392
+ // OLD-PATH: [[TAG_B_a_f32_2]] = !{[[TYPE_B]], [[TYPE_INT]], i64 16}
393
+ // OLD-PATH: [[TAG_S_f32]] = !{[[TYPE_S:!.*]], [[TYPE_INT]], i64 4}
394
+ // OLD-PATH: [[TYPE_S]] = !{!"_ZTS7StructS", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
395
+ // OLD-PATH: [[TAG_S_f16]] = !{[[TYPE_S]], [[TYPE_SHORT]], i64 0}
396
+ // OLD-PATH: [[TAG_S2_f32]] = !{[[TYPE_S2:!.*]], [[TYPE_INT]], i64 4}
397
+ // OLD-PATH: [[TYPE_S2]] = !{!"_ZTS8StructS2", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
398
+ // OLD-PATH: [[TAG_S2_f16]] = !{[[TYPE_S2]], [[TYPE_SHORT]], i64 0}
399
+ // OLD-PATH: [[TAG_C_b_a_f32]] = !{[[TYPE_C:!.*]], [[TYPE_INT]], i64 12}
400
+ // OLD-PATH: [[TYPE_C]] = !{!"_ZTS7StructC", [[TYPE_SHORT]], i64 0, [[TYPE_B]], i64 4, [[TYPE_INT]], i64 28}
401
+ // OLD-PATH: [[TAG_D_b_a_f32]] = !{[[TYPE_D:!.*]], [[TYPE_INT]], i64 12}
402
+ // OLD-PATH: [[TYPE_D]] = !{!"_ZTS7StructD", [[TYPE_SHORT]], i64 0, [[TYPE_B]], i64 4, [[TYPE_INT]], i64 28, [[TYPE_CHAR]], i64 32}
403
+ // OLD-PATH: [[TAG_six_b]] = !{[[TYPE_six:!.*]], [[TYPE_CHAR]], i64 4}
404
+ // OLD-PATH: [[TYPE_six]] = !{!"_ZTS3six", [[TYPE_CHAR]], i64 0, [[TYPE_CHAR]], i64 4, [[TYPE_CHAR]], i64 5}
0 commit comments