blob: 2bff5d0ba07025ed15ff44ecf1372381bb70d9bf [file] [log] [blame]
Manman Ren96d6c452013-10-11 20:48:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa -disable-llvm-optzns %s -emit-llvm -o - | FileCheck %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-optzns %s -emit-llvm -o - | FileCheck %s -check-prefix=PATH
Manman Renb3cced92013-04-05 00:05:09 +00003// Test TBAA metadata generated by front-end.
4
Manman Renc80e0312013-04-05 19:06:10 +00005typedef unsigned char uint8_t;
6typedef unsigned short uint16_t;
7typedef unsigned int uint32_t;
8typedef unsigned long long uint64_t;
Manman Renb3cced92013-04-05 00:05:09 +00009typedef struct
10{
11 uint16_t f16;
12 uint32_t f32;
13 uint16_t f16_2;
14 uint32_t f32_2;
15} StructA;
16typedef struct
17{
18 uint16_t f16;
19 StructA a;
20 uint32_t f32;
21} StructB;
22typedef struct
23{
24 uint16_t f16;
25 StructB b;
26 uint32_t f32;
27} StructC;
28typedef struct
29{
30 uint16_t f16;
31 StructB b;
32 uint32_t f32;
33 uint8_t f8;
34} StructD;
35
36typedef struct
37{
38 uint16_t f16;
39 uint32_t f32;
40} StructS;
41typedef struct
42{
43 uint16_t f16;
44 uint32_t f32;
45} StructS2;
46
47uint32_t g(uint32_t *s, StructA *A, uint64_t count) {
48// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000049// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
50// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +000051// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +000052// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
53// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +000054 *s = 1;
55 A->f32 = 4;
56 return *s;
57}
58
59uint32_t g2(uint32_t *s, StructA *A, uint64_t count) {
60// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000061// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
62// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +000063// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +000064// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
65// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_A_f16:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +000066 *s = 1;
67 A->f16 = 4;
68 return *s;
69}
70
71uint32_t g3(StructA *A, StructB *B, uint64_t count) {
72// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000073// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
74// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +000075// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +000076// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
77// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +000078 A->f32 = 1;
79 B->a.f32 = 4;
80 return A->f32;
81}
82
83uint32_t g4(StructA *A, StructB *B, uint64_t count) {
84// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000085// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
86// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16]]
Manman Renb3cced92013-04-05 00:05:09 +000087// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +000088// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
89// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_B_a_f16:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +000090 A->f32 = 1;
91 B->a.f16 = 4;
92 return A->f32;
93}
94
95uint32_t g5(StructA *A, StructB *B, uint64_t count) {
96// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +000097// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
98// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +000099// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000100// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
101// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_f32:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000102 A->f32 = 1;
103 B->f32 = 4;
104 return A->f32;
105}
106
107uint32_t g6(StructA *A, StructB *B, uint64_t count) {
108// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000109// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
110// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +0000111// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000112// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
113// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32_2:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000114 A->f32 = 1;
115 B->a.f32_2 = 4;
116 return A->f32;
117}
118
119uint32_t g7(StructA *A, StructS *S, uint64_t count) {
120// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000121// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
122// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +0000123// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000124// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
125// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000126 A->f32 = 1;
127 S->f32 = 4;
128 return A->f32;
129}
130
131uint32_t g8(StructA *A, StructS *S, uint64_t count) {
132// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000133// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
134// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16]]
Manman Renb3cced92013-04-05 00:05:09 +0000135// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000136// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_A_f32]]
137// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_S_f16:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000138 A->f32 = 1;
139 S->f16 = 4;
140 return A->f32;
141}
142
143uint32_t g9(StructS *S, StructS2 *S2, uint64_t count) {
144// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000145// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
146// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +0000147// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000148// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
149// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_S2_f32:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000150 S->f32 = 1;
151 S2->f32 = 4;
152 return S->f32;
153}
154
155uint32_t g10(StructS *S, StructS2 *S2, uint64_t count) {
156// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000157// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
158// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_i16]]
Manman Renb3cced92013-04-05 00:05:09 +0000159// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000160// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
161// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa [[TAG_S2_f16:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000162 S->f32 = 1;
163 S2->f16 = 4;
164 return S->f32;
165}
166
167uint32_t g11(StructC *C, StructD *D, uint64_t count) {
168// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000169// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
170// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +0000171// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000172// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_C_b_a_f32:!.*]]
173// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_D_b_a_f32:!.*]]
Manman Renb3cced92013-04-05 00:05:09 +0000174 C->b.a.f32 = 1;
175 D->b.a.f32 = 4;
176 return C->b.a.f32;
177}
178
179uint32_t g12(StructC *C, StructD *D, uint64_t count) {
180// CHECK: define i32 @{{.*}}(
Richard Smitheb54d422013-07-14 06:18:38 +0000181// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
182// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
Manman Renb3cced92013-04-05 00:05:09 +0000183// TODO: differentiate the two accesses.
184// PATH: define i32 @{{.*}}(
Manman Renca835182013-04-11 23:02:56 +0000185// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32]]
186// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_B_a_f32]]
Manman Renb3cced92013-04-05 00:05:09 +0000187 StructB *b1 = &(C->b);
188 StructB *b2 = &(D->b);
189 // b1, b2 have different context.
190 b1->a.f32 = 1;
191 b2->a.f32 = 4;
192 return b1->a.f32;
193}
194
Manman Renc7f2bfb2013-04-22 19:50:07 +0000195// Make sure that zero-length bitfield works.
196#define ATTR __attribute__ ((ms_struct))
197struct five {
198 char a;
199 int :0; /* ignored; prior field is not a bitfield. */
200 char b;
201 char c;
202} ATTR;
203char g13(struct five *a, struct five *b) {
204 return a->b;
205// CHECK: define signext i8 @{{.*}}(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700206// CHECK: load i8, i8* %{{.*}}, align 1, !tbaa [[TAG_char:!.*]]
Manman Renc7f2bfb2013-04-22 19:50:07 +0000207// PATH: define signext i8 @{{.*}}(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700208// PATH: load i8, i8* %{{.*}}, align 1, !tbaa [[TAG_five_b:!.*]]
Manman Renc7f2bfb2013-04-22 19:50:07 +0000209}
210
211struct six {
212 char a;
213 int :0;
214 char b;
215 char c;
216};
217char g14(struct six *a, struct six *b) {
218// CHECK: define signext i8 @{{.*}}(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700219// CHECK: load i8, i8* %{{.*}}, align 1, !tbaa [[TAG_char]]
Manman Renc7f2bfb2013-04-22 19:50:07 +0000220// PATH: define signext i8 @{{.*}}(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700221// PATH: load i8, i8* %{{.*}}, align 1, !tbaa [[TAG_six_b:!.*]]
Manman Renc7f2bfb2013-04-22 19:50:07 +0000222 return a->b;
223}
224
Manman Ren8183b8e2013-08-21 21:00:10 +0000225// Types that differ only by name may alias.
226typedef StructS StructS3;
227uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) {
228// CHECK: define i32 @{{.*}}(
229// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
230// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_i32]]
231// PATH: define i32 @{{.*}}(
232// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
233// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa [[TAG_S_f32]]
234 S->f32 = 1;
235 S3->f32 = 4;
236 return S->f32;
237}
238
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700239// CHECK: [[TYPE_char:!.*]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
240// CHECK: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
241// CHECK: [[TAG_i32]] = !{[[TYPE_i32:!.*]], [[TYPE_i32]], i64 0}
242// CHECK: [[TYPE_i32]] = !{!"int", [[TYPE_char]],
243// CHECK: [[TAG_i16]] = !{[[TYPE_i16:!.*]], [[TYPE_i16]], i64 0}
244// CHECK: [[TYPE_i16]] = !{!"short", [[TYPE_char]],
245// CHECK: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0}
Manman Renb3cced92013-04-05 00:05:09 +0000246
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700247// PATH: [[TYPE_CHAR:!.*]] = !{!"omnipotent char", !
248// PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
249// PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]
250// PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
251// PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
252// PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]
253// PATH: [[TAG_A_f16]] = !{[[TYPE_A]], [[TYPE_SHORT]], i64 0}
254// PATH: [[TAG_B_a_f32]] = !{[[TYPE_B:!.*]], [[TYPE_INT]], i64 8}
255// PATH: [[TYPE_B]] = !{!"_ZTS7StructB", [[TYPE_SHORT]], i64 0, [[TYPE_A]], i64 4, [[TYPE_INT]], i64 20}
256// PATH: [[TAG_B_a_f16]] = !{[[TYPE_B]], [[TYPE_SHORT]], i64 4}
257// PATH: [[TAG_B_f32]] = !{[[TYPE_B]], [[TYPE_INT]], i64 20}
258// PATH: [[TAG_B_a_f32_2]] = !{[[TYPE_B]], [[TYPE_INT]], i64 16}
259// PATH: [[TAG_S_f32]] = !{[[TYPE_S:!.*]], [[TYPE_INT]], i64 4}
260// PATH: [[TYPE_S]] = !{!"_ZTS7StructS", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
261// PATH: [[TAG_S_f16]] = !{[[TYPE_S]], [[TYPE_SHORT]], i64 0}
262// PATH: [[TAG_S2_f32]] = !{[[TYPE_S2:!.*]], [[TYPE_INT]], i64 4}
263// PATH: [[TYPE_S2]] = !{!"_ZTS8StructS2", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
264// PATH: [[TAG_S2_f16]] = !{[[TYPE_S2]], [[TYPE_SHORT]], i64 0}
265// PATH: [[TAG_C_b_a_f32]] = !{[[TYPE_C:!.*]], [[TYPE_INT]], i64 12}
266// PATH: [[TYPE_C]] = !{!"_ZTS7StructC", [[TYPE_SHORT]], i64 0, [[TYPE_B]], i64 4, [[TYPE_INT]], i64 28}
267// PATH: [[TAG_D_b_a_f32]] = !{[[TYPE_D:!.*]], [[TYPE_INT]], i64 12}
268// PATH: [[TYPE_D]] = !{!"_ZTS7StructD", [[TYPE_SHORT]], i64 0, [[TYPE_B]], i64 4, [[TYPE_INT]], i64 28, [[TYPE_CHAR]], i64 32}
269// PATH: [[TAG_five_b]] = !{[[TYPE_five:!.*]], [[TYPE_CHAR]], i64 1}
270// PATH: [[TYPE_five]] = !{!"_ZTS4five", [[TYPE_CHAR]], i64 0, [[TYPE_INT]], i64 1, [[TYPE_CHAR]], i64 1, [[TYPE_CHAR]], i64 2}
271// PATH: [[TAG_six_b]] = !{[[TYPE_six:!.*]], [[TYPE_CHAR]], i64 4}
272// PATH: [[TYPE_six]] = !{!"_ZTS3six", [[TYPE_CHAR]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_CHAR]], i64 4, [[TYPE_CHAR]], i64 5}