From: Manuel Klimek Date: Wed, 23 Jan 2013 10:09:28 +0000 (+0000) Subject: Fix segfaults in the formatter. X-Git-Tag: llvmorg-3.3.0-rc1~7261 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d33516ef32d258945fd5ec8bb4c3205e1adeb252;p=platform%2Fupstream%2Fllvm.git Fix segfaults in the formatter. Also: expletive deleted. llvm-svn: 173247 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index bdcf5b67fecb..90bcf6feb773 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1049,7 +1049,7 @@ public: break; case tok::kw_if: case tok::kw_while: - if (CurrentToken->is(tok::l_paren)) { + if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) { next(); if (!parseParens(/*LookForDecls=*/true)) return false; @@ -1088,7 +1088,7 @@ public: Tok->Type = TT_BinaryOperator; break; case tok::kw_operator: - if (CurrentToken->is(tok::l_paren)) { + if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) { CurrentToken->Type = TT_OverloadedOperator; next(); if (CurrentToken != NULL && CurrentToken->is(tok::r_paren)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c1c1696d9e14..fb5221ee2461 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1679,11 +1679,16 @@ TEST_F(FormatTest, BlockComments) { "/* */someCall(parameter);", getLLVMStyleWithColumns(15))); } -TEST_F(FormatTest, Fuck) { +TEST_F(FormatTest, FormatStarDependingOnContext) { verifyFormat("void f(int *a);"); verifyFormat("void f() { f(fint * b); }"); } +TEST_F(FormatTest, SpecialTokensAtEndOfLine) { + verifyFormat("while"); + verifyFormat("operator"); +} + //===----------------------------------------------------------------------===// // Objective-C tests. //===----------------------------------------------------------------------===//