[PATCH] D36956: [clang-format] Emit absolute splits before lines for comments
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 08:19:49 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311559: [clang-format] Emit absolute splits before lines for comments (authored by krasimir).
Changed prior to commit:
https://reviews.llvm.org/D36956?vs=112147&id=112372#toc
Repository:
rL LLVM
https://reviews.llvm.org/D36956
Files:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -545,15 +545,18 @@
}
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);
- return getReflowSplit(TrimmedContent, ReflowPrefix, PreviousEndColumn,
- ColumnLimit);
+ 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;
}
unsigned BreakableBlockComment::getReflownColumn(
@@ -633,17 +636,12 @@
/*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, BreakSplit, Whitespaces);
- }
+ if (ReflownColumn > ColumnLimit)
+ insertBreak(LineIndex, 0, SplitBefore, Whitespaces);
return;
}
Index: cfe/trunk/unittests/Format/FormatTestComments.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestComments.cpp
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp
@@ -2803,6 +2803,23 @@
" 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36956.112372.patch
Type: text/x-patch
Size: 3111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170823/0c323f63/attachment.bin>
More information about the cfe-commits
mailing list