Skip to content

Commit 378ac8e

Browse files
committed
[TBAA] Only emit pointer tbaa metedata for record types.
Be conservative if the type isn't a record type. Handling other types may require stripping const-qualifiers inside the type, e.g. MemberPointerType. Without this, we assign different tags to the accesses for p an q in the second test in cwg158.
1 parent ce91af3 commit 378ac8e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
230230
->getString();
231231
TyName = Name;
232232
} else {
233+
// Be conservative if the type isn't a record type. Handling other types
234+
// may require stripping const-qualifiers inside the type, e.g.
235+
// MemberPointerType.
236+
if (!Ty->isRecordType())
237+
return AnyPtr;
238+
233239
// For non-builtin types use the mangled name of the canonical type.
234240
llvm::raw_svector_ostream TyOut(TyName);
235241
MangleCtx->mangleCanonicalTypeName(QualType(Ty, 0), TyOut);

clang/test/CXX/drs/cwg158.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_cc1 -triple x86_64-linux -std=c++98 %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK,DEFAULT %s
2-
// RUN: %clang_cc1 -triple x86_64-linux -std=c++11 %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK,DEFAULT %s
3-
// RUN: %clang_cc1 -triple x86_64-linux -std=c++14 %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK,DEFAULT %s
4-
// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK,DEFAULT %s
5-
// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -O3 -pointer-tbaa -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK,POINTER-TBAA %s
1+
// RUN: %clang_cc1 -triple x86_64-linux -std=c++98 %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK %s
2+
// RUN: %clang_cc1 -triple x86_64-linux -std=c++11 %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK %s
3+
// RUN: %clang_cc1 -triple x86_64-linux -std=c++14 %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK %s
4+
// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -O3 -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK %s
5+
// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -O3 -pointer-tbaa -disable-llvm-passes -pedantic-errors -emit-llvm -o - | FileCheck --check-prefixes=CHECK %s
66

77
// cwg158: yes
88

@@ -23,8 +23,7 @@ const int *(A::*const *g(const int *(A::* const **p)[3], int *(A::***q)[3]))[3]
2323
// CHECK: load ptr, ptr %p.addr
2424
// CHECK: load ptr, {{.*}}, !tbaa ![[MEMPTR_TBAA:[^,]*]]
2525
const int *(A::*const *x)[3] = *p;
26-
// DEFAULT: store ptr null, {{.*}}, !tbaa ![[MEMPTR_TBAA]]
27-
// POINTER-TBAA-NOT: store ptr null, {{.*}}, !tbaa ![[MEMPTR_TBAA]]
26+
// CHECK: store ptr null, {{.*}}, !tbaa ![[MEMPTR_TBAA]]
2827
*q = 0;
2928
return x;
3029
}

0 commit comments

Comments
 (0)