clang 22.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 /// \name Statistics
70 /// @{
71
72 /// Number of function CFGs built and analyzed.
73 unsigned NumFunctionsAnalyzed;
74
75 /// Number of functions for which the CFG could not be successfully
76 /// built.
77 unsigned NumFunctionsWithBadCFGs;
78
79 /// Total number of blocks across all CFGs.
80 unsigned NumCFGBlocks;
81
82 /// Largest number of CFG blocks for a single function analyzed.
83 unsigned MaxCFGBlocksPerFunction;
84
85 /// Total number of CFGs with variables analyzed for uninitialized
86 /// uses.
87 unsigned NumUninitAnalysisFunctions;
88
89 /// Total number of variables analyzed for uninitialized uses.
90 unsigned NumUninitAnalysisVariables;
91
92 /// Max number of variables analyzed for uninitialized uses in a single
93 /// function.
94 unsigned MaxUninitAnalysisVariablesPerFunction;
95
96 /// Total number of block visits during uninitialized use analysis.
97 unsigned NumUninitAnalysisBlockVisits;
98
99 /// Max number of block visits during uninitialized use analysis of
100 /// a single function.
101 unsigned MaxUninitAnalysisBlockVisitsPerFunction;
102
103 /// Statistics collected during lifetime safety analysis.
104 /// These are accumulated across all analyzed functions and printed
105 /// when -print-stats is enabled.
107
108 /// @}
109
110public:
113
114 void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
115 const Decl *D, QualType BlockType);
116
117 // Issue warnings that require whole-translation-unit analysis.
119
121
123
124 // Gets the default policy which is in effect at the given source location.
126
127 // Get the policies we may want to override due to things like #pragma clang
128 // diagnostic handling. If a caller sets any of these policies to true, that
129 // will override the policy used to issue warnings.
130 Policy &getPolicyOverrides() { return PolicyOverrides; }
131
132 void PrintStats() const;
133};
134
135} // namespace sema
136} // namespace clang
137
138#endif
__device__ __2f16 float __ockl_bool s
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:2000
A (possibly-)qualified type.
Definition TypeBase.h:937
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:855
Encodes a location in the source.
The top declaration context.
Definition Decl.h:105
Represents a variable declaration or definition.
Definition Decl.h:926
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.