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

>From 5faf0fd027ff5ef3927747cd6ca5efea84d6e3c0 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Tue, 13 May 2025 08:42:41 -0600
Subject: [PATCH 1/9] [clang-format] Add IndentPPDirectives Leave option

Allow an option to leave preprocessor directive indenting as-is.
This simplifies handling mixed styles of CPP directive indentation.

Fixes #38511.
---
 clang/include/clang/Format/Format.h         | 14 +++-
 clang/lib/Format/ContinuationIndenter.cpp   |  6 ++
 clang/lib/Format/Format.cpp                 |  1 +
 clang/lib/Format/TokenAnnotator.cpp         |  3 +-
 clang/lib/Format/UnwrappedLineFormatter.cpp | 17 +++--
 clang/lib/Format/UnwrappedLineParser.cpp    |  9 ++-
 clang/unittests/Format/FormatTest.cpp       | 76 +++++++++++++++++----
 7 files changed, 101 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 03cff5f8cfb66..342fefcfc408c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2976,7 +2976,19 @@ struct FormatStyle {
     ///      #endif
     ///    #endif
     /// \endcode
-    PPDIS_BeforeHash
+    PPDIS_BeforeHash,
+    /// Leaves indentation of directives as-is.
+    /// \note
+    ///  Ignores ``PPIndentWidth``.
+    /// \endnote
+    /// \code
+    ///   #if FOO
+    ///     #if BAR
+    ///   #include <foo>
+    ///     #endif
+    ///   #endif
+    /// \endcode
+    PPDIS_Leave
   };
 
   /// The preprocessor directive indenting style to use.
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 888d0faf80931..a02c1fef19cea 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -778,6 +778,12 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 
   unsigned Spaces = Current.SpacesRequiredBefore + ExtraSpaces;
 
+  if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave &&
+      State.Line->InPPDirective && Previous.is(tok::hash) &&
+      &Previous == State.Line->First) {
+    Spaces += Current.OriginalColumn - Previous.OriginalColumn - 1;
+  }
+
   // Indent preprocessor directives after the hash if required.
   int PPColumnCorrection = 0;
   if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index f095d2c18cfcf..1776e373cf8a8 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -535,6 +535,7 @@ struct 
