[PATCH] D39138: [CodeGen] Generate TBAA info for 'this' pointers

Ivan Kosarev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 12:49:10 PDT 2017


kosarev created this revision.
kosarev added a project: clang.

Repository:
  rL LLVM

https://reviews.llvm.org/D39138

Files:
  lib/CodeGen/CGCXXABI.cpp
  test/CodeGen/tbaa-this.cpp


Index: test/CodeGen/tbaa-this.cpp
===================================================================
--- test/CodeGen/tbaa-this.cpp
+++ test/CodeGen/tbaa-this.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN:     -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for 'this' pointers.
+
+struct C {
+  C *self();
+};
+
+C *C::self() {
+// CHECK-LABEL: _ZN1C4selfEv
+// CHECK: load {{.*}}, !tbaa [[TAG_pointer:!.*]]
+  return this;
+}
+
+C* foo(C *p) {
+  return p->self();
+}
+
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", !{{.*}}, i64 0}
Index: lib/CodeGen/CGCXXABI.cpp
===================================================================
--- lib/CodeGen/CGCXXABI.cpp
+++ lib/CodeGen/CGCXXABI.cpp
@@ -152,9 +152,12 @@
 void CGCXXABI::EmitThisParam(CodeGenFunction &CGF) {
   /// Initialize the 'this' slot.
   assert(getThisDecl(CGF) && "no 'this' variable for function");
-  CGF.CXXABIThisValue
-    = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(getThisDecl(CGF)),
-                             "this");
+  ImplicitParamDecl *ThisPtrDecl = getThisDecl(CGF);
+  auto *Load = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(ThisPtrDecl),
+                                      "this");
+  QualType ThisPtrType = ThisPtrDecl->getType();
+  CGM.DecorateInstructionWithTBAA(Load, CGM.getTBAAAccessInfo(ThisPtrType));
+  CGF.CXXABIThisValue = Load;
 }
 
 void CGCXXABI::EmitReturnFromThunk(CodeGenFunction &CGF,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39138.119692.patch
Type: text/x-patch
Size: 1582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171020/a57c5d98/attachment.bin>


More information about the cfe-commits mailing list