[clang] [Webkit Checkers] Treat const member variables as a safe origin (PR #115594)

Rashmi Mudduluru via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 14 16:29:35 PST 2024


================
@@ -145,25 +145,36 @@ bool isCtorOfSafePtr(const clang::FunctionDecl *F) {
   return isCtorOfRefCounted(F) || isCtorOfCheckedPtr(F);
 }
 
-bool isSafePtrType(const clang::QualType T) {
+template <typename Predicate>
+static bool isPtrOfType(const clang::QualType T, Predicate Pred) {
   QualType type = T;
   while (!type.isNull()) {
     if (auto *elaboratedT = type->getAs<ElaboratedType>()) {
       type = elaboratedT->desugar();
       continue;
     }
     if (auto *specialT = type->getAs<TemplateSpecializationType>()) {
-      if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
-        auto name = decl->getNameAsString();
-        return isRefType(name) || isCheckedPtr(name);
-      }
+      if (auto *decl = specialT->getTemplateName().getAsTemplateDecl())
+        return Pred(decl->getNameAsString());
       return false;
     }
     return false;
   }
   return false;
 }
 
+bool isSafePtrType(const clang::QualType T) {
+  return isPtrOfType(
+      T, [](auto Name) { return isRefType(Name) || isCheckedPtr(Name); });
+}
+
+bool isOwnerPtrType(const clang::QualType T) {
+  return isPtrOfType(T, [](auto Name) {
+    return isRefType(Name) || isCheckedPtr(Name) || Name == "unique_ptr" ||
+           Name == "UniqueRef" || Name == "LazyUniqueRef";
----------------
t-rasmud wrote:

Out of curiosity: Is this (`UniqueRef` and `LazyUniqueRef`) the exhaustive list of additional Webkit defined pointer owner types(I'm assuming)? 

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


More information about the cfe-commits mailing list