clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MemRegion.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/tools/clang/lib/StaticAnalyzer/Core -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/tools/clang/lib/StaticAnalyzer/Core -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/clang/lib/StaticAnalyzer/Core -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/clang/include -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/include -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/include -D NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/tools/clang/lib/StaticAnalyzer/Core -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-09-04-040900-46481-1 -x c++ /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" |
16 | #include "clang/AST/ASTContext.h" |
17 | #include "clang/AST/Attr.h" |
18 | #include "clang/AST/CharUnits.h" |
19 | #include "clang/AST/Decl.h" |
20 | #include "clang/AST/DeclCXX.h" |
21 | #include "clang/AST/DeclObjC.h" |
22 | #include "clang/AST/Expr.h" |
23 | #include "clang/AST/PrettyPrinter.h" |
24 | #include "clang/AST/RecordLayout.h" |
25 | #include "clang/AST/Type.h" |
26 | #include "clang/Analysis/AnalysisDeclContext.h" |
27 | #include "clang/Analysis/Support/BumpVector.h" |
28 | #include "clang/Basic/IdentifierTable.h" |
29 | #include "clang/Basic/LLVM.h" |
30 | #include "clang/Basic/SourceManager.h" |
31 | #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h" |
32 | #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h" |
33 | #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" |
34 | #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" |
35 | #include "llvm/ADT/APInt.h" |
36 | #include "llvm/ADT/FoldingSet.h" |
37 | #include "llvm/ADT/Optional.h" |
38 | #include "llvm/ADT/PointerUnion.h" |
39 | #include "llvm/ADT/SmallString.h" |
40 | #include "llvm/ADT/StringRef.h" |
41 | #include "llvm/ADT/Twine.h" |
42 | #include "llvm/Support/Allocator.h" |
43 | #include "llvm/Support/Casting.h" |
44 | #include "llvm/Support/CheckedArithmetic.h" |
45 | #include "llvm/Support/Compiler.h" |
46 | #include "llvm/Support/Debug.h" |
47 | #include "llvm/Support/ErrorHandling.h" |
48 | #include "llvm/Support/raw_ostream.h" |
49 | #include <cassert> |
50 | #include <cstdint> |
51 | #include <functional> |
52 | #include <iterator> |
53 | #include <string> |
54 | #include <tuple> |
55 | #include <utility> |
56 | |
57 | using namespace clang; |
58 | using namespace ento; |
59 | |
60 | #define DEBUG_TYPE "MemRegion" |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | template <typename RegionTy, typename SuperTy, typename Arg1Ty> |
67 | RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, |
68 | const SuperTy *superRegion) { |
69 | llvm::FoldingSetNodeID ID; |
70 | RegionTy::ProfileRegion(ID, arg1, superRegion); |
71 | void *InsertPos; |
72 | auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos)); |
73 | |
74 | if (!R) { |
75 | R = A.Allocate<RegionTy>(); |
76 | new (R) RegionTy(arg1, superRegion); |
77 | Regions.InsertNode(R, InsertPos); |
78 | } |
79 | |
80 | return R; |
81 | } |
82 | |
83 | template <typename RegionTy, typename SuperTy, typename Arg1Ty, typename Arg2Ty> |
84 | RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, |
85 | const SuperTy *superRegion) { |
86 | llvm::FoldingSetNodeID ID; |
87 | RegionTy::ProfileRegion(ID, arg1, arg2, superRegion); |
88 | void *InsertPos; |
89 | auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos)); |
90 | |
91 | if (!R) { |
92 | R = A.Allocate<RegionTy>(); |
93 | new (R) RegionTy(arg1, arg2, superRegion); |
94 | Regions.InsertNode(R, InsertPos); |
95 | } |
96 | |
97 | return R; |
98 | } |
99 | |
100 | template <typename RegionTy, typename SuperTy, |
101 | typename Arg1Ty, typename Arg2Ty, typename Arg3Ty> |
102 | RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, |
103 | const Arg3Ty arg3, |
104 | const SuperTy *superRegion) { |
105 | llvm::FoldingSetNodeID ID; |
106 | RegionTy::ProfileRegion(ID, arg1, arg2, arg3, superRegion); |
107 | void *InsertPos; |
108 | auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos)); |
109 | |
110 | if (!R) { |
111 | R = A.Allocate<RegionTy>(); |
112 | new (R) RegionTy(arg1, arg2, arg3, superRegion); |
113 | Regions.InsertNode(R, InsertPos); |
114 | } |
115 | |
116 | return R; |
117 | } |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | MemRegion::~MemRegion() = default; |
124 | |
125 | |
126 | |
127 | MemRegionManager::~MemRegionManager() = default; |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | bool SubRegion::isSubRegionOf(const MemRegion* R) const { |
134 | const MemRegion* r = this; |
135 | do { |
136 | if (r == R) |
137 | return true; |
138 | if (const auto *sr = dyn_cast<SubRegion>(r)) |
139 | r = sr->getSuperRegion(); |
140 | else |
141 | break; |
142 | } while (r != nullptr); |
143 | return false; |
144 | } |
145 | |
146 | MemRegionManager &SubRegion::getMemRegionManager() const { |
147 | const SubRegion* r = this; |
148 | do { |
149 | const MemRegion *superRegion = r->getSuperRegion(); |
150 | if (const auto *sr = dyn_cast<SubRegion>(superRegion)) { |
151 | r = sr; |
152 | continue; |
153 | } |
154 | return superRegion->getMemRegionManager(); |
155 | } while (true); |
156 | } |
157 | |
158 | const StackFrameContext *VarRegion::getStackFrame() const { |
159 | const auto *SSR = dyn_cast<StackSpaceRegion>(getMemorySpace()); |
160 | return SSR ? SSR->getStackFrame() : nullptr; |
161 | } |
162 | |
163 | ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg) |
164 | : DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {} |
165 | |
166 | const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; } |
167 | |
168 | QualType ObjCIvarRegion::getValueType() const { |
169 | return getDecl()->getType(); |
170 | } |
171 | |
172 | QualType CXXBaseObjectRegion::getValueType() const { |
173 | return QualType(getDecl()->getTypeForDecl(), 0); |
174 | } |
175 | |
176 | QualType CXXDerivedObjectRegion::getValueType() const { |
177 | return QualType(getDecl()->getTypeForDecl(), 0); |
178 | } |
179 | |
180 | QualType ParamVarRegion::getValueType() const { |
181 | assert(getDecl() && |
182 | "`ParamVarRegion` support functions without `Decl` not implemented" |
183 | " yet."); |
184 | return getDecl()->getType(); |
185 | } |
186 | |
187 | const ParmVarDecl *ParamVarRegion::getDecl() const { |
188 | const Decl *D = getStackFrame()->getDecl(); |
189 | |
190 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { |
191 | assert(Index < FD->param_size()); |
192 | return FD->parameters()[Index]; |
193 | } else if (const auto *BD = dyn_cast<BlockDecl>(D)) { |
194 | assert(Index < BD->param_size()); |
195 | return BD->parameters()[Index]; |
196 | } else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) { |
197 | assert(Index < MD->param_size()); |
198 | return MD->parameters()[Index]; |
199 | } else if (const auto *CD = dyn_cast<CXXConstructorDecl>(D)) { |
200 | assert(Index < CD->param_size()); |
201 | return CD->parameters()[Index]; |
202 | } else { |
203 | llvm_unreachable("Unexpected Decl kind!"); |
204 | } |
205 | } |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | void MemSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
212 | ID.AddInteger(static_cast<unsigned>(getKind())); |
213 | } |
214 | |
215 | void StackSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
216 | ID.AddInteger(static_cast<unsigned>(getKind())); |
217 | ID.AddPointer(getStackFrame()); |
218 | } |
219 | |
220 | void StaticGlobalSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
221 | ID.AddInteger(static_cast<unsigned>(getKind())); |
222 | ID.AddPointer(getCodeRegion()); |
223 | } |
224 | |
225 | void StringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
226 | const StringLiteral *Str, |
227 | const MemRegion *superRegion) { |
228 | ID.AddInteger(static_cast<unsigned>(StringRegionKind)); |
229 | ID.AddPointer(Str); |
230 | ID.AddPointer(superRegion); |
231 | } |
232 | |
233 | void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
234 | const ObjCStringLiteral *Str, |
235 | const MemRegion *superRegion) { |
236 | ID.AddInteger(static_cast<unsigned>(ObjCStringRegionKind)); |
237 | ID.AddPointer(Str); |
238 | ID.AddPointer(superRegion); |
239 | } |
240 | |
241 | void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
242 | const Expr *Ex, unsigned cnt, |
243 | const MemRegion *superRegion) { |
244 | ID.AddInteger(static_cast<unsigned>(AllocaRegionKind)); |
245 | ID.AddPointer(Ex); |
246 | ID.AddInteger(cnt); |
247 | ID.AddPointer(superRegion); |
248 | } |
249 | |
250 | void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
251 | ProfileRegion(ID, Ex, Cnt, superRegion); |
252 | } |
253 | |
254 | void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
255 | CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion); |
256 | } |
257 | |
258 | void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
259 | const CompoundLiteralExpr *CL, |
260 | const MemRegion* superRegion) { |
261 | ID.AddInteger(static_cast<unsigned>(CompoundLiteralRegionKind)); |
262 | ID.AddPointer(CL); |
263 | ID.AddPointer(superRegion); |
264 | } |
265 | |
266 | void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
267 | const PointerType *PT, |
268 | const MemRegion *sRegion) { |
269 | ID.AddInteger(static_cast<unsigned>(CXXThisRegionKind)); |
270 | ID.AddPointer(PT); |
271 | ID.AddPointer(sRegion); |
272 | } |
273 | |
274 | void CXXThisRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
275 | CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion); |
276 | } |
277 | |
278 | void FieldRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
279 | ProfileRegion(ID, getDecl(), superRegion); |
280 | } |
281 | |
282 | void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
283 | const ObjCIvarDecl *ivd, |
284 | const MemRegion* superRegion) { |
285 | ID.AddInteger(static_cast<unsigned>(ObjCIvarRegionKind)); |
286 | ID.AddPointer(ivd); |
287 | ID.AddPointer(superRegion); |
288 | } |
289 | |
290 | void ObjCIvarRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
291 | ProfileRegion(ID, getDecl(), superRegion); |
292 | } |
293 | |
294 | void NonParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
295 | const VarDecl *VD, |
296 | const MemRegion *superRegion) { |
297 | ID.AddInteger(static_cast<unsigned>(NonParamVarRegionKind)); |
298 | ID.AddPointer(VD); |
299 | ID.AddPointer(superRegion); |
300 | } |
301 | |
302 | void NonParamVarRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
303 | ProfileRegion(ID, getDecl(), superRegion); |
304 | } |
305 | |
306 | void ParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, const Expr *OE, |
307 | unsigned Idx, const MemRegion *SReg) { |
308 | ID.AddInteger(static_cast<unsigned>(ParamVarRegionKind)); |
309 | ID.AddPointer(OE); |
310 | ID.AddInteger(Idx); |
311 | ID.AddPointer(SReg); |
312 | } |
313 | |
314 | void ParamVarRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
315 | ProfileRegion(ID, getOriginExpr(), getIndex(), superRegion); |
316 | } |
317 | |
318 | void SymbolicRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SymbolRef sym, |
319 | const MemRegion *sreg) { |
320 | ID.AddInteger(static_cast<unsigned>(MemRegion::SymbolicRegionKind)); |
321 | ID.Add(sym); |
322 | ID.AddPointer(sreg); |
323 | } |
324 | |
325 | void SymbolicRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
326 | SymbolicRegion::ProfileRegion(ID, sym, getSuperRegion()); |
327 | } |
328 | |
329 | void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
330 | QualType ElementType, SVal Idx, |
331 | const MemRegion* superRegion) { |
332 | ID.AddInteger(MemRegion::ElementRegionKind); |
333 | ID.Add(ElementType); |
334 | ID.AddPointer(superRegion); |
335 | Idx.Profile(ID); |
336 | } |
337 | |
338 | void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
339 | ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion); |
340 | } |
341 | |
342 | void FunctionCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
343 | const NamedDecl *FD, |
344 | const MemRegion*) { |
345 | ID.AddInteger(MemRegion::FunctionCodeRegionKind); |
346 | ID.AddPointer(FD); |
347 | } |
348 | |
349 | void FunctionCodeRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
350 | FunctionCodeRegion::ProfileRegion(ID, FD, superRegion); |
351 | } |
352 | |
353 | void BlockCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
354 | const BlockDecl *BD, CanQualType, |
355 | const AnalysisDeclContext *AC, |
356 | const MemRegion*) { |
357 | ID.AddInteger(MemRegion::BlockCodeRegionKind); |
358 | ID.AddPointer(BD); |
359 | } |
360 | |
361 | void BlockCodeRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
362 | BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC, superRegion); |
363 | } |
364 | |
365 | void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
366 | const BlockCodeRegion *BC, |
367 | const LocationContext *LC, |
368 | unsigned BlkCount, |
369 | const MemRegion *sReg) { |
370 | ID.AddInteger(MemRegion::BlockDataRegionKind); |
371 | ID.AddPointer(BC); |
372 | ID.AddPointer(LC); |
373 | ID.AddInteger(BlkCount); |
374 | ID.AddPointer(sReg); |
375 | } |
376 | |
377 | void BlockDataRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
378 | BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount, getSuperRegion()); |
379 | } |
380 | |
381 | void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
382 | Expr const *Ex, |
383 | const MemRegion *sReg) { |
384 | ID.AddPointer(Ex); |
385 | ID.AddPointer(sReg); |
386 | } |
387 | |
388 | void CXXTempObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
389 | ProfileRegion(ID, Ex, getSuperRegion()); |
390 | } |
391 | |
392 | void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
393 | const CXXRecordDecl *RD, |
394 | bool IsVirtual, |
395 | const MemRegion *SReg) { |
396 | ID.AddPointer(RD); |
397 | ID.AddBoolean(IsVirtual); |
398 | ID.AddPointer(SReg); |
399 | } |
400 | |
401 | void CXXBaseObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
402 | ProfileRegion(ID, getDecl(), isVirtual(), superRegion); |
403 | } |
404 | |
405 | void CXXDerivedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
406 | const CXXRecordDecl *RD, |
407 | const MemRegion *SReg) { |
408 | ID.AddPointer(RD); |
409 | ID.AddPointer(SReg); |
410 | } |
411 | |
412 | void CXXDerivedObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
413 | ProfileRegion(ID, getDecl(), superRegion); |
414 | } |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | void GlobalsSpaceRegion::anchor() {} |
421 | |
422 | void NonStaticGlobalSpaceRegion::anchor() {} |
423 | |
424 | void StackSpaceRegion::anchor() {} |
425 | |
426 | void TypedRegion::anchor() {} |
427 | |
428 | void TypedValueRegion::anchor() {} |
429 | |
430 | void CodeTextRegion::anchor() {} |
431 | |
432 | void SubRegion::anchor() {} |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | LLVM_DUMP_METHOD void MemRegion::dump() const { |
439 | dumpToStream(llvm::errs()); |
440 | } |
441 | |
442 | std::string MemRegion::getString() const { |
443 | std::string s; |
444 | llvm::raw_string_ostream os(s); |
445 | dumpToStream(os); |
446 | return os.str(); |
447 | } |
448 | |
449 | void MemRegion::dumpToStream(raw_ostream &os) const { |
450 | os << "<Unknown Region>"; |
451 | } |
452 | |
453 | void AllocaRegion::dumpToStream(raw_ostream &os) const { |
454 | os << "alloca{S" << Ex->getID(getContext()) << ',' << Cnt << '}'; |
455 | } |
456 | |
457 | void FunctionCodeRegion::dumpToStream(raw_ostream &os) const { |
458 | os << "code{" << getDecl()->getDeclName().getAsString() << '}'; |
459 | } |
460 | |
461 | void BlockCodeRegion::dumpToStream(raw_ostream &os) const { |
462 | os << "block_code{" << static_cast<const void *>(this) << '}'; |
463 | } |
464 | |
465 | void BlockDataRegion::dumpToStream(raw_ostream &os) const { |
466 | os << "block_data{" << BC; |
467 | os << "; "; |
468 | for (BlockDataRegion::referenced_vars_iterator |
469 | I = referenced_vars_begin(), |
470 | E = referenced_vars_end(); I != E; ++I) |
471 | os << "(" << I.getCapturedRegion() << "<-" << |
472 | I.getOriginalRegion() << ") "; |
473 | os << '}'; |
474 | } |
475 | |
476 | void CompoundLiteralRegion::dumpToStream(raw_ostream &os) const { |
477 | |
478 | os << "{ S" << CL->getID(getContext()) << " }"; |
479 | } |
480 | |
481 | void CXXTempObjectRegion::dumpToStream(raw_ostream &os) const { |
482 | os << "temp_object{" << getValueType().getAsString() << ", " |
483 | << "S" << Ex->getID(getContext()) << '}'; |
484 | } |
485 | |
486 | void CXXBaseObjectRegion::dumpToStream(raw_ostream &os) const { |
487 | os << "Base{" << superRegion << ',' << getDecl()->getName() << '}'; |
488 | } |
489 | |
490 | void CXXDerivedObjectRegion::dumpToStream(raw_ostream &os) const { |
491 | os << "Derived{" << superRegion << ',' << getDecl()->getName() << '}'; |
492 | } |
493 | |
494 | void CXXThisRegion::dumpToStream(raw_ostream &os) const { |
495 | os << "this"; |
496 | } |
497 | |
498 | void ElementRegion::dumpToStream(raw_ostream &os) const { |
499 | os << "Element{" << superRegion << ',' |
500 | << Index << ',' << getElementType().getAsString() << '}'; |
501 | } |
502 | |
503 | void FieldRegion::dumpToStream(raw_ostream &os) const { |
504 | os << superRegion << "." << *getDecl(); |
505 | } |
506 | |
507 | void ObjCIvarRegion::dumpToStream(raw_ostream &os) const { |
508 | os << "Ivar{" << superRegion << ',' << *getDecl() << '}'; |
509 | } |
510 | |
511 | void StringRegion::dumpToStream(raw_ostream &os) const { |
512 | assert(Str != nullptr && "Expecting non-null StringLiteral"); |
513 | Str->printPretty(os, nullptr, PrintingPolicy(getContext().getLangOpts())); |
514 | } |
515 | |
516 | void ObjCStringRegion::dumpToStream(raw_ostream &os) const { |
517 | assert(Str != nullptr && "Expecting non-null ObjCStringLiteral"); |
518 | Str->printPretty(os, nullptr, PrintingPolicy(getContext().getLangOpts())); |
519 | } |
520 | |
521 | void SymbolicRegion::dumpToStream(raw_ostream &os) const { |
522 | if (isa<HeapSpaceRegion>(getSuperRegion())) |
523 | os << "Heap"; |
524 | os << "SymRegion{" << sym << '}'; |
525 | } |
526 | |
527 | void NonParamVarRegion::dumpToStream(raw_ostream &os) const { |
528 | if (const IdentifierInfo *ID = VD->getIdentifier()) |
529 | os << ID->getName(); |
530 | else |
531 | os << "NonParamVarRegion{D" << VD->getID() << '}'; |
532 | } |
533 | |
534 | LLVM_DUMP_METHOD void RegionRawOffset::dump() const { |
535 | dumpToStream(llvm::errs()); |
536 | } |
537 | |
538 | void RegionRawOffset::dumpToStream(raw_ostream &os) const { |
539 | os << "raw_offset{" << getRegion() << ',' << getOffset().getQuantity() << '}'; |
540 | } |
541 | |
542 | void CodeSpaceRegion::dumpToStream(raw_ostream &os) const { |
543 | os << "CodeSpaceRegion"; |
544 | } |
545 | |
546 | void StaticGlobalSpaceRegion::dumpToStream(raw_ostream &os) const { |
547 | os << "StaticGlobalsMemSpace{" << CR << '}'; |
548 | } |
549 | |
550 | void GlobalInternalSpaceRegion::dumpToStream(raw_ostream &os) const { |
551 | os << "GlobalInternalSpaceRegion"; |
552 | } |
553 | |
554 | void GlobalSystemSpaceRegion::dumpToStream(raw_ostream &os) const { |
555 | os << "GlobalSystemSpaceRegion"; |
556 | } |
557 | |
558 | void GlobalImmutableSpaceRegion::dumpToStream(raw_ostream &os) const { |
559 | os << "GlobalImmutableSpaceRegion"; |
560 | } |
561 | |
562 | void HeapSpaceRegion::dumpToStream(raw_ostream &os) const { |
563 | os << "HeapSpaceRegion"; |
564 | } |
565 | |
566 | void UnknownSpaceRegion::dumpToStream(raw_ostream &os) const { |
567 | os << "UnknownSpaceRegion"; |
568 | } |
569 | |
570 | void StackArgumentsSpaceRegion::dumpToStream(raw_ostream &os) const { |
571 | os << "StackArgumentsSpaceRegion"; |
572 | } |
573 | |
574 | void StackLocalsSpaceRegion::dumpToStream(raw_ostream &os) const { |
575 | os << "StackLocalsSpaceRegion"; |
576 | } |
577 | |
578 | void ParamVarRegion::dumpToStream(raw_ostream &os) const { |
579 | const ParmVarDecl *PVD = getDecl(); |
580 | assert(PVD && |
581 | "`ParamVarRegion` support functions without `Decl` not implemented" |
582 | " yet."); |
583 | if (const IdentifierInfo *ID = PVD->getIdentifier()) { |
584 | os << ID->getName(); |
585 | } else { |
586 | os << "ParamVarRegion{P" << PVD->getID() << '}'; |
587 | } |
588 | } |
589 | |
590 | bool MemRegion::canPrintPretty() const { |
591 | return canPrintPrettyAsExpr(); |
592 | } |
593 | |
594 | bool MemRegion::canPrintPrettyAsExpr() const { |
595 | return false; |
596 | } |
597 | |
598 | void MemRegion::printPretty(raw_ostream &os) const { |
599 | assert(canPrintPretty() && "This region cannot be printed pretty."); |
600 | os << "'"; |
601 | printPrettyAsExpr(os); |
602 | os << "'"; |
603 | } |
604 | |
605 | void MemRegion::printPrettyAsExpr(raw_ostream &) const { |
606 | llvm_unreachable("This region cannot be printed pretty."); |
607 | } |
608 | |
609 | bool NonParamVarRegion::canPrintPrettyAsExpr() const { return true; } |
610 | |
611 | void NonParamVarRegion::printPrettyAsExpr(raw_ostream &os) const { |
612 | os << getDecl()->getName(); |
613 | } |
614 | |
615 | bool ParamVarRegion::canPrintPrettyAsExpr() const { return true; } |
616 | |
617 | void ParamVarRegion::printPrettyAsExpr(raw_ostream &os) const { |
618 | assert(getDecl() && |
619 | "`ParamVarRegion` support functions without `Decl` not implemented" |
620 | " yet."); |
621 | os << getDecl()->getName(); |
622 | } |
623 | |
624 | bool ObjCIvarRegion::canPrintPrettyAsExpr() const { |
625 | return true; |
626 | } |
627 | |
628 | void ObjCIvarRegion::printPrettyAsExpr(raw_ostream &os) const { |
629 | os << getDecl()->getName(); |
630 | } |
631 | |
632 | bool FieldRegion::canPrintPretty() const { |
633 | return true; |
634 | } |
635 | |
636 | bool FieldRegion::canPrintPrettyAsExpr() const { |
637 | return superRegion->canPrintPrettyAsExpr(); |
638 | } |
639 | |
640 | void FieldRegion::printPrettyAsExpr(raw_ostream &os) const { |
641 | assert(canPrintPrettyAsExpr()); |
642 | superRegion->printPrettyAsExpr(os); |
643 | os << "." << getDecl()->getName(); |
644 | } |
645 | |
646 | void FieldRegion::printPretty(raw_ostream &os) const { |
647 | if (canPrintPrettyAsExpr()) { |
648 | os << "\'"; |
649 | printPrettyAsExpr(os); |
650 | os << "'"; |
651 | } else { |
652 | os << "field " << "\'" << getDecl()->getName() << "'"; |
653 | } |
654 | } |
655 | |
656 | bool CXXBaseObjectRegion::canPrintPrettyAsExpr() const { |
657 | return superRegion->canPrintPrettyAsExpr(); |
658 | } |
659 | |
660 | void CXXBaseObjectRegion::printPrettyAsExpr(raw_ostream &os) const { |
661 | superRegion->printPrettyAsExpr(os); |
662 | } |
663 | |
664 | bool CXXDerivedObjectRegion::canPrintPrettyAsExpr() const { |
665 | return superRegion->canPrintPrettyAsExpr(); |
666 | } |
667 | |
668 | void CXXDerivedObjectRegion::printPrettyAsExpr(raw_ostream &os) const { |
669 | superRegion->printPrettyAsExpr(os); |
670 | } |
671 | |
672 | std::string MemRegion::getDescriptiveName(bool UseQuotes) const { |
673 | std::string VariableName; |
674 | std::string ArrayIndices; |
675 | const MemRegion *R = this; |
676 | SmallString<50> buf; |
677 | llvm::raw_svector_ostream os(buf); |
678 | |
679 | |
680 | const ElementRegion *ER = nullptr; |
681 | while ((ER = R->getAs<ElementRegion>())) { |
682 | |
683 | if (auto CI = ER->getIndex().getAs<nonloc::ConcreteInt>()) { |
684 | llvm::SmallString<2> Idx; |
685 | CI->getValue().toString(Idx); |
686 | ArrayIndices = (llvm::Twine("[") + Idx.str() + "]" + ArrayIndices).str(); |
687 | } |
688 | |
689 | |
690 | else { |
691 | std::string Idx = ER->getDescriptiveName(false); |
692 | if (!Idx.empty()) { |
693 | ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str(); |
694 | } |
695 | } |
696 | R = ER->getSuperRegion(); |
697 | } |
698 | |
699 | |
700 | if (R && R->canPrintPrettyAsExpr()) { |
701 | R->printPrettyAsExpr(os); |
702 | if (UseQuotes) |
703 | return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str(); |
704 | else |
705 | return (llvm::Twine(os.str()) + ArrayIndices).str(); |
706 | } |
707 | |
708 | return VariableName; |
709 | } |
710 | |
711 | SourceRange MemRegion::sourceRange() const { |
712 | const auto *const VR = dyn_cast<VarRegion>(this->getBaseRegion()); |
713 | const auto *const FR = dyn_cast<FieldRegion>(this); |
714 | |
715 | |
716 | |
717 | if (FR) { |
718 | return FR->getDecl()->getSourceRange(); |
719 | } |
720 | |
721 | else if (VR) { |
722 | return VR->getDecl()->getSourceRange(); |
723 | } |
724 | |
725 | else |
726 | return {}; |
727 | } |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR, |
734 | SValBuilder &SVB) const { |
735 | const auto *SR = cast<SubRegion>(MR); |
736 | SymbolManager &SymMgr = SVB.getSymbolManager(); |
737 | |
738 | switch (SR->getKind()) { |
739 | case MemRegion::AllocaRegionKind: |
740 | case MemRegion::SymbolicRegionKind: |
741 | return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR)); |
742 | case MemRegion::StringRegionKind: |
743 | return SVB.makeIntVal( |
744 | cast<StringRegion>(SR)->getStringLiteral()->getByteLength() + 1, |
745 | SVB.getArrayIndexType()); |
746 | case MemRegion::CompoundLiteralRegionKind: |
747 | case MemRegion::CXXBaseObjectRegionKind: |
748 | case MemRegion::CXXDerivedObjectRegionKind: |
749 | case MemRegion::CXXTempObjectRegionKind: |
750 | case MemRegion::CXXThisRegionKind: |
751 | case MemRegion::ObjCIvarRegionKind: |
752 | case MemRegion::NonParamVarRegionKind: |
753 | case MemRegion::ParamVarRegionKind: |
754 | case MemRegion::ElementRegionKind: |
755 | case MemRegion::ObjCStringRegionKind: { |
756 | QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx); |
757 | if (isa<VariableArrayType>(Ty)) |
758 | return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR)); |
759 | |
760 | if (Ty->isIncompleteType()) |
761 | return UnknownVal(); |
762 | |
763 | return getElementExtent(Ty, SVB); |
764 | } |
765 | case MemRegion::FieldRegionKind: { |
766 | |
767 | if (cast<FieldRegion>(SR)->getDecl()->isBitField()) |
768 | return UnknownVal(); |
769 | |
770 | QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx); |
771 | const DefinedOrUnknownSVal Size = getElementExtent(Ty, SVB); |
772 | |
773 | |
774 | |
775 | const auto isFlexibleArrayMemberCandidate = [this](QualType Ty) -> bool { |
776 | const ArrayType *AT = Ctx.getAsArrayType(Ty); |
777 | if (!AT) |
778 | return false; |
779 | if (isa<IncompleteArrayType>(AT)) |
780 | return true; |
781 | |
782 | if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) { |
783 | const llvm::APInt &Size = CAT->getSize(); |
784 | if (Size.isNullValue()) |
785 | return true; |
786 | } |
787 | return false; |
788 | }; |
789 | |
790 | if (isFlexibleArrayMemberCandidate(Ty)) |
791 | return UnknownVal(); |
792 | |
793 | return Size; |
794 | } |
795 | |
796 | |
797 | |
798 | case MemRegion::BlockDataRegionKind: |
799 | case MemRegion::BlockCodeRegionKind: |
800 | case MemRegion::FunctionCodeRegionKind: |
801 | return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR)); |
802 | default: |
803 | llvm_unreachable("Unhandled region"); |
804 | } |
805 | } |
806 | |
807 | template <typename REG> |
808 | const REG *MemRegionManager::LazyAllocate(REG*& region) { |
809 | if (!region) { |
810 | region = A.Allocate<REG>(); |
811 | new (region) REG(*this); |
812 | } |
813 | |
814 | return region; |
815 | } |
816 | |
817 | template <typename REG, typename ARG> |
818 | const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) { |
819 | if (!region) { |
820 | region = A.Allocate<REG>(); |
821 | new (region) REG(this, a); |
822 | } |
823 | |
824 | return region; |
825 | } |
826 | |
827 | const StackLocalsSpaceRegion* |
828 | MemRegionManager::getStackLocalsRegion(const StackFrameContext *STC) { |
829 | assert(STC); |
830 | StackLocalsSpaceRegion *&R = StackLocalsSpaceRegions[STC]; |
831 | |
832 | if (R) |
833 | return R; |
834 | |
835 | R = A.Allocate<StackLocalsSpaceRegion>(); |
836 | new (R) StackLocalsSpaceRegion(*this, STC); |
837 | return R; |
838 | } |
839 | |
840 | const StackArgumentsSpaceRegion * |
841 | MemRegionManager::getStackArgumentsRegion(const StackFrameContext *STC) { |
842 | assert(STC); |
843 | StackArgumentsSpaceRegion *&R = StackArgumentsSpaceRegions[STC]; |
844 | |
845 | if (R) |
846 | return R; |
847 | |
848 | R = A.Allocate<StackArgumentsSpaceRegion>(); |
849 | new (R) StackArgumentsSpaceRegion(*this, STC); |
850 | return R; |
851 | } |
852 | |
853 | const GlobalsSpaceRegion |
854 | *MemRegionManager::getGlobalsRegion(MemRegion::Kind K, |
855 | const CodeTextRegion *CR) { |
856 | if (!CR) { |
857 | if (K == MemRegion::GlobalSystemSpaceRegionKind) |
858 | return LazyAllocate(SystemGlobals); |
859 | if (K == MemRegion::GlobalImmutableSpaceRegionKind) |
860 | return LazyAllocate(ImmutableGlobals); |
861 | assert(K == MemRegion::GlobalInternalSpaceRegionKind); |
862 | return LazyAllocate(InternalGlobals); |
863 | } |
864 | |
865 | assert(K == MemRegion::StaticGlobalSpaceRegionKind); |
866 | StaticGlobalSpaceRegion *&R = StaticsGlobalSpaceRegions[CR]; |
867 | if (R) |
868 | return R; |
869 | |
870 | R = A.Allocate<StaticGlobalSpaceRegion>(); |
871 | new (R) StaticGlobalSpaceRegion(*this, CR); |
872 | return R; |
873 | } |
874 | |
875 | const HeapSpaceRegion *MemRegionManager::getHeapRegion() { |
876 | return LazyAllocate(heap); |
877 | } |
878 | |
879 | const UnknownSpaceRegion *MemRegionManager::getUnknownRegion() { |
880 | return LazyAllocate(unknown); |
881 | } |
882 | |
883 | const CodeSpaceRegion *MemRegionManager::getCodeRegion() { |
884 | return LazyAllocate(code); |
885 | } |
886 | |
887 | |
888 | |
889 | |
890 | |
891 | const StringRegion *MemRegionManager::getStringRegion(const StringLiteral *Str){ |
892 | return getSubRegion<StringRegion>( |
893 | Str, cast<GlobalInternalSpaceRegion>(getGlobalsRegion())); |
894 | } |
895 | |
896 | const ObjCStringRegion * |
897 | MemRegionManager::getObjCStringRegion(const ObjCStringLiteral *Str){ |
898 | return getSubRegion<ObjCStringRegion>( |
899 | Str, cast<GlobalInternalSpaceRegion>(getGlobalsRegion())); |
900 | } |
901 | |
902 | |
903 | |
904 | |
905 | static llvm::PointerUnion<const StackFrameContext *, const VarRegion *> |
906 | getStackOrCaptureRegionForDeclContext(const LocationContext *LC, |
907 | const DeclContext *DC, |
908 | const VarDecl *VD) { |
909 | while (LC) { |
910 | if (const auto *SFC = dyn_cast<StackFrameContext>(LC)) { |
911 | if (cast<DeclContext>(SFC->getDecl()) == DC) |
912 | return SFC; |
913 | } |
914 | if (const auto *BC = dyn_cast<BlockInvocationContext>(LC)) { |
915 | const auto *BR = static_cast<const BlockDataRegion *>(BC->getData()); |
916 | |
917 | for (BlockDataRegion::referenced_vars_iterator |
918 | I = BR->referenced_vars_begin(), |
919 | E = BR->referenced_vars_end(); I != E; ++I) { |
920 | const TypedValueRegion *OrigR = I.getOriginalRegion(); |
921 | if (const auto *VR = dyn_cast<VarRegion>(OrigR)) { |
922 | if (VR->getDecl() == VD) |
923 | return cast<VarRegion>(I.getCapturedRegion()); |
924 | } |
925 | } |
926 | } |
927 | |
928 | LC = LC->getParent(); |
929 | } |
930 | return (const StackFrameContext *)nullptr; |
931 | } |
932 | |
933 | const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D, |
934 | const LocationContext *LC) { |
935 | const auto *PVD = dyn_cast<ParmVarDecl>(D); |
936 | if (PVD) { |
937 | unsigned Index = PVD->getFunctionScopeIndex(); |
938 | const StackFrameContext *SFC = LC->getStackFrame(); |
939 | const Stmt *CallSite = SFC->getCallSite(); |
940 | if (CallSite) { |
941 | const Decl *D = SFC->getDecl(); |
942 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { |
943 | if (Index < FD->param_size() && FD->parameters()[Index] == PVD) |
944 | return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index, |
945 | getStackArgumentsRegion(SFC)); |
946 | } else if (const auto *BD = dyn_cast<BlockDecl>(D)) { |
947 | if (Index < BD->param_size() && BD->parameters()[Index] == PVD) |
948 | return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index, |
949 | getStackArgumentsRegion(SFC)); |
950 | } else { |
951 | return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index, |
952 | getStackArgumentsRegion(SFC)); |
953 | } |
954 | } |
955 | } |
956 | |
957 | D = D->getCanonicalDecl(); |
958 | const MemRegion *sReg = nullptr; |
959 | |
960 | if (D->hasGlobalStorage() && !D->isStaticLocal()) { |
961 | |
962 | |
963 | if (Ctx.getSourceManager().isInSystemHeader(D->getLocation())) { |
964 | |
965 | |
966 | if (D->getName().find("errno") != StringRef::npos) |
967 | sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind); |
968 | else |
969 | sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind); |
970 | |
971 | |
972 | } else { |
973 | QualType GQT = D->getType(); |
974 | const Type *GT = GQT.getTypePtrOrNull(); |
975 | |
976 | |
977 | if (GT && GQT.isConstQualified() && GT->isArithmeticType()) |
978 | sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind); |
979 | else |
980 | sReg = getGlobalsRegion(); |
981 | } |
982 | |
983 | |
984 | } else { |
985 | |
986 | |
987 | const DeclContext *DC = D->getDeclContext(); |
988 | llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V = |
989 | getStackOrCaptureRegionForDeclContext(LC, DC, D); |
990 | |
991 | if (V.is<const VarRegion*>()) |
992 | return V.get<const VarRegion*>(); |
993 | |
994 | const auto *STC = V.get<const StackFrameContext *>(); |
995 | |
996 | if (!STC) { |
997 | |
998 | |
999 | sReg = getUnknownRegion(); |
1000 | } else { |
1001 | if (D->hasLocalStorage()) { |
1002 | sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D) |
1003 | ? static_cast<const MemRegion*>(getStackArgumentsRegion(STC)) |
1004 | : static_cast<const MemRegion*>(getStackLocalsRegion(STC)); |
1005 | } |
1006 | else { |
1007 | assert(D->isStaticLocal()); |
1008 | const Decl *STCD = STC->getDecl(); |
1009 | if (isa<FunctionDecl>(STCD) || isa<ObjCMethodDecl>(STCD)) |
1010 | sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind, |
1011 | getFunctionCodeRegion(cast<NamedDecl>(STCD))); |
1012 | else if (const auto *BD = dyn_cast<BlockDecl>(STCD)) { |
1013 | |
1014 | |
1015 | |
1016 | |
1017 | QualType T; |
1018 | if (const TypeSourceInfo *TSI = BD->getSignatureAsWritten()) |
1019 | T = TSI->getType(); |
1020 | if (T.isNull()) |
1021 | T = getContext().VoidTy; |
1022 | if (!T->getAs<FunctionType>()) |
1023 | T = getContext().getFunctionNoProtoType(T); |
1024 | T = getContext().getBlockPointerType(T); |
1025 | |
1026 | const BlockCodeRegion *BTR = |
1027 | getBlockCodeRegion(BD, Ctx.getCanonicalType(T), |
1028 | STC->getAnalysisDeclContext()); |
1029 | sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind, |
1030 | BTR); |
1031 | } |
1032 | else { |
1033 | sReg = getGlobalsRegion(); |
1034 | } |
1035 | } |
1036 | } |
1037 | } |
1038 | |
1039 | return getSubRegion<NonParamVarRegion>(D, sReg); |
1040 | } |
1041 | |
1042 | const NonParamVarRegion * |
1043 | MemRegionManager::getNonParamVarRegion(const VarDecl *D, |
1044 | const MemRegion *superR) { |
1045 | D = D->getCanonicalDecl(); |
1046 | return getSubRegion<NonParamVarRegion>(D, superR); |
1047 | } |
1048 | |
1049 | const ParamVarRegion * |
1050 | MemRegionManager::getParamVarRegion(const Expr *OriginExpr, unsigned Index, |
1051 | const LocationContext *LC) { |
1052 | const StackFrameContext *SFC = LC->getStackFrame(); |
1053 | assert(SFC); |
1054 | return getSubRegion<ParamVarRegion>(OriginExpr, Index, |
1055 | getStackArgumentsRegion(SFC)); |
1056 | } |
1057 | |
1058 | const BlockDataRegion * |
1059 | MemRegionManager::getBlockDataRegion(const BlockCodeRegion *BC, |
1060 | const LocationContext *LC, |
1061 | unsigned blockCount) { |
1062 | const MemSpaceRegion *sReg = nullptr; |
1063 | const BlockDecl *BD = BC->getDecl(); |
1064 | if (!BD->hasCaptures()) { |
1065 | |
1066 | sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind); |
1067 | } |
1068 | else { |
1069 | if (LC) { |
1070 | |
1071 | |
1072 | const StackFrameContext *STC = LC->getStackFrame(); |
1073 | assert(STC); |
1074 | sReg = getStackLocalsRegion(STC); |
1075 | } |
1076 | else { |
1077 | |
1078 | |
1079 | sReg = getUnknownRegion(); |
1080 | } |
1081 | } |
1082 | |
1083 | return getSubRegion<BlockDataRegion>(BC, LC, blockCount, sReg); |
1084 | } |
1085 | |
1086 | const CXXTempObjectRegion * |
1087 | MemRegionManager::getCXXStaticTempObjectRegion(const Expr *Ex) { |
1088 | return getSubRegion<CXXTempObjectRegion>( |
1089 | Ex, getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind, nullptr)); |
1090 | } |
1091 | |
1092 | const CompoundLiteralRegion* |
1093 | MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr *CL, |
1094 | const LocationContext *LC) { |
1095 | const MemSpaceRegion *sReg = nullptr; |
1096 | |
1097 | if (CL->isFileScope()) |
1098 | sReg = getGlobalsRegion(); |
1099 | else { |
1100 | const StackFrameContext *STC = LC->getStackFrame(); |
1101 | assert(STC); |
1102 | sReg = getStackLocalsRegion(STC); |
1103 | } |
1104 | |
1105 | return getSubRegion<CompoundLiteralRegion>(CL, sReg); |
1106 | } |
1107 | |
1108 | const ElementRegion* |
1109 | MemRegionManager::getElementRegion(QualType elementType, NonLoc Idx, |
1110 | const SubRegion* superRegion, |
1111 | ASTContext &Ctx){ |
1112 | QualType T = Ctx.getCanonicalType(elementType).getUnqualifiedType(); |
1113 | |
1114 | llvm::FoldingSetNodeID ID; |
1115 | ElementRegion::ProfileRegion(ID, T, Idx, superRegion); |
1116 | |
1117 | void *InsertPos; |
1118 | MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos); |
1119 | auto *R = cast_or_null<ElementRegion>(data); |
1120 | |
1121 | if (!R) { |
1122 | R = A.Allocate<ElementRegion>(); |
1123 | new (R) ElementRegion(T, Idx, superRegion); |
1124 | Regions.InsertNode(R, InsertPos); |
1125 | } |
1126 | |
1127 | return R; |
1128 | } |
1129 | |
1130 | const FunctionCodeRegion * |
1131 | MemRegionManager::getFunctionCodeRegion(const NamedDecl *FD) { |
1132 | |
1133 | return getSubRegion<FunctionCodeRegion>(FD, getCodeRegion()); |
1134 | } |
1135 | |
1136 | const BlockCodeRegion * |
1137 | MemRegionManager::getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, |
1138 | AnalysisDeclContext *AC) { |
1139 | return getSubRegion<BlockCodeRegion>(BD, locTy, AC, getCodeRegion()); |
1140 | } |
1141 | |
1142 | |
1143 | const SymbolicRegion *MemRegionManager::getSymbolicRegion(SymbolRef sym) { |
1144 | return getSubRegion<SymbolicRegion>(sym, getUnknownRegion()); |
1145 | } |
1146 | |
1147 | const SymbolicRegion *MemRegionManager::getSymbolicHeapRegion(SymbolRef Sym) { |
1148 | return getSubRegion<SymbolicRegion>(Sym, getHeapRegion()); |
1149 | } |
1150 | |
1151 | const FieldRegion* |
1152 | MemRegionManager::getFieldRegion(const FieldDecl *d, |
1153 | const SubRegion* superRegion){ |
1154 | return getSubRegion<FieldRegion>(d, superRegion); |
1155 | } |
1156 | |
1157 | const ObjCIvarRegion* |
1158 | MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl *d, |
1159 | const SubRegion* superRegion) { |
1160 | return getSubRegion<ObjCIvarRegion>(d, superRegion); |
1161 | } |
1162 | |
1163 | const CXXTempObjectRegion* |
1164 | MemRegionManager::getCXXTempObjectRegion(Expr const *E, |
1165 | LocationContext const *LC) { |
1166 | const StackFrameContext *SFC = LC->getStackFrame(); |
1167 | assert(SFC); |
1168 | return getSubRegion<CXXTempObjectRegion>(E, getStackLocalsRegion(SFC)); |
1169 | } |
1170 | |
1171 | |
1172 | |
1173 | static bool isValidBaseClass(const CXXRecordDecl *BaseClass, |
1174 | const TypedValueRegion *Super, |
1175 | bool IsVirtual) { |
1176 | BaseClass = BaseClass->getCanonicalDecl(); |
1177 | |
1178 | const CXXRecordDecl *Class = Super->getValueType()->getAsCXXRecordDecl(); |
1179 | if (!Class) |
1180 | return true; |
1181 | |
1182 | if (IsVirtual) |
1183 | return Class->isVirtuallyDerivedFrom(BaseClass); |
1184 | |
1185 | for (const auto &I : Class->bases()) { |
1186 | if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass) |
1187 | return true; |
1188 | } |
1189 | |
1190 | return false; |
1191 | } |
1192 | |
1193 | const CXXBaseObjectRegion * |
1194 | MemRegionManager::getCXXBaseObjectRegion(const CXXRecordDecl *RD, |
1195 | const SubRegion *Super, |
1196 | bool IsVirtual) { |
1197 | if (isa<TypedValueRegion>(Super)) { |
1198 | assert(isValidBaseClass(RD, cast<TypedValueRegion>(Super), IsVirtual)); |
1199 | (void)&isValidBaseClass; |
1200 | |
1201 | if (IsVirtual) { |
1202 | |
1203 | |
1204 | while (const auto *Base = dyn_cast<CXXBaseObjectRegion>(Super)) |
1205 | Super = cast<SubRegion>(Base->getSuperRegion()); |
1206 | assert(Super && !isa<MemSpaceRegion>(Super)); |
1207 | } |
1208 | } |
1209 | |
1210 | return getSubRegion<CXXBaseObjectRegion>(RD, IsVirtual, Super); |
1211 | } |
1212 | |
1213 | const CXXDerivedObjectRegion * |
1214 | MemRegionManager::getCXXDerivedObjectRegion(const CXXRecordDecl *RD, |
1215 | const SubRegion *Super) { |
1216 | return getSubRegion<CXXDerivedObjectRegion>(RD, Super); |
1217 | } |
1218 | |
1219 | const CXXThisRegion* |
1220 | MemRegionManager::getCXXThisRegion(QualType thisPointerTy, |
1221 | const LocationContext *LC) { |
1222 | const auto *PT = thisPointerTy->getAs<PointerType>(); |
1223 | assert(PT); |
1224 | |
1225 | |
1226 | const auto *D = dyn_cast<CXXMethodDecl>(LC->getDecl()); |
1227 | |
1228 | |
1229 | |
1230 | while (!LC->inTopFrame() && (!D || D->isStatic() || |
1231 | PT != D->getThisType()->getAs<PointerType>())) { |
1232 | LC = LC->getParent(); |
1233 | D = dyn_cast<CXXMethodDecl>(LC->getDecl()); |
1234 | } |
1235 | const StackFrameContext *STC = LC->getStackFrame(); |
1236 | assert(STC); |
1237 | return getSubRegion<CXXThisRegion>(PT, getStackArgumentsRegion(STC)); |
1238 | } |
1239 | |
1240 | const AllocaRegion* |
1241 | MemRegionManager::getAllocaRegion(const Expr *E, unsigned cnt, |
1242 | const LocationContext *LC) { |
1243 | const StackFrameContext *STC = LC->getStackFrame(); |
1244 | assert(STC); |
1245 | return getSubRegion<AllocaRegion>(E, cnt, getStackLocalsRegion(STC)); |
1246 | } |
1247 | |
1248 | const MemSpaceRegion *MemRegion::getMemorySpace() const { |
1249 | const MemRegion *R = this; |
1250 | const auto *SR = dyn_cast<SubRegion>(this); |
1251 | |
1252 | while (SR) { |
1253 | R = SR->getSuperRegion(); |
1254 | SR = dyn_cast<SubRegion>(R); |
1255 | } |
1256 | |
1257 | return dyn_cast<MemSpaceRegion>(R); |
1258 | } |
1259 | |
1260 | bool MemRegion::hasStackStorage() const { |
1261 | return isa<StackSpaceRegion>(getMemorySpace()); |
1262 | } |
1263 | |
1264 | bool MemRegion::hasStackNonParametersStorage() const { |
1265 | return isa<StackLocalsSpaceRegion>(getMemorySpace()); |
1266 | } |
1267 | |
1268 | bool MemRegion::hasStackParametersStorage() const { |
1269 | return isa<StackArgumentsSpaceRegion>(getMemorySpace()); |
1270 | } |
1271 | |
1272 | bool MemRegion::hasGlobalsOrParametersStorage() const { |
1273 | const MemSpaceRegion *MS = getMemorySpace(); |
1274 | return isa<StackArgumentsSpaceRegion>(MS) || |
1275 | isa<GlobalsSpaceRegion>(MS); |
1276 | } |
1277 | |
1278 | |
1279 | |
1280 | const MemRegion *MemRegion::getBaseRegion() const { |
1281 | const MemRegion *R = this; |
1282 | while (true) { |
1283 | switch (R->getKind()) { |
1284 | case MemRegion::ElementRegionKind: |
1285 | case MemRegion::FieldRegionKind: |
1286 | case MemRegion::ObjCIvarRegionKind: |
1287 | case MemRegion::CXXBaseObjectRegionKind: |
1288 | case MemRegion::CXXDerivedObjectRegionKind: |
1289 | R = cast<SubRegion>(R)->getSuperRegion(); |
1290 | continue; |
1291 | default: |
1292 | break; |
1293 | } |
1294 | break; |
1295 | } |
1296 | return R; |
1297 | } |
1298 | |
1299 | |
1300 | |
1301 | const MemRegion *MemRegion::getMostDerivedObjectRegion() const { |
1302 | const MemRegion *R = this; |
1303 | while (const auto *BR = dyn_cast<CXXBaseObjectRegion>(R)) |
1304 | R = BR->getSuperRegion(); |
1305 | return R; |
1306 | } |
1307 | |
1308 | bool MemRegion::isSubRegionOf(const MemRegion *) const { |
1309 | return false; |
1310 | } |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | |
1316 | const MemRegion *MemRegion::StripCasts(bool StripBaseAndDerivedCasts) const { |
1317 | const MemRegion *R = this; |
1318 | while (true) { |
1319 | switch (R->getKind()) { |
1320 | case ElementRegionKind: { |
1321 | const auto *ER = cast<ElementRegion>(R); |
1322 | if (!ER->getIndex().isZeroConstant()) |
1323 | return R; |
1324 | R = ER->getSuperRegion(); |
1325 | break; |
1326 | } |
1327 | case CXXBaseObjectRegionKind: |
1328 | case CXXDerivedObjectRegionKind: |
1329 | if (!StripBaseAndDerivedCasts) |
1330 | return R; |
1331 | R = cast<TypedValueRegion>(R)->getSuperRegion(); |
1332 | break; |
1333 | default: |
1334 | return R; |
1335 | } |
1336 | } |
1337 | } |
1338 | |
1339 | const SymbolicRegion *MemRegion::getSymbolicBase() const { |
1340 | const auto *SubR = dyn_cast<SubRegion>(this); |
1341 | |
1342 | while (SubR) { |
1343 | if (const auto *SymR = dyn_cast<SymbolicRegion>(SubR)) |
1344 | return SymR; |
1345 | SubR = dyn_cast<SubRegion>(SubR->getSuperRegion()); |
1346 | } |
1347 | return nullptr; |
1348 | } |
1349 | |
1350 | RegionRawOffset ElementRegion::getAsArrayOffset() const { |
1351 | int64_t offset = 0; |
1352 | const ElementRegion *ER = this; |
1353 | const MemRegion *superR = nullptr; |
1354 | ASTContext &C = getContext(); |
1355 | |
1356 | |
1357 | |
1358 | while (ER) { |
1359 | superR = ER->getSuperRegion(); |
1360 | |
1361 | |
1362 | SVal index = ER->getIndex(); |
1363 | if (auto CI = index.getAs<nonloc::ConcreteInt>()) { |
1364 | |
1365 | int64_t i = CI->getValue().getSExtValue(); |
1366 | |
1367 | if (i != 0) { |
1368 | QualType elemType = ER->getElementType(); |
1369 | |
1370 | |
1371 | if (elemType->isIncompleteType()) { |
1372 | superR = ER; |
1373 | break; |
1374 | } |
1375 | |
1376 | int64_t size = C.getTypeSizeInChars(elemType).getQuantity(); |
1377 | if (auto NewOffset = llvm::checkedMulAdd(i, size, offset)) { |
1378 | offset = *NewOffset; |
1379 | } else { |
1380 | LLVM_DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: " |
1381 | << "offset overflowing, returning unknown\n"); |
1382 | |
1383 | return nullptr; |
1384 | } |
1385 | } |
1386 | |
1387 | |
1388 | ER = dyn_cast<ElementRegion>(superR); |
1389 | continue; |
1390 | } |
1391 | |
1392 | return nullptr; |
1393 | } |
1394 | |
1395 | assert(superR && "super region cannot be NULL"); |
1396 | return RegionRawOffset(superR, CharUnits::fromQuantity(offset)); |
1397 | } |
1398 | |
1399 | |
1400 | static bool isImmediateBase(const CXXRecordDecl *Child, |
1401 | const CXXRecordDecl *Base) { |
1402 | assert(Child && "Child must not be null"); |
1403 | |
1404 | |
1405 | |
1406 | for (const auto &I : Child->bases()) { |
1407 | if (I.getType()->getAsCXXRecordDecl() == Base) |
1408 | return true; |
1409 | } |
1410 | |
1411 | return false; |
1412 | } |
1413 | |
1414 | static RegionOffset calculateOffset(const MemRegion *R) { |
1415 | const MemRegion *SymbolicOffsetBase = nullptr; |
1416 | int64_t Offset = 0; |
1417 | |
1418 | while (true) { |
| 4 | | Loop condition is true. Entering loop body | |
|
1419 | switch (R->getKind()) { |
| 5 | | Control jumps to 'case FieldRegionKind:' at line 1547 | |
|
1420 | case MemRegion::CodeSpaceRegionKind: |
1421 | case MemRegion::StackLocalsSpaceRegionKind: |
1422 | case MemRegion::StackArgumentsSpaceRegionKind: |
1423 | case MemRegion::HeapSpaceRegionKind: |
1424 | case MemRegion::UnknownSpaceRegionKind: |
1425 | case MemRegion::StaticGlobalSpaceRegionKind: |
1426 | case MemRegion::GlobalInternalSpaceRegionKind: |
1427 | case MemRegion::GlobalSystemSpaceRegionKind: |
1428 | case MemRegion::GlobalImmutableSpaceRegionKind: |
1429 | |
1430 | assert(Offset == 0 && !SymbolicOffsetBase); |
1431 | goto Finish; |
1432 | |
1433 | case MemRegion::FunctionCodeRegionKind: |
1434 | case MemRegion::BlockCodeRegionKind: |
1435 | case MemRegion::BlockDataRegionKind: |
1436 | |
1437 | |
1438 | if (Offset != 0) |
1439 | SymbolicOffsetBase = R; |
1440 | goto Finish; |
1441 | |
1442 | case MemRegion::SymbolicRegionKind: |
1443 | case MemRegion::AllocaRegionKind: |
1444 | case MemRegion::CompoundLiteralRegionKind: |
1445 | case MemRegion::CXXThisRegionKind: |
1446 | case MemRegion::StringRegionKind: |
1447 | case MemRegion::ObjCStringRegionKind: |
1448 | case MemRegion::NonParamVarRegionKind: |
1449 | case MemRegion::ParamVarRegionKind: |
1450 | case MemRegion::CXXTempObjectRegionKind: |
1451 | |
1452 | goto Finish; |
1453 | |
1454 | case MemRegion::ObjCIvarRegionKind: |
1455 | |
1456 | |
1457 | |
1458 | |
1459 | |
1460 | goto Finish; |
1461 | |
1462 | case MemRegion::CXXBaseObjectRegionKind: { |
1463 | const auto *BOR = cast<CXXBaseObjectRegion>(R); |
1464 | R = BOR->getSuperRegion(); |
1465 | |
1466 | QualType Ty; |
1467 | bool RootIsSymbolic = false; |
1468 | if (const auto *TVR = dyn_cast<TypedValueRegion>(R)) { |
1469 | Ty = TVR->getDesugaredValueType(R->getContext()); |
1470 | } else if (const auto *SR = dyn_cast<SymbolicRegion>(R)) { |
1471 | |
1472 | |
1473 | |
1474 | Ty = SR->getSymbol()->getType()->getPointeeType(); |
1475 | RootIsSymbolic = true; |
1476 | } |
1477 | |
1478 | const CXXRecordDecl *Child = Ty->getAsCXXRecordDecl(); |
1479 | if (!Child) { |
1480 | |
1481 | SymbolicOffsetBase = R; |
1482 | } else { |
1483 | if (RootIsSymbolic) { |
1484 | |
1485 | |
1486 | |
1487 | if (BOR->isVirtual()) { |
1488 | if (!Child->isVirtuallyDerivedFrom(BOR->getDecl())) |
1489 | SymbolicOffsetBase = R; |
1490 | } else { |
1491 | if (!isImmediateBase(Child, BOR->getDecl())) |
1492 | SymbolicOffsetBase = R; |
1493 | } |
1494 | } |
1495 | } |
1496 | |
1497 | |
1498 | |
1499 | if (SymbolicOffsetBase) |
1500 | continue; |
1501 | |
1502 | CharUnits BaseOffset; |
1503 | const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(Child); |
1504 | if (BOR->isVirtual()) |
1505 | BaseOffset = Layout.getVBaseClassOffset(BOR->getDecl()); |
1506 | else |
1507 | BaseOffset = Layout.getBaseClassOffset(BOR->getDecl()); |
1508 | |
1509 | |
1510 | Offset += BaseOffset.getQuantity() * R->getContext().getCharWidth(); |
1511 | break; |
1512 | } |
1513 | |
1514 | case MemRegion::CXXDerivedObjectRegionKind: { |
1515 | |
1516 | goto Finish; |
1517 | } |
1518 | |
1519 | case MemRegion::ElementRegionKind: { |
1520 | const auto *ER = cast<ElementRegion>(R); |
1521 | R = ER->getSuperRegion(); |
1522 | |
1523 | QualType EleTy = ER->getValueType(); |
1524 | if (EleTy->isIncompleteType()) { |
1525 | |
1526 | SymbolicOffsetBase = R; |
1527 | continue; |
1528 | } |
1529 | |
1530 | SVal Index = ER->getIndex(); |
1531 | if (Optional<nonloc::ConcreteInt> CI = |
1532 | Index.getAs<nonloc::ConcreteInt>()) { |
1533 | |
1534 | |
1535 | if (SymbolicOffsetBase) |
1536 | continue; |
1537 | |
1538 | int64_t i = CI->getValue().getSExtValue(); |
1539 | |
1540 | Offset += i * R->getContext().getTypeSize(EleTy); |
1541 | } else { |
1542 | |
1543 | SymbolicOffsetBase = R; |
1544 | } |
1545 | break; |
1546 | } |
1547 | case MemRegion::FieldRegionKind: { |
1548 | const auto *FR = cast<FieldRegion>(R); |
| |
1549 | R = FR->getSuperRegion(); |
| |
1550 | assert(R); |
1551 | |
1552 | const RecordDecl *RD = FR->getDecl()->getParent(); |
1553 | if (RD->isUnion() || !RD->isCompleteDefinition()) { |
| 8 | | Calling 'TagDecl::isUnion' | |
|
| 11 | | Returning from 'TagDecl::isUnion' | |
|
1554 | |
1555 | |
1556 | |
1557 | |
1558 | |
1559 | SymbolicOffsetBase = R; |
1560 | } |
1561 | |
1562 | |
1563 | |
1564 | if (SymbolicOffsetBase) |
| 12 | | Assuming 'SymbolicOffsetBase' is null | |
|
| |
1565 | continue; |
1566 | |
1567 | |
1568 | unsigned idx = 0; |
1569 | for (RecordDecl::field_iterator FI = RD->field_begin(), |
| 14 | | Loop condition is false. Execution continues on line 1574 | |
|
1570 | FE = RD->field_end(); FI != FE; ++FI, ++idx) { |
1571 | if (FR->getDecl() == *FI) |
1572 | break; |
1573 | } |
1574 | const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(RD); |
| 15 | | Called C++ object pointer is null |
|
1575 | |
1576 | Offset += Layout.getFieldOffset(idx); |
1577 | break; |
1578 | } |
1579 | } |
1580 | } |
1581 | |
1582 | Finish: |
1583 | if (SymbolicOffsetBase) |
1584 | return RegionOffset(SymbolicOffsetBase, RegionOffset::Symbolic); |
1585 | return RegionOffset(R, Offset); |
1586 | } |
1587 | |
1588 | RegionOffset MemRegion::getAsOffset() const { |
1589 | if (!cachedOffset) |
| 1 | Assuming the condition is true | |
|
| |
1590 | cachedOffset = calculateOffset(this); |
| 3 | | Calling 'calculateOffset' | |
|
1591 | return *cachedOffset; |
1592 | } |
1593 | |
1594 | |
1595 | |
1596 | |
1597 | |
1598 | std::pair<const VarRegion *, const VarRegion *> |
1599 | BlockDataRegion::getCaptureRegions(const VarDecl *VD) { |
1600 | MemRegionManager &MemMgr = getMemRegionManager(); |
1601 | const VarRegion *VR = nullptr; |
1602 | const VarRegion *OriginalVR = nullptr; |
1603 | |
1604 | if (!VD->hasAttr<BlocksAttr>() && VD->hasLocalStorage()) { |
1605 | VR = MemMgr.getNonParamVarRegion(VD, this); |
1606 | OriginalVR = MemMgr.getVarRegion(VD, LC); |
1607 | } |
1608 | else { |
1609 | if (LC) { |
1610 | VR = MemMgr.getVarRegion(VD, LC); |
1611 | OriginalVR = VR; |
1612 | } |
1613 | else { |
1614 | VR = MemMgr.getNonParamVarRegion(VD, MemMgr.getUnknownRegion()); |
1615 | OriginalVR = MemMgr.getVarRegion(VD, LC); |
1616 | } |
1617 | } |
1618 | return std::make_pair(VR, OriginalVR); |
1619 | } |
1620 | |
1621 | void BlockDataRegion::LazyInitializeReferencedVars() { |
1622 | if (ReferencedVars) |
1623 | return; |
1624 | |
1625 | AnalysisDeclContext *AC = getCodeRegion()->getAnalysisDeclContext(); |
1626 | const auto &ReferencedBlockVars = AC->getReferencedBlockVars(BC->getDecl()); |
1627 | auto NumBlockVars = |
1628 | std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end()); |
1629 | |
1630 | if (NumBlockVars == 0) { |
1631 | ReferencedVars = (void*) 0x1; |
1632 | return; |
1633 | } |
1634 | |
1635 | MemRegionManager &MemMgr = getMemRegionManager(); |
1636 | llvm::BumpPtrAllocator &A = MemMgr.getAllocator(); |
1637 | BumpVectorContext BC(A); |
1638 | |
1639 | using VarVec = BumpVector<const MemRegion *>; |
1640 | |
1641 | auto *BV = A.Allocate<VarVec>(); |
1642 | new (BV) VarVec(BC, NumBlockVars); |
1643 | auto *BVOriginal = A.Allocate<VarVec>(); |
1644 | new (BVOriginal) VarVec(BC, NumBlockVars); |
1645 | |
1646 | for (const auto *VD : ReferencedBlockVars) { |
1647 | const VarRegion *VR = nullptr; |
1648 | const VarRegion *OriginalVR = nullptr; |
1649 | std::tie(VR, OriginalVR) = getCaptureRegions(VD); |
1650 | assert(VR); |
1651 | assert(OriginalVR); |
1652 | BV->push_back(VR, BC); |
1653 | BVOriginal->push_back(OriginalVR, BC); |
1654 | } |
1655 | |
1656 | ReferencedVars = BV; |
1657 | OriginalVars = BVOriginal; |
1658 | } |
1659 | |
1660 | BlockDataRegion::referenced_vars_iterator |
1661 | BlockDataRegion::referenced_vars_begin() const { |
1662 | const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars(); |
1663 | |
1664 | auto *Vec = static_cast<BumpVector<const MemRegion *> *>(ReferencedVars); |
1665 | |
1666 | if (Vec == (void*) 0x1) |
1667 | return BlockDataRegion::referenced_vars_iterator(nullptr, nullptr); |
1668 | |
1669 | auto *VecOriginal = |
1670 | static_cast<BumpVector<const MemRegion *> *>(OriginalVars); |
1671 | |
1672 | return BlockDataRegion::referenced_vars_iterator(Vec->begin(), |
1673 | VecOriginal->begin()); |
1674 | } |
1675 | |
1676 | BlockDataRegion::referenced_vars_iterator |
1677 | BlockDataRegion::referenced_vars_end() const { |
1678 | const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars(); |
1679 | |
1680 | auto *Vec = static_cast<BumpVector<const MemRegion *> *>(ReferencedVars); |
1681 | |
1682 | if (Vec == (void*) 0x1) |
1683 | return BlockDataRegion::referenced_vars_iterator(nullptr, nullptr); |
1684 | |
1685 | auto *VecOriginal = |
1686 | static_cast<BumpVector<const MemRegion *> *>(OriginalVars); |
1687 | |
1688 | return BlockDataRegion::referenced_vars_iterator(Vec->end(), |
1689 | VecOriginal->end()); |
1690 | } |
1691 | |
1692 | const VarRegion *BlockDataRegion::getOriginalRegion(const VarRegion *R) const { |
1693 | for (referenced_vars_iterator I = referenced_vars_begin(), |
1694 | E = referenced_vars_end(); |
1695 | I != E; ++I) { |
1696 | if (I.getCapturedRegion() == R) |
1697 | return I.getOriginalRegion(); |
1698 | } |
1699 | return nullptr; |
1700 | } |
1701 | |
1702 | |
1703 | |
1704 | |
1705 | |
1706 | void RegionAndSymbolInvalidationTraits::setTrait(SymbolRef Sym, |
1707 | InvalidationKinds IK) { |
1708 | SymTraitsMap[Sym] |= IK; |
1709 | } |
1710 | |
1711 | void RegionAndSymbolInvalidationTraits::setTrait(const MemRegion *MR, |
1712 | InvalidationKinds IK) { |
1713 | assert(MR); |
1714 | if (const auto *SR = dyn_cast<SymbolicRegion>(MR)) |
1715 | setTrait(SR->getSymbol(), IK); |
1716 | else |
1717 | MRTraitsMap[MR] |= IK; |
1718 | } |
1719 | |
1720 | bool RegionAndSymbolInvalidationTraits::hasTrait(SymbolRef Sym, |
1721 | InvalidationKinds IK) const { |
1722 | const_symbol_iterator I = SymTraitsMap.find(Sym); |
1723 | if (I != SymTraitsMap.end()) |
1724 | return I->second & IK; |
1725 | |
1726 | return false; |
1727 | } |
1728 | |
1729 | bool RegionAndSymbolInvalidationTraits::hasTrait(const MemRegion *MR, |
1730 | InvalidationKinds IK) const { |
1731 | if (!MR) |
1732 | return false; |
1733 | |
1734 | if (const auto *SR = dyn_cast<SymbolicRegion>(MR)) |
1735 | return hasTrait(SR->getSymbol(), IK); |
1736 | |
1737 | const_region_iterator I = MRTraitsMap.find(MR); |
1738 | if (I != MRTraitsMap.end()) |
1739 | return I->second & IK; |
1740 | |
1741 | return false; |
1742 | } |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_AST_DECL_H |
14 | #define LLVM_CLANG_AST_DECL_H |
15 | |
16 | #include "clang/AST/APValue.h" |
17 | #include "clang/AST/ASTContextAllocate.h" |
18 | #include "clang/AST/DeclAccessPair.h" |
19 | #include "clang/AST/DeclBase.h" |
20 | #include "clang/AST/DeclarationName.h" |
21 | #include "clang/AST/ExternalASTSource.h" |
22 | #include "clang/AST/NestedNameSpecifier.h" |
23 | #include "clang/AST/Redeclarable.h" |
24 | #include "clang/AST/Type.h" |
25 | #include "clang/Basic/AddressSpaces.h" |
26 | #include "clang/Basic/Diagnostic.h" |
27 | #include "clang/Basic/IdentifierTable.h" |
28 | #include "clang/Basic/LLVM.h" |
29 | #include "clang/Basic/Linkage.h" |
30 | #include "clang/Basic/OperatorKinds.h" |
31 | #include "clang/Basic/PartialDiagnostic.h" |
32 | #include "clang/Basic/PragmaKinds.h" |
33 | #include "clang/Basic/SourceLocation.h" |
34 | #include "clang/Basic/Specifiers.h" |
35 | #include "clang/Basic/Visibility.h" |
36 | #include "llvm/ADT/APSInt.h" |
37 | #include "llvm/ADT/ArrayRef.h" |
38 | #include "llvm/ADT/Optional.h" |
39 | #include "llvm/ADT/PointerIntPair.h" |
40 | #include "llvm/ADT/PointerUnion.h" |
41 | #include "llvm/ADT/StringRef.h" |
42 | #include "llvm/ADT/iterator_range.h" |
43 | #include "llvm/Support/Casting.h" |
44 | #include "llvm/Support/Compiler.h" |
45 | #include "llvm/Support/TrailingObjects.h" |
46 | #include <cassert> |
47 | #include <cstddef> |
48 | #include <cstdint> |
49 | #include <string> |
50 | #include <utility> |
51 | |
52 | namespace clang { |
53 | |
54 | class ASTContext; |
55 | struct ASTTemplateArgumentListInfo; |
56 | class Attr; |
57 | class CompoundStmt; |
58 | class DependentFunctionTemplateSpecializationInfo; |
59 | class EnumDecl; |
60 | class Expr; |
61 | class FunctionTemplateDecl; |
62 | class FunctionTemplateSpecializationInfo; |
63 | class FunctionTypeLoc; |
64 | class LabelStmt; |
65 | class MemberSpecializationInfo; |
66 | class Module; |
67 | class NamespaceDecl; |
68 | class ParmVarDecl; |
69 | class RecordDecl; |
70 | class Stmt; |
71 | class StringLiteral; |
72 | class TagDecl; |
73 | class TemplateArgumentList; |
74 | class TemplateArgumentListInfo; |
75 | class TemplateParameterList; |
76 | class TypeAliasTemplateDecl; |
77 | class TypeLoc; |
78 | class UnresolvedSetImpl; |
79 | class VarTemplateDecl; |
80 | |
81 | |
82 | class TranslationUnitDecl : public Decl, |
83 | public DeclContext, |
84 | public Redeclarable<TranslationUnitDecl> { |
85 | using redeclarable_base = Redeclarable<TranslationUnitDecl>; |
86 | |
87 | TranslationUnitDecl *getNextRedeclarationImpl() override { |
88 | return getNextRedeclaration(); |
89 | } |
90 | |
91 | TranslationUnitDecl *getPreviousDeclImpl() override { |
92 | return getPreviousDecl(); |
93 | } |
94 | |
95 | TranslationUnitDecl *getMostRecentDeclImpl() override { |
96 | return getMostRecentDecl(); |
97 | } |
98 | |
99 | ASTContext &Ctx; |
100 | |
101 | |
102 | |
103 | NamespaceDecl *AnonymousNamespace = nullptr; |
104 | |
105 | explicit TranslationUnitDecl(ASTContext &ctx); |
106 | |
107 | virtual void anchor(); |
108 | |
109 | public: |
110 | using redecl_range = redeclarable_base::redecl_range; |
111 | using redecl_iterator = redeclarable_base::redecl_iterator; |
112 | |
113 | using redeclarable_base::getMostRecentDecl; |
114 | using redeclarable_base::getPreviousDecl; |
115 | using redeclarable_base::isFirstDecl; |
116 | using redeclarable_base::redecls; |
117 | using redeclarable_base::redecls_begin; |
118 | using redeclarable_base::redecls_end; |
119 | |
120 | ASTContext &getASTContext() const { return Ctx; } |
121 | |
122 | NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; } |
123 | void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; } |
124 | |
125 | static TranslationUnitDecl *Create(ASTContext &C); |
126 | |
127 | |
128 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
129 | static bool classofKind(Kind K) { return K == TranslationUnit; } |
130 | static DeclContext *castToDeclContext(const TranslationUnitDecl *D) { |
131 | return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D)); |
132 | } |
133 | static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { |
134 | return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC)); |
135 | } |
136 | }; |
137 | |
138 | |
139 | |
140 | class PragmaCommentDecl final |
141 | : public Decl, |
142 | private llvm::TrailingObjects<PragmaCommentDecl, char> { |
143 | friend class ASTDeclReader; |
144 | friend class ASTDeclWriter; |
145 | friend TrailingObjects; |
146 | |
147 | PragmaMSCommentKind CommentKind; |
148 | |
149 | PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc, |
150 | PragmaMSCommentKind CommentKind) |
151 | : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {} |
152 | |
153 | virtual void anchor(); |
154 | |
155 | public: |
156 | static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC, |
157 | SourceLocation CommentLoc, |
158 | PragmaMSCommentKind CommentKind, |
159 | StringRef Arg); |
160 | static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
161 | unsigned ArgSize); |
162 | |
163 | PragmaMSCommentKind getCommentKind() const { return CommentKind; } |
164 | |
165 | StringRef getArg() const { return getTrailingObjects<char>(); } |
166 | |
167 | |
168 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
169 | static bool classofKind(Kind K) { return K == PragmaComment; } |
170 | }; |
171 | |
172 | |
173 | |
174 | class PragmaDetectMismatchDecl final |
175 | : public Decl, |
176 | private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> { |
177 | friend class ASTDeclReader; |
178 | friend class ASTDeclWriter; |
179 | friend TrailingObjects; |
180 | |
181 | size_t ValueStart; |
182 | |
183 | PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc, |
184 | size_t ValueStart) |
185 | : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {} |
186 | |
187 | virtual void anchor(); |
188 | |
189 | public: |
190 | static PragmaDetectMismatchDecl *Create(const ASTContext &C, |
191 | TranslationUnitDecl *DC, |
192 | SourceLocation Loc, StringRef Name, |
193 | StringRef Value); |
194 | static PragmaDetectMismatchDecl * |
195 | CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize); |
196 | |
197 | StringRef getName() const { return getTrailingObjects<char>(); } |
198 | StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; } |
199 | |
200 | |
201 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
202 | static bool classofKind(Kind K) { return K == PragmaDetectMismatch; } |
203 | }; |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | class ExternCContextDecl : public Decl, public DeclContext { |
223 | explicit ExternCContextDecl(TranslationUnitDecl *TU) |
224 | : Decl(ExternCContext, TU, SourceLocation()), |
225 | DeclContext(ExternCContext) {} |
226 | |
227 | virtual void anchor(); |
228 | |
229 | public: |
230 | static ExternCContextDecl *Create(const ASTContext &C, |
231 | TranslationUnitDecl *TU); |
232 | |
233 | |
234 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
235 | static bool classofKind(Kind K) { return K == ExternCContext; } |
236 | static DeclContext *castToDeclContext(const ExternCContextDecl *D) { |
237 | return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D)); |
238 | } |
239 | static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) { |
240 | return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC)); |
241 | } |
242 | }; |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | class NamedDecl : public Decl { |
250 | |
251 | |
252 | |
253 | DeclarationName Name; |
254 | |
255 | virtual void anchor(); |
256 | |
257 | private: |
258 | NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY; |
259 | |
260 | protected: |
261 | NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) |
262 | : Decl(DK, DC, L), Name(N) {} |
263 | |
264 | public: |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); } |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | StringRef getName() const { |
277 | assert(Name.isIdentifier() && "Name is not a simple identifier"); |
278 | return getIdentifier() ? getIdentifier()->getName() : ""; |
279 | } |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | std::string getNameAsString() const { return Name.getAsString(); } |
293 | |
294 | |
295 | |
296 | virtual void printName(raw_ostream &os) const; |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | |
309 | |
310 | |
311 | |
312 | |
313 | DeclarationName getDeclName() const { return Name; } |
314 | |
315 | |
316 | void setDeclName(DeclarationName N) { Name = N; } |
317 | |
318 | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | |
325 | |
326 | void printQualifiedName(raw_ostream &OS) const; |
327 | void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const; |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | void printNestedNameSpecifier(raw_ostream &OS) const; |
334 | void printNestedNameSpecifier(raw_ostream &OS, |
335 | const PrintingPolicy &Policy) const; |
336 | |
337 | |
338 | std::string getQualifiedNameAsString() const; |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | virtual void getNameForDiagnostic(raw_ostream &OS, |
347 | const PrintingPolicy &Policy, |
348 | bool Qualified) const; |
349 | |
350 | |
351 | |
352 | |
353 | |
354 | |
355 | |
356 | |
357 | |
358 | |
359 | |
360 | bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const; |
361 | |
362 | |
363 | bool hasLinkage() const; |
364 | |
365 | using Decl::isModulePrivate; |
366 | using Decl::setModulePrivate; |
367 | |
368 | |
369 | bool isCXXClassMember() const { |
370 | const DeclContext *DC = getDeclContext(); |
371 | |
372 | |
373 | |
374 | |
375 | if (isa<EnumDecl>(DC)) |
376 | DC = DC->getRedeclContext(); |
377 | |
378 | return DC->isRecord(); |
379 | } |
380 | |
381 | |
382 | |
383 | bool isCXXInstanceMember() const; |
384 | |
385 | |
386 | |
387 | ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const; |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | Linkage getLinkageInternal() const; |
395 | |
396 | |
397 | |
398 | Linkage getFormalLinkage() const { |
399 | return clang::getFormalLinkage(getLinkageInternal()); |
400 | } |
401 | |
402 | |
403 | bool hasExternalFormalLinkage() const { |
404 | return isExternalFormalLinkage(getLinkageInternal()); |
405 | } |
406 | |
407 | bool isExternallyVisible() const { |
408 | return clang::isExternallyVisible(getLinkageInternal()); |
409 | } |
410 | |
411 | |
412 | |
413 | bool isExternallyDeclarable() const { |
414 | return isExternallyVisible() && !getOwningModuleForLinkage(); |
415 | } |
416 | |
417 | |
418 | Visibility getVisibility() const { |
419 | return getLinkageAndVisibility().getVisibility(); |
420 | } |
421 | |
422 | |
423 | LinkageInfo getLinkageAndVisibility() const; |
424 | |
425 | |
426 | enum ExplicitVisibilityKind { |
427 | |
428 | |
429 | |
430 | VisibilityForType, |
431 | |
432 | |
433 | |
434 | |
435 | VisibilityForValue |
436 | }; |
437 | |
438 | |
439 | |
440 | Optional<Visibility> |
441 | getExplicitVisibility(ExplicitVisibilityKind kind) const; |
442 | |
443 | |
444 | |
445 | bool isLinkageValid() const; |
446 | |
447 | |
448 | |
449 | |
450 | |
451 | |
452 | |
453 | bool hasLinkageBeenComputed() const { |
454 | return hasCachedLinkage(); |
455 | } |
456 | |
457 | |
458 | |
459 | NamedDecl *getUnderlyingDecl() { |
460 | |
461 | if (this->getKind() != UsingShadow && |
462 | this->getKind() != ConstructorUsingShadow && |
463 | this->getKind() != ObjCCompatibleAlias && |
464 | this->getKind() != NamespaceAlias) |
465 | return this; |
466 | |
467 | return getUnderlyingDeclImpl(); |
468 | } |
469 | const NamedDecl *getUnderlyingDecl() const { |
470 | return const_cast<NamedDecl*>(this)->getUnderlyingDecl(); |
471 | } |
472 | |
473 | NamedDecl *getMostRecentDecl() { |
474 | return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl()); |
475 | } |
476 | const NamedDecl *getMostRecentDecl() const { |
477 | return const_cast<NamedDecl*>(this)->getMostRecentDecl(); |
478 | } |
479 | |
480 | ObjCStringFormatFamily getObjCFStringFormattingFamily() const; |
481 | |
482 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
483 | static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; } |
484 | }; |
485 | |
486 | inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) { |
487 | ND.printName(OS); |
488 | return OS; |
489 | } |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | class LabelDecl : public NamedDecl { |
497 | LabelStmt *TheStmt; |
498 | StringRef MSAsmName; |
499 | bool MSAsmNameResolved = false; |
500 | |
501 | |
502 | |
503 | |
504 | SourceLocation LocStart; |
505 | |
506 | LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II, |
507 | LabelStmt *S, SourceLocation StartL) |
508 | : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {} |
509 | |
510 | void anchor() override; |
511 | |
512 | public: |
513 | static LabelDecl *Create(ASTContext &C, DeclContext *DC, |
514 | SourceLocation IdentL, IdentifierInfo *II); |
515 | static LabelDecl *Create(ASTContext &C, DeclContext *DC, |
516 | SourceLocation IdentL, IdentifierInfo *II, |
517 | SourceLocation GnuLabelL); |
518 | static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
519 | |
520 | LabelStmt *getStmt() const { return TheStmt; } |
521 | void setStmt(LabelStmt *T) { TheStmt = T; } |
522 | |
523 | bool isGnuLocal() const { return LocStart != getLocation(); } |
524 | void setLocStart(SourceLocation L) { LocStart = L; } |
525 | |
526 | SourceRange getSourceRange() const override LLVM_READONLY { |
527 | return SourceRange(LocStart, getLocation()); |
528 | } |
529 | |
530 | bool isMSAsmLabel() const { return !MSAsmName.empty(); } |
531 | bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; } |
532 | void setMSAsmLabel(StringRef Name); |
533 | StringRef getMSAsmLabel() const { return MSAsmName; } |
534 | void setMSAsmLabelResolved() { MSAsmNameResolved = true; } |
535 | |
536 | |
537 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
538 | static bool classofKind(Kind K) { return K == Label; } |
539 | }; |
540 | |
541 | |
542 | class NamespaceDecl : public NamedDecl, public DeclContext, |
543 | public Redeclarable<NamespaceDecl> |
544 | { |
545 | |
546 | |
547 | SourceLocation LocStart; |
548 | |
549 | |
550 | SourceLocation RBraceLoc; |
551 | |
552 | |
553 | |
554 | |
555 | |
556 | llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline; |
557 | |
558 | NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, |
559 | SourceLocation StartLoc, SourceLocation IdLoc, |
560 | IdentifierInfo *Id, NamespaceDecl *PrevDecl); |
561 | |
562 | using redeclarable_base = Redeclarable<NamespaceDecl>; |
563 | |
564 | NamespaceDecl *getNextRedeclarationImpl() override; |
565 | NamespaceDecl *getPreviousDeclImpl() override; |
566 | NamespaceDecl *getMostRecentDeclImpl() override; |
567 | |
568 | public: |
569 | friend class ASTDeclReader; |
570 | friend class ASTDeclWriter; |
571 | |
572 | static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, |
573 | bool Inline, SourceLocation StartLoc, |
574 | SourceLocation IdLoc, IdentifierInfo *Id, |
575 | NamespaceDecl *PrevDecl); |
576 | |
577 | static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
578 | |
579 | using redecl_range = redeclarable_base::redecl_range; |
580 | using redecl_iterator = redeclarable_base::redecl_iterator; |
581 | |
582 | using redeclarable_base::redecls_begin; |
583 | using redeclarable_base::redecls_end; |
584 | using redeclarable_base::redecls; |
585 | using redeclarable_base::getPreviousDecl; |
586 | using redeclarable_base::getMostRecentDecl; |
587 | using redeclarable_base::isFirstDecl; |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | bool isAnonymousNamespace() const { |
599 | return !getIdentifier(); |
600 | } |
601 | |
602 | |
603 | bool isInline() const { |
604 | return AnonOrFirstNamespaceAndInline.getInt(); |
605 | } |
606 | |
607 | |
608 | void setInline(bool Inline) { |
609 | AnonOrFirstNamespaceAndInline.setInt(Inline); |
610 | } |
611 | |
612 | |
613 | bool isRedundantInlineQualifierFor(DeclarationName Name) const { |
614 | if (!isInline()) |
615 | return false; |
616 | auto X = lookup(Name); |
617 | |
618 | |
619 | auto Y = getParent()->getNonTransparentContext()->lookup(Name); |
620 | return std::distance(X.begin(), X.end()) == |
621 | std::distance(Y.begin(), Y.end()); |
622 | } |
623 | |
624 | |
625 | NamespaceDecl *getOriginalNamespace(); |
626 | |
627 | |
628 | const NamespaceDecl *getOriginalNamespace() const; |
629 | |
630 | |
631 | |
632 | |
633 | bool isOriginalNamespace() const; |
634 | |
635 | |
636 | |
637 | NamespaceDecl *getAnonymousNamespace() const { |
638 | return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer(); |
639 | } |
640 | |
641 | void setAnonymousNamespace(NamespaceDecl *D) { |
642 | getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D); |
643 | } |
644 | |
645 | |
646 | NamespaceDecl *getCanonicalDecl() override { |
647 | return getOriginalNamespace(); |
648 | } |
649 | const NamespaceDecl *getCanonicalDecl() const { |
650 | return getOriginalNamespace(); |
651 | } |
652 | |
653 | SourceRange getSourceRange() const override LLVM_READONLY { |
654 | return SourceRange(LocStart, RBraceLoc); |
655 | } |
656 | |
657 | SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; } |
658 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
659 | void setLocStart(SourceLocation L) { LocStart = L; } |
660 | void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } |
661 | |
662 | |
663 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
664 | static bool classofKind(Kind K) { return K == Namespace; } |
665 | static DeclContext *castToDeclContext(const NamespaceDecl *D) { |
666 | return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D)); |
667 | } |
668 | static NamespaceDecl *castFromDeclContext(const DeclContext *DC) { |
669 | return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC)); |
670 | } |
671 | }; |
672 | |
673 | |
674 | |
675 | |
676 | class ValueDecl : public NamedDecl { |
677 | QualType DeclType; |
678 | |
679 | void anchor() override; |
680 | |
681 | protected: |
682 | ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, |
683 | DeclarationName N, QualType T) |
684 | : NamedDecl(DK, DC, L, N), DeclType(T) {} |
685 | |
686 | public: |
687 | QualType getType() const { return DeclType; } |
688 | void setType(QualType newType) { DeclType = newType; } |
689 | |
690 | |
691 | |
692 | bool isWeak() const; |
693 | |
694 | |
695 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
696 | static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; } |
697 | }; |
698 | |
699 | |
700 | |
701 | struct QualifierInfo { |
702 | NestedNameSpecifierLoc QualifierLoc; |
703 | |
704 | |
705 | |
706 | |
707 | |
708 | unsigned NumTemplParamLists = 0; |
709 | |
710 | |
711 | |
712 | |
713 | |
714 | |
715 | TemplateParameterList** TemplParamLists = nullptr; |
716 | |
717 | QualifierInfo() = default; |
718 | QualifierInfo(const QualifierInfo &) = delete; |
719 | QualifierInfo& operator=(const QualifierInfo &) = delete; |
720 | |
721 | |
722 | void setTemplateParameterListsInfo(ASTContext &Context, |
723 | ArrayRef<TemplateParameterList *> TPLists); |
724 | }; |
725 | |
726 | |
727 | |
728 | class DeclaratorDecl : public ValueDecl { |
729 | |
730 | |
731 | |
732 | struct ExtInfo : public QualifierInfo { |
733 | TypeSourceInfo *TInfo; |
734 | Expr *TrailingRequiresClause = nullptr; |
735 | }; |
736 | |
737 | llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo; |
738 | |
739 | |
740 | |
741 | SourceLocation InnerLocStart; |
742 | |
743 | bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); } |
744 | ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); } |
745 | const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); } |
746 | |
747 | protected: |
748 | DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, |
749 | DeclarationName N, QualType T, TypeSourceInfo *TInfo, |
750 | SourceLocation StartL) |
751 | : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {} |
752 | |
753 | public: |
754 | friend class ASTDeclReader; |
755 | friend class ASTDeclWriter; |
756 | |
757 | TypeSourceInfo *getTypeSourceInfo() const { |
758 | return hasExtInfo() |
759 | ? getExtInfo()->TInfo |
760 | : DeclInfo.get<TypeSourceInfo*>(); |
761 | } |
762 | |
763 | void setTypeSourceInfo(TypeSourceInfo *TI) { |
764 | if (hasExtInfo()) |
765 | getExtInfo()->TInfo = TI; |
766 | else |
767 | DeclInfo = TI; |
768 | } |
769 | |
770 | |
771 | SourceLocation getInnerLocStart() const { return InnerLocStart; } |
772 | void setInnerLocStart(SourceLocation L) { InnerLocStart = L; } |
773 | |
774 | |
775 | |
776 | SourceLocation getOuterLocStart() const; |
777 | |
778 | SourceRange getSourceRange() const override LLVM_READONLY; |
779 | |
780 | SourceLocation getBeginLoc() const LLVM_READONLY { |
781 | return getOuterLocStart(); |
782 | } |
783 | |
784 | |
785 | |
786 | NestedNameSpecifier *getQualifier() const { |
787 | return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() |
788 | : nullptr; |
789 | } |
790 | |
791 | |
792 | |
793 | |
794 | NestedNameSpecifierLoc getQualifierLoc() const { |
795 | return hasExtInfo() ? getExtInfo()->QualifierLoc |
796 | : NestedNameSpecifierLoc(); |
797 | } |
798 | |
799 | void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); |
800 | |
801 | |
802 | |
803 | |
804 | Expr *getTrailingRequiresClause() { |
805 | return hasExtInfo() ? getExtInfo()->TrailingRequiresClause |
806 | : nullptr; |
807 | } |
808 | |
809 | const Expr *getTrailingRequiresClause() const { |
810 | return hasExtInfo() ? getExtInfo()->TrailingRequiresClause |
811 | : nullptr; |
812 | } |
813 | |
814 | void setTrailingRequiresClause(Expr *TrailingRequiresClause); |
815 | |
816 | unsigned getNumTemplateParameterLists() const { |
817 | return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; |
818 | } |
819 | |
820 | TemplateParameterList *getTemplateParameterList(unsigned index) const { |
821 | assert(index < getNumTemplateParameterLists()); |
822 | return getExtInfo()->TemplParamLists[index]; |
823 | } |
824 | |
825 | void setTemplateParameterListsInfo(ASTContext &Context, |
826 | ArrayRef<TemplateParameterList *> TPLists); |
827 | |
828 | SourceLocation getTypeSpecStartLoc() const; |
829 | SourceLocation getTypeSpecEndLoc() const; |
830 | |
831 | |
832 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
833 | static bool classofKind(Kind K) { |
834 | return K >= firstDeclarator && K <= lastDeclarator; |
835 | } |
836 | }; |
837 | |
838 | |
839 | |
840 | |
841 | struct EvaluatedStmt { |
842 | |
843 | bool WasEvaluated : 1; |
844 | |
845 | |
846 | bool IsEvaluating : 1; |
847 | |
848 | |
849 | |
850 | |
851 | |
852 | bool HasConstantInitialization : 1; |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | bool HasConstantDestruction : 1; |
860 | |
861 | |
862 | |
863 | bool HasICEInit : 1; |
864 | bool CheckedForICEInit : 1; |
865 | |
866 | Stmt *Value; |
867 | APValue Evaluated; |
868 | |
869 | EvaluatedStmt() |
870 | : WasEvaluated(false), IsEvaluating(false), |
871 | HasConstantInitialization(false), HasConstantDestruction(false), |
872 | HasICEInit(false), CheckedForICEInit(false) {} |
873 | }; |
874 | |
875 | |
876 | class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { |
877 | public: |
878 | |
879 | enum InitializationStyle { |
880 | |
881 | CInit, |
882 | |
883 | |
884 | CallInit, |
885 | |
886 | |
887 | ListInit |
888 | }; |
889 | |
890 | |
891 | enum TLSKind { |
892 | |
893 | TLS_None, |
894 | |
895 | |
896 | TLS_Static, |
897 | |
898 | |
899 | TLS_Dynamic |
900 | }; |
901 | |
902 | |
903 | |
904 | |
905 | static const char *getStorageClassSpecifierString(StorageClass SC); |
906 | |
907 | protected: |
908 | |
909 | |
910 | |
911 | |
912 | |
913 | |
914 | |
915 | using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>; |
916 | |
917 | |
918 | |
919 | mutable InitType Init; |
920 | |
921 | private: |
922 | friend class ASTDeclReader; |
923 | friend class ASTNodeImporter; |
924 | friend class StmtIteratorBase; |
925 | |
926 | class VarDeclBitfields { |
927 | friend class ASTDeclReader; |
928 | friend class VarDecl; |
929 | |
930 | unsigned SClass : 3; |
931 | unsigned TSCSpec : 2; |
932 | unsigned InitStyle : 2; |
933 | |
934 | |
935 | |
936 | unsigned ARCPseudoStrong : 1; |
937 | }; |
938 | enum { NumVarDeclBits = 8 }; |
939 | |
940 | protected: |
941 | enum { NumParameterIndexBits = 8 }; |
942 | |
943 | enum DefaultArgKind { |
944 | DAK_None, |
945 | DAK_Unparsed, |
946 | DAK_Uninstantiated, |
947 | DAK_Normal |
948 | }; |
949 | |
950 | enum { NumScopeDepthOrObjCQualsBits = 7 }; |
951 | |
952 | class ParmVarDeclBitfields { |
953 | friend class ASTDeclReader; |
954 | friend class ParmVarDecl; |
955 | |
956 | unsigned : NumVarDeclBits; |
957 | |
958 | |
959 | |
960 | unsigned HasInheritedDefaultArg : 1; |
961 | |
962 | |
963 | |
964 | |
965 | |
966 | unsigned DefaultArgKind : 2; |
967 | |
968 | |
969 | unsigned IsKNRPromoted : 1; |
970 | |
971 | |
972 | unsigned IsObjCMethodParam : 1; |
973 | |
974 | |
975 | |
976 | |
977 | |
978 | unsigned ScopeDepthOrObjCQuals : NumScopeDepthOrObjCQualsBits; |
979 | |
980 | |
981 | |
982 | unsigned ParameterIndex : NumParameterIndexBits; |
983 | }; |
984 | |
985 | class NonParmVarDeclBitfields { |
986 | friend class ASTDeclReader; |
987 | friend class ImplicitParamDecl; |
988 | friend class VarDecl; |
989 | |
990 | unsigned : NumVarDeclBits; |
991 | |
992 | |
993 | |
994 | |
995 | unsigned IsThisDeclarationADemotedDefinition : 1; |
996 | |
997 | |
998 | |
999 | unsigned ExceptionVar : 1; |
1000 | |
1001 | |
1002 | |
1003 | |
1004 | unsigned NRVOVariable : 1; |
1005 | |
1006 | |
1007 | |
1008 | unsigned CXXForRangeDecl : 1; |
1009 | |
1010 | |
1011 | unsigned ObjCForDecl : 1; |
1012 | |
1013 | |
1014 | unsigned IsInline : 1; |
1015 | |
1016 | |
1017 | unsigned IsInlineSpecified : 1; |
1018 | |
1019 | |
1020 | unsigned IsConstexpr : 1; |
1021 | |
1022 | |
1023 | |
1024 | unsigned IsInitCapture : 1; |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | unsigned PreviousDeclInSameBlockScope : 1; |
1030 | |
1031 | |
1032 | |
1033 | unsigned ImplicitParamKind : 3; |
1034 | |
1035 | unsigned EscapingByref : 1; |
1036 | }; |
1037 | |
1038 | union { |
1039 | unsigned AllBits; |
1040 | VarDeclBitfields VarDeclBits; |
1041 | ParmVarDeclBitfields ParmVarDeclBits; |
1042 | NonParmVarDeclBitfields NonParmVarDeclBits; |
1043 | }; |
1044 | |
1045 | VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1046 | SourceLocation IdLoc, IdentifierInfo *Id, QualType T, |
1047 | TypeSourceInfo *TInfo, StorageClass SC); |
1048 | |
1049 | using redeclarable_base = Redeclarable<VarDecl>; |
1050 | |
1051 | VarDecl *getNextRedeclarationImpl() override { |
1052 | return getNextRedeclaration(); |
1053 | } |
1054 | |
1055 | VarDecl *getPreviousDeclImpl() override { |
1056 | return getPreviousDecl(); |
1057 | } |
1058 | |
1059 | VarDecl *getMostRecentDeclImpl() override { |
1060 | return getMostRecentDecl(); |
1061 | } |
1062 | |
1063 | public: |
1064 | using redecl_range = redeclarable_base::redecl_range; |
1065 | using redecl_iterator = redeclarable_base::redecl_iterator; |
1066 | |
1067 | using redeclarable_base::redecls_begin; |
1068 | using redeclarable_base::redecls_end; |
1069 | using redeclarable_base::redecls; |
1070 | using redeclarable_base::getPreviousDecl; |
1071 | using redeclarable_base::getMostRecentDecl; |
1072 | using redeclarable_base::isFirstDecl; |
1073 | |
1074 | static VarDecl *Create(ASTContext &C, DeclContext *DC, |
1075 | SourceLocation StartLoc, SourceLocation IdLoc, |
1076 | IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, |
1077 | StorageClass S); |
1078 | |
1079 | static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1080 | |
1081 | SourceRange getSourceRange() const override LLVM_READONLY; |
1082 | |
1083 | |
1084 | |
1085 | StorageClass getStorageClass() const { |
1086 | return (StorageClass) VarDeclBits.SClass; |
1087 | } |
1088 | void setStorageClass(StorageClass SC); |
1089 | |
1090 | void setTSCSpec(ThreadStorageClassSpecifier TSC) { |
1091 | VarDeclBits.TSCSpec = TSC; |
1092 | assert(VarDeclBits.TSCSpec == TSC && "truncation"); |
1093 | } |
1094 | ThreadStorageClassSpecifier getTSCSpec() const { |
1095 | return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec); |
1096 | } |
1097 | TLSKind getTLSKind() const; |
1098 | |
1099 | |
1100 | |
1101 | bool hasLocalStorage() const { |
1102 | if (getStorageClass() == SC_None) { |
1103 | |
1104 | |
1105 | |
1106 | |
1107 | if (getType().getAddressSpace() == LangAS::opencl_constant) |
1108 | return false; |
1109 | |
1110 | return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified; |
1111 | } |
1112 | |
1113 | |
1114 | if (getStorageClass() == SC_Register && !isLocalVarDeclOrParm()) |
1115 | return false; |
1116 | |
1117 | |
1118 | |
1119 | |
1120 | return getStorageClass() >= SC_Auto; |
1121 | } |
1122 | |
1123 | |
1124 | |
1125 | bool isStaticLocal() const { |
1126 | return (getStorageClass() == SC_Static || |
1127 | |
1128 | (getStorageClass() == SC_None && getTSCSpec() == TSCS_thread_local)) |
1129 | && !isFileVarDecl(); |
1130 | } |
1131 | |
1132 | |
1133 | |
1134 | bool hasExternalStorage() const { |
1135 | return getStorageClass() == SC_Extern || |
1136 | getStorageClass() == SC_PrivateExtern; |
1137 | } |
1138 | |
1139 | |
1140 | |
1141 | |
1142 | |
1143 | bool hasGlobalStorage() const { return !hasLocalStorage(); } |
1144 | |
1145 | |
1146 | StorageDuration getStorageDuration() const { |
1147 | return hasLocalStorage() ? SD_Automatic : |
1148 | getTSCSpec() ? SD_Thread : SD_Static; |
1149 | } |
1150 | |
1151 | |
1152 | LanguageLinkage getLanguageLinkage() const; |
1153 | |
1154 | |
1155 | bool isExternC() const; |
1156 | |
1157 | |
1158 | |
1159 | bool isInExternCContext() const; |
1160 | |
1161 | |
1162 | |
1163 | bool isInExternCXXContext() const; |
1164 | |
1165 | |
1166 | |
1167 | |
1168 | |
1169 | |
1170 | bool isLocalVarDecl() const { |
1171 | if (getKind() != Decl::Var && getKind() != Decl::Decomposition) |
1172 | return false; |
1173 | if (const DeclContext *DC = getLexicalDeclContext()) |
1174 | return DC->getRedeclContext()->isFunctionOrMethod(); |
1175 | return false; |
1176 | } |
1177 | |
1178 | |
1179 | bool isLocalVarDeclOrParm() const { |
1180 | return isLocalVarDecl() || getKind() == Decl::ParmVar; |
1181 | } |
1182 | |
1183 | |
1184 | bool isFunctionOrMethodVarDecl() const { |
1185 | if (getKind() != Decl::Var && getKind() != Decl::Decomposition) |
1186 | return false; |
1187 | const DeclContext *DC = getLexicalDeclContext()->getRedeclContext(); |
1188 | return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block; |
1189 | } |
1190 | |
1191 | |
1192 | |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | |
1198 | |
1199 | |
1200 | bool isStaticDataMember() const { |
1201 | |
1202 | return getKind() != Decl::ParmVar && getDeclContext()->isRecord(); |
1203 | } |
1204 | |
1205 | VarDecl *getCanonicalDecl() override; |
1206 | const VarDecl *getCanonicalDecl() const { |
1207 | return const_cast<VarDecl*>(this)->getCanonicalDecl(); |
1208 | } |
1209 | |
1210 | enum DefinitionKind { |
1211 | |
1212 | DeclarationOnly, |
1213 | |
1214 | |
1215 | TentativeDefinition, |
1216 | |
1217 | |
1218 | Definition |
1219 | }; |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | DefinitionKind isThisDeclarationADefinition(ASTContext &) const; |
1225 | DefinitionKind isThisDeclarationADefinition() const { |
1226 | return isThisDeclarationADefinition(getASTContext()); |
1227 | } |
1228 | |
1229 | |
1230 | DefinitionKind hasDefinition(ASTContext &) const; |
1231 | DefinitionKind hasDefinition() const { |
1232 | return hasDefinition(getASTContext()); |
1233 | } |
1234 | |
1235 | |
1236 | |
1237 | VarDecl *getActingDefinition(); |
1238 | const VarDecl *getActingDefinition() const { |
1239 | return const_cast<VarDecl*>(this)->getActingDefinition(); |
1240 | } |
1241 | |
1242 | |
1243 | VarDecl *getDefinition(ASTContext &); |
1244 | const VarDecl *getDefinition(ASTContext &C) const { |
1245 | return const_cast<VarDecl*>(this)->getDefinition(C); |
1246 | } |
1247 | VarDecl *getDefinition() { |
1248 | return getDefinition(getASTContext()); |
1249 | } |
1250 | const VarDecl *getDefinition() const { |
1251 | return const_cast<VarDecl*>(this)->getDefinition(); |
1252 | } |
1253 | |
1254 | |
1255 | |
1256 | bool isOutOfLine() const override; |
1257 | |
1258 | |
1259 | bool isFileVarDecl() const { |
1260 | Kind K = getKind(); |
1261 | if (K == ParmVar || K == ImplicitParam) |
1262 | return false; |
1263 | |
1264 | if (getLexicalDeclContext()->getRedeclContext()->isFileContext()) |
1265 | return true; |
1266 | |
1267 | if (isStaticDataMember()) |
1268 | return true; |
1269 | |
1270 | return false; |
1271 | } |
1272 | |
1273 | |
1274 | |
1275 | const Expr *getAnyInitializer() const { |
1276 | const VarDecl *D; |
1277 | return getAnyInitializer(D); |
1278 | } |
1279 | |
1280 | |
1281 | |
1282 | const Expr *getAnyInitializer(const VarDecl *&D) const; |
1283 | |
1284 | bool hasInit() const; |
1285 | const Expr *getInit() const { |
1286 | return const_cast<VarDecl *>(this)->getInit(); |
1287 | } |
1288 | Expr *getInit(); |
1289 | |
1290 | |
1291 | Stmt **getInitAddress(); |
1292 | |
1293 | void setInit(Expr *I); |
1294 | |
1295 | |
1296 | |
1297 | |
1298 | VarDecl *getInitializingDeclaration(); |
1299 | const VarDecl *getInitializingDeclaration() const { |
1300 | return const_cast<VarDecl *>(this)->getInitializingDeclaration(); |
1301 | } |
1302 | |
1303 | |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | bool mightBeUsableInConstantExpressions(const ASTContext &C) const; |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | bool isUsableInConstantExpressions(const ASTContext &C) const; |
1316 | |
1317 | EvaluatedStmt *ensureEvaluatedStmt() const; |
1318 | EvaluatedStmt *getEvaluatedStmt() const; |
1319 | |
1320 | |
1321 | |
1322 | |
1323 | APValue *evaluateValue() const; |
1324 | |
1325 | private: |
1326 | APValue *evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes, |
1327 | bool IsConstantInitialization) const; |
1328 | |
1329 | public: |
1330 | |
1331 | |
1332 | |
1333 | APValue *getEvaluatedValue() const; |
1334 | |
1335 | |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | |
1341 | bool evaluateDestruction(SmallVectorImpl<PartialDiagnosticAt> &Notes) const; |
1342 | |
1343 | |
1344 | |
1345 | |
1346 | |
1347 | |
1348 | |
1349 | bool hasConstantInitialization() const; |
1350 | |
1351 | |
1352 | |
1353 | |
1354 | bool hasICEInitializer(const ASTContext &Context) const; |
1355 | |
1356 | |
1357 | |
1358 | |
1359 | bool checkForConstantInitialization( |
1360 | SmallVectorImpl<PartialDiagnosticAt> &Notes) const; |
1361 | |
1362 | void setInitStyle(InitializationStyle Style) { |
1363 | VarDeclBits.InitStyle = Style; |
1364 | } |
1365 | |
1366 | |
1367 | |
1368 | |
1369 | |
1370 | |
1371 | |
1372 | |
1373 | |
1374 | |
1375 | |
1376 | InitializationStyle getInitStyle() const { |
1377 | return static_cast<InitializationStyle>(VarDeclBits.InitStyle); |
1378 | } |
1379 | |
1380 | |
1381 | bool isDirectInit() const { |
1382 | return getInitStyle() != CInit; |
1383 | } |
1384 | |
1385 | |
1386 | bool isThisDeclarationADemotedDefinition() const { |
1387 | return isa<ParmVarDecl>(this) ? false : |
1388 | NonParmVarDeclBits.IsThisDeclarationADemotedDefinition; |
1389 | } |
1390 | |
1391 | |
1392 | |
1393 | |
1394 | |
1395 | |
1396 | void demoteThisDefinitionToDeclaration() { |
1397 | assert(isThisDeclarationADefinition() && "Not a definition!"); |
1398 | assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!"); |
1399 | NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1; |
1400 | } |
1401 | |
1402 | |
1403 | |
1404 | bool isExceptionVariable() const { |
1405 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar; |
1406 | } |
1407 | void setExceptionVariable(bool EV) { |
1408 | assert(!isa<ParmVarDecl>(this)); |
1409 | NonParmVarDeclBits.ExceptionVar = EV; |
1410 | } |
1411 | |
1412 | |
1413 | |
1414 | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | bool isNRVOVariable() const { |
1423 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable; |
1424 | } |
1425 | void setNRVOVariable(bool NRVO) { |
1426 | assert(!isa<ParmVarDecl>(this)); |
1427 | NonParmVarDeclBits.NRVOVariable = NRVO; |
1428 | } |
1429 | |
1430 | |
1431 | |
1432 | bool isCXXForRangeDecl() const { |
1433 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl; |
1434 | } |
1435 | void setCXXForRangeDecl(bool FRD) { |
1436 | assert(!isa<ParmVarDecl>(this)); |
1437 | NonParmVarDeclBits.CXXForRangeDecl = FRD; |
1438 | } |
1439 | |
1440 | |
1441 | |
1442 | bool isObjCForDecl() const { |
1443 | return NonParmVarDeclBits.ObjCForDecl; |
1444 | } |
1445 | |
1446 | void setObjCForDecl(bool FRD) { |
1447 | NonParmVarDeclBits.ObjCForDecl = FRD; |
1448 | } |
1449 | |
1450 | |
1451 | |
1452 | |
1453 | |
1454 | |
1455 | |
1456 | |
1457 | bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; } |
1458 | void setARCPseudoStrong(bool PS) { VarDeclBits.ARCPseudoStrong = PS; } |
1459 | |
1460 | |
1461 | bool isInline() const { |
1462 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInline; |
1463 | } |
1464 | bool isInlineSpecified() const { |
1465 | return isa<ParmVarDecl>(this) ? false |
1466 | : NonParmVarDeclBits.IsInlineSpecified; |
1467 | } |
1468 | void setInlineSpecified() { |
1469 | assert(!isa<ParmVarDecl>(this)); |
1470 | NonParmVarDeclBits.IsInline = true; |
1471 | NonParmVarDeclBits.IsInlineSpecified = true; |
1472 | } |
1473 | void setImplicitlyInline() { |
1474 | assert(!isa<ParmVarDecl>(this)); |
1475 | NonParmVarDeclBits.IsInline = true; |
1476 | } |
1477 | |
1478 | |
1479 | bool isConstexpr() const { |
1480 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr; |
1481 | } |
1482 | void setConstexpr(bool IC) { |
1483 | assert(!isa<ParmVarDecl>(this)); |
1484 | NonParmVarDeclBits.IsConstexpr = IC; |
1485 | } |
1486 | |
1487 | |
1488 | bool isInitCapture() const { |
1489 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture; |
1490 | } |
1491 | void setInitCapture(bool IC) { |
1492 | assert(!isa<ParmVarDecl>(this)); |
1493 | NonParmVarDeclBits.IsInitCapture = IC; |
1494 | } |
1495 | |
1496 | |
1497 | |
1498 | bool isParameterPack() const; |
1499 | |
1500 | |
1501 | |
1502 | bool isPreviousDeclInSameBlockScope() const { |
1503 | return isa<ParmVarDecl>(this) |
1504 | ? false |
1505 | : NonParmVarDeclBits.PreviousDeclInSameBlockScope; |
1506 | } |
1507 | void setPreviousDeclInSameBlockScope(bool Same) { |
1508 | assert(!isa<ParmVarDecl>(this)); |
1509 | NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same; |
1510 | } |
1511 | |
1512 | |
1513 | |
1514 | |
1515 | bool isEscapingByref() const; |
1516 | |
1517 | |
1518 | |
1519 | bool isNonEscapingByref() const; |
1520 | |
1521 | void setEscapingByref() { |
1522 | NonParmVarDeclBits.EscapingByref = true; |
1523 | } |
1524 | |
1525 | |
1526 | bool hasDependentAlignment() const; |
1527 | |
1528 | |
1529 | |
1530 | VarDecl *getTemplateInstantiationPattern() const; |
1531 | |
1532 | |
1533 | |
1534 | |
1535 | VarDecl *getInstantiatedFromStaticDataMember() const; |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | TemplateSpecializationKind |
1546 | getTemplateSpecializationKindForInstantiation() const; |
1547 | |
1548 | |
1549 | |
1550 | |
1551 | SourceLocation getPointOfInstantiation() const; |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1557 | |
1558 | |
1559 | |
1560 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK, |
1561 | SourceLocation PointOfInstantiation = SourceLocation()); |
1562 | |
1563 | |
1564 | |
1565 | void setInstantiationOfStaticDataMember(VarDecl *VD, |
1566 | TemplateSpecializationKind TSK); |
1567 | |
1568 | |
1569 | |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | |
1579 | VarTemplateDecl *getDescribedVarTemplate() const; |
1580 | |
1581 | void setDescribedVarTemplate(VarTemplateDecl *Template); |
1582 | |
1583 | |
1584 | |
1585 | |
1586 | bool isKnownToBeDefined() const; |
1587 | |
1588 | |
1589 | |
1590 | bool isNoDestroy(const ASTContext &) const; |
1591 | |
1592 | |
1593 | |
1594 | QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const; |
1595 | |
1596 | |
1597 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1598 | static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; } |
1599 | }; |
1600 | |
1601 | class ImplicitParamDecl : public VarDecl { |
1602 | void anchor() override; |
1603 | |
1604 | public: |
1605 | |
1606 | |
1607 | |
1608 | enum ImplicitParamKind : unsigned { |
1609 | |
1610 | ObjCSelf, |
1611 | |
1612 | |
1613 | ObjCCmd, |
1614 | |
1615 | |
1616 | CXXThis, |
1617 | |
1618 | |
1619 | CXXVTT, |
1620 | |
1621 | |
1622 | CapturedContext, |
1623 | |
1624 | |
1625 | Other, |
1626 | }; |
1627 | |
1628 | |
1629 | static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC, |
1630 | SourceLocation IdLoc, IdentifierInfo *Id, |
1631 | QualType T, ImplicitParamKind ParamKind); |
1632 | static ImplicitParamDecl *Create(ASTContext &C, QualType T, |
1633 | ImplicitParamKind ParamKind); |
1634 | |
1635 | static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1636 | |
1637 | ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, |
1638 | IdentifierInfo *Id, QualType Type, |
1639 | ImplicitParamKind ParamKind) |
1640 | : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type, |
1641 | nullptr, SC_None) { |
1642 | NonParmVarDeclBits.ImplicitParamKind = ParamKind; |
1643 | setImplicit(); |
1644 | } |
1645 | |
1646 | ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind) |
1647 | : VarDecl(ImplicitParam, C, nullptr, SourceLocation(), |
1648 | SourceLocation(), nullptr, Type, |
1649 | nullptr, SC_None) { |
1650 | NonParmVarDeclBits.ImplicitParamKind = ParamKind; |
1651 | setImplicit(); |
1652 | } |
1653 | |
1654 | |
1655 | ImplicitParamKind getParameterKind() const { |
1656 | return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind); |
1657 | } |
1658 | |
1659 | |
1660 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1661 | static bool classofKind(Kind K) { return K == ImplicitParam; } |
1662 | }; |
1663 | |
1664 | |
1665 | class ParmVarDecl : public VarDecl { |
1666 | public: |
1667 | enum { MaxFunctionScopeDepth = 255 }; |
1668 | enum { MaxFunctionScopeIndex = 255 }; |
1669 | |
1670 | protected: |
1671 | ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1672 | SourceLocation IdLoc, IdentifierInfo *Id, QualType T, |
1673 | TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg) |
1674 | : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) { |
1675 | assert(ParmVarDeclBits.HasInheritedDefaultArg == false); |
1676 | assert(ParmVarDeclBits.DefaultArgKind == DAK_None); |
1677 | assert(ParmVarDeclBits.IsKNRPromoted == false); |
1678 | assert(ParmVarDeclBits.IsObjCMethodParam == false); |
1679 | setDefaultArg(DefArg); |
1680 | } |
1681 | |
1682 | public: |
1683 | static ParmVarDecl *Create(ASTContext &C, DeclContext *DC, |
1684 | SourceLocation StartLoc, |
1685 | SourceLocation IdLoc, IdentifierInfo *Id, |
1686 | QualType T, TypeSourceInfo *TInfo, |
1687 | StorageClass S, Expr *DefArg); |
1688 | |
1689 | static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1690 | |
1691 | SourceRange getSourceRange() const override LLVM_READONLY; |
1692 | |
1693 | void setObjCMethodScopeInfo(unsigned parameterIndex) { |
1694 | ParmVarDeclBits.IsObjCMethodParam = true; |
1695 | setParameterIndex(parameterIndex); |
1696 | } |
1697 | |
1698 | void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) { |
1699 | assert(!ParmVarDeclBits.IsObjCMethodParam); |
1700 | |
1701 | ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth; |
1702 | assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth |
1703 | && "truncation!"); |
1704 | |
1705 | setParameterIndex(parameterIndex); |
1706 | } |
1707 | |
1708 | bool isObjCMethodParameter() const { |
1709 | return ParmVarDeclBits.IsObjCMethodParam; |
1710 | } |
1711 | |
1712 | |
1713 | bool isDestroyedInCallee() const; |
1714 | |
1715 | unsigned getFunctionScopeDepth() const { |
1716 | if (ParmVarDeclBits.IsObjCMethodParam) return 0; |
1717 | return ParmVarDeclBits.ScopeDepthOrObjCQuals; |
1718 | } |
1719 | |
1720 | static constexpr unsigned getMaxFunctionScopeDepth() { |
1721 | return (1u << NumScopeDepthOrObjCQualsBits) - 1; |
1722 | } |
1723 | |
1724 | |
1725 | unsigned getFunctionScopeIndex() const { |
1726 | return getParameterIndex(); |
1727 | } |
1728 | |
1729 | ObjCDeclQualifier getObjCDeclQualifier() const { |
1730 | if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None; |
1731 | return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals); |
1732 | } |
1733 | void setObjCDeclQualifier(ObjCDeclQualifier QTVal) { |
1734 | assert(ParmVarDeclBits.IsObjCMethodParam); |
1735 | ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal; |
1736 | } |
1737 | |
1738 | |
1739 | |
1740 | |
1741 | |
1742 | |
1743 | |
1744 | |
1745 | |
1746 | bool isKNRPromoted() const { |
1747 | return ParmVarDeclBits.IsKNRPromoted; |
1748 | } |
1749 | void setKNRPromoted(bool promoted) { |
1750 | ParmVarDeclBits.IsKNRPromoted = promoted; |
1751 | } |
1752 | |
1753 | Expr *getDefaultArg(); |
1754 | const Expr *getDefaultArg() const { |
1755 | return const_cast<ParmVarDecl *>(this)->getDefaultArg(); |
1756 | } |
1757 | |
1758 | void setDefaultArg(Expr *defarg); |
1759 | |
1760 | |
1761 | |
1762 | SourceRange getDefaultArgRange() const; |
1763 | void setUninstantiatedDefaultArg(Expr *arg); |
1764 | Expr *getUninstantiatedDefaultArg(); |
1765 | const Expr *getUninstantiatedDefaultArg() const { |
1766 | return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg(); |
1767 | } |
1768 | |
1769 | |
1770 | |
1771 | bool hasDefaultArg() const; |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | |
1780 | |
1781 | |
1782 | bool hasUnparsedDefaultArg() const { |
1783 | return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed; |
1784 | } |
1785 | |
1786 | bool hasUninstantiatedDefaultArg() const { |
1787 | return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated; |
1788 | } |
1789 | |
1790 | |
1791 | |
1792 | |
1793 | |
1794 | void setUnparsedDefaultArg() { |
1795 | ParmVarDeclBits.DefaultArgKind = DAK_Unparsed; |
1796 | } |
1797 | |
1798 | bool hasInheritedDefaultArg() const { |
1799 | return ParmVarDeclBits.HasInheritedDefaultArg; |
1800 | } |
1801 | |
1802 | void setHasInheritedDefaultArg(bool I = true) { |
1803 | ParmVarDeclBits.HasInheritedDefaultArg = I; |
1804 | } |
1805 | |
1806 | QualType getOriginalType() const; |
1807 | |
1808 | |
1809 | |
1810 | |
1811 | |
1812 | void setOwningFunction(DeclContext *FD) { setDeclContext(FD); } |
1813 | |
1814 | |
1815 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1816 | static bool classofKind(Kind K) { return K == ParmVar; } |
1817 | |
1818 | private: |
1819 | enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 }; |
1820 | |
1821 | void setParameterIndex(unsigned parameterIndex) { |
1822 | if (parameterIndex >= ParameterIndexSentinel) { |
1823 | setParameterIndexLarge(parameterIndex); |
1824 | return; |
1825 | } |
1826 | |
1827 | ParmVarDeclBits.ParameterIndex = parameterIndex; |
1828 | assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!"); |
1829 | } |
1830 | unsigned getParameterIndex() const { |
1831 | unsigned d = ParmVarDeclBits.ParameterIndex; |
1832 | return d == ParameterIndexSentinel ? getParameterIndexLarge() : d; |
1833 | } |
1834 | |
1835 | void setParameterIndexLarge(unsigned parameterIndex); |
1836 | unsigned getParameterIndexLarge() const; |
1837 | }; |
1838 | |
1839 | enum class MultiVersionKind { |
1840 | None, |
1841 | Target, |
1842 | CPUSpecific, |
1843 | CPUDispatch |
1844 | }; |
1845 | |
1846 | |
1847 | |
1848 | |
1849 | |
1850 | |
1851 | |
1852 | |
1853 | |
1854 | |
1855 | |
1856 | class FunctionDecl : public DeclaratorDecl, |
1857 | public DeclContext, |
1858 | public Redeclarable<FunctionDecl> { |
1859 | |
1860 | |
1861 | public: |
1862 | |
1863 | enum TemplatedKind { |
1864 | |
1865 | TK_NonTemplate, |
1866 | |
1867 | TK_FunctionTemplate, |
1868 | |
1869 | |
1870 | TK_MemberSpecialization, |
1871 | |
1872 | |
1873 | |
1874 | TK_FunctionTemplateSpecialization, |
1875 | |
1876 | |
1877 | TK_DependentFunctionTemplateSpecialization |
1878 | }; |
1879 | |
1880 | |
1881 | |
1882 | class DefaultedFunctionInfo final |
1883 | : llvm::TrailingObjects<DefaultedFunctionInfo, DeclAccessPair> { |
1884 | friend TrailingObjects; |
1885 | unsigned NumLookups; |
1886 | |
1887 | public: |
1888 | static DefaultedFunctionInfo *Create(ASTContext &Context, |
1889 | ArrayRef<DeclAccessPair> Lookups); |
1890 | |
1891 | |
1892 | ArrayRef<DeclAccessPair> getUnqualifiedLookups() const { |
1893 | return {getTrailingObjects<DeclAccessPair>(), NumLookups}; |
1894 | } |
1895 | }; |
1896 | |
1897 | private: |
1898 | |
1899 | |
1900 | |
1901 | ParmVarDecl **ParamInfo = nullptr; |
1902 | |
1903 | |
1904 | |
1905 | union { |
1906 | |
1907 | LazyDeclStmtPtr Body; |
1908 | |
1909 | DefaultedFunctionInfo *DefaultedInfo; |
1910 | }; |
1911 | |
1912 | unsigned ODRHash; |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | |
1921 | SourceLocation EndRangeLoc; |
1922 | |
1923 | |
1924 | |
1925 | |
1926 | |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | |
1933 | |
1934 | |
1935 | llvm::PointerUnion<FunctionTemplateDecl *, |
1936 | MemberSpecializationInfo *, |
1937 | FunctionTemplateSpecializationInfo *, |
1938 | DependentFunctionTemplateSpecializationInfo *> |
1939 | TemplateOrSpecialization; |
1940 | |
1941 | |
1942 | |
1943 | DeclarationNameLoc DNLoc; |
1944 | |
1945 | |
1946 | |
1947 | |
1948 | |
1949 | |
1950 | |
1951 | |
1952 | |
1953 | |
1954 | |
1955 | |
1956 | |
1957 | |
1958 | |
1959 | |
1960 | |
1961 | |
1962 | |
1963 | |
1964 | |
1965 | |
1966 | void setFunctionTemplateSpecialization(ASTContext &C, |
1967 | FunctionTemplateDecl *Template, |
1968 | const TemplateArgumentList *TemplateArgs, |
1969 | void *InsertPos, |
1970 | TemplateSpecializationKind TSK, |
1971 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
1972 | SourceLocation PointOfInstantiation); |
1973 | |
1974 | |
1975 | |
1976 | void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD, |
1977 | TemplateSpecializationKind TSK); |
1978 | |
1979 | void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo); |
1980 | |
1981 | |
1982 | |
1983 | |
1984 | bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; } |
1985 | |
1986 | |
1987 | bool hasODRHash() const { return FunctionDeclBits.HasODRHash; } |
1988 | |
1989 | |
1990 | void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; } |
1991 | |
1992 | protected: |
1993 | FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1994 | const DeclarationNameInfo &NameInfo, QualType T, |
1995 | TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin, |
1996 | bool isInlineSpecified, ConstexprSpecKind ConstexprKind, |
1997 | Expr *TrailingRequiresClause = nullptr); |
1998 | |
1999 | using redeclarable_base = Redeclarable<FunctionDecl>; |
2000 | |
2001 | FunctionDecl *getNextRedeclarationImpl() override { |
2002 | return getNextRedeclaration(); |
2003 | } |
2004 | |
2005 | FunctionDecl *getPreviousDeclImpl() override { |
2006 | return getPreviousDecl(); |
2007 | } |
2008 | |
2009 | FunctionDecl *getMostRecentDeclImpl() override { |
2010 | return getMostRecentDecl(); |
2011 | } |
2012 | |
2013 | public: |
2014 | friend class ASTDeclReader; |
2015 | friend class ASTDeclWriter; |
2016 | |
2017 | using redecl_range = redeclarable_base::redecl_range; |
2018 | using redecl_iterator = redeclarable_base::redecl_iterator; |
2019 | |
2020 | using redeclarable_base::redecls_begin; |
2021 | using redeclarable_base::redecls_end; |
2022 | using redeclarable_base::redecls; |
2023 | using redeclarable_base::getPreviousDecl; |
2024 | using redeclarable_base::getMostRecentDecl; |
2025 | using redeclarable_base::isFirstDecl; |
2026 | |
2027 | static FunctionDecl * |
2028 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
2029 | SourceLocation NLoc, DeclarationName N, QualType T, |
2030 | TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false, |
2031 | bool isInlineSpecified = false, bool hasWrittenPrototype = true, |
2032 | ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified, |
2033 | Expr *TrailingRequiresClause = nullptr) { |
2034 | DeclarationNameInfo NameInfo(N, NLoc); |
2035 | return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC, |
2036 | UsesFPIntrin, isInlineSpecified, |
2037 | hasWrittenPrototype, ConstexprKind, |
2038 | TrailingRequiresClause); |
2039 | } |
2040 | |
2041 | static FunctionDecl * |
2042 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
2043 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2044 | StorageClass SC, bool UsesFPIntrin, bool isInlineSpecified, |
2045 | bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind, |
2046 | Expr *TrailingRequiresClause); |
2047 | |
2048 | static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2049 | |
2050 | DeclarationNameInfo getNameInfo() const { |
2051 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
2052 | } |
2053 | |
2054 | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, |
2055 | bool Qualified) const override; |
2056 | |
2057 | void setRangeEnd(SourceLocation E) { EndRangeLoc = E; } |
2058 | |
2059 | |
2060 | SourceLocation getEllipsisLoc() const { |
2061 | const auto *FPT = getType()->getAs<FunctionProtoType>(); |
2062 | if (FPT && FPT->isVariadic()) |
2063 | return FPT->getEllipsisLoc(); |
2064 | return SourceLocation(); |
2065 | } |
2066 | |
2067 | SourceRange getSourceRange() const override LLVM_READONLY; |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | |
2079 | |
2080 | |
2081 | |
2082 | |
2083 | |
2084 | |
2085 | |
2086 | |
2087 | |
2088 | bool hasBody(const FunctionDecl *&Definition) const; |
2089 | |
2090 | bool hasBody() const override { |
2091 | const FunctionDecl* Definition; |
2092 | return hasBody(Definition); |
2093 | } |
2094 | |
2095 | |
2096 | |
2097 | bool hasTrivialBody() const; |
2098 | |
2099 | |
2100 | |
2101 | |
2102 | |
2103 | |
2104 | |
2105 | |
2106 | |
2107 | |
2108 | |
2109 | |
2110 | bool isDefined(const FunctionDecl *&Definition, |
2111 | bool CheckForPendingFriendDefinition = false) const; |
2112 | |
2113 | bool isDefined() const { |
2114 | const FunctionDecl* Definition; |
2115 | return isDefined(Definition); |
2116 | } |
2117 | |
2118 | |
2119 | FunctionDecl *getDefinition() { |
2120 | const FunctionDecl *Definition; |
2121 | if (isDefined(Definition)) |
2122 | return const_cast<FunctionDecl *>(Definition); |
2123 | return nullptr; |
2124 | } |
2125 | const FunctionDecl *getDefinition() const { |
2126 | return const_cast<FunctionDecl *>(this)->getDefinition(); |
2127 | } |
2128 | |
2129 | |
2130 | |
2131 | |
2132 | |
2133 | |
2134 | |
2135 | Stmt *getBody(const FunctionDecl *&Definition) const; |
2136 | |
2137 | Stmt *getBody() const override { |
2138 | const FunctionDecl* Definition; |
2139 | return getBody(Definition); |
2140 | } |
2141 | |
2142 | |
2143 | |
2144 | |
2145 | |
2146 | |
2147 | |
2148 | |
2149 | |
2150 | |
2151 | bool isThisDeclarationADefinition() const { |
2152 | return isDeletedAsWritten() || isDefaulted() || |
2153 | doesThisDeclarationHaveABody() || hasSkippedBody() || |
2154 | willHaveBody() || hasDefiningAttr(); |
2155 | } |
2156 | |
2157 | |
2158 | |
2159 | |
2160 | bool isThisDeclarationInstantiatedFromAFriendDefinition() const; |
2161 | |
2162 | |
2163 | bool doesThisDeclarationHaveABody() const { |
2164 | return (!FunctionDeclBits.HasDefaultedFunctionInfo && Body) || |
2165 | isLateTemplateParsed(); |
2166 | } |
2167 | |
2168 | void setBody(Stmt *B); |
2169 | void setLazyBody(uint64_t Offset) { |
2170 | FunctionDeclBits.HasDefaultedFunctionInfo = false; |
2171 | Body = LazyDeclStmtPtr(Offset); |
2172 | } |
2173 | |
2174 | void setDefaultedFunctionInfo(DefaultedFunctionInfo *Info); |
2175 | DefaultedFunctionInfo *getDefaultedFunctionInfo() const; |
2176 | |
2177 | |
2178 | bool isVariadic() const; |
2179 | |
2180 | |
2181 | bool isVirtualAsWritten() const { |
2182 | return FunctionDeclBits.IsVirtualAsWritten; |
2183 | } |
2184 | |
2185 | |
2186 | void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; } |
2187 | |
2188 | |
2189 | |
2190 | bool isPure() const { return FunctionDeclBits.IsPure; } |
2191 | void setPure(bool P = true); |
2192 | |
2193 | |
2194 | bool isLateTemplateParsed() const { |
2195 | return FunctionDeclBits.IsLateTemplateParsed; |
2196 | } |
2197 | |
2198 | |
2199 | void setLateTemplateParsed(bool ILT = true) { |
2200 | FunctionDeclBits.IsLateTemplateParsed = ILT; |
2201 | } |
2202 | |
2203 | |
2204 | |
2205 | |
2206 | |
2207 | bool isTrivial() const { return FunctionDeclBits.IsTrivial; } |
2208 | void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; } |
2209 | |
2210 | bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; } |
2211 | void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; } |
2212 | |
2213 | |
2214 | |
2215 | bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; } |
2216 | void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; } |
2217 | |
2218 | |
2219 | bool isExplicitlyDefaulted() const { |
2220 | return FunctionDeclBits.IsExplicitlyDefaulted; |
2221 | } |
2222 | |
2223 | |
2224 | void setExplicitlyDefaulted(bool ED = true) { |
2225 | FunctionDeclBits.IsExplicitlyDefaulted = ED; |
2226 | } |
2227 | |
2228 | |
2229 | |
2230 | bool isUserProvided() const { |
2231 | auto *DeclAsWritten = this; |
2232 | if (FunctionDecl *Pattern = getTemplateInstantiationPattern()) |
2233 | DeclAsWritten = Pattern; |
2234 | return !(DeclAsWritten->isDeleted() || |
2235 | DeclAsWritten->getCanonicalDecl()->isDefaulted()); |
2236 | } |
2237 | |
2238 | |
2239 | |
2240 | |
2241 | bool hasImplicitReturnZero() const { |
2242 | return FunctionDeclBits.HasImplicitReturnZero; |
2243 | } |
2244 | |
2245 | |
2246 | |
2247 | |
2248 | void setHasImplicitReturnZero(bool IRZ) { |
2249 | FunctionDeclBits.HasImplicitReturnZero = IRZ; |
2250 | } |
2251 | |
2252 | |
2253 | |
2254 | |
2255 | |
2256 | bool hasPrototype() const { |
2257 | return hasWrittenPrototype() || hasInheritedPrototype(); |
2258 | } |
2259 | |
2260 | |
2261 | bool hasWrittenPrototype() const { |
2262 | return FunctionDeclBits.HasWrittenPrototype; |
2263 | } |
2264 | |
2265 | |
2266 | void setHasWrittenPrototype(bool P = true) { |
2267 | FunctionDeclBits.HasWrittenPrototype = P; |
2268 | } |
2269 | |
2270 | |
2271 | |
2272 | bool hasInheritedPrototype() const { |
2273 | return FunctionDeclBits.HasInheritedPrototype; |
2274 | } |
2275 | |
2276 | |
2277 | |
2278 | void setHasInheritedPrototype(bool P = true) { |
2279 | FunctionDeclBits.HasInheritedPrototype = P; |
2280 | } |
2281 | |
2282 | |
2283 | bool isConstexpr() const { |
2284 | return getConstexprKind() != ConstexprSpecKind::Unspecified; |
2285 | } |
2286 | void setConstexprKind(ConstexprSpecKind CSK) { |
2287 | FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(CSK); |
2288 | } |
2289 | ConstexprSpecKind getConstexprKind() const { |
2290 | return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind); |
2291 | } |
2292 | bool isConstexprSpecified() const { |
2293 | return getConstexprKind() == ConstexprSpecKind::Constexpr; |
2294 | } |
2295 | bool isConsteval() const { |
2296 | return getConstexprKind() == ConstexprSpecKind::Consteval; |
2297 | } |
2298 | |
2299 | |
2300 | |
2301 | |
2302 | |
2303 | |
2304 | |
2305 | bool instantiationIsPending() const { |
2306 | return FunctionDeclBits.InstantiationIsPending; |
2307 | } |
2308 | |
2309 | |
2310 | |
2311 | void setInstantiationIsPending(bool IC) { |
2312 | FunctionDeclBits.InstantiationIsPending = IC; |
2313 | } |
2314 | |
2315 | |
2316 | bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; } |
2317 | void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; } |
2318 | |
2319 | |
2320 | |
2321 | |
2322 | |
2323 | |
2324 | |
2325 | |
2326 | |
2327 | |
2328 | |
2329 | |
2330 | |
2331 | |
2332 | |
2333 | |
2334 | |
2335 | |
2336 | |
2337 | |
2338 | bool isDeleted() const { |
2339 | return getCanonicalDecl()->FunctionDeclBits.IsDeleted; |
2340 | } |
2341 | |
2342 | bool isDeletedAsWritten() const { |
2343 | return FunctionDeclBits.IsDeleted && !isDefaulted(); |
2344 | } |
2345 | |
2346 | void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; } |
2347 | |
2348 | |
2349 | |
2350 | bool isMain() const; |
2351 | |
2352 | |
2353 | |
2354 | bool isMSVCRTEntryPoint() const; |
2355 | |
2356 | |
2357 | |
2358 | |
2359 | |
2360 | |
2361 | |
2362 | |
2363 | |
2364 | |
2365 | |
2366 | |
2367 | |
2368 | |
2369 | bool isReservedGlobalPlacementOperator() const; |
2370 | |
2371 | |
2372 | |
2373 | |
2374 | |
2375 | |
2376 | |
2377 | |
2378 | |
2379 | |
2380 | |
2381 | |
2382 | |
2383 | |
2384 | |
2385 | |
2386 | |
2387 | |
2388 | |
2389 | |
2390 | |
2391 | |
2392 | bool isReplaceableGlobalAllocationFunction( |
2393 | Optional<unsigned> *AlignmentParam = nullptr, |
2394 | bool *IsNothrow = nullptr) const; |
2395 | |
2396 | |
2397 | bool isInlineBuiltinDeclaration() const; |
2398 | |
2399 | |
2400 | bool isDestroyingOperatorDelete() const; |
2401 | |
2402 | |
2403 | LanguageLinkage getLanguageLinkage() const; |
2404 | |
2405 | |
2406 | |
2407 | bool isExternC() const; |
2408 | |
2409 | |
2410 | |
2411 | bool isInExternCContext() const; |
2412 | |
2413 | |
2414 | |
2415 | bool isInExternCXXContext() const; |
2416 | |
2417 | |
2418 | bool isGlobal() const; |
2419 | |
2420 | |
2421 | |
2422 | bool isNoReturn() const; |
2423 | |
2424 | |
2425 | bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; } |
2426 | void setHasSkippedBody(bool Skipped = true) { |
2427 | FunctionDeclBits.HasSkippedBody = Skipped; |
2428 | } |
2429 | |
2430 | |
2431 | bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; } |
2432 | void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; } |
2433 | |
2434 | |
2435 | bool isMultiVersion() const { |
2436 | return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion; |
2437 | } |
2438 | |
2439 | |
2440 | |
2441 | void setIsMultiVersion(bool V = true) { |
2442 | getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V; |
2443 | } |
2444 | |
2445 | |
2446 | |
2447 | |
2448 | MultiVersionKind getMultiVersionKind() const; |
2449 | |
2450 | |
2451 | |
2452 | |
2453 | bool isCPUDispatchMultiVersion() const; |
2454 | |
2455 | |
2456 | bool isCPUSpecificMultiVersion() const; |
2457 | |
2458 | |
2459 | |
2460 | bool isTargetMultiVersion() const; |
2461 | |
2462 | |
2463 | |
2464 | |
2465 | |
2466 | |
2467 | |
2468 | void getAssociatedConstraints(SmallVectorImpl<const Expr *> &AC) const { |
2469 | if (auto *TRC = getTrailingRequiresClause()) |
2470 | AC.push_back(TRC); |
2471 | } |
2472 | |
2473 | void setPreviousDeclaration(FunctionDecl * PrevDecl); |
2474 | |
2475 | FunctionDecl *getCanonicalDecl() override; |
2476 | const FunctionDecl *getCanonicalDecl() const { |
2477 | return const_cast<FunctionDecl*>(this)->getCanonicalDecl(); |
2478 | } |
2479 | |
2480 | unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const; |
2481 | |
2482 | |
2483 | ArrayRef<ParmVarDecl *> parameters() const { |
2484 | return {ParamInfo, getNumParams()}; |
2485 | } |
2486 | MutableArrayRef<ParmVarDecl *> parameters() { |
2487 | return {ParamInfo, getNumParams()}; |
2488 | } |
2489 | |
2490 | |
2491 | using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator; |
2492 | using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator; |
2493 | |
2494 | bool param_empty() const { return parameters().empty(); } |
2495 | param_iterator param_begin() { return parameters().begin(); } |
2496 | param_iterator param_end() { return parameters().end(); } |
2497 | param_const_iterator param_begin() const { return parameters().begin(); } |
2498 | param_const_iterator param_end() const { return parameters().end(); } |
2499 | size_t param_size() const { return parameters().size(); } |
2500 | |
2501 | |
2502 | |
2503 | |
2504 | unsigned getNumParams() const; |
2505 | |
2506 | const ParmVarDecl *getParamDecl(unsigned i) const { |
2507 | assert(i < getNumParams() && "Illegal param #"); |
2508 | return ParamInfo[i]; |
2509 | } |
2510 | ParmVarDecl *getParamDecl(unsigned i) { |
2511 | assert(i < getNumParams() && "Illegal param #"); |
2512 | return ParamInfo[i]; |
2513 | } |
2514 | void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) { |
2515 | setParams(getASTContext(), NewParamInfo); |
2516 | } |
2517 | |
2518 | |
2519 | |
2520 | |
2521 | unsigned getMinRequiredArguments() const; |
2522 | |
2523 | |
2524 | |
2525 | |
2526 | |
2527 | |
2528 | |
2529 | bool hasOneParamOrDefaultArgs() const; |
2530 | |
2531 | |
2532 | |
2533 | |
2534 | |
2535 | FunctionTypeLoc getFunctionTypeLoc() const; |
2536 | |
2537 | QualType getReturnType() const { |
2538 | return getType()->castAs<FunctionType>()->getReturnType(); |
2539 | } |
2540 | |
2541 | |
2542 | |
2543 | |
2544 | SourceRange getReturnTypeSourceRange() const; |
2545 | |
2546 | |
2547 | |
2548 | |
2549 | |
2550 | SourceRange getParametersSourceRange() const; |
2551 | |
2552 | |
2553 | |
2554 | QualType getDeclaredReturnType() const { |
2555 | auto *TSI = getTypeSourceInfo(); |
2556 | QualType T = TSI ? TSI->getType() : getType(); |
2557 | return T->castAs<FunctionType>()->getReturnType(); |
2558 | } |
2559 | |
2560 | |
2561 | ExceptionSpecificationType getExceptionSpecType() const { |
2562 | auto *TSI = getTypeSourceInfo(); |
2563 | QualType T = TSI ? TSI->getType() : getType(); |
2564 | const auto *FPT = T->getAs<FunctionProtoType>(); |
2565 | return FPT ? FPT->getExceptionSpecType() : EST_None; |
2566 | } |
2567 | |
2568 | |
2569 | |
2570 | SourceRange getExceptionSpecSourceRange() const; |
2571 | |
2572 | |
2573 | QualType getCallResultType() const { |
2574 | return getType()->castAs<FunctionType>()->getCallResultType( |
2575 | getASTContext()); |
2576 | } |
2577 | |
2578 | |
2579 | |
2580 | StorageClass getStorageClass() const { |
2581 | return static_cast<StorageClass>(FunctionDeclBits.SClass); |
2582 | } |
2583 | |
2584 | |
2585 | void setStorageClass(StorageClass SClass) { |
2586 | FunctionDeclBits.SClass = SClass; |
2587 | } |
2588 | |
2589 | |
2590 | |
2591 | bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; } |
2592 | |
2593 | |
2594 | void setInlineSpecified(bool I) { |
2595 | FunctionDeclBits.IsInlineSpecified = I; |
2596 | FunctionDeclBits.IsInline = I; |
2597 | } |
2598 | |
2599 | |
2600 | |
2601 | bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; } |
2602 | |
2603 | |
2604 | |
2605 | void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; } |
2606 | |
2607 | |
2608 | void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; } |
2609 | |
2610 | |
2611 | |
2612 | |
2613 | bool isInlined() const { return FunctionDeclBits.IsInline; } |
2614 | |
2615 | bool isInlineDefinitionExternallyVisible() const; |
2616 | |
2617 | bool isMSExternInline() const; |
2618 | |
2619 | bool doesDeclarationForceExternallyVisibleDefinition() const; |
2620 | |
2621 | bool isStatic() const { return getStorageClass() == SC_Static; } |
2622 | |
2623 | |
2624 | |
2625 | bool isOverloadedOperator() const { |
2626 | return getOverloadedOperator() != OO_None; |
2627 | } |
2628 | |
2629 | OverloadedOperatorKind getOverloadedOperator() const; |
2630 | |
2631 | const IdentifierInfo *getLiteralIdentifier() const; |
2632 | |
2633 | |
2634 | |
2635 | |
2636 | |
2637 | |
2638 | |
2639 | |
2640 | |
2641 | |
2642 | |
2643 | |
2644 | |
2645 | |
2646 | |
2647 | |
2648 | |
2649 | |
2650 | |
2651 | |
2652 | |
2653 | |
2654 | FunctionDecl *getInstantiatedFromMemberFunction() const; |
2655 | |
2656 | |
2657 | TemplatedKind getTemplatedKind() const; |
2658 | |
2659 | |
2660 | |
2661 | |
2662 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
2663 | |
2664 | |
2665 | |
2666 | void setInstantiationOfMemberFunction(FunctionDecl *FD, |
2667 | TemplateSpecializationKind TSK) { |
2668 | setInstantiationOfMemberFunction(getASTContext(), FD, TSK); |
2669 | } |
2670 | |
2671 | |
2672 | |
2673 | |
2674 | |
2675 | |
2676 | |
2677 | |
2678 | |
2679 | |
2680 | |
2681 | |
2682 | |
2683 | FunctionTemplateDecl *getDescribedFunctionTemplate() const; |
2684 | |
2685 | void setDescribedFunctionTemplate(FunctionTemplateDecl *Template); |
2686 | |
2687 | |
2688 | |
2689 | bool isFunctionTemplateSpecialization() const { |
2690 | return getPrimaryTemplate() != nullptr; |
2691 | } |
2692 | |
2693 | |
2694 | |
2695 | |
2696 | FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const; |
2697 | |
2698 | |
2699 | |
2700 | |
2701 | bool isImplicitlyInstantiable() const; |
2702 | |
2703 | |
2704 | |
2705 | bool isTemplateInstantiation() const; |
2706 | |
2707 | |
2708 | |
2709 | |
2710 | |
2711 | |
2712 | |
2713 | |
2714 | |
2715 | FunctionDecl * |
2716 | getTemplateInstantiationPattern(bool ForDefinition = true) const; |
2717 | |
2718 | |
2719 | |
2720 | |
2721 | |
2722 | |
2723 | FunctionTemplateDecl *getPrimaryTemplate() const; |
2724 | |
2725 | |
2726 | |
2727 | |
2728 | |
2729 | |
2730 | const TemplateArgumentList *getTemplateSpecializationArgs() const; |
2731 | |
2732 | |
2733 | |
2734 | |
2735 | |
2736 | |
2737 | |
2738 | |
2739 | const ASTTemplateArgumentListInfo* |
2740 | getTemplateSpecializationArgsAsWritten() const; |
2741 | |
2742 | |
2743 | |
2744 | |
2745 | |
2746 | |
2747 | |
2748 | |
2749 | |
2750 | |
2751 | |
2752 | |
2753 | |
2754 | |
2755 | |
2756 | |
2757 | |
2758 | |
2759 | |
2760 | |
2761 | void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, |
2762 | const TemplateArgumentList *TemplateArgs, |
2763 | void *InsertPos, |
2764 | TemplateSpecializationKind TSK = TSK_ImplicitInstantiation, |
2765 | const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr, |
2766 | SourceLocation PointOfInstantiation = SourceLocation()) { |
2767 | setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs, |
2768 | InsertPos, TSK, TemplateArgsAsWritten, |
2769 | PointOfInstantiation); |
2770 | } |
2771 | |
2772 | |
2773 | |
2774 | void setDependentTemplateSpecialization(ASTContext &Context, |
2775 | const UnresolvedSetImpl &Templates, |
2776 | const TemplateArgumentListInfo &TemplateArgs); |
2777 | |
2778 | DependentFunctionTemplateSpecializationInfo * |
2779 | getDependentSpecializationInfo() const; |
2780 | |
2781 | |
2782 | |
2783 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
2784 | |
2785 | |
2786 | |
2787 | TemplateSpecializationKind |
2788 | getTemplateSpecializationKindForInstantiation() const; |
2789 | |
2790 | |
2791 | |
2792 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK, |
2793 | SourceLocation PointOfInstantiation = SourceLocation()); |
2794 | |
2795 | |
2796 | |
2797 | |
2798 | |
2799 | |
2800 | |
2801 | SourceLocation getPointOfInstantiation() const; |
2802 | |
2803 | |
2804 | |
2805 | bool isOutOfLine() const override; |
2806 | |
2807 | |
2808 | |
2809 | |
2810 | |
2811 | unsigned getMemoryFunctionKind() const; |
2812 | |
2813 | |
2814 | |
2815 | unsigned getODRHash(); |
2816 | |
2817 | |
2818 | |
2819 | unsigned getODRHash() const; |
2820 | |
2821 | |
2822 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2823 | static bool classofKind(Kind K) { |
2824 | return K >= firstFunction && K <= lastFunction; |
2825 | } |
2826 | static DeclContext *castToDeclContext(const FunctionDecl *D) { |
2827 | return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D)); |
2828 | } |
2829 | static FunctionDecl *castFromDeclContext(const DeclContext *DC) { |
2830 | return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC)); |
2831 | } |
2832 | }; |
2833 | |
2834 | |
2835 | class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> { |
2836 | unsigned BitField : 1; |
2837 | unsigned Mutable : 1; |
2838 | mutable unsigned CachedFieldIndex : 30; |
2839 | |
2840 | |
2841 | |
2842 | |
2843 | |
2844 | enum InitStorageKind { |
2845 | |
2846 | |
2847 | |
2848 | ISK_NoInit = (unsigned) ICIS_NoInit, |
2849 | |
2850 | |
2851 | |
2852 | ISK_InClassCopyInit = (unsigned) ICIS_CopyInit, |
2853 | |
2854 | |
2855 | |
2856 | ISK_InClassListInit = (unsigned) ICIS_ListInit, |
2857 | |
2858 | |
2859 | |
2860 | ISK_CapturedVLAType, |
2861 | }; |
2862 | |
2863 | |
2864 | |
2865 | struct InitAndBitWidth { |
2866 | Expr *Init; |
2867 | Expr *BitWidth; |
2868 | }; |
2869 | |
2870 | |
2871 | |
2872 | |
2873 | |
2874 | |
2875 | |
2876 | |
2877 | |
2878 | |
2879 | llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage; |
2880 | |
2881 | protected: |
2882 | FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, |
2883 | SourceLocation IdLoc, IdentifierInfo *Id, |
2884 | QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, |
2885 | InClassInitStyle InitStyle) |
2886 | : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), |
2887 | BitField(false), Mutable(Mutable), CachedFieldIndex(0), |
2888 | InitStorage(nullptr, (InitStorageKind) InitStyle) { |
2889 | if (BW) |
2890 | setBitWidth(BW); |
2891 | } |
2892 | |
2893 | public: |
2894 | friend class ASTDeclReader; |
2895 | friend class ASTDeclWriter; |
2896 | |
2897 | static FieldDecl *Create(const ASTContext &C, DeclContext *DC, |
2898 | SourceLocation StartLoc, SourceLocation IdLoc, |
2899 | IdentifierInfo *Id, QualType T, |
2900 | TypeSourceInfo *TInfo, Expr *BW, bool Mutable, |
2901 | InClassInitStyle InitStyle); |
2902 | |
2903 | static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2904 | |
2905 | |
2906 | |
2907 | unsigned getFieldIndex() const; |
2908 | |
2909 | |
2910 | bool isMutable() const { return Mutable; } |
2911 | |
2912 | |
2913 | bool isBitField() const { return BitField; } |
2914 | |
2915 | |
2916 | bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); } |
2917 | |
2918 | |
2919 | |
2920 | |
2921 | |
2922 | bool isAnonymousStructOrUnion() const; |
2923 | |
2924 | Expr *getBitWidth() const { |
2925 | if (!BitField) |
2926 | return nullptr; |
2927 | void *Ptr = InitStorage.getPointer(); |
2928 | if (getInClassInitStyle()) |
2929 | return static_cast<InitAndBitWidth*>(Ptr)->BitWidth; |
2930 | return static_cast<Expr*>(Ptr); |
2931 | } |
2932 | |
2933 | unsigned getBitWidthValue(const ASTContext &Ctx) const; |
2934 | |
2935 | |
2936 | |
2937 | void setBitWidth(Expr *Width) { |
2938 | assert(!hasCapturedVLAType() && !BitField && |
2939 | "bit width or captured type already set"); |
2940 | assert(Width && "no bit width specified"); |
2941 | InitStorage.setPointer( |
2942 | InitStorage.getInt() |
2943 | ? new (getASTContext()) |
2944 | InitAndBitWidth{getInClassInitializer(), Width} |
2945 | : static_cast<void*>(Width)); |
2946 | BitField = true; |
2947 | } |
2948 | |
2949 | |
2950 | |
2951 | void removeBitWidth() { |
2952 | assert(isBitField() && "no bitfield width to remove"); |
2953 | InitStorage.setPointer(getInClassInitializer()); |
2954 | BitField = false; |
2955 | } |
2956 | |
2957 | |
2958 | |
2959 | |
2960 | bool isZeroLengthBitField(const ASTContext &Ctx) const; |
2961 | |
2962 | |
2963 | |
2964 | |
2965 | bool isZeroSize(const ASTContext &Ctx) const; |
2966 | |
2967 | |
2968 | InClassInitStyle getInClassInitStyle() const { |
2969 | InitStorageKind storageKind = InitStorage.getInt(); |
2970 | return (storageKind == ISK_CapturedVLAType |
2971 | ? ICIS_NoInit : (InClassInitStyle) storageKind); |
2972 | } |
2973 | |
2974 | |
2975 | bool hasInClassInitializer() const { |
2976 | return getInClassInitStyle() != ICIS_NoInit; |
2977 | } |
2978 | |
2979 | |
2980 | |
2981 | |
2982 | Expr *getInClassInitializer() const { |
2983 | if (!hasInClassInitializer()) |
2984 | return nullptr; |
2985 | void *Ptr = InitStorage.getPointer(); |
2986 | if (BitField) |
2987 | return static_cast<InitAndBitWidth*>(Ptr)->Init; |
2988 | return static_cast<Expr*>(Ptr); |
2989 | } |
2990 | |
2991 | |
2992 | void setInClassInitializer(Expr *Init) { |
2993 | assert(hasInClassInitializer() && !getInClassInitializer()); |
2994 | if (BitField) |
2995 | static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init; |
2996 | else |
2997 | InitStorage.setPointer(Init); |
2998 | } |
2999 | |
3000 | |
3001 | void removeInClassInitializer() { |
3002 | assert(hasInClassInitializer() && "no initializer to remove"); |
3003 | InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit); |
3004 | } |
3005 | |
3006 | |
3007 | |
3008 | bool hasCapturedVLAType() const { |
3009 | return InitStorage.getInt() == ISK_CapturedVLAType; |
3010 | } |
3011 | |
3012 | |
3013 | const VariableArrayType *getCapturedVLAType() const { |
3014 | return hasCapturedVLAType() ? static_cast<const VariableArrayType *>( |
3015 | InitStorage.getPointer()) |
3016 | : nullptr; |
3017 | } |
3018 | |
3019 | |
3020 | void setCapturedVLAType(const VariableArrayType *VLAType); |
3021 | |
3022 | |
3023 | |
3024 | |
3025 | |
3026 | |
3027 | const RecordDecl *getParent() const { |
3028 | return dyn_cast<RecordDecl>(getDeclContext()); |
3029 | } |
3030 | |
3031 | RecordDecl *getParent() { |
3032 | return dyn_cast<RecordDecl>(getDeclContext()); |
3033 | } |
3034 | |
3035 | SourceRange getSourceRange() const override LLVM_READONLY; |
3036 | |
3037 | |
3038 | FieldDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3039 | const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3040 | |
3041 | |
3042 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3043 | static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } |
3044 | }; |
3045 | |
3046 | |
3047 | |
3048 | |
3049 | |
3050 | class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> { |
3051 | Stmt *Init; |
3052 | llvm::APSInt Val; |
3053 | |
3054 | protected: |
3055 | EnumConstantDecl(DeclContext *DC, SourceLocation L, |
3056 | IdentifierInfo *Id, QualType T, Expr *E, |
3057 | const llvm::APSInt &V) |
3058 | : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {} |
3059 | |
3060 | public: |
3061 | friend class StmtIteratorBase; |
3062 | |
3063 | static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC, |
3064 | SourceLocation L, IdentifierInfo *Id, |
3065 | QualType T, Expr *E, |
3066 | const llvm::APSInt &V); |
3067 | static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3068 | |
3069 | const Expr *getInitExpr() const { return (const Expr*) Init; } |
3070 | Expr *getInitExpr() { return (Expr*) Init; } |
3071 | const llvm::APSInt &getInitVal() const { return Val; } |
3072 | |
3073 | void setInitExpr(Expr *E) { Init = (Stmt*) E; } |
3074 | void setInitVal(const llvm::APSInt &V) { Val = V; } |
3075 | |
3076 | SourceRange getSourceRange() const override LLVM_READONLY; |
3077 | |
3078 | |
3079 | EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3080 | const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3081 | |
3082 | |
3083 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3084 | static bool classofKind(Kind K) { return K == EnumConstant; } |
3085 | }; |
3086 | |
3087 | |
3088 | |
3089 | class IndirectFieldDecl : public ValueDecl, |
3090 | public Mergeable<IndirectFieldDecl> { |
3091 | NamedDecl **Chaining; |
3092 | unsigned ChainingSize; |
3093 | |
3094 | IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
3095 | DeclarationName N, QualType T, |
3096 | MutableArrayRef<NamedDecl *> CH); |
3097 | |
3098 | void anchor() override; |
3099 | |
3100 | public: |
3101 | friend class ASTDeclReader; |
3102 | |
3103 | static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC, |
3104 | SourceLocation L, IdentifierInfo *Id, |
3105 | QualType T, llvm::MutableArrayRef<NamedDecl *> CH); |
3106 | |
3107 | static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3108 | |
3109 | using chain_iterator = ArrayRef<NamedDecl *>::const_iterator; |
3110 | |
3111 | ArrayRef<NamedDecl *> chain() const { |
3112 | return llvm::makeArrayRef(Chaining, ChainingSize); |
3113 | } |
3114 | chain_iterator chain_begin() const { return chain().begin(); } |
3115 | chain_iterator chain_end() const { return chain().end(); } |
3116 | |
3117 | unsigned getChainingSize() const { return ChainingSize; } |
3118 | |
3119 | FieldDecl *getAnonField() const { |
3120 | assert(chain().size() >= 2); |
3121 | return cast<FieldDecl>(chain().back()); |
3122 | } |
3123 | |
3124 | VarDecl *getVarDecl() const { |
3125 | assert(chain().size() >= 2); |
3126 | return dyn_cast<VarDecl>(chain().front()); |
3127 | } |
3128 | |
3129 | IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3130 | const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3131 | |
3132 | |
3133 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3134 | static bool classofKind(Kind K) { return K == IndirectField; } |
3135 | }; |
3136 | |
3137 | |
3138 | class TypeDecl : public NamedDecl { |
3139 | friend class ASTContext; |
3140 | |
3141 | |
3142 | |
3143 | |
3144 | |
3145 | mutable const Type *TypeForDecl = nullptr; |
3146 | |
3147 | |
3148 | SourceLocation LocStart; |
3149 | |
3150 | void anchor() override; |
3151 | |
3152 | protected: |
3153 | TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, |
3154 | SourceLocation StartL = SourceLocation()) |
3155 | : NamedDecl(DK, DC, L, Id), LocStart(StartL) {} |
3156 | |
3157 | public: |
3158 | |
3159 | |
3160 | |
3161 | |
3162 | const Type *getTypeForDecl() const { return TypeForDecl; } |
3163 | void setTypeForDecl(const Type *TD) { TypeForDecl = TD; } |
3164 | |
3165 | SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; } |
3166 | void setLocStart(SourceLocation L) { LocStart = L; } |
3167 | SourceRange getSourceRange() const override LLVM_READONLY { |
3168 | if (LocStart.isValid()) |
3169 | return SourceRange(LocStart, getLocation()); |
3170 | else |
3171 | return SourceRange(getLocation()); |
3172 | } |
3173 | |
3174 | |
3175 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3176 | static bool classofKind(Kind K) { return K >= firstType && K <= lastType; } |
3177 | }; |
3178 | |
3179 | |
3180 | class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> { |
3181 | struct alignas(8) ModedTInfo { |
3182 | TypeSourceInfo *first; |
3183 | QualType second; |
3184 | }; |
3185 | |
3186 | |
3187 | |
3188 | mutable llvm::PointerIntPair< |
3189 | llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2> |
3190 | MaybeModedTInfo; |
3191 | |
3192 | void anchor() override; |
3193 | |
3194 | protected: |
3195 | TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, |
3196 | SourceLocation StartLoc, SourceLocation IdLoc, |
3197 | IdentifierInfo *Id, TypeSourceInfo *TInfo) |
3198 | : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C), |
3199 | MaybeModedTInfo(TInfo, 0) {} |
3200 | |
3201 | using redeclarable_base = Redeclarable<TypedefNameDecl>; |
3202 | |
3203 | TypedefNameDecl *getNextRedeclarationImpl() override { |
3204 | return getNextRedeclaration(); |
3205 | } |
3206 | |
3207 | TypedefNameDecl *getPreviousDeclImpl() override { |
3208 | return getPreviousDecl(); |
3209 | } |
3210 | |
3211 | TypedefNameDecl *getMostRecentDeclImpl() override { |
3212 | return getMostRecentDecl(); |
3213 | } |
3214 | |
3215 | public: |
3216 | using redecl_range = redeclarable_base::redecl_range; |
3217 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3218 | |
3219 | using redeclarable_base::redecls_begin; |
3220 | using redeclarable_base::redecls_end; |
3221 | using redeclarable_base::redecls; |
3222 | using redeclarable_base::getPreviousDecl; |
3223 | using redeclarable_base::getMostRecentDecl; |
3224 | using redeclarable_base::isFirstDecl; |
3225 | |
3226 | bool isModed() const { |
3227 | return MaybeModedTInfo.getPointer().is<ModedTInfo *>(); |
3228 | } |
3229 | |
3230 | TypeSourceInfo *getTypeSourceInfo() const { |
3231 | return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first |
3232 | : MaybeModedTInfo.getPointer().get<TypeSourceInfo *>(); |
3233 | } |
3234 | |
3235 | QualType getUnderlyingType() const { |
3236 | return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second |
3237 | : MaybeModedTInfo.getPointer() |
3238 | .get<TypeSourceInfo *>() |
3239 | ->getType(); |
3240 | } |
3241 | |
3242 | void setTypeSourceInfo(TypeSourceInfo *newType) { |
3243 | MaybeModedTInfo.setPointer(newType); |
3244 | } |
3245 | |
3246 | void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) { |
3247 | MaybeModedTInfo.setPointer(new (getASTContext(), 8) |
3248 | ModedTInfo({unmodedTSI, modedTy})); |
3249 | } |
3250 | |
3251 | |
3252 | TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3253 | const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3254 | |
3255 | |
3256 | |
3257 | |
3258 | |
3259 | |
3260 | TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const; |
3261 | |
3262 | |
3263 | |
3264 | bool isTransparentTag() const { |
3265 | if (MaybeModedTInfo.getInt()) |
3266 | return MaybeModedTInfo.getInt() & 0x2; |
3267 | return isTransparentTagSlow(); |
3268 | } |
3269 | |
3270 | |
3271 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3272 | static bool classofKind(Kind K) { |
3273 | return K >= firstTypedefName && K <= lastTypedefName; |
3274 | } |
3275 | |
3276 | private: |
3277 | bool isTransparentTagSlow() const; |
3278 | }; |
3279 | |
3280 | |
3281 | |
3282 | class TypedefDecl : public TypedefNameDecl { |
3283 | TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3284 | SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) |
3285 | : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {} |
3286 | |
3287 | public: |
3288 | static TypedefDecl *Create(ASTContext &C, DeclContext *DC, |
3289 | SourceLocation StartLoc, SourceLocation IdLoc, |
3290 | IdentifierInfo *Id, TypeSourceInfo *TInfo); |
3291 | static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3292 | |
3293 | SourceRange getSourceRange() const override LLVM_READONLY; |
3294 | |
3295 | |
3296 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3297 | static bool classofKind(Kind K) { return K == Typedef; } |
3298 | }; |
3299 | |
3300 | |
3301 | |
3302 | class TypeAliasDecl : public TypedefNameDecl { |
3303 | |
3304 | TypeAliasTemplateDecl *Template; |
3305 | |
3306 | TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3307 | SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) |
3308 | : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo), |
3309 | Template(nullptr) {} |
3310 | |
3311 | public: |
3312 | static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC, |
3313 | SourceLocation StartLoc, SourceLocation IdLoc, |
3314 | IdentifierInfo *Id, TypeSourceInfo *TInfo); |
3315 | static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3316 | |
3317 | SourceRange getSourceRange() const override LLVM_READONLY; |
3318 | |
3319 | TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; } |
3320 | void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; } |
3321 | |
3322 | |
3323 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3324 | static bool classofKind(Kind K) { return K == TypeAlias; } |
3325 | }; |
3326 | |
3327 | |
3328 | class TagDecl : public TypeDecl, |
3329 | public DeclContext, |
3330 | public Redeclarable<TagDecl> { |
3331 | |
3332 | |
3333 | public: |
3334 | |
3335 | using TagKind = TagTypeKind; |
3336 | |
3337 | private: |
3338 | SourceRange BraceRange; |
3339 | |
3340 | |
3341 | |
3342 | using ExtInfo = QualifierInfo; |
3343 | |
3344 | |
3345 | |
3346 | |
3347 | |
3348 | |
3349 | |
3350 | |
3351 | |
3352 | llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier; |
3353 | |
3354 | bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); } |
3355 | ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); } |
3356 | const ExtInfo *getExtInfo() const { |
3357 | return TypedefNameDeclOrQualifier.get<ExtInfo *>(); |
3358 | } |
3359 | |
3360 | protected: |
3361 | TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, |
3362 | SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, |
3363 | SourceLocation StartL); |
3364 | |
3365 | using redeclarable_base = Redeclarable<TagDecl>; |
3366 | |
3367 | TagDecl *getNextRedeclarationImpl() override { |
3368 | return getNextRedeclaration(); |
3369 | } |
3370 | |
3371 | TagDecl *getPreviousDeclImpl() override { |
3372 | return getPreviousDecl(); |
3373 | } |
3374 | |
3375 | TagDecl *getMostRecentDeclImpl() override { |
3376 | return getMostRecentDecl(); |
3377 | } |
3378 | |
3379 | |
3380 | |
3381 | |
3382 | void completeDefinition(); |
3383 | |
3384 | |
3385 | void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; } |
3386 | |
3387 | |
3388 | |
3389 | |
3390 | |
3391 | void setMayHaveOutOfDateDef(bool V = true) { |
3392 | TagDeclBits.MayHaveOutOfDateDef = V; |
3393 | } |
3394 | |
3395 | public: |
3396 | friend class ASTDeclReader; |
3397 | friend class ASTDeclWriter; |
3398 | |
3399 | using redecl_range = redeclarable_base::redecl_range; |
3400 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3401 | |
3402 | using redeclarable_base::redecls_begin; |
3403 | using redeclarable_base::redecls_end; |
3404 | using redeclarable_base::redecls; |
3405 | using redeclarable_base::getPreviousDecl; |
3406 | using redeclarable_base::getMostRecentDecl; |
3407 | using redeclarable_base::isFirstDecl; |
3408 | |
3409 | SourceRange getBraceRange() const { return BraceRange; } |
3410 | void setBraceRange(SourceRange R) { BraceRange = R; } |
3411 | |
3412 | |
3413 | |
3414 | SourceLocation getInnerLocStart() const { return getBeginLoc(); } |
3415 | |
3416 | |
3417 | |
3418 | SourceLocation getOuterLocStart() const; |
3419 | SourceRange getSourceRange() const override LLVM_READONLY; |
3420 | |
3421 | TagDecl *getCanonicalDecl() override; |
3422 | const TagDecl *getCanonicalDecl() const { |
3423 | return const_cast<TagDecl*>(this)->getCanonicalDecl(); |
3424 | } |
3425 | |
3426 | |
3427 | |
3428 | bool isThisDeclarationADefinition() const { |
3429 | return isCompleteDefinition(); |
3430 | } |
3431 | |
3432 | |
3433 | bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; } |
3434 | |
3435 | |
3436 | void setCompleteDefinition(bool V = true) { |
3437 | TagDeclBits.IsCompleteDefinition = V; |
3438 | } |
3439 | |
3440 | |
3441 | |
3442 | bool isCompleteDefinitionRequired() const { |
3443 | return TagDeclBits.IsCompleteDefinitionRequired; |
3444 | } |
3445 | |
3446 | |
3447 | |
3448 | void setCompleteDefinitionRequired(bool V = true) { |
3449 | TagDeclBits.IsCompleteDefinitionRequired = V; |
3450 | } |
3451 | |
3452 | |
3453 | bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; } |
3454 | |
3455 | |
3456 | |
3457 | bool isEmbeddedInDeclarator() const { |
3458 | return TagDeclBits.IsEmbeddedInDeclarator; |
3459 | } |
3460 | |
3461 | |
3462 | |
3463 | void setEmbeddedInDeclarator(bool isInDeclarator) { |
3464 | TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator; |
3465 | } |
3466 | |
3467 | |
3468 | bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; } |
3469 | |
3470 | |
3471 | void setFreeStanding(bool isFreeStanding = true) { |
3472 | TagDeclBits.IsFreeStanding = isFreeStanding; |
3473 | } |
3474 | |
3475 | |
3476 | |
3477 | |
3478 | |
3479 | bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; } |
3480 | |
3481 | |
3482 | |
3483 | |
3484 | bool isDependentType() const { return isDependentContext(); } |
3485 | |
3486 | |
3487 | |
3488 | |
3489 | |
3490 | |
3491 | void startDefinition(); |
3492 | |
3493 | |
3494 | |
3495 | |
3496 | |
3497 | |
3498 | |
3499 | |
3500 | |
3501 | TagDecl *getDefinition() const; |
3502 | |
3503 | StringRef getKindName() const { |
3504 | return TypeWithKeyword::getTagTypeKindName(getTagKind()); |
3505 | } |
3506 | |
3507 | TagKind getTagKind() const { |
3508 | return static_cast<TagKind>(TagDeclBits.TagDeclKind); |
3509 | } |
3510 | |
3511 | void setTagKind(TagKind TK) { TagDeclBits.TagDeclKind = TK; } |
3512 | |
3513 | bool isStruct() const { return getTagKind() == TTK_Struct; } |
3514 | bool isInterface() const { return getTagKind() == TTK_Interface; } |
3515 | bool isClass() const { return getTagKind() == TTK_Class; } |
3516 | bool isUnion() const { return getTagKind() == TTK_Union; } |
| 9 | | Assuming the condition is true | |
|
| 10 | | Returning the value 1, which participates in a condition later | |
|
3517 | bool isEnum() const { return getTagKind() == TTK_Enum; } |
3518 | |
3519 | |
3520 | |
3521 | |
3522 | |
3523 | |
3524 | |
3525 | |
3526 | |
3527 | |
3528 | |
3529 | |
3530 | |
3531 | |
3532 | |
3533 | |
3534 | bool hasNameForLinkage() const { |
3535 | return (getDeclName() || getTypedefNameForAnonDecl()); |
3536 | } |
3537 | |
3538 | TypedefNameDecl *getTypedefNameForAnonDecl() const { |
3539 | return hasExtInfo() ? nullptr |
3540 | : TypedefNameDeclOrQualifier.get<TypedefNameDecl *>(); |
3541 | } |
3542 | |
3543 | void setTypedefNameForAnonDecl(TypedefNameDecl *TDD); |
3544 | |
3545 | |
3546 | |
3547 | NestedNameSpecifier *getQualifier() const { |
3548 | return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() |
3549 | : nullptr; |
3550 | } |
3551 | |
3552 | |
3553 | |
3554 | |
3555 | NestedNameSpecifierLoc getQualifierLoc() const { |
3556 | return hasExtInfo() ? getExtInfo()->QualifierLoc |
3557 | : NestedNameSpecifierLoc(); |
3558 | } |
3559 | |
3560 | void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); |
3561 | |
3562 | unsigned getNumTemplateParameterLists() const { |
3563 | return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; |
3564 | } |
3565 | |
3566 | TemplateParameterList *getTemplateParameterList(unsigned i) const { |
3567 | assert(i < getNumTemplateParameterLists()); |
3568 | return getExtInfo()->TemplParamLists[i]; |
3569 | } |
3570 | |
3571 | void setTemplateParameterListsInfo(ASTContext &Context, |
3572 | ArrayRef<TemplateParameterList *> TPLists); |
3573 | |
3574 | |
3575 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3576 | static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; } |
3577 | |
3578 | static DeclContext *castToDeclContext(const TagDecl *D) { |
3579 | return static_cast<DeclContext *>(const_cast<TagDecl*>(D)); |
3580 | } |
3581 | |
3582 | static TagDecl *castFromDeclContext(const DeclContext *DC) { |
3583 | return static_cast<TagDecl *>(const_cast<DeclContext*>(DC)); |
3584 | } |
3585 | }; |
3586 | |
3587 | |
3588 | |
3589 | |
3590 | class EnumDecl : public TagDecl { |
3591 | |
3592 | |
3593 | |
3594 | |
3595 | |
3596 | |
3597 | |
3598 | |
3599 | |
3600 | |
3601 | |
3602 | |
3603 | |
3604 | |
3605 | |
3606 | |
3607 | |
3608 | llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType; |
3609 | |
3610 | |
3611 | |
3612 | |
3613 | |
3614 | QualType PromotionType; |
3615 | |
3616 | |
3617 | |
3618 | |
3619 | MemberSpecializationInfo *SpecializationInfo = nullptr; |
3620 | |
3621 | |
3622 | |
3623 | |
3624 | unsigned ODRHash; |
3625 | |
3626 | EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3627 | SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, |
3628 | bool Scoped, bool ScopedUsingClassTag, bool Fixed); |
3629 | |
3630 | void anchor() override; |
3631 | |
3632 | void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, |
3633 | TemplateSpecializationKind TSK); |
3634 | |
3635 | |
3636 | |
3637 | void setNumPositiveBits(unsigned Num) { |
3638 | EnumDeclBits.NumPositiveBits = Num; |
3639 | assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount"); |
3640 | } |
3641 | |
3642 | |
3643 | |
3644 | void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; } |
3645 | |
3646 | public: |
3647 | |
3648 | |
3649 | void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; } |
3650 | |
3651 | |
3652 | |
3653 | |
3654 | |
3655 | void setScopedUsingClassTag(bool ScopedUCT = true) { |
3656 | EnumDeclBits.IsScopedUsingClassTag = ScopedUCT; |
3657 | } |
3658 | |
3659 | |
3660 | |
3661 | void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; } |
3662 | |
3663 | private: |
3664 | |
3665 | bool hasODRHash() const { return EnumDeclBits.HasODRHash; } |
3666 | void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; } |
3667 | |
3668 | public: |
3669 | friend class ASTDeclReader; |
3670 | |
3671 | EnumDecl *getCanonicalDecl() override { |
3672 | return cast<EnumDecl>(TagDecl::getCanonicalDecl()); |
3673 | } |
3674 | const EnumDecl *getCanonicalDecl() const { |
3675 | return const_cast<EnumDecl*>(this)->getCanonicalDecl(); |
3676 | } |
3677 | |
3678 | EnumDecl *getPreviousDecl() { |
3679 | return cast_or_null<EnumDecl>( |
3680 | static_cast<TagDecl *>(this)->getPreviousDecl()); |
3681 | } |
3682 | const EnumDecl *getPreviousDecl() const { |
3683 | return const_cast<EnumDecl*>(this)->getPreviousDecl(); |
3684 | } |
3685 | |
3686 | EnumDecl *getMostRecentDecl() { |
3687 | return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl()); |
3688 | } |
3689 | const EnumDecl *getMostRecentDecl() const { |
3690 | return const_cast<EnumDecl*>(this)->getMostRecentDecl(); |
3691 | } |
3692 | |
3693 | EnumDecl *getDefinition() const { |
3694 | return cast_or_null<EnumDecl>(TagDecl::getDefinition()); |
3695 | } |
3696 | |
3697 | static EnumDecl *Create(ASTContext &C, DeclContext *DC, |
3698 | SourceLocation StartLoc, SourceLocation IdLoc, |
3699 | IdentifierInfo *Id, EnumDecl *PrevDecl, |
3700 | bool IsScoped, bool IsScopedUsingClassTag, |
3701 | bool IsFixed); |
3702 | static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3703 | |
3704 | |
3705 | |
3706 | |
3707 | |
3708 | |
3709 | void completeDefinition(QualType NewType, |
3710 | QualType PromotionType, |
3711 | unsigned NumPositiveBits, |
3712 | unsigned NumNegativeBits); |
3713 | |
3714 | |
3715 | using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>; |
3716 | using enumerator_range = |
3717 | llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>; |
3718 | |
3719 | enumerator_range enumerators() const { |
3720 | return enumerator_range(enumerator_begin(), enumerator_end()); |
3721 | } |
3722 | |
3723 | enumerator_iterator enumerator_begin() const { |
3724 | const EnumDecl *E = getDefinition(); |
3725 | if (!E) |
3726 | E = this; |
3727 | return enumerator_iterator(E->decls_begin()); |
3728 | } |
3729 | |
3730 | enumerator_iterator enumerator_end() const { |
3731 | const EnumDecl *E = getDefinition(); |
3732 | if (!E) |
3733 | E = this; |
3734 | return enumerator_iterator(E->decls_end()); |
3735 | } |
3736 | |
3737 | |
3738 | QualType getPromotionType() const { return PromotionType; } |
3739 | |
3740 | |
3741 | void setPromotionType(QualType T) { PromotionType = T; } |
3742 | |
3743 | |
3744 | |
3745 | |
3746 | QualType getIntegerType() const { |
3747 | if (!IntegerType) |
3748 | return QualType(); |
3749 | if (const Type *T = IntegerType.dyn_cast<const Type*>()) |
3750 | return QualType(T, 0); |
3751 | return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType(); |
3752 | } |
3753 | |
3754 | |
3755 | void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); } |
3756 | |
3757 | |
3758 | void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; } |
3759 | |
3760 | |
3761 | |
3762 | TypeSourceInfo *getIntegerTypeSourceInfo() const { |
3763 | return IntegerType.dyn_cast<TypeSourceInfo*>(); |
3764 | } |
3765 | |
3766 | |
3767 | |
3768 | SourceRange getIntegerTypeRange() const LLVM_READONLY; |
3769 | |
3770 | |
3771 | |
3772 | unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; } |
3773 | |
3774 | |
3775 | |
3776 | |
3777 | |
3778 | |
3779 | |
3780 | |
3781 | |
3782 | |
3783 | unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; } |
3784 | |
3785 | |
3786 | bool isScoped() const { return EnumDeclBits.IsScoped; } |
3787 | |
3788 | |
3789 | bool isScopedUsingClassTag() const { |
3790 | return EnumDeclBits.IsScopedUsingClassTag; |
3791 | } |
3792 | |
3793 | |
3794 | |
3795 | bool isFixed() const { return EnumDeclBits.IsFixed; } |
3796 | |
3797 | unsigned getODRHash(); |
3798 | |
3799 | |
3800 | bool isComplete() const { |
3801 | |
3802 | |
3803 | return isCompleteDefinition() || IntegerType; |
3804 | } |
3805 | |
3806 | |
3807 | |
3808 | bool isClosed() const; |
3809 | |
3810 | |
3811 | |
3812 | bool isClosedFlag() const; |
3813 | |
3814 | |
3815 | |
3816 | bool isClosedNonFlag() const; |
3817 | |
3818 | |
3819 | |
3820 | EnumDecl *getTemplateInstantiationPattern() const; |
3821 | |
3822 | |
3823 | |
3824 | |
3825 | EnumDecl *getInstantiatedFromMemberEnum() const; |
3826 | |
3827 | |
3828 | |
3829 | |
3830 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
3831 | |
3832 | |
3833 | |
3834 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK, |
3835 | SourceLocation PointOfInstantiation = SourceLocation()); |
3836 | |
3837 | |
3838 | |
3839 | |
3840 | MemberSpecializationInfo *getMemberSpecializationInfo() const { |
3841 | return SpecializationInfo; |
3842 | } |
3843 | |
3844 | |
3845 | |
3846 | void setInstantiationOfMemberEnum(EnumDecl *ED, |
3847 | TemplateSpecializationKind TSK) { |
3848 | setInstantiationOfMemberEnum(getASTContext(), ED, TSK); |
3849 | } |
3850 | |
3851 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3852 | static bool classofKind(Kind K) { return K == Enum; } |
3853 | }; |
3854 | |
3855 | |
3856 | |
3857 | |
3858 | |
3859 | class RecordDecl : public TagDecl { |
3860 | |
3861 | |
3862 | public: |
3863 | friend class DeclContext; |
3864 | |
3865 | |
3866 | |
3867 | |
3868 | enum ArgPassingKind : unsigned { |
3869 | |
3870 | APK_CanPassInRegs, |
3871 | |
3872 | |
3873 | |
3874 | |
3875 | |
3876 | |
3877 | |
3878 | |
3879 | APK_CannotPassInRegs, |
3880 | |
3881 | |
3882 | |
3883 | |
3884 | APK_CanNeverPassInRegs |
3885 | }; |
3886 | |
3887 | protected: |
3888 | RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, |
3889 | SourceLocation StartLoc, SourceLocation IdLoc, |
3890 | IdentifierInfo *Id, RecordDecl *PrevDecl); |
3891 | |
3892 | public: |
3893 | static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
3894 | SourceLocation StartLoc, SourceLocation IdLoc, |
3895 | IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr); |
3896 | static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
3897 | |
3898 | RecordDecl *getPreviousDecl() { |
3899 | return cast_or_null<RecordDecl>( |
3900 | static_cast<TagDecl *>(this)->getPreviousDecl()); |
3901 | } |
3902 | const RecordDecl *getPreviousDecl() const { |
3903 | return const_cast<RecordDecl*>(this)->getPreviousDecl(); |
3904 | } |
3905 | |
3906 | RecordDecl *getMostRecentDecl() { |
3907 | return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl()); |
3908 | } |
3909 | const RecordDecl *getMostRecentDecl() const { |
3910 | return const_cast<RecordDecl*>(this)->getMostRecentDecl(); |
3911 | } |
3912 | |
3913 | bool hasFlexibleArrayMember() const { |
3914 | return RecordDeclBits.HasFlexibleArrayMember; |
3915 | } |
3916 | |
3917 | void setHasFlexibleArrayMember(bool V) { |
3918 | RecordDeclBits.HasFlexibleArrayMember = V; |
3919 | } |
3920 | |
3921 | |
3922 | |
3923 | |
3924 | |
3925 | |
3926 | |
3927 | |
3928 | |
3929 | |
3930 | |
3931 | |
3932 | bool isAnonymousStructOrUnion() const { |
3933 | return RecordDeclBits.AnonymousStructOrUnion; |
3934 | } |
3935 | |
3936 | void setAnonymousStructOrUnion(bool Anon) { |
3937 | RecordDeclBits.AnonymousStructOrUnion = Anon; |
3938 | } |
3939 | |
3940 | bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; } |
3941 | void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; } |
3942 | |
3943 | bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; } |
3944 | |
3945 | void setHasVolatileMember(bool val) { |
3946 | RecordDeclBits.HasVolatileMember = val; |
3947 | } |
3948 | |
3949 | bool hasLoadedFieldsFromExternalStorage() const { |
3950 | return RecordDeclBits.LoadedFieldsFromExternalStorage; |
3951 | } |
3952 | |
3953 | void setHasLoadedFieldsFromExternalStorage(bool val) const { |
3954 | RecordDeclBits.LoadedFieldsFromExternalStorage = val; |
3955 | } |
3956 | |
3957 | |
3958 | bool isNonTrivialToPrimitiveDefaultInitialize() const { |
3959 | return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize; |
3960 | } |
3961 | |
3962 | void setNonTrivialToPrimitiveDefaultInitialize(bool V) { |
3963 | RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V; |
3964 | } |
3965 | |
3966 | bool isNonTrivialToPrimitiveCopy() const { |
3967 | return RecordDeclBits.NonTrivialToPrimitiveCopy; |
3968 | } |
3969 | |
3970 | void setNonTrivialToPrimitiveCopy(bool V) { |
3971 | RecordDeclBits.NonTrivialToPrimitiveCopy = V; |
3972 | } |
3973 | |
3974 | bool isNonTrivialToPrimitiveDestroy() const { |
3975 | return RecordDeclBits.NonTrivialToPrimitiveDestroy; |
3976 | } |
3977 | |
3978 | void setNonTrivialToPrimitiveDestroy(bool V) { |
3979 | RecordDeclBits.NonTrivialToPrimitiveDestroy = V; |
3980 | } |
3981 | |
3982 | bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const { |
3983 | return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion; |
3984 | } |
3985 | |
3986 | void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V) { |
3987 | RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V; |
3988 | } |
3989 | |
3990 | bool hasNonTrivialToPrimitiveDestructCUnion() const { |
3991 | return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion; |
3992 | } |
3993 | |
3994 | void setHasNonTrivialToPrimitiveDestructCUnion(bool V) { |
3995 | RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V; |
3996 | } |
3997 | |
3998 | bool hasNonTrivialToPrimitiveCopyCUnion() const { |
3999 | return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion; |
4000 | } |
4001 | |
4002 | void setHasNonTrivialToPrimitiveCopyCUnion(bool V) { |
4003 | RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V; |
4004 | } |
4005 | |
4006 | |
4007 | |
4008 | |
4009 | bool canPassInRegisters() const { |
4010 | return getArgPassingRestrictions() == APK_CanPassInRegs; |
4011 | } |
4012 | |
4013 | ArgPassingKind getArgPassingRestrictions() const { |
4014 | return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions); |
4015 | } |
4016 | |
4017 | void setArgPassingRestrictions(ArgPassingKind Kind) { |
4018 | RecordDeclBits.ArgPassingRestrictions = Kind; |
4019 | } |
4020 | |
4021 | bool isParamDestroyedInCallee() const { |
4022 | return RecordDeclBits.ParamDestroyedInCallee; |
4023 | } |
4024 | |
4025 | void setParamDestroyedInCallee(bool V) { |
4026 | RecordDeclBits.ParamDestroyedInCallee = V; |
4027 | } |
4028 | |
4029 | |
4030 | |
4031 | |
4032 | |
4033 | |
4034 | |
4035 | |
4036 | |
4037 | |
4038 | |
4039 | |
4040 | |
4041 | |
4042 | bool isInjectedClassName() const; |
4043 | |
4044 | |
4045 | |
4046 | bool isLambda() const; |
4047 | |
4048 | |
4049 | |
4050 | bool isCapturedRecord() const; |
4051 | |
4052 | |
4053 | |
4054 | void setCapturedRecord(); |
4055 | |
4056 | |
4057 | |
4058 | |
4059 | |
4060 | |
4061 | |
4062 | |
4063 | |
4064 | RecordDecl *getDefinition() const { |
4065 | return cast_or_null<RecordDecl>(TagDecl::getDefinition()); |
4066 | } |
4067 | |
4068 | |
4069 | |
4070 | |
4071 | bool isOrContainsUnion() const; |
4072 | |
4073 | |
4074 | |
4075 | |
4076 | using field_iterator = specific_decl_iterator<FieldDecl>; |
4077 | using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>; |
4078 | |
4079 | field_range fields() const { return field_range(field_begin(), field_end()); } |
4080 | field_iterator field_begin() const; |
4081 | |
4082 | field_iterator field_end() const { |
4083 | return field_iterator(decl_iterator()); |
4084 | } |
4085 | |
4086 | |
4087 | bool field_empty() const { |
4088 | return field_begin() == field_end(); |
4089 | } |
4090 | |
4091 | |
4092 | virtual void completeDefinition(); |
4093 | |
4094 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4095 | static bool classofKind(Kind K) { |
4096 | return K >= firstRecord && K <= lastRecord; |
4097 | } |
4098 | |
4099 | |
4100 | |
4101 | |
4102 | bool isMsStruct(const ASTContext &C) const; |
4103 | |
4104 | |
4105 | |
4106 | |
4107 | bool mayInsertExtraPadding(bool EmitRemark = false) const; |
4108 | |
4109 | |
4110 | |
4111 | const FieldDecl *findFirstNamedDataMember() const; |
4112 | |
4113 | private: |
4114 | |
4115 | void LoadFieldsFromExternalStorage() const; |
4116 | }; |
4117 | |
4118 | class FileScopeAsmDecl : public Decl { |
4119 | StringLiteral *AsmString; |
4120 | SourceLocation RParenLoc; |
4121 | |
4122 | FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring, |
4123 | SourceLocation StartL, SourceLocation EndL) |
4124 | : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {} |
4125 | |
4126 | virtual void anchor(); |
4127 | |
4128 | public: |
4129 | static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, |
4130 | StringLiteral *Str, SourceLocation AsmLoc, |
4131 | SourceLocation RParenLoc); |
4132 | |
4133 | static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4134 | |
4135 | SourceLocation getAsmLoc() const { return getLocation(); } |
4136 | SourceLocation getRParenLoc() const { return RParenLoc; } |
4137 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
4138 | SourceRange getSourceRange() const override LLVM_READONLY { |
4139 | return SourceRange(getAsmLoc(), getRParenLoc()); |
4140 | } |
4141 | |
4142 | const StringLiteral *getAsmString() const { return AsmString; } |
4143 | StringLiteral *getAsmString() { return AsmString; } |
4144 | void setAsmString(StringLiteral *Asm) { AsmString = Asm; } |
4145 | |
4146 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4147 | static bool classofKind(Kind K) { return K == FileScopeAsm; } |
4148 | }; |
4149 | |
4150 | |
4151 | |
4152 | |
4153 | class BlockDecl : public Decl, public DeclContext { |
4154 | |
4155 | |
4156 | public: |
4157 | |
4158 | |
4159 | class Capture { |
4160 | enum { |
4161 | flag_isByRef = 0x1, |
4162 | flag_isNested = 0x2 |
4163 | }; |
4164 | |
4165 | |
4166 | llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags; |
4167 | |
4168 | |
4169 | |
4170 | |
4171 | Expr *CopyExpr; |
4172 | |
4173 | public: |
4174 | Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy) |
4175 | : VariableAndFlags(variable, |
4176 | (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)), |
4177 | CopyExpr(copy) {} |
4178 | |
4179 | |
4180 | VarDecl *getVariable() const { return VariableAndFlags.getPointer(); } |
4181 | |
4182 | |
4183 | |
4184 | bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; } |
4185 | |
4186 | bool isEscapingByref() const { |
4187 | return getVariable()->isEscapingByref(); |
4188 | } |
4189 | |
4190 | bool isNonEscapingByref() const { |
4191 | return getVariable()->isNonEscapingByref(); |
4192 | } |
4193 | |
4194 | |
4195 | |
4196 | bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; } |
4197 | |
4198 | bool hasCopyExpr() const { return CopyExpr != nullptr; } |
4199 | Expr *getCopyExpr() const { return CopyExpr; } |
4200 | void setCopyExpr(Expr *e) { CopyExpr = e; } |
4201 | }; |
4202 | |
4203 | private: |
4204 | |
4205 | |
4206 | |
4207 | ParmVarDecl **ParamInfo = nullptr; |
4208 | unsigned NumParams = 0; |
4209 | |
4210 | Stmt *Body = nullptr; |
4211 | TypeSourceInfo *SignatureAsWritten = nullptr; |
4212 | |
4213 | const Capture *Captures = nullptr; |
4214 | unsigned NumCaptures = 0; |
4215 | |
4216 | unsigned ManglingNumber = 0; |
4217 | Decl *ManglingContextDecl = nullptr; |
4218 | |
4219 | protected: |
4220 | BlockDecl(DeclContext *DC, SourceLocation CaretLoc); |
4221 | |
4222 | public: |
4223 | static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); |
4224 | static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4225 | |
4226 | SourceLocation getCaretLocation() const { return getLocation(); } |
4227 | |
4228 | bool isVariadic() const { return BlockDeclBits.IsVariadic; } |
4229 | void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; } |
4230 | |
4231 | CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; } |
4232 | Stmt *getBody() const override { return (Stmt*) Body; } |
4233 | void setBody(CompoundStmt *B) { Body = (Stmt*) B; } |
4234 | |
4235 | void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; } |
4236 | TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; } |
4237 | |
4238 | |
4239 | ArrayRef<ParmVarDecl *> parameters() const { |
4240 | return {ParamInfo, getNumParams()}; |
4241 | } |
4242 | MutableArrayRef<ParmVarDecl *> parameters() { |
4243 | return {ParamInfo, getNumParams()}; |
4244 | } |
4245 | |
4246 | |
4247 | using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator; |
4248 | using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator; |
4249 | |
4250 | bool param_empty() const { return parameters().empty(); } |
4251 | param_iterator param_begin() { return parameters().begin(); } |
4252 | param_iterator param_end() { return parameters().end(); } |
4253 | param_const_iterator param_begin() const { return parameters().begin(); } |
4254 | param_const_iterator param_end() const { return parameters().end(); } |
4255 | size_t param_size() const { return parameters().size(); } |
4256 | |
4257 | unsigned getNumParams() const { return NumParams; } |
4258 | |
4259 | const ParmVarDecl *getParamDecl(unsigned i) const { |
4260 | assert(i < getNumParams() && "Illegal param #"); |
4261 | return ParamInfo[i]; |
4262 | } |
4263 | ParmVarDecl *getParamDecl(unsigned i) { |
4264 | assert(i < getNumParams() && "Illegal param #"); |
4265 | return ParamInfo[i]; |
4266 | } |
4267 | |
4268 | void setParams(ArrayRef<ParmVarDecl *> NewParamInfo); |
4269 | |
4270 | |
4271 | |
4272 | bool hasCaptures() const { return NumCaptures || capturesCXXThis(); } |
4273 | |
4274 | |
4275 | |
4276 | unsigned getNumCaptures() const { return NumCaptures; } |
4277 | |
4278 | using capture_const_iterator = ArrayRef<Capture>::const_iterator; |
4279 | |
4280 | ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; } |
4281 | |
4282 | capture_const_iterator capture_begin() const { return captures().begin(); } |
4283 | capture_const_iterator capture_end() const { return captures().end(); } |
4284 | |
4285 | bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; } |
4286 | void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; } |
4287 | |
4288 | bool blockMissingReturnType() const { |
4289 | return BlockDeclBits.BlockMissingReturnType; |
4290 | } |
4291 | |
4292 | void setBlockMissingReturnType(bool val = true) { |
4293 | BlockDeclBits.BlockMissingReturnType = val; |
4294 | } |
4295 | |
4296 | bool isConversionFromLambda() const { |
4297 | return BlockDeclBits.IsConversionFromLambda; |
4298 | } |
4299 | |
4300 | void setIsConversionFromLambda(bool val = true) { |
4301 | BlockDeclBits.IsConversionFromLambda = val; |
4302 | } |
4303 | |
4304 | bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; } |
4305 | void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; } |
4306 | |
4307 | bool canAvoidCopyToHeap() const { |
4308 | return BlockDeclBits.CanAvoidCopyToHeap; |
4309 | } |
4310 | void setCanAvoidCopyToHeap(bool B = true) { |
4311 | BlockDeclBits.CanAvoidCopyToHeap = B; |
4312 | } |
4313 | |
4314 | bool capturesVariable(const VarDecl *var) const; |
4315 | |
4316 | void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures, |
4317 | bool CapturesCXXThis); |
4318 | |
4319 | unsigned getBlockManglingNumber() const { return ManglingNumber; } |
4320 | |
4321 | Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; } |
4322 | |
4323 | void setBlockMangling(unsigned Number, Decl *Ctx) { |
4324 | ManglingNumber = Number; |
4325 | ManglingContextDecl = Ctx; |
4326 | } |
4327 | |
4328 | SourceRange getSourceRange() const override LLVM_READONLY; |
4329 | |
4330 | |
4331 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4332 | static bool classofKind(Kind K) { return K == Block; } |
4333 | static DeclContext *castToDeclContext(const BlockDecl *D) { |
4334 | return static_cast<DeclContext *>(const_cast<BlockDecl*>(D)); |
4335 | } |
4336 | static BlockDecl *castFromDeclContext(const DeclContext *DC) { |
4337 | return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC)); |
4338 | } |
4339 | }; |
4340 | |
4341 | |
4342 | class CapturedDecl final |
4343 | : public Decl, |
4344 | public DeclContext, |
4345 | private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> { |
4346 | protected: |
4347 | size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) { |
4348 | return NumParams; |
4349 | } |
4350 | |
4351 | private: |
4352 | |
4353 | unsigned NumParams; |
4354 | |
4355 | |
4356 | unsigned ContextParam; |
4357 | |
4358 | |
4359 | llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow; |
4360 | |
4361 | explicit CapturedDecl(DeclContext *DC, unsigned NumParams); |
4362 | |
4363 | ImplicitParamDecl *const *getParams() const { |
4364 | return getTrailingObjects<ImplicitParamDecl *>(); |
4365 | } |
4366 | |
4367 | ImplicitParamDecl **getParams() { |
4368 | return getTrailingObjects<ImplicitParamDecl *>(); |
4369 | } |
4370 | |
4371 | public: |
4372 | friend class ASTDeclReader; |
4373 | friend class ASTDeclWriter; |
4374 | friend TrailingObjects; |
4375 | |
4376 | static CapturedDecl *Create(ASTContext &C, DeclContext *DC, |
4377 | unsigned NumParams); |
4378 | static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
4379 | unsigned NumParams); |
4380 | |
4381 | Stmt *getBody() const override; |
4382 | void setBody(Stmt *B); |
4383 | |
4384 | bool isNothrow() const; |
4385 | void setNothrow(bool Nothrow = true); |
4386 | |
4387 | unsigned getNumParams() const { return NumParams; } |
4388 | |
4389 | ImplicitParamDecl *getParam(unsigned i) const { |
4390 | assert(i < NumParams); |
4391 | return getParams()[i]; |
4392 | } |
4393 | void setParam(unsigned i, ImplicitParamDecl *P) { |
4394 | assert(i < NumParams); |
4395 | getParams()[i] = P; |
4396 | } |
4397 | |
4398 | |
4399 | ArrayRef<ImplicitParamDecl *> parameters() const { |
4400 | return {getParams(), getNumParams()}; |
4401 | } |
4402 | MutableArrayRef<ImplicitParamDecl *> parameters() { |
4403 | return {getParams(), getNumParams()}; |
4404 | } |
4405 | |
4406 | |
4407 | ImplicitParamDecl *getContextParam() const { |
4408 | assert(ContextParam < NumParams); |
4409 | return getParam(ContextParam); |
4410 | } |
4411 | void setContextParam(unsigned i, ImplicitParamDecl *P) { |
4412 | assert(i < NumParams); |
4413 | ContextParam = i; |
4414 | setParam(i, P); |
4415 | } |
4416 | unsigned getContextParamPosition() const { return ContextParam; } |
4417 | |
4418 | using param_iterator = ImplicitParamDecl *const *; |
4419 | using param_range = llvm::iterator_range<param_iterator>; |
4420 | |
4421 | |
4422 | param_iterator param_begin() const { return getParams(); } |
4423 | |
4424 | param_iterator param_end() const { return getParams() + NumParams; } |
4425 | |
4426 | |
4427 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4428 | static bool classofKind(Kind K) { return K == Captured; } |
4429 | static DeclContext *castToDeclContext(const CapturedDecl *D) { |
4430 | return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D)); |
4431 | } |
4432 | static CapturedDecl *castFromDeclContext(const DeclContext *DC) { |
4433 | return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC)); |
4434 | } |
4435 | }; |
4436 | |
4437 | |
4438 | |
4439 | |
4440 | |
4441 | |
4442 | |
4443 | |
4444 | |
4445 | |
4446 | |
4447 | class ImportDecl final : public Decl, |
4448 | llvm::TrailingObjects<ImportDecl, SourceLocation> { |
4449 | friend class ASTContext; |
4450 | friend class ASTDeclReader; |
4451 | friend class ASTReader; |
4452 | friend TrailingObjects; |
4453 | |
4454 | |
4455 | Module *ImportedModule = nullptr; |
4456 | |
4457 | |
4458 | |
4459 | |
4460 | |
4461 | |
4462 | |
4463 | |
4464 | |
4465 | llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete; |
4466 | |
4467 | ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, |
4468 | ArrayRef<SourceLocation> IdentifierLocs); |
4469 | |
4470 | ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, |
4471 | SourceLocation EndLoc); |
4472 | |
4473 | ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {} |
4474 | |
4475 | bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); } |
4476 | |
4477 | void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); } |
4478 | |
4479 | |
4480 | |
4481 | ImportDecl *getNextLocalImport() const { |
4482 | return NextLocalImportAndComplete.getPointer(); |
4483 | } |
4484 | |
4485 | void setNextLocalImport(ImportDecl *Import) { |
4486 | NextLocalImportAndComplete.setPointer(Import); |
4487 | } |
4488 | |
4489 | public: |
4490 | |
4491 | static ImportDecl *Create(ASTContext &C, DeclContext *DC, |
4492 | SourceLocation StartLoc, Module *Imported, |
4493 | ArrayRef<SourceLocation> IdentifierLocs); |
4494 | |
4495 | |
4496 | |
4497 | static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, |
4498 | SourceLocation StartLoc, Module *Imported, |
4499 | SourceLocation EndLoc); |
4500 | |
4501 | |
4502 | static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
4503 | unsigned NumLocations); |
4504 | |
4505 | |
4506 | Module *getImportedModule() const { return ImportedModule; } |
4507 | |
4508 | |
4509 | |
4510 | |
4511 | |
4512 | |
4513 | ArrayRef<SourceLocation> getIdentifierLocs() const; |
4514 | |
4515 | SourceRange getSourceRange() const override LLVM_READONLY; |
4516 | |
4517 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4518 | static bool classofKind(Kind K) { return K == Import; } |
4519 | }; |
4520 | |
4521 | |
4522 | |
4523 | |
4524 | |
4525 | |
4526 | |
4527 | class ExportDecl final : public Decl, public DeclContext { |
4528 | virtual void anchor(); |
4529 | |
4530 | private: |
4531 | friend class ASTDeclReader; |
4532 | |
4533 | |
4534 | SourceLocation RBraceLoc; |
4535 | |
4536 | ExportDecl(DeclContext *DC, SourceLocation ExportLoc) |
4537 | : Decl(Export, DC, ExportLoc), DeclContext(Export), |
4538 | RBraceLoc(SourceLocation()) {} |
4539 | |
4540 | public: |
4541 | static ExportDecl *Create(ASTContext &C, DeclContext *DC, |
4542 | SourceLocation ExportLoc); |
4543 | static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4544 | |
4545 | SourceLocation getExportLoc() const { return getLocation(); } |
4546 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
4547 | void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } |
4548 | |
4549 | bool hasBraces() const { return RBraceLoc.isValid(); } |
4550 | |
4551 | SourceLocation getEndLoc() const LLVM_READONLY { |
4552 | if (hasBraces()) |
4553 | return RBraceLoc; |
4554 | |
4555 | |
4556 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
4557 | } |
4558 | |
4559 | SourceRange getSourceRange() const override LLVM_READONLY { |
4560 | return SourceRange(getLocation(), getEndLoc()); |
4561 | } |
4562 | |
4563 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4564 | static bool classofKind(Kind K) { return K == Export; } |
4565 | static DeclContext *castToDeclContext(const ExportDecl *D) { |
4566 | return static_cast<DeclContext *>(const_cast<ExportDecl*>(D)); |
4567 | } |
4568 | static ExportDecl *castFromDeclContext(const DeclContext *DC) { |
4569 | return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC)); |
4570 | } |
4571 | }; |
4572 | |
4573 | |
4574 | class EmptyDecl : public Decl { |
4575 | EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {} |
4576 | |
4577 | virtual void anchor(); |
4578 | |
4579 | public: |
4580 | static EmptyDecl *Create(ASTContext &C, DeclContext *DC, |
4581 | SourceLocation L); |
4582 | static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4583 | |
4584 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4585 | static bool classofKind(Kind K) { return K == Empty; } |
4586 | }; |
4587 | |
4588 | |
4589 | |
4590 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD, |
4591 | const NamedDecl *ND) { |
4592 | PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND), |
4593 | DiagnosticsEngine::ak_nameddecl); |
4594 | return PD; |
4595 | } |
4596 | |
4597 | template<typename decl_type> |
4598 | void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) { |
4599 | |
4600 | |
4601 | assert(RedeclLink.isFirst() && |
4602 | "setPreviousDecl on a decl already in a redeclaration chain"); |
4603 | |
4604 | if (PrevDecl) { |
4605 | |
4606 | |
4607 | |
4608 | First = PrevDecl->getFirstDecl(); |
4609 | assert(First->RedeclLink.isFirst() && "Expected first"); |
4610 | decl_type *MostRecent = First->getNextRedeclaration(); |
4611 | RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent)); |
4612 | |
4613 | |
4614 | |
4615 | static_cast<decl_type*>(this)->IdentifierNamespace |= |
4616 | MostRecent->getIdentifierNamespace() & |
4617 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); |
4618 | } else { |
4619 | |
4620 | First = static_cast<decl_type*>(this); |
4621 | } |
4622 | |
4623 | |
4624 | First->RedeclLink.setLatest(static_cast<decl_type*>(this)); |
4625 | |
4626 | assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) || |
4627 | cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid()); |
4628 | } |
4629 | |
4630 | |
4631 | |
4632 | |
4633 | |
4634 | |
4635 | |
4636 | inline bool IsEnumDeclComplete(EnumDecl *ED) { |
4637 | return ED->isComplete(); |
4638 | } |
4639 | |
4640 | |
4641 | |
4642 | |
4643 | |
4644 | inline bool IsEnumDeclScoped(EnumDecl *ED) { |
4645 | return ED->isScoped(); |
4646 | } |
4647 | |
4648 | |
4649 | |
4650 | |
4651 | static constexpr StringRef getOpenMPVariantManglingSeparatorStr() { |
4652 | return "$ompvariant"; |
4653 | } |
4654 | |
4655 | } |
4656 | |
4657 | #endif // LLVM_CLANG_AST_DECL_H |