<div dir="ltr">Thanks. The fix is in <a href="https://reviews.llvm.org/rL311040">https://reviews.llvm.org/rL311040</a>.<div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 16, 2017 at 1:39 PM, Evgenii Stepanov <span dir="ltr"><<a href="mailto:eugeni.stepanov@gmail.com" target="_blank">eugeni.stepanov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
this change breaks build:<br>
clang-tools-extra/clang-tidy/<wbr>android/CloexecSocketCheck.<wbr>cpp:20:30:<br>
error: unused variable 'SOCK_CLOEXEC'<br>
[-Werror,-Wunused-const-<wbr>variable]<br>
static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";<br>
<br>
Please test with LLVM_ENABLE_WERROR=ON before submitting!<br>
<br>
<br>
On Wed, Aug 16, 2017 at 9:59 AM, Chih-Hung Hsieh via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: chh<br>
> Date: Wed Aug 16 09:59:26 2017<br>
> New Revision: 311020<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=311020&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=311020&view=rev</a><br>
> Log:<br>
> [clang-tidy] Use CloexecCheck as base class.<br>
><br>
> Summary:<br>
> Simplify registerMatchers and check functions in CloexecCreatCheck,<br>
> CloexecSocketCheck, CloexecFopenCheck, and CloexecOpenCheck.<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D36761" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D36761</a><br>
><br>
><br>
> Modified:<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.cpp<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.h<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.cpp<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.h<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.cpp<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.h<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>cpp<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>h<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.cpp<br>
>     clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.h<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecCheck.cpp?rev=311020&<wbr>r1=311019&r2=311020&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.cpp Wed Aug 16 09:59:26 2017<br>
> @@ -20,10 +20,6 @@ namespace tidy {<br>
>  namespace android {<br>
><br>
>  namespace {<br>
> -<br>
> -const char *const FuncDeclBindingStr = "funcDecl";<br>
> -const char *const FuncBindingStr = "func";<br>
> -<br>
>  // Helper function to form the correct string mode for Type3.<br>
>  // Build the replace text. If it's string constant, add <Mode> directly in the<br>
>  // end of the string. Else, add <Mode>.<br>
> @@ -41,6 +37,10 @@ std::string buildFixMsgForStringFlag(con<br>
>  }<br>
>  } // namespace<br>
><br>
> +constexpr char CloexecCheck::<wbr>FuncDeclBindingStr[];<br>
> +<br>
> +constexpr char CloexecCheck::FuncBindingStr[]<wbr>;<br>
> +<br>
>  void CloexecCheck::<wbr>registerMatchersImpl(<br>
>      MatchFinder *Finder, internal::Matcher<<wbr>FunctionDecl> Function) {<br>
>    // We assume all the checked APIs are C functions.<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecCheck.h?rev=311020&r1=<wbr>311019&r2=311020&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.h (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecCheck.h Wed Aug 16 09:59:26 2017<br>
> @@ -90,6 +90,12 @@ protected:<br>
>    /// Helper function to get the spelling of a particular argument.<br>
>    StringRef getSpellingArg(const ast_matchers::MatchFinder::<wbr>MatchResult &Result,<br>
>                             int N) const;<br>
> +<br>
> +  /// Binding name of the FuncDecl of a function call.<br>
> +  static constexpr char FuncDeclBindingStr[] = "funcDecl";<br>
> +<br>
> +  /// Binding name of the function call expression.<br>
> +  static constexpr char FuncBindingStr[] = "func";<br>
>  };<br>
><br>
>  } // namespace android<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecCreatCheck.cpp?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.cpp Wed Aug 16 09:59:26 2017<br>
> @@ -10,7 +10,6 @@<br>
>  #include "CloexecCreatCheck.h"<br>
>  #include "clang/AST/ASTContext.h"<br>
>  #include "clang/ASTMatchers/<wbr>ASTMatchFinder.h"<br>
> -#include "clang/Lex/Lexer.h"<br>
><br>
>  using namespace clang::ast_matchers;<br>
><br>
> @@ -21,37 +20,22 @@ namespace android {<br>
>  void CloexecCreatCheck::<wbr>registerMatchers(MatchFinder *Finder) {<br>
>    auto CharPointerType = hasType(pointerType(pointee(<wbr>isAnyCharacter())));<br>
>    auto MODETType = hasType(namedDecl(hasName("<wbr>mode_t")));<br>
> -<br>
> -  Finder->addMatcher(<br>
> -      callExpr(callee(functionDecl(<wbr>isExternC(), returns(isInteger()),<br>
> -                                   hasName("creat"),<br>
> -                                   hasParameter(0, CharPointerType),<br>
> -                                   hasParameter(1, MODETType))<br>
> -                          .bind("funcDecl")))<br>
> -          .bind("creatFn"),<br>
> -      this);<br>
> +  registerMatchersImpl(Finder,<br>
> +                       functionDecl(isExternC(), returns(isInteger()),<br>
> +                                    hasName("creat"),<br>
> +                                    hasParameter(0, CharPointerType),<br>
> +                                    hasParameter(1, MODETType)));<br>
>  }<br>
><br>
>  void CloexecCreatCheck::check(const MatchFinder::MatchResult &Result) {<br>
> -  const auto *MatchedCall = Result.Nodes.getNodeAs<<wbr>CallExpr>("creatFn");<br>
> -  const SourceManager &SM = *Result.SourceManager;<br>
> -<br>
>    const std::string &ReplacementText =<br>
> -      (Twine("open (") +<br>
> -       Lexer::getSourceText(<wbr>CharSourceRange::<wbr>getTokenRange(<br>
> -                                MatchedCall->getArg(0)-><wbr>getSourceRange()),<br>
> -                            SM, Result.Context->getLangOpts()) +<br>
> +      (Twine("open (") + getSpellingArg(Result, 0) +<br>
>         ", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, " +<br>
> -       Lexer::getSourceText(<wbr>CharSourceRange::<wbr>getTokenRange(<br>
> -                                MatchedCall->getArg(1)-><wbr>getSourceRange()),<br>
> -                            SM, Result.Context->getLangOpts()) +<br>
> -       ")")<br>
> +       getSpellingArg(Result, 1) + ")")<br>
>            .str();<br>
> -<br>
> -  diag(MatchedCall->getLocStart(<wbr>),<br>
> -       "prefer open() to creat() because open() allows O_CLOEXEC")<br>
> -      << FixItHint::CreateReplacement(<wbr>MatchedCall->getSourceRange(),<br>
> -                                      ReplacementText);<br>
> +  replaceFunc(Result,<br>
> +              "prefer open() to creat() because open() allows O_CLOEXEC",<br>
> +              ReplacementText);<br>
>  }<br>
><br>
>  } // namespace android<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.h?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecCreatCheck.h?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.h (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecCreatCheck.h Wed Aug 16 09:59:26 2017<br>
> @@ -10,7 +10,7 @@<br>
>  #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_CREAT_H<br>
>  #define LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_CREAT_H<br>
><br>
> -#include "../ClangTidy.h"<br>
> +#include "CloexecCheck.h"<br>
><br>
>  namespace clang {<br>
>  namespace tidy {<br>
> @@ -20,10 +20,10 @@ namespace android {<br>
>  /// Find the usage of creat() and redirect user to use open().<br>
><br>
>  /// <a href="http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-creat.html" rel="noreferrer" target="_blank">http://clang.llvm.org/extra/<wbr>clang-tidy/checks/android-<wbr>cloexec-creat.html</a><br>
> -class CloexecCreatCheck : public ClangTidyCheck {<br>
> +class CloexecCreatCheck : public CloexecCheck {<br>
>  public:<br>
>    CloexecCreatCheck(StringRef Name, ClangTidyContext *Context)<br>
> -      : ClangTidyCheck(Name, Context) {}<br>
> +      : CloexecCheck(Name, Context) {}<br>
>    void registerMatchers(ast_matchers:<wbr>:MatchFinder *Finder) override;<br>
>    void check(const ast_matchers::MatchFinder::<wbr>MatchResult &Result) override;<br>
>  };<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecFopenCheck.cpp?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.cpp Wed Aug 16 09:59:26 2017<br>
> @@ -18,55 +18,17 @@ namespace clang {<br>
>  namespace tidy {<br>
>  namespace android {<br>
><br>
> -namespace {<br>
> -static const char MODE = 'e';<br>
> -<br>
> -// Build the replace text. If it's string constant, add 'e' directly in the end<br>
> -// of the string. Else, add "e".<br>
> -std::string BuildReplaceText(const Expr *Arg, const SourceManager &SM,<br>
> -                             const LangOptions &LangOpts) {<br>
> -  if (Arg->getLocStart().isMacroID(<wbr>))<br>
> -    return (Lexer::getSourceText(<br>
> -                CharSourceRange::<wbr>getTokenRange(Arg-><wbr>getSourceRange()), SM,<br>
> -                LangOpts) +<br>
> -            " \"" + Twine(MODE) + "\"")<br>
> -        .str();<br>
> -<br>
> -  StringRef SR = cast<StringLiteral>(Arg-><wbr>IgnoreParenCasts())-><wbr>getString();<br>
> -  return ("\"" + SR + Twine(MODE) + "\"").str();<br>
> -}<br>
> -} // namespace<br>
> -<br>
>  void CloexecFopenCheck::<wbr>registerMatchers(MatchFinder *Finder) {<br>
>    auto CharPointerType = hasType(pointerType(pointee(<wbr>isAnyCharacter())));<br>
> -<br>
> -  Finder->addMatcher(<br>
> -      callExpr(callee(functionDecl(<wbr>isExternC(), returns(asString("FILE *")),<br>
> -                                   hasName("fopen"),<br>
> -                                   hasParameter(0, CharPointerType),<br>
> -                                   hasParameter(1, CharPointerType))<br>
> -                          .bind("funcDecl")))<br>
> -          .bind("fopenFn"),<br>
> -      this);<br>
> +  registerMatchersImpl(Finder,<br>
> +                       functionDecl(isExternC(), returns(asString("FILE *")),<br>
> +                                    hasName("fopen"),<br>
> +                                    hasParameter(0, CharPointerType),<br>
> +                                    hasParameter(1, CharPointerType)));<br>
>  }<br>
><br>
>  void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {<br>
> -  const auto *MatchedCall = Result.Nodes.getNodeAs<<wbr>CallExpr>("fopenFn");<br>
> -  const auto *FD = Result.Nodes.getNodeAs<<wbr>FunctionDecl>("funcDecl");<br>
> -  const Expr *ModeArg = MatchedCall->getArg(1);<br>
> -<br>
> -  // Check if the 'e' may be in the mode string.<br>
> -  const auto *ModeStr = dyn_cast<StringLiteral>(<wbr>ModeArg->IgnoreParenCasts());<br>
> -  if (!ModeStr || (ModeStr->getString().find(<wbr>MODE) != StringRef::npos))<br>
> -    return;<br>
> -<br>
> -  const std::string &ReplacementText = BuildReplaceText(<br>
> -      ModeArg, *Result.SourceManager, Result.Context->getLangOpts())<wbr>;<br>
> -<br>
> -  diag(ModeArg->getLocStart(), "use %0 mode 'e' to set O_CLOEXEC")<br>
> -      << FD<br>
> -      << FixItHint::CreateReplacement(<wbr>ModeArg->getSourceRange(),<br>
> -                                      ReplacementText);<br>
> +  insertStringFlag(Result, /*Mode=*/'e', /*ArgPos=*/1);<br>
>  }<br>
><br>
>  } // namespace android<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.h?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecFopenCheck.h?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.h (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecFopenCheck.h Wed Aug 16 09:59:26 2017<br>
> @@ -10,7 +10,7 @@<br>
>  #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_FOPEN_H<br>
>  #define LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_FOPEN_H<br>
><br>
> -#include "../ClangTidy.h"<br>
> +#include "CloexecCheck.h"<br>
><br>
>  namespace clang {<br>
>  namespace tidy {<br>
> @@ -23,10 +23,10 @@ namespace android {<br>
>  /// constant propagation.<br>
>  ///<br>
>  /// <a href="http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-fopen.html" rel="noreferrer" target="_blank">http://clang.llvm.org/extra/<wbr>clang-tidy/checks/android-<wbr>cloexec-fopen.html</a><br>
> -class CloexecFopenCheck : public ClangTidyCheck {<br>
> +class CloexecFopenCheck : public CloexecCheck {<br>
>  public:<br>
>    CloexecFopenCheck(StringRef Name, ClangTidyContext *Context)<br>
> -      : ClangTidyCheck(Name, Context) {}<br>
> +      : CloexecCheck(Name, Context) {}<br>
>    void registerMatchers(ast_matchers:<wbr>:MatchFinder *Finder) override;<br>
>    void check(const ast_matchers::MatchFinder::<wbr>MatchResult &Result) override;<br>
>  };<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecOpenCheck.cpp?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>cpp Wed Aug 16 09:59:26 2017<br>
> @@ -8,10 +8,8 @@<br>
>  //===-------------------------<wbr>------------------------------<wbr>---------------===//<br>
><br>
>  #include "CloexecOpenCheck.h"<br>
> -#include "../utils/ASTUtils.h"<br>
>  #include "clang/AST/ASTContext.h"<br>
>  #include "clang/ASTMatchers/<wbr>ASTMatchFinder.h"<br>
> -#include "clang/Lex/Lexer.h"<br>
><br>
>  using namespace clang::ast_matchers;<br>
><br>
> @@ -19,54 +17,26 @@ namespace clang {<br>
>  namespace tidy {<br>
>  namespace android {<br>
><br>
> -static constexpr const char *O_CLOEXEC = "O_CLOEXEC";<br>
> -<br>
>  void CloexecOpenCheck::<wbr>registerMatchers(MatchFinder *Finder) {<br>
>    auto CharPointerType = hasType(pointerType(pointee(<wbr>isAnyCharacter())));<br>
> -<br>
> -  Finder->addMatcher(<br>
> -      callExpr(callee(functionDecl(<wbr>isExternC(), returns(isInteger()),<br>
> -                                   hasAnyName("open", "open64"),<br>
> -                                   hasParameter(0, CharPointerType),<br>
> -                                   hasParameter(1, hasType(isInteger())))<br>
> -                          .bind("funcDecl")))<br>
> -          .bind("openFn"),<br>
> -      this);<br>
> -  Finder->addMatcher(<br>
> -      callExpr(callee(functionDecl(<wbr>isExternC(), returns(isInteger()),<br>
> -                                   hasName("openat"),<br>
> -                                   hasParameter(0, hasType(isInteger())),<br>
> -                                   hasParameter(1, CharPointerType),<br>
> -                                   hasParameter(2, hasType(isInteger())))<br>
> -                          .bind("funcDecl")))<br>
> -          .bind("openatFn"),<br>
> -      this);<br>
> +  registerMatchersImpl(Finder,<br>
> +                       functionDecl(isExternC(), returns(isInteger()),<br>
> +                                    hasAnyName("open", "open64"),<br>
> +                                    hasParameter(0, CharPointerType),<br>
> +                                    hasParameter(1, hasType(isInteger()))));<br>
> +  registerMatchersImpl(Finder,<br>
> +                       functionDecl(isExternC(), returns(isInteger()),<br>
> +                                    hasName("openat"),<br>
> +                                    hasParameter(0, hasType(isInteger())),<br>
> +                                    hasParameter(1, CharPointerType),<br>
> +                                    hasParameter(2, hasType(isInteger()))));<br>
>  }<br>
><br>
>  void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {<br>
> -  const Expr *FlagArg = nullptr;<br>
> -  if (const auto *OpenFnCall = Result.Nodes.getNodeAs<<wbr>CallExpr>("openFn"))<br>
> -    FlagArg = OpenFnCall->getArg(1);<br>
> -  else if (const auto *OpenFnCall =<br>
> -               Result.Nodes.getNodeAs<<wbr>CallExpr>("openatFn"))<br>
> -    FlagArg = OpenFnCall->getArg(2);<br>
> -  assert(FlagArg);<br>
> -<br>
> -  const auto *FD = Result.Nodes.getNodeAs<<wbr>FunctionDecl>("funcDecl");<br>
> -<br>
> -  // Check the required flag.<br>
> -  SourceManager &SM = *Result.SourceManager;<br>
> -  if (utils::<wbr>exprHasBitFlagWithSpelling(<wbr>FlagArg->IgnoreParenCasts(), SM,<br>
> -                     Result.Context->getLangOpts(), O_CLOEXEC))<br>
> -    return;<br>
> -<br>
> -  SourceLocation EndLoc =<br>
> -      Lexer::getLocForEndOfToken(SM.<wbr>getFileLoc(FlagArg->getLocEnd(<wbr>)), 0, SM,<br>
> -                                 Result.Context->getLangOpts())<wbr>;<br>
> -<br>
> -  diag(EndLoc, "%0 should use %1 where possible")<br>
> -      << FD << O_CLOEXEC<br>
> -      << FixItHint::CreateInsertion(<wbr>EndLoc, (Twine(" | ") + O_CLOEXEC).str());<br>
> +  const auto *FD = Result.Nodes.getNodeAs<<wbr>FunctionDecl>(<wbr>FuncDeclBindingStr);<br>
> +  assert(FD->param_size() > 1);<br>
> +  int ArgPos = (FD->param_size() > 2) ? 2 : 1;<br>
> +  insertMacroFlag(Result, /*MarcoFlag=*/"O_CLOEXEC", ArgPos);<br>
>  }<br>
><br>
>  } // namespace android<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.h?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecOpenCheck.h?rev=311020&<wbr>r1=311019&r2=311020&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>h (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/CloexecOpenCheck.<wbr>h Wed Aug 16 09:59:26 2017<br>
> @@ -10,7 +10,7 @@<br>
>  #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_OPEN_H<br>
>  #define LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_OPEN_H<br>
><br>
> -#include "../ClangTidy.h"<br>
> +#include "CloexecCheck.h"<br>
><br>
>  namespace clang {<br>
>  namespace tidy {<br>
> @@ -25,10 +25,10 @@ namespace android {<br>
>  ///<br>
>  /// Only the symbolic 'O_CLOEXEC' macro definition is checked, not the concrete<br>
>  /// value.<br>
> -class CloexecOpenCheck : public ClangTidyCheck {<br>
> +class CloexecOpenCheck : public CloexecCheck {<br>
>  public:<br>
>    CloexecOpenCheck(StringRef Name, ClangTidyContext *Context)<br>
> -      : ClangTidyCheck(Name, Context) {}<br>
> +      : CloexecCheck(Name, Context) {}<br>
>    void registerMatchers(ast_matchers:<wbr>:MatchFinder *Finder) override;<br>
>    void check(const ast_matchers::MatchFinder::<wbr>MatchResult &Result) override;<br>
>  };<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecSocketCheck.cpp?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.cpp Wed Aug 16 09:59:26 2017<br>
> @@ -8,7 +8,6 @@<br>
>  //===-------------------------<wbr>------------------------------<wbr>---------------===//<br>
><br>
>  #include "CloexecSocketCheck.h"<br>
> -#include "../utils/ASTUtils.h"<br>
>  #include "clang/AST/ASTContext.h"<br>
>  #include "clang/ASTMatchers/<wbr>ASTMatchFinder.h"<br>
><br>
> @@ -21,35 +20,16 @@ namespace android {<br>
>  static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";<br>
><br>
>  void CloexecSocketCheck::<wbr>registerMatchers(MatchFinder *Finder) {<br>
> -  Finder->addMatcher(<br>
> -      callExpr(callee(functionDecl(<wbr>isExternC(), returns(isInteger()),<br>
> -                                   hasName("socket"),<br>
> -                                   hasParameter(0, hasType(isInteger())),<br>
> -                                   hasParameter(1, hasType(isInteger())),<br>
> -                                   hasParameter(2, hasType(isInteger())))<br>
> -                          .bind("funcDecl")))<br>
> -          .bind("socketFn"),<br>
> -      this);<br>
> +  registerMatchersImpl(Finder,<br>
> +                       functionDecl(isExternC(), returns(isInteger()),<br>
> +                                    hasName("socket"),<br>
> +                                    hasParameter(0, hasType(isInteger())),<br>
> +                                    hasParameter(1, hasType(isInteger())),<br>
> +                                    hasParameter(2, hasType(isInteger()))));<br>
>  }<br>
><br>
>  void CloexecSocketCheck::check(<wbr>const MatchFinder::MatchResult &Result) {<br>
> -  const auto *MatchedCall = Result.Nodes.getNodeAs<<wbr>CallExpr>("socketFn");<br>
> -  const auto *FD = Result.Nodes.getNodeAs<<wbr>FunctionDecl>("funcDecl");<br>
> -  const Expr *FlagArg = MatchedCall->getArg(1);<br>
> -  SourceManager &SM = *Result.SourceManager;<br>
> -<br>
> -  if (utils::<wbr>exprHasBitFlagWithSpelling(<wbr>FlagArg->IgnoreParenCasts(), SM,<br>
> -                     Result.Context->getLangOpts(), SOCK_CLOEXEC))<br>
> -    return;<br>
> -<br>
> -  SourceLocation EndLoc =<br>
> -      Lexer::getLocForEndOfToken(SM.<wbr>getFileLoc(FlagArg->getLocEnd(<wbr>)), 0, SM,<br>
> -                                 Result.Context->getLangOpts())<wbr>;<br>
> -<br>
> -  diag(EndLoc, "%0 should use %1 where possible")<br>
> -      << FD << SOCK_CLOEXEC<br>
> -      << FixItHint::CreateInsertion(<wbr>EndLoc,<br>
> -                                    (Twine(" | ") + SOCK_CLOEXEC).str());<br>
> +  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);<br>
>  }<br>
><br>
>  } // namespace android<br>
><br>
> Modified: clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h?rev=311020&r1=311019&r2=311020&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-tidy/android/<wbr>CloexecSocketCheck.h?rev=<wbr>311020&r1=311019&r2=311020&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.h (original)<br>
> +++ clang-tools-extra/trunk/clang-<wbr>tidy/android/<wbr>CloexecSocketCheck.h Wed Aug 16 09:59:26 2017<br>
> @@ -10,7 +10,7 @@<br>
>  #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_SOCKET_H<br>
>  #define LLVM_CLANG_TOOLS_EXTRA_CLANG_<wbr>TIDY_ANDROID_CLOEXEC_SOCKET_H<br>
><br>
> -#include "../ClangTidy.h"<br>
> +#include "CloexecCheck.h"<br>
><br>
>  namespace clang {<br>
>  namespace tidy {<br>
> @@ -20,10 +20,10 @@ namespace android {<br>
>  ///<br>
>  /// For the user-facing documentation see:<br>
>  /// <a href="http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html" rel="noreferrer" target="_blank">http://clang.llvm.org/extra/<wbr>clang-tidy/checks/android-<wbr>cloexec-socket.html</a><br>
> -class CloexecSocketCheck : public ClangTidyCheck {<br>
> +class CloexecSocketCheck : public CloexecCheck {<br>
>  public:<br>
>    CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)<br>
> -      : ClangTidyCheck(Name, Context) {}<br>
> +      : CloexecCheck(Name, Context) {}<br>
>    void registerMatchers(ast_matchers:<wbr>:MatchFinder *Finder) override;<br>
>    void check(const ast_matchers::MatchFinder::<wbr>MatchResult &Result) override;<br>
>  };<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>