clang 24.0.0git
clang::CFG Class Reference

Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt. More...

#include "clang/Analysis/CFG.h"

Classes

class  BuildOptions

Public Types

using CFGBlockListTy = BumpVector<CFGBlock *>
using iterator = CFGBlockListTy::iterator
using const_iterator = CFGBlockListTy::const_iterator
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>
using try_block_iterator = std::vector<const CFGBlock *>::const_iterator
using try_block_range = llvm::iterator_range<try_block_iterator>
using synthetic_stmt_iterator
using synthetic_stmt_range = llvm::iterator_range<synthetic_stmt_iterator>

Public Member Functions

CFGBlock * createBlock ()
 Create a new block in the CFG.
void setEntry (CFGBlock *B)
 Set the entry block of the CFG.
void setIndirectGotoBlock (CFGBlock *B)
 Set the block used for indirect goto jumps.
CFGBlock & front ()
CFGBlock & back ()
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
iterator nodes_begin ()
iterator nodes_end ()
llvm::iterator_range< iterator > nodes ()
llvm::iterator_range< const_iterator > const_nodes () const
const_iterator nodes_begin () const
const_iterator nodes_end () const
reverse_iterator rbegin ()
reverse_iterator rend ()
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
llvm::iterator_range< reverse_iterator > reverse_nodes ()
llvm::iterator_range< const_reverse_iterator > const_reverse_nodes () const
CFGBlock & getEntry ()
const CFGBlock & getEntry () const
CFGBlock & getExit ()
const CFGBlock & getExit () const
CFGBlock * getIndirectGotoBlock ()
const CFGBlock * getIndirectGotoBlock () const
try_block_iterator try_blocks_begin () const
try_block_iterator try_blocks_end () const
try_block_range try_blocks () const
void addTryDispatchBlock (const CFGBlock *block)
void addSyntheticDeclStmt (const DeclStmt *Synthetic, const DeclStmt *Source)
 Records a synthetic DeclStmt and the DeclStmt it was constructed from.
synthetic_stmt_iterator synthetic_stmt_begin () const
 Iterates over synthetic DeclStmts in the CFG.
synthetic_stmt_iterator synthetic_stmt_end () const
synthetic_stmt_range synthetic_stmts () const
template<typename Callback>
void VisitBlockStmts (Callback &O) const
unsigned getNumBlockIDs () const
 Returns the total number of BlockIDs allocated (which start at 0).
unsigned size () const
 Return the total number of CFGBlocks within the CFG This is simply a renaming of the getNumBlockIDs().
bool isLinear () const
 Returns true if the CFG has no branches.
void viewCFG (const LangOptions &LO) const
void print (raw_ostream &OS, const LangOptions &LO, bool ShowColors) const
 print - A simple pretty printer of a CFG that outputs to an ostream.
void dump (const LangOptions &LO, bool ShowColors) const
 dump - A simple pretty printer of a CFG that outputs to stderr.
 CFG ()
llvm::BumpPtrAllocator & getAllocator ()
BumpVectorContext & getBumpVectorContext ()

Static Public Member Functions

static std::unique_ptr< CFG > buildCFG (const Decl *D, Stmt *AST, ASTContext *C, const BuildOptions &BO)
 Builds a CFG from an AST.

Detailed Description

Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.

The Stmt can represent an entire function body, or a single expression. A CFG will always contain one empty block that represents the Exit point of the CFG. A CFG will also contain a designated Entry block. The CFG solely represents control-flow; it consists of CFGBlocks which are simply containers of Stmt*'s in the AST the CFG was constructed from.

Definition at line 1295 of file CFG.h.

Member Typedef Documentation

◆ CFGBlockListTy

Definition at line 1372 of file CFG.h.

◆ const_iterator

◆ const_reverse_iterator

using clang::CFG::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 1376 of file CFG.h.

◆ iterator

Definition at line 1373 of file CFG.h.

◆ reverse_iterator

using clang::CFG::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 1375 of file CFG.h.

◆ synthetic_stmt_iterator

Initial value:
llvm::DenseMap<const DeclStmt *, const DeclStmt *>::const_iterator

Definition at line 1448 of file CFG.h.

◆ synthetic_stmt_range

Definition at line 1450 of file CFG.h.

◆ try_block_iterator

Definition at line 1417 of file CFG.h.

◆ try_block_range

using clang::CFG::try_block_range = llvm::iterator_range<try_block_iterator>

Definition at line 1418 of file CFG.h.

Constructor & Destructor Documentation

◆ CFG()

clang::CFG::CFG ( )
inline

Definition at line 1513 of file CFG.h.

Member Function Documentation

◆ addSyntheticDeclStmt()

void clang::CFG::addSyntheticDeclStmt ( const DeclStmt * Synthetic,
const DeclStmt * Source )
inline

Records a synthetic DeclStmt and the DeclStmt it was constructed from.

The CFG uses synthetic DeclStmts when a single AST DeclStmt contains multiple decls.

