https://github.com/davidstone updated 
https://github.com/llvm/llvm-project/pull/172529

>From f2c939534609f8279a6d3c973e1ee271fb349416 Mon Sep 17 00:00:00 2001
From: David Stone <[email protected]>
Date: Mon, 15 Dec 2025 15:22:47 -0700
Subject: [PATCH] [clang][NFC] Make `CFGStmtMap` `const`-correct

---
 clang/include/clang/Analysis/AnalysisDeclContext.h        | 2 +-
 clang/include/clang/Analysis/CFGStmtMap.h                 | 8 ++++----
 clang/lib/Analysis/AnalysisDeclContext.cpp                | 4 ++--
 clang/lib/Analysis/CFGStmtMap.cpp                         | 8 ++++----
 .../lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp  | 3 ++-
 clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp     | 2 +-
 clang/lib/StaticAnalyzer/Core/CallEvent.cpp               | 2 +-
 7 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Analysis/AnalysisDeclContext.h 
b/clang/include/clang/Analysis/AnalysisDeclContext.h
index ced4bb8595bea..76fb96bacc377 100644
--- a/clang/include/clang/Analysis/AnalysisDeclContext.h
+++ b/clang/include/clang/Analysis/AnalysisDeclContext.h
@@ -151,7 +151,7 @@ class AnalysisDeclContext {
 
   CFG *getCFG();
 
-  CFGStmtMap *getCFGStmtMap();
+  const CFGStmtMap *getCFGStmtMap();
 
   CFGReverseBlockReachabilityAnalysis *getCFGReachablityAnalysis();
 
diff --git a/clang/include/clang/Analysis/CFGStmtMap.h 
b/clang/include/clang/Analysis/CFGStmtMap.h
index c1cefbe45a7b5..e83a00a2508e9 100644
--- a/clang/include/clang/Analysis/CFGStmtMap.h
+++ b/clang/include/clang/Analysis/CFGStmtMap.h
@@ -23,16 +23,16 @@ class ParentMap;
 class Stmt;
 
 class CFGStmtMap {
-  using SMap = llvm::DenseMap<const Stmt *, CFGBlock *>;
-  ParentMap *PM;
+  using SMap = llvm::DenseMap<const Stmt *, const CFGBlock *>;
+  const ParentMap *PM;
   SMap M;
 
-  CFGStmtMap(ParentMap *pm, SMap m) : PM(pm), M(std::move(m)) {}
+  CFGStmtMap(const ParentMap *pm, SMap m) : PM(pm), M(std::move(m)) {}
 
 public:
   /// Returns a new CFGMap for the given CFG.  It is the caller's
   /// responsibility to 'delete' this object when done using it.
-  static CFGStmtMap *Build(CFG* C, ParentMap *PM);
+  static CFGStmtMap *Build(const CFG *C, const ParentMap *PM);
 
   /// Returns the CFGBlock the specified Stmt* appears in.  For Stmt* that
   /// are terminators, the CFGBlock is the block they appear as a terminator,
diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp 
b/clang/lib/Analysis/AnalysisDeclContext.cpp
index f188fc6921ed1..f683b9efc1d1e 100644
--- a/clang/lib/Analysis/AnalysisDeclContext.cpp
+++ b/clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -250,11 +250,11 @@ CFG *AnalysisDeclContext::getUnoptimizedCFG() {
   return completeCFG.get();
 }
 
-CFGStmtMap *AnalysisDeclContext::getCFGStmtMap() {
+const CFGStmtMap *AnalysisDeclContext::getCFGStmtMap() {
   if (cfgStmtMap)
     return cfgStmtMap.get();
 
-  if (CFG *c = getCFG()) {
+  if (const CFG *c = getCFG()) {
     cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap()));
     return cfgStmtMap.get();
   }
diff --git a/clang/lib/Analysis/CFGStmtMap.cpp 
b/clang/lib/Analysis/CFGStmtMap.cpp
index c376788173d0d..adbec58210954 100644
--- a/clang/lib/Analysis/CFGStmtMap.cpp
+++ b/clang/lib/Analysis/CFGStmtMap.cpp
@@ -33,7 +33,7 @@ const CFGBlock *CFGStmtMap::getBlock(const Stmt *S) const {
   return nullptr;
 }
 
-CFGStmtMap *CFGStmtMap::Build(CFG *C, ParentMap *PM) {
+CFGStmtMap *CFGStmtMap::Build(const CFG *C, const ParentMap *PM) {
   if (!C || !PM)
     return nullptr;
 
@@ -41,7 +41,7 @@ CFGStmtMap *CFGStmtMap::Build(CFG *C, ParentMap *PM) {
 
   // Walk all blocks, accumulating the block-level expressions, labels,
   // and terminators.
-  for (CFGBlock *B : *C) {
+  for (const CFGBlock *B : *C) {
     // First walk the block-level expressions.
     for (const CFGElement &CE : *B) {
       if (std::optional<CFGStmt> CS = CE.getAs<CFGStmt>())
@@ -49,13 +49,13 @@ CFGStmtMap *CFGStmtMap::Build(CFG *C, ParentMap *PM) {
     }
 
     // Look at the label of the block.
-    if (Stmt *Label = B->getLabel())
+    if (const Stmt *Label = B->getLabel())
       SM[Label] = B;
 
     // Finally, look at the terminator.  If the terminator was already added
     // because it is a block-level expression in another block, overwrite
     // that mapping.
-    if (Stmt *Term = B->getTerminatorStmt())
+    if (const Stmt *Term = B->getTerminatorStmt())
       SM[Term] = B;
   }
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
index 309e3d250de06..49b20fc877188 100644
--- a/clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
@@ -162,7 +162,8 @@ class AnalysisOrderChecker
         return;
 
       llvm::errs() << "CFGElement: ";
-      CFGStmtMap *Map = C.getCurrentAnalysisDeclContext()->getCFGStmtMap();
+      const CFGStmtMap *Map =
+          C.getCurrentAnalysisDeclContext()->getCFGStmtMap();
       CFGElement LastElement = Map->getBlock(S)->back();
 
       if (LastElement.getAs<CFGStmt>())
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 0ba3c05d2d163..7df5fab0843ac 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1906,7 +1906,7 @@ SuppressInlineDefensiveChecksVisitor::VisitNode(const 
ExplodedNode *Succ,
       if (!CurStmt->getBeginLoc().isMacroID())
         return nullptr;
 
-      CFGStmtMap *Map = CurLC->getAnalysisDeclContext()->getCFGStmtMap();
+      const CFGStmtMap *Map = CurLC->getAnalysisDeclContext()->getCFGStmtMap();
       CurTerminatorStmt = Map->getBlock(CurStmt)->getTerminatorStmt();
     } else {
       return nullptr;
diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp 
b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index d04c827ce1391..3c0e2641e65fe 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -174,7 +174,7 @@ CallEvent::getCalleeStackFrame(unsigned BlockCount) const {
   // instead of doing this reverse lookup, we would be able to build the stack
   // frame for non-expression-based calls, and also we wouldn't need the 
reverse
   // lookup.
-  CFGStmtMap *Map = LCtx->getAnalysisDeclContext()->getCFGStmtMap();
+  const CFGStmtMap *Map = LCtx->getAnalysisDeclContext()->getCFGStmtMap();
   const CFGBlock *B = Map->getBlock(E);
   assert(B);
 

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

Reply via email to