Skip to content

Commit f2dcfda

Browse files
committed
[webkit.UncountedLambdaCapturesChecker] Ignore a lambda which gets called immediately (llvm#162977)
Recognize more ways in which a lambda can be declared and called immediately. (cherry picked from commit e23e570)
1 parent d2ae766 commit f2dcfda

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,17 @@ class RawPtrRefLambdaCapturesChecker
343343
auto *Callee = CE->getCallee();
344344
if (!Callee)
345345
return;
346+
Callee = Callee->IgnoreParenCasts();
347+
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Callee)) {
348+
Callee = MTE->getSubExpr();
349+
if (!Callee)
350+
return;
351+
Callee = Callee->IgnoreParenCasts();
352+
}
353+
if (auto *L = dyn_cast<LambdaExpr>(Callee)) {
354+
LambdasToIgnore.insert(L); // Calling a lambda upon creation is safe.
355+
return;
356+
}
346357
auto *DRE = dyn_cast<DeclRefExpr>(Callee->IgnoreParenCasts());
347358
if (!DRE)
348359
return;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,23 @@ void capture_copy_in_lambda(CheckedObj& checked) {
520520
});
521521
}
522522

523+
struct TemplateFunctionCallsLambda {
524+
void ref() const;
525+
void deref() const;
526+
527+
RefCountable* obj();
528+
529+
template <typename T>
530+
RefPtr<T> method(T* t) {
531+
auto ret = ([&]() -> RefPtr<T> {
532+
if constexpr (T::isEncodable)
533+
return t;
534+
return obj() ? t : nullptr;
535+
})();
536+
return ret;
537+
}
538+
};
539+
523540
class Iterator {
524541
public:
525542
Iterator(void* array, unsigned long sizeOfElement, unsigned int index);

0 commit comments

Comments
 (0)