[clang] e1ca3d9 - [webkit.UncountedLambdaCapturesChecker] Ignore DeclRefExpr to a lambda in an no-escape argument (#155025)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 9 13:46:42 PDT 2025
Author: Ryosuke Niwa
Date: 2025-09-09T13:46:39-07:00
New Revision: e1ca3d9376541829a2ced11fbb4aa9015d656d44
URL: https://github.com/llvm/llvm-project/commit/e1ca3d9376541829a2ced11fbb4aa9015d656d44
DIFF: https://github.com/llvm/llvm-project/commit/e1ca3d9376541829a2ced11fbb4aa9015d656d44.diff
LOG: [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.
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
index 27a91132fa9be..03eeb9999c4dd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
@@ -232,14 +232,11 @@ class RawPtrRefLambdaCapturesChecker
if (!Init)
return nullptr;
if (auto *Lambda = dyn_cast<LambdaExpr>(Init)) {
+ DeclRefExprsToIgnore.insert(DRE);
updateIgnoreList();
return Lambda;
}
- TempExpr = dyn_cast<CXXBindTemporaryExpr>(Init->IgnoreParenCasts());
- if (!TempExpr)
- return nullptr;
- updateIgnoreList();
- return dyn_cast_or_null<LambdaExpr>(TempExpr->getSubExpr());
+ return nullptr;
}
void checkCalleeLambda(CallExpr *CE) {
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
index 3079f8e833fcd..0b8af0d1e8dc1 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
@@ -448,4 +448,27 @@ void ranges_for_each(RefCountable* obj) {
obj->method();
++(*static_cast<unsigned*>(item));
});
-}
\ No newline at end of file
+}
+
+class RefCountedObj {
+public:
+ void ref();
+ void deref();
+
+ void call() const;
+ void callLambda([[clang::noescape]] const WTF::Function<void ()>& callback) const;
+ void doSomeWork() const;
+};
+
+void RefCountedObj::callLambda([[clang::noescape]] const WTF::Function<void ()>& callback) const
+{
+ callback();
+}
+
+void RefCountedObj::call() const
+{
+ auto lambda = [&] {
+ doSomeWork();
+ };
+ callLambda(lambda);
+}
More information about the cfe-commits
mailing list