r203645 - clang-format: Fix crasher.
Daniel Jasper
djasper at google.com
Wed Mar 12 01:24:49 PDT 2014
Author: djasper
Date: Wed Mar 12 03:24:47 2014
New Revision: 203645
URL: http://llvm.org/viewvc/llvm-project?rev=203645&view=rev
Log:
clang-format: Fix crasher.
Caused by unknown tokens (e.g. "\n") not properly updating the state.
Example:
const char* c = STRINGIFY(
\na : b);
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=203645&r1=203644&r2=203645&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Mar 12 03:24:47 2014
@@ -227,8 +227,8 @@ unsigned ContinuationIndenter::addTokenT
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::addTokenO
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.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=203645&r1=203644&r2=203645&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 12 03:24:47 2014
@@ -2024,6 +2024,10 @@ TEST_F(FormatTest, DoesntRemoveUnknownTo
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) {
More information about the cfe-commits
mailing list