Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38889.
angelgarcia added a comment.

Sorry, I forgot. That case works just fine.


http://reviews.llvm.org/D14204

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp

Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult , SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 

Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a reviewer: alexfh.
alexfh added a comment.
This revision is now accepted and ready to land.

Thanks! Looks good!


http://reviews.llvm.org/D14204



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL251792: Fix crash in redundant-void-arg check. (authored by 
angelgarcia).

Changed prior to commit:
  http://reviews.llvm.org/D14204?vs=38889=38890#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14204

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult , SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}


Index: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+ 

Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38887.
angelgarcia added a comment.

Use Lexer::makeFileCharRange (and a few changes due to clang-format).

It seems to work as well.


http://reviews.llvm.org/D14204

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp

Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,13 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult , SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,13 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
 }
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  

Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

In http://reviews.llvm.org/D14204#278833, @angelgarcia wrote:

> Use Lexer::makeFileCharRange (and a few changes due to clang-format).
>
> It seems to work as well.


Can you add a test where a void argument is removed in a macro (which would be 
the whole point of using the makeFileCharRange instead of just bailing out on 
all macros)?

E.g. does this work in a simple case like this one?

  #define M(x) x
  M(void f(void) {})
  // CHECK-FIXES: M(void f() {})


http://reviews.llvm.org/D14204



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D14204: Fix crash in redundant-void-arg check.

2015-10-30 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added reviewers: klimek, LegalizeAdulthood.
angelgarcia added subscribers: alexfh, cfe-commits.

When applying this check to the unit tests, it would hit an assertion:
llvm/tools/clang/lib/Lex/Lexer.cpp:1056: clang::SourceLocation 
clang::Lexer::getSourceLocation(const char*, unsigned int) const: Assertion `PP 
&& "This doesn't work on raw lexers"' failed.

http://reviews.llvm.org/D14204

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp

Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,13 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -128,6 +128,9 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult , SourceRange Range,
 StringRef GrammarLocation) {
+  if (Range.getBegin().isMacroID() || Range.getEnd().isMacroID())
+return;
+
   std::string DeclText =
   Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
*Result.SourceManager,


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,13 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
 }
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -128,6 +128,9 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult , SourceRange Range,
 StringRef GrammarLocation) {
+  if (Range.getBegin().isMacroID() || Range.getEnd().isMacroID())
+return;
+
   std::string DeclText =
   Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
*Result.SourceManager,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits