summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Format/UnwrappedLineFormatter.cpp4
-rw-r--r--lib/Format/WhitespaceManager.cpp5
-rw-r--r--unittests/Format/FormatTest.cpp2
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) {