clang  9.0.0svn
AnalysisBasedWarnings.h
Go to the documentation of this file.
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 
18 namespace clang {
19 
20 class BlockExpr;
21 class Decl;
22 class FunctionDecl;
23 class ObjCMethodDecl;
24 class QualType;
25 class Sema;
26 namespace sema {
27  class FunctionScopeInfo;
28 }
29 
30 namespace sema {
31 
33 public:
34  class Policy {
35  friend class AnalysisBasedWarnings;
36  // The warnings to run.
37  unsigned enableCheckFallThrough : 1;
38  unsigned enableCheckUnreachable : 1;
39  unsigned enableThreadSafetyAnalysis : 1;
40  unsigned enableConsumedAnalysis : 1;
41  public:
42  Policy();
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  /// Number of function CFGs built and analyzed.
57  unsigned NumFunctionsAnalyzed;
58 
59  /// Number of functions for which the CFG could not be successfully
60  /// built.
61  unsigned NumFunctionsWithBadCFGs;
62 
63  /// Total number of blocks across all CFGs.
64  unsigned NumCFGBlocks;
65 
66  /// Largest number of CFG blocks for a single function analyzed.
67  unsigned MaxCFGBlocksPerFunction;
68 
69  /// Total number of CFGs with variables analyzed for uninitialized
70  /// uses.
71  unsigned NumUninitAnalysisFunctions;
72 
73  /// Total number of variables analyzed for uninitialized uses.
74  unsigned NumUninitAnalysisVariables;
75 
76  /// Max number of variables analyzed for uninitialized uses in a single
77  /// function.
78  unsigned MaxUninitAnalysisVariablesPerFunction;
79 
80  /// Total number of block visits during uninitialized use analysis.
81  unsigned NumUninitAnalysisBlockVisits;
82 
83  /// Max number of block visits during uninitialized use analysis of
84  /// a single function.
85  unsigned MaxUninitAnalysisBlockVisitsPerFunction;
86 
87  /// @}
88 
89 public:
91 
92  void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
93  const Decl *D, const BlockExpr *blkExpr);
94 
95  Policy getDefaultPolicy() { return DefaultPolicy; }
96 
97  void PrintStats() const;
98 };
99 
100 }} // end namespace clang::sema
101 
102 #endif
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
StringRef P
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:96
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:328
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5461
Dataflow Directional Tag Classes.