clang 20.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. | |
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.
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 5375 of file CFG.cpp.
References clang::C, 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 |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 902 of file CFG.h.
References Elements.
Referenced by isBuiltinAssumeFalse(), and neverReturns().
|
inline |
Definition at line 904 of file CFG.h.
References Elements.
Referenced by Accumulate(), isInCoroutineStmt(), print_block(), and ref_begin().
|
inline |
LLVM_DUMP_METHOD void CFGBlock::dump | ( | ) | const |
void CFGBlock::dump | ( | const CFG * | cfg, |
const LangOptions & | LO, | ||
bool | ShowColors = false |
||
) | const |
dump - A simply pretty printer of a CFGBlock that outputs to stderr.
Definition at line 6134 of file CFG.cpp.
References print(), and ShowColors.
|
inline |
Definition at line 947 of file CFG.h.
References Elements.
Referenced by DiagnoseSwitchLabelsFallthrough(), clang::ento::CoreEngine::ExecuteWorkList(), clang::BlockEntrance::getFirstElement(), isBuiltinAssumeFalse(), neverReturns(), clang::ento::ExprEngine::processCallEnter(), and clang::ento::ExprEngine::VisitLogicalExpr().
|
inline |
Definition at line 905 of file CFG.h.
References Elements.
Referenced by Accumulate(), isInCoroutineStmt(), print_block(), and ref_end().
|
inline |
|
inline |
Definition at line 1060 of file CFG.h.
References pred_begin(), and pred_end().
Referenced by CheckFallThrough().
|
inline |
Definition at line 1064 of file CFG.h.
References succ_begin(), and succ_end().
|
static |
Definition at line 5386 of file CFG.cpp.
References getLabel(), getTerminatorStmt(), clang::CFGBlock::FilterOptions::IgnoreDefaultsWithCoveredEnums, and clang::CFGBlock::FilterOptions::IgnoreNullPredecessors.
|
inline |
Definition at line 901 of file CFG.h.
References Elements.
Referenced by clang::BlockEntrance::getFirstElement().
|
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().
size_t CFGBlock::getIndexInCFG | ( | ) | const |
Definition at line 6129 of file CFG.cpp.
References clang::CFG::begin(), and getParent().
|
inline |
Definition at line 1100 of file CFG.h.
References Label.
Referenced by Accumulate(), DiagnoseSwitchLabelsFallthrough(), FilterEdge(), 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 6235 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 1098 of file CFG.h.
References LoopTarget.
Referenced by clang::dataflow::isBackedgeNode().
|
inline |
Definition at line 1107 of file CFG.h.
Referenced by annotateStartParameter(), clang::internal::buildInterval(), clang::ento::PathDiagnosticLocation::create(), dump(), getIndexInCFG(), and isInevitablySinking().
|
inline |
Definition at line 1079 of file CFG.h.
References Terminator.
Referenced by clang::ento::PathDiagnosticLocation::create(), clang::ento::SwitchNodeBuilder::getSwitch(), print_block(), printTerminator(), ResolveCondition(), runOnBlock(), and clang::ento::ExprEngine::VisitLogicalExpr().
Definition at line 6263 of file CFG.cpp.
References E, getTerminatorStmt(), clang::Expr::IgnoreParens(), and Terminator.
Referenced by clang::ento::PathDiagnosticLocation::create(), getTerminatorCondition(), getTerminatorCondition(), isAssertlikeBlock(), and shouldTreatSuccessorsAsReachable().
Definition at line 1094 of file CFG.h.
References getTerminatorCondition().
|
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().
|
inline |
Definition at line 1082 of file CFG.h.
References clang::CFGTerminator::getStmt(), and Terminator.
|
inline |
Definition at line 1103 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 6197 of file CFG.cpp.
References clang::CFG::getExit(), getParent(), isImmediateSinkBlock(), succs(), and Visited.
Referenced by isAssertlikeBlock().
|
inline |
|
inline |
Definition at line 966 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(), getLastStmtLoc(), preds(), print_block(), and runOnBlock().
|
inline |
|
inline |
Definition at line 1006 of file CFG.h.
Referenced by checkRecursiveFunction(), checkThrowInNonThrowingFunc(), and print_block().
|
inline |
Definition at line 967 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 1005 of file CFG.h.
Referenced by getLastStmtLoc(), and print_block().
|
inline |
Definition at line 976 of file CFG.h.
References pred_begin(), and pred_end().
|
inline |
Definition at line 980 of file CFG.h.
References pred_begin(), and pred_end().
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 6145 of file CFG.cpp.
References print_block(), and ShowColors.
Referenced by dump(), and clang::CFG::dump().
|
inline |
Definition at line 1119 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 6153 of file CFG.cpp.
References getTerminator().
Referenced by printTerminatorJson().
void CFGBlock::printTerminatorJson | ( | raw_ostream & | Out, |
const LangOptions & | LO, | ||
bool | AddQuotes | ||
) | const |
printTerminatorJson - Pretty-prints the terminator in JSON format.
Definition at line 6160 of file CFG.cpp.
References clang::JsonFormat(), and printTerminator().
|
inline |
Definition at line 909 of file CFG.h.
References Elements.
Referenced by CheckFallThrough(), getLastCondition(), getLastStmtLoc(), rref_begin(), and clang::ento::ExprEngine::VisitLogicalExpr().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 939 of file CFG.h.
References ref_begin(), and ref_end().
|
inline |
Definition at line 940 of file CFG.h.
References ref_begin(), and ref_end().
|
inline |
Definition at line 910 of file CFG.h.
References Elements.
Referenced by CheckFallThrough(), getLastStmtLoc(), and rref_end().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 941 of file CFG.h.
References rref_begin(), and rref_end().
|
inline |
Definition at line 942 of file CFG.h.
References rref_begin(), and rref_end().
|
inline |
|
inline |
Definition at line 1072 of file CFG.h.
References LoopTarget.
|
inline |
Definition at line 1070 of file CFG.h.
References Terminator.
|
inline |
Definition at line 946 of file CFG.h.
References Elements.
Referenced by clang::ento::CallEvent::getCalleeStackFrame(), and getLastCondition().
|
inline |
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().
|
inline |
|
inline |
Definition at line 1003 of file CFG.h.
Referenced by print_block().
|
inline |
Definition at line 985 of file CFG.h.
Referenced by checkForRecursiveFunctionCall(), 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 989 of file CFG.h.
Referenced by clang::ento::SwitchNodeBuilder::begin(), and clang::ento::SwitchNodeBuilder::generateDefaultCaseNode().
|
inline |
|
inline |
Definition at line 990 of file CFG.h.
Referenced by clang::ento::SwitchNodeBuilder::end(), and clang::ento::SwitchNodeBuilder::generateDefaultCaseNode().
|
inline |
|
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().
|
inline |
Definition at line 994 of file CFG.h.
References succ_begin(), and succ_end().
Referenced by clang::dataflow::blockIndexInPredecessor(), CheckFallThrough(), isInevitablySinking(), clang::CFG::isLinear(), and throwEscapes().
|
inline |
Definition at line 998 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 811 of file CFG.h.
Referenced by getBlockID().
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().
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 799 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 808 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 803 of file CFG.h.
Referenced by getLastCondition(), getTerminator(), getTerminatorCondition(), getTerminatorStmt(), and setTerminator().