[llvm-branch-commits] [cfe-branch] r311573 - Merging r311532:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 23 09:49:21 PDT 2017


Author: hans
Date: Wed Aug 23 09:49:21 2017
New Revision: 311573

URL: http://llvm.org/viewvc/llvm-project?rev=311573&view=rev
Log:
Merging r311532:
------------------------------------------------------------------------
r311532 | krasimir | 2017-08-23 00:18:36 -0700 (Wed, 23 Aug 2017) | 24 lines

[clang-format] Align trailing comments if ColumnLimit is 0

Summary:
ColumnLimit = 0 means no limit, so comment should always be aligned if requested. This was broken with

  https://llvm.org/svn/llvm-project/cfe/trunk@304687

introduced via

  https://reviews.llvm.org/D33830

and is included in 5.0.0-rc2. This commit fixes it and adds a unittest for this property.

Should go into clang-5.0 IMHO.

Contributed by @pboettch!

Reviewers: djasper, krasimir

Reviewed By: djasper, krasimir

Subscribers: hans, klimek

Differential Revision: https://reviews.llvm.org/D36967
------------------------------------------------------------------------

Modified:
    cfe/branches/release_50/   (props changed)
    cfe/branches/release_50/lib/Format/WhitespaceManager.cpp
    cfe/branches/release_50/unittests/Format/FormatTestComments.cpp

Propchange: cfe/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 23 09:49:21 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309226,309263,309327,309382-309383,309488,309503,309523,309569,309607,309633,309636,309640,309722,309752,309975,310006,310158,310191,310359,310516,310672,310691-310692,310694,310700,310704,310706,310776,310804,310829,310983,311115,311182,311391,311397,311443
+/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309226,309263,309327,309382-309383,309488,309503,309523,309569,309607,309633,309636,309640,309722,309752,309975,310006,310158,310191,310359,310516,310672,310691-310692,310694,310700,310704,310706,310776,310804,310829,310983,311115,311182,311391,311397,311443,311532
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_50/lib/Format/WhitespaceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Format/WhitespaceManager.cpp?rev=311573&r1=311572&r2=311573&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/branches/release_50/lib/Format/WhitespaceManager.cpp Wed Aug 23 09:49:21 2017
@@ -472,9 +472,14 @@ void WhitespaceManager::alignTrailingCom
       continue;
 
     unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
-    unsigned ChangeMaxColumn = Style.ColumnLimit >= Changes[i].TokenLength
-                                   ? Style.ColumnLimit - Changes[i].TokenLength
-                                   : ChangeMinColumn;
+    unsigned ChangeMaxColumn;
+
+    if (Style.ColumnLimit == 0)
+      ChangeMaxColumn = UINT_MAX;
+    else if (Style.ColumnLimit >= Changes[i].TokenLength)
+      ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+    else
+      ChangeMaxColumn = ChangeMinColumn;
 
     // If we don't create a replacement for this change, we have to consider
     // it to be immovable.

Modified: cfe/branches/release_50/unittests/Format/FormatTestComments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/unittests/Format/FormatTestComments.cpp?rev=311573&r1=311572&r2=311573&view=diff
==============================================================================
--- cfe/branches/release_50/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/branches/release_50/unittests/Format/FormatTestComments.cpp Wed Aug 23 09:49:21 2017
@@ -2267,6 +2267,13 @@ TEST_F(FormatTestComments, AlignTrailing
                    "int k; // line longg long",
                    getLLVMStyleWithColumns(20)));
 
+  // Always align if ColumnLimit = 0
+  EXPECT_EQ("int i, j; // line 1\n"
+            "int k;    // line longg long",
+            format("int i, j; // line 1\n"
+                   "int k; // line longg long",
+                   getLLVMStyleWithColumns(0)));
+
   // Align comment line sections aligned with the next token with the next
   // token.
   EXPECT_EQ("class A {\n"




More information about the llvm-branch-commits mailing list