[clang-tools-extra] r251792 - Fix crash in redundant-void-arg check.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 03:39:18 PST 2015


Author: angelgarcia
Date: Mon Nov  2 05:39:17 2015
New Revision: 251792

URL: http://llvm.org/viewvc/llvm-project?rev=251792&view=rev
Log:
Fix crash in redundant-void-arg check.

Summary:
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.

Reviewers: klimek, LegalizeAdulthood, alexfh

Subscribers: cfe-commits, alexfh

Differential Revision: http://reviews.llvm.org/D14204

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

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=251792&r1=251791&r2=251792&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Mon Nov  2 05:39:17 2015
@@ -47,8 +47,8 @@ namespace modernize {
 
 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 @@ void RedundantVoidArgCheck::registerMatc
       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::processFunct
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
     const ast_matchers::MatchFinder::MatchResult &Result, 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 {

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=251792&r1=251791&r2=251792&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp Mon Nov  2 05:39:17 2015
@@ -417,3 +417,19 @@ void test_lambda_functions() {
   // 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) {
+
+}




More information about the cfe-commits mailing list