Author: Ryosuke Niwa Date: 2025-12-12T14:58:38-08:00 New Revision: e23e5705e69aa7c6e4f35394b673977cca97308a
URL: https://github.com/llvm/llvm-project/commit/e23e5705e69aa7c6e4f35394b673977cca97308a DIFF: https://github.com/llvm/llvm-project/commit/e23e5705e69aa7c6e4f35394b673977cca97308a.diff LOG: [webkit.UncountedLambdaCapturesChecker] Ignore a lambda which gets called immediately (#162977) Recognize more ways in which a lambda can be declared and called immediately. 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 ebfc654cccd5d..b5b03624a5601 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp @@ -343,6 +343,17 @@ class RawPtrRefLambdaCapturesChecker auto *Callee = CE->getCallee(); if (!Callee) return; + Callee = Callee->IgnoreParenCasts(); + if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Callee)) { + Callee = MTE->getSubExpr(); + if (!Callee) + return; + Callee = Callee->IgnoreParenCasts(); + } + if (auto *L = dyn_cast<LambdaExpr>(Callee)) { + LambdasToIgnore.insert(L); // Calling a lambda upon creation is safe. + return; + } auto *DRE = dyn_cast<DeclRefExpr>(Callee->IgnoreParenCasts()); if (!DRE) return; diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp index 8eb15f4f77973..c06466d258c7d 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp @@ -520,6 +520,23 @@ void capture_copy_in_lambda(CheckedObj& checked) { }); } +struct TemplateFunctionCallsLambda { + void ref() const; + void deref() const; + + RefCountable* obj(); + + template <typename T> + RefPtr<T> method(T* t) { + auto ret = ([&]() -> RefPtr<T> { + if constexpr (T::isEncodable) + return t; + return obj() ? t : nullptr; + })(); + return ret; + } +}; + class Iterator { public: Iterator(void* array, unsigned long sizeOfElement, unsigned int index); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
