summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-14 16:02:06 +0000
committerDaniel Jasper <djasper@google.com>2013-01-14 16:02:06 +0000
commit3e9218e50a96784dd014f202290e9569f7584b97 (patch)
tree63c15116269a5d7d7f2e1e18ee523a198dafbac3
parent2ab0d01a8e2c7002478fa49f8aca4b32cc72b432 (diff)
downloadbcm5719-llvm-3e9218e50a96784dd014f202290e9569f7584b97.tar.gz
bcm5719-llvm-3e9218e50a96784dd014f202290e9569f7584b97.zip
Fix a bug in the line merging.
If the first line of a merge would exactly fit into the column limit, an unsigned overflow made us not break. llvm-svn: 172426
-rw-r--r--clang/lib/Format/Format.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp2
2 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 742b9a8d1cc..4e9fd405df3 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1408,6 +1408,8 @@ private:
unsigned Length = 0;
if (!fitsIntoLimit(I->First, Limit, &Length))
return false;
+ if (Limit == Length)
+ return true; // Couldn't fit a space.
Limit -= Length + 1; // One space.
if (I + 1 == E)
return true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index daebc4ddab1..8e55ddb5d0f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -138,6 +138,8 @@ TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
" f();");
verifyFormat("if (a) return;", getLLVMStyleWithColumns(14));
verifyFormat("if (a)\n return;", getLLVMStyleWithColumns(13));
+ verifyFormat("if (aaaaaaaaa)\n"
+ " return;", getLLVMStyleWithColumns(14));
}
TEST_F(FormatTest, ParseIfElse) {
OpenPOWER on IntegriCloud