[clang] [webkit.UncountedLambdaCapturesChecker] Support [[clang::noescape]] on a constructor (PR #126869)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 14 13:43:45 PST 2025


================
@@ -106,6 +107,26 @@ class UncountedLambdaCapturesChecker
         return safeGetName(NsDecl) == "WTF" && safeGetName(Decl) == "switchOn";
       }
 
+      bool VisitCXXConstructExpr(CXXConstructExpr *CE) override {
+        if (ConstructToIgnore.contains(CE))
+          return true;
+        if (auto *Callee = CE->getConstructor()) {
+          unsigned ArgIndex = 0;
+          for (auto *Param : Callee->parameters()) {
+            if (ArgIndex >= CE->getNumArgs())
+              return true;
+            auto *Arg = CE->getArg(ArgIndex)->IgnoreParenCasts();
+            if (auto *L = findLambdaInArg(Arg)) {
----------------
rniwa wrote:

Oh, so we wanna ignore lambda expressions that are passed to `[[clang::noescape]]`. The code in `VisitCallExpr` and now `VisitCXXConstructExpr` is there to detect this specific case, and then ignore the argument.

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


More information about the cfe-commits mailing list