ScalarEnumerationTraits<FormatStyle::PPDirectiveIndentStyle> {
     IO.enumCase(Value, "None", FormatStyle::PPDIS_None);
     IO.enumCase(Value, "AfterHash", FormatStyle::PPDIS_AfterHash);
     IO.enumCase(Value, "BeforeHash", FormatStyle::PPDIS_BeforeHash);
+    IO.enumCase(Value, "Leave", FormatStyle::PPDIS_Leave);
   }
 };
 
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index bbb7ef2c337d6..e20c50f387f41 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3627,7 +3627,8 @@ void TokenAnnotator::setCommentLineLevels(
       // Align comments for preprocessor lines with the # in column 0 if
       // preprocessor lines are not indented. Otherwise, align with the next
       // line.
-      Line->Level = Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash 
&&
+      Line->Level = (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash 
||
+                     Style.IndentPPDirectives == FormatStyle::PPDIS_None) &&
                             PPDirectiveOrImportStmt
                         ? 0
                         : NextNonCommentLine->Level;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 2a7bfd1a7dc5b..561d303039010 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -62,10 +62,16 @@ class LevelIndentTracker {
     // having the right size in adjustToUnmodifiedline.
     if (Line.Level >= IndentForLevel.size())
       IndentForLevel.resize(Line.Level + 1, -1);
-    if (Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
-        (Line.InPPDirective ||
-         (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
-          Line.Type == LT_CommentAbovePPDirective))) {
+    if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave &&
+        Line.InPPDirective) {
+      Indent = Line.InMacroBody
+                   ? (Line.Level - Line.PPLevel) * Style.IndentWidth +
+                         AdditionalIndent
+                   : Line.First->OriginalColumn;
+    } else if (Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
+               (Line.InPPDirective ||
+                (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
+                 Line.Type == LT_CommentAbovePPDirective))) {
       unsigned PPIndentWidth =
           (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth;
       Indent = Line.InMacroBody
@@ -1656,7 +1662,8 @@ void UnwrappedLineFormatter::formatFirstToken(
   // Preprocessor directives get indented before the hash only if specified. In
   // Javascript import statements are indented like normal statements.
   if (!Style.isJavaScript() &&
-      Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
+      (Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
+       Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash) &&
       (Line.Type == LT_PreprocessorDirective ||
        Line.Type == LT_ImportStatement)) {
     Indent = 0;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index f4bbfcf8461bc..ff5b8b01f3e80 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -162,7 +162,8 @@ UnwrappedLineParser::UnwrappedLineParser(
       LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords),
       CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
       Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1),
-      IncludeGuard(Style.IndentPPDirectives == FormatStyle::PPDIS_None
+      IncludeGuard((Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
+                    Style.IndentPPDirectives == FormatStyle::PPDIS_Leave)
                        ? IG_Rejected
                        : IG_Inited),
       IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn),
@@ -170,7 +171,8 @@ UnwrappedLineParser::UnwrappedLineParser(
 
 void UnwrappedLineParser::reset() {
   PPBranchLevel = -1;
-  IncludeGuard = Style.IndentPPDirectives == FormatStyle::PPDIS_None
+  IncludeGuard = Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
+                         Style.IndentPPDirectives == FormatStyle::PPDIS_Leave
                      ? IG_Rejected
                      : IG_Inited;
   IncludeGuardToken = nullptr;
@@ -1140,7 +1142,8 @@ void UnwrappedLineParser::parsePPEndIf() {
   // If the #endif of a potential include guard is the last thing in the file,
   // then we found an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == -1 && Tokens->isEOF() &&
-      Style.IndentPPDirectives != FormatStyle::PPDIS_None) {
+      !(Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
+        Style.IndentPPDirectives == FormatStyle::PPDIS_Leave)) {
     IncludeGuard = IG_Found;
   }
 }
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4e9d31895998f..223bab5d285d2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5527,7 +5527,6 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
                "        x; \\\n"
                "    }",
                style);
-
   style.PPIndentWidth = 2;
   verifyFormat("#ifdef foo\n"
                "#define bar() \\\n"
@@ -5547,22 +5546,55 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) 
{
                "#endif",
                style);
 
+  style.IndentPPDirectives = FormatStyle::PPDIS_Leave;
+  style.IndentWidth = 4;
+  verifyNoChange("#ifndef foo\n"
+                 "#define foo\n"
+                 "if (emacs) {\n"
+                 "#ifdef is\n"
+                 "#define lit           \\\n"
+                 "    if (af) {         \\\n"
+                 "        return duh(); \\\n"
+                 "    }\n"
+                 "#endif\n"
+                 "}\n"
+                 "#endif",
+                 style);
+  verifyNoChange("#ifndef foo\n"
+                 "  #define foo\n"
+                 "if (emacs) {\n"
+                 "  #ifdef is\n"
+                 "#define lit           \\\n"
+                 "    if (af) {         \\\n"
+                 "        return duh(); \\\n"
+                 "    }\n"
+                 "  #endif\n"
+                 "}\n"
+                 "#endif",
+                 style);
+  verifyNoChange("  #ifndef foo\n"
+                 "#  define foo\n"
+                 "if (emacs) {\n"
+                 "#ifdef is\n"
+                 "  #  define lit       \\\n"
+                 "    if (af) {         \\\n"
+                 "        return duh(); \\\n"
+                 "    }\n"
+                 "#endif\n"
+                 "}\n"
+                 "  #endif",
+                 style);
+
   style.IndentWidth = 1;
   style.PPIndentWidth = 4;
-  verifyFormat("#if 1\n"
-               "#define X \\\n"
-               " {        \\\n"
-               "  x;      \\\n"
-               "  x;      \\\n"
-               " }\n"
-               "#endif",
-               style);
-  verifyFormat("#define X \\\n"
-               " {        \\\n"
-               "  x;      \\\n"
-               "  x;      \\\n"
-               " }",
-               style);
+  verifyNoChange("# if 1\n"
+                 "  #define X \\\n"
+                 " {          \\\n"
+                 "  x;        \\\n"
+                 "  x;        \\\n"
+                 " }\n"
+                 "# endif",
+                 style);
 
   style.IndentWidth = 4;
   style.PPIndentWidth = 1;
@@ -25597,6 +25629,20 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
                  "a",
                  Style);
 
+  Style.IndentPPDirectives = FormatStyle::PPDIS_Leave;
+  verifyNoChange("#if A\n"
+                 "#define A a\n"
+                 "#endif",
+                 Style);
+  verifyNoChange("#if A\n"
+                 "  #define A a\n"
+                 "#endif",
+                 Style);
+  verifyNoChange("#if A\n"
+                 "#  define A a\n"
+                 "#endif",
+                 Style);
+
   // Adjust indendations but don't change the definition.
   Style.IndentPPDirectives = FormatStyle::PPDIS_None;
   verifyNoChange("#if A\n"

>From 7131f2446e86b289d6a680b4c06a363291eec59c Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Tue, 13 May 2025 08:49:27 -0600
Subject: [PATCH 2/9] clang-format-style

---
 clang/docs/ClangFormatStyleOptions.rst | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6be4d512bda6a..9413b9a348b76 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4426,6 +4426,21 @@ the configuration (without a prefix: ``Auto``).
          #endif
        #endif
 
+  * ``PPDIS_Leave`` (in configuration: ``Leave``)
+    Leaves indentation of directives as-is.
+
+    .. note::
+
+     Ignores ``PPIndentWidth``.
+
+    .. code-block:: c++
+
+      #if FOO
+        #if BAR
+      #include <foo>
+        #endif
+      #endif
+
 
 
 .. _IndentRequiresClause:

>From 1d757daa677f09c6f0fe719a562a105530ec8362 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Tue, 13 May 2025 08:52:09 -0600
Subject: [PATCH 3/9] release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 51e5973098c14..47299d1cd9a5f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -470,8 +470,10 @@ AST Matchers
 clang-format
 ------------
 - Add ``SpaceInEmptyBraces`` option and set it to ``Always`` for WebKit style.
+<<<<<<< HEAD
 - Add ``NumericLiteralCase`` option for enforcing character case in numeric
   literals.
+- Add ``Leave`` suboption to ``IndentPPDirectives``.
 
 libclang
 --------

>From a0532119c32d18dd56a73ef43c758cef7fe34a76 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Thu, 15 May 2025 21:46:14 -0600
Subject: [PATCH 4/9] remove spurious whitespace change

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

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 223bab5d285d2..80ea0ab555365 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5527,6 +5527,7 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
                "        x; \\\n"
                "    }",
                style);
+
   style.PPIndentWidth = 2;
   verifyFormat("#ifdef foo\n"
                "#define bar() \\\n"

>From 7039ddcbba05aec747ef2f5c896bd057a56b253b Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Mon, 19 May 2025 13:15:05 -0600
Subject: [PATCH 5/9] Update clang/lib/Format/UnwrappedLineParser.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers <git...@hazardy.de>
---
 clang/lib/Format/UnwrappedLineParser.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index ff5b8b01f3e80..4812dddf4216c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1142,8 +1142,8 @@ void UnwrappedLineParser::parsePPEndIf() {
   // If the #endif of a potential include guard is the last thing in the file,
   // then we found an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == -1 && Tokens->isEOF() &&
-      !(Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
-        Style.IndentPPDirectives == FormatStyle::PPDIS_Leave)) {
+      Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
+      Style.IndentPPDirectives != FormatStyle::PPDIS_Leave) {
     IncludeGuard = IG_Found;
   }
 }

>From 2ee8fabaea372cd2a79a23c20081782ed65cc0f6 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Thu, 11 Sep 2025 13:45:20 -0600
Subject: [PATCH 6/9] Handle comment above PP Directive

---
 clang/lib/Format/UnwrappedLineFormatter.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp       | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 561d303039010..0fb0dd7f2f164 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -63,7 +63,7 @@ class LevelIndentTracker {
     if (Line.Level >= IndentForLevel.size())
       IndentForLevel.resize(Line.Level + 1, -1);
     if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave &&
-        Line.InPPDirective) {
+        (Line.InPPDirective || Line.Type == LT_CommentAbovePPDirective)) {
       Indent = Line.InMacroBody
                    ? (Line.Level - Line.PPLevel) * Style.IndentWidth +
                          AdditionalIndent
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 80ea0ab555365..79eb341f91ed5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5585,6 +5585,13 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
                  "}\n"
                  "  #endif",
                  style);
+  verifyNoChange("#ifdef foo\n"
+                 "#else\n"
+                 "/* This is a comment */\n"
+                 "#ifdef BAR\n"
+                 "#endif\n"
+                 "#endif",
+                 style);
 
   style.IndentWidth = 1;
   style.PPIndentWidth = 4;

>From 35abd12c3a6d431ad6012e34e3951b99d2206059 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Fri, 12 Sep 2025 19:22:03 -0600
Subject: [PATCH 7/9] Updates from review

---
 clang/lib/Format/ContinuationIndenter.cpp   | 30 +++++++++------------
 clang/lib/Format/TokenAnnotator.cpp         |  3 +--
 clang/lib/Format/UnwrappedLineFormatter.cpp |  3 +--
 clang/lib/Format/UnwrappedLineParser.cpp    |  4 +--
 clang/unittests/Format/FormatTest.cpp       | 17 ++++++++++++
 5 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a02c1fef19cea..9413c13a4137e 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -778,27 +778,23 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
 
   unsigned Spaces = Current.SpacesRequiredBefore + ExtraSpaces;
 
-  if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave &&
-      State.Line->InPPDirective && Previous.is(tok::hash) &&
-      &Previous == State.Line->First) {
-    Spaces += Current.OriginalColumn - Previous.OriginalColumn - 1;
-  }
-
   // Indent preprocessor directives after the hash if required.
   int PPColumnCorrection = 0;
-  if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash &&
-      Previous.is(tok::hash) && State.FirstIndent > 0 &&
-      &Previous == State.Line->First &&
+  if (&Previous == State.Line->First && Previous.is(tok::hash) &&
       (State.Line->Type == LT_PreprocessorDirective ||
        State.Line->Type == LT_ImportStatement)) {
-    Spaces += State.FirstIndent;
-
-    // For preprocessor indent with tabs, State.Column will be 1 because of the
-    // hash. This causes second-level indents onward to have an extra space
-    // after the tabs. We avoid this misalignment by subtracting 1 from the
-    // column value passed to replaceWhitespace().
-    if (Style.UseTab != FormatStyle::UT_Never)
-      PPColumnCorrection = -1;
+    if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash) {
+      Spaces += State.FirstIndent;
+
+      // For preprocessor indent with tabs, State.Column will be 1 because of
+      // the hash. This causes second-level indents onward to have an extra
+      // space after the tabs. We avoid this misalignment by subtracting 1 from
+      // the column value passed to replaceWhitespace().
+      if (Style.UseTab != FormatStyle::UT_Never)
+        PPColumnCorrection = -1;
+    } else if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave) {
+      Spaces += Current.OriginalColumn - Previous.OriginalColumn - 1;
+    }
   }
 
   if (!DryRun) {
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e20c50f387f41..d97f56751ea69 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3627,8 +3627,7 @@ void TokenAnnotator::setCommentLineLevels(
       // Align comments for preprocessor lines with the # in column 0 if
       // preprocessor lines are not indented. Otherwise, align with the next
       // line.
-      Line->Level = (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash 
||
-                     Style.IndentPPDirectives == FormatStyle::PPDIS_None) &&
+      Line->Level = Style.IndentPPDirectives < FormatStyle::PPDIS_BeforeHash &&
                             PPDirectiveOrImportStmt
                         ? 0
                         : NextNonCommentLine->Level;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 0fb0dd7f2f164..ac9d147defc13 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1662,8 +1662,7 @@ void UnwrappedLineFormatter::formatFirstToken(
   // Preprocessor directives get indented before the hash only if specified. In
   // Javascript import statements are indented like normal statements.
   if (!Style.isJavaScript() &&
-      (Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
-       Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash) &&
+      Style.IndentPPDirectives < FormatStyle::PPDIS_BeforeHash &&
       (Line.Type == LT_PreprocessorDirective ||
        Line.Type == LT_ImportStatement)) {
     Indent = 0;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4812dddf4216c..6bb1de50c94a6 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -162,8 +162,8 @@ UnwrappedLineParser::UnwrappedLineParser(
       LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords),
       CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
       Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1),
-      IncludeGuard((Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
-                    Style.IndentPPDirectives == FormatStyle::PPDIS_Leave)
+      IncludeGuard(Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
+                           Style.IndentPPDirectives == FormatStyle::PPDIS_Leave
                        ? IG_Rejected
                        : IG_Inited),
       IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn),
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 79eb341f91ed5..d9db06667d802 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5547,6 +5547,23 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
                "#endif",
                style);
 
+  style.IndentWidth = 1;
+  style.PPIndentWidth = 4;
+  verifyFormat("#if 1\n"
+               "#define X \\\n"
+               " {        \\\n"
+               "  x;      \\\n"
+               "  x;      \\\n"
+               " }\n"
+               "#endif",
+               style);
+  verifyFormat("#define X \\\n"
+               " {        \\\n"
+               "  x;      \\\n"
+               "  x;      \\\n"
+               " }",
+               style);
+
   style.IndentPPDirectives = FormatStyle::PPDIS_Leave;
   style.IndentWidth = 4;
   verifyNoChange("#ifndef foo\n"

>From 351e04b5dbbdd0dd29630d7a307c2eed862db7f8 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Fri, 12 Sep 2025 19:32:36 -0600
Subject: [PATCH 8/9] fix leftover merge conflict text

---
 clang/docs/ReleaseNotes.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 47299d1cd9a5f..39dfa73059fde 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -470,7 +470,6 @@ AST Matchers
 clang-format
 ------------
 - Add ``SpaceInEmptyBraces`` option and set it to ``Always`` for WebKit style.
-<<<<<<< HEAD
 - Add ``NumericLiteralCase`` option for enforcing character case in numeric
   literals.
 - Add ``Leave`` suboption to ``IndentPPDirectives``.

>From 4b5d4084631f0c0ed5b5a9cb84ab769409fde060 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <ged...@rtems.org>
Date: Sat, 13 Sep 2025 09:53:16 -0600
Subject: [PATCH 9/9] refactor and add getIncludeGuardState

---
 clang/lib/Format/UnwrappedLineParser.cpp | 13 +++----------
 clang/lib/Format/UnwrappedLineParser.h   |  7 +++++++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 6bb1de50c94a6..2c9766c9b7bc0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -162,19 +162,13 @@ UnwrappedLineParser::UnwrappedLineParser(
       LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords),
       CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
       Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1),
-      IncludeGuard(Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
-                           Style.IndentPPDirectives == FormatStyle::PPDIS_Leave
-                       ? IG_Rejected
-                       : IG_Inited),
+      IncludeGuard(getIncludeGuardState(Style.IndentPPDirectives)),
       IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn),
       Macros(Style.Macros, SourceMgr, Style, Allocator, IdentTable) {}
 
 void UnwrappedLineParser::reset() {
   PPBranchLevel = -1;
-  IncludeGuard = Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
-                         Style.IndentPPDirectives == FormatStyle::PPDIS_Leave
-                     ? IG_Rejected
-                     : IG_Inited;
+  IncludeGuard = getIncludeGuardState(Style.IndentPPDirectives);
   IncludeGuardToken = nullptr;
   Line.reset(new UnwrappedLine);
   CommentsBeforeNextToken.clear();
@@ -1142,8 +1136,7 @@ void UnwrappedLineParser::parsePPEndIf() {
   // If the #endif of a potential include guard is the last thing in the file,
   // then we found an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == -1 && Tokens->isEOF() &&
-      Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
-      Style.IndentPPDirectives != FormatStyle::PPDIS_Leave) {
+      getIncludeGuardState(Style.IndentPPDirectives) == IG_Inited) {
     IncludeGuard = IG_Found;
   }
 }
diff --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 8e29680ff244b..8b8ad84896f1a 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -397,6 +397,13 @@ class UnwrappedLineParser {
   // Current state of include guard search.
   IncludeGuardState IncludeGuard;
 
+  IncludeGuardState
+  getIncludeGuardState(FormatStyle::PPDirectiveIndentStyle Style) const {
+    return Style == FormatStyle::PPDIS_None || Style == 
FormatStyle::PPDIS_Leave
+               ? IG_Rejected
+               : IG_Inited;
+  }
+
   // Points to the #ifndef condition for a potential include guard. Null unless
   // IncludeGuardState == IG_IfNdefed.
   FormatToken *IncludeGuardToken;

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to