]> granicus.if.org Git - clang/commitdiff
CommentLexer: When proceeding with a typo corrected name don't clobber the token.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 1 Dec 2013 15:09:32 +0000 (15:09 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 1 Dec 2013 15:09:32 +0000 (15:09 +0000)
This would crash if the token is used in another diagnostic. PR18051.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196048 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/CommentLexer.cpp
test/Sema/warn-documentation-fixits.cpp

index 475532d9a9924f3e23c03761dc5868d6c05826c7..01ed3ce80a66f0bbdcc4495a7905c74e04f12601 100644 (file)
@@ -353,16 +353,17 @@ void Lexer::lexCommentText(Token &T) {
 
         const CommandInfo *Info = Traits.getCommandInfoOrNULL(CommandName);
         if (!Info) {
-          formTokenWithChars(T, TokenPtr, tok::unknown_command);
-          T.setUnknownCommandName(CommandName);
           if ((Info = Traits.getTypoCorrectCommandInfo(CommandName))) {
             StringRef CorrectedName = Info->Name;
-            SourceRange CommandRange(T.getLocation().getLocWithOffset(1),
-                                     T.getEndLocation());
-            Diag(T.getLocation(), diag::warn_correct_comment_command_name)
+            SourceLocation Loc = getSourceLocation(BufferPtr);
+            SourceRange CommandRange(Loc.getLocWithOffset(1),
+                                     getSourceLocation(TokenPtr));
+            Diag(Loc, diag::warn_correct_comment_command_name)
               << 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);
             return;
           }
index a5a477f66d6d91401455f18589692a2edc021f9a..675d86c366db01815afeafd65bec38b06dd2ab3b 100644 (file)
@@ -70,6 +70,11 @@ int gorf();
 /// \t bbb IS_DOXYGEN_END
 int Bar();
 
+// expected-warning@+2  {{unknown command tag name 'encode'; did you mean 'endcode'?}}
+// expected-warning@+1  {{'\endcode' command does not terminate a verbatim text block}}
+/// \encode PR18051
+int PR18051();
+
 // CHECK: fix-it:"{{.*}}":{5:12-5:22}:"a"
 // CHECK: fix-it:"{{.*}}":{9:12-9:15}:"aaa"
 // CHECK: fix-it:"{{.*}}":{13:13-13:23}:"T"
@@ -83,3 +88,4 @@ int Bar();
 // CHECK: fix-it:"{{.*}}":{58:30-58:30}:" MY_ATTR_DEPRECATED"
 // CHECK: fix-it:"{{.*}}":{63:6-63:11}:"return"
 // CHECK: fix-it:"{{.*}}":{67:6-67:11}:"foobar"
+// CHECK: fix-it:"{{.*}}":{75:6-75:12}:"endcode"