clang: include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
14#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
15
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/STLFunctionalExtras.h"
25
27namespace dataflow {
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
51public:
52 using Base::Base;
53
54
55
56
57
58
59
60
61
65
66
67
68
69
70
71
72
73
74
75
76
77
78
82
83
84
85
86
87
88
89
90
91
92
96
98 ConstMethodReturnValues.erase(&RecordLoc);
99 }
100
103 ConstMethodReturnStorageLocations.erase(&RecordLoc);
104 }
105
107 return Base::operator==(Other);
108 }
109
111
112private:
113
114
115 using ConstMethodReturnValuesType =
117 llvm::SmallDenseMap<const FunctionDecl *, Value *>>;
118 ConstMethodReturnValuesType ConstMethodReturnValues;
119
120
121
122 using ConstMethodReturnStorageLocationsType = llvm::SmallDenseMap<
124 llvm::SmallDenseMap<const FunctionDecl *, StorageLocation *>>;
125 ConstMethodReturnStorageLocationsType ConstMethodReturnStorageLocations;
126};
127
128namespace internal {
129
130template
131llvm::SmallDenseMap<const RecordStorageLocation *,
132 llvm::SmallDenseMap<const FunctionDecl *, T *>>
135 llvm::SmallDenseMap<const FunctionDecl *, T *>>
136 &Map1,
138 llvm::SmallDenseMap<const FunctionDecl *, T *>>
139 &Map2,
142 llvm::SmallDenseMap<const FunctionDecl *, T *>>
144 for (auto &[Loc, DeclToT] : Map1) {
145 auto It = Map2.find(Loc);
146 if (It == Map2.end()) {
148 continue;
149 }
150 const auto &OtherDeclToT = It->second;
151 auto &JoinedDeclToT = Result[Loc];
152 for (auto [Func, Var] : DeclToT) {
153 T *OtherVar = OtherDeclToT.lookup(Func);
154 if (OtherVar == nullptr || OtherVar != Var) {
156 continue;
157 }
158 JoinedDeclToT.insert({Func, Var});
159 }
160 }
162}
163
164}
165
166template
169
171
172
173
174
175
176 ConstMethodReturnValues =
177 clang::dataflow::internal::joinConstMethodMapdataflow::Value(
178 ConstMethodReturnValues, Other.ConstMethodReturnValues, Effect);
179
180 ConstMethodReturnStorageLocations =
181 clang::dataflow::internal::joinConstMethodMapdataflow::StorageLocation(
182 ConstMethodReturnStorageLocations,
183 Other.ConstMethodReturnStorageLocations, Effect);
184
185 return Effect;
186}
187
188template
193 assert(.isNull());
196
197 auto &ObjMap = ConstMethodReturnValues[&RecordLoc];
199 if (DirectCallee == nullptr)
200 return nullptr;
201 auto it = ObjMap.find(DirectCallee);
202 if (it != ObjMap.end())
203 return it->second;
204
206 if (Val != nullptr)
207 ObjMap.insert({DirectCallee, Val});
208 return Val;
209}
210
211template
218 auto &ObjMap = ConstMethodReturnStorageLocations[&RecordLoc];
220 if (DirectCallee == nullptr)
221 return nullptr;
222 auto it = ObjMap.find(DirectCallee);
223 if (it != ObjMap.end())
224 return it->second;
225
228 Initialize(Loc);
229
230 ObjMap.insert({DirectCallee, &Loc});
231 return &Loc;
232}
233
234template
239 assert(Callee != nullptr);
241 assert(.isNull());
243 auto &ObjMap = ConstMethodReturnStorageLocations[&RecordLoc];
244 auto it = ObjMap.find(Callee);
245 if (it != ObjMap.end())
246 return *it->second;
247
249 Initialize(Loc);
250
251 ObjMap.insert({Callee, &Loc});
252 return Loc;
253}
254
255}
256}
257
258#endif
llvm::MachO::RecordLoc RecordLoc
C Language Family Type Representation.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Represents a function declaration or definition.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
The base class of the type hierarchy.
bool isReferenceType() const
bool isRecordType() const
A mixin for a lattice that additionally maintains a cache of stable method call return values to mode...
LatticeJoinEffect join(const CachedConstAccessorsLattice &Other)
void clearConstMethodReturnStorageLocations(const RecordStorageLocation &RecordLoc)
bool operator==(const CachedConstAccessorsLattice &Other) const
StorageLocation * getOrCreateConstMethodReturnStorageLocation(const RecordStorageLocation &RecordLoc, const CallExpr *CE, Environment &Env, llvm::function_ref< void(StorageLocation &)> Initialize)
Creates or returns a previously created StorageLocation associated with a const method call obj....
void clearConstMethodReturnValues(const RecordStorageLocation &RecordLoc)
Value * getOrCreateConstMethodReturnValue(const RecordStorageLocation &RecordLoc, const CallExpr *CE, Environment &Env)
Creates or returns a previously created Value associated with a const method call obj....
Holds the state of the program (store and heap) at a given program point.
StorageLocation & createStorageLocation(QualType Type)
Creates a storage location appropriate for Type.
Value * createValue(QualType Type)
Creates a value appropriate for Type, if Type is supported, otherwise returns null.
A storage location for a record (struct, class, or union).
Base class for elements of the local variable store and of the heap.
Base class for all values computed by abstract interpretation.
llvm::SmallDenseMap< const RecordStorageLocation *, llvm::SmallDenseMap< const FunctionDecl *, T * > > joinConstMethodMap(const llvm::SmallDenseMap< const RecordStorageLocation *, llvm::SmallDenseMap< const FunctionDecl *, T * > > &Map1, const llvm::SmallDenseMap< const RecordStorageLocation *, llvm::SmallDenseMap< const FunctionDecl *, T * > > &Map2, LatticeEffect &Effect)
LatticeEffect
Effect indicating whether a lattice operation resulted in a new value.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Other
Other implicit parameter.