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"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/MapVector.h"
20#include <memory>
21
22namespace clang {
23
25class Decl;
26class FunctionDecl;
27class QualType;
28class Sema;
29class VarDecl;
30namespace sema {
32 class SemaPPCallbacks;
33}
34
35namespace sema {
36
38public:
39 class Policy {
41 friend class SemaPPCallbacks;
42 // The warnings to run.
43 LLVM_PREFERRED_TYPE(bool)
44 unsigned enableCheckFallThrough : 1;
45 LLVM_PREFERRED_TYPE(bool)
46 unsigned enableCheckUnreachable : 1;
47 LLVM_PREFERRED_TYPE(bool)
48 unsigned enableThreadSafetyAnalysis : 1;
49 LLVM_PREFERRED_TYPE(bool)
50 unsigned enableConsumedAnalysis : 1;
51 public:
52 Policy();
53 void disableCheckFallThrough() { enableCheckFallThrough = 0; }
54 };
55
56private:
57 Sema &S;
58
59 class InterProceduralData;
60 std::unique_ptr<InterProceduralData> IPData;
61
62 enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
63 llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
64 std::multimap<VarDecl *, PossiblyUnreachableDiag>
65 VarDeclPossiblyUnreachableDiags;
66
67 Policy PolicyOverrides;
68 void clearOverrides();
69
70 /// \name Statistics
71 /// @{
72
73 /// Number of function CFGs built and analyzed.
74 unsigned NumFunctionsAnalyzed;
75
76 /// Number of functions for which the CFG could not be successfully
77 /// built.
78 unsigned NumFunctionsWithBadCFGs;
79
80 /// Total number of blocks across all CFGs.
81 unsigned NumCFGBlocks;
82
83 /// Largest number of CFG blocks for a single function analyzed.
84 unsigned MaxCFGBlocksPerFunction;
85
86 /// Total number of CFGs with variables analyzed for uninitialized
87 /// uses.
88 unsigned NumUninitAnalysisFunctions;
89
90 /// Total number of variables analyzed for uninitialized uses.
91 unsigned NumUninitAnalysisVariables;
92
93 /// Max number of variables analyzed for uninitialized uses in a single
94 /// function.
95 unsigned MaxUninitAnalysisVariablesPerFunction;
96
97 /// Total number of block visits during uninitialized use analysis.
98 unsigned NumUninitAnalysisBlockVisits;
99
100 /// Max number of block visits during uninitialized use analysis of
101 /// a single function.
102 unsigned MaxUninitAnalysisBlockVisitsPerFunction;
103
104 /// @}
105
106public:
109
110 void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
111 const Decl *D, QualType BlockType);
112
113 // Issue warnings that require whole-translation-unit analysis.
115
117
119
120 // Gets the default policy which is in effect at the given source location.
122
123 // Get the policies we may want to override due to things like #pragma clang
124 // diagnostic handling. If a caller sets any of these policies to true, that
125 // will override the policy used to issue warnings.
126 Policy &getPolicyOverrides() { return PolicyOverrides; }
127
128 void PrintStats() const;
129};
130
131} // namespace sema
132} // namespace clang
133
134#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:854
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.