diff options
author | Daniel Jasper <djasper@google.com> | 2015-01-29 10:47:14 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-01-29 10:47:14 +0000 |
commit | 2a27967cd6072877cd42dba59bea170561284e5e (patch) | |
tree | d6f7b7e594cfad526991b76b467e1e181d25be84 | |
parent | 0aaadda8e18ef6cf8fd65fad649f5a21b4070c3c (diff) |
clang-format: Fix crasher caused by not properly setting dry-run.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227427 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/UnwrappedLineFormatter.cpp | 4 | ||||
-rw-r--r-- | lib/Format/WhitespaceManager.cpp | 5 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 6c4aadc0f1..4844b66f9f 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -409,7 +409,7 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, TheLine.Type == LT_ImportStatement) { LineState State = Indenter->getInitialState(Indent, &TheLine, DryRun); while (State.NextToken) { - formatChildren(State, /*Newline=*/false, /*DryRun=*/false, Penalty); + formatChildren(State, /*Newline=*/false, DryRun, Penalty); Indenter->addTokenToState(State, /*Newline=*/false, DryRun); } } else if (Style.ColumnLimit == 0) { @@ -657,8 +657,8 @@ void UnwrappedLineFormatter::addNextStateToQueue(unsigned Penalty, bool UnwrappedLineFormatter::formatChildren(LineState &State, bool NewLine, bool DryRun, unsigned &Penalty) { - FormatToken &Previous = *State.NextToken->Previous; const FormatToken *LBrace = State.NextToken->getPreviousNonComment(); + FormatToken &Previous = *State.NextToken->Previous; if (!LBrace || LBrace->isNot(tok::l_brace) || LBrace->BlockKind != BK_Block || Previous.Children.size() == 0) // The previous token does not open a block. Nothing to do. We don't diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index bf1207e59c..44e5f690a2 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -264,6 +264,11 @@ void WhitespaceManager::alignEscapedNewlines(unsigned Start, unsigned End, void WhitespaceManager::generateChanges() { for (unsigned i = 0, e = Changes.size(); i != e; ++i) { const Change &C = Changes[i]; + if (i > 0) { + assert(Changes[i - 1].OriginalWhitespaceRange.getBegin() != + C.OriginalWhitespaceRange.getBegin() && + "Generating two replacements for the same location"); + } if (C.CreateReplacement) { std::string ReplacementText = C.PreviousLinePostfix; if (C.ContinuesPPDirective) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 65a7bff599..f099f20a6e 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3081,6 +3081,8 @@ TEST_F(FormatTest, LayoutNestedBlocks) { " if (aaaaaaaaaaaaaaaaaaaaaaaa) return;\n" "}, a);", Style); + + verifyNoCrash("^{v^{a}}"); } TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) { |