<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>