summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-06-04 19:27:02 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-06-04 19:27:02 +0000
commit59ed77b813a58e6f81fca3896f61e967a4f5f495 (patch)
tree1170a895ab3c1139df1583750efae54dd1ee8711 /clang/lib/Format/WhitespaceManager.cpp
parentc4bfef50f33b6939d9680da8d1389511dc28a7f4 (diff)
downloadbcm5719-llvm-59ed77b813a58e6f81fca3896f61e967a4f5f495.tar.gz
bcm5719-llvm-59ed77b813a58e6f81fca3896f61e967a4f5f495.zip
[clang-format] Don't align too long broken trailing comments
Summary: This patch fixes a bug where clang-format will align newly broken trailing comments even if this will make them exceed the line limit. The bug was caused by a combination of unsigned arithmetic overflow and an imprecise computation of the length of broken comment lines. Reviewers: djasper, alexfh Reviewed By: alexfh Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33830 llvm-svn: 304687
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 3b6311d1548..c48883351c7 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -111,7 +111,7 @@ void WhitespaceManager::calculateLineBreakInformation() {
// If there are multiple changes in this token, sum up all the changes until
// the end of the line.
- if (Changes[i - 1].IsInsideToken)
+ if (Changes[i - 1].IsInsideToken && Changes[i - 1].NewlinesBefore == 0)
LastOutsideTokenChange->TokenLength +=
Changes[i - 1].TokenLength + Changes[i - 1].Spaces;
else
@@ -434,7 +434,9 @@ void WhitespaceManager::alignTrailingComments() {
continue;
unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
- unsigned ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+ unsigned ChangeMaxColumn = Style.ColumnLimit >= Changes[i].TokenLength
+ ? Style.ColumnLimit - Changes[i].TokenLength
+ : ChangeMinColumn;
// If we don't create a replacement for this change, we have to consider
// it to be immovable.
OpenPOWER on IntegriCloud