Author: Ryosuke Niwa
Date: 2025-03-26T16:57:49-07:00
New Revision: 2b43ecd27b9651ac2bfb1328ad14b43a0f47a385

URL: 
https://github.com/llvm/llvm-project/commit/2b43ecd27b9651ac2bfb1328ad14b43a0f47a385
DIFF: 
https://github.com/llvm/llvm-project/commit/2b43ecd27b9651ac2bfb1328ad14b43a0f47a385.diff

LOG: [webkit.RefCntblBaseVirtualDtor] Add support for NoVirtualDestructorBase. 
(#132497)

This PR adds the support for WTF::NoVirtualDestructorBase, which
signifies to the checker that the class is exempt from having a virtual
destructor.

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
    clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 77520f1f731c1..98c587d62978b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -202,6 +202,13 @@ class RefCntblBaseVirtualDtorChecker
           if (!C)
             continue;
 
+          bool isExempt = T.getAsString() == "NoVirtualDestructorBase" &&
+                          safeGetName(C->getParent()) == "WTF";
+          if (isExempt || ExemptDecls.contains(C)) {
+            ExemptDecls.insert(RD);
+            continue;
+          }
+
           if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(C)) {
             for (auto &Arg : CTSD->getTemplateArgs().asArray()) {
               if (Arg.getKind() != TemplateArgument::Type)
@@ -223,12 +230,13 @@ class RefCntblBaseVirtualDtorChecker
 
       llvm::SetVector<const CXXRecordDecl *> Decls;
       llvm::DenseSet<const CXXRecordDecl *> CRTPs;
+      llvm::DenseSet<const CXXRecordDecl *> ExemptDecls;
     };
 
     LocalVisitor visitor(this);
     visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
     for (auto *RD : visitor.Decls) {
-      if (visitor.CRTPs.contains(RD))
+      if (visitor.CRTPs.contains(RD) || visitor.ExemptDecls.contains(RD))
         continue;
       visitCXXRecordDecl(RD);
     }

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp
index 5cf7e7614d06e..fd4144d572e01 100644
--- a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp
@@ -1,5 +1,13 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor 
-verify %s
 
+namespace WTF {
+
+class NoVirtualDestructorBase { };
+
+};
+
+using WTF::NoVirtualDestructorBase;
+
 struct RefCntblBase {
   void ref() {}
   void deref() {}
@@ -19,6 +27,15 @@ struct [[clang::suppress]] SuppressedDerivedWithVirtualDtor 
: RefCntblBase {
   virtual ~SuppressedDerivedWithVirtualDtor() {}
 };
 
+class ClassWithoutVirtualDestructor : public NoVirtualDestructorBase {
+public:
+  void ref() const;
+  void deref() const;
+};
+
+class DerivedClassWithoutVirtualDestructor : public 
ClassWithoutVirtualDestructor {
+};
+
 // FIXME: Support attributes on base specifiers? Currently clang
 // doesn't support such attributes at all, even though it knows
 // how to parse them.


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to