[clang] [webkit.UncountedLambdaCapturesChecker] Ignore lambda invocation with arguments (PR #117394)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 22 14:46:46 PST 2024
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/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.
>From 7aeb699b83f3ef7f379a9c1f21df16d9e6973368 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Fri, 22 Nov 2024 14:17:29 -0800
Subject: [PATCH] [webkit.UncountedLambdaCapturesChecker] Ignore lambda
invocation with arguments
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.
---
.../Checkers/WebKit/UncountedLambdaCapturesChecker.cpp | 2 +-
.../Checkers/WebKit/uncounted-lambda-captures.cpp | 9 ++++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
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