[PATCH] D25870: Fix 'unknown documentation command' warning ranges

Erik Verbruggen via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 21 07:27:34 PDT 2016


erikjv created this revision.
erikjv added reviewers: bkramer, klimek.
erikjv added a subscriber: cfe-commits.

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.

Now that the full range is available, nice underlineing can be done, and
tools that support more/other commands than doxygen can filter out those
warnings.


https://reviews.llvm.org/D25870

Files:
  lib/AST/CommentLexer.cpp
  test/Sema/warn-documentation-unknown-command.cpp


Index: test/Sema/warn-documentation-unknown-command.cpp
===================================================================
--- test/Sema/warn-documentation-unknown-command.cpp
+++ test/Sema/warn-documentation-unknown-command.cpp
@@ -9,3 +9,7 @@
 /// \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'?
Index: lib/AST/CommentLexer.cpp
===================================================================
--- lib/AST/CommentLexer.cpp
+++ lib/AST/CommentLexer.cpp
@@ -378,15 +378,17 @@
           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;
           }
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25870.75422.patch
Type: text/x-patch
Size: 2051 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161021/86aea8de/attachment.bin>


More information about the cfe-commits mailing list