Re: [PATCH] D14204: Fix crash in redundant-void-arg check.
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&id=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 &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 { 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(), CastDestinationIsFu
Re: [PATCH] D14204: Fix crash in redundant-void-arg check.
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.
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 &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 { 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(), CastDestinat
Re: [PATCH] D14204: Fix crash in redundant-void-arg check.
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
Re: [PATCH] D14204: Fix crash in redundant-void-arg check.
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 &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 { 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( + cx
Re: [PATCH] D14204: Fix crash in redundant-void-arg check.
alexfh added inline comments. Comment at: clang-tidy/modernize/RedundantVoidArgCheck.cpp:131 @@ -130,1 +130,3 @@ StringRef GrammarLocation) { + if (Range.getBegin().isMacroID() || Range.getEnd().isMacroID()) +return; What happens if instead you pass the range through `Lexer::makeFileCharRange`? This might be a way to enable fixes at least in some trivial cases involving macros. http://reviews.llvm.org/D14204 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits