rymiel created this revision.
rymiel added a project: clang-format.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
rymiel requested review of this revision.

Previously, using ColumnLimit: 0 with extended inline asm with the
BreakBeforeInlineASMColon: OnlyMultiline option (the default style),
the formatter would act as if in Always mode, meaning a line break was
added before every colon in an extended inline assembly block.

This patch respects the already existing line breaks, and doesn't add
any new ones, if in ColumnLimit 0 mode.

Behaviour with Always stays as expected, with a break before every colon
regardless of any existing line breaks.

Behaviour with Never was broken before, and remains broken with this patch,
it is just never respected in ColumnLimit 0 mode.

Fixes https://github.com/llvm/llvm-project/issues/62754


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150848

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4617,6 +4617,42 @@
             format("__asm   {\n"
                    "}\n"
                    "int   i;"));
+
+  auto Style = getLLVMStyleWithColumns(0);
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
+  verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));", Style);
+  EXPECT_EQ("asm(\"xyz\"\n"
+            "    : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\"\n"
+                   "    : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
+  EXPECT_EQ("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  EXPECT_EQ(
+      "asm(\"xyz\"\n"
+      "    : \"=a\"(a), \"=d\"(b)\n"
+      "    : \"a\"(data));",
+      format("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));", Style));
+  EXPECT_EQ("asm(\"xyz\"\n"
+            "    : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\"\n"
+                   "    : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
+  EXPECT_EQ("asm(\"xyz\"\n"
+            "    : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -357,7 +357,8 @@
   if (Current.MustBreakBefore ||
       (Current.is(TT_InlineASMColon) &&
        (Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
-        Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline))) 
{
+        (Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline &&
+         Style.ColumnLimit != 0)))) {
     return true;
   }
   if (CurrentState.BreakBeforeClosingBrace &&


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4617,6 +4617,42 @@
             format("__asm   {\n"
                    "}\n"
                    "int   i;"));
+
+  auto Style = getLLVMStyleWithColumns(0);
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
+  verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));", Style);
+  EXPECT_EQ("asm(\"xyz\"\n"
+            "    : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\"\n"
+                   "    : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
+  EXPECT_EQ("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  EXPECT_EQ(
+      "asm(\"xyz\"\n"
+      "    : \"=a\"(a), \"=d\"(b)\n"
+      "    : \"a\"(data));",
+      format("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));", Style));
+  EXPECT_EQ("asm(\"xyz\"\n"
+            "    : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\"\n"
+                   "    : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
+  EXPECT_EQ("asm(\"xyz\"\n"
+            "    : \"=a\"(a), \"=d\"(b)\n"
+            "    : \"a\"(data));",
+            format("asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+                   "    : \"a\"(data));",
+                   Style));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -357,7 +357,8 @@
   if (Current.MustBreakBefore ||
       (Current.is(TT_InlineASMColon) &&
        (Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
-        Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline))) {
+        (Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline &&
+         Style.ColumnLimit != 0)))) {
     return true;
   }
   if (CurrentState.BreakBeforeClosingBrace &&
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D150848: [clang-format... Emilia Kond via Phabricator via cfe-commits

Reply via email to