[PATCH] D36761: [clang-tidy] Use CloexecCheck as base class.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 16 03:13:13 PDT 2017


hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM with a few nits.



================
Comment at: clang-tidy/android/CloexecCheck.h:95
+  /// Binding name of the FuncDecl of a function call.
+  static const char *FuncDeclBindingStr;
+
----------------
nit: use `static constexpr char FuncDeclBindingStr[] ="..."`, the same below.


================
Comment at: clang-tidy/android/CloexecFopenCheck.cpp:31
 void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>("fopenFn");
-  const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("funcDecl");
-  const Expr *ModeArg = MatchedCall->getArg(1);
-
-  // Check if the 'e' may be in the mode string.
-  const auto *ModeStr = dyn_cast<StringLiteral>(ModeArg->IgnoreParenCasts());
-  if (!ModeStr || (ModeStr->getString().find(MODE) != StringRef::npos))
-    return;
-
-  const std::string &ReplacementText = BuildReplaceText(
-      ModeArg, *Result.SourceManager, Result.Context->getLangOpts());
-
-  diag(ModeArg->getLocStart(), "use %0 mode 'e' to set O_CLOEXEC")
-      << FD
-      << FixItHint::CreateReplacement(ModeArg->getSourceRange(),
-                                      ReplacementText);
+  insertStringFlag(Result, 'e', 1);
 }
----------------
nit: add `/*Mode=*/'e', /*ArgsPos=*/1`, the same to other places.


================
Comment at: clang-tidy/android/CloexecOpenCheck.cpp:37
+  const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
+  int ArgPos = (FD->param_size() > 2) ? 2 : 1;
+  insertMacroFlag(Result, "O_CLOEXEC", ArgPos);
----------------
Should we check or assert `FD->param_size() > 0`?


https://reviews.llvm.org/D36761





More information about the cfe-commits mailing list