clang  19.0.0git
Namespaces | Functions
ReachableCode.cpp File Reference
#include "clang/Analysis/Analyses/ReachableCode.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtCXX.h"
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Analysis/CFG.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include <optional>

Go to the source code of this file.

Namespaces

 clang
 The JSON file list parser is used to communicate input to InstallAPI.
 
 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. More...
 
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. More...
 
static bool shouldTreatSuccessorsAsReachable (const CFGBlock *B, Preprocessor &PP)
 Returns true if we should always explore all successors of a block. More...
 
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. More...
 
void clang::reachable_code::FindUnreachableCode (AnalysisDeclContext &AC, Preprocessor &PP, Callback &CB)
 

Function Documentation

◆ getTopMostMacro()

static SourceLocation getTopMostMacro ( SourceLocation  Loc,
SourceManager SM 
)
static

Definition at line 139 of file ReachableCode.cpp.

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

◆ GetUnreachableLoc()

static SourceLocation GetUnreachableLoc ( const Stmt S,
SourceRange R1,
SourceRange R2 
)
static

Definition at line 595 of file ReachableCode.cpp.

◆ isBuiltinAssumeFalse()

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

Definition at line 72 of file ReachableCode.cpp.

◆ isBuiltinUnreachable()

static bool isBuiltinUnreachable ( const Stmt S)
static

Definition at line 64 of file ReachableCode.cpp.

◆ isConfigurationValue() [1/2]

static 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 189 of file ReachableCode.cpp.

◆ isConfigurationValue() [2/2]

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

Definition at line 274 of file ReachableCode.cpp.

Referenced by shouldTreatSuccessorsAsReachable().

◆ isDeadReturn()

static bool isDeadReturn ( const CFGBlock B,
const Stmt S 
)
static

Definition at line 87 of file ReachableCode.cpp.

◆ isEnumConstant()

static bool isEnumConstant ( const Expr Ex)
static

Definition at line 37 of file ReachableCode.cpp.

References clang::DeclRefExpr::getDecl().

Referenced by isTrivialExpression().

◆ isExpandedFromConfigurationMacro()

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

Returns true if the statement is expanded from a configuration macro.

Definition at line 150 of file ReachableCode.cpp.

◆ isInCoroutineStmt()

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

Definition at line 459 of file ReachableCode.cpp.

References clang::CFGBlock::begin(), Block, and clang::CFGBlock::end().

◆ isTrivialDoWhile()

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

Definition at line 52 of file ReachableCode.cpp.

◆ isTrivialExpression()

static bool isTrivialExpression ( const Expr Ex)
static

Definition at line 44 of file ReachableCode.cpp.

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

◆ isValidDeadStmt()

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

Definition at line 496 of file ReachableCode.cpp.

◆ scanFromBlock()

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

◆ scanMaybeReachableFromBlock()

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

Definition at line 383 of file ReachableCode.cpp.

References scanFromBlock().

◆ shouldTreatSuccessorsAsReachable()

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

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

Definition at line 296 of file ReachableCode.cpp.

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

Referenced by scanFromBlock().

◆ SrcCmp()

static 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.