[cfe-commits] r173539 - Comment parsing: actually check for a block command after "\param x"

Dmitri Gribenko gribozavr at gmail.com
Fri Jan 25 16:36:14 PST 2013


Author: gribozavr
Date: Fri Jan 25 18:36:14 2013
New Revision: 173539

URL: http://llvm.org/viewvc/llvm-project?rev=173539&view=rev
Log:
Comment parsing: actually check for a block command after "\param x"

This fixes PR15068.

Modified:
    cfe/trunk/include/clang/AST/CommentParser.h
    cfe/trunk/lib/AST/CommentParser.cpp
    cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp
    cfe/trunk/test/Sema/warn-documentation.cpp

Modified: cfe/trunk/include/clang/AST/CommentParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentParser.h?rev=173539&r1=173538&r2=173539&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentParser.h (original)
+++ cfe/trunk/include/clang/AST/CommentParser.h Fri Jan 25 18:36:14 2013
@@ -86,6 +86,11 @@ class Parser {
     Tok = Toks[0];
   }
 
+  bool isTokBlockCommand() {
+    return Tok.is(tok::command) &&
+           Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand;
+  }
+
 public:
   Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
          const SourceManager &SourceMgr, DiagnosticsEngine &Diags,

Modified: cfe/trunk/lib/AST/CommentParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=173539&r1=173538&r2=173539&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentParser.cpp Fri Jan 25 18:36:14 2013
@@ -329,8 +329,7 @@ BlockCommandComment *Parser::parseBlockC
   }
   consumeToken();
 
-  if (Tok.is(tok::command) &&
-      Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand) {
+  if (isTokBlockCommand()) {
     // Block command ahead.  We can't nest block commands, so pretend that this
     // command has an empty argument.
     ParagraphComment *Paragraph = S.actOnParagraphComment(
@@ -362,10 +361,28 @@ BlockCommandComment *Parser::parseBlockC
     Retokenizer.putBackLeftoverTokens();
   }
 
-  BlockContentComment *Block = parseParagraphOrBlockCommand();
-  // Since we have checked for a block command, we should have parsed a
-  // paragraph.
-  ParagraphComment *Paragraph = cast<ParagraphComment>(Block);
+  // If there's a block command ahead, we will attach an empty paragraph to
+  // this command.
+  bool EmptyParagraph = false;
+  if (isTokBlockCommand())
+    EmptyParagraph = true;
+  else if (Tok.is(tok::newline)) {
+    Token PrevTok = Tok;
+    consumeToken();
+    EmptyParagraph = isTokBlockCommand();
+    putBack(PrevTok);
+  }
+
+  ParagraphComment *Paragraph;
+  if (EmptyParagraph)
+    Paragraph = S.actOnParagraphComment(ArrayRef<InlineContentComment *>());
+  else {
+    BlockContentComment *Block = parseParagraphOrBlockCommand();
+    // Since we have checked for a block command, we should have parsed a
+    // paragraph.
+    Paragraph = cast<ParagraphComment>(Block);
+  }
+
   if (IsParam) {
     S.actOnParamCommandFinish(PC, Paragraph);
     return PC;

Modified: cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp?rev=173539&r1=173538&r2=173539&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp Fri Jan 25 18:36:14 2013
@@ -1,6 +1,7 @@
 // RUN: rm -f %t
 // RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-temporary-dtors=true %s > %t 2>&1
 // RUN: FileCheck --input-file=%t %s
+// XPASS: *
 
 class A {
 public:

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=173539&r1=173538&r2=173539&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Fri Jan 25 18:36:14 2013
@@ -836,3 +836,31 @@ typedef const struct test_nocrash7 * tes
 /// aaa \unknown aaa \unknown aaa
 int test_nocrash9;
 
+
+// We used to crash on this.  PR15068
+
+// expected-warning at +2 {{empty paragraph passed to '\param' command}}
+// expected-warning at +2 {{empty paragraph passed to '\param' command}}
+///@param x
+///@param y
+int test_nocrash10(int x, int y);
+
+// expected-warning at +2 {{empty paragraph passed to '\param' command}} expected-warning at +2 {{parameter 'x' not found in the function declaration}}
+// expected-warning at +2 {{empty paragraph passed to '\param' command}} expected-warning at +2 {{parameter 'y' not found in the function declaration}}
+///@param x
+///@param y
+int test_nocrash11();
+
+// expected-warning at +3 {{empty paragraph passed to '\param' command}} expected-warning at +3 {{parameter 'x' not found in the function declaration}}
+// expected-warning at +3 {{empty paragraph passed to '\param' command}} expected-warning at +3 {{parameter 'y' not found in the function declaration}}
+/**
+ at param x
+ at param y
+**/
+int test_nocrash12();
+
+// expected-warning at +2 {{empty paragraph passed to '\param' command}}
+// expected-warning at +1 {{empty paragraph passed to '\param' command}}
+///@param x at param y
+int test_nocrash13(int x, int y);
+





More information about the cfe-commits mailing list