[clang] 7a38b3b - [clang-format] Respect ColumnLimit 0 line breaks in inline asm

Emilia Kond via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 23 07:35:11 PDT 2023


Author: Emilia Kond
Date: 2023-06-23T17:30:24+03:00
New Revision: 7a38b3bfeb5623fb970a03ed9f295288802f4506

URL: https://github.com/llvm/llvm-project/commit/7a38b3bfeb5623fb970a03ed9f295288802f4506
DIFF: https://github.com/llvm/llvm-project/commit/7a38b3bfeb5623fb970a03ed9f295288802f4506.diff

LOG: [clang-format] Respect ColumnLimit 0 line breaks in inline asm

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

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index f6f6bf61f1c37..13b853ea9e226 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -357,7 +357,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   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 &&

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 6b0540400d7b7..7c0645c7cf01b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4612,6 +4612,24 @@ TEST_F(FormatTest, FormatsInlineASM) {
             format("__asm   {\n"
                    "}\n"
                    "int   i;"));
+
+  auto Style = getLLVMStyleWithColumns(0);
+  const StringRef Code1{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"};
+  const StringRef Code2{"asm(\"xyz\"\n"
+                        "    : \"=a\"(a), \"=d\"(b)\n"
+                        "    : \"a\"(data));"};
+  const StringRef Code3{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+                        "    : \"a\"(data));"};
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
+  verifyFormat(Code1, Style);
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code3, format(Code3, Style));
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  EXPECT_EQ(Code2, format(Code1, Style));
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code2, format(Code3, Style));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {


        


More information about the cfe-commits mailing list