Re: [clang-tools-extra] r311020 - [clang-tidy] Use CloexecCheck as base class.

2017-08-16 Thread Chih-hung Hsieh via cfe-commits
Thanks. The fix is in https://reviews.llvm.org/rL311040.


On Wed, Aug 16, 2017 at 1:39 PM, Evgenii Stepanov  wrote:

> Hi,
>
> this change breaks build:
> clang-tools-extra/clang-tidy/android/CloexecSocketCheck.cpp:20:30:
> error: unused variable 'SOCK_CLOEXEC'
> [-Werror,-Wunused-const-variable]
> static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
>
> Please test with LLVM_ENABLE_WERROR=ON before submitting!
>
>
> On Wed, Aug 16, 2017 at 9:59 AM, Chih-Hung Hsieh via cfe-commits
>  wrote:
> > Author: chh
> > Date: Wed Aug 16 09:59:26 2017
> > New Revision: 311020
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=311020&view=rev
> > Log:
> > [clang-tidy] Use CloexecCheck as base class.
> >
> > Summary:
> > Simplify registerMatchers and check functions in CloexecCreatCheck,
> > CloexecSocketCheck, CloexecFopenCheck, and CloexecOpenCheck.
> >
> > Differential Revision: https://reviews.llvm.org/D36761
> >
> >
> > Modified:
> > clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
> > clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
> > clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
> > clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.h
> > clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp
> > clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.h
> > clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
> > clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.h
> > clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
> > clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
> >
> > Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/android/CloexecCheck.cpp?rev=311020&
> r1=311019&r2=311020&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
> (original)
> > +++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp Wed Aug
> 16 09:59:26 2017
> > @@ -20,10 +20,6 @@ namespace tidy {
> >  namespace android {
> >
> >  namespace {
> > -
> > -const char *const FuncDeclBindingStr = "funcDecl";
> > -const char *const FuncBindingStr = "func";
> > -
> >  // Helper function to form the correct string mode for Type3.
> >  // Build the replace text. If it's string constant, add  directly
> in the
> >  // end of the string. Else, add .
> > @@ -41,6 +37,10 @@ std::string buildFixMsgForStringFlag(con
> >  }
> >  } // namespace
> >
> > +constexpr char CloexecCheck::FuncDeclBindingStr[];
> > +
> > +constexpr char CloexecCheck::FuncBindingStr[];
> > +
> >  void CloexecCheck::registerMatchersImpl(
> >  MatchFinder *Finder, internal::Matcher Function) {
> >// We assume all the checked APIs are C functions.
> >
> > Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/android/CloexecCheck.h?rev=311020&r1=
> 311019&r2=311020&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h (original)
> > +++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h Wed Aug
> 16 09:59:26 2017
> > @@ -90,6 +90,12 @@ protected:
> >/// Helper function to get the spelling of a particular argument.
> >StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult
> &Result,
> > int N) const;
> > +
> > +  /// Binding name of the FuncDecl of a function call.
> > +  static constexpr char FuncDeclBindingStr[] = "funcDecl";
> > +
> > +  /// Binding name of the function call expression.
> > +  static constexpr char FuncBindingStr[] = "func";
> >  };
> >
> >  } // namespace android
> >
> > Modified: clang-tools-extra/trunk/clang-tidy/android/
> CloexecCreatCheck.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/android/CloexecCreatCheck.cpp?rev=
> 311020&r1=311019&r2=311020&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
> (original)
> > +++ clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
> Wed Aug 16 09:59:26 2017
> > @@ -10,7 +10,6 @@
> >  #include "CloexecCreatCheck.h"
> >  #include "clang/AST/ASTContext.h"
> >  #include "clang/ASTMatchers/ASTMatchFinder.h"
> > -#include "clang/Lex/Lexer.h"
> >
> >  using namespace clang::ast_matchers;
> >
> > @@ -21,37 +20,22 @@ namespace android {
> >  void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
> >auto CharPointerType = hasType(pointerType(pointee(
> isAnyCharacter(;
> >auto MODETType = hasType(namedDecl(hasName("mode_t")));
> > -
> > -  Finder->addMatcher(
> > -  callExpr(callee(functio

Re: [clang-tools-extra] r311020 - [clang-tidy] Use CloexecCheck as base class.

2017-08-16 Thread Evgenii Stepanov via cfe-commits
Hi,

this change breaks build:
clang-tools-extra/clang-tidy/android/CloexecSocketCheck.cpp:20:30:
error: unused variable 'SOCK_CLOEXEC'
[-Werror,-Wunused-const-variable]
static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";

Please test with LLVM_ENABLE_WERROR=ON before submitting!


On Wed, Aug 16, 2017 at 9:59 AM, Chih-Hung Hsieh via cfe-commits
 wrote:
> Author: chh
> Date: Wed Aug 16 09:59:26 2017
> New Revision: 311020
>
> URL: http://llvm.org/viewvc/llvm-project?rev=311020&view=rev
> Log:
> [clang-tidy] Use CloexecCheck as base class.
>
> Summary:
> Simplify registerMatchers and check functions in CloexecCreatCheck,
> CloexecSocketCheck, CloexecFopenCheck, and CloexecOpenCheck.
>
> Differential Revision: https://reviews.llvm.org/D36761
>
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
> clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
> clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
> clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.h
> clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp
> clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.h
> clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
> clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.h
> clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
> clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
>
> Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp (original)
> +++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp Wed Aug 16 
> 09:59:26 2017
> @@ -20,10 +20,6 @@ namespace tidy {
>  namespace android {
>
>  namespace {
> -
> -const char *const FuncDeclBindingStr = "funcDecl";
> -const char *const FuncBindingStr = "func";
> -
>  // Helper function to form the correct string mode for Type3.
>  // Build the replace text. If it's string constant, add  directly in 
> the
>  // end of the string. Else, add .
> @@ -41,6 +37,10 @@ std::string buildFixMsgForStringFlag(con
>  }
>  } // namespace
>
> +constexpr char CloexecCheck::FuncDeclBindingStr[];
> +
> +constexpr char CloexecCheck::FuncBindingStr[];
> +
>  void CloexecCheck::registerMatchersImpl(
>  MatchFinder *Finder, internal::Matcher Function) {
>// We assume all the checked APIs are C functions.
>
> Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h?rev=311020&r1=311019&r2=311020&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h (original)
> +++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h Wed Aug 16 
> 09:59:26 2017
> @@ -90,6 +90,12 @@ protected:
>/// Helper function to get the spelling of a particular argument.
>StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult 
> &Result,
> int N) const;
> +
> +  /// Binding name of the FuncDecl of a function call.
> +  static constexpr char FuncDeclBindingStr[] = "funcDecl";
> +
> +  /// Binding name of the function call expression.
> +  static constexpr char FuncBindingStr[] = "func";
>  };
>
>  } // namespace android
>
> Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp 
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp Wed Aug 
> 16 09:59:26 2017
> @@ -10,7 +10,6 @@
>  #include "CloexecCreatCheck.h"
>  #include "clang/AST/ASTContext.h"
>  #include "clang/ASTMatchers/ASTMatchFinder.h"
> -#include "clang/Lex/Lexer.h"
>
>  using namespace clang::ast_matchers;
>
> @@ -21,37 +20,22 @@ namespace android {
>  void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
>auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
>auto MODETType = hasType(namedDecl(hasName("mode_t")));
> -
> -  Finder->addMatcher(
> -  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
> -   hasName("creat"),
> -   hasParameter(0, CharPointerType),
> -   hasParameter(1, MODETType))
> -  .bind("funcDecl")))
> -  .bind("creatFn"),
> -  this);
> +  registerMatc

[clang-tools-extra] r311020 - [clang-tidy] Use CloexecCheck as base class.

2017-08-16 Thread Chih-Hung Hsieh via cfe-commits
Author: chh
Date: Wed Aug 16 09:59:26 2017
New Revision: 311020

URL: http://llvm.org/viewvc/llvm-project?rev=311020&view=rev
Log:
[clang-tidy] Use CloexecCheck as base class.

Summary:
Simplify registerMatchers and check functions in CloexecCreatCheck,
CloexecSocketCheck, CloexecFopenCheck, and CloexecOpenCheck.

Differential Revision: https://reviews.llvm.org/D36761


Modified:
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.h
clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.h
clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.h
clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp Wed Aug 16 
09:59:26 2017
@@ -20,10 +20,6 @@ namespace tidy {
 namespace android {
 
 namespace {
-
-const char *const FuncDeclBindingStr = "funcDecl";
-const char *const FuncBindingStr = "func";
-
 // Helper function to form the correct string mode for Type3.
 // Build the replace text. If it's string constant, add  directly in the
 // end of the string. Else, add .
@@ -41,6 +37,10 @@ std::string buildFixMsgForStringFlag(con
 }
 } // namespace
 
+constexpr char CloexecCheck::FuncDeclBindingStr[];
+
+constexpr char CloexecCheck::FuncBindingStr[];
+
 void CloexecCheck::registerMatchersImpl(
 MatchFinder *Finder, internal::Matcher Function) {
   // We assume all the checked APIs are C functions.

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h?rev=311020&r1=311019&r2=311020&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h Wed Aug 16 
09:59:26 2017
@@ -90,6 +90,12 @@ protected:
   /// Helper function to get the spelling of a particular argument.
   StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult 
&Result,
int N) const;
+
+  /// Binding name of the FuncDecl of a function call.
+  static constexpr char FuncDeclBindingStr[] = "funcDecl";
+
+  /// Binding name of the function call expression.
+  static constexpr char FuncBindingStr[] = "func";
 };
 
 } // namespace android

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp?rev=311020&r1=311019&r2=311020&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp Wed Aug 16 
09:59:26 2017
@@ -10,7 +10,6 @@
 #include "CloexecCreatCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -21,37 +20,22 @@ namespace android {
 void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
   auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
   auto MODETType = hasType(namedDecl(hasName("mode_t")));
-
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("creat"),
-   hasParameter(0, CharPointerType),
-   hasParameter(1, MODETType))
-  .bind("funcDecl")))
-  .bind("creatFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("creat"),
+hasParameter(0, CharPointerType),
+hasParameter(1, MODETType)));
 }
 
 void CloexecCreatCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("creatFn");
-  const SourceManager &SM = *Result.SourceManager;
-
   const std::string &ReplacementText =
-  (Twine("open (") +
-   Lexer::getSource