summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-12 20:17:17 +0000
committerDaniel Jasper <djasper@google.com>2013-02-12 20:17:17 +0000
commitf52ab8d60cfc3222b7b7543c8789e1c507b1b438 (patch)
treed83a8ceb6f8db8b582798e395358cc08ab7fd502
parent4d3c008c7d1ec5a6ef0c4426c216c62d179df16d (diff)
downloadbcm5719-llvm-f52ab8d60cfc3222b7b7543c8789e1c507b1b438.tar.gz
bcm5719-llvm-f52ab8d60cfc3222b7b7543c8789e1c507b1b438.zip
Fix crash for incomplete labels in macros.
Still the formatting can be improved, but at least we don't assert any more. This happened when trying to format lib/Sema/SemaType.cpp. llvm-svn: 175003
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp6
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 922671600d2..28522a3e327 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -565,8 +565,8 @@ void UnwrappedLineParser::parseDoWhile() {
}
void UnwrappedLineParser::parseLabel() {
- // FIXME: remove all asserts.
- assert(FormatTok.Tok.is(tok::colon) && "':' expected");
+ if (FormatTok.Tok.isNot(tok::colon))
+ return;
nextToken();
unsigned OldLineLevel = Line->Level;
if (Line->Level > 0)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f1cef2a03d1..f28bc884445 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -353,6 +353,12 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
"}");
verifyFormat("switch (test)\n"
" ;");
+
+ // FIXME: Improve formatting of case labels in macros.
+ verifyFormat("#define SOMECASES \\\n"
+ "case 1: \\\n"
+ " case 2\n", getLLVMStyleWithColumns(20));
+
verifyGoogleFormat("switch (x) {\n"
" case 1:\n"
" f();\n"
OpenPOWER on IntegriCloud