[clang] [webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings (PR #108656)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 15:22:31 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-static-analyzer-1
Author: Ryosuke Niwa (rniwa)
<details>
<summary>Changes</summary>
Improve the fix in 203a2ca8cd6af505e11a38aebceeaf864271042c by allowing variable references and more ignoring of parentheses.
---
Full diff: https://github.com/llvm/llvm-project/pull/108656.diff
2 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp (+14-5)
- (modified) clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp (+18)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index ecba5f9aa23ee3..5ea19233bb65c2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -84,13 +84,22 @@ class DerefFuncDeleteExprVisitor
E = E->IgnoreParenCasts();
if (auto *TempE = dyn_cast<CXXBindTemporaryExpr>(E))
E = TempE->getSubExpr();
+ E = E->IgnoreParenCasts();
+ if (auto *Ref = dyn_cast<DeclRefExpr>(E)) {
+ if (auto *Decl = Ref->getDecl()) {
+ if (auto *VD = dyn_cast<VarDecl>(Decl))
+ return VisitLabmdaArgument(VD->getInit());
+ }
+ return false;
+ }
+ if (auto *Lambda = dyn_cast<LambdaExpr>(E)) {
+ if (VisitBody(Lambda->getBody()))
+ return true;
+ }
if (auto *ConstructE = dyn_cast<CXXConstructExpr>(E)) {
for (unsigned i = 0; i < ConstructE->getNumArgs(); ++i) {
- auto *Arg = ConstructE->getArg(i);
- if (auto *Lambda = dyn_cast<LambdaExpr>(Arg)) {
- if (VisitBody(Lambda->getBody()))
- return true;
- }
+ if (VisitLabmdaArgument(ConstructE->getArg(i)))
+ return true;
}
}
return false;
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
index 01527addb52992..33c60ea8ca64d1 100644
--- a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
@@ -119,6 +119,11 @@ template<class T, DestructionThread destructionThread = DestructionThread::Any>
ensureOnMainThread([this] {
delete static_cast<const T*>(this);
});
+ } else if constexpr (destructionThread == DestructionThread::MainRunLoop) {
+ auto deleteThis = [this] {
+ delete static_cast<const T*>(this);
+ };
+ ensureOnMainThread(deleteThis);
}
}
@@ -230,3 +235,16 @@ class FancyRefCountedClass4 final : public BadNestedThreadSafeRefCounted<FancyRe
private:
FancyRefCountedClass4();
};
+
+class FancyRefCountedClass5 final : public ThreadSafeRefCounted<FancyRefCountedClass5, DestructionThread::MainRunLoop> {
+public:
+ static Ref<FancyRefCountedClass5> create()
+ {
+ return adoptRef(*new FancyRefCountedClass5());
+ }
+
+ virtual ~FancyRefCountedClass5();
+
+private:
+ FancyRefCountedClass5();
+};
``````````
</details>
https://github.com/llvm/llvm-project/pull/108656
More information about the cfe-commits
mailing list