diff options
| author | Ivan A. Kosarev <ikosarev@accesssoftek.com> | 2017-12-22 09:57:24 +0000 |
|---|---|---|
| committer | Ivan A. Kosarev <ikosarev@accesssoftek.com> | 2017-12-22 09:57:24 +0000 |
| commit | 57493e29198836bfcdab58c0780c106a4f7f30c8 (patch) | |
| tree | 05ede5055a04e5485652aa76e494c186be80f8a0 /clang | |
| parent | d50b847ac8f034b0d954a731060459547789dd26 (diff) | |
| download | bcm5719-llvm-57493e29198836bfcdab58c0780c106a4f7f30c8.tar.gz bcm5719-llvm-57493e29198836bfcdab58c0780c106a4f7f30c8.zip | |
[CodeGen] Represent array members in new-format TBAA type descriptors
Now that in the new TBAA format we allow access types to be of
any object types, including aggregate ones, it becomes critical
to specify types of all sub-objects such aggregates comprise as
their members. In order to meet this requirement, this patch
enables generation of field descriptors for members of array
types.
Differential Revision: https://reviews.llvm.org/D41399
llvm-svn: 321352
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenTBAA.cpp | 4 | ||||
| -rw-r--r-- | clang/test/CodeGen/tbaa-array.cpp | 34 |
2 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index ab45d1f7f96..ad473032db1 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -161,6 +161,10 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { if (Ty->isPointerType() || Ty->isReferenceType()) return createScalarTypeNode("any pointer", getChar(), Size); + // Accesses to arrays are accesses to objects of their element types. + if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType()) + return getTypeInfo(cast<ArrayType>(Ty)->getElementType()); + // Enum types are distinct types. In C++ they have "underlying types", // however they aren't related for TBAA. if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) { diff --git a/clang/test/CodeGen/tbaa-array.cpp b/clang/test/CodeGen/tbaa-array.cpp index 86ca5ccb40d..4a6576e2eeb 100644 --- a/clang/test/CodeGen/tbaa-array.cpp +++ b/clang/test/CodeGen/tbaa-array.cpp @@ -1,18 +1,52 @@ // RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \ // RUN: -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \ +// RUN: -new-struct-path-tbaa -emit-llvm -o - | \ +// RUN: FileCheck -check-prefix=CHECK-NEW %s // // Check that we generate correct TBAA information for accesses to array // elements. struct A { int i; }; struct B { A a[1]; }; +struct C { int i; int x[3]; }; int foo(B *b) { // CHECK-LABEL: _Z3fooP1B // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]] +// CHECK-NEW-LABEL: _Z3fooP1B +// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]] return b->a->i; } +// Check that members of array types are represented correctly. +int bar(C *c) { +// CHECK-NEW-LABEL: _Z3barP1C +// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]] + return c->i; +} + +int bar2(C *c) { +// CHECK-NEW-LABEL: _Z4bar2P1C +// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]] + return c->x[2]; +} + +int bar3(C *c, int j) { +// CHECK-NEW-LABEL: _Z4bar3P1Ci +// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]] + return c->x[j]; +} + // CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0} // CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0} // CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0} + +// CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"} +// CHECK-NEW-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"} +// CHECK-NEW-DAG: [[TAG_int]] = !{[[TYPE_int]], [[TYPE_int]], i64 0, i64 4} +// CHECK-NEW-DAG: [[TYPE_pointer:!.*]] = !{[[TYPE_char]], i64 8, !"any pointer"} +// CHECK-NEW-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 4, !"_ZTS1A", [[TYPE_int]], i64 0, i64 4} +// CHECK-NEW-DAG: [[TAG_A_i]] = !{[[TYPE_A]], [[TYPE_int]], i64 0, i64 4} +// CHECK-NEW-DAG: [[TYPE_C:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1C", [[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 4, i64 12} +// CHECK-NEW-DAG: [[TAG_C_i]] = !{[[TYPE_C:!.*]], [[TYPE_int:!.*]], i64 0, i64 4} |

