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
20namespace clang {
21
22class Decl;
23class FunctionDecl;
24class QualType;
25class Sema;
26namespace sema {
28}
29
30namespace sema {
31
33public:
34 class Policy {
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
50private:
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
96public:
99
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:85
A (possibly-)qualified type.
Definition: Type.h:738
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:457
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.