clang  19.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 "clang/AST/Decl.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include <memory>
19 
20 namespace clang {
21 
22 class Decl;
23 class FunctionDecl;
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  LLVM_PREFERRED_TYPE(bool)
38  unsigned enableCheckFallThrough : 1;
39  LLVM_PREFERRED_TYPE(bool)
40  unsigned enableCheckUnreachable : 1;
41  LLVM_PREFERRED_TYPE(bool)
42  unsigned enableThreadSafetyAnalysis : 1;
43  LLVM_PREFERRED_TYPE(bool)
44  unsigned enableConsumedAnalysis : 1;
45  public:
46  Policy();
47  void disableCheckFallThrough() { enableCheckFallThrough = 0; }
48  };
49 
50 private:
51  Sema &S;
52  Policy DefaultPolicy;
53 
54  class InterProceduralData;
55  std::unique_ptr<InterProceduralData> IPData;
56 
57  enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
58  llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
59 
60  /// \name Statistics
61  /// @{
62 
63  /// Number of function CFGs built and analyzed.
64  unsigned NumFunctionsAnalyzed;
65 
66  /// Number of functions for which the CFG could not be successfully
67  /// built.
68  unsigned NumFunctionsWithBadCFGs;
69 
70  /// Total number of blocks across all CFGs.
71  unsigned NumCFGBlocks;
72 
73  /// Largest number of CFG blocks for a single function analyzed.
74  unsigned MaxCFGBlocksPerFunction;
75 
76  /// Total number of CFGs with variables analyzed for uninitialized
77  /// uses.
78  unsigned NumUninitAnalysisFunctions;
79 
80  /// Total number of variables analyzed for uninitialized uses.
81  unsigned NumUninitAnalysisVariables;
82 
83  /// Max number of variables analyzed for uninitialized uses in a single
84  /// function.
85  unsigned MaxUninitAnalysisVariablesPerFunction;
86 
87  /// Total number of block visits during uninitialized use analysis.
88  unsigned NumUninitAnalysisBlockVisits;
89 
90  /// Max number of block visits during uninitialized use analysis of
91  /// a single function.
92  unsigned MaxUninitAnalysisBlockVisitsPerFunction;
93 
94  /// @}
95 
96 public:
99 
100  void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
101  const Decl *D, QualType BlockType);
102 
103  // Issue warnings that require whole-translation-unit analysis.
105 
106  Policy getDefaultPolicy() { return DefaultPolicy; }
107 
108  void PrintStats() const;
109 };
110 
111 } // namespace sema
112 } // namespace clang
113 
114 #endif
StringRef P
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:146
__device__ __2f16 float __ockl_bool s
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
A (possibly-)qualified type.
Definition: Type.h:940
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:462
The top declaration context.
Definition: Decl.h:84
void IssueWarnings(Policy P, FunctionScopeInfo *fscope, const Decl *D, QualType BlockType)
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:104
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.