Skip to content

Commit e1ca3d9

Browse files
authored
[webkit.UncountedLambdaCapturesChecker] Ignore DeclRefExpr to a lambda in an no-escape argument (#155025)
Fix a bug that webkit.UncountedLambdaCapturesChecker was erroneously emitting a warning for a DeclRefExpr which is passed in as an argument to a no-escape function argument. The bug was caused by findLambdaInArg not adding DeclRefExpr to the ignored set even when a lambda was identified as an argument.
1 parent 2bd0d77 commit e1ca3d9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,11 @@ class RawPtrRefLambdaCapturesChecker
232232
if (!Init)
233233
return nullptr;
234234
if (auto *Lambda = dyn_cast<LambdaExpr>(Init)) {
235+
DeclRefExprsToIgnore.insert(DRE);
235236
updateIgnoreList();
236237
return Lambda;
237238
}
238-
TempExpr = dyn_cast<CXXBindTemporaryExpr>(Init->IgnoreParenCasts());
239-
if (!TempExpr)
240-
return nullptr;
241-
updateIgnoreList();
242-
return dyn_cast_or_null<LambdaExpr>(TempExpr->getSubExpr());
239+
return nullptr;
243240
}
244241

245242
void checkCalleeLambda(CallExpr *CE) {

clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,27 @@ void ranges_for_each(RefCountable* obj) {
448448
obj->method();
449449
++(*static_cast<unsigned*>(item));
450450
});
451-
}
451+
}
452+
453+
class RefCountedObj {
454+
public:
455+
void ref();
456+
void deref();
457+
458+
void call() const;
459+
void callLambda([[clang::noescape]] const WTF::Function<void ()>& callback) const;
460+
void doSomeWork() const;
461+
};
462+
463+
void RefCountedObj::callLambda([[clang::noescape]] const WTF::Function<void ()>& callback) const
464+
{
465+
callback();
466+
}
467+
468+
void RefCountedObj::call() const
469+
{
470+
auto lambda = [&] {
471+
doSomeWork();
472+
};
473+
callLambda(lambda);
474+
}

0 commit comments

Comments
 (0)