diff --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h --- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h +++ b/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, + ControlFlowContext(const Decl &D, std::unique_ptr Cfg, llvm::DenseMap 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; llvm::DenseMap StmtToBlock; llvm::BitVector BlockReachable; diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp --- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp +++ b/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)); } diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp --- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp +++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp @@ -167,15 +167,14 @@ this->CFG = &CFG; *OS << llvm::StringRef(HTMLLogger_html).split("").first; - if (const auto *D = CFG.getDecl()) { - const auto &SM = A.getASTContext().getSourceManager(); - *OS << ""; - if (const auto *ND = dyn_cast<NamedDecl>(D)) - *OS << ND->getNameAsString() << " at "; - *OS << SM.getFilename(D->getLocation()) << ":" - << SM.getSpellingLineNumber(D->getLocation()); - *OS << "\n"; - }; + const auto &D = CFG.getDecl(); + const auto &SM = A.getASTContext().getSourceManager(); + *OS << ""; + if (const auto *ND = dyn_cast<NamedDecl>(&D)) + *OS << ND->getNameAsString() << " at "; + *OS << SM.getFilename(D.getLocation()) << ":" + << SM.getSpellingLineNumber(D.getLocation()); + *OS << "\n"; *OS << "\n"; *OS << "\n"; @@ -308,9 +307,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. @@ -318,7 +315,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; diff --git a/clang/lib/Analysis/FlowSensitive/Logger.cpp b/clang/lib/Analysis/FlowSensitive/Logger.cpp --- a/clang/lib/Analysis/FlowSensitive/Logger.cpp +++ b/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; diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -727,9 +727,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 = diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp --- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ b/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); }