clang
15.0.0git
|
Represents a single basic block in a source-level CFG. More...
#include "clang/Analysis/CFG.h"
Classes | |
class | AdjacentBlock |
This class represents a potential adjacent block in the CFG. More... | |
class | FilteredCFGBlockIterator |
class | FilterOptions |
Static Public Member Functions | |
static bool | FilterEdge (const FilterOptions &F, const CFGBlock *Src, const CFGBlock *Dst) |
Public Attributes | |
ElementList | Elements |
The set of statements in the basic block. More... | |
Stmt * | Label = nullptr |
An (optional) label that prefixes the executable statements in the block. More... | |
CFGTerminator | Terminator |
The terminator for a basic block that indicates the type of control-flow that occurs between a block and its successors. More... | |
const Stmt * | LoopTarget = nullptr |
Some blocks are used to represent the "loop edge" to the start of a loop from within the loop body. More... | |
unsigned | BlockID |
A numerical ID assigned to a CFGBlock during construction of the CFG. More... | |
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.
using clang::CFGBlock::CFGElementRef = ElementRefImpl<false> |
using clang::CFGBlock::const_iterator = ElementList::const_iterator |
using clang::CFGBlock::const_ref_iterator = ElementRefIterator<false, true> |
using clang::CFGBlock::const_ref_iterator_range = llvm::iterator_range<const_ref_iterator> |
using clang::CFGBlock::const_reverse_ref_iterator = ElementRefIterator<true, true> |
using clang::CFGBlock::const_reverse_ref_iterator_range = llvm::iterator_range<const_reverse_ref_iterator> |
using clang::CFGBlock::ConstCFGElementRef = ElementRefImpl<true> |
using clang::CFGBlock::iterator = ElementList::iterator |
using clang::CFGBlock::pred_const_range = llvm::iterator_range<const_pred_iterator> |
using clang::CFGBlock::pred_range = llvm::iterator_range<pred_iterator> |
using clang::CFGBlock::ref_iterator = ElementRefIterator<false, false> |
using clang::CFGBlock::ref_iterator_range = llvm::iterator_range<ref_iterator> |
using clang::CFGBlock::reverse_ref_iterator = ElementRefIterator<true, false> |
using clang::CFGBlock::reverse_ref_iterator_range = llvm::iterator_range<reverse_ref_iterator> |
using clang::CFGBlock::succ_const_range = llvm::iterator_range<const_succ_iterator> |
using clang::CFGBlock::succ_range = llvm::iterator_range<succ_iterator> |
|
inlineexplicit |
void CFGBlock::addSuccessor | ( | AdjacentBlock | Succ, |
BumpVectorContext & | C | ||
) |
Adds a (potentially unreachable) successor block to the current block.
Definition at line 5180 of file CFG.cpp.
References clang::CFGBlock::AdjacentBlock::getPossiblyUnreachableBlock(), clang::CFGBlock::AdjacentBlock::getReachableBlock(), clang::CFGBlock::AdjacentBlock::isReachable(), and clang::BumpVector< T >::push_back().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 1115 of file CFG.h.
References Elements, and clang::interp::NE().
|
inline |
|
inline |
|
inline |
Definition at line 1095 of file CFG.h.
References Elements, and clang::transformer::statement().
|
inline |
|
inline |
|
inline |
Definition at line 875 of file CFG.h.
References Elements.
Referenced by Accumulate(), print_block(), and ref_begin().
|
inline |
|
inline |
|
inline |
|
inline |
LLVM_DUMP_METHOD void CFGBlock::dump | ( | ) | const |
Definition at line 5932 of file CFG.cpp.
References getParent().
void CFGBlock::dump | ( | const CFG * | cfg, |
const LangOptions & | LO, | ||
bool | ShowColors = false |
||
) | const |
|
inline |
Definition at line 918 of file CFG.h.
References Elements.
Referenced by clang::ento::CoreEngine::ExecuteWorkList(), clang::BlockEntrance::getFirstElement(), neverReturns(), clang::ento::ExprEngine::processCallEnter(), and clang::ento::ExprEngine::VisitLogicalExpr().
|
inline |
Definition at line 876 of file CFG.h.
References Elements.
Referenced by Accumulate(), print_block(), and ref_end().
|
inline |
|
inline |
Definition at line 1029 of file CFG.h.
References pred_begin(), and pred_end().
|
inline |
Definition at line 1033 of file CFG.h.
References succ_begin(), and succ_end().
|
static |
Definition at line 5191 of file CFG.cpp.
References clang::CFGBlock::FilterOptions::IgnoreDefaultsWithCoveredEnums, and clang::CFGBlock::FilterOptions::IgnoreNullPredecessors.
|
inline |
Definition at line 872 of file CFG.h.
References Elements.
Referenced by clang::BlockEntrance::getFirstElement().
|
inline |
Definition at line 1074 of file CFG.h.
References BlockID.
Referenced by clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), clang::ento::NodeBuilderContext::blockCount(), CheckFallThrough(), checkForRecursiveFunctionCall(), clang::LiveVariables::computeLiveness(), clang::DataflowWorklistBase< PostOrderCFGView::BlockOrderCompare, 20 >::dequeue(), clang::ento::CoreEngine::ExecuteWorkList(), clang::reachable_code::FindUnreachableCode(), clang::ento::CheckerContext::getBlockID(), clang::consumed::ConsumedBlockInfo::isBackEdge(), clang::CFGReverseBlockReachabilityAnalysis::isReachable(), clang::threadSafety::SExprBuilder::lookupBlock(), print_block(), printAsOperand(), runOnBlock(), clang::dataflow::runTypeErasedDataflowAnalysis(), clang::runUninitializedVariablesAnalysis(), and scanFromBlock().
size_t CFGBlock::getIndexInCFG | ( | ) | const |
Definition at line 5922 of file CFG.cpp.
References clang::CFG::begin(), and getParent().
|
inline |
Definition at line 1069 of file CFG.h.
References Label.
Referenced by Accumulate(), and print_block().
|
inline |
const Expr * CFGBlock::getLastCondition | ( | ) | const |
rbegin()
) 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()
would retrieve the entire condition, rather than C itself, while this method would only return C. Definition at line 6028 of file CFG.cpp.
References clang::CFGElement::getAs(), clang::CFGTerminator::getKind(), clang::Expr::IgnoreParens(), rbegin(), size(), clang::CFGTerminator::StmtBranch, succ_size(), and Terminator.
|
inline |
Definition at line 1067 of file CFG.h.
References LoopTarget.
|
inline |
Definition at line 1076 of file CFG.h.
References Parent.
Referenced by annotateStartParameter(), dump(), getIndexInCFG(), and isInevitablySinking().
|
inline |
Definition at line 1048 of file CFG.h.
References Terminator.
Referenced by clang::ento::SwitchNodeBuilder::getSwitch(), print_block(), printTerminator(), ResolveCondition(), and clang::ento::ExprEngine::VisitLogicalExpr().
Definition at line 6056 of file CFG.cpp.
References getTerminatorStmt(), clang::Expr::IgnoreParens(), and Terminator.
Referenced by getTerminatorCondition(), isAssertlikeBlock(), and shouldTreatSuccessorsAsReachable().
Definition at line 1063 of file CFG.h.
References getTerminatorCondition().
|
inline |
Definition at line 1050 of file CFG.h.
References clang::CFGTerminator::getStmt(), and Terminator.
Referenced by Accumulate(), CheckFallThrough(), clang::BlockExit::getTerminator(), getTerminatorCondition(), peelOffOuterExpr(), clang::ento::ExprEngine::processCFGBlockEntrance(), shouldTreatSuccessorsAsReachable(), clang::ento::SuppressInlineDefensiveChecksVisitor::VisitNode(), and clang::ento::ConditionBRVisitor::VisitNodeImpl().
|
inline |
Definition at line 1051 of file CFG.h.
References clang::CFGTerminator::getStmt(), and Terminator.
|
inline |
Definition at line 1072 of file CFG.h.
Referenced by CheckFallThrough(), isImmediateSinkBlock(), neverReturns(), and print_block().
bool CFGBlock::isInevitablySinking | ( | ) | const |
Returns true if the block would eventually end with a sink (a noreturn node).
Definition at line 5990 of file CFG.cpp.
References clang::CFG::getExit(), getParent(), isImmediateSinkBlock(), and succs().
Referenced by isAssertlikeBlock().
|
inline |
|
inline |
Definition at line 937 of file CFG.h.
Referenced by clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), llvm::GraphTraits< Inverse< ::clang::CFGBlock * > >::child_begin(), llvm::GraphTraits< Inverse< const ::clang::CFGBlock * > >::child_begin(), filtered_pred_start_end(), preds(), print_block(), and runOnBlock().
|
inline |
|
inline |
Definition at line 977 of file CFG.h.
Referenced by print_block().
|
inline |
Definition at line 938 of file CFG.h.
Referenced by clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), llvm::GraphTraits< Inverse< ::clang::CFGBlock * > >::child_end(), llvm::GraphTraits< Inverse< const ::clang::CFGBlock * > >::child_end(), filtered_pred_start_end(), preds(), print_block(), and runOnBlock().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 976 of file CFG.h.
Referenced by print_block().
|
inline |
Definition at line 947 of file CFG.h.
References pred_begin(), and pred_end().
|
inline |
Definition at line 951 of file CFG.h.
References pred_begin(), and pred_end().
|
inline |
|
inline |
void CFGBlock::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.
Generally this will only be called from CFG::print.
Definition at line 5938 of file CFG.cpp.
References print_block().
Referenced by dump(), and clang::CFG::dump().
|
inline |
Definition at line 1088 of file CFG.h.
References getBlockID().
void CFGBlock::printTerminator | ( | raw_ostream & | OS, |
const LangOptions & | LO | ||
) | const |
printTerminator - A simple pretty printer of the terminator of a CFGBlock.
Definition at line 5946 of file CFG.cpp.
References getTerminator().
void CFGBlock::printTerminatorJson | ( | raw_ostream & | Out, |
const LangOptions & | LO, | ||
bool | AddQuotes | ||
) | const |
|
inline |
Definition at line 880 of file CFG.h.
References Elements.
Referenced by CheckFallThrough(), getLastCondition(), ResolveCondition(), rref_begin(), and clang::ento::ExprEngine::VisitLogicalExpr().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 910 of file CFG.h.
References ref_begin(), and ref_end().
|
inline |
Definition at line 911 of file CFG.h.
References ref_begin(), and ref_end().
|
inline |
Definition at line 881 of file CFG.h.
References Elements.
Referenced by CheckFallThrough(), ResolveCondition(), and rref_end().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 912 of file CFG.h.
References rref_begin(), and rref_end().
|
inline |
Definition at line 913 of file CFG.h.
References rref_begin(), and rref_end().
|
inline |
|
inline |
Definition at line 1041 of file CFG.h.
References LoopTarget.
|
inline |
Definition at line 1039 of file CFG.h.
References Terminator.
|
inline |
Definition at line 917 of file CFG.h.
References Elements.
Referenced by clang::ento::CallEvent::getCalleeStackFrame(), and getLastCondition().
|
inline |
Definition at line 955 of file CFG.h.
Referenced by clang::ento::IndirectGotoNodeBuilder::begin(), clang::dataflow::blockIndexInPredecessor(), llvm::GraphTraits< ::clang::CFGBlock * >::child_begin(), llvm::GraphTraits< const ::clang::CFGBlock * >::child_begin(), clang::LiveVariables::computeLiveness(), clang::ento::CoreEngine::ExecuteWorkList(), filtered_succ_start_end(), isAssertlikeBlock(), isJumpToFalseBranch(), peelOffOuterExpr(), print_block(), clang::ento::ExprEngine::processCallEnter(), scanFromBlock(), succs(), clang::ento::ExprEngine::VisitLogicalExpr(), and clang::ento::ConditionBRVisitor::VisitTerminator().
|
inline |
|
inline |
Definition at line 974 of file CFG.h.
Referenced by print_block().
|
inline |
Definition at line 956 of file CFG.h.
Referenced by llvm::GraphTraits< ::clang::CFGBlock * >::child_end(), llvm::GraphTraits< const ::clang::CFGBlock * >::child_end(), clang::LiveVariables::computeLiveness(), clang::ento::IndirectGotoNodeBuilder::end(), filtered_succ_start_end(), print_block(), scanFromBlock(), and succs().
|
inline |
|
inline |
Definition at line 960 of file CFG.h.
Referenced by clang::ento::SwitchNodeBuilder::begin(), and clang::ento::SwitchNodeBuilder::generateDefaultCaseNode().
|
inline |
|
inline |
Definition at line 961 of file CFG.h.
Referenced by clang::ento::SwitchNodeBuilder::end(), and clang::ento::SwitchNodeBuilder::generateDefaultCaseNode().
|
inline |
|
inline |
Definition at line 973 of file CFG.h.
Referenced by clang::ento::CoreEngine::ExecuteWorkList(), getLastCondition(), isAssertlikeBlock(), isJumpToFalseBranch(), print_block(), clang::ento::ExprEngine::processCallEnter(), clang::ento::ExprEngine::VisitLogicalExpr(), and clang::ento::ConditionBRVisitor::VisitTerminator().
|
inline |
Definition at line 965 of file CFG.h.
References succ_begin(), and succ_end().
Referenced by clang::dataflow::blockIndexInPredecessor(), isInevitablySinking(), and clang::CFG::isLinear().
|
inline |
Definition at line 969 of file CFG.h.
References succ_begin(), and succ_end().
unsigned clang::CFGBlock::BlockID |
A numerical ID assigned to a CFGBlock during construction of the CFG.
Definition at line 783 of file CFG.h.
Referenced by getBlockID().
ElementList clang::CFGBlock::Elements |
The set of statements in the basic block.
Definition at line 766 of file CFG.h.
Referenced by appendBaseDtor(), appendConstructor(), appendCXXRecordTypedCall(), appendDeleteDtor(), appendInitializer(), appendLoopExit(), appendMemberDtor(), appendNewAllocator(), appendStmt(), appendTemporaryDtor(), back(), begin(), beginAutomaticObjDtorsInsert(), beginLifetimeEndsInsert(), beginScopeEndInsert(), empty(), end(), front(), operator[](), rbegin(), rend(), and size().
Stmt* clang::CFGBlock::Label = nullptr |
An (optional) label that prefixes the executable statements in the block.
When this variable is non-NULL, it is either an instance of LabelStmt, SwitchCase or CXXCatchStmt.
Definition at line 771 of file CFG.h.
Referenced by getLabel(), print_block(), and setLabel().
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 780 of file CFG.h.
Referenced by getLoopTarget(), and setLoopTarget().
CFGTerminator clang::CFGBlock::Terminator |
The terminator for a basic block that indicates the type of control-flow that occurs between a block and its successors.
Definition at line 775 of file CFG.h.
Referenced by getLastCondition(), getTerminator(), getTerminatorCondition(), getTerminatorStmt(), and setTerminator().