https://github.com/ankurkraj updated 
https://github.com/llvm/llvm-project/pull/156046

>From 52d10bccd7e348ecfbdf1a5c25950d9e7f74a381 Mon Sep 17 00:00:00 2001
From: ankurkraj <[email protected]>
Date: Fri, 29 Aug 2025 20:49:27 +0530
Subject: [PATCH 1/5] Add plist macro formatting

---
 clang/include/clang/Analysis/PathDiagnostic.h |  5 ++
 .../StaticAnalyzer/Core/AnalyzerOptions.def   |  5 ++
 .../StaticAnalyzer/Core/AnalyzerOptions.h     |  8 +--
 clang/lib/StaticAnalyzer/Core/CMakeLists.txt  |  1 +
 .../StaticAnalyzer/Core/PlistDiagnostics.cpp  | 71 ++++++++++++++++---
 5 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Analysis/PathDiagnostic.h 
b/clang/include/clang/Analysis/PathDiagnostic.h
index 5907df022e449..665edcf8756ad 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -68,6 +68,11 @@ struct PathDiagnosticConsumerOptions {
   /// without re-compiling the program under analysis.
   bool ShouldDisplayMacroExpansions = false;
 
+  /// Whether to include clang-formatted macros during macro expansions
+  /// or to keep it as it was stored, the default setting is to kee it as
+  /// is.
+  bool ShouldFormatMacrosPlist = false;
+
   /// Whether to include LLVM statistics of the process in the diagnostic.
   /// Useful for profiling the tool on large real-world codebases.
   bool ShouldSerializeStats = false;
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 90b80e5201aa8..3f19e3020ba42 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -351,6 +351,11 @@ ANALYZER_OPTION(bool, ShouldDisplayMacroExpansions, 
"expand-macros",
                 "expanded and included in the plist output.",
                 false)
 
+ANALYZER_OPTION(bool, ShouldFormatMacrosPlist, "format-macros-plist",
+                "Whether the macros being displayed in the plist "
+                "files are clang-formatted .",
+                false)
+
 ANALYZER_OPTION(bool, DisplayCTUProgress, "display-ctu-progress",
                 "Whether to emit verbose output about "
                 "the analyzer's progress related to ctu.",
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index 7d0c2d8658f35..d8f32d659a6a1 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -403,16 +403,14 @@ class AnalyzerOptions {
   bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const;
 
   ento::PathDiagnosticConsumerOptions getDiagOpts() const {
-    return {FullCompilerInvocation,
-            ShouldDisplayMacroExpansions,
-            ShouldSerializeStats,
+    return {FullCompilerInvocation, ShouldDisplayMacroExpansions,
+            ShouldFormatMacrosPlist, ShouldSerializeStats,
             // The stable report filename option is deprecated because
             // file names are now always stable. Now the old option acts as
             // an alias to the new verbose filename option because this
             // closely mimics the behavior under the old option.
             ShouldWriteStableReportFilename || 
ShouldWriteVerboseReportFilename,
-            static_cast<bool>(AnalyzerWerror),
-            ShouldApplyFixIts,
+            static_cast<bool>(AnalyzerWerror), ShouldApplyFixIts,
             ShouldDisplayCheckerNameForText};
   }
 };
diff --git a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
index d0a9b202f9c52..6d51fcd0e7cc8 100644
--- a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -60,6 +60,7 @@ add_clang_library(clangStaticAnalyzerCore
   clangAnalysis
   clangBasic
   clangCrossTU
+  clangFormat
   clangFrontend
   clangLex
   clangRewrite
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index 771d09e19f178..d38e6491c1ce3 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/TokenConcatenation.h"
@@ -100,7 +101,8 @@ class PlistPrinter {
   /// is found through a call piece, etc), it's subpieces are reported, and the
   /// piece itself is collected. Call this function after the entire bugpath
   /// was reported.
-  void ReportMacroExpansions(raw_ostream &o, unsigned indent);
+  void ReportMacroExpansions(raw_ostream &o, unsigned indent,
+                             bool ShouldFormatMacrosPlist);
 
 private:
   void ReportPiece(raw_ostream &o, const PathDiagnosticPiece &P,
@@ -163,9 +165,15 @@ static void printCoverage(const PathDiagnostic *D,
                           FIDMap &FM,
                           llvm::raw_fd_ostream &o);
 
-static std::optional<StringRef> getExpandedMacro(
-    SourceLocation MacroLoc, const cross_tu::CrossTranslationUnitContext &CTU,
-    const MacroExpansionContext &MacroExpansions, const SourceManager &SM);
+static std::optional<StringRef>
+getExpandedMacro(SourceLocation MacroLoc,
+                 const cross_tu::CrossTranslationUnitContext &CTU,
+                 const MacroExpansionContext &MacroExpansions,
+                 const SourceManager &SM, bool ShouldFormatMacrosPlist);
+
+static std::optional<StringRef>
+getFormattedMacro(std::optional<StringRef> ExpandedText,
+                  bool ShouldFormatMacrosPlist);
 
 
//===----------------------------------------------------------------------===//
 // Methods of PlistPrinter.
@@ -372,7 +380,8 @@ void PlistPrinter::ReportMacroSubPieces(raw_ostream &o,
          "Fixits on constrol flow pieces are not implemented yet!");
 }
 
-void PlistPrinter::ReportMacroExpansions(raw_ostream &o, unsigned indent) {
+void PlistPrinter::ReportMacroExpansions(raw_ostream &o, unsigned indent,
+                                         bool ShouldFormatMacrosPlist) {
 
   for (const PathDiagnosticMacroPiece *P : MacroPieces) {
     const SourceManager &SM = PP.getSourceManager();
@@ -382,8 +391,8 @@ void PlistPrinter::ReportMacroExpansions(raw_ostream &o, 
unsigned indent) {
 
     const std::optional<StringRef> MacroName =
         MacroExpansions.getOriginalText(MacroExpansionLoc);
-    const std::optional<StringRef> ExpansionText =
-        getExpandedMacro(MacroExpansionLoc, CTU, MacroExpansions, SM);
+    const std::optional<StringRef> ExpansionText = getExpandedMacro(
+        MacroExpansionLoc, CTU, MacroExpansions, SM, ShouldFormatMacrosPlist);
 
     if (!MacroName || !ExpansionText)
       continue;
@@ -602,7 +611,8 @@ void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, 
const FIDMap &FM,
 
   o << "   <key>macro_expansions</key>\n"
        "   <array>\n";
-  Printer.ReportMacroExpansions(o, /* indent */ 4);
+  Printer.ReportMacroExpansions(o, /* indent */ 4,
+                                DiagOpts.ShouldFormatMacrosPlist);
   o << "   </array>\n";
 }
 
@@ -824,10 +834,49 @@ static std::optional<StringRef>
 getExpandedMacro(SourceLocation MacroExpansionLoc,
                  const cross_tu::CrossTranslationUnitContext &CTU,
                  const MacroExpansionContext &MacroExpansions,
-                 const SourceManager &SM) {
+                 const SourceManager &SM, bool ShouldFormatMacrosPlist) {
+  std::optional<StringRef> ExpandedText;
   if (auto CTUMacroExpCtx =
           CTU.getMacroExpansionContextForSourceLocation(MacroExpansionLoc)) {
-    return CTUMacroExpCtx->getExpandedText(MacroExpansionLoc);
+    ExpandedText = CTUMacroExpCtx->getExpandedText(MacroExpansionLoc);
+  } else {
+    ExpandedText = MacroExpansions.getExpandedText(MacroExpansionLoc);
   }
-  return MacroExpansions.getExpandedText(MacroExpansionLoc);
+
+  std::optional<StringRef> FormattedMacroText =
+      getFormattedMacro(ExpandedText, ShouldFormatMacrosPlist);
+  return FormattedMacroText;
 }
+
+static std::optional<StringRef>
+getFormattedMacro(std::optional<StringRef> ExpandedText,
+                  bool ShouldFormatMacrosPlist) {
+  if (!ExpandedText) {
+    return std::nullopt;
+  }
+
+  if (!ShouldFormatMacrosPlist) {
+    return *ExpandedText;
+  }
+
+  clang::format::FormatStyle Style = clang::format::getLLVMStyle();
+
+  std::string MacroCodeBlock = ExpandedText->str();
+
+  std::vector<clang::tooling::Range> Ranges;
+  Ranges.emplace_back(0, MacroCodeBlock.length());
+
+  auto Replacements = clang::format::reformat(Style, MacroCodeBlock, Ranges,
+                                              "<macro-expansion>");
+
+  auto Result =
+      clang::tooling::applyAllReplacements(MacroCodeBlock, Replacements);
+  if (!Result) {
+    return *ExpandedText;
+  }
+
+  static std::vector<std::string> FormattedResults;
+  FormattedResults.emplace_back(*Result);
+
+  return StringRef(FormattedResults.back());
+}
\ No newline at end of file

>From 5dbde8093850579fb133ce02c99b943410f76e92 Mon Sep 17 00:00:00 2001
From: ankurkraj <[email protected]>
Date: Sat, 30 Aug 2025 16:01:51 +0530
Subject: [PATCH 2/5] Update clang/include/clang/Analysis/PathDiagnostic.h
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Donát Nagy <[email protected]>
---
 clang/include/clang/Analysis/PathDiagnostic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Analysis/PathDiagnostic.h 
b/clang/include/clang/Analysis/PathDiagnostic.h
index 665edcf8756ad..9eca70bf68652 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -69,7 +69,7 @@ struct PathDiagnosticConsumerOptions {
   bool ShouldDisplayMacroExpansions = false;
 
   /// Whether to include clang-formatted macros during macro expansions
-  /// or to keep it as it was stored, the default setting is to kee it as
+  /// or to keep it as it was stored, the default setting is to keep it as
   /// is.
   bool ShouldFormatMacrosPlist = false;
 

>From 958ea776bd6113200708cea74a3f75c7ffa9d71b Mon Sep 17 00:00:00 2001
From: ankurkraj <[email protected]>
Date: Mon, 24 Nov 2025 20:04:22 +0530
Subject: [PATCH 3/5] Refractot

---
 .../clang/Analysis/MacroExpansionContext.h    | 13 +++++
 clang/lib/Analysis/CMakeLists.txt             |  1 +
 clang/lib/Analysis/MacroExpansionContext.cpp  | 36 ++++++++++++++
 clang/lib/StaticAnalyzer/Core/CMakeLists.txt  |  1 -
 .../StaticAnalyzer/Core/PlistDiagnostics.cpp  | 49 ++-----------------
 clang/test/Analysis/analyzer-config.c         |  1 +
 .../Analysis/MacroExpansionContextTest.cpp    | 39 +++++++++++++++
 7 files changed, 94 insertions(+), 46 deletions(-)

diff --git a/clang/include/clang/Analysis/MacroExpansionContext.h 
b/clang/include/clang/Analysis/MacroExpansionContext.h
index 2a27aba76656d..f9a69c84baa7d 100644
--- a/clang/include/clang/Analysis/MacroExpansionContext.h
+++ b/clang/include/clang/Analysis/MacroExpansionContext.h
@@ -96,6 +96,15 @@ class MacroExpansionContext {
   std::optional<StringRef>
   getOriginalText(SourceLocation MacroExpansionLoc) const;
 
+  /// \param MacroExpansionLoc Must be the expansion location of a macro.
+  /// \param ShouldFormatMacrosPlist Whether to format the expanded text for
+  ///         better readability in plist diagnostics.
+  /// \return A formatted representation of the textual representation of the 
+  ///         token sequence which was substituted in place of the macro.
+  ///         If no macro was expanded at that location, returns std::nullopt.
+  std::optional<StringRef> 
+  getFormattedExpandedText(SourceLocation MacroExpansionLoc, bool 
ShouldFormatMacrosPlist) const;
+
   LLVM_DUMP_METHOD void dumpExpansionRangesToStream(raw_ostream &OS) const;
   LLVM_DUMP_METHOD void dumpExpandedTextsToStream(raw_ostream &OS) const;
   LLVM_DUMP_METHOD void dumpExpansionRanges() const;
@@ -106,6 +115,7 @@ class MacroExpansionContext {
   using MacroExpansionText = SmallString<40>;
   using ExpansionMap = llvm::DenseMap<SourceLocation, MacroExpansionText>;
   using ExpansionRangeMap = llvm::DenseMap<SourceLocation, SourceLocation>;
+  using FormattedExpansionMap = llvm::DenseMap<SourceLocation, std::string>;
 
   /// Associates the textual representation of the expanded tokens at the given
   /// macro expansion location.
@@ -115,6 +125,9 @@ class MacroExpansionContext {
   /// substitution starting from a given macro expansion location.
   ExpansionRangeMap ExpansionRanges;
 
+  /// Caches formatted macro expansions keyed by expansion location.
+  mutable FormattedExpansionMap FormattedExpandedTokens;
+
   Preprocessor *PP = nullptr;
   SourceManager *SM = nullptr;
   const LangOptions &LangOpts;
diff --git a/clang/lib/Analysis/CMakeLists.txt 
b/clang/lib/Analysis/CMakeLists.txt
index 1dbd4153d856f..ac63b81de90ec 100644
--- a/clang/lib/Analysis/CMakeLists.txt
+++ b/clang/lib/Analysis/CMakeLists.txt
@@ -40,6 +40,7 @@ add_clang_library(clangAnalysis
   clangAST
   clangASTMatchers
   clangBasic
+  clangFormat
   clangLex
 
   DEPENDS
diff --git a/clang/lib/Analysis/MacroExpansionContext.cpp 
b/clang/lib/Analysis/MacroExpansionContext.cpp
index b212b7f245792..18f02b7a82023 100644
--- a/clang/lib/Analysis/MacroExpansionContext.cpp
+++ b/clang/lib/Analysis/MacroExpansionContext.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/MacroExpansionContext.h"
+#include "clang/Format/Format.h"
 #include "llvm/Support/Debug.h"
 #include <optional>
 
@@ -132,6 +133,41 @@ MacroExpansionContext::getOriginalText(SourceLocation 
MacroExpansionLoc) const {
       LangOpts);
 }
 
+std::optional<StringRef> MacroExpansionContext::getFormattedExpandedText(
+    SourceLocation MacroExpansionLoc, bool ShouldFormatMacrosPlist) const {
+  std::optional<StringRef> ExpandedText = getExpandedText(MacroExpansionLoc);
+  if (!ExpandedText)
+    return std::nullopt;
+
+  if (!ShouldFormatMacrosPlist)
+    return ExpandedText;
+
+  auto CachedIt = FormattedExpandedTokens.find(MacroExpansionLoc);
+  if (CachedIt != FormattedExpandedTokens.end())
+    return StringRef(CachedIt->getSecond());
+
+  clang::format::FormatStyle Style = clang::format::getLLVMStyle();
+
+  std::string MacroCodeBlock = ExpandedText->str();
+
+  std::vector<clang::tooling::Range> Ranges;
+  Ranges.emplace_back(0, MacroCodeBlock.length());
+
+  auto Replacements = clang::format::reformat(Style, MacroCodeBlock, Ranges,
+                                              "<macro-expansion>");
+
+  auto Result =
+      clang::tooling::applyAllReplacements(MacroCodeBlock, Replacements);
+
+  const std::string &Stored =
+      FormattedExpandedTokens
+          .try_emplace(MacroExpansionLoc,
+                       Result ? std::move(*Result) : std::move(MacroCodeBlock))
+          .first->getSecond();
+
+  return StringRef(Stored);
+}
+
 void MacroExpansionContext::dumpExpansionRanges() const {
   dumpExpansionRangesToStream(llvm::dbgs());
 }
diff --git a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
index 2965c35c378d9..b8095a5427b51 100644
--- a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -60,7 +60,6 @@ add_clang_library(clangStaticAnalyzerCore
   clangAnalysis
   clangBasic
   clangCrossTU
-  clangFormat
   clangFrontend
   clangIndex
   clangLex
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index ce2eea1b5db53..8cc2a188b85c2 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -18,7 +18,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Format/Format.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/TokenConcatenation.h"
@@ -172,10 +171,6 @@ getExpandedMacro(SourceLocation MacroLoc,
                  const MacroExpansionContext &MacroExpansions,
                  const SourceManager &SM, bool ShouldFormatMacrosPlist);
 
-static std::optional<StringRef>
-getFormattedMacro(std::optional<StringRef> ExpandedText,
-                  bool ShouldFormatMacrosPlist);
-
 
//===----------------------------------------------------------------------===//
 // Methods of PlistPrinter.
 
//===----------------------------------------------------------------------===//
@@ -843,48 +838,12 @@ getExpandedMacro(SourceLocation MacroExpansionLoc,
                  const cross_tu::CrossTranslationUnitContext &CTU,
                  const MacroExpansionContext &MacroExpansions,
                  const SourceManager &SM, bool ShouldFormatMacrosPlist) {
-  std::optional<StringRef> ExpandedText;
   if (auto CTUMacroExpCtx =
           CTU.getMacroExpansionContextForSourceLocation(MacroExpansionLoc)) {
-    ExpandedText = CTUMacroExpCtx->getExpandedText(MacroExpansionLoc);
-  } else {
-    ExpandedText = MacroExpansions.getExpandedText(MacroExpansionLoc);
+    return CTUMacroExpCtx->getFormattedExpandedText(MacroExpansionLoc,
+                                                    ShouldFormatMacrosPlist);
   }
 
-  std::optional<StringRef> FormattedMacroText =
-      getFormattedMacro(ExpandedText, ShouldFormatMacrosPlist);
-  return FormattedMacroText;
+  return MacroExpansions.getFormattedExpandedText(MacroExpansionLoc,
+                                                  ShouldFormatMacrosPlist);
 }
-
-static std::optional<StringRef>
-getFormattedMacro(std::optional<StringRef> ExpandedText,
-                  bool ShouldFormatMacrosPlist) {
-  if (!ExpandedText) {
-    return std::nullopt;
-  }
-
-  if (!ShouldFormatMacrosPlist) {
-    return *ExpandedText;
-  }
-
-  clang::format::FormatStyle Style = clang::format::getLLVMStyle();
-
-  std::string MacroCodeBlock = ExpandedText->str();
-
-  std::vector<clang::tooling::Range> Ranges;
-  Ranges.emplace_back(0, MacroCodeBlock.length());
-
-  auto Replacements = clang::format::reformat(Style, MacroCodeBlock, Ranges,
-                                              "<macro-expansion>");
-
-  auto Result =
-      clang::tooling::applyAllReplacements(MacroCodeBlock, Replacements);
-  if (!Result) {
-    return *ExpandedText;
-  }
-
-  static std::vector<std::string> FormattedResults;
-  FormattedResults.emplace_back(*Result);
-
-  return StringRef(FormattedResults.back());
-}
\ No newline at end of file
diff --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index 7936273415ad4..c97ab56dfd61d 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -86,6 +86,7 @@
 // CHECK-NEXT: experimental-enable-naive-ctu-analysis = false
 // CHECK-NEXT: exploration_strategy = unexplored_first_queue
 // CHECK-NEXT: faux-bodies = true
+// CHECK-NEXT: format-macros-plist = false
 // CHECK-NEXT: graph-trim-interval = 1000
 // CHECK-NEXT: ignore-bison-generated-files = true
 // CHECK-NEXT: ignore-flex-generated-files = true
diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp 
b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 25a76edbfdc49..7ea7131fe22ba 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -405,6 +405,45 @@ TEST_F(MacroExpansionContextTest, UnbalacedParenthesis) {
   EXPECT_EQ("f(f(1))", *Ctx->getOriginalText(at(13, 12)));
 }
 
+TEST_F(MacroExpansionContextTest, FormattedExpandedTextNoneWhenNoExpansion) {
+  const auto Ctx = getMacroExpansionContextFor(R"code(
+  #define UNUSED 1
+  int value = 0;
+      )code");
+  EXPECT_FALSE(Ctx->getFormattedExpandedText(at(3, 3), false).has_value());
+  EXPECT_FALSE(Ctx->getFormattedExpandedText(at(3, 3), true).has_value());
+}
+
+TEST_F(MacroExpansionContextTest, 
FormattedExpandedTextKeepsOriginalWhenStable) {
+  const auto Ctx = getMacroExpansionContextFor(R"code(
+  #define ANSWER 42
+  int life = ANSWER;
+      )code");
+
+  const auto Expanded = Ctx->getExpandedText(at(3, 14));
+  ASSERT_TRUE(Expanded.has_value());
+
+  EXPECT_EQ(*Expanded, *Ctx->getFormattedExpandedText(at(3, 14), false));
+  EXPECT_EQ(*Expanded, *Ctx->getFormattedExpandedText(at(3, 14), true));
+}
+
+TEST_F(MacroExpansionContextTest, FormattedExpandedTextChangesWhenFormatting) {
+  const auto Ctx = getMacroExpansionContextFor(R"code(
+  #define ADD(x, y) (x+y* x)
+  int result = ADD(1,2);
+      )code");
+
+  const auto Expanded = Ctx->getExpandedText(at(3, 16));
+  ASSERT_TRUE(Expanded.has_value());
+
+  const auto Formatted = Ctx->getFormattedExpandedText(at(3, 16), true);
+  ASSERT_TRUE(Formatted.has_value());
+
+  EXPECT_EQ(*Expanded, *Ctx->getFormattedExpandedText(at(3, 16), false));
+  EXPECT_EQ(*Formatted, *Ctx->getFormattedExpandedText(at(3, 16), true));
+  EXPECT_NE(*Expanded, *Formatted);
+}
+
 } // namespace
 } // namespace analysis
 } // namespace clang

>From 806ef584b214fa75c2e76468f753d24d0de4a120 Mon Sep 17 00:00:00 2001
From: ankurkraj <[email protected]>
Date: Mon, 24 Nov 2025 22:02:17 +0530
Subject: [PATCH 4/5] Update
 clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Donát Nagy <[email protected]>
---
 clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 3f19e3020ba42..159b0e8696029 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -353,7 +353,7 @@ ANALYZER_OPTION(bool, ShouldDisplayMacroExpansions, 
"expand-macros",
 
 ANALYZER_OPTION(bool, ShouldFormatMacrosPlist, "format-macros-plist",
                 "Whether the macros being displayed in the plist "
-                "files are clang-formatted .",
+                "files are clang-formatted.",
                 false)
 
 ANALYZER_OPTION(bool, DisplayCTUProgress, "display-ctu-progress",

>From 95d0c946da9ef4618205f5c2bb0d2828f4cb8944 Mon Sep 17 00:00:00 2001
From: ankurkraj <[email protected]>
Date: Mon, 24 Nov 2025 22:14:24 +0530
Subject: [PATCH 5/5] Fix review comments

---
 clang/lib/Analysis/MacroExpansionContext.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Analysis/MacroExpansionContext.cpp 
b/clang/lib/Analysis/MacroExpansionContext.cpp
index 18f02b7a82023..562b7c687148b 100644
--- a/clang/lib/Analysis/MacroExpansionContext.cpp
+++ b/clang/lib/Analysis/MacroExpansionContext.cpp
@@ -153,10 +153,10 @@ std::optional<StringRef> 
MacroExpansionContext::getFormattedExpandedText(
   std::vector<clang::tooling::Range> Ranges;
   Ranges.emplace_back(0, MacroCodeBlock.length());
 
-  auto Replacements = clang::format::reformat(Style, MacroCodeBlock, Ranges,
-                                              "<macro-expansion>");
+  clang::tooling::Replacements Replacements = clang::format::reformat(
+      Style, MacroCodeBlock, Ranges, "<macro-expansion>");
 
-  auto Result =
+  llvm::Expected<std::string> Result =
       clang::tooling::applyAllReplacements(MacroCodeBlock, Replacements);
 
   const std::string &Stored =

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to