[clang] [clang-format] Add SpacesInParensOption for attributes and filtering for repeated parens (PR #77522)

Gedare Bloom via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 21:12:26 PST 2024


https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/77522

>From f068aca0a48b1bafb7d611c8b6c803793fc22707 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Mon, 17 Jul 2023 18:24:30 -0600
Subject: [PATCH 01/16] Add SpaceInParensOption for __attribute__ keyword

The __attribute((specifier-list)) currently is formatted based on the
SpacesInParensOptions.Other (previously, SpacesInParentheses). This change
allows finer control over addition of spaces between the consecutive parens,
and between the inner parens and the list of attribute specifiers.

Differential Revision: https://reviews.llvm.org/D155529
---
 clang/docs/ClangFormatStyleOptions.rst     |  7 +++++++
 clang/docs/ReleaseNotes.rst                |  2 ++
 clang/include/clang/Format/Format.h        | 19 ++++++++++++++-----
 clang/lib/Format/Format.cpp                |  2 ++
 clang/lib/Format/TokenAnnotator.cpp        | 16 ++++++++++++----
 clang/unittests/Format/ConfigParseTest.cpp | 13 +++++++++----
 clang/unittests/Format/FormatTest.cpp      |  7 +++++++
 7 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f2650..f48b77caeeb1e8d 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5703,6 +5703,13 @@ the configuration (without a prefix: ``Auto``).
       InConditionalStatements: true
       Other: true
 
+  * ``bool InAttributeSpecifiers`` Put a space in parentheses of attribute specifiers.
+
+    .. code-block:: c++
+
+       true:                                  false:
+       __attribute__( ( noreturn ) )    vs.     __attribute__((noreturn))
+
   * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements
     (``for/if/while/switch...``).
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0b37b5fc2926081..38346d95143a732 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1282,6 +1282,8 @@ clang-format
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for ``AlignConsecutiveDeclarations``.
 - Add ``SkipMacroDefinitionBody`` option.
+- Add ``InAttributeSpecifiers`` style option to ``SpacesInParensOptions``
+  to control addition of spaces after the ``__attribute__`` keyword.
 
 libclang
 --------
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebfd..3f2ae4c4cfac07e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4542,6 +4542,12 @@ struct FormatStyle {
   ///     Other: true
   /// \endcode
   struct SpacesInParensCustom {
+    /// Put a space in parentheses of attribute specifiers.
+    /// \code
+    ///    true:                                  false:
+    ///    __attribute__( ( noreturn ) )    vs.     __attribute__((noreturn))
+    /// \endcode
+    bool InAttributeSpecifiers;
     /// Put a space in parentheses only inside conditional statements
     /// (``for/if/while/switch...``).
     /// \code
@@ -4575,17 +4581,20 @@ struct FormatStyle {
     bool Other;
 
     SpacesInParensCustom()
-        : InConditionalStatements(false), InCStyleCasts(false),
-          InEmptyParentheses(false), Other(false) {}
+        : InAttributeSpecifiers(false), InConditionalStatements(false),
+          InCStyleCasts(false), InEmptyParentheses(false), Other(false) {}
 
-    SpacesInParensCustom(bool InConditionalStatements, bool InCStyleCasts,
+    SpacesInParensCustom(bool InAttributeSpecifiers,
+                         bool InConditionalStatements, bool InCStyleCasts,
                          bool InEmptyParentheses, bool Other)
-        : InConditionalStatements(InConditionalStatements),
+        : InAttributeSpecifiers(InAttributeSpecifiers),
+          InConditionalStatements(InConditionalStatements),
           InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses),
           Other(Other) {}
 
     bool operator==(const SpacesInParensCustom &R) const {
-      return InConditionalStatements == R.InConditionalStatements &&
+      return InAttributeSpecifiers == R.InAttributeSpecifiers &&
+             InConditionalStatements == R.InConditionalStatements &&
              InCStyleCasts == R.InCStyleCasts &&
              InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
     }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b2..d52def573ac0153 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -752,6 +752,7 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
 
 template <> struct MappingTraits<FormatStyle::SpacesInParensCustom> {
   static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
+    IO.mapOptional("InAttributeSpecifiers", Spaces.InAttributeSpecifiers);
     IO.mapOptional("InCStyleCasts", Spaces.InCStyleCasts);
     IO.mapOptional("InConditionalStatements", Spaces.InConditionalStatements);
     IO.mapOptional("InEmptyParentheses", Spaces.InEmptyParentheses);
@@ -1193,6 +1194,7 @@ template <> struct MappingTraits<FormatStyle> {
       if (SpacesInParentheses) {
         // set all options except InCStyleCasts and InEmptyParentheses
         // to true for backward compatibility.
+        Style.SpacesInParensOptions.InAttributeSpecifiers = true;
         Style.SpacesInParensOptions.InConditionalStatements = true;
         Style.SpacesInParensOptions.InCStyleCasts =
             SpacesInCStyleCastParentheses;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 25fcceb87864379..7070257a15b7278 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4006,10 +4006,18 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   }
 
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren)) {
-    return (Right.is(TT_CastRParen) ||
-            (Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen)))
-               ? Style.SpacesInParensOptions.InCStyleCasts
-               : Style.SpacesInParensOptions.Other;
+    if (Right.is(TT_CastRParen) ||
+        (Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen))) {
+      return Style.SpacesInParensOptions.InCStyleCasts;
+    }
+    const auto isAttributeParen = [](const FormatToken *Paren) {
+      return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
+    };
+    if (isAttributeParen(&Left) || isAttributeParen(&Right) ||
+        isAttributeParen(Left.Previous) || isAttributeParen(Right.Next)) {
+      return Style.SpacesInParensOptions.InAttributeSpecifiers;
+    }
+    return Style.SpacesInParensOptions.Other;
   }
   if (Right.isOneOf(tok::semi, tok::comma))
     return false;
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 2a8d79359a49b40..e02eb76464fe9c1 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -232,6 +232,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InAttributeSpecifiers);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
@@ -635,19 +636,23 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(true, false, false, true));
+              FormatStyle::SpacesInParensCustom(true, true, false, false,
+                  true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(true, false, false, false));
+              FormatStyle::SpacesInParensCustom(false, true, false, false,
+                  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(false, true, false, false));
+              FormatStyle::SpacesInParensCustom(false, false, true, false,
+                  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(false, false, true, false));
+              FormatStyle::SpacesInParensCustom(false, false, false, true,
+                  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index a0825dc2ad4ef1a..98a8521b9f3447d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16833,6 +16833,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16907,6 +16908,12 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
+  verifyFormat("void f( ) __attribute__( ( asdf ) );", Spaces);
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = false;
+
   // Run the first set of tests again with:
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("call(x, y, z);", Spaces);

>From e06490683c5e6898b98182aa92782a6693167e0f Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Tue, 9 Jan 2024 15:11:05 -0700
Subject: [PATCH 02/16] Create suboption for spaces in parens custom for
 non-consecutive parens

---
 clang/include/clang/Format/Format.h        | 29 ++++++++++++++++----
 clang/lib/Format/Format.cpp                | 10 ++++++-
 clang/lib/Format/TokenAnnotator.cpp        |  8 +++---
 clang/unittests/Format/ConfigParseTest.cpp | 31 +++++++++++++++-------
 clang/unittests/Format/FormatTest.cpp      | 13 ++++++---
 5 files changed, 69 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 3f2ae4c4cfac07e..7d048adfad106a0 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4533,6 +4533,16 @@ struct FormatStyle {
   /// \version 17
   SpacesInParensStyle SpacesInParens;
 
+  /// Selective control over spaces in parens.
+  enum SpacesInParensCustomStyle : int8_t {
+    /// Never put spaces in parens.
+    SIPCS_Never,
+    /// Only put spaces in parens not followed by the same consecutive parens.
+    SIPCS_NonConsecutive,
+    /// Always put spaces in parens.
+    SIPCS_Always
+  };
+
   /// Precise control over the spacing in parentheses.
   /// \code
   ///   # Should be declared this way:
@@ -4544,10 +4554,18 @@ struct FormatStyle {
   struct SpacesInParensCustom {
     /// Put a space in parentheses of attribute specifiers.
     /// \code
-    ///    true:                                  false:
-    ///    __attribute__( ( noreturn ) )    vs.     __attribute__((noreturn))
+    ///    Always:
+    ///    __attribute__( ( noreturn ) )
+    /// \endcode
+    /// \code
+    ///   NonConsecutive:
+    ///   _attribute__(( noreturn ))
+    /// \endcode
+    /// \code
+    ///   Never:
+    ///   _attribute__((noreturn))
     /// \endcode
-    bool InAttributeSpecifiers;
+    SpacesInParensCustomStyle InAttributeSpecifiers;
     /// Put a space in parentheses only inside conditional statements
     /// (``for/if/while/switch...``).
     /// \code
@@ -4581,10 +4599,10 @@ struct FormatStyle {
     bool Other;
 
     SpacesInParensCustom()
-        : InAttributeSpecifiers(false), InConditionalStatements(false),
+        : InAttributeSpecifiers(SIPCS_Never), InConditionalStatements(false),
           InCStyleCasts(false), InEmptyParentheses(false), Other(false) {}
 
-    SpacesInParensCustom(bool InAttributeSpecifiers,
+    SpacesInParensCustom(SpacesInParensCustomStyle InAttributeSpecifiers,
                          bool InConditionalStatements, bool InCStyleCasts,
                          bool InEmptyParentheses, bool Other)
         : InAttributeSpecifiers(InAttributeSpecifiers),
@@ -4612,6 +4630,7 @@ struct FormatStyle {
   ///   # Example of usage:
   ///   SpacesInParens: Custom
   ///   SpacesInParensOptions:
+  ///     InAttributeSpecifiers: NonConsecutive
   ///     InConditionalStatements: true
   ///     InEmptyParentheses: true
   /// \endcode
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d52def573ac0153..99bd4a962caf5cd 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -750,6 +750,14 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
   }
 };
 
+template <> struct ScalarEnumerationTraits<FormatStyle::SpacesInParensCustomStyle> {
+  static void enumeration(IO &IO, FormatStyle::SpacesInParensCustomStyle &Value) {
+    IO.enumCase(Value, "Never", FormatStyle::SIPCS_Never);
+    IO.enumCase(Value, "NonConsecutive", FormatStyle::SIPCS_NonConsecutive);
+    IO.enumCase(Value, "Always", FormatStyle::SIPCS_Always);
+  }
+};
+
 template <> struct MappingTraits<FormatStyle::SpacesInParensCustom> {
   static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
     IO.mapOptional("InAttributeSpecifiers", Spaces.InAttributeSpecifiers);
@@ -1194,7 +1202,7 @@ template <> struct MappingTraits<FormatStyle> {
       if (SpacesInParentheses) {
         // set all options except InCStyleCasts and InEmptyParentheses
         // to true for backward compatibility.
-        Style.SpacesInParensOptions.InAttributeSpecifiers = true;
+        Style.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Always;
         Style.SpacesInParensOptions.InConditionalStatements = true;
         Style.SpacesInParensOptions.InCStyleCasts =
             SpacesInCStyleCastParentheses;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 7070257a15b7278..5dc12b52056dc43 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4013,10 +4013,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     const auto isAttributeParen = [](const FormatToken *Paren) {
       return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
     };
-    if (isAttributeParen(&Left) || isAttributeParen(&Right) ||
-        isAttributeParen(Left.Previous) || isAttributeParen(Right.Next)) {
-      return Style.SpacesInParensOptions.InAttributeSpecifiers;
-    }
+    if (isAttributeParen(&Left) || isAttributeParen(&Right))
+      return Style.SpacesInParensOptions.InAttributeSpecifiers == FormatStyle::SIPCS_Always;
+    if (isAttributeParen(Left.Previous) || isAttributeParen(Right.Next))
+      return Style.SpacesInParensOptions.InAttributeSpecifiers != FormatStyle::SIPCS_Never;
     return Style.SpacesInParensOptions.Other;
   }
   if (Right.isOneOf(tok::semi, tok::comma))
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index e02eb76464fe9c1..c71342c9524c09a 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -232,7 +232,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
-  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InAttributeSpecifiers);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
@@ -628,6 +627,20 @@ TEST(ConfigParseTest, ParsesConfiguration) {
               SpaceBeforeParensOptions.AfterPlacementOperator,
               FormatStyle::SpaceBeforeParensCustom::APO_Leave);
 
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
+  CHECK_PARSE("SpacesInParensOptions:\n"
+              "  InAttributeSpecifiers: Always",
+              SpacesInParensOptions.InAttributeSpecifiers,
+              FormatStyle::SIPCS_Always);
+  CHECK_PARSE("SpacesInParensOptions:\n"
+              "  InAttributeSpecifiers: Never",
+              SpacesInParensOptions.InAttributeSpecifiers,
+              FormatStyle::SIPCS_Never);
+  CHECK_PARSE("SpacesInParensOptions:\n"
+              "  InAttributeSpecifiers: NonConsecutive",
+              SpacesInParensOptions.InAttributeSpecifiers,
+              FormatStyle::SIPCS_NonConsecutive);
   // For backward compatibility:
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
@@ -636,23 +649,23 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(true, true, false, false,
-                  true));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Always, true,
+                  false, false, true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(false, true, false, false,
-                  false));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never, true,
+                  false, false, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(false, false, true, false,
-                  false));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never, false,
+                  true, false, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(false, false, false, true,
-                  false));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never, false,
+                  false, true, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 98a8521b9f3447d..053778e0f9c0b00 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16833,7 +16833,8 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers =
+      FormatStyle::SIPCS_Always;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16908,11 +16909,17 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers =
+      FormatStyle::SIPCS_Always;
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
   verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__( ( asdf ) );", Spaces);
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers = false;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers =
+      FormatStyle::SIPCS_NonConsecutive;
+  verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__(( naked )) foo(int bar)", Spaces);
+  verifyFormat("void f( ) __attribute__(( asdf ));", Spaces); 
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
 
   // Run the first set of tests again with:
   Spaces.SpaceAfterCStyleCast = true;

>From 58c1133e2a1556684fcd7312721643d0b018f4f0 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Tue, 9 Jan 2024 15:14:44 -0700
Subject: [PATCH 03/16] Fix style problems

---
 clang/lib/Format/Format.cpp         |  9 ++++++---
 clang/lib/Format/TokenAnnotator.cpp | 12 ++++++++----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 99bd4a962caf5cd..97d5655db301fd5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -750,8 +750,10 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
   }
 };
 
