[llvm-branch-commits] [cfe-branch] r311800 - Merging r311792:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Aug 25 13:30:43 PDT 2017


Author: hans
Date: Fri Aug 25 13:30:43 2017
New Revision: 311800

URL: http://llvm.org/viewvc/llvm-project?rev=311800&view=rev
Log:
Merging r311792:
------------------------------------------------------------------------
r311792 | djasper | 2017-08-25 12:14:53 -0700 (Fri, 25 Aug 2017) | 9 lines

[Format] Invert nestingAndIndentLevel pair in WhitespaceManager used for
alignments

Indent should be compared before nesting level to determine if a token
is on the same scope as the one we align with. Because it was inverted,
clang-format sometimes tried to align tokens with tokens from outer
scopes, causing the assert(Shift >= 0) to fire.

This fixes bug #33507. Patch by Beren Minor, thank you!
------------------------------------------------------------------------

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

Propchange: cfe/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 25 13:30:43 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309263,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,311330,311391,311397,311443,311532,311601,311695
+/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309263,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,311330,311391,311397,311443,311532,311601,311695,311792
 /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=311800&r1=311799&r2=311800&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/branches/release_50/lib/Format/WhitespaceManager.cpp Fri Aug 25 13:30:43 2017
@@ -246,12 +246,12 @@ AlignTokenSequence(unsigned Start, unsig
 
   for (unsigned i = Start; i != End; ++i) {
     if (ScopeStack.size() != 0 &&
-        Changes[i].nestingAndIndentLevel() <
-            Changes[ScopeStack.back()].nestingAndIndentLevel())
+        Changes[i].indentAndNestingLevel() <
+            Changes[ScopeStack.back()].indentAndNestingLevel())
       ScopeStack.pop_back();
 
-    if (i != Start && Changes[i].nestingAndIndentLevel() >
-                          Changes[i - 1].nestingAndIndentLevel())
+    if (i != Start && Changes[i].indentAndNestingLevel() >
+                          Changes[i - 1].indentAndNestingLevel())
       ScopeStack.push_back(i);
 
     bool InsideNestedScope = ScopeStack.size() != 0;
@@ -327,8 +327,8 @@ static unsigned AlignTokens(const Format
 
   // Measure the scope level (i.e. depth of (), [], {}) of the first token, and
   // abort when we hit any token in a higher scope than the starting one.
-  auto NestingAndIndentLevel = StartAt < Changes.size()
-                                   ? Changes[StartAt].nestingAndIndentLevel()
+  auto IndentAndNestingLevel = StartAt < Changes.size()
+                                   ? Changes[StartAt].indentAndNestingLevel()
                                    : std::pair<unsigned, unsigned>(0, 0);
 
   // Keep track of the number of commas before the matching tokens, we will only
@@ -359,7 +359,7 @@ static unsigned AlignTokens(const Format
 
   unsigned i = StartAt;
   for (unsigned e = Changes.size(); i != e; ++i) {
-    if (Changes[i].nestingAndIndentLevel() < NestingAndIndentLevel)
+    if (Changes[i].indentAndNestingLevel() < IndentAndNestingLevel)
       break;
 
     if (Changes[i].NewlinesBefore != 0) {
@@ -375,7 +375,7 @@ static unsigned AlignTokens(const Format
 
     if (Changes[i].Tok->is(tok::comma)) {
       ++CommasBeforeMatch;
-    } else if (Changes[i].nestingAndIndentLevel() > NestingAndIndentLevel) {
+    } else if (Changes[i].indentAndNestingLevel() > IndentAndNestingLevel) {
       // Call AlignTokens recursively, skipping over this scope block.
       unsigned StoppedAt = AlignTokens(Style, Matches, Changes, i);
       i = StoppedAt - 1;

Modified: cfe/branches/release_50/lib/Format/WhitespaceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Format/WhitespaceManager.h?rev=311800&r1=311799&r2=311800&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Format/WhitespaceManager.h (original)
+++ cfe/branches/release_50/lib/Format/WhitespaceManager.h Fri Aug 25 13:30:43 2017
@@ -154,12 +154,11 @@ public:
     const Change *StartOfBlockComment;
     int IndentationOffset;
 
-    // A combination of nesting level and indent level, which are used in
+    // A combination of indent level and nesting level, which are used in
     // tandem to compute lexical scope, for the purposes of deciding
     // when to stop consecutive alignment runs.
-    std::pair<unsigned, unsigned>
-    nestingAndIndentLevel() const {
-      return std::make_pair(Tok->NestingLevel, Tok->IndentLevel);
+    std::pair<unsigned, unsigned> indentAndNestingLevel() const {
+      return std::make_pair(Tok->IndentLevel, Tok->NestingLevel);
     }
   };
 

Modified: cfe/branches/release_50/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/unittests/Format/FormatTest.cpp?rev=311800&r1=311799&r2=311800&view=diff
==============================================================================
--- cfe/branches/release_50/unittests/Format/FormatTest.cpp (original)
+++ cfe/branches/release_50/unittests/Format/FormatTest.cpp Fri Aug 25 13:30:43 2017
@@ -8860,6 +8860,16 @@ TEST_F(FormatTest, AlignConsecutiveDecla
                Alignment);
   Alignment.BinPackParameters = true;
   Alignment.ColumnLimit = 80;
+
+  // Bug 33507
+  Alignment.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat(
+      "auto found = range::find_if(vsProducts, [&](auto * aProduct) {\n"
+      "  static const Version verVs2017;\n"
+      "  return true;\n"
+      "});\n",
+      Alignment);
+  Alignment.PointerAlignment = FormatStyle::PAS_Right;
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {




More information about the llvm-branch-commits mailing list