[cfe-commits] r172426 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Mon Jan 14 08:02:06 PST 2013


Author: djasper
Date: Mon Jan 14 10:02:06 2013
New Revision: 172426

URL: http://llvm.org/viewvc/llvm-project?rev=172426&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172426&r1=172425&r2=172426&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jan 14 10:02:06 2013
@@ -1408,6 +1408,8 @@
     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;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172426&r1=172425&r2=172426&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 14 10:02:06 2013
@@ -138,6 +138,8 @@
                "  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) {





More information about the cfe-commits mailing list