-template <> struct ScalarEnumerationTraits<FormatStyle::SpacesInParensCustomStyle> {
-  static void enumeration(IO &IO, FormatStyle::SpacesInParensCustomStyle &Value) {
+template <>
+struct ScalarEnumerationTraits<FormatStyle::SpacesInParensCustomStyle> {
+  static void enumeration(IO &IO,
+                          FormatStyle::SpacesInParensCustomStyle &Value) {
     IO.enumCase(Value, "Never", FormatStyle::SIPCS_Never);
     IO.enumCase(Value, "NonConsecutive", FormatStyle::SIPCS_NonConsecutive);
     IO.enumCase(Value, "Always", FormatStyle::SIPCS_Always);
@@ -1202,7 +1204,8 @@ template <> struct MappingTraits<FormatStyle> {
       if (SpacesInParentheses) {
         // set all options except InCStyleCasts and InEmptyParentheses
         // to true for backward compatibility.
-        Style.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Always;
+        Style.SpacesInParensOptions.InAttributeSpecifiers =
+            FormatStyle::SIPCS_Always;
         Style.SpacesInParensOptions.InConditionalStatements = true;
         Style.SpacesInParensOptions.InCStyleCasts =
             SpacesInCStyleCastParentheses;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5dc12b52056dc43..f6d684c3992438c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4013,10 +4013,14 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     const auto isAttributeParen = [](const FormatToken *Paren) {
       return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
     };
-    if (isAttributeParen(&Left) || isAttributeParen(&Right))
-      return Style.SpacesInParensOptions.InAttributeSpecifiers == FormatStyle::SIPCS_Always;
-    if (isAttributeParen(Left.Previous) || isAttributeParen(Right.Next))
-      return Style.SpacesInParensOptions.InAttributeSpecifiers != FormatStyle::SIPCS_Never;
+    if (isAttributeParen(&Left) || isAttributeParen(&Right)) {
+      return Style.SpacesInParensOptions.InAttributeSpecifiers ==
+             FormatStyle::SIPCS_Always;
+    }
+    if (isAttributeParen(Left.Previous) || isAttributeParen(Right.Next)) {
+      return Style.SpacesInParensOptions.InAttributeSpecifiers !=
+             FormatStyle::SIPCS_Never;
+    }
     return Style.SpacesInParensOptions.Other;
   }
   if (Right.isOneOf(tok::semi, tok::comma))

>From 275357ee84afc90337606397d25675f95fa5ff49 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Tue, 9 Jan 2024 15:15:06 -0700
Subject: [PATCH 04/16] dump format style

---
 clang/docs/ClangFormatStyleOptions.rst | 30 +++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index f48b77caeeb1e8d..460eb924bc858ac 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5688,6 +5688,7 @@ the configuration (without a prefix: ``Auto``).
     # Example of usage:
     SpacesInParens: Custom
     SpacesInParensOptions:
+      InAttributeSpecifiers: NonConsecutive
       InConditionalStatements: true
       InEmptyParentheses: true
 
@@ -5703,12 +5704,35 @@ the configuration (without a prefix: ``Auto``).
       InConditionalStatements: true
       Other: true
 
-  * ``bool InAttributeSpecifiers`` Put a space in parentheses of attribute specifiers.
+  * ``SpacesInParensCustomStyle InAttributeSpecifiers``
+    Put a space in parentheses of attribute specifiers.
 
     .. code-block:: c++
 
-       true:                                  false:
-       __attribute__( ( noreturn ) )    vs.     __attribute__((noreturn))
+       Always:
+       __attribute__( ( noreturn ) )
+
+    .. code-block:: c++
+
+      NonConsecutive:
+      _attribute__(( noreturn ))
+
+    .. code-block:: c++
+
+      Never:
+      _attribute__((noreturn))
+
+    Possible values:
+
+    * ``SIPCS_Never`` (in configuration: ``Never``)
+      Never put spaces in parens.
+
+    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
+      Only put spaces in parens not followed by the same consecutive parens.
+
+    * ``SIPCS_Always`` (in configuration: ``Always``)
+      Always put spaces in parens.
+
 
   * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements
     (``for/if/while/switch...``).

>From c9daa98bc91cc4f86a37e1169bcdf7595c773dbf Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 13:15:18 -0700
Subject: [PATCH 05/16] Use SIPCS for other sub-options

---
 clang/docs/ClangFormatStyleOptions.rst       | 111 ++++++++++++++++---
 clang/docs/ReleaseNotes.rst                  |   4 +
 clang/include/clang/Format/Format.h          |  80 +++++++++----
 clang/lib/Format/Format.cpp                  |  20 +++-
 clang/lib/Format/TokenAnnotator.cpp          |  18 +--
 clang/unittests/Format/ConfigParseTest.cpp   |  64 ++++++-----
 clang/unittests/Format/FormatTest.cpp        |  28 ++---
 clang/unittests/Format/FormatTestVerilog.cpp |   6 +-
 8 files changed, 244 insertions(+), 87 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 460eb924bc858ac..d25273d95e2f245 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5689,7 +5689,7 @@ the configuration (without a prefix: ``Auto``).
     SpacesInParens: Custom
     SpacesInParensOptions:
       InAttributeSpecifiers: NonConsecutive
-      InConditionalStatements: true
+      InConditionalStatements: Always
       InEmptyParentheses: true
 
   Nested configuration flags:
@@ -5712,15 +5712,49 @@ the configuration (without a prefix: ``Auto``).
        Always:
        __attribute__( ( noreturn ) )
 
+    .. code-block:: c++
+
+       NonConsecutive:
+       _attribute__(( noreturn ))
+
+    .. code-block:: c++
+
+       Never:
+       _attribute__((noreturn))
+
+    Possible values:
+
+    * ``SIPCS_Never`` (in configuration: ``Never``)
+      Never put spaces in parens.
+
+    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
+      Only put spaces in parens not followed by the same consecutive parens.
+
+    * ``SIPCS_Always`` (in configuration: ``Always``)
+      Always put spaces in parens.
+
+
+  * ``SpacesInParensCustomStyle InConditionalStatements``
+    Put a space in parentheses only inside conditional statements
+    (``for/if/while/switch...``).
+
+    .. code-block:: c++
+
+       Always:
+       if ( ( a ) )  { ... }
+       while ( i < 5 )  { ... }
+
     .. code-block:: c++
 
       NonConsecutive:
-      _attribute__(( noreturn ))
+      if (( a )) { ... }
+      while ( i < 5 ) { ... }
 
     .. code-block:: c++
 
       Never:
-      _attribute__((noreturn))
+      if ((a)) { ... }
+      while (i < 5) { ... }
 
     Possible values:
 
@@ -5734,21 +5768,38 @@ the configuration (without a prefix: ``Auto``).
       Always put spaces in parens.
 
 
-  * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements
-    (``for/if/while/switch...``).
+  * ``SpacesInParensCustomStyle InCStyleCasts``
+    Put a space in C style casts.
 
     .. code-block:: c++
 
-       true:                                  false:
-       if ( a )  { ... }              vs.     if (a) { ... }
-       while ( i < 5 )  { ... }               while (i < 5) { ... }
+      Always:                                  false:
+      x = ( int32 )y                 vs.     x = (int32)y
+      y = (( int (*)(int) )foo)(x);
+
+    .. code-block:: c++
 
-  * ``bool InCStyleCasts`` Put a space in C style casts.
+      NonConsecutive:
+      x = ( int32 )y
+      y = ((int (*)(int))foo)(x);
 
     .. code-block:: c++
 
-       true:                                  false:
-       x = ( int32 )y                 vs.     x = (int32)y
+      Never:
+      x = (int32)y
+      y = ((int (*)(int))foo)(x);
+
+    Possible values:
+
+    * ``SIPCS_Never`` (in configuration: ``Never``)
+      Never put spaces in parens.
+
+    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
+      Only put spaces in parens not followed by the same consecutive parens.
+
+    * ``SIPCS_Always`` (in configuration: ``Always``)
+      Always put spaces in parens.
+
 
   * ``bool InEmptyParentheses`` Put a space in parentheses only if the parentheses are empty i.e. '()'
 
@@ -5762,12 +5813,44 @@ the configuration (without a prefix: ``Auto``).
          }                                    }
        }                                    }
 
-  * ``bool Other`` Put a space in parentheses not covered by preceding options.
+  * ``SpacesInParensCustomStyle Other``
+    Put a space in parentheses not covered by preceding options.
 
     .. code-block:: c++
 
-       true:                                  false:
-       t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
+      Always:
+      t f( Deleted & ) & = delete;
+      decltype( ( x ) )
+      x = ( (int32)y )
+      y = ( (int ( * )( int ))foo )( x );
+
+    .. code-block:: c++
+
+      NonConsecutive:
+      t f( Deleted & ) & = delete;
+      decltype(( x ))
+      x = ((int32))y
+      y = ((int ( * )( int ))foo)( x );
+
+    .. code-block:: c++
+
+      Never:
+      t f(Deleted &) & = delete;
+      decltype((x))
+      x = ((int32))y
+      y = ((int (*)(int))foo)(x);
+
+    Possible values:
+
+    * ``SIPCS_Never`` (in configuration: ``Never``)
+      Never put spaces in parens.
+
+    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
+      Only put spaces in parens not followed by the same consecutive parens.
+
+    * ``SIPCS_Always`` (in configuration: ``Always``)
+      Always put spaces in parens.
+
 
 
 .. _SpacesInParentheses:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 38346d95143a732..ed77f0503f6b189 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1284,6 +1284,10 @@ clang-format
 - Add ``SkipMacroDefinitionBody`` option.
 - Add ``InAttributeSpecifiers`` style option to ``SpacesInParensOptions``
   to control addition of spaces after the ``__attribute__`` keyword.
+- Add ``NonConsecutive`` sub-option for ``InAttributeSpecifiers``,
+  ``InConditionalStatements``, ``InCStyleCasts``, and ``Other`` options of
+  ``SpacesInParensOptions`` to control addition of spaces between consecutive
+  parentheses.
 
 libclang
 --------
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 7d048adfad106a0..8f022593d66c029 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4558,28 +4558,49 @@ struct FormatStyle {
     ///    __attribute__( ( noreturn ) )
     /// \endcode
     /// \code
-    ///   NonConsecutive:
-    ///   _attribute__(( noreturn ))
+    ///    NonConsecutive:
+    ///    _attribute__(( noreturn ))
     /// \endcode
     /// \code
-    ///   Never:
-    ///   _attribute__((noreturn))
+    ///    Never:
+    ///    _attribute__((noreturn))
     /// \endcode
     SpacesInParensCustomStyle InAttributeSpecifiers;
     /// Put a space in parentheses only inside conditional statements
     /// (``for/if/while/switch...``).
     /// \code
-    ///    true:                                  false:
-    ///    if ( a )  { ... }              vs.     if (a) { ... }
-    ///    while ( i < 5 )  { ... }               while (i < 5) { ... }
+    ///    Always:
+    ///    if ( ( a ) )  { ... }
+    ///    while ( i < 5 )  { ... }
+    /// \endcode
+    /// \code
+    ///   NonConsecutive:
+    ///   if (( a )) { ... }
+    ///   while ( i < 5 ) { ... }
     /// \endcode
-    bool InConditionalStatements;
+    /// \code
+    ///   Never:
+    ///   if ((a)) { ... }
+    ///   while (i < 5) { ... }
+    /// \endcode
+    SpacesInParensCustomStyle InConditionalStatements;
     /// Put a space in C style casts.
     /// \code
-    ///    true:                                  false:
-    ///    x = ( int32 )y                 vs.     x = (int32)y
+    ///   Always:                                  false:
+    ///   x = ( int32 )y                 vs.     x = (int32)y
+    ///   y = (( int (*)(int) )foo)(x);
     /// \endcode
-    bool InCStyleCasts;
+    /// \code
+    ///   NonConsecutive:
+    ///   x = ( int32 )y
+    ///   y = ((int (*)(int))foo)(x);
+    /// \endcode
+    /// \code
+    ///   Never:
+    ///   x = (int32)y
+    ///   y = ((int (*)(int))foo)(x);
+    /// \endcode
+    SpacesInParensCustomStyle InCStyleCasts;
     /// Put a space in parentheses only if the parentheses are empty i.e. '()'
     /// \code
     ///    true:                                false:
@@ -4593,18 +4614,39 @@ struct FormatStyle {
     bool InEmptyParentheses;
     /// Put a space in parentheses not covered by preceding options.
     /// \code
-    ///    true:                                  false:
-    ///    t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
+    ///   Always:
+    ///   t f( Deleted & ) & = delete;
+    ///   decltype( ( x ) )
+    ///   x = ( (int32)y )
+    ///   y = ( (int ( * )( int ))foo )( x );
+    /// \endcode
+    /// \code
+    ///   NonConsecutive:
+    ///   t f( Deleted & ) & = delete;
+    ///   decltype(( x ))
+    ///   x = ((int32))y
+    ///   y = ((int ( * )( int ))foo)( x );
+    /// \endcode
+    /// \code
+    ///   Never:
+    ///   t f(Deleted &) & = delete;
+    ///   decltype((x))
+    ///   x = ((int32))y 
+    ///   y = ((int (*)(int))foo)(x);
     /// \endcode
-    bool Other;
+    SpacesInParensCustomStyle Other;
 
     SpacesInParensCustom()
-        : InAttributeSpecifiers(SIPCS_Never), InConditionalStatements(false),
-          InCStyleCasts(false), InEmptyParentheses(false), Other(false) {}
+        : InAttributeSpecifiers(SIPCS_Never),
+          InConditionalStatements(SIPCS_Never),
+          InCStyleCasts(SIPCS_Never), InEmptyParentheses(false),
+          Other(SIPCS_Never) {}
 
     SpacesInParensCustom(SpacesInParensCustomStyle InAttributeSpecifiers,
-                         bool InConditionalStatements, bool InCStyleCasts,
-                         bool InEmptyParentheses, bool Other)
+                         SpacesInParensCustomStyle InConditionalStatements,
+                         SpacesInParensCustomStyle InCStyleCasts,
+                         bool InEmptyParentheses,
+                         SpacesInParensCustomStyle Other)
         : InAttributeSpecifiers(InAttributeSpecifiers),
           InConditionalStatements(InConditionalStatements),
           InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses),
@@ -4631,7 +4673,7 @@ struct FormatStyle {
   ///   SpacesInParens: Custom
   ///   SpacesInParensOptions:
   ///     InAttributeSpecifiers: NonConsecutive
-  ///     InConditionalStatements: true
+  ///     InConditionalStatements: Always
   ///     InEmptyParentheses: true
   /// \endcode
   /// \version 17
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 97d5655db301fd5..26504319223d17c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -757,6 +757,10 @@ struct ScalarEnumerationTraits<FormatStyle::SpacesInParensCustomStyle> {
     IO.enumCase(Value, "Never", FormatStyle::SIPCS_Never);
     IO.enumCase(Value, "NonConsecutive", FormatStyle::SIPCS_NonConsecutive);
     IO.enumCase(Value, "Always", FormatStyle::SIPCS_Always);
+
+    // For backward compatibility.
+    IO.enumCase(Value, "true", FormatStyle::SIPCS_Always);
+    IO.enumCase(Value, "false", FormatStyle::SIPCS_Never);
   }
 };
 
@@ -1201,23 +1205,27 @@ template <> struct MappingTraits<FormatStyle> {
     if (Style.SpacesInParens != FormatStyle::SIPO_Custom &&
         (SpacesInParentheses || SpaceInEmptyParentheses ||
          SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
+      const auto CoerceBooleanToSIPCS = [](const bool enabled) {
+        return enabled ? FormatStyle::SIPCS_Always : FormatStyle::SIPCS_Never;
+      };
       if (SpacesInParentheses) {
         // set all options except InCStyleCasts and InEmptyParentheses
-        // to true for backward compatibility.
+        // to true/Always for backward compatibility.
         Style.SpacesInParensOptions.InAttributeSpecifiers =
             FormatStyle::SIPCS_Always;
-        Style.SpacesInParensOptions.InConditionalStatements = true;
+        Style.SpacesInParensOptions.InConditionalStatements =
+            FormatStyle::SIPCS_Always;
         Style.SpacesInParensOptions.InCStyleCasts =
-            SpacesInCStyleCastParentheses;
+            CoerceBooleanToSIPCS(SpacesInCStyleCastParentheses);
         Style.SpacesInParensOptions.InEmptyParentheses =
             SpaceInEmptyParentheses;
-        Style.SpacesInParensOptions.Other = true;
+        Style.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
       } else {
         Style.SpacesInParensOptions = {};
         Style.SpacesInParensOptions.InConditionalStatements =
-            SpacesInConditionalStatement;
+            CoerceBooleanToSIPCS(SpacesInConditionalStatement);
         Style.SpacesInParensOptions.InCStyleCasts =
-            SpacesInCStyleCastParentheses;
+            CoerceBooleanToSIPCS(SpacesInCStyleCastParentheses);
         Style.SpacesInParensOptions.InEmptyParentheses =
             SpaceInEmptyParentheses;
       }
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index f6d684c3992438c..8dc696dbb115c98 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3550,8 +3550,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
     const FormatToken *Prev = Current->Previous;
     if (Current->is(TT_LineComment)) {
       if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
-        Current->SpacesRequiredBefore =
-            (Style.Cpp11BracedListStyle && !Style.SpacesInParensOptions.Other)
+        Current->SpacesRequiredBefore = (Style.Cpp11BracedListStyle && Style.SpacesInParensOptions.Other ==            FormatStyle::SIPCS_Never)
                 ? 0
                 : 1;
       } else if (Prev->is(TT_VerilogMultiLineListLParen)) {
@@ -3969,7 +3968,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
        Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
     return Style.SpacesInParensOptions.InEmptyParentheses;
   }
-  if (Style.SpacesInParensOptions.InConditionalStatements) {
+  if (Style.SpacesInParensOptions.InConditionalStatements != FormatStyle::SIPCS_Never) {
+  // TODO: check consecutive parens
     const FormatToken *LeftParen = nullptr;
     if (Left.is(tok::l_paren))
       LeftParen = &Left;
@@ -4005,10 +4005,12 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     return true;
   }
 
+  // TODO: check consecutive parens
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren)) {
     if (Right.is(TT_CastRParen) ||
         (Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen))) {
-      return Style.SpacesInParensOptions.InCStyleCasts;
+      return Style.SpacesInParensOptions.InCStyleCasts !=
+             FormatStyle::SIPCS_Never;
     }
     const auto isAttributeParen = [](const FormatToken *Paren) {
       return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
@@ -4021,7 +4023,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
       return Style.SpacesInParensOptions.InAttributeSpecifiers !=
              FormatStyle::SIPCS_Never;
     }
-    return Style.SpacesInParensOptions.Other;
+    return Style.SpacesInParensOptions.Other != FormatStyle::SIPCS_Never;
   }
   if (Right.isOneOf(tok::semi, tok::comma))
     return false;
@@ -4244,7 +4246,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   if ((Left.is(tok::l_brace) && Left.isNot(BK_Block)) ||
       (Right.is(tok::r_brace) && Right.MatchingParen &&
        Right.MatchingParen->isNot(BK_Block))) {
-    return !Style.Cpp11BracedListStyle || Style.SpacesInParensOptions.Other;
+    return !Style.Cpp11BracedListStyle || (Style.SpacesInParensOptions.Other !=
+                                           FormatStyle::SIPCS_Never);
   }
   if (Left.is(TT_BlockComment)) {
     // No whitespace in x(/*foo=*/1), except for JavaScript.
@@ -4934,7 +4937,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
            !(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
                           tok::kw___super, TT_TemplateOpener,
                           TT_TemplateCloser)) ||
-           (Left.is(tok::l_paren) && Style.SpacesInParensOptions.Other);
+           (Left.is(tok::l_paren) && Style.SpacesInParensOptions.Other !=
+                                     FormatStyle::SIPCS_Always);
   }
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
     return ShouldAddSpacesInAngles();
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index c71342c9524c09a..0cd3aec53ab28d3 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -232,10 +232,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
-  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);
-  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements);
-  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
-  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, Other);
 }
 
 #undef CHECK_PARSE_BOOL
