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