Skip to content

Commit 50ad6fb

Browse files
rniwaRyosuke Niwa
authored and
Ryosuke Niwa
committed
[webkit.RefCntblBaseVirtualDtor] Add support for NoVirtualDestructorBase. (llvm#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 2a385be commit 50ad6fb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ class RefCntblBaseVirtualDtorChecker
203203
if (!C)
204204
continue;
205205

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

225232
llvm::SetVector<const CXXRecordDecl *> Decls;
226233
llvm::DenseSet<const CXXRecordDecl *> CRTPs;
234+
llvm::DenseSet<const CXXRecordDecl *> ExemptDecls;
227235
};
228236

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

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

+17
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)