anastasiia_lukianenko updated this revision to Diff 307804.
anastasiia_lukianenko added a comment.

1. Diff was made by git diff with full context
2. Added description in documentation
3. Added unit test


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91950/new/

https://reviews.llvm.org/D91950

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5046,6 +5046,20 @@
             format(Input, Style));
 }
 
+TEST_F(FormatTest, BreakBeforeInlineASMColon) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 80;
+  Style.BreakBeforeInlineASMColon = false;
+  verifyFormat("asm volatile(\"loooooooooooooooooooooooooooooooooooooooooooooong\",\n"
+               ": : val);",
+               Style);
+  Style.BreakBeforeInlineASMColon = true;
+  verifyFormat("asm volatile(\"loooooooooooooooooooooooooooooooooooooooooooooong\",\n"
+               ":"
+               ": val);",
+               Style);
+}
+
 TEST_F(FormatTest, BreakBeforeStructInitialization) {
   FormatStyle Style = getLLVMStyle();
   Style.ColumnLimit = 80;
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -513,6 +513,9 @@
         Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon)
       Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
 
+    IO.mapOptional("BreakBeforeInlineASMColon",
+                   Style.BreakBeforeInlineASMColon);
+
     IO.mapOptional("BreakBeforeStructInitialization",
                    Style.BreakBeforeStructInitialization);
 
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -334,7 +334,7 @@
     auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
     return (LambdaBodyLength > getColumnLimit(State));
   }
-  if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
+  if (Current.MustBreakBefore || (Current.is(TT_InlineASMColon) && Style.BreakBeforeInlineASMColon))
     return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
       Current.closesBlockOrBlockTypeList(Style))
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1160,6 +1160,19 @@
   /// \endcode
   BraceWrappingFlags BraceWrapping;
 
+  /// If ``true``, colons in ASM parameters will be placed after line breaks.
+  /// \code
+  ///    true:
+  ///    asm volatile("loooooooooooooooooooooooooooooooooooooooooooooong",
+  ///                 :
+  ///                 : val);
+  ///
+  ///    false:
+  ///    asm volatile("loooooooooooooooooooooooooooooooooooooooooooooong",
+  ///                 : : val);
+  /// \endcode
+  bool BreakBeforeInlineASMColon;
+
   /// If ``true``, struct left brace will be placed after line breaks.
   /// \code
   ///    true:
@@ -2448,6 +2461,7 @@
            BinPackParameters == R.BinPackParameters &&
            BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
            BreakBeforeBraces == R.BreakBeforeBraces &&
+           BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
            BreakBeforeStructInitialization == R.BreakBeforeStructInitialization &&
            BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
            BreakConstructorInitializers == R.BreakConstructorInitializers &&
Index: clang/docs/ClangFormatStyleOptions.rst
===================================================================
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1382,6 +1382,20 @@
 
 
 
+**BreakBeforeInlineASMColon** (``bool``)
+  If ``true``, colons in ASM parameters will be placed after line breaks.
+
+  .. code-block:: c++
+
+     true:
+     asm volatile("loooooooooooooooooooooooooooooooooooooooooooooong",
+                  :
+                  : val);
+
+     false:
+     asm volatile("loooooooooooooooooooooooooooooooooooooooooooooong",
+                  : : val);
+
 **BreakBeforeStructInitialization** (``bool``)
   If ``true``, struct left brace will be placed after line breaks.
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to