Index: lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- lib/Format/UnwrappedLineFormatter.cpp	(revision 311154)
+++ lib/Format/UnwrappedLineFormatter.cpp	(working copy)
@@ -283,6 +283,21 @@
         TheLine->First != TheLine->Last) {
       return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
     }
+    if (TheLine->Last->is(tok::l_brace) &&
+        TheLine->First != TheLine->Last &&
+        TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { 
+      return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I, E, Limit) : 0;
+    }
+    if (I[1]->First->is(tok::l_brace) && 
+        TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { 
+      return Style.BraceWrapping.AfterControlStatement ? tryMergeSimpleBlock(I, E, Limit) : 0;
+    }
+    if (TheLine->First->is(tok::l_brace) &&
+       (TheLine->First == TheLine->Last) &&
+       (I != AnnotatedLines.begin()) &&
+       (I[-1]->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for))) { 
+      return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I-1, E, Limit) : 0;
+    }
     if (TheLine->Last->is(tok::l_brace)) {
       return !Style.BraceWrapping.AfterFunction
                  ? tryMergeSimpleBlock(I, E, Limit)
@@ -460,6 +475,7 @@
         return 0;
     }
 
+    if (Line.Last->is(tok::l_brace)) {
     FormatToken *Tok = I[1]->First;
     if (Tok->is(tok::r_brace) && !Tok->MustBreakBefore &&
         (Tok->getNextNonComment() == nullptr ||
@@ -507,8 +523,28 @@
 
       return 2;
     }
+    } else if (I[1]->First->is(tok::l_brace)) {
+      if (I[1]->Last->is(TT_LineComment))
     return 0;
+
+      // Check for Limit <= 2 to account for the " {".
+      if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(*I)))
+        return 0;
+      Limit -= 2;
+      unsigned MergedLines = 0;
+      if ((Style.AllowShortBlocksOnASingleLine ||
+          (I[1]->First == I[1]->Last && I + 2 != E &&
+          I[2]->First->is(tok::r_brace)))) {
+      MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);
+      // If we managed to merge the block, count the statement header, which is
+      // on a separate line.
+      if (MergedLines > 0)
+        ++MergedLines;
   }
+      return MergedLines;
+    }
+    return 0;
+  }
 
   /// Returns the modified column limit for \p I if it is inside a macro and
   /// needs a trailing '\'.
