Skip to content

Commit 69bbcce

Browse files
committed
[webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings (llvm#108656)
Improve the fix in 203a2ca by allowing variable references and more ignoring of parentheses.
1 parent bd4a088 commit 69bbcce

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,32 @@ class DerefFuncDeleteExprVisitor
7272
if (name == "ensureOnMainThread" || name == "ensureOnMainRunLoop") {
7373
for (unsigned i = 0; i < CE->getNumArgs(); ++i) {
7474
auto *Arg = CE->getArg(i);
75-
if (VisitLabmdaArgument(Arg))
75+
if (VisitLambdaArgument(Arg))
7676
return true;
7777
}
7878
}
7979
}
8080
return false;
8181
}
8282

83-
bool VisitLabmdaArgument(const Expr *E) {
83+
bool VisitLambdaArgument(const Expr *E) {
8484
E = E->IgnoreParenCasts();
8585
if (auto *TempE = dyn_cast<CXXBindTemporaryExpr>(E))
8686
E = TempE->getSubExpr();
87+
E = E->IgnoreParenCasts();
88+
if (auto *Ref = dyn_cast<DeclRefExpr>(E)) {
89+
if (auto *VD = dyn_cast_or_null<VarDecl>(Ref->getDecl()))
90+
return VisitLambdaArgument(VD->getInit());
91+
return false;
92+
}
93+
if (auto *Lambda = dyn_cast<LambdaExpr>(E)) {
94+
if (VisitBody(Lambda->getBody()))
95+
return true;
96+
}
8797
if (auto *ConstructE = dyn_cast<CXXConstructExpr>(E)) {
8898
for (unsigned i = 0; i < ConstructE->getNumArgs(); ++i) {
89-
auto *Arg = ConstructE->getArg(i);
90-
if (auto *Lambda = dyn_cast<LambdaExpr>(Arg)) {
91-
if (VisitBody(Lambda->getBody()))
92-
return true;
93-
}
99+
if (VisitLambdaArgument(ConstructE->getArg(i)))
100+
return true;
94101
}
95102
}
96103
return false;

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

+18
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ template<class T, DestructionThread destructionThread = DestructionThread::Any>
119119
ensureOnMainThread([this] {
120120
delete static_cast<const T*>(this);
121121
});
122+
} else if constexpr (destructionThread == DestructionThread::MainRunLoop) {
123+
auto deleteThis = [this] {
124+
delete static_cast<const T*>(this);
125+
};
126+
ensureOnMainThread(deleteThis);
122127
}
123128
}
124129

@@ -230,3 +235,16 @@ class FancyRefCountedClass4 final : public BadNestedThreadSafeRefCounted<FancyRe
230235
private:
231236
FancyRefCountedClass4();
232237
};
238+
239+
class FancyRefCountedClass5 final : public ThreadSafeRefCounted<FancyRefCountedClass5, DestructionThread::MainRunLoop> {
240+
public:
241+
static Ref<FancyRefCountedClass5> create()
242+
{
243+
return adoptRef(*new FancyRefCountedClass5());
244+
}
245+
246+
virtual ~FancyRefCountedClass5();
247+
248+
private:
249+
FancyRefCountedClass5();
250+
};

0 commit comments

Comments
 (0)