19#include "llvm/ADT/BitVector.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/Support/Error.h"
28static llvm::DenseMap<const Stmt *, const CFGBlock *>
30 llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock;
42 if (
const Stmt *TerminatorStmt =
Block->getTerminatorStmt())
43 StmtToBlock[TerminatorStmt] =
Block;
52 BlocksToVisit.push_back(&Cfg.
getEntry());
53 while (!BlocksToVisit.empty()) {
55 BlocksToVisit.pop_back();
57 if (BlockReachable[
Block->getBlockID()])
60 BlockReachable[
Block->getBlockID()] =
true;
64 BlocksToVisit.push_back(Succ);
67 return BlockReachable;
73 return llvm::createStringError(
74 std::make_error_code(std::errc::invalid_argument),
75 "Cannot analyze function without a body");
83 return llvm::createStringError(
84 std::make_error_code(std::errc::invalid_argument),
85 "Cannot analyze templated declarations");
88 Options.PruneTriviallyFalseEdges =
true;
89 Options.AddImplicitDtors =
true;
90 Options.AddTemporaryDtors =
true;
91 Options.AddInitializers =
true;
92 Options.AddCXXDefaultInitExprInCtors =
true;
95 Options.setAllAlwaysAdd();
99 return llvm::createStringError(
100 std::make_error_code(std::errc::invalid_argument),
101 "CFG::buildCFG failed");
103 llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock =
109 std::move(BlockReachable));
115 return llvm::createStringError(
116 std::make_error_code(std::errc::invalid_argument),
117 "Declaration must not be null");
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a single basic block in a source-level CFG.
Represents a top-level expression in a basic block.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
static std::unique_ptr< CFG > buildCFG(const Decl *D, Stmt *AST, ASTContext *C, const BuildOptions &BO)
Builds a CFG from an AST.
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Represents a function declaration or definition.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Stmt - This represents one statement.
Holds CFG and other derived context that is needed to perform dataflow analysis.
static llvm::Expected< ControlFlowContext > build(const FunctionDecl &Func)
Builds a ControlFlowContext from a FunctionDecl.
static llvm::DenseMap< const Stmt *, const CFGBlock * > buildStmtToBasicBlockMap(const CFG &Cfg)
Returns a map from statements to basic blocks that contain them.
static llvm::BitVector findReachableBlocks(const CFG &Cfg)
@ C
Languages that the frontend can parse and compile.