clang: clang::CFGBlock Class Reference (original) (raw)

Represents a single basic block in a source-level CFG. More...

#include "[clang/Analysis/CFG.h](CFG%5F8h%5Fsource.html)"

Classes
class AdjacentBlock
This class represents a potential adjacent block in the CFG. More...
class FilteredCFGBlockIterator
class FilterOptions
Public Types
using iterator = ElementList::iterator
using const_iterator = ElementList::const_iterator
using reverse_iterator = ElementList::reverse_iterator
using const_reverse_iterator = ElementList::const_reverse_iterator
using CFGElementRef = ElementRefImpl< false >
using ConstCFGElementRef = ElementRefImpl< true >
using ref_iterator = ElementRefIterator< false, false >
using ref_iterator_range = llvm::iterator_range< ref_iterator >
using const_ref_iterator = ElementRefIterator< false, true >
using const_ref_iterator_range = llvm::iterator_range< const_ref_iterator >
using reverse_ref_iterator = ElementRefIterator< true, false >
using reverse_ref_iterator_range = llvm::iterator_range< reverse_ref_iterator >
using const_reverse_ref_iterator = ElementRefIterator< true, true >
using const_reverse_ref_iterator_range = llvm::iterator_range< const_reverse_ref_iterator >
using pred_iterator = AdjacentBlocks::iterator
using const_pred_iterator = AdjacentBlocks::const_iterator
using pred_reverse_iterator = AdjacentBlocks::reverse_iterator
using const_pred_reverse_iterator = AdjacentBlocks::const_reverse_iterator
using pred_range = llvm::iterator_range< pred_iterator >
using pred_const_range = llvm::iterator_range< const_pred_iterator >
using succ_iterator = AdjacentBlocks::iterator
using const_succ_iterator = AdjacentBlocks::const_iterator
using succ_reverse_iterator = AdjacentBlocks::reverse_iterator
using const_succ_reverse_iterator = AdjacentBlocks::const_reverse_iterator
using succ_range = llvm::iterator_range< succ_iterator >
using succ_const_range = llvm::iterator_range< const_succ_iterator >
using filtered_pred_iterator = FilteredCFGBlockIterator< const_pred_iterator, true >
using filtered_succ_iterator = FilteredCFGBlockIterator< const_succ_iterator, false >
Public Member Functions
CFGBlock (unsigned blockid, BumpVectorContext &C, CFG *parent)
size_t getIndexInCFG () const
CFGElement front () const
CFGElement back () const
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
reverse_iterator rbegin ()
reverse_iterator rend ()
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
ref_iterator ref_begin ()
ref_iterator ref_end ()
const_ref_iterator ref_begin () const
const_ref_iterator ref_end () const
reverse_ref_iterator rref_begin ()
reverse_ref_iterator rref_end ()
const_reverse_ref_iterator rref_begin () const
const_reverse_ref_iterator rref_end () const
ref_iterator_range refs ()
const_ref_iterator_range refs () const
reverse_ref_iterator_range rrefs ()
const_reverse_ref_iterator_range rrefs () const
unsigned size () const
bool empty () const
CFGElement operator[] (size_t i) const
pred_iterator pred_begin ()
pred_iterator pred_end ()
const_pred_iterator pred_begin () const
const_pred_iterator pred_end () const
pred_reverse_iterator pred_rbegin ()
pred_reverse_iterator pred_rend ()
const_pred_reverse_iterator pred_rbegin () const
const_pred_reverse_iterator pred_rend () const
pred_range preds ()
pred_const_range preds () const
succ_iterator succ_begin ()
succ_iterator succ_end ()
const_succ_iterator succ_begin () const
const_succ_iterator succ_end () const
succ_reverse_iterator succ_rbegin ()
succ_reverse_iterator succ_rend ()
const_succ_reverse_iterator succ_rbegin () const
const_succ_reverse_iterator succ_rend () const
succ_range succs ()
succ_const_range succs () const
unsigned succ_size () const
bool succ_empty () const
unsigned pred_size () const
bool pred_empty () const
filtered_pred_iterator filtered_pred_start_end (const FilterOptions &f) const
filtered_succ_iterator filtered_succ_start_end (const FilterOptions &f) const
void setTerminator (CFGTerminator Term)
void setLabel (Stmt *Statement)
void setLoopTarget (const Stmt *loopTarget)
void setHasNoReturnElement ()
bool isInevitablySinking () const
Returns true if the block would eventually end with a sink (a noreturn node).
CFGTerminator getTerminator () const
Stmt * getTerminatorStmt ()
const Stmt * getTerminatorStmt () const
const Expr * getLastCondition () const
Stmt * getTerminatorCondition (bool StripParens=true)
const Stmt * getTerminatorCondition (bool StripParens=true) const
const Stmt * getLoopTarget () const
Stmt * getLabel ()
const Stmt * getLabel () const
bool hasNoReturnElement () const
unsigned getBlockID () const
CFG * getParent () const
void dump () const
void dump (const CFG *cfg, const LangOptions &LO, bool ShowColors=false) const
dump - A simply pretty printer of a CFGBlock that outputs to stderr.
void print (raw_ostream &OS, const CFG *cfg, const LangOptions &LO, bool ShowColors) const
print - A simple pretty printer of a CFGBlock that outputs to an ostream.
void printTerminator (raw_ostream &OS, const LangOptions &LO) const
printTerminator - A simple pretty printer of the terminator of a CFGBlock.
void printTerminatorJson (raw_ostream &Out, const LangOptions &LO, bool AddQuotes) const
printTerminatorJson - Pretty-prints the terminator in JSON format.
void printAsOperand (raw_ostream &OS, bool)
void addSuccessor (AdjacentBlock Succ, BumpVectorContext &C)
Adds a (potentially unreachable) successor block to the current block.
void appendStmt (Stmt *statement, BumpVectorContext &C)
void appendConstructor (CXXConstructExpr *CE, const ConstructionContext *CC, BumpVectorContext &C)
void appendCXXRecordTypedCall (Expr *E, const ConstructionContext *CC, BumpVectorContext &C)
void appendInitializer (CXXCtorInitializer *initializer, BumpVectorContext &C)
void appendNewAllocator (CXXNewExpr *NE, BumpVectorContext &C)
void appendScopeBegin (const VarDecl *VD, const Stmt *S, BumpVectorContext &C)
void appendScopeEnd (const VarDecl *VD, const Stmt *S, BumpVectorContext &C)
void appendBaseDtor (const CXXBaseSpecifier *BS, BumpVectorContext &C)
void appendMemberDtor (FieldDecl *FD, BumpVectorContext &C)
void appendTemporaryDtor (CXXBindTemporaryExpr *E, BumpVectorContext &C)
void appendAutomaticObjDtor (VarDecl *VD, Stmt *S, BumpVectorContext &C)
void appendCleanupFunction (const VarDecl *VD, BumpVectorContext &C)
void appendLifetimeEnds (VarDecl *VD, Stmt *S, BumpVectorContext &C)
void appendLoopExit (const Stmt *LoopStmt, BumpVectorContext &C)
void appendDeleteDtor (CXXRecordDecl *RD, CXXDeleteExpr *DE, BumpVectorContext &C)
Public Attributes
ElementList Elements
The set of statements in the basic block.
Stmt * Label = nullptr
An (optional) label that prefixes the executable statements in the block.
CFGTerminator Terminator
The terminator for a basic block that indicates the type of control-flow that occurs between a block and its successors.
const Stmt * LoopTarget = nullptr
Some blocks are used to represent the "loop edge" to the start of a loop from within the loop body.
unsigned BlockID
A numerical ID assigned to a CFGBlock during construction of the CFG.

