Skip to content

Commit 2b43ecd

Browse files
authored
[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.
1 parent 3386156 commit 2b43ecd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ class RefCntblBaseVirtualDtorChecker
202202
if (!C)
203203
continue;
204204

205+
bool isExempt = T.getAsString() == "NoVirtualDestructorBase" &&
206+
safeGetName(C->getParent()) == "WTF";
207+
if (isExempt || ExemptDecls.contains(C)) {
208+
ExemptDecls.insert(RD);
209+
continue;
210+
}
211+
205212
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(C)) {
206213
for (auto &Arg : CTSD->getTemplateArgs().asArray()) {
207214
if (Arg.getKind() != TemplateArgument::Type)
@@ -223,12 +230,13 @@ class RefCntblBaseVirtualDtorChecker
223230

224231
llvm::SetVector<const CXXRecordDecl *> Decls;
225232
llvm::DenseSet<const CXXRecordDecl *> CRTPs;
233+
llvm::DenseSet<const CXXRecordDecl *> ExemptDecls;
226234
};
227235

228236
LocalVisitor visitor(this);
229237
visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
230238
for (auto *RD : visitor.Decls) {
231-
if (visitor.CRTPs.contains(RD))
239+
if (visitor.CRTPs.contains(RD) || visitor.ExemptDecls.contains(RD))
232240
continue;
233241
visitCXXRecordDecl(RD);
234242
}

clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor -verify %s
22

3+
namespace WTF {
4+
5+
class NoVirtualDestructorBase { };
6+
7+
};
8+
9+
using WTF::NoVirtualDestructorBase;
10+
311
struct RefCntblBase {
412
void ref() {}
513
void deref() {}
@@ -19,6 +27,15 @@ struct [[clang::suppress]] SuppressedDerivedWithVirtualDtor : RefCntblBase {
1927
virtual ~SuppressedDerivedWithVirtualDtor() {}
2028
};
2129

30+
class ClassWithoutVirtualDestructor : public NoVirtualDestructorBase {
31+
public:
32+
void ref() const;
33+
void deref() const;
34+
};
35+
36+
class DerivedClassWithoutVirtualDestructor : public ClassWithoutVirtualDestructor {
37+
};
38+
2239
// FIXME: Support attributes on base specifiers? Currently clang
2340
// doesn't support such attributes at all, even though it knows
2441
// how to parse them.

0 commit comments

Comments
 (0)