@@ -627,20 +623,32 @@ TEST(ConfigParseTest, ParsesConfiguration) {
               SpaceBeforeParensOptions.AfterPlacementOperator,
               FormatStyle::SpaceBeforeParensCustom::APO_Leave);
 
-  Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
-  CHECK_PARSE("SpacesInParensOptions:\n"
-              "  InAttributeSpecifiers: Always",
-              SpacesInParensOptions.InAttributeSpecifiers,
-              FormatStyle::SIPCS_Always);
-  CHECK_PARSE("SpacesInParensOptions:\n"
-              "  InAttributeSpecifiers: Never",
-              SpacesInParensOptions.InAttributeSpecifiers,
-              FormatStyle::SIPCS_Never);
-  CHECK_PARSE("SpacesInParensOptions:\n"
-              "  InAttributeSpecifiers: NonConsecutive",
-              SpacesInParensOptions.InAttributeSpecifiers,
-              FormatStyle::SIPCS_NonConsecutive);
+#define CHECK_SPACES_IN_PARENS_OPTIONS(FIELD)                                  \
+  do {                                                                         \
+    Style.SpacesInParens = FormatStyle::SIPO_Custom;                           \
+    Style.SpacesInParensOptions.FIELD = FormatStyle::SIPCS_Never;              \
+    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": Always",                \
+                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Always);       \
+    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": Never",                 \
+                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Never);        \
+    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": NonConsecutive",        \
+                SpacesInParensOptions.FIELD,                                   \
+                FormatStyle::SIPCS_NonConsecutive);                            \
+    /* For backwards compatibility */                                          \
+    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": false",                 \
+                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Never);        \
+    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": true",                  \
+                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Always);       \
+  } while (false)
+
+  CHECK_SPACES_IN_PARENS_OPTIONS(InAttributeSpecifiers);
+  CHECK_SPACES_IN_PARENS_OPTIONS(InConditionalStatements);
+  CHECK_SPACES_IN_PARENS_OPTIONS(InCStyleCasts);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
+  CHECK_SPACES_IN_PARENS_OPTIONS(Other);
+
+#undef CHECK_SPACES_IN_PARENS_OPTIONS
+
   // For backward compatibility:
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
@@ -649,23 +657,27 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Always, true,
-                  false, false, true));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Always,
+              FormatStyle::SIPCS_Always, FormatStyle::SIPCS_Never, false,
+              FormatStyle::SIPCS_Always));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never, true,
-                  false, false, false));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never,
+              FormatStyle::SIPCS_Always, FormatStyle::SIPCS_Never, false,
+              FormatStyle::SIPCS_Never));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never, false,
-                  true, false, false));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never,
+              FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Always, false,
+              FormatStyle::SIPCS_Never));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never, false,
-                  false, true, false));
+              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never,
+              FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Never, true,
+              FormatStyle::SIPCS_Never));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 053778e0f9c0b00..652d817ec0a1cf7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11174,14 +11174,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InCStyleCasts = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
   verifyFormat("Deleted &operator=(const Deleted &) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces);
   verifyFormat("Deleted &operator=(const Deleted &) &;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
-  Spaces.SpacesInParensOptions.InCStyleCasts = false;
-  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
+  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
   verifyFormat("Deleted &operator=( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
                Spaces);
@@ -13747,7 +13747,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   FormatStyle SpaceBetweenBraces = getLLVMStyle();
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
   SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
-  SpaceBetweenBraces.SpacesInParensOptions.Other = true;
+  SpaceBetweenBraces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -16831,8 +16831,9 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.Other = true;
-  Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_Always;
   Spaces.SpacesInParensOptions.InAttributeSpecifiers =
       FormatStyle::SIPCS_Always;
   verifyFormat("do_something( ::globalVar );", Spaces);
@@ -16867,7 +16868,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InCStyleCasts = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
   verifyFormat("Type *A = ( Type * )P;", Spaces);
   verifyFormat("Type *A = ( vector<Type *, int *> )P;", Spaces);
   verifyFormat("x = ( int32 )y;", Spaces);
@@ -16881,7 +16882,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.InEmptyParentheses = true;
-  Spaces.SpacesInParensOptions.InCStyleCasts = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
   verifyFormat("call(x, y, z);", Spaces);
   verifyFormat("call( );", Spaces);
   verifyFormat("std::function<void(int, int)> callback;", Spaces);
@@ -16957,7 +16958,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
   // Run subset of tests again with:
-  Spaces.SpacesInParensOptions.InCStyleCasts = false;
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("while ((bool) 1)\n"
                "  continue;",
@@ -24095,10 +24096,10 @@ TEST_F(FormatTest, AtomicQualifier) {
   verifyFormat("vector<_Atomic(uint64_t)* attr> x;", Style);
 
   Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InCStyleCasts = true;
+  Style.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
   verifyFormat("x = ( _Atomic(uint64_t) )*a;", Style);
-  Style.SpacesInParensOptions.InCStyleCasts = false;
-  Style.SpacesInParensOptions.Other = true;
+  Style.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
+  Style.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
   verifyFormat("x = (_Atomic( uint64_t ))*a;", Style);
   verifyFormat("x = (_Atomic( uint64_t ))&a;", Style);
 }
@@ -24162,7 +24163,8 @@ TEST_F(FormatTest, SpacesInConditionalStatement) {
   Spaces.IfMacros.clear();
   Spaces.IfMacros.push_back("MYIF");
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
-  Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_Always;
   verifyFormat("for ( int i = 0; i; i++ )\n  continue;", Spaces);
   verifyFormat("if ( !a )\n  return;", Spaces);
   verifyFormat("if ( a )\n  return;", Spaces);
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp
index abebf9f7d4c785c..5078cbe3b66d43a 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -885,7 +885,8 @@ TEST_F(FormatTestVerilog, If) {
                "    x = x;",
                Style);
   Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InConditionalStatements = true;
+  Style.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_Always;
   verifyFormat("if ( x )\n"
                "  x = x;\n"
                "else if ( x )\n"
@@ -982,7 +983,8 @@ TEST_F(FormatTestVerilog, Loop) {
                "end");
   auto Style = getDefaultStyle();
   Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InConditionalStatements = true;
+  Style.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_Always;
   verifyFormat("foreach ( x[x] )\n"
                "  x = x;",
                Style);

>From fb36a11644a92816c25108f3c4da9d923a0c7254 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 13:57:05 -0700
Subject: [PATCH 06/16] fix local formatting

---
 clang/lib/Format/TokenAnnotator.cpp | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 8dc696dbb115c98..3f3f5675e2ff166 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3550,7 +3550,9 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
     const FormatToken *Prev = Current->Previous;
     if (Current->is(TT_LineComment)) {
       if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
-        Current->SpacesRequiredBefore = (Style.Cpp11BracedListStyle && Style.SpacesInParensOptions.Other ==            FormatStyle::SIPCS_Never)
+        Current->SpacesRequiredBefore =
+            (Style.Cpp11BracedListStyle &&
+             Style.SpacesInParensOptions.Other == FormatStyle::SIPCS_Never)
                 ? 0
                 : 1;
       } else if (Prev->is(TT_VerilogMultiLineListLParen)) {
@@ -3968,8 +3970,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
        Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
     return Style.SpacesInParensOptions.InEmptyParentheses;
   }
-  if (Style.SpacesInParensOptions.InConditionalStatements != FormatStyle::SIPCS_Never) {
-  // TODO: check consecutive parens
+  if (Style.SpacesInParensOptions.InConditionalStatements !=
+      FormatStyle::SIPCS_Never) {
+    // TODO: check consecutive parens
     const FormatToken *LeftParen = nullptr;
     if (Left.is(tok::l_paren))
       LeftParen = &Left;
@@ -4246,8 +4249,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   if ((Left.is(tok::l_brace) && Left.isNot(BK_Block)) ||
       (Right.is(tok::r_brace) && Right.MatchingParen &&
        Right.MatchingParen->isNot(BK_Block))) {
-    return !Style.Cpp11BracedListStyle || (Style.SpacesInParensOptions.Other !=
-                                           FormatStyle::SIPCS_Never);
+    return !Style.Cpp11BracedListStyle ||
+           (Style.SpacesInParensOptions.Other != FormatStyle::SIPCS_Never);
   }
   if (Left.is(TT_BlockComment)) {
     // No whitespace in x(/*foo=*/1), except for JavaScript.
@@ -4937,8 +4940,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
            !(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
                           tok::kw___super, TT_TemplateOpener,
                           TT_TemplateCloser)) ||
-           (Left.is(tok::l_paren) && Style.SpacesInParensOptions.Other !=
-                                     FormatStyle::SIPCS_Always);
+           (Left.is(tok::l_paren) &&
+            Style.SpacesInParensOptions.Other != FormatStyle::SIPCS_Always);
   }
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
     return ShouldAddSpacesInAngles();

>From 15e1057302ed1a9a041e0cc5edf618b2d73b502b Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 15:06:22 -0700
Subject: [PATCH 07/16] add test cases

---
 clang/unittests/Format/FormatTest.cpp | 191 ++++++++++++++++++++++++++
 1 file changed, 191 insertions(+)

diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 652d817ec0a1cf7..4592279dfc849c2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16828,6 +16828,23 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f() __attribute__((asdf));", Spaces);
+  verifyFormat("x = (int32)y;", Spaces);
+  verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
+  verifyFormat("decltype(x) y = 42;", Spaces);
+  verifyFormat("decltype((x)) y = z;", Spaces);
+  verifyFormat("decltype((foo())) a = foo();", Spaces);
+  verifyFormat("decltype((bar(10))) a = bar(11);", Spaces);
+  verifyFormat("if ((x - y) && (a ^ b))\n"
+               "  f();\n",
+               Spaces);
+  verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
+               "  foo(i);",
+               Spaces);
+  verifyFormat("switch (x * (y + z)) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
@@ -16865,6 +16882,23 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
   verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces);
   verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
+  verifyFormat("x = (int32)y;", Spaces);
+  verifyFormat("y = ( (int (*)(int))foo )( x );", Spaces);
+  verifyFormat("decltype( x ) y = 42;", Spaces);
+  verifyFormat("decltype( ( x ) ) y = z;", Spaces);
+  verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces);
+  verifyFormat("decltype( ( bar( 10 ) ) ) a = bar( 11 );", Spaces);
+  verifyFormat("if ( ( x - y ) && ( a ^ b ) )\n"
+               "  f();\n",
+               Spaces);
+  verifyFormat("for ( int i = 0; i < 10; i = ( i+1 ) )\n"
+               "  foo( i );",
+               Spaces);
+  verifyFormat("switch ( x * ( y + z ) ) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
@@ -16877,6 +16911,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("#define AA(X) sizeof((( X * )NULL)->a)", Spaces);
   verifyFormat("my_int a = ( my_int )sizeof(int);", Spaces);
   verifyFormat("#define x (( int )-1)", Spaces);
+  verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
 
   // Run the first set of tests again with:
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
@@ -16909,7 +16944,27 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
+  verifyFormat("x = ( int32 )y;", Spaces);
+  verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
+  verifyFormat("decltype(x) y = 42;", Spaces);
+  verifyFormat("decltype((x)) y = z;", Spaces);
+  verifyFormat("decltype((foo( ))) a = foo( );", Spaces);
+  verifyFormat("decltype((bar(10))) a = bar(11);", Spaces);
+  verifyFormat("if ((x - y) && (a ^ b))\n"
+               "  f( );\n",
+               Spaces);
+  verifyFormat("for (int i = 0; i < 10; i = (i+1))\n"
+               "  foo(i);",
+               Spaces);
+  verifyFormat("switch (x * (y + z)) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
 
+  // Check NonConsecutive spaces
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.InAttributeSpecifiers =
       FormatStyle::SIPCS_Always;
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
@@ -16922,6 +16977,142 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("void f( ) __attribute__(( asdf ));", Spaces); 
   Spaces.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
 
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
+  verifyFormat("x = ( int32 )y;", Spaces);
+  verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
+  Spaces.SpacesInParensOptions.InCStyleCasts =
+      FormatStyle::SIPCS_NonConsecutive;
+  verifyFormat("x = ( int32 )y;", Spaces);
+  verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
+  verifyFormat("x = (int32)y;", Spaces);
+  verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
+
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {}; 
+  Spaces.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_Always;
+  verifyFormat("while ( (bool)1 )\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("for ( ;; )\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("if ( true )\n"
+               "  f();\n"
+               "else if ( true )\n"
+               "  f();",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int)i);\n"
+               "} while ( something() );",
+               Spaces);
+  verifyFormat("switch ( x ) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+  verifyFormat("if ( (x - y) && (a ^ b) )\n"
+               "  f();\n",
+               Spaces);
+  verifyFormat("for ( int i = 0; i < 10; i = (i+1) )\n"
+               "  foo(i);",
+               Spaces);
+  verifyFormat("switch ( x * (y + z) ) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+  Spaces.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_NonConsecutive;
+  verifyFormat("while ((bool)1)\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("for ( ;; )\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("if ( true )\n"
+               "  f();\n"
+               "else if ( true )\n"
+               "  f();",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int)i);\n"
+               "} while (something());",
+               Spaces);
+  verifyFormat("switch ( x ) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+  verifyFormat("if ((x - y) && (a ^ b))\n"
+               "  f();\n",
+               Spaces);
+  verifyFormat("for (int i = 0; i < 10; i = (i+1))\n"
+               "  foo(i);",
+               Spaces);
+  verifyFormat("switch (x * (y + z)) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+  Spaces.SpacesInParensOptions.InConditionalStatements =
+      FormatStyle::SIPCS_Never;
+  verifyFormat("while ((bool)1)\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("for (;;)\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("if (true)\n"
+               "  f();\n"
+               "else if (true)\n"
+               "  f();",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int)i);\n"
+               "} while (something());",
+               Spaces);
+  verifyFormat("switch (x) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+  verifyFormat("if ((x - y) && (a ^ b))\n"
+               "  f();\n",
+               Spaces);
+  verifyFormat("for (int i = 0; i < 10; i = (i+1))\n"
+               "  foo(i);",
+               Spaces);
+  verifyFormat("switch (x * (y + z)) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {}; 
+  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+  verifyFormat("decltype( x ) y = 42;", Spaces);
+  verifyFormat("decltype( ( x ) ) y = z;", Spaces);
+  verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces);
+  verifyFormat("decltype( ( bar( 10 ) ) ) a = bar( 11 );", Spaces);
+  verifyFormat("x = foo( ( a * ( b - c ) ) );", Spaces);
+  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_NonConsecutive;
+  verifyFormat("decltype( x ) y = 42;", Spaces);
+  verifyFormat("decltype(( x )) y = z;", Spaces);
+  verifyFormat("decltype((foo())) a = foo();", Spaces);
+  verifyFormat("decltype((bar( 10 ))) a = bar( 11 );", Spaces);
+  verifyFormat("x = foo((a * ( b - c )));", Spaces);
+  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Never;
+  verifyFormat("decltype(x) y = 42;", Spaces);
+  verifyFormat("decltype((x)) y = z;", Spaces);
+  verifyFormat("decltype((foo())) a = foo();", Spaces);
+  verifyFormat("decltype((bar(10))) a = bar( 11 );", Spaces);
+  verifyFormat("x = foo((a * (b - c)));", Spaces);
+
   // Run the first set of tests again with:
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("call(x, y, z);", Spaces);

>From a0fb99c20c2b13cc2691cc317e6ba493cb0cdfac Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 16:05:54 -0700
Subject: [PATCH 08/16] fix tests and add initial support for conditionals

---
 clang/lib/Format/TokenAnnotator.cpp   |  18 +-
 clang/unittests/Format/FormatTest.cpp | 245 +++++++++++++-------------
 2 files changed, 137 insertions(+), 126 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 3f3f5675e2ff166..20a82c012d2d0fd 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3979,10 +3979,20 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     else if (Right.is(tok::r_paren) && Right.MatchingParen)
       LeftParen = Right.MatchingParen;
     if (LeftParen) {
-      if (LeftParen->is(TT_ConditionLParen))
-        return true;
-      if (LeftParen->Previous && isKeywordWithCondition(*LeftParen->Previous))
-        return true;
+      if (LeftParen->is(TT_ConditionLParen) || (LeftParen->Previous &&
+              isKeywordWithCondition(*LeftParen->Previous))) {
+        if (Style.SpacesInParensOptions.InConditionalStatements ==
+            FormatStyle::SIPCS_Always) {
+          return true;
+        }
+        const FormatToken *RightParen = LeftParen->MatchingParen;
+        if (LeftParen->Next && LeftParen->Next->isNot(tok::l_paren))
+          return true;
+        if (RightParen && RightParen->Previous &&
+            RightParen->Previous->isNot(tok::r_paren)) {
+          return true;
+        }
+      }
     }
   }
 
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4592279dfc849c2..ad2bf63838aff04 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16840,7 +16840,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
                "  foo(i);",
                Spaces);
-  verifyFormat("switch (x * (y + z)) {\n"
+  verifyFormat("switch (x / (y + z)) {\n"
                "default:\n"
                "  break;\n"
                "}",
@@ -16883,7 +16883,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces);
   verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
   verifyFormat("x = (int32)y;", Spaces);
-  verifyFormat("y = ( (int (*)(int))foo )( x );", Spaces);
+  verifyFormat("y = ( (int ( * )( int ))foo )( x );", Spaces);
   verifyFormat("decltype( x ) y = 42;", Spaces);
   verifyFormat("decltype( ( x ) ) y = z;", Spaces);
   verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces);
@@ -16891,10 +16891,10 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ( ( x - y ) && ( a ^ b ) )\n"
                "  f();\n",
                Spaces);
-  verifyFormat("for ( int i = 0; i < 10; i = ( i+1 ) )\n"
+  verifyFormat("for ( int i = 0; i < 10; i = ( i + 1 ) )\n"
                "  foo( i );",
                Spaces);
-  verifyFormat("switch ( x * ( y + z ) ) {\n"
+  verifyFormat("switch ( x / ( y + z ) ) {\n"
                "default:\n"
                "  break;\n"
                "}",
@@ -16953,28 +16953,136 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ((x - y) && (a ^ b))\n"
                "  f( );\n",
                Spaces);
-  verifyFormat("for (int i = 0; i < 10; i = (i+1))\n"
+  verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
                "  foo(i);",
                Spaces);
-  verifyFormat("switch (x * (y + z)) {\n"
+  verifyFormat("switch (x / (y + z)) {\n"
+               "default:\n"
+               "  break;\n"
+               "}",
+               Spaces);
+
+  // Run the first set of tests again with:
+  Spaces.SpaceAfterCStyleCast = true;
+  verifyFormat("call(x, y, z);", Spaces);
+  verifyFormat("call( );", Spaces);
+  verifyFormat("std::function<void(int, int)> callback;", Spaces);
+  verifyFormat("while (( bool ) 1)\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("for (;;)\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("if (true)\n"
+               "  f( );\n"
+               "else if (true)\n"
+               "  f( );",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something(( int ) i);\n"
+               "} while (something( ));",
+               Spaces);
+  verifyFormat("switch (x) {\n"
                "default:\n"
                "  break;\n"
                "}",
                Spaces);
+  verifyFormat("#define CONF_BOOL(x) ( bool * ) ( void * ) (x)", Spaces);
+  verifyFormat("#define CONF_BOOL(x) ( bool * ) (x)", Spaces);
+  verifyFormat("#define CONF_BOOL(x) ( bool ) (x)", Spaces);
+  verifyFormat("bool *y = ( bool * ) ( void * ) (x);", Spaces);
+  verifyFormat("bool *y = ( bool * ) (x);", Spaces);
+  verifyFormat("throw ( int32 ) x;", Spaces);
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
+  verifyFormat("void f( ) __attribute__((asdf));", Spaces);
+
+  // Run subset of tests again with:
+  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
+  Spaces.SpaceAfterCStyleCast = true;
+  verifyFormat("while ((bool) 1)\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int) i);\n"
+               "} while (something( ));",
+               Spaces);
+
+  verifyFormat("size_t idx = (size_t) (ptr - ((char *) file));", Spaces);
+  verifyFormat("size_t idx = (size_t) a;", Spaces);
+  verifyFormat("size_t idx = (size_t) (a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  verifyFormat("#define CONF_BOOL(x) (bool *) (void *) (x)", Spaces);
+  verifyFormat("#define CONF_BOOL(x) (bool *) (void *) (int) (x)", Spaces);
+  verifyFormat("bool *y = (bool *) (void *) (x);", Spaces);
+  verifyFormat("bool *y = (bool *) (void *) (int) (x);", Spaces);
+  verifyFormat("bool *y = (bool *) (void *) (int) foo(x);", Spaces);
+  verifyFormat("throw (int32) x;", Spaces);
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
+  verifyFormat("void f( ) __attribute__((asdf));", Spaces);
+
+  Spaces.ColumnLimit = 80;
+  Spaces.IndentWidth = 4;
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo( ) {\n"
+               "    size_t foo = (*(function))(\n"
+               "        Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
+               "BarrrrrrrrrrrrLong,\n"
+               "        FoooooooooLooooong);\n"
+               "}",
+               Spaces);
+  Spaces.SpaceAfterCStyleCast = false;
+  verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
+  verifyFormat("size_t idx = (size_t)a;", Spaces);
+  verifyFormat("size_t idx = (size_t)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat("void foo( ) {\n"
+               "    size_t foo = (*(function))(\n"
+               "        Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
+               "BarrrrrrrrrrrrLong,\n"
+               "        FoooooooooLooooong);\n"
+               "}",
+               Spaces);
+
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  verifyFormat("void foo( ) {\n"
+               "    size_t foo = (*(function))(\n"
+               "        Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
+               "BarrrrrrrrrrrrLong,\n"
+               "        FoooooooooLooooong\n"
+               "    );\n"
+               "}",
+               Spaces);
+  verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
+  verifyFormat("size_t idx = (size_t)a;", Spaces);
+  verifyFormat("size_t idx = (size_t)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
 
   // Check NonConsecutive spaces
+  Spaces.IndentWidth = 2;
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.InAttributeSpecifiers =
       FormatStyle::SIPCS_Always;
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
   verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
-  verifyFormat("void f( ) __attribute__( ( asdf ) );", Spaces);
+  verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
   Spaces.SpacesInParensOptions.InAttributeSpecifiers =
       FormatStyle::SIPCS_NonConsecutive;
   verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
   verifyFormat("void __attribute__(( naked )) foo(int bar)", Spaces);
-  verifyFormat("void f( ) __attribute__(( asdf ));", Spaces); 
+  verifyFormat("void f() __attribute__(( asdf ));", Spaces); 
   Spaces.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
@@ -17017,10 +17125,10 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ( (x - y) && (a ^ b) )\n"
                "  f();\n",
                Spaces);
-  verifyFormat("for ( int i = 0; i < 10; i = (i+1) )\n"
+  verifyFormat("for ( int i = 0; i < 10; i = (i + 1) )\n"
                "  foo(i);",
                Spaces);
-  verifyFormat("switch ( x * (y + z) ) {\n"
+  verifyFormat("switch ( x / (y + z) ) {\n"
                "default:\n"
                "  break;\n"
                "}",
@@ -17050,10 +17158,10 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ((x - y) && (a ^ b))\n"
                "  f();\n",
                Spaces);
-  verifyFormat("for (int i = 0; i < 10; i = (i+1))\n"
+  verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
                "  foo(i);",
                Spaces);
-  verifyFormat("switch (x * (y + z)) {\n"
+  verifyFormat("switch (x / (y + z)) {\n"
                "default:\n"
                "  break;\n"
                "}",
@@ -17083,10 +17191,10 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ((x - y) && (a ^ b))\n"
                "  f();\n",
                Spaces);
-  verifyFormat("for (int i = 0; i < 10; i = (i+1))\n"
+  verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
                "  foo(i);",
                Spaces);
-  verifyFormat("switch (x * (y + z)) {\n"
+  verifyFormat("switch (x / (y + z)) {\n"
                "default:\n"
                "  break;\n"
                "}",
@@ -17110,115 +17218,8 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("decltype(x) y = 42;", Spaces);
   verifyFormat("decltype((x)) y = z;", Spaces);
   verifyFormat("decltype((foo())) a = foo();", Spaces);
-  verifyFormat("decltype((bar(10))) a = bar( 11 );", Spaces);
+  verifyFormat("decltype((bar(10))) a = bar(11);", Spaces);
   verifyFormat("x = foo((a * (b - c)));", Spaces);
-
-  // Run the first set of tests again with:
-  Spaces.SpaceAfterCStyleCast = true;
-  verifyFormat("call(x, y, z);", Spaces);
-  verifyFormat("call( );", Spaces);
-  verifyFormat("std::function<void(int, int)> callback;", Spaces);
-  verifyFormat("while (( bool ) 1)\n"
-               "  continue;",
-               Spaces);
-  verifyFormat("for (;;)\n"
-               "  continue;",
-               Spaces);
-  verifyFormat("if (true)\n"
-               "  f( );\n"
-               "else if (true)\n"
-               "  f( );",
-               Spaces);
-  verifyFormat("do {\n"
-               "  do_something(( int ) i);\n"
-               "} while (something( ));",
-               Spaces);
-  verifyFormat("switch (x) {\n"
-               "default:\n"
-               "  break;\n"
-               "}",
-               Spaces);
-  verifyFormat("#define CONF_BOOL(x) ( bool * ) ( void * ) (x)", Spaces);
-  verifyFormat("#define CONF_BOOL(x) ( bool * ) (x)", Spaces);
-  verifyFormat("#define CONF_BOOL(x) ( bool ) (x)", Spaces);
-  verifyFormat("bool *y = ( bool * ) ( void * ) (x);", Spaces);
-  verifyFormat("bool *y = ( bool * ) (x);", Spaces);
-  verifyFormat("throw ( int32 ) x;", Spaces);
-  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
-  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
-  verifyFormat("void f( ) __attribute__((asdf));", Spaces);
-
-  // Run subset of tests again with:
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
-  Spaces.SpaceAfterCStyleCast = true;
-  verifyFormat("while ((bool) 1)\n"
-               "  continue;",
-               Spaces);
-  verifyFormat("do {\n"
-               "  do_something((int) i);\n"
-               "} while (something( ));",
-               Spaces);
-
-  verifyFormat("size_t idx = (size_t) (ptr - ((char *) file));", Spaces);
-  verifyFormat("size_t idx = (size_t) a;", Spaces);
-  verifyFormat("size_t idx = (size_t) (a - 1);", Spaces);
-  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
-  verifyFormat("#define CONF_BOOL(x) (bool *) (void *) (x)", Spaces);
-  verifyFormat("#define CONF_BOOL(x) (bool *) (void *) (int) (x)", Spaces);
-  verifyFormat("bool *y = (bool *) (void *) (x);", Spaces);
-  verifyFormat("bool *y = (bool *) (void *) (int) (x);", Spaces);
-  verifyFormat("bool *y = (bool *) (void *) (int) foo(x);", Spaces);
-  verifyFormat("throw (int32) x;", Spaces);
-  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
-  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
-  verifyFormat("void f( ) __attribute__((asdf));", Spaces);
-
-  Spaces.ColumnLimit = 80;
-  Spaces.IndentWidth = 4;
-  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
-  verifyFormat("void foo( ) {\n"
-               "    size_t foo = (*(function))(\n"
-               "        Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
-               "BarrrrrrrrrrrrLong,\n"
-               "        FoooooooooLooooong);\n"
-               "}",
-               Spaces);
-  Spaces.SpaceAfterCStyleCast = false;
-  verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
-  verifyFormat("size_t idx = (size_t)a;", Spaces);
-  verifyFormat("size_t idx = (size_t)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
-
-  verifyFormat("void foo( ) {\n"
-               "    size_t foo = (*(function))(\n"
-               "        Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
-               "BarrrrrrrrrrrrLong,\n"
-               "        FoooooooooLooooong);\n"
-               "}",
-               Spaces);
-
-  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
-  verifyFormat("void foo( ) {\n"
-               "    size_t foo = (*(function))(\n"
-               "        Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
-               "BarrrrrrrrrrrrLong,\n"
-               "        FoooooooooLooooong\n"
-               "    );\n"
-               "}",
-               Spaces);
-  verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
-  verifyFormat("size_t idx = (size_t)a;", Spaces);
-  verifyFormat("size_t idx = (size_t)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
-  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {

>From 5ee5e28c3a7b7769bf51addf0246b4bf7e5dab1c Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 16:11:33 -0700
Subject: [PATCH 09/16] fix conditionals logic to catch repeated parens on
 right

---
 clang/lib/Format/TokenAnnotator.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 20a82c012d2d0fd..c2e74730820cb93 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3972,7 +3972,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   }
   if (Style.SpacesInParensOptions.InConditionalStatements !=
       FormatStyle::SIPCS_Never) {
-    // TODO: check consecutive parens
     const FormatToken *LeftParen = nullptr;
     if (Left.is(tok::l_paren))
       LeftParen = &Left;
@@ -3985,10 +3984,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
             FormatStyle::SIPCS_Always) {
           return true;
         }
+        // check for non-repeated parens
         const FormatToken *RightParen = LeftParen->MatchingParen;
-        if (LeftParen->Next && LeftParen->Next->isNot(tok::l_paren))
-          return true;
-        if (RightParen && RightParen->Previous &&
+        if (LeftParen->Next && LeftParen->Next->isNot(tok::l_paren) &&
+            RightParen && RightParen->Previous &&
             RightParen->Previous->isNot(tok::r_paren)) {
           return true;
         }

>From a430cbd05225fbf27eae2d3f2cdd58aa50075239 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 17:42:45 -0700
Subject: [PATCH 10/16] Add support for SpacesInParens NonConsecutive options

---
 clang/lib/Format/TokenAnnotator.cpp | 71 ++++++++++++++---------------
 1 file changed, 33 insertions(+), 38 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c2e74730820cb93..b0905a319ba9553 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3970,30 +3970,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
        Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
     return Style.SpacesInParensOptions.InEmptyParentheses;
   }
-  if (Style.SpacesInParensOptions.InConditionalStatements !=
-      FormatStyle::SIPCS_Never) {
-    const FormatToken *LeftParen = nullptr;
-    if (Left.is(tok::l_paren))
-      LeftParen = &Left;
-    else if (Right.is(tok::r_paren) && Right.MatchingParen)
-      LeftParen = Right.MatchingParen;
-    if (LeftParen) {
-      if (LeftParen->is(TT_ConditionLParen) || (LeftParen->Previous &&
-              isKeywordWithCondition(*LeftParen->Previous))) {
-        if (Style.SpacesInParensOptions.InConditionalStatements ==
-            FormatStyle::SIPCS_Always) {
-          return true;
-        }
-        // check for non-repeated parens
-        const FormatToken *RightParen = LeftParen->MatchingParen;
-        if (LeftParen->Next && LeftParen->Next->isNot(tok::l_paren) &&
-            RightParen && RightParen->Previous &&
-            RightParen->Previous->isNot(tok::r_paren)) {
-          return true;
-        }
-      }
-    }
-  }
 
   // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
   if (Left.is(tok::kw_auto) && Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace,
@@ -4017,26 +3993,45 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     return true;
   }
 
-  // TODO: check consecutive parens
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren)) {
-    if (Right.is(TT_CastRParen) ||
-        (Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen))) {
-      return Style.SpacesInParensOptions.InCStyleCasts !=
-             FormatStyle::SIPCS_Never;
+    const FormatToken *LeftParen =
+        Left.is(tok::l_paren) ? &Left : Right.MatchingParen;
+    const FormatToken *RightParen =
+        LeftParen ? LeftParen->MatchingParen : nullptr;
+
+    auto NotConsecutiveParens = [&](auto *Left, auto *Right) {
+      return Left && Left->Next && Left->Next->isNot(tok::l_paren) && Right &&
+             Right->Previous && Right->Previous->isNot(tok::r_paren);
+    };
+    const auto AddSpace = [&](FormatStyle::SpacesInParensCustomStyle Option) {
+      if (Option == FormatStyle::SIPCS_Always)
+        return true;
+      if (Option == FormatStyle::SIPCS_NonConsecutive) {
+        if (NotConsecutiveParens(LeftParen, RightParen))
+          return true;
+      }
+      return false;
+    };
+
+    if (LeftParen && (LeftParen->is(TT_ConditionLParen) ||
+                      (LeftParen->Previous &&
+                       isKeywordWithCondition(*LeftParen->Previous)))) {
+      return AddSpace(Style.SpacesInParensOptions.InConditionalStatements);
     }
-    const auto isAttributeParen = [](const FormatToken *Paren) {
+    if (RightParen && RightParen->is(TT_CastRParen))
+      return AddSpace(Style.SpacesInParensOptions.InCStyleCasts);
+    const auto IsAttributeParen = [](const FormatToken *Paren) {
       return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
     };
-    if (isAttributeParen(&Left) || isAttributeParen(&Right)) {
-      return Style.SpacesInParensOptions.InAttributeSpecifiers ==
-             FormatStyle::SIPCS_Always;
+    if (IsAttributeParen(LeftParen) || IsAttributeParen(RightParen))
+      return AddSpace(Style.SpacesInParensOptions.InAttributeSpecifiers);
+    if ((LeftParen && IsAttributeParen(LeftParen->Previous)) ||
+        (RightParen && IsAttributeParen(RightParen->Next))) {
+      return AddSpace(Style.SpacesInParensOptions.InAttributeSpecifiers);
     }
-    if (isAttributeParen(Left.Previous) || isAttributeParen(Right.Next)) {
-      return Style.SpacesInParensOptions.InAttributeSpecifiers !=
-             FormatStyle::SIPCS_Never;
-    }
-    return Style.SpacesInParensOptions.Other != FormatStyle::SIPCS_Never;
+    return AddSpace(Style.SpacesInParensOptions.Other);
   }
+
   if (Right.isOneOf(tok::semi, tok::comma))
     return false;
   if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) {

>From 087d3f6b3a2b98dde68b4acd429932589257df0c Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 17:49:37 -0700
Subject: [PATCH 11/16] Minor fix in Format.h documentation and redump

---
 clang/docs/ClangFormatStyleOptions.rst | 4 ++--
 clang/include/clang/Format/Format.h    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index d25273d95e2f245..7d9c75d82926cb0 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5773,8 +5773,8 @@ the configuration (without a prefix: ``Auto``).
 
     .. code-block:: c++
 
-      Always:                                  false:
-      x = ( int32 )y                 vs.     x = (int32)y
+      Always:
+      x = ( int32 )y
       y = (( int (*)(int) )foo)(x);
 
     .. code-block:: c++
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 8f022593d66c029..a4b4d0787876f54 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4586,8 +4586,8 @@ struct FormatStyle {
     SpacesInParensCustomStyle InConditionalStatements;
     /// Put a space in C style casts.
     /// \code
-    ///   Always:                                  false:
-    ///   x = ( int32 )y                 vs.     x = (int32)y
+    ///   Always:
+    ///   x = ( int32 )y
     ///   y = (( int (*)(int) )foo)(x);
     /// \endcode
     /// \code

>From 9f9f46878425767753a8c8fd83b45e4cf5026e88 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 17:58:10 -0700
Subject: [PATCH 12/16] FormatTest: fix whitespace problems

---
 clang/unittests/Format/FormatTest.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ad2bf63838aff04..ceac4f7e7d695e6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17082,7 +17082,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
       FormatStyle::SIPCS_NonConsecutive;
   verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
   verifyFormat("void __attribute__(( naked )) foo(int bar)", Spaces);
-  verifyFormat("void f() __attribute__(( asdf ));", Spaces); 
+  verifyFormat("void f() __attribute__(( asdf ));", Spaces);
   Spaces.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
@@ -17099,7 +17099,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
-  Spaces.SpacesInParensOptions = {}; 
+  Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.InConditionalStatements =
       FormatStyle::SIPCS_Always;
   verifyFormat("while ( (bool)1 )\n"
@@ -17201,7 +17201,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
-  Spaces.SpacesInParensOptions = {}; 
+  Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
   verifyFormat("decltype( x ) y = 42;", Spaces);
   verifyFormat("decltype( ( x ) ) y = z;", Spaces);

>From 9f081517cec8811734d9d7af812f355b0f34ad8e Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 18:01:47 -0700
Subject: [PATCH 13/16] Format.h: whitespace

---
 clang/include/clang/Format/Format.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index a4b4d0787876f54..8eed69b59b8085b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4631,7 +4631,7 @@ struct FormatStyle {
     ///   Never:
     ///   t f(Deleted &) & = delete;
     ///   decltype((x))
-    ///   x = ((int32))y 
+    ///   x = ((int32))y
     ///   y = ((int (*)(int))foo)(x);
     /// \endcode
     SpacesInParensCustomStyle Other;

>From 54b8f88c5fa9d465043e54d9c94327127ce777fd Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Thu, 11 Jan 2024 18:05:55 -0700
Subject: [PATCH 14/16] Remember to run clang-format locally

---
 clang/include/clang/Format/Format.h        |  5 ++---
 clang/unittests/Format/ConfigParseTest.cpp | 24 +++++++++++-----------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 8eed69b59b8085b..b0d432dc1fb6528 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4638,9 +4638,8 @@ struct FormatStyle {
 
     SpacesInParensCustom()
         : InAttributeSpecifiers(SIPCS_Never),
-          InConditionalStatements(SIPCS_Never),
-          InCStyleCasts(SIPCS_Never), InEmptyParentheses(false),
-          Other(SIPCS_Never) {}
+          InConditionalStatements(SIPCS_Never), InCStyleCasts(SIPCS_Never),
+          InEmptyParentheses(false), Other(SIPCS_Never) {}
 
     SpacesInParensCustom(SpacesInParensCustomStyle InAttributeSpecifiers,
                          SpacesInParensCustomStyle InConditionalStatements,
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 0cd3aec53ab28d3..77c48f9eb0a14dd 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -657,27 +657,27 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Always,
-              FormatStyle::SIPCS_Always, FormatStyle::SIPCS_Never, false,
-              FormatStyle::SIPCS_Always));
+              FormatStyle::SpacesInParensCustom(
+                  FormatStyle::SIPCS_Always, FormatStyle::SIPCS_Always,
+                  FormatStyle::SIPCS_Never, false, FormatStyle::SIPCS_Always));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never,
-              FormatStyle::SIPCS_Always, FormatStyle::SIPCS_Never, false,
-              FormatStyle::SIPCS_Never));
+              FormatStyle::SpacesInParensCustom(
+                  FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Always,
+                  FormatStyle::SIPCS_Never, false, FormatStyle::SIPCS_Never));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never,
-              FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Always, false,
-              FormatStyle::SIPCS_Never));
+              FormatStyle::SpacesInParensCustom(
+                  FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Never,
+                  FormatStyle::SIPCS_Always, false, FormatStyle::SIPCS_Never));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(FormatStyle::SIPCS_Never,
-              FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Never, true,
-              FormatStyle::SIPCS_Never));
+              FormatStyle::SpacesInParensCustom(
+                  FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Never,
+                  FormatStyle::SIPCS_Never, true, FormatStyle::SIPCS_Never));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 

>From dbc3ea4912700b35540568ce064f4b6237904511 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Fri, 12 Jan 2024 14:50:46 -0700
Subject: [PATCH 15/16] Address review requests

---
 clang/lib/Format/TokenAnnotator.cpp   | 6 +++---
 clang/unittests/Format/FormatTest.cpp | 8 +++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index b0905a319ba9553..5ce0064cbd58e34 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4006,9 +4006,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     const auto AddSpace = [&](FormatStyle::SpacesInParensCustomStyle Option) {
       if (Option == FormatStyle::SIPCS_Always)
         return true;
-      if (Option == FormatStyle::SIPCS_NonConsecutive) {
-        if (NotConsecutiveParens(LeftParen, RightParen))
-          return true;
+      if (Option == FormatStyle::SIPCS_NonConsecutive &&
+          NotConsecutiveParens(LeftParen, RightParen)) {
+        return true;
       }
       return false;
     };
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ceac4f7e7d695e6..22a07b23bc6456d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17078,22 +17078,24 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
   verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
   verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
+
   Spaces.SpacesInParensOptions.InAttributeSpecifiers =
       FormatStyle::SIPCS_NonConsecutive;
   verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
   verifyFormat("void __attribute__(( naked )) foo(int bar)", Spaces);
   verifyFormat("void f() __attribute__(( asdf ));", Spaces);
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers = FormatStyle::SIPCS_Never;
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
   verifyFormat("x = ( int32 )y;", Spaces);
   verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
+
   Spaces.SpacesInParensOptions.InCStyleCasts =
       FormatStyle::SIPCS_NonConsecutive;
   verifyFormat("x = ( int32 )y;", Spaces);
   verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
+
   Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
   verifyFormat("x = (int32)y;", Spaces);
   verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
@@ -17133,6 +17135,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                "  break;\n"
                "}",
                Spaces);
+
   Spaces.SpacesInParensOptions.InConditionalStatements =
       FormatStyle::SIPCS_NonConsecutive;
   verifyFormat("while ((bool)1)\n"
@@ -17166,6 +17169,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                "  break;\n"
                "}",
                Spaces);
+
   Spaces.SpacesInParensOptions.InConditionalStatements =
       FormatStyle::SIPCS_Never;
   verifyFormat("while ((bool)1)\n"
@@ -17208,12 +17212,14 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces);
   verifyFormat("decltype( ( bar( 10 ) ) ) a = bar( 11 );", Spaces);
   verifyFormat("x = foo( ( a * ( b - c ) ) );", Spaces);
+
   Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_NonConsecutive;
   verifyFormat("decltype( x ) y = 42;", Spaces);
   verifyFormat("decltype(( x )) y = z;", Spaces);
   verifyFormat("decltype((foo())) a = foo();", Spaces);
   verifyFormat("decltype((bar( 10 ))) a = bar( 11 );", Spaces);
   verifyFormat("x = foo((a * ( b - c )));", Spaces);
+
   Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Never;
   verifyFormat("decltype(x) y = 42;", Spaces);
   verifyFormat("decltype((x)) y = z;", Spaces);

>From d5a563bc60fa575aca74b13a0714e2525b2a8ed0 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Mon, 22 Jan 2024 22:11:39 -0700
Subject: [PATCH 16/16] Only filter doubled parens situationally like
 RemoveParentheses

---
 clang/docs/ClangFormatStyleOptions.rst       | 114 +++--------
 clang/docs/ReleaseNotes.rst                  |   7 +-
 clang/include/clang/Format/Format.h          |  94 ++++-----
 clang/lib/Format/Format.cpp                  |  36 +---
 clang/lib/Format/TokenAnnotator.cpp          |  53 +++--
 clang/unittests/Format/ConfigParseTest.cpp   |  54 ++----
 clang/unittests/Format/FormatTest.cpp        | 193 ++++++++++++++-----
 clang/unittests/Format/FormatTestVerilog.cpp |   6 +-
 8 files changed, 271 insertions(+), 286 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 7d9c75d82926cb0..3af269cf2d14ef1 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5688,8 +5688,8 @@ the configuration (without a prefix: ``Auto``).
     # Example of usage:
     SpacesInParens: Custom
     SpacesInParensOptions:
-      InAttributeSpecifiers: NonConsecutive
-      InConditionalStatements: Always
+      InAttributeSpecifiers: false
+      InConditionalStatements: true
       InEmptyParentheses: true
 
   Nested configuration flags:
@@ -5704,103 +5704,60 @@ the configuration (without a prefix: ``Auto``).
       InConditionalStatements: true
       Other: true
 
-  * ``SpacesInParensCustomStyle InAttributeSpecifiers``
-    Put a space in parentheses of attribute specifiers.
+  * ``bool ExceptDoubleParentheses`` Override any of the following options to prevent addition of space
+    between the first two parentheses in situations where a pair of
+    parentheses have been used.
 
     .. code-block:: c++
 
-       Always:
-       __attribute__( ( noreturn ) )
+      true:
+      __attribute__(( noreturn ))
+      __decltype__(( x ))
+      if (( a = b ))
+     false:
+       Uses the applicable option.
+
+  * ``bool InAttributeSpecifiers`` Put a space in parentheses of attribute specifiers.
 
     .. code-block:: c++
 
-       NonConsecutive:
-       _attribute__(( noreturn ))
+       true:
+       __attribute__( ( noreturn ) )
 
     .. code-block:: c++
 
-       Never:
+       false:
        _attribute__((noreturn))
 
-    Possible values:
-
-    * ``SIPCS_Never`` (in configuration: ``Never``)
-      Never put spaces in parens.
-
-    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
-      Only put spaces in parens not followed by the same consecutive parens.
-
-    * ``SIPCS_Always`` (in configuration: ``Always``)
-      Always put spaces in parens.
-
-
-  * ``SpacesInParensCustomStyle InConditionalStatements``
-    Put a space in parentheses only inside conditional statements
+  * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements
     (``for/if/while/switch...``).
 
     .. code-block:: c++
 
-       Always:
+       true:
        if ( ( a ) )  { ... }
        while ( i < 5 )  { ... }
 
     .. code-block:: c++
 
-      NonConsecutive:
-      if (( a )) { ... }
-      while ( i < 5 ) { ... }
-
-    .. code-block:: c++
-
-      Never:
+      false:
       if ((a)) { ... }
       while (i < 5) { ... }
 
-    Possible values:
-
-    * ``SIPCS_Never`` (in configuration: ``Never``)
-      Never put spaces in parens.
-
-    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
-      Only put spaces in parens not followed by the same consecutive parens.
-
-    * ``SIPCS_Always`` (in configuration: ``Always``)
-      Always put spaces in parens.
-
-
-  * ``SpacesInParensCustomStyle InCStyleCasts``
-    Put a space in C style casts.
+  * ``bool InCStyleCasts`` Put a space in C style casts.
 
     .. code-block:: c++
 
-      Always:
+      true:
       x = ( int32 )y
       y = (( int (*)(int) )foo)(x);
 
     .. code-block:: c++
 
-      NonConsecutive:
-      x = ( int32 )y
-      y = ((int (*)(int))foo)(x);
-
-    .. code-block:: c++
-
-      Never:
+      false:
       x = (int32)y
       y = ((int (*)(int))foo)(x);
 
-    Possible values:
-
-    * ``SIPCS_Never`` (in configuration: ``Never``)
-      Never put spaces in parens.
-
-    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
-      Only put spaces in parens not followed by the same consecutive parens.
-
-    * ``SIPCS_Always`` (in configuration: ``Always``)
-      Always put spaces in parens.
-
-
   * ``bool InEmptyParentheses`` Put a space in parentheses only if the parentheses are empty i.e. '()'
 
     .. code-block:: c++
@@ -5813,12 +5770,11 @@ the configuration (without a prefix: ``Auto``).
          }                                    }
        }                                    }
 
-  * ``SpacesInParensCustomStyle Other``
-    Put a space in parentheses not covered by preceding options.
+  * ``bool Other`` Put a space in parentheses not covered by preceding options.
 
     .. code-block:: c++
 
-      Always:
+      true:
       t f( Deleted & ) & = delete;
       decltype( ( x ) )
       x = ( (int32)y )
@@ -5826,32 +5782,12 @@ the configuration (without a prefix: ``Auto``).
 
     .. code-block:: c++
 
-      NonConsecutive:
-      t f( Deleted & ) & = delete;
-      decltype(( x ))
-      x = ((int32))y
-      y = ((int ( * )( int ))foo)( x );
-
-    .. code-block:: c++
-
-      Never:
+      false:
       t f(Deleted &) & = delete;
       decltype((x))
       x = ((int32))y
       y = ((int (*)(int))foo)(x);
 
-    Possible values:
-
-    * ``SIPCS_Never`` (in configuration: ``Never``)
-      Never put spaces in parens.
-
-    * ``SIPCS_NonConsecutive`` (in configuration: ``NonConsecutive``)
-      Only put spaces in parens not followed by the same consecutive parens.
-
-    * ``SIPCS_Always`` (in configuration: ``Always``)
-      Always put spaces in parens.
-
-
 
 .. _SpacesInParentheses:
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed77f0503f6b189..bcc7157ca5f3859 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1284,10 +1284,9 @@ clang-format
 - Add ``SkipMacroDefinitionBody`` option.
 - Add ``InAttributeSpecifiers`` style option to ``SpacesInParensOptions``
   to control addition of spaces after the ``__attribute__`` keyword.
-- Add ``NonConsecutive`` sub-option for ``InAttributeSpecifiers``,
-  ``InConditionalStatements``, ``InCStyleCasts``, and ``Other`` options of
-  ``SpacesInParensOptions`` to control addition of spaces between consecutive
-  parentheses.
+- Add ``ExceptDoubleParentheses`` sub-option for ``SpacesInParensOptions``
+  to override addition of spaces between multiple, non-redundant parentheses
+  similar to the rules used for ``RemoveParentheses``.
 
 libclang
 --------
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index b0d432dc1fb6528..e9052bd474df0a9 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4533,16 +4533,6 @@ struct FormatStyle {
   /// \version 17
   SpacesInParensStyle SpacesInParens;
 
-  /// Selective control over spaces in parens.
-  enum SpacesInParensCustomStyle : int8_t {
-    /// Never put spaces in parens.
-    SIPCS_Never,
-    /// Only put spaces in parens not followed by the same consecutive parens.
-    SIPCS_NonConsecutive,
-    /// Always put spaces in parens.
-    SIPCS_Always
-  };
-
   /// Precise control over the spacing in parentheses.
   /// \code
   ///   # Should be declared this way:
@@ -4552,55 +4542,53 @@ struct FormatStyle {
   ///     Other: true
   /// \endcode
   struct SpacesInParensCustom {
-    /// Put a space in parentheses of attribute specifiers.
+    /// Override any of the following options to prevent addition of space
+    /// between the first two parentheses in situations where a pair of
+    /// parentheses have been used.
     /// \code
-    ///    Always:
-    ///    __attribute__( ( noreturn ) )
+    ///   true:
+    ///   __attribute__(( noreturn ))
+    ///   __decltype__(( x ))
+    ///   if (( a = b ))
     /// \endcode
+    ///  false:
+    ///    Uses the applicable option.
+    bool ExceptDoubleParentheses;
+    /// Put a space in parentheses of attribute specifiers.
     /// \code
-    ///    NonConsecutive:
-    ///    _attribute__(( noreturn ))
+    ///    true:
+    ///    __attribute__( ( noreturn ) )
     /// \endcode
     /// \code
-    ///    Never:
+    ///    false:
     ///    _attribute__((noreturn))
     /// \endcode
-    SpacesInParensCustomStyle InAttributeSpecifiers;
+    bool InAttributeSpecifiers;
     /// Put a space in parentheses only inside conditional statements
     /// (``for/if/while/switch...``).
     /// \code
-    ///    Always:
+    ///    true:
     ///    if ( ( a ) )  { ... }
     ///    while ( i < 5 )  { ... }
     /// \endcode
     /// \code
-    ///   NonConsecutive:
-    ///   if (( a )) { ... }
-    ///   while ( i < 5 ) { ... }
-    /// \endcode
-    /// \code
-    ///   Never:
+    ///   false:
     ///   if ((a)) { ... }
     ///   while (i < 5) { ... }
     /// \endcode
-    SpacesInParensCustomStyle InConditionalStatements;
+    bool InConditionalStatements;
     /// Put a space in C style casts.
     /// \code
-    ///   Always:
+    ///   true:
     ///   x = ( int32 )y
     ///   y = (( int (*)(int) )foo)(x);
     /// \endcode
     /// \code
-    ///   NonConsecutive:
-    ///   x = ( int32 )y
-    ///   y = ((int (*)(int))foo)(x);
-    /// \endcode
-    /// \code
-    ///   Never:
+    ///   false:
     ///   x = (int32)y
     ///   y = ((int (*)(int))foo)(x);
     /// \endcode
-    SpacesInParensCustomStyle InCStyleCasts;
+    bool InCStyleCasts;
     /// Put a space in parentheses only if the parentheses are empty i.e. '()'
     /// \code
     ///    true:                                false:
@@ -4614,45 +4602,39 @@ struct FormatStyle {
     bool InEmptyParentheses;
     /// Put a space in parentheses not covered by preceding options.
     /// \code
-    ///   Always:
+    ///   true:
     ///   t f( Deleted & ) & = delete;
     ///   decltype( ( x ) )
     ///   x = ( (int32)y )
     ///   y = ( (int ( * )( int ))foo )( x );
     /// \endcode
     /// \code
-    ///   NonConsecutive:
-    ///   t f( Deleted & ) & = delete;
-    ///   decltype(( x ))
-    ///   x = ((int32))y
-    ///   y = ((int ( * )( int ))foo)( x );
-    /// \endcode
-    /// \code
-    ///   Never:
+    ///   false:
     ///   t f(Deleted &) & = delete;
     ///   decltype((x))
     ///   x = ((int32))y
     ///   y = ((int (*)(int))foo)(x);
     /// \endcode
-    SpacesInParensCustomStyle Other;
+    bool Other;
 
     SpacesInParensCustom()
-        : InAttributeSpecifiers(SIPCS_Never),
-          InConditionalStatements(SIPCS_Never), InCStyleCasts(SIPCS_Never),
-          InEmptyParentheses(false), Other(SIPCS_Never) {}
-
-    SpacesInParensCustom(SpacesInParensCustomStyle InAttributeSpecifiers,
-                         SpacesInParensCustomStyle InConditionalStatements,
-                         SpacesInParensCustomStyle InCStyleCasts,
-                         bool InEmptyParentheses,
-                         SpacesInParensCustomStyle Other)
-        : InAttributeSpecifiers(InAttributeSpecifiers),
+        : ExceptDoubleParentheses(false), InAttributeSpecifiers(false),
+          InConditionalStatements(false), InCStyleCasts(false),
+          InEmptyParentheses(false), Other(false) {}
+
+    SpacesInParensCustom(bool ExceptDoubleParentheses,
+                         bool InAttributeSpecifiers,
+                         bool InConditionalStatements, bool InCStyleCasts,
+                         bool InEmptyParentheses, bool Other)
+        : ExceptDoubleParentheses(ExceptDoubleParentheses),
+          InAttributeSpecifiers(InAttributeSpecifiers),
           InConditionalStatements(InConditionalStatements),
           InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses),
           Other(Other) {}
 
     bool operator==(const SpacesInParensCustom &R) const {
-      return InAttributeSpecifiers == R.InAttributeSpecifiers &&
+      return ExceptDoubleParentheses == R.ExceptDoubleParentheses &&
+             InAttributeSpecifiers == R.InAttributeSpecifiers &&
              InConditionalStatements == R.InConditionalStatements &&
              InCStyleCasts == R.InCStyleCasts &&
              InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
@@ -4671,8 +4653,8 @@ struct FormatStyle {
   ///   # Example of usage:
   ///   SpacesInParens: Custom
   ///   SpacesInParensOptions:
-  ///     InAttributeSpecifiers: NonConsecutive
-  ///     InConditionalStatements: Always
+  ///     InAttributeSpecifiers: false
+  ///     InConditionalStatements: true
   ///     InEmptyParentheses: true
   /// \endcode
   /// \version 17
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 26504319223d17c..d7d7a67cfb53a6c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -750,22 +750,9 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
   }
 };
 
-template <>
-struct ScalarEnumerationTraits<FormatStyle::SpacesInParensCustomStyle> {
-  static void enumeration(IO &IO,
-                          FormatStyle::SpacesInParensCustomStyle &Value) {
-    IO.enumCase(Value, "Never", FormatStyle::SIPCS_Never);
-    IO.enumCase(Value, "NonConsecutive", FormatStyle::SIPCS_NonConsecutive);
-    IO.enumCase(Value, "Always", FormatStyle::SIPCS_Always);
-
-    // For backward compatibility.
-    IO.enumCase(Value, "true", FormatStyle::SIPCS_Always);
-    IO.enumCase(Value, "false", FormatStyle::SIPCS_Never);
-  }
-};
-
 template <> struct MappingTraits<FormatStyle::SpacesInParensCustom> {
   static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
+    IO.mapOptional("ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
     IO.mapOptional("InAttributeSpecifiers", Spaces.InAttributeSpecifiers);
     IO.mapOptional("InCStyleCasts", Spaces.InCStyleCasts);
     IO.mapOptional("InConditionalStatements", Spaces.InConditionalStatements);
@@ -1205,27 +1192,22 @@ template <> struct MappingTraits<FormatStyle> {
     if (Style.SpacesInParens != FormatStyle::SIPO_Custom &&
         (SpacesInParentheses || SpaceInEmptyParentheses ||
          SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
-      const auto CoerceBooleanToSIPCS = [](const bool enabled) {
-        return enabled ? FormatStyle::SIPCS_Always : FormatStyle::SIPCS_Never;
-      };
       if (SpacesInParentheses) {
-        // set all options except InCStyleCasts and InEmptyParentheses
-        // to true/Always for backward compatibility.
-        Style.SpacesInParensOptions.InAttributeSpecifiers =
-            FormatStyle::SIPCS_Always;
-        Style.SpacesInParensOptions.InConditionalStatements =
-            FormatStyle::SIPCS_Always;
+        // for backward compatibility.
+        Style.SpacesInParensOptions.ExceptDoubleParentheses = false;
+        Style.SpacesInParensOptions.InAttributeSpecifiers = true;
+        Style.SpacesInParensOptions.InConditionalStatements = true;
         Style.SpacesInParensOptions.InCStyleCasts =
-            CoerceBooleanToSIPCS(SpacesInCStyleCastParentheses);
+            SpacesInCStyleCastParentheses;
         Style.SpacesInParensOptions.InEmptyParentheses =
             SpaceInEmptyParentheses;
-        Style.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+        Style.SpacesInParensOptions.Other = true;
       } else {
         Style.SpacesInParensOptions = {};
         Style.SpacesInParensOptions.InConditionalStatements =
-            CoerceBooleanToSIPCS(SpacesInConditionalStatement);
+            SpacesInConditionalStatement;
         Style.SpacesInParensOptions.InCStyleCasts =
-            CoerceBooleanToSIPCS(SpacesInCStyleCastParentheses);
+            SpacesInCStyleCastParentheses;
         Style.SpacesInParensOptions.InEmptyParentheses =
             SpaceInEmptyParentheses;
       }
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5ce0064cbd58e34..e941135e57eb1a6 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3551,8 +3551,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
     if (Current->is(TT_LineComment)) {
       if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
         Current->SpacesRequiredBefore =
-            (Style.Cpp11BracedListStyle &&
-             Style.SpacesInParensOptions.Other == FormatStyle::SIPCS_Never)
+            (Style.Cpp11BracedListStyle && !Style.SpacesInParensOptions.Other)
                 ? 0
                 : 1;
       } else if (Prev->is(TT_VerilogMultiLineListLParen)) {
@@ -3998,19 +3997,36 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
         Left.is(tok::l_paren) ? &Left : Right.MatchingParen;
     const FormatToken *RightParen =
         LeftParen ? LeftParen->MatchingParen : nullptr;
-
-    auto NotConsecutiveParens = [&](auto *Left, auto *Right) {
-      return Left && Left->Next && Left->Next->isNot(tok::l_paren) && Right &&
-             Right->Previous && Right->Previous->isNot(tok::r_paren);
+    const auto IsAttributeParen = [](const FormatToken *Paren) {
+      return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
     };
-    const auto AddSpace = [&](FormatStyle::SpacesInParensCustomStyle Option) {
-      if (Option == FormatStyle::SIPCS_Always)
-        return true;
-      if (Option == FormatStyle::SIPCS_NonConsecutive &&
-          NotConsecutiveParens(LeftParen, RightParen)) {
-        return true;
-      }
-      return false;
+    auto AddSpaceInDoubleParens = [&]() {
+      const auto *RPrev = RightParen ? RightParen->Previous : nullptr;
+      const auto *LNext = LeftParen->Next;
+      const auto *LPrev = LeftParen->Previous;
+      const bool DoubleParens =
+          RPrev && RPrev->is(tok::r_paren) && LNext && LNext->is(tok::l_paren);
+      auto HasEqualBeforeNextParen = [&]() {
+        auto *Tok = LNext;
+        if (!Tok || !Tok->is(tok::l_paren))
+          return false;
+        while ((Tok = Tok->Next) && !Tok->isOneOf(tok::l_paren, tok::r_paren))
+          if (Tok->is(tok::equal))
+            return true;
+        return false;
+      };
+      const bool SuppressSpace =
+          IsAttributeParen(LeftParen) ||
+          (LPrev && (LPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) ||
+                     (HasEqualBeforeNextParen() &&
+                      (LPrev->isOneOf(tok::kw_if, tok::kw_while) ||
+                       LPrev->endsSequence(tok::kw_constexpr, tok::kw_if)))));
+      return !(DoubleParens && SuppressSpace);
+    };
+    const auto AddSpace = [&](bool Option) {
+      if (Style.SpacesInParensOptions.ExceptDoubleParentheses && Option)
+        return AddSpaceInDoubleParens();
+      return Option;
     };
 
     if (LeftParen && (LeftParen->is(TT_ConditionLParen) ||
@@ -4020,9 +4036,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     }
     if (RightParen && RightParen->is(TT_CastRParen))
       return AddSpace(Style.SpacesInParensOptions.InCStyleCasts);
-    const auto IsAttributeParen = [](const FormatToken *Paren) {
-      return Paren && Paren->isOneOf(TT_AttributeLParen, TT_AttributeRParen);
-    };
     if (IsAttributeParen(LeftParen) || IsAttributeParen(RightParen))
       return AddSpace(Style.SpacesInParensOptions.InAttributeSpecifiers);
     if ((LeftParen && IsAttributeParen(LeftParen->Previous)) ||
@@ -4253,8 +4266,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   if ((Left.is(tok::l_brace) && Left.isNot(BK_Block)) ||
       (Right.is(tok::r_brace) && Right.MatchingParen &&
        Right.MatchingParen->isNot(BK_Block))) {
-    return !Style.Cpp11BracedListStyle ||
-           (Style.SpacesInParensOptions.Other != FormatStyle::SIPCS_Never);
+    return !Style.Cpp11BracedListStyle || Style.SpacesInParensOptions.Other;
   }
   if (Left.is(TT_BlockComment)) {
     // No whitespace in x(/*foo=*/1), except for JavaScript.
@@ -4944,8 +4956,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
            !(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
                           tok::kw___super, TT_TemplateOpener,
                           TT_TemplateCloser)) ||
-           (Left.is(tok::l_paren) &&
-            Style.SpacesInParensOptions.Other != FormatStyle::SIPCS_Always);
+           (Left.is(tok::l_paren) && Style.SpacesInParensOptions.Other);
   }
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
     return ShouldAddSpacesInAngles();
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 77c48f9eb0a14dd..cc97c0cf6138d03 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -232,6 +232,12 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, ExceptDoubleParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InAttributeSpecifiers);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, Other);
 }
 
 #undef CHECK_PARSE_BOOL
@@ -623,32 +629,6 @@ TEST(ConfigParseTest, ParsesConfiguration) {
               SpaceBeforeParensOptions.AfterPlacementOperator,
               FormatStyle::SpaceBeforeParensCustom::APO_Leave);
 
-#define CHECK_SPACES_IN_PARENS_OPTIONS(FIELD)                                  \
-  do {                                                                         \
-    Style.SpacesInParens = FormatStyle::SIPO_Custom;                           \
-    Style.SpacesInParensOptions.FIELD = FormatStyle::SIPCS_Never;              \
-    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": Always",                \
-                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Always);       \
-    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": Never",                 \
-                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Never);        \
-    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": NonConsecutive",        \
-                SpacesInParensOptions.FIELD,                                   \
-                FormatStyle::SIPCS_NonConsecutive);                            \
-    /* For backwards compatibility */                                          \
-    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": false",                 \
-                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Never);        \
-    CHECK_PARSE("SpacesInParensOptions:\n  " #FIELD ": true",                  \
-                SpacesInParensOptions.FIELD, FormatStyle::SIPCS_Always);       \
-  } while (false)
-
-  CHECK_SPACES_IN_PARENS_OPTIONS(InAttributeSpecifiers);
-  CHECK_SPACES_IN_PARENS_OPTIONS(InConditionalStatements);
-  CHECK_SPACES_IN_PARENS_OPTIONS(InCStyleCasts);
-  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
-  CHECK_SPACES_IN_PARENS_OPTIONS(Other);
-
-#undef CHECK_SPACES_IN_PARENS_OPTIONS
-
   // For backward compatibility:
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
@@ -656,28 +636,24 @@ TEST(ConfigParseTest, ParsesConfiguration) {
               FormatStyle::SIPO_Custom);
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
-  CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(
-                  FormatStyle::SIPCS_Always, FormatStyle::SIPCS_Always,
-                  FormatStyle::SIPCS_Never, false, FormatStyle::SIPCS_Always));
+  CHECK_PARSE(
+      "SpacesInParentheses: true", SpacesInParensOptions,
+      FormatStyle::SpacesInParensCustom(false, true, true, false, false, true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(
-                  FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Always,
-                  FormatStyle::SIPCS_Never, false, FormatStyle::SIPCS_Never));
+              FormatStyle::SpacesInParensCustom(false, false, true, false,
+                                                false, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(
-                  FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Never,
-                  FormatStyle::SIPCS_Always, false, FormatStyle::SIPCS_Never));
+              FormatStyle::SpacesInParensCustom(false, false, false, true,
+                                                false, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-              FormatStyle::SpacesInParensCustom(
-                  FormatStyle::SIPCS_Never, FormatStyle::SIPCS_Never,
-                  FormatStyle::SIPCS_Never, true, FormatStyle::SIPCS_Never));
+              FormatStyle::SpacesInParensCustom(false, false, false, false,
+                                                true, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 22a07b23bc6456d..a9d389cf5dc1bea 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11174,14 +11174,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Deleted &operator=(const Deleted &) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces);
   verifyFormat("Deleted &operator=(const Deleted &) &;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
-  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InCStyleCasts = false;
+  Spaces.SpacesInParensOptions.Other = true;
   verifyFormat("Deleted &operator=( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
                Spaces);
@@ -13747,7 +13747,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   FormatStyle SpaceBetweenBraces = getLLVMStyle();
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
   SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
-  SpaceBetweenBraces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+  SpaceBetweenBraces.SpacesInParensOptions.Other = true;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -16848,11 +16848,9 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
-  Spaces.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_Always;
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers =
-      FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16902,7 +16900,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Type *A = ( Type * )P;", Spaces);
   verifyFormat("Type *A = ( vector<Type *, int *> )P;", Spaces);
   verifyFormat("x = ( int32 )y;", Spaces);
@@ -16917,7 +16915,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.InEmptyParentheses = true;
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("call(x, y, z);", Spaces);
   verifyFormat("call( );", Spaces);
   verifyFormat("std::function<void(int, int)> callback;", Spaces);
@@ -16998,7 +16996,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
   // Run subset of tests again with:
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
+  Spaces.SpacesInParensOptions.InCStyleCasts = false;
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("while ((bool) 1)\n"
                "  continue;",
@@ -17069,44 +17067,60 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
 
-  // Check NonConsecutive spaces
+  // Check ExceptDoubleParentheses spaces
   Spaces.IndentWidth = 2;
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers =
-      FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
   verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
   verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
+  verifyFormat("__attribute__( ( __aligned__(x) ) ) z;", Spaces);
+  verifyFormat("int x __attribute__( ( aligned(16) ) ) = 0;", Spaces);
+  verifyFormat("class __declspec( dllimport ) X {};", Spaces);
+  verifyFormat("class __declspec( ( dllimport ) ) X {};", Spaces);
 
-  Spaces.SpacesInParensOptions.InAttributeSpecifiers =
-      FormatStyle::SIPCS_NonConsecutive;
+  Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
   verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
   verifyFormat("void __attribute__(( naked )) foo(int bar)", Spaces);
   verifyFormat("void f() __attribute__(( asdf ));", Spaces);
+  verifyFormat("__attribute__(( __aligned__(x) )) z;", Spaces);
+  verifyFormat("int x __attribute__(( aligned(16) )) = 0;", Spaces);
+  verifyFormat("class __declspec( dllimport ) X {};", Spaces);
+  verifyFormat("class __declspec(( dllimport )) X {};", Spaces);
+
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = false;
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
+  verifyFormat("void f() __attribute__((asdf));", Spaces);
+  verifyFormat("__attribute__((__aligned__(x))) z;", Spaces);
+  verifyFormat("int x __attribute__((aligned(16))) = 0;", Spaces);
+  verifyFormat("class __declspec(dllimport) X {};", Spaces);
+  verifyFormat("class __declspec((dllimport)) X {};", Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("x = ( int32 )y;", Spaces);
   verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
 
-  Spaces.SpacesInParensOptions.InCStyleCasts =
-      FormatStyle::SIPCS_NonConsecutive;
+  Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
   verifyFormat("x = ( int32 )y;", Spaces);
-  verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
+  verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
 
-  Spaces.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
+  Spaces.SpacesInParensOptions.InCStyleCasts = false;
   verifyFormat("x = (int32)y;", Spaces);
   verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("while ( (bool)1 )\n"
                "  continue;",
                Spaces);
+  verifyFormat("while ( (i = j) )\n"
+               "  continue;",
+               Spaces);
   verifyFormat("for ( ;; )\n"
                "  continue;",
                Spaces);
@@ -17119,6 +17133,10 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                "  do_something((int)i);\n"
                "} while ( something() );",
                Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int)i);\n"
+               "} while ( (i = i + 1) );",
+               Spaces);
   verifyFormat("switch ( x ) {\n"
                "default:\n"
                "  break;\n"
@@ -17127,6 +17145,9 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ( (x - y) && (a ^ b) )\n"
                "  f();\n",
                Spaces);
+  verifyFormat("if ( (i = j) )\n"
+               "  do_something(i);",
+               Spaces);
   verifyFormat("for ( int i = 0; i < 10; i = (i + 1) )\n"
                "  foo(i);",
                Spaces);
@@ -17135,10 +17156,18 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                "  break;\n"
                "}",
                Spaces);
+  verifyFormat("if constexpr ( (a = b) )\n"
+               "  c;",
+               Spaces);
+  verifyFormat("if ( ({ a; }) )\n"
+               "  b;",
+               Spaces);
 
-  Spaces.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_NonConsecutive;
-  verifyFormat("while ((bool)1)\n"
+  Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
+  verifyFormat("while ( (bool)1 )\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("while ((i = j))\n"
                "  continue;",
                Spaces);
   verifyFormat("for ( ;; )\n"
@@ -17151,30 +17180,42 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                Spaces);
   verifyFormat("do {\n"
                "  do_something((int)i);\n"
-               "} while (something());",
+               "} while ( something() );",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int)i);\n"
+               "} while ((i = i + 1));",
                Spaces);
   verifyFormat("switch ( x ) {\n"
                "default:\n"
                "  break;\n"
                "}",
                Spaces);
-  verifyFormat("if ((x - y) && (a ^ b))\n"
+  verifyFormat("if ( (x - y) && (a ^ b) )\n"
                "  f();\n",
                Spaces);
-  verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
+  verifyFormat("if ((i = j))\n"
+               "  do_something(i);",
+               Spaces);
+  verifyFormat("for ( int i = 0; i < 10; i = (i + 1) )\n"
                "  foo(i);",
                Spaces);
-  verifyFormat("switch (x / (y + z)) {\n"
+  verifyFormat("switch ( x / (y + z) ) {\n"
                "default:\n"
                "  break;\n"
                "}",
                Spaces);
+  verifyFormat("if constexpr ((a = b))\n"
+               "  c;",
+               Spaces);
 
-  Spaces.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_Never;
+  Spaces.SpacesInParensOptions.InConditionalStatements = false;
   verifyFormat("while ((bool)1)\n"
                "  continue;",
                Spaces);
+  verifyFormat("while ((i = j))\n"
+               "  continue;",
+               Spaces);
   verifyFormat("for (;;)\n"
                "  continue;",
                Spaces);
@@ -17187,6 +17228,10 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                "  do_something((int)i);\n"
                "} while (something());",
                Spaces);
+  verifyFormat("do {\n"
+               "  do_something((int)i);\n"
+               "} while ((i = i + 1));",
+               Spaces);
   verifyFormat("switch (x) {\n"
                "default:\n"
                "  break;\n"
@@ -17195,6 +17240,9 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   verifyFormat("if ((x - y) && (a ^ b))\n"
                "  f();\n",
                Spaces);
+  verifyFormat("if ((i = j))\n"
+               "  do_something(i);",
+               Spaces);
   verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
                "  foo(i);",
                Spaces);
@@ -17203,29 +17251,83 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
                "  break;\n"
                "}",
                Spaces);
+  verifyFormat("if constexpr ((a = b))\n"
+               "  c;",
+               Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
-  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.Other = true;
   verifyFormat("decltype( x ) y = 42;", Spaces);
   verifyFormat("decltype( ( x ) ) y = z;", Spaces);
   verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces);
   verifyFormat("decltype( ( bar( 10 ) ) ) a = bar( 11 );", Spaces);
-  verifyFormat("x = foo( ( a * ( b - c ) ) );", Spaces);
+  verifyFormat("decltype( ( foo->bar ) ) baz;", Spaces);
+  verifyFormat("if (( i = j ))\n"
+               "  do_something( i );",
+               Spaces);
+  verifyFormat("if constexpr (( a = b ))\n"
+               "  c;",
+               Spaces);
 
-  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_NonConsecutive;
+  Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
   verifyFormat("decltype( x ) y = 42;", Spaces);
   verifyFormat("decltype(( x )) y = z;", Spaces);
-  verifyFormat("decltype((foo())) a = foo();", Spaces);
-  verifyFormat("decltype((bar( 10 ))) a = bar( 11 );", Spaces);
-  verifyFormat("x = foo((a * ( b - c )));", Spaces);
+  verifyFormat("decltype(( foo() )) a = foo();", Spaces);
+  verifyFormat("decltype(( bar( 10 ) )) a = bar( 11 );", Spaces);
+  verifyFormat("decltype(( foo->bar )) baz;", Spaces);
+  verifyFormat("if (( i = j ))\n"
+               "  do_something( i );",
+               Spaces);
+  verifyFormat("if constexpr (( a = b ))\n"
+               "  c;",
+               Spaces);
 
-  Spaces.SpacesInParensOptions.Other = FormatStyle::SIPCS_Never;
+  Spaces.SpacesInParensOptions.Other = false;
   verifyFormat("decltype(x) y = 42;", Spaces);
   verifyFormat("decltype((x)) y = z;", Spaces);
   verifyFormat("decltype((foo())) a = foo();", Spaces);
   verifyFormat("decltype((bar(10))) a = bar(11);", Spaces);
-  verifyFormat("x = foo((a * (b - c)));", Spaces);
+  verifyFormat("decltype((foo->bar)) baz;", Spaces);
+  verifyFormat("if ((i = j))\n"
+               "  do_something(i);",
+               Spaces);
+  verifyFormat("if constexpr ((a = b))\n"
+               "  c;",
+               Spaces);
+
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  verifyFormat("if ( ( i = j ) )\n"
+               "  do_something( i );",
+               Spaces);
+  verifyFormat("if constexpr ( ( a = b ) )\n"
+               "  c;",
+               Spaces);
+  verifyFormat("while ( ( i = j ) )\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something( (int)i );\n"
+               "} while ( ( i = i + 1 ) );",
+               Spaces);
+
+  Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
+  verifyFormat("if (( i = j ))\n"
+               "  do_something( i );",
+               Spaces);
+  verifyFormat("if constexpr (( a = b ))\n"
+               "  c;",
+               Spaces);
+  verifyFormat("while (( i = j ))\n"
+               "  continue;",
+               Spaces);
+  verifyFormat("do {\n"
+               "  do_something( (int)i );\n"
+               "} while (( i = i + 1 ));",
+               Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
@@ -24294,10 +24396,10 @@ TEST_F(FormatTest, AtomicQualifier) {
   verifyFormat("vector<_Atomic(uint64_t)* attr> x;", Style);
 
   Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Always;
+  Style.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("x = ( _Atomic(uint64_t) )*a;", Style);
-  Style.SpacesInParensOptions.InCStyleCasts = FormatStyle::SIPCS_Never;
-  Style.SpacesInParensOptions.Other = FormatStyle::SIPCS_Always;
+  Style.SpacesInParensOptions.InCStyleCasts = false;
+  Style.SpacesInParensOptions.Other = true;
   verifyFormat("x = (_Atomic( uint64_t ))*a;", Style);
   verifyFormat("x = (_Atomic( uint64_t ))&a;", Style);
 }
@@ -24361,8 +24463,7 @@ TEST_F(FormatTest, SpacesInConditionalStatement) {
   Spaces.IfMacros.clear();
   Spaces.IfMacros.push_back("MYIF");
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
-  Spaces.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_Always;
+  Spaces.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("for ( int i = 0; i; i++ )\n  continue;", Spaces);
   verifyFormat("if ( !a )\n  return;", Spaces);
   verifyFormat("if ( a )\n  return;", Spaces);
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp
index 5078cbe3b66d43a..abebf9f7d4c785c 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -885,8 +885,7 @@ TEST_F(FormatTestVerilog, If) {
                "    x = x;",
                Style);
   Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_Always;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("if ( x )\n"
                "  x = x;\n"
                "else if ( x )\n"
@@ -983,8 +982,7 @@ TEST_F(FormatTestVerilog, Loop) {
                "end");
   auto Style = getDefaultStyle();
   Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.InConditionalStatements =
-      FormatStyle::SIPCS_Always;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("foreach ( x[x] )\n"
                "  x = x;",
                Style);



More information about the cfe-commits mailing list