clang 17.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 unsigned enableCheckFallThrough : 1;
38 unsigned enableCheckUnreachable : 1;
39 unsigned enableThreadSafetyAnalysis : 1;
40 unsigned enableConsumedAnalysis : 1;
41 public:
42 Policy();
43 void disableCheckFallThrough() { enableCheckFallThrough = 0; }
44 };
45
46private:
47 Sema &S;
48 Policy DefaultPolicy;
49
50 class InterProceduralData;
51 std::unique_ptr<InterProceduralData> IPData;
52
53 enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
54 llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
55
56 /// \name Statistics
57 /// @{
58
59 /// Number of function CFGs built and analyzed.
60 unsigned NumFunctionsAnalyzed;
61
62 /// Number of functions for which the CFG could not be successfully
63 /// built.
64 unsigned NumFunctionsWithBadCFGs;
65
66 /// Total number of blocks across all CFGs.
67 unsigned NumCFGBlocks;
68
69 /// Largest number of CFG blocks for a single function analyzed.
70 unsigned MaxCFGBlocksPerFunction;
71
72 /// Total number of CFGs with variables analyzed for uninitialized
73 /// uses.
74 unsigned NumUninitAnalysisFunctions;
75
76 /// Total number of variables analyzed for uninitialized uses.
77 unsigned NumUninitAnalysisVariables;
78
79 /// Max number of variables analyzed for uninitialized uses in a single
80 /// function.
81 unsigned MaxUninitAnalysisVariablesPerFunction;
82
83 /// Total number of block visits during uninitialized use analysis.
84 unsigned NumUninitAnalysisBlockVisits;
85
86 /// Max number of block visits during uninitialized use analysis of
87 /// a single function.
88 unsigned MaxUninitAnalysisBlockVisitsPerFunction;
89
90 /// @}
91
92public:
95
97 const Decl *D, QualType BlockType);
98
99 // Issue warnings that require whole-translation-unit analysis.
101
102 Policy getDefaultPolicy() { return DefaultPolicy; }
103
104 void PrintStats() const;
105};
106
107} // namespace sema
108} // namespace clang
109
110#endif
StringRef P
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:168
__device__ __2f16 float bool s
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
A (possibly-)qualified type.
Definition: Type.h:736
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
The top declaration context.
Definition: Decl.h:82
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:102
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...