[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:01 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.
----------------
rjmccall wrote:

This comment both is incorrect and doesn't match the code.  What you seem to be implementing here is the C++ similar-type rule, in which what matters is whether the pointer type sub-structure matches while ignoring qualifiers.

Unfortunately, this rule seems to treat `void*` and `char*` as different types.  That is wrong in C because those types are compatible, and we probably ought to use the C rule even in C++.

Also, in general, I would suggest that you write `getPointeeName` much more conservatively rather than assuming that you can just render an arbitrary type and it's going to be okay to treat different renderings as distinct for TBAA purposes.  For example, this is going to treat pointers to different vector types as non-aliasing, which worries me a lot because vector programmers are often pretty fast-and-loose.  You're also going to be stricter about ObjC than I'm comfortable with.  I would strongly suggest just doing this rendering for specific kinds of types, like records, and otherwise having some kind of fallback to the any-pointer metadata.

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


More information about the cfe-commits mailing list