]> granicus.if.org Git - clang/commitdiff
Revert "[clang-format] Emit absolute splits before lines for comments"
authorKrasimir Georgiev <krasimir@google.com>
Wed, 23 Aug 2017 15:58:10 +0000 (15:58 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Wed, 23 Aug 2017 15:58:10 +0000 (15:58 +0000)
This reverts commit r311559, which added a test containing raw string
literals in macros, which chokes gcc:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311566 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/BreakableToken.cpp
unittests/Format/FormatTestComments.cpp

index b9e48e63019c1e42e1240394623f62fe41e67f23..20e3e5b1dfd665abb79af9e7ba3276ec0f1b971d 100644 (file)
@@ -545,18 +545,15 @@ void BreakableBlockComment::insertBreak(unsigned LineIndex, unsigned TailOffset,
 }
 
 BreakableToken::Split BreakableBlockComment::getSplitBefore(
-    unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit,
+    unsigned LineIndex,
+    unsigned PreviousEndColumn,
+    unsigned ColumnLimit,
     llvm::Regex &CommentPragmasRegex) const {
   if (!mayReflow(LineIndex, CommentPragmasRegex))
     return Split(StringRef::npos, 0);
   StringRef TrimmedContent = Content[LineIndex].ltrim(Blanks);
-  Split Result = getReflowSplit(TrimmedContent, ReflowPrefix, PreviousEndColumn,
-                                ColumnLimit);
-  // Result is relative to TrimmedContent. Adapt it relative to
-  // Content[LineIndex].
-  if (Result.first != StringRef::npos)
-    Result.first += Content[LineIndex].size() - TrimmedContent.size();
-  return Result;
+  return getReflowSplit(TrimmedContent, ReflowPrefix, PreviousEndColumn,
+                        ColumnLimit);
 }
 
 unsigned BreakableBlockComment::getReflownColumn(
@@ -636,12 +633,17 @@ void BreakableBlockComment::replaceWhitespaceBefore(
         /*CurrentPrefix=*/ReflowPrefix, InPPDirective, /*Newlines=*/0,
         /*Spaces=*/0);
     // Check if we need to also insert a break at the whitespace range.
+    // For this we first adapt the reflow split relative to the beginning of the
+    // content.
     // Note that we don't need a penalty for this break, since it doesn't change
     // the total number of lines.
+    Split BreakSplit = SplitBefore;
+    BreakSplit.first += TrimmedContent.data() - Content[LineIndex].data();
     unsigned ReflownColumn =
         getReflownColumn(TrimmedContent, LineIndex, PreviousEndColumn);
-    if (ReflownColumn > ColumnLimit)
-      insertBreak(LineIndex, 0, SplitBefore, Whitespaces);
+    if (ReflownColumn > ColumnLimit) {
+      insertBreak(LineIndex, 0, BreakSplit, Whitespaces);
+    }
     return;
   }
 
index 70fa965adee6b19a4a19ed93a3a910ff0245769b..79dc003ae85518968c9f14cd98d661c90a9a133a 100644 (file)
@@ -2803,23 +2803,6 @@ TEST_F(FormatTestComments, NonTrailingBlockComments) {
                    "    A = B;",
                    getLLVMStyleWithColumns(40)));
 }
-
-TEST_F(FormatTestComments, NoCrush_Bug34236) {
-  // This is a test case from a crasher reported in:
-  // https://bugs.llvm.org/show_bug.cgi?id=34236
-  EXPECT_EQ(
-      R"(
-/*                                                                */ /*
-                                                                      *       a
-                                                                      * b c
-                                                                      * d*/)",
-      format(
-          R"(
-/*                                                                */ /*
- *       a b
- *       c     d*/)",
-          getLLVMStyleWithColumns(80)));
-}
 } // end namespace
 } // end namespace format
 } // end namespace clang