r314209 - Fix TBAA information for reference accesses
Ivan A. Kosarev via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 26 07:22:48 PDT 2017
Author: kosarev
Date: Tue Sep 26 07:22:48 2017
New Revision: 314209
URL: http://llvm.org/viewvc/llvm-project?rev=314209&view=rev
Log:
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
Added:
cfe/trunk/test/CodeGen/tbaa-reference.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=314209&r1=314208&r2=314209&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Sep 26 07:22:48 2017
@@ -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());
Added: cfe/trunk/test/CodeGen/tbaa-reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-reference.cpp?rev=314209&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/tbaa-reference.cpp (added)
+++ cfe/trunk/test/CodeGen/tbaa-reference.cpp Tue Sep 26 07:22:48 2017
@@ -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}
More information about the cfe-commits
mailing list