[clang] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. (PR #76612)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 11:13:34 PDT 2024


================
@@ -185,10 +185,33 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
     return getChar();
 
   // Handle pointers and references.
-  // TODO: Implement C++'s type "similarity" and consider dis-"similar"
-  // pointers distinct.
-  if (Ty->isPointerType() || Ty->isReferenceType())
-    return createScalarTypeNode("any pointer", getChar(), Size);
+  if (Ty->isPointerType() || Ty->isReferenceType()) {
+    llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size);
+    if (CodeGenOpts.RelaxedPointerAliasing)
+      return AnyPtr;
+    // Compute the depth of the pointer and generate a tag of the form "p<depth>
+    // <base type tag>".
+    unsigned PtrDepth = 0;
+    do {
+      PtrDepth++;
+      Ty = Ty->getPointeeType().getTypePtr();
+    } while (Ty->isPointerType() || Ty->isReferenceType());
----------------
rjmccall wrote:

A reference type is impossible in these nested positions; you can never have references/pointers to references.  I believe it is possible in the original position because we can use this when building aggregate TBAA.

https://github.com/llvm/llvm-project/pull/76612


More information about the cfe-commits mailing list