]> granicus.if.org Git - clang/commitdiff
clang-format: Fix crasher caused by not properly setting dry-run.
authorDaniel Jasper <djasper@google.com>
Thu, 29 Jan 2015 10:47:14 +0000 (10:47 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 29 Jan 2015 10:47:14 +0000 (10:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227427 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineFormatter.cpp
lib/Format/WhitespaceManager.cpp
unittests/Format/FormatTest.cpp

index 6c4aadc0f1c355f76c974162ab30b4bbef3b2e65..4844b66f9fdaa2a43130043b45ac2ee19e544941 100644 (file)
@@ -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
index bf1207e59c9020b6ea5961ebfde9602d9f72a854..44e5f690a2630aa13d6f29c89aca2d23cbf3477f 100644 (file)
@@ -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)
index 65a7bff599ae1f1debfb67c85deccae360438ade..f099f20a6e582cd9092ab0ecb4e6700b1b10fb67 100644 (file)
@@ -3081,6 +3081,8 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
                "  if (aaaaaaaaaaaaaaaaaaaaaaaa) return;\n"
                "}, a);",
                Style);
+
+  verifyNoCrash("^{v^{a}}");
 }
 
 TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) {