• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     unsigned enableThreadSafetyAnalysis : 1;
41   public:
42     Policy();
disableCheckFallThrough()43     void disableCheckFallThrough() { enableCheckFallThrough = 0; }
44   };
45 
46 private:
47   Sema &S;
48   Policy DefaultPolicy;
49 
50   enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
51   llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
52 
53   /// \name Statistics
54   /// @{
55 
56   /// \brief Number of function CFGs built and analyzed.
57   unsigned NumFunctionsAnalyzed;
58 
59   /// \brief Number of functions for which the CFG could not be successfully
60   /// built.
61   unsigned NumFunctionsWithBadCFGs;
62 
63   /// \brief Total number of blocks across all CFGs.
64   unsigned NumCFGBlocks;
65 
66   /// \brief Largest number of CFG blocks for a single function analyzed.
67   unsigned MaxCFGBlocksPerFunction;
68 
69   /// \brief Total number of CFGs with variables analyzed for uninitialized
70   /// uses.
71   unsigned NumUninitAnalysisFunctions;
72 
73   /// \brief Total number of variables analyzed for uninitialized uses.
74   unsigned NumUninitAnalysisVariables;
75 
76   /// \brief Max number of variables analyzed for uninitialized uses in a single
77   /// function.
78   unsigned MaxUninitAnalysisVariablesPerFunction;
79 
80   /// \brief Total number of block visits during uninitialized use analysis.
81   unsigned NumUninitAnalysisBlockVisits;
82 
83   /// \brief Max number of block visits during uninitialized use analysis of
84   /// a single function.
85   unsigned MaxUninitAnalysisBlockVisitsPerFunction;
86 
87   /// @}
88 
89 public:
90   AnalysisBasedWarnings(Sema &s);
91 
92   void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
93                      const Decl *D, const BlockExpr *blkExpr);
94 
getDefaultPolicy()95   Policy getDefaultPolicy() { return DefaultPolicy; }
96 
97   void PrintStats() const;
98 };
99 
100 }} // end namespace clang::sema
101 
102 #endif
103