[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


================
@@ -105,13 +105,34 @@ static bool isValidBaseType(QualType QTy) {
     if (RD->hasFlexibleArrayMember())
       return false;
     // RD can be struct, union, class, interface or enum.
-    // For now, we only handle struct and class.
-    if (RD->isStruct() || RD->isClass())
+    if (RD->isStruct() || RD->isClass() ||
+        (RD->isUnion() && CodeGenOpts.UnionTBAA))
       return true;
   }
   return false;
 }
 
+// Give unique tag for compatible types.
+std::string CodeGenTBAA::getPointeeName(const Type *Ty) {
----------------
rjmccall wrote:

Since this is always being used to build a larger string, could you make this append to a `raw_ostream`?

I guess `Ty` *is* guaranteed to be a canonical type here, because that's apparently a precondition of `getTypeInfoHelper`.  Could you assert that?

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


More information about the cfe-commits mailing list