Represents a single basic block in a source-level CFG.

It consists of:

(1) A set of statements/expressions (which may contain subexpressions). (2) A "terminator" statement (not in the set of statements). (3) A list of successors and predecessors.

Terminator: The terminator represents the type of control-flow that occurs at the end of the basic block. The terminator is a Stmt* referring to an AST node that has control-flow: if-statements, breaks, loops, etc. If the control-flow is conditional, the condition expression will appear within the set of statements in the block (usually the last statement).

Predecessors: the order in the set of predecessors is arbitrary.

Successors: the order in the set of successors is NOT arbitrary. We currently have the following orderings based on the terminator:

Terminator Successor Ordering
if Then Block; Else Block
? operator LHS expression; RHS expression
logical and/or expression that consumes the op, RHS
vbase inits already handled by the most derived class; not yet

But note that any of that may be NULL in case of optimized-out edges.

Definition at line 604 of file CFG.h.

CFGElementRef

const_iterator

const_pred_iterator

const_pred_reverse_iterator

const_ref_iterator

const_ref_iterator_range

const_reverse_iterator

const_reverse_ref_iterator

const_reverse_ref_iterator_range

const_succ_iterator

const_succ_reverse_iterator

ConstCFGElementRef

filtered_pred_iterator

filtered_succ_iterator

iterator

pred_const_range

pred_iterator

pred_range

pred_reverse_iterator

ref_iterator

ref_iterator_range

reverse_iterator

reverse_ref_iterator

reverse_ref_iterator_range

succ_const_range

