[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 13:36:14 PDT 2020


njames93 added subscribers: Eugene.Zelenko, njames93.
njames93 added a comment.

Please override `isLanguageVersionSupported` to restrict this check to just running on ObjectiveC translation units.



================
Comment at: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp:33
+      Result.Nodes.getNodeAs<BlockExpr>("arg-block");
+  const auto *EscapingBlockDecl = MatchedEscapingBlock->getBlockDecl();
+  for (const auto CapturedVar : EscapingBlockDecl->captures()) {
----------------
Don't use `auto` here as type isn't spelled out explicitly in the initializer.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp:34
+  const auto *EscapingBlockDecl = MatchedEscapingBlock->getBlockDecl();
+  for (const auto CapturedVar : EscapingBlockDecl->captures()) {
+    const VarDecl *Var = CapturedVar.getVariable();
----------------
Ditto, also could this be a reference to avoid an unnecessary copy?


================
Comment at: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp:38
+      diag(MatchedEscapingBlock->getBeginLoc(),
+           "Pointer '%0' with attribute 'noescape' is captured by an "
+           "asynchronously-executed block")
----------------
Convention is warnings start with a lower case letter, same goes for the note below.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp:40
+           "asynchronously-executed block")
+          << Var->getName();
+      diag(Var->getBeginLoc(), "The 'noescape' attribute is declared here.",
----------------
You can get rid of `->getName()` and just pass `Var`, The diagnostics builder has a special case for `const NamedDecl*`


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m:25
+    *q = 0;
+    // CHECK-MESSAGES-NOT: ::[@LINE-2]:{{[0-9]*}}: warning: {{.*}} [bugprone-no-escape]
+  });
----------------
Be explicit about the column number and warning message. You don't need to include the diagnostic name though.
Also the macro should be `[[@LINE-2]]`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904





More information about the cfe-commits mailing list