[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 20 14:16:00 PST 2023


================
@@ -184,13 +199,24 @@ 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);
+  // Pointer types never alias if their pointee type is distinct.
+  if ((Ty->isPointerType() || Ty->isReferenceType())) {
+    llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size);
+    if (!CodeGenOpts.PointerTBAA)
+      return AnyPtr;
+    unsigned PtrDepth = 0;
+    do {
+      PtrDepth++;
+      Ty = Ty->getPointeeType().getTypePtr();
+    } while (!Ty->getPointeeType().isNull());
----------------
rjmccall wrote:

`getPointeeType()` will look through a lot of types that you probably don't want to look through, including member pointers.  You should write this to specifically look for pointers.  (References can't occur in nested positions.)

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


More information about the cfe-commits mailing list