Definition at line 1440 of file CFG.h.

References clang::DeclStmt::isSingleDecl().

◆ addTryDispatchBlock()

void clang::CFG::addTryDispatchBlock ( const CFGBlock * block)
inline

Definition at line 1432 of file CFG.h.

◆ back()

CFGBlock & clang::CFG::back ( )
inline

Definition at line 1379 of file CFG.h.

References clang::CFGBlock::back().

Referenced by createBlock().

◆ begin() [1/2]

iterator clang::CFG::begin ( )
inline

Definition at line 1381 of file CFG.h.

References clang::CFGBlock::begin().

Referenced by const_nodes(), createBlock(), clang::CFGBlock::getIndexInCFG(), and nodes().

◆ begin() [2/2]

const_iterator clang::CFG::begin ( ) const
inline

Definition at line 1383 of file CFG.h.

References clang::CFGBlock::begin().

◆ buildCFG()

std::unique_ptr< CFG > CFG::buildCFG ( const Decl * D,
Stmt * AST,
ASTContext * C,
const BuildOptions & BO )
static

Builds a CFG from an AST.

buildCFG - Constructs a CFG from an AST.

Definition at line 5469 of file CFG.cpp.

References clang::C.

Referenced by clang::dataflow::AdornedCFG::build(), clang::AnalysisDeclContext::getCFG(), and clang::AnalysisDeclContext::getUnoptimizedCFG().

◆ const_nodes()

llvm::iterator_range< const_iterator > clang::CFG::const_nodes ( ) const
inline

Definition at line 1390 of file CFG.h.

References begin(), and end().

◆ const_reverse_nodes()

llvm::iterator_range< const_reverse_iterator > clang::CFG::const_reverse_nodes ( ) const
inline

Definition at line 1405 of file CFG.h.

References rbegin(), and rend().

◆ createBlock()

CFGBlock * CFG::createBlock ( )

Create a new block in the CFG.

createBlock - Constructs and adds a new CFGBlock to the CFG.

The CFG owns the block; the caller should not directly free it.

The block has no successors or predecessors. If this is the first block created in the CFG, it is automatically set to be the Entry and Exit of the CFG.

Definition at line 5453 of file CFG.cpp.

References back(), begin(), end(), and getAllocator().

◆ dump()

void CFG::dump ( const LangOptions & LO,
bool ShowColors ) const

dump - A simple pretty printer of a CFG that outputs to stderr.

Definition at line 6374 of file CFG.cpp.

References clang::CFGBlock::print().

Referenced by clang::lifetimes::internal::DebugOnlyFunction(), clang::AnalysisDeclContext::dumpCFG(), and clang::lifetimes::internal::LifetimeSafetyAnalysis::run().

◆ end() [1/2]

iterator clang::CFG::end ( )
inline

Definition at line 1382 of file CFG.h.

References clang::CFGBlock::end().

Referenced by const_nodes(), createBlock(), and nodes().

◆ end() [2/2]

const_iterator clang::CFG::end ( ) const
inline

Definition at line 1384 of file CFG.h.

References clang::CFGBlock::end().

◆ front()

CFGBlock & clang::CFG::front ( )
inline

Definition at line 1378 of file CFG.h.

References clang::CFGBlock::front().

◆ getAllocator()

llvm::BumpPtrAllocator & clang::CFG::getAllocator ( )
inline

Definition at line 1515 of file CFG.h.

Referenced by createBlock().

◆ getBumpVectorContext()

BumpVectorContext & clang::CFG::getBumpVectorContext ( )
inline

Definition at line 1519 of file CFG.h.

◆ getEntry() [1/2]

◆ getEntry() [2/2]

const CFGBlock & clang::CFG::getEntry ( ) const
inline

Definition at line 1410 of file CFG.h.

◆ getExit() [1/2]

◆ getExit() [2/2]

const CFGBlock & clang::CFG::getExit ( ) const
inline

Definition at line 1412 of file CFG.h.

◆ getIndirectGotoBlock() [1/2]

CFGBlock * clang::CFG::getIndirectGotoBlock ( )
inline

Definition at line 1414 of file CFG.h.

Referenced by print_block().

◆ getIndirectGotoBlock() [2/2]

const CFGBlock * clang::CFG::getIndirectGotoBlock ( ) const
inline

Definition at line 1415 of file CFG.h.

◆ getNumBlockIDs()

◆ isLinear()

bool CFG::isLinear ( ) const

Returns true if the CFG has no branches.

Usually it boils down to the CFG having exactly three blocks (entry, the actual code, exit), but sometimes more blocks appear due to having control flow that can be fully resolved in compile time.

Definition at line 5476 of file CFG.cpp.

References size(), and clang::CFGBlock::succs().

Referenced by clang::ento::NoStateChangeFuncVisitor::VisitNode().

◆ nodes()

llvm::iterator_range< iterator > clang::CFG::nodes ( )
inline

