[clang-tools-extra] r272155 - [clang-tidy] misc-argument-comment: don't bail out when an argument is a macro expansion (e.g. NULL).
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 8 08:27:47 PDT 2016
Author: alexfh
Date: Wed Jun 8 10:27:46 2016
New Revision: 272155
URL: http://llvm.org/viewvc/llvm-project?rev=272155&view=rev
Log:
[clang-tidy] misc-argument-comment: don't bail out when an argument is a macro expansion (e.g. NULL).
Add CHECK-FIX tests.
Modified:
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp?rev=272155&r1=272154&r2=272155&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp Wed Jun 8 10:27:46 2016
@@ -37,8 +37,8 @@ void ArgumentCommentCheck::registerMatch
Finder->addMatcher(cxxConstructExpr().bind("expr"), this);
}
-std::vector<std::pair<SourceLocation, StringRef>>
-ArgumentCommentCheck::getCommentsInRange(ASTContext *Ctx, SourceRange Range) {
+static std::vector<std::pair<SourceLocation, StringRef>>
+getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
std::vector<std::pair<SourceLocation, StringRef>> Comments;
auto &SM = Ctx->getSourceManager();
std::pair<FileID, unsigned> BeginLoc = SM.getDecomposedLoc(Range.getBegin()),
@@ -132,16 +132,13 @@ void ArgumentCommentCheck::checkCallArgs
}
}
- SourceLocation BeginSLoc, EndSLoc = Args[i]->getLocStart();
- if (i == 0)
- BeginSLoc = ArgBeginLoc;
- else
- BeginSLoc = Args[i - 1]->getLocEnd();
- if (BeginSLoc.isMacroID() || EndSLoc.isMacroID())
- continue;
+ CharSourceRange BeforeArgument = CharSourceRange::getCharRange(
+ i == 0 ? ArgBeginLoc : Args[i - 1]->getLocEnd(),
+ Args[i]->getLocStart());
+ BeforeArgument = Lexer::makeFileCharRange(
+ BeforeArgument, Ctx->getSourceManager(), Ctx->getLangOpts());
- for (auto Comment :
- getCommentsInRange(Ctx, SourceRange(BeginSLoc, EndSLoc))) {
+ for (auto Comment : getCommentsInRange(Ctx, BeforeArgument)) {
llvm::SmallVector<StringRef, 2> Matches;
if (IdentRE.match(Comment.second, &Matches)) {
if (Matches[2] != II->getName()) {
Modified: clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h?rev=272155&r1=272154&r2=272155&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.h Wed Jun 8 10:27:46 2016
@@ -43,8 +43,6 @@ private:
bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params, StringRef ArgName,
unsigned ArgIndex);
- std::vector<std::pair<SourceLocation, StringRef>>
- getCommentsInRange(ASTContext *Ctx, SourceRange Range);
void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
SourceLocation ArgBeginLoc,
llvm::ArrayRef<const Expr *> Args);
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp?rev=272155&r1=272154&r2=272155&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp Wed Jun 8 10:27:46 2016
@@ -12,6 +12,7 @@ void g() {
// CHECK-MESSAGES: [[@LINE+2]]:14: warning: argument name 'z' in comment does not match parameter name 'y'
// CHECK-MESSAGES: :[[@LINE-5]]:19: note: 'y' declared here
f(/*y=*/0, /*z=*/0);
+ // CHECK-FIXES: {{^}} f(/*y=*/0, /*z=*/0);
}
struct Closure {};
@@ -37,4 +38,11 @@ void templates() {
variadic(/*xxx=*/0, /*yyy=*/1);
variadic2(/*zzZ=*/0, /*xxx=*/1, /*yyy=*/2);
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: argument name 'zzZ' in comment does not match parameter name 'zzz'
+ // CHECK-FIXES: variadic2(/*zzz=*/0, /*xxx=*/1, /*yyy=*/2);
}
+
+#define FALSE 0
+void qqq(bool aaa);
+void f() { qqq(/*bbb=*/FALSE); }
+// CHECK-MESSAGES: [[@LINE-1]]:16: warning: argument name 'bbb' in comment does not match parameter name 'aaa'
+// CHECK-FIXES: void f() { qqq(/*bbb=*/FALSE); }
More information about the cfe-commits
mailing list