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

Florian Hahn via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 14:11:29 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());
----------------
fhahn wrote:

Adjusted, thanks!

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


More information about the cfe-commits mailing list