Debian Codegraph @

clang/test/CodeGen/tbaa-array.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-linux -O1 %s \
2 // RUN: -emit-llvm -o - | FileCheck %s
3 // RUN: %clang_cc1 -triple x86_64-linux -O1 %s \
4 // RUN: -new-struct-path-tbaa -emit-llvm -o - | \
5 // RUN: FileCheck -check-prefix=CHECK-NEW %s
6 //
7 // Check that we generate correct TBAA information for accesses to array
8 // elements.
9
10 struct A { int i; };
11 struct B { A a[1]; };
12 struct C { int i; int x[3]; };
13 struct D { int n; int arr[]; }; // flexible array member
14 extern int AA[]; // incomplete array type
15
16 typedef int __attribute__((may_alias)) aliasing_int;
17 typedef int __attribute__((may_alias)) aliasing_array[10];
18 struct E { aliasing_int x[4]; aliasing_array y; };
19
20 int foo(B *b) {
21 // CHECK-LABEL: _Z3fooP1B
22 // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
23 // CHECK-NEW-LABEL: _Z3fooP1B
24 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
25 return b->a->i;
26 }
27
28 // Check that members of array types are represented correctly.
29 int bar(C *c) {
30 // CHECK-NEW-LABEL: _Z3barP1C
31 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]
32 return c->i;
33 }
34
35 int bar2(C *c) {
36 // CHECK-NEW-LABEL: _Z4bar2P1C
37 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_x:!.*]]
38 return c->x[2];
39 }
40
41 int bar3(C *c, int j) {
42 // CHECK-NEW-LABEL: _Z4bar3P1Ci
43 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_x]]
44 return c->x[j];
45 }
46
47 int bar4(D *d) {
48 // CHECK-NEW-LABEL: _Z4bar4P1D
49 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
50 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
51 return d->arr[d->n];
52 }
53
54 int bar5(int j) {
55 // CHECK-NEW-LABEL: _Z4bar5i
56 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
57 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
58 return AA[2] + AA[j];
59 }
60
61 int bar6(E *e, int j) {
62 // CHECK-NEW-LABEL: _Z4bar6P1Ei
63 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_E_x:!.*]]
64 return e->x[j];
65 }
66
67 int bar7(E *e, int j) {
68 // CHECK-NEW-LABEL: _Z4bar7P1Ei
69 // CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_E_y:!.*]]
70 return e->y[j];
71 }
72
73 // CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0}
74 // CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0}
75 // CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
76
77 // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
78 // CHECK-NEW-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"}
79 // CHECK-NEW-DAG: [[TAG_int]] = !{[[TYPE_int]], [[TYPE_int]], i64 0, i64 4}
80 // CHECK-NEW-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 4, !"_ZTS1A", [[TYPE_int]], i64 0, i64 4}
81 // CHECK-NEW-DAG: [[TAG_A_i]] = !{[[TYPE_A]], [[TYPE_int]], i64 0, i64 4}
82 // CHECK-NEW-DAG: [[TYPE_C:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1C", [[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 4, i64 12}
83 // CHECK-NEW-DAG: [[TAG_C_i]] = !{[[TYPE_C]], [[TYPE_int]], i64 0, i64 4}
84 // CHECK-NEW-DAG: [[TAG_C_x]] = !{[[TYPE_C]], [[TYPE_int]], i64 4, i64 4}
85 // CHECK-NEW-DAG: [[TYPE_E:!.*]] = !{[[TYPE_char]], i64 56, !"_ZTS1E", [[TYPE_char]], i64 0, i64 16, [[TYPE_char]], i64 16, i64 40}
86 // CHECK-NEW-DAG: [[TAG_E_x]] = !{[[TYPE_E]], [[TYPE_char]], i64 0, i64 4}
87 // CHECK-NEW-DAG: [[TAG_E_y]] = !{[[TYPE_E]], [[TYPE_char]], i64 16, i64 4}