;
41 returnisa<EnumConstantDecl>(DR->
getDecl());
46 returnisa<IntegerLiteral>(Ex) || isa<StringLiteral>(Ex) ||
47isa<CXXBoolLiteralExpr>(Ex) || isa<ObjCBoolLiteralExpr>(Ex) ||
48isa<CharacterLiteral>(Ex) ||
56 if(
const DoStmt*DS = dyn_cast<DoStmt>(Term)) {
65 if(
const auto*DRE = dyn_cast<DeclRefExpr>(S))
66 if(
const auto*FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()))
67 returnFDecl->getIdentifier() &&
68FDecl->getBuiltinID() == Builtin::BI__builtin_unreachable;
80 if(
const auto*CE = dyn_cast<CallExpr>(CS->getStmt())) {
81 returnCE->getCallee()->IgnoreCasts() == S && CE->isBuiltinAssumeFalse(
C);
93 for(
const CFGElement&CE : llvm::reverse(*Current)) {
94 if(std::optional<CFGStmt> CS = CE.getAs<
CFGStmt>()) {
95 if(
const ReturnStmt*RS = dyn_cast<ReturnStmt>(CS->getStmt())) {
98 if(
const Expr*RE = RS->getRetValue()) {
99RE = RE->IgnoreParenCasts();
114 if(Current->getTerminator().isTemporaryDtorsBranch()) {
119assert(Current->succ_size() == 2);
120Current = *(Current->succ_begin() + 1);
121}
else if(!Current->getTerminatorStmt() && Current->succ_size() == 1) {
124Current = *Current->succ_begin();
125 if(Current->pred_size() > 1) {
136llvm_unreachable(
"Broke out of infinite loop.");
144 Loc=
SM.getImmediateMacroCallerLoc(
Loc);
152 boolIgnoreYES_NO =
false) {
166 if(MacroName ==
"YES"|| MacroName ==
"NO")
172 if(MacroName ==
"false"|| MacroName ==
"true")
192 boolIncludeIntegers =
true,
193 boolWrappedInParens =
false) {
197 if(
const auto*Ex = dyn_cast<Expr>(S))
198S = Ex->IgnoreImplicit();
200 if(
const auto*Ex = dyn_cast<Expr>(S))
201S = Ex->IgnoreCasts();
204 if(
const ParenExpr*PE = dyn_cast<ParenExpr>(S))
205 if(!PE->getBeginLoc().isMacroID())
207IncludeIntegers,
true);
209 if(
const Expr*Ex = dyn_cast<Expr>(S))
210S = Ex->IgnoreCasts();
212 boolIgnoreYES_NO =
false;
214 switch(S->getStmtClass()) {
215 caseStmt::CallExprClass: {
217dyn_cast_or_null<FunctionDecl>(cast<CallExpr>(S)->getCalleeDecl());
218 returnCallee ? Callee->isConstexpr() :
false;
220 caseStmt::DeclRefExprClass:
222 caseStmt::ObjCBoolLiteralExprClass:
223IgnoreYES_NO =
true;
225 caseStmt::CXXBoolLiteralExprClass:
226 caseStmt::IntegerLiteralClass: {
227 const Expr*
E= cast<Expr>(S);
228 if(IncludeIntegers) {
229 if(SilenceableCondVal && !SilenceableCondVal->getBegin().isValid())
231 returnWrappedInParens ||
236 caseStmt::MemberExprClass:
238 caseStmt::UnaryExprOrTypeTraitExprClass:
240 caseStmt::BinaryOperatorClass: {
251 caseStmt::UnaryOperatorClass: {
255 boolSilenceableCondValNotSet =
256SilenceableCondVal && SilenceableCondVal->getBegin().isInvalid();
257 boolIsSubExprConfigValue =
259IncludeIntegers, WrappedInParens);
262 if(SilenceableCondValNotSet &&
263SilenceableCondVal->getBegin().isValid() &&
264*SilenceableCondVal ==
267 returnIsSubExprConfigValue;
277 if(
const VarDecl*VD = dyn_cast<VarDecl>(
D)) {
285 if(!VD->hasLocalStorage())
290 returnVD->getType().isLocalConstQualified();
299 if(isa<SwitchStmt>(Term))
302 if(isa<BinaryOperator>(Term)) {
308 if(
const auto*IS = dyn_cast<IfStmt>(Term);
309IS !=
nullptr&& IS->isConstexpr())
318llvm::BitVector &Reachable,
320 boolIncludeSometimesUnreachableEdges) {
336 while(!WL.empty()) {
337 const CFGBlock*item = WL.pop_back_val();
345std::optional<bool> TreatAllSuccessorsAsReachable;
346 if(!IncludeSometimesUnreachableEdges)
347TreatAllSuccessorsAsReachable =
false;
353 const CFGBlock*UB = I->getPossiblyUnreachableBlock();
357 if(!TreatAllSuccessorsAsReachable) {
359TreatAllSuccessorsAsReachable =
363 if(*TreatAllSuccessorsAsReachable) {
372 if(!Reachable[blockID]) {
373Reachable.set(blockID);
385llvm::BitVector &Reachable) {
396llvm::BitVector &Reachable;
404DeferredLocsTy DeferredLocs;
409Reachable(reachable),
412 voidenqueue(
const CFGBlock*block);
413 unsignedscanBackwards(
const CFGBlock*Start,
420 voidreportDeadCode(
const CFGBlock*B,
426voidDeadCodeScan::enqueue(
const CFGBlock*block) {
428 if(Reachable[blockID] ||
Visited[blockID])
431WorkList.push_back(block);
435 boolisDeadRoot =
true;
439 if(
const CFGBlock*PredBlock = *I) {
440 unsignedblockID = PredBlock->getBlockID();
445 if(!Reachable[blockID]) {
448WorkList.push_back(PredBlock);
461 const Stmt*CoroStmt =
nullptr;
463 boolAfterDeadStmt =
false;
466 if(std::optional<CFGStmt> CS = I->getAs<
CFGStmt>()) {
467 const Stmt*S = CS->getStmt();
469AfterDeadStmt =
true;
472(llvm::isa<CoreturnStmt>(S) || llvm::isa<CoroutineSuspendExpr>(S))) {
480 const Stmt*DeadStmt;
481 boolCoroutineSubStmt =
false;
482Checker(
const Stmt*S) : DeadStmt(S) {
484ShouldVisitImplicitCode =
true;
489CoroutineSubStmt =
true;
493Checker checker(DeadStmt);
494checker.TraverseStmt(
const_cast<Stmt*
>(CoroStmt));
495 returnchecker.CoroutineSubStmt;
499 if(S->getBeginLoc().isInvalid())
502 returnBO->getOpcode() != BO_Comma;
511 if(std::optional<CFGStmt> CS = I->getAs<
CFGStmt>()) {
512 const Stmt*S = CS->getStmt();
518 if(
T.isStmtBranch()) {
519 const Stmt*S =
T.getStmt();
527static int SrcCmp(
conststd::pair<const CFGBlock *, const Stmt *> *p1,
528 conststd::pair<const CFGBlock *, const Stmt *> *p2) {
529 if(p1->second->getBeginLoc() < p2->second->getBeginLoc())
531 if(p2->second->getBeginLoc() < p1->second->getBeginLoc())
542 while(!WorkList.empty()) {
557 if(
const CFGBlock*predBlock = *I)
564 if(S->getBeginLoc().isMacroID()) {
569 if(isDeadCodeRoot(
Block)) {
570reportDeadCode(
Block, S, CB);
577DeferredLocs.push_back(std::make_pair(
Block, S));
583 if(!DeferredLocs.empty()) {
584llvm::array_pod_sort(DeferredLocs.begin(), DeferredLocs.end(),
SrcCmp);
585 for(
const auto&I : DeferredLocs) {
589reportDeadCode(
Block, I.second, CB);
602 if(
const Expr*Ex = dyn_cast<Expr>(S))
603S = Ex->IgnoreParenImpCasts();
605 switch(S->getStmtClass()) {
606 caseExpr::BinaryOperatorClass: {
610 caseExpr::UnaryOperatorClass: {
615 caseExpr::CompoundAssignOperatorClass: {
621 caseExpr::BinaryConditionalOperatorClass:
622 caseExpr::ConditionalOperatorClass: {
624cast<AbstractConditionalOperator>(S);
627 caseExpr::MemberExprClass: {
632 caseExpr::ArraySubscriptExprClass: {
638 caseExpr::CStyleCastExprClass: {
643 caseExpr::CXXFunctionalCastExprClass: {
648 caseStmt::CXXTryStmtClass: {
649 returncast<CXXTryStmt>(S)->getHandler(0)->getCatchLoc();
651 caseExpr::ObjCBridgedCastExprClass: {
658R1 = S->getSourceRange();
659 returnS->getBeginLoc();
662voidDeadCodeScan::reportDeadCode(
const CFGBlock*B,
668 if(isa<BreakStmt>(S)) {
678 const auto*AS = dyn_cast<AttributedStmt>(S);
679 boolHasFallThroughAttr =
680AS && hasSpecificAttr<FallThroughAttr>(AS->getAttrs());
692 if(
const ForStmt*FS = dyn_cast<ForStmt>(LoopTarget)) {
693 const Expr*
Inc= FS->getInc();
694 Loc=
Inc->getBeginLoc();
695R2 =
Inc->getSourceRange();
709 if(
const CFGBlock*PredBlock = PI->getPossiblyUnreachableBlock()) {
710 const Stmt*TermCond =
711PredBlock->getTerminatorCondition(
false);
726namespace clang{
namespacereachable_code {
728voidCallback::anchor() { }
731llvm::BitVector &Reachable) {
738 CFG*cfg = AC.getCFG();
745 unsignednumReachable =
752 if(!AC.getCFGBuildOptions().AddEHEdges) {
761 for(
const CFGBlock*block : *cfg) {
766DeadCodeScan DS(reachable, PP, AC.getASTContext());
767numReachable += DS.scanBackwards(block, CB);
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
Defines enum values for all the target-independent builtin functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::DenseSet< const void * > Visited
Defines the clang::Preprocessor interface.
static SourceLocation getTopMostMacro(SourceLocation Loc, SourceManager &SM)
static bool isEnumConstant(const Expr *Ex)
static bool isInCoroutineStmt(const Stmt *DeadStmt, const CFGBlock *Block)
static bool shouldTreatSuccessorsAsReachable(const CFGBlock *B, Preprocessor &PP)
Returns true if we should always explore all successors of a block.
static int SrcCmp(const std::pair< const CFGBlock *, const Stmt * > *p1, const std::pair< const CFGBlock *, const Stmt * > *p2)
static bool isTrivialDoWhile(const CFGBlock *B, const Stmt *S)
static bool isExpandedFromConfigurationMacro(const Stmt *S, Preprocessor &PP, bool IgnoreYES_NO=false)
Returns true if the statement is expanded from a configuration macro.
static bool isValidDeadStmt(const Stmt *S, const clang::CFGBlock *Block)
static unsigned scanFromBlock(const CFGBlock *Start, llvm::BitVector &Reachable, Preprocessor *PP, bool IncludeSometimesUnreachableEdges)
static bool isConfigurationValue(const ValueDecl *D, Preprocessor &PP)
static bool isBuiltinUnreachable(const Stmt *S)
static bool isBuiltinAssumeFalse(const CFGBlock *B, const Stmt *S, ASTContext &C)
static bool isDeadReturn(const CFGBlock *B, const Stmt *S)
static unsigned scanMaybeReachableFromBlock(const CFGBlock *Start, Preprocessor &PP, llvm::BitVector &Reachable)
static SourceLocation GetUnreachableLoc(const Stmt *S, SourceRange &R1, SourceRange &R2)
static bool isTrivialExpression(const Expr *Ex)
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
SourceLocation getQuestionLoc() const
AnalysisDeclContext contains the context data for the function, method or block under analysis.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
SourceLocation getRBracketLoc() const
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
SourceLocation getOperatorLoc() const
Represents a single basic block in a source-level CFG.
ElementList::const_iterator const_iterator
CFGTerminator getTerminator() const
succ_iterator succ_begin()
Stmt * getTerminatorStmt()
const Stmt * getLoopTarget() const
AdjacentBlocks::const_iterator const_pred_iterator
pred_iterator pred_begin()
unsigned getBlockID() const
Stmt * getTerminatorCondition(bool StripParens=true)
AdjacentBlocks::const_iterator const_succ_iterator
Represents a top-level expression in a basic block.
std::optional< T > getAs() const
Convert to the specified CFGElement type, returning std::nullopt if this CFGElement is not of the des...
Represents CFGBlock terminator statement.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
try_block_range try_blocks() const
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
SourceLocation getLParenLoc() const
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
SourceLocation getBeginLoc() const LLVM_READONLY
CompoundAssignOperator - For compound assignments (e.g.
A reference to a declared variable, function, enum, etc.
DoStmt - This represents a 'do/while' stmt.
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool VisitStmt(MaybeConst< Stmt > *S)
An instance of this object exists for each enum constant that is defined.
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Expr * IgnoreCasts() LLVM_READONLY
Skip past any casts which might surround this expression until reaching a fixed point.
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Represents a function declaration or definition.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
SourceLocation getLParenLoc() const
ParenExpr - This represents a parenthesized expression, e.g.
Stmt * getParent(Stmt *) const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
SourceManager & getSourceManager() const
StringRef getImmediateMacroName(SourceLocation Loc)
Retrieve the name of the immediate macro expansion.
const LangOptions & getLangOpts() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Expr * getSubExpr() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
virtual void HandleUnreachable(UnreachableKind UK, SourceLocation L, SourceRange ConditionVal, SourceRange R1, SourceRange R2, bool HasFallThroughAttr)=0
bool Inc(InterpState &S, CodePtr OpPC)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
void FindUnreachableCode(AnalysisDeclContext &AC, Preprocessor &PP, Callback &CB)
unsigned ScanReachableFromBlock(const CFGBlock *Start, llvm::BitVector &Reachable)
ScanReachableFromBlock - Mark all blocks reachable from Start.
UnreachableKind
Classifications of unreachable code.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4