aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-08-28 09:07:32 +0000
committerDaniel Jasper <djasper@google.com>2013-08-28 09:07:32 +0000
commita49393f54de2f9944972c7b52789ab4ac120353e (patch)
treea7c0d57e59b6b98435e67168d9b20ac8042e117c /clang/lib/Format/WhitespaceManager.cpp
parentbe133a8757103c430a36f15d6210f99a0206921f (diff)
downloadllvm-a49393f54de2f9944972c7b52789ab4ac120353e.zip
llvm-a49393f54de2f9944972c7b52789ab4ac120353e.tar.gz
llvm-a49393f54de2f9944972c7b52789ab4ac120353e.tar.bz2
clang-format: Fix infinite loop in macro special case.
If escaped newlines are aligned right (FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained too many characters to fit into the column limit, this would result in a (virtually) endless loop creating a negative number of spaces. Instead, allow the escaped newlines to be pushed past the column limit in this case. This fixes llvm.org/PR16515. llvm-svn: 189459
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 94aca02..41519b6 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -185,19 +185,17 @@ void WhitespaceManager::alignTrailingComments(unsigned Start, unsigned End,
}
void WhitespaceManager::alignEscapedNewlines() {
- unsigned MaxEndOfLine = 0;
+ unsigned MaxEndOfLine =
+ Style.AlignEscapedNewlinesLeft ? 0 : Style.ColumnLimit;
unsigned StartOfMacro = 0;
for (unsigned i = 1, e = Changes.size(); i < e; ++i) {
Change &C = Changes[i];
if (C.NewlinesBefore > 0) {
if (C.ContinuesPPDirective) {
- if (Style.AlignEscapedNewlinesLeft)
- MaxEndOfLine = std::max(C.PreviousEndOfTokenColumn + 2, MaxEndOfLine);
- else
- MaxEndOfLine = Style.ColumnLimit;
+ MaxEndOfLine = std::max(C.PreviousEndOfTokenColumn + 2, MaxEndOfLine);
} else {
alignEscapedNewlines(StartOfMacro + 1, i, MaxEndOfLine);
- MaxEndOfLine = 0;
+ MaxEndOfLine = Style.AlignEscapedNewlinesLeft ? 0 : Style.ColumnLimit;
StartOfMacro = i;
}
}