clang  15.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 Decl;
22 class FunctionDecl;
23 class QualType;
24 class Sema;
25 namespace sema {
26  class FunctionScopeInfo;
27 }
28 
29 namespace sema {
30 
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:
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
clang::sema::AnalysisBasedWarnings
Definition: AnalysisBasedWarnings.h:31
clang::sema::AnalysisBasedWarnings::PrintStats
void PrintStats() const
Definition: AnalysisBasedWarnings.cpp:2455
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:731
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:97
clang::sema::AnalysisBasedWarnings::Policy
Definition: AnalysisBasedWarnings.h:33
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:354
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:98
clang::sema::AnalysisBasedWarnings::Policy::disableCheckFallThrough
void disableCheckFallThrough()
Definition: AnalysisBasedWarnings.h:42
clang::sema::AnalysisBasedWarnings::Policy::Policy
Policy()
Definition: AnalysisBasedWarnings.cpp:2147
clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings
AnalysisBasedWarnings(Sema &s)
Definition: AnalysisBasedWarnings.cpp:2176
clang::sema::AnalysisBasedWarnings::IssueWarnings
void IssueWarnings(Policy P, FunctionScopeInfo *fscope, const Decl *D, QualType BlockType)
Definition: AnalysisBasedWarnings.cpp:2206