[cfe-commits] r160568 - in /cfe/trunk: lib/AST/CommentParser.cpp test/Sema/warn-documentation.cpp unittests/AST/CommentParser.cpp
Dmitri Gribenko
gribozavr at gmail.com
Fri Jul 20 13:18:53 PDT 2012
Author: gribozavr
Date: Fri Jul 20 15:18:53 2012
New Revision: 160568
URL: http://llvm.org/viewvc/llvm-project?rev=160568&view=rev
Log:
Fix PR13411: Comment parsing: failed assertion on unterminated verbatim block.
The assertion was wrong in case we have a verbatim block without a closing
command.
Also add tests for closing command name in a verbatim block, since now it can
be empty in such cases.
Modified:
cfe/trunk/lib/AST/CommentParser.cpp
cfe/trunk/test/Sema/warn-documentation.cpp
cfe/trunk/unittests/AST/CommentParser.cpp
Modified: cfe/trunk/lib/AST/CommentParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=160568&r1=160567&r2=160568&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentParser.cpp Fri Jul 20 15:18:53 2012
@@ -378,11 +378,16 @@
Lines.push_back(Line);
}
- assert(Tok.is(tok::verbatim_block_end));
- VB = S.actOnVerbatimBlockFinish(VB, Tok.getLocation(),
- Tok.getVerbatimBlockName(),
- copyArray(llvm::makeArrayRef(Lines)));
- consumeToken();
+ if (Tok.is(tok::verbatim_block_end)) {
+ VB = S.actOnVerbatimBlockFinish(VB, Tok.getLocation(),
+ Tok.getVerbatimBlockName(),
+ copyArray(llvm::makeArrayRef(Lines)));
+ consumeToken();
+ } else {
+ // Unterminated \\verbatim block
+ VB = S.actOnVerbatimBlockFinish(VB, SourceLocation(), "",
+ copyArray(llvm::makeArrayRef(Lines)));
+ }
return VB;
}
Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=160568&r1=160567&r2=160568&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Fri Jul 20 15:18:53 2012
@@ -276,3 +276,9 @@
}
}
+// PR13411, reduced. We used to crash on this.
+/**
+ * @code Aaa.
+ */
+void test_nocrash1(int);
+
Modified: cfe/trunk/unittests/AST/CommentParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/CommentParser.cpp?rev=160568&r1=160567&r2=160568&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/CommentParser.cpp (original)
+++ cfe/trunk/unittests/AST/CommentParser.cpp Fri Jul 20 15:18:53 2012
@@ -388,7 +388,8 @@
::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
size_t Idx,
VerbatimBlockComment *&VBC,
- StringRef Name) {
+ StringRef Name,
+ StringRef CloseName) {
::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
if (!AR)
return AR;
@@ -399,17 +400,27 @@
<< "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
"expected \"" << Name.str() << "\"";
+ StringRef ActualCloseName = VBC->getCloseName();
+ if (ActualCloseName != CloseName)
+ return ::testing::AssertionFailure()
+ << "VerbatimBlockComment has closing command name \""
+ << ActualCloseName.str() << "\", "
+ "expected \"" << CloseName.str() << "\"";
+
return ::testing::AssertionSuccess();
}
struct NoLines {};
+struct Lines {};
::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
size_t Idx,
VerbatimBlockComment *&VBC,
StringRef Name,
+ StringRef CloseName,
NoLines) {
- ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name);
+ ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
+ CloseName);
if (!AR)
return AR;
@@ -425,8 +436,11 @@
size_t Idx,
VerbatimBlockComment *&VBC,
StringRef Name,
+ StringRef CloseName,
+ Lines,
StringRef Line0) {
- ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name);
+ ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
+ CloseName);
if (!AR)
return AR;
@@ -448,9 +462,12 @@
size_t Idx,
VerbatimBlockComment *&VBC,
StringRef Name,
+ StringRef CloseName,
+ Lines,
StringRef Line0,
StringRef Line1) {
- ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name);
+ ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
+ CloseName);
if (!AR)
return AR;
@@ -994,7 +1011,8 @@
}
{
VerbatimBlockComment *VCC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", NoLines()));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
+ NoLines()));
}
}
@@ -1013,11 +1031,32 @@
}
{
VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", " Aaa "));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
+ Lines(), " Aaa "));
}
}
TEST_F(CommentParserTest, VerbatimBlock3) {
+ const char *Source = "// \\verbatim Aaa\n";
+
+ FullComment *FC = parseString(Source);
+ ASSERT_TRUE(HasChildCount(FC, 2));
+
+ {
+ ParagraphComment *PC;
+ ASSERT_TRUE(GetChildAt(FC, 0, PC));
+
+ ASSERT_TRUE(HasChildCount(PC, 1));
+ ASSERT_TRUE(HasTextAt(PC, 0, " "));
+ }
+ {
+ VerbatimBlockComment *VBC;
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
+ Lines(), " Aaa"));
+ }
+}
+
+TEST_F(CommentParserTest, VerbatimBlock4) {
const char *Source =
"//\\verbatim\n"
"//\\endverbatim\n";
@@ -1027,11 +1066,12 @@
{
VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", NoLines()));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
+ NoLines()));
}
}
-TEST_F(CommentParserTest, VerbatimBlock4) {
+TEST_F(CommentParserTest, VerbatimBlock5) {
const char *Sources[] = {
"//\\verbatim\n"
"// Aaa\n"
@@ -1048,12 +1088,13 @@
{
VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", " Aaa"));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
+ Lines(), " Aaa"));
}
}
}
-TEST_F(CommentParserTest, VerbatimBlock5) {
+TEST_F(CommentParserTest, VerbatimBlock6) {
const char *Sources[] = {
"// \\verbatim\n"
"// Aaa\n"
@@ -1077,12 +1118,13 @@
}
{
VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", " Aaa"));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
+ Lines(), " Aaa"));
}
}
}
-TEST_F(CommentParserTest, VerbatimBlock6) {
+TEST_F(CommentParserTest, VerbatimBlock7) {
const char *Sources[] = {
"// \\verbatim\n"
"// Aaa\n"
@@ -1108,12 +1150,13 @@
}
{
VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", " Aaa", " Bbb"));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
+ Lines(), " Aaa", " Bbb"));
}
}
}
-TEST_F(CommentParserTest, VerbatimBlock7) {
+TEST_F(CommentParserTest, VerbatimBlock8) {
const char *Sources[] = {
"// \\verbatim\n"
"// Aaa\n"
@@ -1140,7 +1183,7 @@
}
{
VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim"));
+ ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
ASSERT_EQ(3U, VBC->getNumLines());
ASSERT_EQ(" Aaa", VBC->getText(0));
ASSERT_EQ("", VBC->getText(1));
More information about the cfe-commits
mailing list