[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
Thu Dec 28 22:23:15 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:
You're right, you do need to look through member pointers here, although this means you're also treating member-pointer structure as if it were just pointer structure. I guess that's okay for now.
https://github.com/llvm/llvm-project/pull/75177
More information about the cfe-commits
mailing list