diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-08-23 15:16:47 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-08-23 15:16:47 +0000 |
commit | 7f7c3dc0aa3f8bbca09949d1860120aade2f5b31 (patch) | |
tree | bbcf2ba240d61830b8a098030a12357d1121cc55 /clang/lib/Format/BreakableToken.cpp | |
parent | 9f11c0bddfb04bb6697db065a48771dc3af03878 (diff) | |
download | bcm5719-llvm-7f7c3dc0aa3f8bbca09949d1860120aade2f5b31.tar.gz bcm5719-llvm-7f7c3dc0aa3f8bbca09949d1860120aade2f5b31.zip |
[clang-format] Emit absolute splits before lines for comments
Summary:
This patch makes the splits emitted for the beginning of comment lines during
reformatting absolute. Previously, they were relative to the start of the
non-whitespace content of the line, which messes up further TailOffset
calculations in breakProtrudingToken. This fixes an assertion failure reported
in bug 34236: https://bugs.llvm.org/show_bug.cgi?id=34236.
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D36956
llvm-svn: 311559
Diffstat (limited to 'clang/lib/Format/BreakableToken.cpp')
-rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index 20e3e5b1dfd..b9e48e63019 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -545,15 +545,18 @@ 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); - 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 @@ 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, BreakSplit, Whitespaces); - } + if (ReflownColumn > ColumnLimit) + insertBreak(LineIndex, 0, SplitBefore, Whitespaces); return; } |