https://github.com/geoffreygaren created 
https://github.com/llvm/llvm-project/pull/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

>From 634143497808e4df1ab1d7ae3936dc7f90957f7d Mon Sep 17 00:00:00 2001
From: Geoff Garen <[email protected]>
Date: Sun, 23 Aug 2026 16:31:40 -0700
Subject: [PATCH] [WebKit Checkers] Do not report lambda captures in system
 headers

This matches the policy in other WebKit checkers.

Assisted-by: Claude
---
 .../Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp    | 2 ++
 clang/test/Analysis/Checkers/WebKit/mock-system-header.h  | 8 ++++++++
 .../Checkers/WebKit/uncounted-lambda-captures.cpp         | 5 +++++
 3 files changed, 15 insertions(+)

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);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to