88 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux -O1 %s \2// RUN: -emit-llvm -o - | FileCheck %s3// 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 %s6//7// Check that we generate correct TBAA information for accesses to array8// elements.9 10struct A { int i; };11struct B { A a[1]; };12struct C { int i; int x[3]; };13struct D { int n; int arr[]; }; // flexible array member14extern int AA[]; // incomplete array type15 16typedef int __attribute__((may_alias)) aliasing_int;17typedef int __attribute__((may_alias)) aliasing_array[10];18struct E { aliasing_int x[4]; aliasing_array y; };19 20int foo(B *b) {21// CHECK-LABEL: _Z3fooP1B22// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]23// CHECK-NEW-LABEL: _Z3fooP1B24// 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.29int bar(C *c) {30// CHECK-NEW-LABEL: _Z3barP1C31// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]32 return c->i;33}34 35int bar2(C *c) {36// CHECK-NEW-LABEL: _Z4bar2P1C37// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_x:!.*]]38 return c->x[2];39}40 41int bar3(C *c, int j) {42// CHECK-NEW-LABEL: _Z4bar3P1Ci43// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_x]]44 return c->x[j];45}46 47int bar4(D *d) {48// CHECK-NEW-LABEL: _Z4bar4P1D49// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]50// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]51 return d->arr[d->n];52}53 54int bar5(int j) {55// CHECK-NEW-LABEL: _Z4bar5i56// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]57// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]58 return AA[2] + AA[j];59}60 61int bar6(E *e, int j) {62// CHECK-NEW-LABEL: _Z4bar6P1Ei63// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_E_x:!.*]]64 return e->x[j];65}66 67int bar7(E *e, int j) {68// CHECK-NEW-LABEL: _Z4bar7P1Ei69// 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}88