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

Bushev Dmitry via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 22 10:49:13 PST 2023


================
@@ -105,13 +105,28 @@ 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;
 }
 
+std::string CodeGenTBAA::getPointeeName(const Type *Ty) {
+  if (isa<BuiltinType>(Ty)) {
+    llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty);
+    auto &Op = ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0);
+    assert(isa<llvm::MDString>(Op) && "Expected MDString operand");
+    return cast<llvm::MDString>(Op)->getString().str();
+  }
+
+  if (Ty->isIncompleteType())
+    return "<incomplete type>";
----------------
dybv-sc wrote:

Removed. I was uncertain in a moment what to do in that case, but after revisiting C/C++ standard I learned that there is no difference between complete and incomplete types when considering their similarity/compatibility.

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


More information about the cfe-commits mailing list