[clang] 4127345 - [WebKit Checkers] Do not report lambda captures in system headers (#226182)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 24 08:45:57 PDT 2026


Author: geoffreygaren
Date: 2026-09-24T08:45:51-07:00
New Revision: 4127345110ee862f01e81801fbfe8f84e4a75874

URL: https://github.com/llvm/llvm-project/commit/4127345110ee862f01e81801fbfe8f84e4a75874
DIFF: https://github.com/llvm/llvm-project/commit/4127345110ee862f01e81801fbfe8f84e4a75874.diff

LOG: [WebKit Checkers] Do not report lambda captures in system headers (#226182)

This matches the policy in other WebKit checkers.

Some `std` namespace lambdas like `find` lack the `noescape` annotation,
so the borrow checker flags them.

Assisted-by: Claude

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
    clang/test/Analysis/Checkers/WebKit/mock-system-header.h
    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 e0debb764af00..3fc4c38c8bed7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
@@ -549,6 +549,8 @@ class RawPtrRefLambdaCapturesChecker
   void visitLambdaExpr(const LambdaExpr *L, bool shouldCheckThis,
                        const QualType T,
                        bool ignoreParamVarDecl = false) const {
+    if (BR->getSourceManager().isInSystemHeader(L->getBeginLoc()))
+      return;
     if (TFA.isTrivial(L->getBody()))
       return;
     for (const LambdaCapture &C : L->captures()) {

diff  --git a/clang/test/Analysis/Checkers/WebKit/mock-system-header.h b/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
index d55b3abd34f4c..fc675418a1d79 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
@@ -1,5 +1,13 @@
 #pragma clang system_header
 
+template <typename F>
+void takeLambda(F);
+
+template <typename T>
+inline void lambdaInSystemHeader(T* obj) {
+  takeLambda([obj] { obj->method(); });
+}
+
 template <typename T, typename CreateFunction>
 void callMethod(CreateFunction createFunction) {
   createFunction()->method();

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
index 3394315effe6f..4bfd095165ca8 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s
 
 #include "mock-types.h"
+#include "mock-system-header.h"
 
 struct A {
   static void b();
@@ -720,3 +721,7 @@ void instantiate_dependent_callables(NoEscapeCallable& noEscape,
   call_through_noescape_callable(noEscape);
   call_through_escaping_callable(escape);
 }
+
+void lambda_in_system_header(RefCountable* ref_countable) {
+  lambdaInSystemHeader(ref_countable);
+}


        


More information about the cfe-commits mailing list