[PATCH] D150848: [clang-format] Respect ColumnLimit 0 lines breaks in inline asm

Emilia Kond via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 18 00:29:43 PDT 2023


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 &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150848.523285.patch
Type: text/x-patch
Size: 2444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230518/13ef9078/attachment.bin>


More information about the cfe-commits mailing list