clang 22.0.0git
ReachableCode.cpp File Reference

Go to the source code of this file.

Namespaces

namespace  clang
 The JSON file list parser is used to communicate input to InstallAPI.
namespace  clang::reachable_code

Functions

static bool isEnumConstant (const Expr *Ex)
static bool isTrivialExpression (const Expr *Ex)
static bool isTrivialDoWhile (const CFGBlock *B, const Stmt *S)
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 SourceLocation getTopMostMacro (SourceLocation Loc, SourceManager &SM)
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 isConfigurationValue (const ValueDecl *D, Preprocessor &PP)
static bool isConfigurationValue (const Stmt *S, Preprocessor &PP, SourceRange *SilenceableCondVal=nullptr, bool IncludeIntegers=true, bool WrappedInParens=false)
 Returns true if the statement represents a configuration value.
static bool shouldTreatSuccessorsAsReachable (const CFGBlock *B, Preprocessor &PP)
 Returns true if we should always explore all successors of a block.
static unsigned scanFromBlock (const CFGBlock *Start, llvm::BitVector &Reachable, Preprocessor *PP, bool IncludeSometimesUnreachableEdges)
static unsigned scanMaybeReachableFromBlock (const CFGBlock *Start, Preprocessor &PP, llvm::BitVector &Reachable)
static bool isInCoroutineStmt (const Stmt *DeadStmt, const CFGBlock *Block)
static bool isValidDeadStmt (const Stmt *S, const clang::CFGBlock *Block)
static int SrcCmp (const std::pair< const CFGBlock *, const Stmt * > *p1, const std::pair< const CFGBlock *, const Stmt * > *p2)
static SourceLocation GetUnreachableLoc (const Stmt *S, SourceRange &R1, SourceRange &R2)
unsigned clang::reachable_code::ScanReachableFromBlock (const CFGBlock *Start, llvm::BitVector &Reachable)
 ScanReachableFromBlock - Mark all blocks reachable from Start.
void clang::reachable_code::FindUnreachableCode (AnalysisDeclContext &AC, Preprocessor &PP, Callback &CB)

Function Documentation

◆ getTopMostMacro()

SourceLocation getTopMostMacro ( SourceLocation Loc,
SourceManager & SM )
static

Definition at line 138 of file ReachableCode.cpp.

References clang::SourceLocation::isMacroID(), clang::Last, and SM.

Referenced by isExpandedFromConfigurationMacro().

◆ GetUnreachableLoc()

◆ isBuiltinAssumeFalse()

bool isBuiltinAssumeFalse ( const CFGBlock * B,
const Stmt * S,
ASTContext & C )
static

◆ isBuiltinUnreachable()

bool isBuiltinUnreachable ( const Stmt * S)
static

Definition at line 63 of file ReachableCode.cpp.

◆ isConfigurationValue() [1/2]

bool isConfigurationValue ( const Stmt * S,
Preprocessor & PP,
SourceRange * SilenceableCondVal = nullptr,
bool IncludeIntegers = true,
bool WrappedInParens = false )
static

Returns true if the statement represents a configuration value.

A configuration value is something usually determined at compile-time to conditionally always execute some branch. Such guards are for "sometimes unreachable" code. Such code is usually not interesting to report as unreachable, and may mask truly unreachable code within those blocks.

Definition at line 188 of file ReachableCode.cpp.

References clang::cast(), clang::BinaryOperator::getLHS(), clang::UnaryOperator::getOpcode(), clang::BinaryOperator::getRHS(), clang::Stmt::getSourceRange(), clang::Stmt::getStmtClass(), clang::UnaryOperator::getSubExpr(), clang::Expr::IgnoreCasts(), clang::BinaryOperator::isComparisonOp(), isConfigurationValue(), isExpandedFromConfigurationMacro(), and clang::BinaryOperator::isLogicalOp().

◆ isConfigurationValue() [2/2]

bool isConfigurationValue ( const ValueDecl * D,
Preprocessor & PP )
static

◆ isDeadReturn()

◆ isEnumConstant()

bool isEnumConstant ( const Expr * Ex)
static

◆ isExpandedFromConfigurationMacro()

bool isExpandedFromConfigurationMacro ( const Stmt * S,
Preprocessor & PP,
bool IgnoreYES_NO = false )
static

◆ isInCoroutineStmt()

bool isInCoroutineStmt ( const Stmt * DeadStmt,
const CFGBlock * Block )
static

Definition at line 458 of file ReachableCode.cpp.

References clang::Block.

Referenced by isValidDeadStmt().

◆ isTrivialDoWhile()

bool isTrivialDoWhile ( const CFGBlock * B,
const Stmt * S )
static

◆ isTrivialExpression()

bool isTrivialExpression ( const Expr * Ex)
static

Definition at line 43 of file ReachableCode.cpp.

References clang::Expr::IgnoreParenCasts(), clang::isa(), and isEnumConstant().

Referenced by isTrivialDoWhile().

◆ isValidDeadStmt()

bool isValidDeadStmt ( const Stmt * S,
const clang::CFGBlock * Block )
static

◆ scanFromBlock()

unsigned scanFromBlock ( const CFGBlock * Start,
llvm::BitVector & Reachable,
Preprocessor * PP,
bool IncludeSometimesUnreachableEdges )
static

◆ scanMaybeReachableFromBlock()

unsigned scanMaybeReachableFromBlock ( const CFGBlock * Start,
Preprocessor & PP,
llvm::BitVector & Reachable )
static

Definition at line 382 of file ReachableCode.cpp.

References scanFromBlock().

Referenced by clang::reachable_code::FindUnreachableCode().

◆ shouldTreatSuccessorsAsReachable()

bool shouldTreatSuccessorsAsReachable ( const CFGBlock * B,
Preprocessor & PP )
static

Returns true if we should always explore all successors of a block.

Definition at line 295 of file ReachableCode.cpp.

References clang::Cond, clang::CFGBlock::getTerminatorCondition(), clang::CFGBlock::getTerminatorStmt(), clang::isa(), and isConfigurationValue().

Referenced by scanFromBlock().

◆ SrcCmp()

int SrcCmp ( const std::pair< const CFGBlock *, const Stmt * > * p1,
const std::pair< const CFGBlock *, const Stmt * > * p2 )
static

Definition at line 525 of file ReachableCode.cpp.