From: Daniel Jasper Date: Wed, 12 Mar 2014 08:24:47 +0000 (+0000) Subject: clang-format: Fix crasher. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=727fd088959ba1f3fcca0813b51a431f46830bb1;p=clang clang-format: Fix crasher. Caused by unknown tokens (e.g. "\n") not properly updating the state. Example: const char* c = STRINGIFY( \na : b); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203645 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index a96f1680db..17af2fa5f2 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -227,8 +227,8 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline, State.NextToken->WhitespaceRange.getEnd()) - SourceMgr.getSpellingColumnNumber( State.NextToken->WhitespaceRange.getBegin()); - State.Column += WhitespaceLength + State.NextToken->ColumnWidth; - State.NextToken = State.NextToken->Next; + State.Column += WhitespaceLength; + moveStateToNextToken(State, DryRun, /*NewLine=*/false); return 0; } @@ -349,7 +349,6 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, Penalty += State.NextToken->SplitPenalty; - // Breaking before the first "<<" is generally not desirable if the LHS is // short. Also always add the penalty if the LHS is split over mutliple lines // to avoid unncessary line breaks that just work around this penalty. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 78aa3ce7c8..44e8bf849d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2024,6 +2024,10 @@ TEST_F(FormatTest, DoesntRemoveUnknownTokens) { verifyFormat("#define A ''qqq"); verifyFormat("#define A `qqq"); verifyFormat("f(\"aaaa, bbbb, \"\\\"ccccc\\\"\");"); + EXPECT_EQ("const char *c = STRINGIFY(\n" + "\\na : b);", + format("const char * c = STRINGIFY(\n" + "\\na : b);")); } TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {