-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[webkit.RefCntblBaseVirtualDtor] Add support for NoVirtualDestructorBase. #132497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ase. This PR adds the support for WTF::NoVirtualDestructorBase, which signifies to the checker that the class is exempt from having a virtual destructor.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesThis PR adds the support for WTF::NoVirtualDestructorBase, which signifies to the checker that the class is exempt from having a virtual destructor. Full diff: https://github.com/llvm/llvm-project/pull/132497.diff 2 Files Affected:
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you for the review! |
…ase. (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.
…ase. (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.
This PR adds the support for WTF::NoVirtualDestructorBase, which signifies to the checker that the class is exempt from having a virtual destructor.