succ_iterator

succ_range

succ_reverse_iterator

addSuccessor()

appendAutomaticObjDtor()

appendBaseDtor()

appendCleanupFunction()

appendConstructor()

appendCXXRecordTypedCall()

appendDeleteDtor()

appendInitializer()

appendLifetimeEnds()

appendLoopExit()

appendMemberDtor()

appendNewAllocator()

appendScopeBegin()

appendScopeEnd()

appendStmt()

appendTemporaryDtor()

back()

begin() [1/2]

iterator clang::CFGBlock::begin ( ) inline

begin() [2/2]

dump() [1/2]

LLVM_DUMP_METHOD void CFGBlock::dump ( ) const

dump() [2/2]

empty()

bool clang::CFGBlock::empty ( ) const inline

end() [1/2]

iterator clang::CFGBlock::end ( ) inline

end() [2/2]

filtered_pred_start_end()

filtered_succ_start_end()

FilterEdge()

front()

CFGElement clang::CFGBlock::front ( ) const inline

getBlockID()

unsigned clang::CFGBlock::getBlockID ( ) const inline

Definition at line 1105 of file CFG.h.

References BlockID.

Referenced by clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), CheckFallThrough(), checkForRecursiveFunctionCall(), clang::LiveVariables::computeLiveness(), clang::DataflowWorklistBase< Comp, QueueSize >::dequeue(), clang::ento::CoreEngine::ExecuteWorkList(), clang::reachable_code::FindUnreachableCode(), clang::ento::CheckerContext::getBlockID(), clang::internal::getID(), clang::consumed::ConsumedBlockInfo::isBackEdge(), clang::dataflow::AdornedCFG::isBlockReachable(), clang::CFGReverseBlockReachabilityAnalysis::isReachable(), clang::threadSafety::SExprBuilder::lookupBlock(), clang::WTOCompare::operator()(), print_block(), printAsOperand(), runOnBlock(), clang::dataflow::runTypeErasedDataflowAnalysis(), clang::runUninitializedVariablesAnalysis(), scanFromBlock(), and throwEscapes().

getIndexInCFG()

size_t CFGBlock::getIndexInCFG ( ) const

getLabel() [1/2]

Stmt * clang::CFGBlock::getLabel ( ) inline

getLabel() [2/2]

const Stmt * clang::CFGBlock::getLabel ( ) const inline

getLastCondition()

const Expr * CFGBlock::getLastCondition ( ) const

Returns

