[clang-format] Separate line comment sections after a right brace from comment sections in the scope.

Summary:
The following two comment lines form a single comment section:
```
if (1) { // line 1
   // line 2
}
```
This is because the break of a comment section was based on the original column
of the first token of the previous line (in this case, the 'if').
This patch splits these two comment lines into different sections by taking into
account the original column of the right brace preceding the first line comment
where applicable.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D29291

llvm-svn: 293539
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2be5062..d282001 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,64 @@
                "    0x00, 0x00, 0x00, 0x00};            // comment\n");
 }
 
+TEST_F(FormatTest, LineCommentsAfterRightBrace) {
+  EXPECT_EQ("if (true) { // comment about branch\n"
+            "  // comment about f\n"
+            "  f();\n"
+            "}",
+            format("if (true) { // comment about branch\n"
+                   "  // comment about f\n"
+                   "  f();\n"
+                   "}",
+                   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("if (1) { // if line 1\n"
+            "         // if line 2\n"
+            "         // if line 3\n"
+            "  // f line 1\n"
+            "  // f line 2\n"
+            "  f();\n"
+            "} else { // else line 1\n"
+            "         // else line 2\n"
+            "         // else line 3\n"
+            "  // g line 1\n"
+            "  g();\n"
+            "}",
+            format("if (1) { // if line 1\n"
+                   "          // if line 2\n"
+                   "        // if line 3\n"
+                   "  // f line 1\n"
+                   "    // f line 2\n"
+                   "  f();\n"
+                   "} else { // else line 1\n"
+                   "        // else line 2\n"
+                   "         // else line 3\n"
+                   "  // g line 1\n"
+                   "  g();\n"
+                   "}"));
+  EXPECT_EQ("do { // line 1\n"
+            "     // line 2\n"
+            "     // line 3\n"
+            "  f();\n"
+            "} while (true);",
+            format("do { // line 1\n"
+                   "     // line 2\n"
+                   "   // line 3\n"
+                   "  f();\n"
+                   "} while (true);",
+                   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("while (a < b) { // line 1\n"
+            "  // line 2\n"
+            "  // line 3\n"
+            "  f();\n"
+            "}",
+            format("while (a < b) {// line 1\n"
+                   "  // line 2\n"
+                   "  // line 3\n"
+                   "  f();\n"
+                   "}",
+                   getLLVMStyleWithColumns(80)));
+}
+
 TEST_F(FormatTest, ReflowsComments) {
   // Break a long line and reflow with the full next line.
   EXPECT_EQ("// long long long\n"