[clang] [llvm] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a WebKit checker for lambda capturing NS or CF types. (PR #128651)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 24 23:54:34 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff b335d5a8303250cb49901ecae7570adf61abbd3c dc53e0602fcec63bdd1bc84325ecc16a3f3e293b --extensions cpp,h -- clang/test/Analysis/Checkers/WebKit/objc-mock-types.h clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
index 314b3dc72c..4a297a6c0a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
@@ -75,8 +75,8 @@ public:
       }
 
       bool shouldCheckThis() {
-        auto result = !ClsType.isNull() ?
-            Checker->isUnsafePtr(ClsType) : std::nullopt;
+        auto result =
+            !ClsType.isNull() ? Checker->isUnsafePtr(ClsType) : std::nullopt;
         return result && *result;
       }
 
@@ -138,9 +138,8 @@ public:
             if (auto *L = findLambdaInArg(Arg)) {
               LambdasToIgnore.insert(L);
               if (!Param->hasAttr<NoEscapeAttr>())
-                Checker->visitLambdaExpr(L, shouldCheckThis() &&
-                                                !hasProtectedThis(L),
-                                         ClsType);
+                Checker->visitLambdaExpr(
+                    L, shouldCheckThis() && !hasProtectedThis(L), ClsType);
             }
             ++ArgIndex;
           }
@@ -160,9 +159,8 @@ public:
             if (auto *L = findLambdaInArg(Arg)) {
               LambdasToIgnore.insert(L);
               if (!Param->hasAttr<NoEscapeAttr>() && !TreatAllArgsAsNoEscape)
-                Checker->visitLambdaExpr(L, shouldCheckThis() &&
-                                                !hasProtectedThis(L),
-                                         ClsType);
+                Checker->visitLambdaExpr(
+                    L, shouldCheckThis() && !hasProtectedThis(L), ClsType);
             }
             ++ArgIndex;
           }
@@ -328,8 +326,7 @@ public:
     visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
   }
 
-  void visitLambdaExpr(LambdaExpr *L, bool shouldCheckThis,
-                       const QualType T,
+  void visitLambdaExpr(LambdaExpr *L, bool shouldCheckThis, const QualType T,
                        bool ignoreParamVarDecl = false) const {
     if (TFA.isTrivial(L->getBody()))
       return;
@@ -353,7 +350,7 @@ public:
   void reportBug(const LambdaCapture &Capture, ValueDecl *CapturedVar,
                  const QualType T) const {
     assert(CapturedVar);
-    
+
     if (isa<ImplicitParamDecl>(CapturedVar) && !Capture.getLocation().isValid())
       return; // Ignore implicit captruing of self.
 
@@ -421,7 +418,6 @@ public:
       return "uncounted";
     return "unchecked";
   }
-
 };
 
 class UnretainedLambdaCapturesChecker : public RawPtrRefLambdaCapturesChecker {
@@ -436,9 +432,7 @@ public:
     return RTC->isUnretained(QT);
   }
 
-  const char *ptrKind(QualType QT) const final {
-    return "unretained";
-  }
+  const char *ptrKind(QualType QT) const final { return "unretained"; }
 };
 
 } // namespace

``````````

</details>


https://github.com/llvm/llvm-project/pull/128651


More information about the cfe-commits mailing list