[llvm-dev] [PATCH 2/2] [clang-format] Add BreakBeforeInlineASMColon configuration

Anastasiia Lukianenko via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 19 04:40:14 PST 2020


From: Anastasiia Lukianenko <anastasiia_lukianenko at epam.com>

If ``true``, colons in ASM parameters will be placed after line breaks.
true:
asm volatile("loooooooooooooooooooooooooooooooooooooooooooooong",
             :
             : val);
false:
asm volatile("loooooooooooooooooooooooooooooooooooooooooooooong",
             : : val);

Signed-off-by: Anastasiia Lukianenko <anastasiia_lukianenko at epam.com>
---
 clang/include/clang/Format/Format.h       | 14 ++++++++++++++
 clang/lib/Format/ContinuationIndenter.cpp |  2 +-
 clang/lib/Format/Format.cpp               |  3 +++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index a3e04e1ee6f..c3290949b6b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1160,6 +1160,19 @@ struct FormatStyle {
   /// \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 @@ struct FormatStyle {
            BinPackParameters == R.BinPackParameters &&
            BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
            BreakBeforeBraces == R.BreakBeforeBraces &&
+           BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
            BreakBeforeStructInitialization == R.BreakBeforeStructInitialization &&
            BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
            BreakConstructorInitializers == R.BreakConstructorInitializers &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index af6be432b5f..bb5d5475505 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -334,7 +334,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
     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))
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index eb4d64aa919..1ec2110714e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -513,6 +513,9 @@ template <> struct MappingTraits<FormatStyle> {
         Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon)
       Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
 
+    IO.mapOptional("BreakBeforeInlineASMColon",
+                   Style.BreakBeforeInlineASMColon);
+
     IO.mapOptional("BreakBeforeStructInitialization",
                    Style.BreakBeforeStructInitialization);
 
-- 
2.17.1



More information about the llvm-dev mailing list