[clang-tools-extra] r357312 - [clang-tidy] Fix PR28406
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 29 13:55:29 PDT 2019
Author: alexfh
Date: Fri Mar 29 13:55:29 2019
New Revision: 357312
URL: http://llvm.org/viewvc/llvm-project?rev=357312&view=rev
Log:
[clang-tidy] Fix PR28406
Fix the crash resulting from a careless use of getLocWithOffset. At the
beginning of a macro expansion it produces an invalid SourceLocation that causes
an assertion failure later on.
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=357312&r1=357311&r2=357312&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Fri Mar 29 13:55:29 2019
@@ -101,10 +101,15 @@ void RedundantVoidArgCheck::check(const
void RedundantVoidArgCheck::processFunctionDecl(
const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
if (Function->isThisDeclarationADefinition()) {
- const Stmt *Body = Function->getBody();
SourceLocation Start = Function->getBeginLoc();
- SourceLocation End =
- Body ? Body->getBeginLoc().getLocWithOffset(-1) : Function->getEndLoc();
+ SourceLocation End = Function->getEndLoc();
+ if (const Stmt *Body = Function->getBody()) {
+ End = Body->getBeginLoc();
+ if (End.isMacroID() &&
+ Result.SourceManager->isAtStartOfImmediateMacroExpansion(End))
+ End = Result.SourceManager->getExpansionLoc(End);
+ End = End.getLocWithOffset(-1);
+ }
removeVoidArgumentTokens(Result, SourceRange(Start, End),
"function definition");
} else {
@@ -172,10 +177,8 @@ void RedundantVoidArgCheck::removeVoidAr
void RedundantVoidArgCheck::removeVoidToken(Token VoidToken,
StringRef Diagnostic) {
- SourceLocation VoidLoc(VoidToken.getLocation());
- auto VoidRange =
- CharSourceRange::getTokenRange(VoidLoc, VoidLoc.getLocWithOffset(3));
- diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidRange);
+ SourceLocation VoidLoc = VoidToken.getLocation();
+ diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidLoc);
}
void RedundantVoidArgCheck::processTypedefNameDecl(
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=357312&r1=357311&r2=357312&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 Fri Mar 29 13:55:29 2019
@@ -489,6 +489,13 @@ void lambda_expression_with_macro_test()
// CHECK-FIXES: []() BODY;
}
+namespace qqq {
+void foo() BODY
+void bar(void) BODY;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant void argument list in function definition
+// CHECK-FIXES: void bar() BODY;
+}
+
struct S_1 {
void g_1(void) const {
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
More information about the cfe-commits
mailing list