From 490823746a13bca58798e11543701c1cd30ffdf6 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 25 Oct 2016 10:06:11 +0000 Subject: [PATCH] Fix 'unknown documentation command' warning ranges Warnings generated by -Wdocumentation-unknown-command did only have a start location, not a full source range. This resulted in only the "carret" being show in messages, and IDEs highlighting only the single initial character. llvm-svn: 285056 --- clang/lib/AST/CommentLexer.cpp | 10 ++++++---- clang/test/Sema/warn-documentation-unknown-command.cpp | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp index 57bfef08df6e..65d0f56f09ab 100644 --- a/clang/lib/AST/CommentLexer.cpp +++ b/clang/lib/AST/CommentLexer.cpp @@ -378,15 +378,17 @@ void Lexer::lexCommentText(Token &T) { if ((Info = Traits.getTypoCorrectCommandInfo(CommandName))) { StringRef CorrectedName = Info->Name; SourceLocation Loc = getSourceLocation(BufferPtr); - SourceRange CommandRange(Loc.getLocWithOffset(1), - getSourceLocation(TokenPtr)); + SourceLocation EndLoc = getSourceLocation(TokenPtr); + SourceRange FullRange = SourceRange(Loc, EndLoc); + SourceRange CommandRange(Loc.getLocWithOffset(1), EndLoc); Diag(Loc, diag::warn_correct_comment_command_name) - << CommandName << CorrectedName + << FullRange << CommandName << CorrectedName << FixItHint::CreateReplacement(CommandRange, CorrectedName); } else { formTokenWithChars(T, TokenPtr, tok::unknown_command); T.setUnknownCommandName(CommandName); - Diag(T.getLocation(), diag::warn_unknown_comment_command_name); + Diag(T.getLocation(), diag::warn_unknown_comment_command_name) + << SourceRange(T.getLocation(), T.getEndLocation()); return; } } diff --git a/clang/test/Sema/warn-documentation-unknown-command.cpp b/clang/test/Sema/warn-documentation-unknown-command.cpp index 3674a9c68010..4328c9682f21 100644 --- a/clang/test/Sema/warn-documentation-unknown-command.cpp +++ b/clang/test/Sema/warn-documentation-unknown-command.cpp @@ -9,3 +9,7 @@ int test_unknown_comand_1; /// \retur aaa int test_unknown_comand_2(); +// RUN: c-index-test -test-load-source all -Wdocumentation-unknown-command %s > /dev/null 2> %t.err +// RUN: FileCheck < %t.err -check-prefix=CHECK-RANGE %s +// CHECK-RANGE: warn-documentation-unknown-command.cpp:5:9:{5:9-5:17}: warning: unknown command tag name +// CHECK-RANGE: warn-documentation-unknown-command.cpp:9:5:{9:5-9:11}: warning: unknown command tag name 'retur'; did you mean 'return'?