the last ([rbegin()](classclang%5F1%5F1CFGBlock.html#a28d1c9e2bcd34217a4debc899ebb8a58)) condition, e.g. observe the following code snippet: if (A && B && C) A block would be created for A, B, and C. For the latter, [getTerminatorStmt()](classclang%5F1%5F1CFGBlock.html#a9e91112f6a1a24d88a426593138b45bd) would retrieve the entire condition, rather than C itself, while this method would only return C.

Definition at line 6242 of file CFG.cpp.

References clang::CFGElement::getAs(), clang::CFGTerminator::getKind(), clang::Expr::IgnoreParens(), rbegin(), size(), clang::CFGTerminator::StmtBranch, succ_size(), and Terminator.

getLoopTarget()

const Stmt * clang::CFGBlock::getLoopTarget ( ) const inline

getParent()

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

getTerminator()

getTerminatorCondition() [1/2]

Stmt * CFGBlock::getTerminatorCondition ( bool StripParens = true )

getTerminatorCondition() [2/2]

const Stmt * clang::CFGBlock::getTerminatorCondition ( bool StripParens = true) const inline

getTerminatorStmt() [1/2]

Stmt * clang::CFGBlock::getTerminatorStmt ( ) inline

Definition at line 1081 of file CFG.h.

References clang::CFGTerminator::getStmt(), and Terminator.

Referenced by Accumulate(), CheckFallThrough(), DiagnoseSwitchLabelsFallthrough(), FilterEdge(), getLastStmtLoc(), clang::BlockExit::getTerminator(), getTerminatorCondition(), isTrivialDoWhile(), peelOffOuterExpr(), clang::ento::ExprEngine::processCFGBlockEntrance(), shouldTreatSuccessorsAsReachable(), clang::ento::SuppressInlineDefensiveChecksVisitor::VisitNode(), and clang::ento::ConditionBRVisitor::VisitNodeImpl().

getTerminatorStmt() [2/2]

const Stmt * clang::CFGBlock::getTerminatorStmt ( ) const inline

hasNoReturnElement()

bool clang::CFGBlock::hasNoReturnElement ( ) const inline

isInevitablySinking()

bool CFGBlock::isInevitablySinking ( ) const

operator[]()

pred_begin() [1/2]

pred_begin() [2/2]

pred_empty()

bool clang::CFGBlock::pred_empty ( ) const inline

pred_end() [1/2]

pred_end() [2/2]

pred_rbegin() [1/2]

pred_rbegin() [2/2]

pred_rend() [1/2]

pred_rend() [2/2]

pred_size()

unsigned clang::CFGBlock::pred_size ( ) const inline

preds() [1/2]

preds() [2/2]

print()

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

printAsOperand()

void clang::CFGBlock::printAsOperand ( raw_ostream & OS, bool ) inline

printTerminator()

void CFGBlock::printTerminator ( raw_ostream & OS,
const LangOptions & LO
) const

printTerminatorJson()

void CFGBlock::printTerminatorJson ( raw_ostream & Out,
const LangOptions & LO,
bool AddQuotes
) const

rbegin() [1/2]

rbegin() [2/2]

ref_begin() [1/2]

ref_begin() [2/2]

ref_end() [1/2]

ref_end() [2/2]

refs() [1/2]

refs() [2/2]

rend() [1/2]

rend() [2/2]

rref_begin() [1/2]

rref_begin() [2/2]

rref_end() [1/2]

rref_end() [2/2]

rrefs() [1/2]

rrefs() [2/2]

setHasNoReturnElement()

void clang::CFGBlock::setHasNoReturnElement ( ) inline

Definition at line 1073 of file CFG.h.

setLabel()

void clang::CFGBlock::setLabel ( Stmt * Statement) inline

setLoopTarget()

void clang::CFGBlock::setLoopTarget ( const Stmt * loopTarget) inline

setTerminator()

size()

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

succ_begin() [1/2]

Definition at line 984 of file CFG.h.

Referenced by clang::ento::IndirectGotoNodeBuilder::begin(), clang::dataflow::blockIndexInPredecessor(), checkForRecursiveFunctionCall(), llvm::GraphTraits< ::clang::CFGBlock * >::child_begin(), llvm::GraphTraits< const ::clang::CFGBlock * >::child_begin(), clang::LiveVariables::computeLiveness(), DiagnoseSwitchLabelsFallthrough(), clang::ento::CoreEngine::ExecuteWorkList(), filtered_succ_start_end(), getFirstStmtLoc(), getLastStmtLoc(), isAssertlikeBlock(), isJumpToFalseBranch(), peelOffOuterExpr(), print_block(), clang::ento::ExprEngine::processCallEnter(), scanFromBlock(), succs(), clang::ento::ExprEngine::VisitLogicalExpr(), and clang::ento::ConditionBRVisitor::VisitTerminator().

succ_begin() [2/2]

succ_empty()

bool clang::CFGBlock::succ_empty ( ) const inline

succ_end() [1/2]

succ_end() [2/2]

succ_rbegin() [1/2]

succ_rbegin() [2/2]

succ_rend() [1/2]

succ_rend() [2/2]

succ_size()

unsigned clang::CFGBlock::succ_size ( ) const inline

Definition at line 1002 of file CFG.h.

Referenced by DiagnoseSwitchLabelsFallthrough(), clang::ento::CoreEngine::ExecuteWorkList(), getFirstStmtLoc(), getLastCondition(), getLastStmtLoc(), isAssertlikeBlock(), isJumpToFalseBranch(), print_block(), clang::ento::ExprEngine::processCallEnter(), clang::ento::ExprEngine::VisitLogicalExpr(), and clang::ento::ConditionBRVisitor::VisitTerminator().

succs() [1/2]

succs() [2/2]

BlockID

Elements

ElementList clang::CFGBlock::Elements

The set of statements in the basic block.

Definition at line 794 of file CFG.h.

Referenced by appendAutomaticObjDtor(), appendBaseDtor(), appendCleanupFunction(), appendConstructor(), appendCXXRecordTypedCall(), appendDeleteDtor(), appendInitializer(), appendLifetimeEnds(), appendLoopExit(), appendMemberDtor(), appendNewAllocator(), appendScopeBegin(), appendScopeEnd(), appendStmt(), appendTemporaryDtor(), back(), begin(), empty(), end(), front(), operator, rbegin(), rend(), and size().

Label

Stmt* clang::CFGBlock::Label = nullptr

LoopTarget

const Stmt* clang::CFGBlock::LoopTarget = nullptr

Some blocks are used to represent the "loop edge" to the start of a loop from within the loop body.

This Stmt* will be refer to the loop statement for such blocks (and be null otherwise).

Definition at line 808 of file CFG.h.

Referenced by getLoopTarget(), and setLoopTarget().

Terminator


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