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"
17#include "llvm/ADT/DenseMap.h"
18#include <memory>
19
20namespace clang {
21
22class Decl;
23class FunctionDecl;
24class QualType;
25class Sema;
26namespace sema {
28 class SemaPPCallbacks;
29}
30
31namespace sema {
32
34public:
35 class Policy {
37 friend class SemaPPCallbacks;
38 // The warnings to run.
39 LLVM_PREFERRED_TYPE(bool)
40 unsigned enableCheckFallThrough : 1;
41 LLVM_PREFERRED_TYPE(bool)
42 unsigned enableCheckUnreachable : 1;
43 LLVM_PREFERRED_TYPE(bool)
44 unsigned enableThreadSafetyAnalysis : 1;
45 LLVM_PREFERRED_TYPE(bool)
46 unsigned enableConsumedAnalysis : 1;
47 public:
48 Policy();
49 void disableCheckFallThrough() { enableCheckFallThrough = 0; }
50 };
51
52private:
53 Sema &S;
54
55 class InterProceduralData;
56 std::unique_ptr<InterProceduralData> IPData;
57
58 enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
59 llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
60
61 Policy PolicyOverrides;
62 void clearOverrides();
63
64 /// \name Statistics
65 /// @{
66
67 /// Number of function CFGs built and analyzed.
68 unsigned NumFunctionsAnalyzed;
69
70 /// Number of functions for which the CFG could not be successfully
71 /// built.
72 unsigned NumFunctionsWithBadCFGs;
73
74 /// Total number of blocks across all CFGs.
75 unsigned NumCFGBlocks;
76
77 /// Largest number of CFG blocks for a single function analyzed.
78 unsigned MaxCFGBlocksPerFunction;
79
80 /// Total number of CFGs with variables analyzed for uninitialized
81 /// uses.
82 unsigned NumUninitAnalysisFunctions;
83
84 /// Total number of variables analyzed for uninitialized uses.
85 unsigned NumUninitAnalysisVariables;
86
87 /// Max number of variables analyzed for uninitialized uses in a single
88 /// function.
89 unsigned MaxUninitAnalysisVariablesPerFunction;
90
91 /// Total number of block visits during uninitialized use analysis.
92 unsigned NumUninitAnalysisBlockVisits;
93
94 /// Max number of block visits during uninitialized use analysis of
95 /// a single function.
96 unsigned MaxUninitAnalysisBlockVisitsPerFunction;
97
98 /// @}
99
100public:
103
105 const Decl *D, QualType BlockType);
106
107 // Issue warnings that require whole-translation-unit analysis.
109
110 // Gets the default policy which is in effect at the given source location.
112
113 // Get the policies we may want to override due to things like #pragma clang
114 // diagnostic handling. If a caller sets any of these policies to true, that
115 // will override the policy used to issue warnings.
116 Policy &getPolicyOverrides() { return PolicyOverrides; }
117
118 void PrintStats() const;
119};
120
121} // namespace sema
122} // namespace clang
123
124#endif
StringRef P
const Decl * D
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:145
SourceLocation Loc
Definition: SemaObjC.cpp:754
__device__ __2f16 float __ockl_bool s
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
A (possibly-)qualified type.
Definition: TypeBase.h:937
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
Encodes a location in the source.
The top declaration context.
Definition: Decl.h:104
void IssueWarnings(Policy P, FunctionScopeInfo *fscope, const Decl *D, QualType BlockType)
Policy getPolicyInEffectAt(SourceLocation Loc)
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:104
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Definition: ModuleMapFile.h:36
The JSON file list parser is used to communicate input to InstallAPI.