1 //===- ReachableCode.h -----------------------------------------*- C++ --*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // A flow-sensitive, path-insensitive analysis of unreachable code. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_REACHABLECODE_H 15 #define LLVM_CLANG_ANALYSIS_ANALYSES_REACHABLECODE_H 16 17 #include "clang/Basic/SourceLocation.h" 18 19 //===----------------------------------------------------------------------===// 20 // Forward declarations. 21 //===----------------------------------------------------------------------===// 22 23 namespace llvm { 24 class BitVector; 25 } 26 27 namespace clang { 28 class AnalysisDeclContext; 29 class CFGBlock; 30 class Preprocessor; 31 } 32 33 //===----------------------------------------------------------------------===// 34 // API. 35 //===----------------------------------------------------------------------===// 36 37 namespace clang { 38 namespace reachable_code { 39 40 /// Classifications of unreachable code. 41 enum UnreachableKind { 42 UK_Return, 43 UK_Break, 44 UK_Loop_Increment, 45 UK_Other 46 }; 47 48 class Callback { 49 virtual void anchor(); 50 public: ~Callback()51 virtual ~Callback() {} 52 virtual void HandleUnreachable(UnreachableKind UK, 53 SourceLocation L, 54 SourceRange ConditionVal, 55 SourceRange R1, 56 SourceRange R2) = 0; 57 }; 58 59 /// ScanReachableFromBlock - Mark all blocks reachable from Start. 60 /// Returns the total number of blocks that were marked reachable. 61 unsigned ScanReachableFromBlock(const CFGBlock *Start, 62 llvm::BitVector &Reachable); 63 64 void FindUnreachableCode(AnalysisDeclContext &AC, Preprocessor &PP, 65 Callback &CB); 66 67 }} // end namespace clang::reachable_code 68 69 #endif 70