]> granicus.if.org Git - clang/commitdiff
clang-format: Fix crasher.
authorDaniel Jasper <djasper@google.com>
Wed, 12 Mar 2014 08:24:47 +0000 (08:24 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 12 Mar 2014 08:24:47 +0000 (08:24 +0000)
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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index a96f1680db775a5cc0bb03c31a0e7de2185a9693..17af2fa5f2520d555105a0e28a14a0449e9e0a22 100644 (file)
@@ -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.
index 78aa3ce7c8a4ed1d16f7f1b9813a9a4a60e87ef5..44e8bf849d38e3de51ade4d9e73e7b609bf50ea4 100644 (file)
@@ -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) {