https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/108656
Improve the fix in 203a2ca8cd6af505e11a38aebceeaf864271042c by allowing variable references and more ignoring of parentheses. >From e86f101c5cd87db597c5fc8ab017b20adba98284 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa <rn...@webkit.org> Date: Fri, 13 Sep 2024 15:19:45 -0700 Subject: [PATCH] [webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings Improve the fix in 203a2ca8cd6af505e11a38aebceeaf864271042c by allowing variable references and more ignoring of parentheses. --- .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 19 ++++++++++++++----- .../ref-cntbl-crtp-base-no-virtual-dtor.cpp | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) 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(); +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits