Author: Ryosuke Niwa Date: 2025-02-06T18:57:44-08:00 New Revision: 6f508492d13944edd0e7e70a3cc34eb29caeb8e9
URL: https://github.com/llvm/llvm-project/commit/6f508492d13944edd0e7e70a3cc34eb29caeb8e9 DIFF: https://github.com/llvm/llvm-project/commit/6f508492d13944edd0e7e70a3cc34eb29caeb8e9.diff LOG: [webkit.UncountedLambdaCapturesChecker] Fix a regression that [[noescape]] on a member function no longer works. (#126016) 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 53ef423bd82e7e2..a56f48c83c660a9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -109,9 +109,7 @@ class UncountedLambdaCapturesChecker bool VisitCallExpr(CallExpr *CE) override { checkCalleeLambda(CE); if (auto *Callee = CE->getDirectCallee()) { - unsigned ArgIndex = 0; - if (auto *CXXCallee = dyn_cast<CXXMethodDecl>(Callee)) - ArgIndex = CXXCallee->isInstance(); + unsigned ArgIndex = isa<CXXOperatorCallExpr>(CE); bool TreatAllArgsAsNoEscape = shouldTreatAllArgAsNoEscape(Callee); for (auto *Param : Callee->parameters()) { if (ArgIndex >= CE->getNumArgs()) diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp index 2a1a164557cdbe7..4f4a96028225303 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp @@ -63,6 +63,19 @@ template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::Callab return Function<Out(In...)>(impl, Function<Out(In...)>::Adopt); } +template <typename KeyType, typename ValueType> +class HashMap { +public: + HashMap(); + HashMap([[clang::noescape]] const Function<ValueType()>&); + void ensure(const KeyType&, [[clang::noescape]] const Function<ValueType()>&); + bool operator+([[clang::noescape]] const Function<ValueType()>&) const; + static void ifAny(HashMap, [[clang::noescape]] const Function<bool(ValueType)>&); + +private: + ValueType* m_table { nullptr }; +}; + } // namespace WTF struct A { @@ -268,6 +281,24 @@ struct RefCountableWithLambdaCapturingThis { nonTrivial(); }); } + + static void callLambda([[clang::noescape]] const WTF::Function<RefPtr<RefCountable>()>&); + void method_captures_this_in_template_method() { + RefCountable* obj = make_obj(); + WTF::HashMap<int, RefPtr<RefCountable>> nextMap; + nextMap.ensure(3, [&] { + return obj->next(); + }); + nextMap+[&] { + return obj->next(); + }; + WTF::HashMap<int, RefPtr<RefCountable>>::ifAny(nextMap, [&](auto& item) -> bool { + return item->next() && obj->next(); + }); + callLambda([&]() -> RefPtr<RefCountable> { + return obj->next(); + }); + } }; struct NonRefCountableWithLambdaCapturingThis { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits