From: Ivan A. Kosarev Date: Tue, 26 Sep 2017 14:22:48 +0000 (+0000) Subject: Fix TBAA information for reference accesses X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=597065b960a9ea92e9ccdc805013b8210574a777;p=clang Fix TBAA information for reference accesses This patch fixes clang to decorate reference accesses as pointers and not as "omnipotent chars". Differential Revision: https://reviews.llvm.org/D38074 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314209 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp index 8a75a552d9..3ae2956e6e 100644 --- a/lib/CodeGen/CodeGenTBAA.cpp +++ b/lib/CodeGen/CodeGenTBAA.cpp @@ -145,10 +145,10 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { if (Ty->isStdByteType()) return MetadataCache[Ty] = getChar(); - // Handle pointers. + // Handle pointers and references. // TODO: Implement C++'s type "similarity" and consider dis-"similar" // pointers distinct. - if (Ty->isPointerType()) + if (Ty->isPointerType() || Ty->isReferenceType()) return MetadataCache[Ty] = createTBAAScalarType("any pointer", getChar()); diff --git a/test/CodeGen/tbaa-reference.cpp b/test/CodeGen/tbaa-reference.cpp new file mode 100644 index 0000000000..aae6a82a8f --- /dev/null +++ b/test/CodeGen/tbaa-reference.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s +// +// Check that we generate correct TBAA information for reference accesses. + +struct S; + +struct B { + S &s; + B(S &s) : s(s) {} + void bar(); +}; + +void foo(S &s) { + B b(s); + b.bar(); +} + +// CHECK-LABEL: _Z3fooR1S +// Check initialization of the reference parameter in foo(). +// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]] +// +// CHECK-LABEL: _ZN1BC2ER1S +// TODO: Check loading of the reference parameter in B::B(S&). +// Check initialization of B::s in B::B(S&). +// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]] +// +// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0} +// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0} +// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}