1 //=- AnalysisBasedWarnings.h - Sema warnings based on libAnalysis -*- 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 // This file defines AnalysisBasedWarnings, a worker object used by Sema 11 // that issues warnings based on dataflow-analysis. 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_SEMA_ANALYSIS_WARNINGS_H 15 #define LLVM_CLANG_SEMA_ANALYSIS_WARNINGS_H 16 17 #include "llvm/ADT/DenseMap.h" 18 19 namespace clang { 20 21 class BlockExpr; 22 class Decl; 23 class FunctionDecl; 24 class ObjCMethodDecl; 25 class QualType; 26 class Sema; 27 namespace sema { 28 class FunctionScopeInfo; 29 } 30 31 namespace sema { 32 33 class AnalysisBasedWarnings { 34 public: 35 class Policy { 36 friend class AnalysisBasedWarnings; 37 // The warnings to run. 38 unsigned enableCheckFallThrough : 1; 39 unsigned enableCheckUnreachable : 1; 40 public: 41 Policy(); disableCheckFallThrough()42 void disableCheckFallThrough() { enableCheckFallThrough = 0; } 43 }; 44 45 private: 46 Sema &S; 47 Policy DefaultPolicy; 48 49 enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 }; 50 llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD; 51 52 /// \name Statistics 53 /// @{ 54 55 /// \brief Number of function CFGs built and analyzed. 56 unsigned NumFunctionsAnalyzed; 57 58 /// \brief Number of functions for which the CFG could not be successfully 59 /// built. 60 unsigned NumFunctionsWithBadCFGs; 61 62 /// \brief Total number of blocks across all CFGs. 63 unsigned NumCFGBlocks; 64 65 /// \brief Largest number of CFG blocks for a single function analyzed. 66 unsigned MaxCFGBlocksPerFunction; 67 68 /// \brief Total number of CFGs with variables analyzed for uninitialized 69 /// uses. 70 unsigned NumUninitAnalysisFunctions; 71 72 /// \brief Total number of variables analyzed for uninitialized uses. 73 unsigned NumUninitAnalysisVariables; 74 75 /// \brief Max number of variables analyzed for uninitialized uses in a single 76 /// function. 77 unsigned MaxUninitAnalysisVariablesPerFunction; 78 79 /// \brief Total number of block visits during uninitialized use analysis. 80 unsigned NumUninitAnalysisBlockVisits; 81 82 /// \brief Max number of block visits during uninitialized use analysis of 83 /// a single function. 84 unsigned MaxUninitAnalysisBlockVisitsPerFunction; 85 86 /// @} 87 88 public: 89 AnalysisBasedWarnings(Sema &s); 90 91 void IssueWarnings(Policy P, FunctionScopeInfo *fscope, 92 const Decl *D, const BlockExpr *blkExpr); 93 getDefaultPolicy()94 Policy getDefaultPolicy() { return DefaultPolicy; } 95 96 void PrintStats() const; 97 }; 98 99 }} // end namespace clang::sema 100 101 #endif 102