|
clang 24.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::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 |
Definition at line 951 of file CFG.h.
References BlockID, clang::C, Elements, clang::nullptr, and Terminator.
Referenced by addSuccessor(), clang::CFGBlock::AdjacentBlock::AdjacentBlock(), clang::CFGBlock::AdjacentBlock::AdjacentBlock(), clang::CFGBlock::FilteredCFGBlockIterator< const_pred_iterator, true >::FilteredCFGBlockIterator(), FilterEdge(), clang::CFGBlock::AdjacentBlock::getPossiblyUnreachableBlock(), clang::CFGBlock::AdjacentBlock::getReachableBlock(), isInevitablySinking(), clang::CFGBlock::AdjacentBlock::operator CFGBlock *(), clang::CFGBlock::AdjacentBlock::operator*(), clang::CFGBlock::FilteredCFGBlockIterator< const_pred_iterator, true >::operator*(), and clang::CFGBlock::AdjacentBlock::operator->().
| void CFGBlock::addSuccessor | ( | AdjacentBlock | Succ, |
| BumpVectorContext & | C ) |
Adds a (potentially unreachable) successor block to the current block.
Definition at line 5610 of file CFG.cpp.
References clang::C, CFGBlock(), 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 |
|
inline |
Definition at line 964 of file CFG.h.
References Elements.
Referenced by clang::CFG::back(), isBuiltinAssumeFalse(), and neverReturns().
|
inline |
Definition at line 966 of file CFG.h.
References Elements.
Referenced by clang::CFG::begin(), clang::CFG::begin(), print_block(), ref_begin(), and ref_begin().
|
inline |
| LLVM_DUMP_METHOD void CFGBlock::dump | ( | ) | const |
Definition at line 6410 of file CFG.cpp.
References dump(), and getParent().
Referenced by dump(), and clang::lifetimes::internal::DataflowAnalysis< Derived, Lattice, Dir >::dump().
| void CFGBlock::dump | ( | const CFG * | cfg, |
| const LangOptions & | LO, | ||
| bool | ShowColors = false ) const |
|
inline |
Definition at line 1009 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 967 of file CFG.h.
References Elements.
Referenced by clang::CFG::end(), clang::CFG::end(), print_block(), ref_end(), and ref_end().
|
inline |
|
inline |
Definition at line 1122 of file CFG.h.
References pred_begin(), and pred_end().
Referenced by CheckFallThrough().
|
inline |
Definition at line 1126 of file CFG.h.
References succ_begin(), and succ_end().
|
static |
Definition at line 5621 of file CFG.cpp.
References CFGBlock(), getLabel(), getTerminatorStmt(), clang::CFGBlock::FilterOptions::IgnoreDefaultsWithCoveredEnums, clang::CFGBlock::FilterOptions::IgnoreNullPredecessors, and clang::isa().
|
inline |
Definition at line 963 of file CFG.h.
References Elements.
Referenced by clang::CFG::front(), and clang::BlockEntrance::getFirstElement().
|
inline |
Definition at line 1178 of file CFG.h.
References BlockID.
Referenced by clang::lifetimes::internal::FactManager::addBlockFacts(), clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), clang::lifetimes::internal::FactManager::appendBlockFact(), CheckFallThrough(), checkForRecursiveFunctionCall(), clang::LiveVariables::computeLiveness(), clang::DataflowWorklistBase< Comp, QueueSize >::dequeue(), clang::ento::CoreEngine::ExecuteWorkList(), clang::findCFGBackEdges(), clang::reachable_code::FindUnreachableCode(), clang::lifetimes::internal::FactManager::getFacts(), clang::internal::getID(), llvm::GraphTraits< clang::CFGBlock * >::getNumber(), llvm::GraphTraits< const clang::CFGBlock * >::getNumber(), llvm::GraphTraits< Inverse< clang::CFGBlock * > >::getNumber(), llvm::GraphTraits< Inverse< const clang::CFGBlock * > >::getNumber(), clang::consumed::ConsumedBlockInfo::isBackEdge(), clang::dataflow::AdornedCFG::isBlockReachable(), clang::CFGReverseBlockReachabilityAnalysis::isReachable(), clang::threadSafety::SExprBuilder::lookupBlock(), clang::WTOCompare::operator()(), print_block(), printAsOperand(), clang::ProgramPoint::printJson(), clang::ento::ExprEngine::runCheckersForBlockEntrance(), runOnBlock(), clang::dataflow::runTypeErasedDataflowAnalysis(), clang::runUninitializedVariablesAnalysis(), scanFromBlock(), and throwEscapes().
| size_t CFGBlock::getIndexInCFG | ( | ) | const |
Definition at line 6400 of file CFG.cpp.
References clang::CFG::begin(), and getParent().
|
inline |
Definition at line 1163 of file CFG.h.
References Label.
Referenced by DiagnoseSwitchLabelsFallthrough(), FilterEdge(), print_block(), and clang::ProgramPoint::printJson().
|
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 6505 of file CFG.cpp.
References clang::cast(), clang::CFGElement::getAs(), clang::isa(), rbegin(), size(), clang::CFGTerminator::StmtBranch, succ_size(), and Terminator.
|
inline |
Definition at line 1161 of file CFG.h.
References LoopTarget.
Referenced by clang::isBackedgeCFGNode().
|
inline |
Definition at line 1180 of file CFG.h.
Referenced by annotateStartParameter(), clang::internal::buildInterval(), clang::ento::PathDiagnosticLocation::create(), dump(), getIndexInCFG(), and isInevitablySinking().
|
inline |
Definition at line 1146 of file CFG.h.
References Terminator.
Referenced by clang::ento::PathDiagnosticLocation::create(), isDeadReturn(), print_block(), printTerminator(), ResolveCondition(), runOnBlock(), and clang::ento::ExprEngine::VisitLogicalExpr().
Definition at line 6533 of file CFG.cpp.
References clang::cast(), getTerminatorStmt(), clang::Expr::IgnoreParens(), and Terminator.
Referenced by clang::ento::PathDiagnosticLocation::create(), getTerminatorCondition(), isAssertlikeBlock(), and shouldTreatSuccessorsAsReachable().
|
inline |
Definition at line 1148 of file CFG.h.
References Terminator.
Referenced by CheckFallThrough(), DiagnoseSwitchLabelsFallthrough(), FilterEdge(), clang::BlockExit::getTerminator(), getTerminatorCondition(), isDeadReturn(), isTrivialDoWhile(), peelOffOuterExpr(), clang::ProgramPoint::printJson(), clang::ento::ExprEngine::processCFGBlockEntrance(), shouldTreatSuccessorsAsReachable(), clang::ento::SuppressInlineDefensiveChecksVisitor::VisitNode(), and clang::ento::ConditionBRVisitor::VisitNodeImpl().
|
inline |
Definition at line 1149 of file CFG.h.
References Terminator.
|
inline |
Returns true if the block has a noreturn element, whether it is a real 'noreturn' or an 'analyzer_noreturn'.
Definition at line 1168 of file CFG.h.
Referenced by CheckFallThrough(), isImmediateSinkBlock(), neverReturns(), and print_block().
|
inline |
Returns true if the block ends in an 'analyzer_noreturn' call (as opposed to a real 'noreturn' one).
Most analyses treat the two indistinguishably (see hasNoReturnElement). This is for clients that need to tell them apart (e.g., -Wunreachable-code).
Definition at line 1174 of file CFG.h.
Referenced by print_block(), and scanFromBlock().
| bool CFGBlock::isInevitablySinking | ( | ) | const |
Returns true if the block would eventually end with a sink (a noreturn node).
Definition at line 6468 of file CFG.cpp.
References CFGBlock(), clang::CFG::getExit(), getParent(), isImmediateSinkBlock(), and succs().
Referenced by isAssertlikeBlock().
|
inline |
|
inline |
Definition at line 1028 of file CFG.h.
Referenced by clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), filtered_pred_start_end(), preds(), preds(), print_block(), and runOnBlock().
|
inline |
|
inline |
Definition at line 1068 of file CFG.h.
Referenced by checkRecursiveFunction(), checkThrowInNonThrowingFunc(), and print_block().
|
inline |
Definition at line 1029 of file CFG.h.
Referenced by clang::consumed::ConsumedBlockInfo::allBackEdgesVisited(), filtered_pred_start_end(), preds(), preds(), print_block(), and runOnBlock().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 1067 of file CFG.h.
Referenced by isDeadReturn(), and print_block().
|
inline |
Definition at line 1038 of file CFG.h.
References pred_begin(), and pred_end().
Referenced by llvm::GraphTraits< Inverse< clang::CFGBlock * > >::child_begin(), llvm::GraphTraits< Inverse< const clang::CFGBlock * > >::child_begin(), llvm::GraphTraits< Inverse< clang::CFGBlock * > >::child_end(), llvm::GraphTraits< Inverse< const clang::CFGBlock * > >::child_end(), and clang::lifetimes::internal::findPredBlockForExpr().
|
inline |
Definition at line 1042 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 6416 of file CFG.cpp.
References print_block().
Referenced by clang::CFG::dump(), and dump().
|
inline |
Definition at line 1192 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 6424 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 6431 of file CFG.cpp.
References clang::JsonFormat(), and printTerminator().
Referenced by clang::ProgramPoint::printJson().
|
inline |
Definition at line 971 of file CFG.h.
References Elements.
Referenced by CheckFallThrough(), getLastCondition(), rref_begin(), rref_begin(), and clang::ento::ExprEngine::VisitLogicalExpr().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 1001 of file CFG.h.
References ref_begin(), and ref_end().
|
inline |
Definition at line 1002 of file CFG.h.
References ref_begin(), and ref_end().
|
inline |
Definition at line 972 of file CFG.h.
References Elements.
Referenced by CheckFallThrough(), rref_end(), and rref_end().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 1003 of file CFG.h.
References rref_begin(), and rref_end().
|
inline |
Definition at line 1004 of file CFG.h.
References rref_begin(), and rref_end().
|
inline |
|
inline |
Definition at line 1134 of file CFG.h.
References LoopTarget.
|
inline |
Definition at line 1132 of file CFG.h.
References Terminator.
|
inline |
Definition at line 1008 of file CFG.h.
References Elements.
Referenced by clang::ento::CallEvent::getCalleeStackFrame(), and getLastCondition().
|
inline |
Definition at line 1046 of file CFG.h.
Referenced by clang::dataflow::blockIndexInPredecessor(), DiagnoseSwitchLabelsFallthrough(), clang::ento::CoreEngine::ExecuteWorkList(), filtered_succ_start_end(), clang::findCFGBackEdges(), isAssertlikeBlock(), isDeadReturn(), isJumpToFalseBranch(), neverReturns(), peelOffOuterExpr(), print_block(), clang::ento::ExprEngine::processCallEnter(), scanFromBlock(), succs(), succs(), clang::ento::ExprEngine::VisitLogicalExpr(), and clang::ento::ConditionBRVisitor::VisitTerminator().
|
inline |
|
inline |
Definition at line 1065 of file CFG.h.
Referenced by print_block().
|
inline |
Definition at line 1047 of file CFG.h.
Referenced by filtered_succ_start_end(), print_block(), scanFromBlock(), succs(), and succs().
|
inline |
|
inline |
Definition at line 1051 of file CFG.h.
Referenced by clang::ento::ExprEngine::processSwitch().
|
inline |
|
inline |
Definition at line 1052 of file CFG.h.
Referenced by clang::ento::ExprEngine::processSwitch().
|
inline |
|
inline |
Definition at line 1064 of file CFG.h.
Referenced by DiagnoseSwitchLabelsFallthrough(), clang::ento::CoreEngine::ExecuteWorkList(), getLastCondition(), isAssertlikeBlock(), isDeadReturn(), isJumpToFalseBranch(), neverReturns(), print_block(), clang::ento::ExprEngine::processCallEnter(), clang::ento::ExprEngine::processSwitch(), clang::ento::ExprEngine::VisitLogicalExpr(), and clang::ento::ConditionBRVisitor::VisitTerminator().
|
inline |
Definition at line 1056 of file CFG.h.
References succ_begin(), and succ_end().
Referenced by clang::dataflow::blockIndexInPredecessor(), CheckFallThrough(), llvm::GraphTraits< clang::CFGBlock * >::child_begin(), llvm::GraphTraits< const clang::CFGBlock * >::child_begin(), llvm::GraphTraits< clang::CFGBlock * >::child_end(), llvm::GraphTraits< const clang::CFGBlock * >::child_end(), clang::LiveVariables::computeLiveness(), isInevitablySinking(), clang::CFG::isLinear(), clang::ento::ExprEngine::processIndirectGoto(), clang::lifetimes::internal::DataflowAnalysis< Derived, Lattice, Dir >::run(), and throwEscapes().
|
inline |
Definition at line 1060 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 864 of file CFG.h.
Referenced by CFGBlock(), and getBlockID().
| ElementList clang::CFGBlock::Elements |
The set of statements in the basic block.
Definition at line 847 of file CFG.h.
Referenced by appendAutomaticObjDtor(), appendBaseDtor(), appendCleanupFunction(), appendConstructor(), appendCXXRecordTypedCall(), appendDeleteDtor(), appendFullExprCleanup(), appendInitializer(), appendLifetimeEnds(), appendLoopExit(), appendMemberDtor(), appendNewAllocator(), appendScopeBegin(), appendScopeEnd(), appendStmt(), appendTemporaryDtor(), back(), begin(), begin(), CFGBlock(), empty(), end(), end(), front(), operator[](), rbegin(), rbegin(), rend(), rend(), and size().
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 852 of file CFG.h.
Referenced by getLabel(), getLabel(), print_block(), and setLabel().
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 861 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 856 of file CFG.h.
Referenced by CFGBlock(), getLastCondition(), getTerminator(), getTerminatorCondition(), getTerminatorStmt(), getTerminatorStmt(), and setTerminator().