This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6cd409fc639: [clang][dataflow] In `ControlFlowContext`, 
handle `Decl` by reference instead… (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156859/new/

https://reviews.llvm.org/D156859

Files:
  clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/Logger.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -189,7 +189,7 @@
   void print(raw_ostream &OS) const override {
     OS << Message << "\n";
     OS << "Decl:\n";
-    CFCtx.getDecl()->dump(OS);
+    CFCtx.getDecl().dump(OS);
     OS << "CFG:\n";
     CFCtx.getCFG().print(OS, LangOptions(), false);
   }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -725,9 +725,7 @@
     // FIXME: Use the same analysis as the caller for the callee. Note,
     // though, that doing so would require support for changing the analysis's
     // ASTContext.
-    assert(CFCtx->getDecl() != nullptr &&
-           "ControlFlowContexts in the environment should always carry a decl");
-    auto Analysis = NoopAnalysis(CFCtx->getDecl()->getASTContext(),
+    auto Analysis = NoopAnalysis(CFCtx->getDecl().getASTContext(),
                                  DataflowAnalysisOptions{Options});
 
     auto BlockToOutputState =
Index: clang/lib/Analysis/FlowSensitive/Logger.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/Logger.cpp
+++ clang/lib/Analysis/FlowSensitive/Logger.cpp
@@ -39,11 +39,10 @@
       llvm::WithColor Header(OS, llvm::raw_ostream::Colors::RED, /*Bold=*/true);
       OS << "=== Beginning data flow analysis ===\n";
     }
-    if (auto *D = CFG.getDecl()) {
-      D->print(OS);
-      OS << "\n";
-      D->dump(OS);
-    }
+    auto &D = CFG.getDecl();
+    D.print(OS);
+    OS << "\n";
+    D.dump(OS);
     CurrentCFG = &CFG.getCFG();
     CurrentCFG->print(OS, Analysis.getASTContext().getLangOpts(), ShowColors);
     CurrentAnalysis = &Analysis;
Index: clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -166,15 +166,14 @@
     this->CFG = &CFG;
     *OS << llvm::StringRef(HTMLLogger_html).split("<?INJECT?>").first;
 
-    if (const auto *D = CFG.getDecl()) {
-      const auto &SM = A.getASTContext().getSourceManager();
-      *OS << "<title>";
-      if (const auto *ND = dyn_cast<NamedDecl>(D))
-        *OS << ND->getNameAsString() << " at ";
-      *OS << SM.getFilename(D->getLocation()) << ":"
-          << SM.getSpellingLineNumber(D->getLocation());
-      *OS << "</title>\n";
-    };
+    const auto &D = CFG.getDecl();
+    const auto &SM = A.getASTContext().getSourceManager();
+    *OS << "<title>";
+    if (const auto *ND = dyn_cast<NamedDecl>(&D))
+      *OS << ND->getNameAsString() << " at ";
+    *OS << SM.getFilename(D.getLocation()) << ":"
+        << SM.getSpellingLineNumber(D.getLocation());
+    *OS << "</title>\n";
 
     *OS << "<style>" << HTMLLogger_css << "</style>\n";
     *OS << "<script>" << HTMLLogger_js << "</script>\n";
@@ -307,9 +306,7 @@
   // tokens are associated with, and even which BB element (so that clicking
   // can select the right element).
   void writeCode() {
-    if (!CFG->getDecl())
-      return;
-    const auto &AST = CFG->getDecl()->getASTContext();
+    const auto &AST = CFG->getDecl().getASTContext();
     bool Invalid = false;
 
     // Extract the source code from the original file.
@@ -317,7 +314,7 @@
     // indentation to worry about), but we need the boundaries of particular
     // AST nodes and the printer doesn't provide this.
     auto Range = clang::Lexer::makeFileCharRange(
-        CharSourceRange::getTokenRange(CFG->getDecl()->getSourceRange()),
+        CharSourceRange::getTokenRange(CFG->getDecl().getSourceRange()),
         AST.getSourceManager(), AST.getLangOpts());
     if (Range.isInvalid())
       return;
Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -105,7 +105,7 @@
 
   llvm::BitVector BlockReachable = findReachableBlocks(*Cfg);
 
-  return ControlFlowContext(&D, std::move(Cfg), std::move(StmtToBlock),
+  return ControlFlowContext(D, std::move(Cfg), std::move(StmtToBlock),
                             std::move(BlockReachable));
 }
 
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -48,7 +48,7 @@
 
   /// Returns the `Decl` containing the statement used to construct the CFG, if
   /// available.
-  const Decl *getDecl() const { return ContainingDecl; }
+  const Decl &getDecl() const { return ContainingDecl; }
 
   /// Returns the CFG that is stored in this context.
   const CFG &getCFG() const { return *Cfg; }
@@ -64,9 +64,7 @@
   }
 
 private:
-  // FIXME: Once the deprecated `build` method is removed, mark `D` as "must not
-  // be null" and add an assertion.
-  ControlFlowContext(const Decl *D, std::unique_ptr<CFG> Cfg,
+  ControlFlowContext(const Decl &D, std::unique_ptr<CFG> Cfg,
                      llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock,
                      llvm::BitVector BlockReachable)
       : ContainingDecl(D), Cfg(std::move(Cfg)),
@@ -74,7 +72,7 @@
         BlockReachable(std::move(BlockReachable)) {}
 
   /// The `Decl` containing the statement used to construct the CFG.
-  const Decl *ContainingDecl;
+  const Decl &ContainingDecl;
   std::unique_ptr<CFG> Cfg;
   llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock;
   llvm::BitVector BlockReachable;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to