[clang] dd8d85d - [webkit.UncountedLambdaCapturesChecker] Ignore lambda invocation with arguments (#117394)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 22 16:42:43 PST 2024
Author: Ryosuke Niwa
Date: 2024-11-22T16:42:39-08:00
New Revision: dd8d85dba6e8f74a55fb5053107797e21894a0c6
URL: https://github.com/llvm/llvm-project/commit/dd8d85dba6e8f74a55fb5053107797e21894a0c6
DIFF: https://github.com/llvm/llvm-project/commit/dd8d85dba6e8f74a55fb5053107797e21894a0c6.diff
LOG: [webkit.UncountedLambdaCapturesChecker] Ignore lambda invocation with arguments (#117394)
Fixed a bug that UncountedLambdaCapturesChecker would emit a warning on
a lambda capture when the lambda is invoked with arguments.
LocalVisitor::VisitCallExpr was not tolerating a lambda invocation with
more than 1 arguments.
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index 9312bf0af16dbf..599c2179db0f0e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -114,7 +114,7 @@ class UncountedLambdaCapturesChecker
if (!DRE)
return;
auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl());
- if (!MD || CE->getNumArgs() != 1)
+ if (!MD || CE->getNumArgs() < 1)
return;
auto *Arg = CE->getArg(0)->IgnoreParenCasts();
auto *ArgRef = dyn_cast<DeclRefExpr>(Arg);
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
index b63ffed8809fef..65eee9d49106df 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
@@ -125,7 +125,7 @@ void noescape_lambda() {
}
void lambda_capture_param(RefCountable* obj) {
- auto someLambda = [&] {
+ auto someLambda = [&]() {
obj->method();
};
someLambda();
@@ -178,3 +178,10 @@ void trivial_lambda() {
};
trivial_lambda();
}
+
+void lambda_with_args(RefCountable* obj) {
+ auto trivial_lambda = [&](int v) {
+ obj->method();
+ };
+ trivial_lambda(1);
+}
More information about the cfe-commits
mailing list