r175003 - Fix crash for incomplete labels in macros.
Daniel Jasper
djasper at google.com
Tue Feb 12 12:17:17 PST 2013
Author: djasper
Date: Tue Feb 12 14:17:17 2013
New Revision: 175003
URL: http://llvm.org/viewvc/llvm-project?rev=175003&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=175003&r1=175002&r2=175003&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Feb 12 14:17:17 2013
@@ -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)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175003&r1=175002&r2=175003&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 12 14:17:17 2013
@@ -353,6 +353,12 @@ TEST_F(FormatTest, FormatsSwitchStatemen
"}");
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"
More information about the cfe-commits
mailing list