clang  14.0.0git
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 #include <memory>
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 
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  unsigned enableConsumedAnalysis : 1;
42  public:
43  Policy();
44  void disableCheckFallThrough() { enableCheckFallThrough = 0; }
45  };
46 
47 private:
48  Sema &S;
49  Policy DefaultPolicy;
50 
51  class InterProceduralData;
52  std::unique_ptr<InterProceduralData> IPData;
53 
54  enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
55  llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
56 
57  /// \name Statistics
58  /// @{
59 
60  /// Number of function CFGs built and analyzed.
61  unsigned NumFunctionsAnalyzed;
62 
63  /// Number of functions for which the CFG could not be successfully
64  /// built.
65  unsigned NumFunctionsWithBadCFGs;
66 
67  /// Total number of blocks across all CFGs.
68  unsigned NumCFGBlocks;
69 
70  /// Largest number of CFG blocks for a single function analyzed.
71  unsigned MaxCFGBlocksPerFunction;
72 
73  /// Total number of CFGs with variables analyzed for uninitialized
74  /// uses.
75  unsigned NumUninitAnalysisFunctions;
76 
77  /// Total number of variables analyzed for uninitialized uses.
78  unsigned NumUninitAnalysisVariables;
79 
80  /// Max number of variables analyzed for uninitialized uses in a single
81  /// function.
82  unsigned MaxUninitAnalysisVariablesPerFunction;
83 
84  /// Total number of block visits during uninitialized use analysis.
85  unsigned NumUninitAnalysisBlockVisits;
86 
87  /// Max number of block visits during uninitialized use analysis of
88  /// a single function.
89  unsigned MaxUninitAnalysisBlockVisitsPerFunction;
90 
91  /// @}
92 
93 public:
96 
97  void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
98  const Decl *D, QualType BlockType);
99 
100  Policy getDefaultPolicy() { return DefaultPolicy; }
101 
102  void PrintStats() const;
103 };
104 
105 } // namespace sema
106 } // namespace clang
107 
108 #endif
clang::sema::AnalysisBasedWarnings
Definition: AnalysisBasedWarnings.h:33
clang::sema::AnalysisBasedWarnings::PrintStats
void PrintStats() const
Definition: AnalysisBasedWarnings.cpp:2461
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::sema::AnalysisBasedWarnings::~AnalysisBasedWarnings
~AnalysisBasedWarnings()
clang::sema::FunctionScopeInfo
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:98
clang::sema::AnalysisBasedWarnings::Policy
Definition: AnalysisBasedWarnings.h:35
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:355
clang
Definition: CalledOnceCheck.h:17
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:315
clang::sema::AnalysisBasedWarnings::getDefaultPolicy
Policy getDefaultPolicy()
Definition: AnalysisBasedWarnings.h:100
clang::sema::AnalysisBasedWarnings::Policy::disableCheckFallThrough
void disableCheckFallThrough()
Definition: AnalysisBasedWarnings.h:44
clang::sema::AnalysisBasedWarnings::Policy::Policy
Policy()
Definition: AnalysisBasedWarnings.cpp:2153
clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings
AnalysisBasedWarnings(Sema &s)
Definition: AnalysisBasedWarnings.cpp:2182
clang::sema::AnalysisBasedWarnings::IssueWarnings
void IssueWarnings(Policy P, FunctionScopeInfo *fscope, const Decl *D, QualType BlockType)
Definition: AnalysisBasedWarnings.cpp:2212