clang 24.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"
19#include <memory>
20
21namespace clang {
22
24class Decl;
25class FunctionDecl;
26class QualType;
27class Sema;
28class VarDecl;
29namespace sema {
31 class SemaPPCallbacks;
32}
33
34namespace sema {
35
37public:
38 class Policy {
40 friend class SemaPPCallbacks;
41 // The warnings to run.
42 LLVM_PREFERRED_TYPE(bool)
43 unsigned enableCheckFallThrough : 1;
44 LLVM_PREFERRED_TYPE(bool)
45 unsigned enableCheckUnreachable : 1;
46 LLVM_PREFERRED_TYPE(bool)
47 unsigned enableThreadSafetyAnalysis : 1;
48 LLVM_PREFERRED_TYPE(bool)
49 unsigned enableConsumedAnalysis : 1;
50 public:
51 Policy();
52 void disableCheckFallThrough() { enableCheckFallThrough = 0; }
53 };
54
55private:
56 Sema &S;
57
58 class InterProceduralData;
59 std::unique_ptr<InterProceduralData> IPData;
60
61 enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
62 llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
63 std::multimap<VarDecl *, PossiblyUnreachableDiag>
64 VarDeclPossiblyUnreachableDiags;
65
66 Policy PolicyOverrides;
67 void clearOverrides();
68
69 /// Caches results for getPolicyInEffectAt().
70 /// Flushed whenever a diagnostic pragma changes severities.
71 llvm::DenseMap<const void *, Policy> PolicyCache[4];
72
73 /// \name Statistics
74 /// @{
75
76 /// Number of function CFGs built and analyzed.
77 unsigned NumFunctionsAnalyzed;
78
79 /// Number of functions for which the CFG could not be successfully
80 /// built.
81 unsigned NumFunctionsWithBadCFGs;
82
83 /// Total number of blocks across all CFGs.
84 unsigned NumCFGBlocks;
85
86 /// Largest number of CFG blocks for a single function analyzed.
87 unsigned MaxCFGBlocksPerFunction;
88
89 /// Total number of CFGs with variables analyzed for uninitialized
90 /// uses.
91 unsigned NumUninitAnalysisFunctions;
92
93 /// Total number of variables analyzed for uninitialized uses.
94 unsigned NumUninitAnalysisVariables;
95
96 /// Max number of variables analyzed for uninitialized uses in a single
97 /// function.
98 unsigned MaxUninitAnalysisVariablesPerFunction;
99
100 /// Total number of block visits during uninitialized use analysis.
101 unsigned NumUninitAnalysisBlockVisits;
102
103 /// Max number of block visits during uninitialized use analysis of
104 /// a single function.
105 unsigned MaxUninitAnalysisBlockVisitsPerFunction;
106
107 /// Statistics collected during lifetime safety analysis.
108 /// These are accumulated across all analyzed functions and printed
109 /// when -print-stats is enabled.
111
112 /// @}
113
114public:
117
118 void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
119 const Decl *D, QualType BlockType);
120
121 // Issue warnings that require whole-translation-unit analysis.
123
124 // Run analysis-based warnings on an implicitly-defined function body (e.g. a
125 // defaulted/implicit default constructor). Such functions never reach the
126 // normal IssueWarnings path.
128
130
132
133 // Gets the default policy which is in effect at the given source location.
135
136 // Get the policies we may want to override due to things like #pragma clang
137 // diagnostic handling. If a caller sets any of these policies to true, that
138 // will override the policy used to issue warnings.
139 Policy &getPolicyOverrides() { return PolicyOverrides; }
140
141 /// Drop cached getPolicyInEffectAt() results (diagnostic state changed).
142 void clearPolicyCache();
143
144 void PrintStats() const;
145};
146
147} // namespace sema
148} // namespace clang
149
150#endif
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Represents a function declaration or definition.
Definition Decl.h:2029
A (possibly-)qualified type.
Definition TypeBase.h:938
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
Encodes a location in the source.
The top declaration context.
Definition Decl.h:105
Represents a variable declaration or definition.
Definition Decl.h:932
void clearPolicyCache()
Drop cached getPolicyInEffectAt() results (diagnostic state changed).
void IssueWarnings(Policy P, FunctionScopeInfo *fscope, const Decl *D, QualType BlockType)
void registerVarDeclWarning(VarDecl *VD, PossiblyUnreachableDiag PUD)
Policy getPolicyInEffectAt(SourceLocation Loc)
Retains information about a function, method, or block that is currently being parsed.
Definition ScopeInfo.h:104
The JSON file list parser is used to communicate input to InstallAPI.
A structure to hold the statistics related to LifetimeAnalysis.