Definition at line 1389 of file CFG.h.

References begin(), and end().

Referenced by clang::LiveVariables::computeLiveness().

◆ nodes_begin() [1/2]

iterator clang::CFG::nodes_begin ( )
inline

◆ nodes_begin() [2/2]

const_iterator clang::CFG::nodes_begin ( ) const
inline

Definition at line 1394 of file CFG.h.

◆ nodes_end() [1/2]

iterator clang::CFG::nodes_end ( )
inline

◆ nodes_end() [2/2]

const_iterator clang::CFG::nodes_end ( ) const
inline

Definition at line 1395 of file CFG.h.

◆ print()

void CFG::print ( raw_ostream & OS,
const LangOptions & LO,
bool ShowColors ) const

print - A simple pretty printer of a CFG that outputs to an ostream.

Definition at line 6379 of file CFG.cpp.

References getEntry(), getExit(), and print_block().

◆ rbegin() [1/2]

reverse_iterator clang::CFG::rbegin ( )
inline

Definition at line 1397 of file CFG.h.

Referenced by const_reverse_nodes(), and reverse_nodes().

◆ rbegin() [2/2]

const_reverse_iterator clang::CFG::rbegin ( ) const
inline

Definition at line 1399 of file CFG.h.

◆ rend() [1/2]

reverse_iterator clang::CFG::rend ( )
inline

Definition at line 1398 of file CFG.h.

Referenced by const_reverse_nodes(), and reverse_nodes().

◆ rend() [2/2]

const_reverse_iterator clang::CFG::rend ( ) const
inline

Definition at line 1400 of file CFG.h.

◆ reverse_nodes()

llvm::iterator_range< reverse_iterator > clang::CFG::reverse_nodes ( )
inline

Definition at line 1402 of file CFG.h.

References rbegin(), and rend().

◆ setEntry()

void clang::CFG::setEntry ( CFGBlock * B)
inline

Set the entry block of the CFG.

This is typically used only during CFG construction. Most CFG clients expect that the entry block has no predecessors and contains no statements.

Definition at line 1362 of file CFG.h.

◆ setIndirectGotoBlock()

void clang::CFG::setIndirectGotoBlock ( CFGBlock * B)
inline

Set the block used for indirect goto jumps.

This is typically used only during CFG construction.

Definition at line 1366 of file CFG.h.

◆ size()

unsigned clang::CFG::size ( ) const
inline

Return the total number of CFGBlocks within the CFG This is simply a renaming of the getNumBlockIDs().

This is necessary because the dominator implementation needs such an interface.

Definition at line 1493 of file CFG.h.

Referenced by clang::getIntervalWTO(), isLinear(), clang::dataflow::NumReachableBlocks(), clang::dataflow::runTypeErasedDataflowAnalysis(), and llvm::GraphTraits<::clang::CFG * >::size().

◆ synthetic_stmt_begin()

synthetic_stmt_iterator clang::CFG::synthetic_stmt_begin ( ) const
inline

Iterates over synthetic DeclStmts in the CFG.

Each element is a (synthetic statement, source statement) pair.

See also
addSyntheticDeclStmt

Definition at line 1457 of file CFG.h.

Referenced by addParentsForSyntheticStmts(), and synthetic_stmts().

◆ synthetic_stmt_end()

synthetic_stmt_iterator clang::CFG::synthetic_stmt_end ( ) const
inline
See also
synthetic_stmt_begin

Definition at line 1462 of file CFG.h.

Referenced by addParentsForSyntheticStmts(), and synthetic_stmts().

◆ synthetic_stmts()

synthetic_stmt_range clang::CFG::synthetic_stmts ( ) const
inline
See also
synthetic_stmt_begin

Definition at line 1467 of file CFG.h.

References synthetic_stmt_begin(), and synthetic_stmt_end().

◆ try_blocks()

try_block_range clang::CFG::try_blocks ( ) const
inline

Definition at line 1428 of file CFG.h.

References try_blocks_begin(), and try_blocks_end().

Referenced by clang::reachable_code::FindUnreachableCode().

◆ try_blocks_begin()

try_block_iterator clang::CFG::try_blocks_begin ( ) const
inline

Definition at line 1420 of file CFG.h.

Referenced by try_blocks().

◆ try_blocks_end()

try_block_iterator clang::CFG::try_blocks_end ( ) const
inline

Definition at line 1424 of file CFG.h.

Referenced by try_blocks().

◆ viewCFG()

void CFG::viewCFG ( const LangOptions & LO) const

Definition at line 6604 of file CFG.cpp.

References GraphHelper.

◆ VisitBlockStmts()

template<typename Callback>
void clang::CFG::VisitBlockStmts ( Callback & O) const
inline

Definition at line 1475 of file CFG.h.

References clang::Callback, and clang::ast_matchers::stmt.

Referenced by clang::runUninitializedVariablesAnalysis().


The documentation for this class was generated from the following files: