clang  16.0.0git
MemRegion.cpp
Go to the documentation of this file.
1 //===- MemRegion.cpp - Abstract memory regions for static analysis --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines MemRegion and its subclasses. MemRegion defines a
10 // partially-typed abstraction of memory useful for path-sensitive dataflow
11 // analyses.
12 //
13 //===----------------------------------------------------------------------===//
14 
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"
24 #include "clang/AST/RecordLayout.h"
25 #include "clang/AST/Type.h"
29 #include "clang/Basic/LLVM.h"
36 #include "llvm/ADT/APInt.h"
37 #include "llvm/ADT/FoldingSet.h"
38 #include "llvm/ADT/Optional.h"
39 #include "llvm/ADT/PointerUnion.h"
40 #include "llvm/ADT/SmallString.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/Twine.h"
43 #include "llvm/Support/Allocator.h"
44 #include "llvm/Support/Casting.h"
45 #include "llvm/Support/CheckedArithmetic.h"
46 #include "llvm/Support/Compiler.h"
47 #include "llvm/Support/Debug.h"
48 #include "llvm/Support/ErrorHandling.h"
49 #include "llvm/Support/raw_ostream.h"
50 #include <cassert>
51 #include <cstdint>
52 #include <functional>
53 #include <iterator>
54 #include <string>
55 #include <tuple>
56 #include <utility>
57 
58 using namespace clang;
59 using namespace ento;
60 
61 #define DEBUG_TYPE "MemRegion"
62 
63 //===----------------------------------------------------------------------===//
64 // MemRegion Construction.
65 //===----------------------------------------------------------------------===//
66 
67 template <typename RegionTy, typename SuperTy, typename Arg1Ty>
68 RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1,
69  const SuperTy *superRegion) {
70  llvm::FoldingSetNodeID ID;
71  RegionTy::ProfileRegion(ID, arg1, superRegion);
72  void *InsertPos;
73  auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
74 
75  if (!R) {
76  R = A.Allocate<RegionTy>();
77  new (R) RegionTy(arg1, superRegion);
78  Regions.InsertNode(R, InsertPos);
79  }
80 
81  return R;
82 }
83 
84 template <typename RegionTy, typename SuperTy, typename Arg1Ty, typename Arg2Ty>
85 RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2,
86  const SuperTy *superRegion) {
87  llvm::FoldingSetNodeID ID;
88  RegionTy::ProfileRegion(ID, arg1, arg2, superRegion);
89  void *InsertPos;
90  auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
91 
92  if (!R) {
93  R = A.Allocate<RegionTy>();
94  new (R) RegionTy(arg1, arg2, superRegion);
95  Regions.InsertNode(R, InsertPos);
96  }
97 
98  return R;
99 }
100 
101 template <typename RegionTy, typename SuperTy,
102  typename Arg1Ty, typename Arg2Ty, typename Arg3Ty>
103 RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2,
104  const Arg3Ty arg3,
105  const SuperTy *superRegion) {
106  llvm::FoldingSetNodeID ID;
107  RegionTy::ProfileRegion(ID, arg1, arg2, arg3, superRegion);
108  void *InsertPos;
109  auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
110 
111  if (!R) {
112  R = A.Allocate<RegionTy>();
113  new (R) RegionTy(arg1, arg2, arg3, superRegion);
114  Regions.InsertNode(R, InsertPos);
115  }
116 
117  return R;
118 }
119 
120 //===----------------------------------------------------------------------===//
121 // Object destruction.
122 //===----------------------------------------------------------------------===//
123 
124 MemRegion::~MemRegion() = default;
125 
126 // All regions and their data are BumpPtrAllocated. No need to call their
127 // destructors.
129 
130 //===----------------------------------------------------------------------===//
131 // Basic methods.
132 //===----------------------------------------------------------------------===//
133 
134 bool SubRegion::isSubRegionOf(const MemRegion* R) const {
135  const MemRegion* r = this;
136  do {
137  if (r == R)
138  return true;
139  if (const auto *sr = dyn_cast<SubRegion>(r))
140  r = sr->getSuperRegion();
141  else
142  break;
143  } while (r != nullptr);
144  return false;
145 }
146 
148  const SubRegion* r = this;
149  do {
150  const MemRegion *superRegion = r->getSuperRegion();
151  if (const auto *sr = dyn_cast<SubRegion>(superRegion)) {
152  r = sr;
153  continue;
154  }
156  } while (true);
157 }
158 
160  const auto *SSR = dyn_cast<StackSpaceRegion>(getMemorySpace());
161  return SSR ? SSR->getStackFrame() : nullptr;
162 }
163 
164 ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg)
165  : DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
166  assert(IVD);
167 }
168 
169 const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; }
170 
172  return getDecl()->getType();
173 }
174 
176  return QualType(getDecl()->getTypeForDecl(), 0);
177 }
178 
180  return QualType(getDecl()->getTypeForDecl(), 0);
181 }
182 
184  assert(getDecl() &&
185  "`ParamVarRegion` support functions without `Decl` not implemented"
186  " yet.");
187  return getDecl()->getType();
188 }
189 
191  const Decl *D = getStackFrame()->getDecl();
192 
193  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
194  assert(Index < FD->param_size());
195  return FD->parameters()[Index];
196  } else if (const auto *BD = dyn_cast<BlockDecl>(D)) {
197  assert(Index < BD->param_size());
198  return BD->parameters()[Index];
199  } else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
200  assert(Index < MD->param_size());
201  return MD->parameters()[Index];
202  } else if (const auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
203  assert(Index < CD->param_size());
204  return CD->parameters()[Index];
205  } else {
206  llvm_unreachable("Unexpected Decl kind!");
207  }
208 }
209 
210 //===----------------------------------------------------------------------===//
211 // FoldingSet profiling.
212 //===----------------------------------------------------------------------===//
213 
214 void MemSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const {
215  ID.AddInteger(static_cast<unsigned>(getKind()));
216 }
217 
218 void StackSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const {
219  ID.AddInteger(static_cast<unsigned>(getKind()));
220  ID.AddPointer(getStackFrame());
221 }
222 
223 void StaticGlobalSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const {
224  ID.AddInteger(static_cast<unsigned>(getKind()));
225  ID.AddPointer(getCodeRegion());
226 }
227 
228 void StringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
229  const StringLiteral *Str,
230  const MemRegion *superRegion) {
231  ID.AddInteger(static_cast<unsigned>(StringRegionKind));
232  ID.AddPointer(Str);
233  ID.AddPointer(superRegion);
234 }
235 
236 void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
237  const ObjCStringLiteral *Str,
238  const MemRegion *superRegion) {
239  ID.AddInteger(static_cast<unsigned>(ObjCStringRegionKind));
240  ID.AddPointer(Str);
241  ID.AddPointer(superRegion);
242 }
243 
244 void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
245  const Expr *Ex, unsigned cnt,
246  const MemRegion *superRegion) {
247  ID.AddInteger(static_cast<unsigned>(AllocaRegionKind));
248  ID.AddPointer(Ex);
249  ID.AddInteger(cnt);
250  ID.AddPointer(superRegion);
251 }
252 
253 void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const {
254  ProfileRegion(ID, Ex, Cnt, superRegion);
255 }
256 
257 void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const {
258  CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
259 }
260 
261 void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
262  const CompoundLiteralExpr *CL,
263  const MemRegion* superRegion) {
264  ID.AddInteger(static_cast<unsigned>(CompoundLiteralRegionKind));
265  ID.AddPointer(CL);
266  ID.AddPointer(superRegion);
267 }
268 
269 void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
270  const PointerType *PT,
271  const MemRegion *sRegion) {
272  ID.AddInteger(static_cast<unsigned>(CXXThisRegionKind));
273  ID.AddPointer(PT);
274  ID.AddPointer(sRegion);
275 }
276 
277 void CXXThisRegion::Profile(llvm::FoldingSetNodeID &ID) const {
278  CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion);
279 }
280 
281 void FieldRegion::Profile(llvm::FoldingSetNodeID &ID) const {
282  ProfileRegion(ID, getDecl(), superRegion);
283 }
284 
285 void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
286  const ObjCIvarDecl *ivd,
287  const MemRegion* superRegion) {
288  ID.AddInteger(static_cast<unsigned>(ObjCIvarRegionKind));
289  ID.AddPointer(ivd);
290  ID.AddPointer(superRegion);
291 }
292 
293 void ObjCIvarRegion::Profile(llvm::FoldingSetNodeID &ID) const {
294  ProfileRegion(ID, getDecl(), superRegion);
295 }
296 
297 void NonParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
298  const VarDecl *VD,
299  const MemRegion *superRegion) {
300  ID.AddInteger(static_cast<unsigned>(NonParamVarRegionKind));
301  ID.AddPointer(VD);
302  ID.AddPointer(superRegion);
303 }
304 
305 void NonParamVarRegion::Profile(llvm::FoldingSetNodeID &ID) const {
306  ProfileRegion(ID, getDecl(), superRegion);
307 }
308 
309 void ParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, const Expr *OE,
310  unsigned Idx, const MemRegion *SReg) {
311  ID.AddInteger(static_cast<unsigned>(ParamVarRegionKind));
312  ID.AddPointer(OE);
313  ID.AddInteger(Idx);
314  ID.AddPointer(SReg);
315 }
316 
317 void ParamVarRegion::Profile(llvm::FoldingSetNodeID &ID) const {
318  ProfileRegion(ID, getOriginExpr(), getIndex(), superRegion);
319 }
320 
321 void SymbolicRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SymbolRef sym,
322  const MemRegion *sreg) {
323  ID.AddInteger(static_cast<unsigned>(MemRegion::SymbolicRegionKind));
324  ID.Add(sym);
325  ID.AddPointer(sreg);
326 }
327 
328 void SymbolicRegion::Profile(llvm::FoldingSetNodeID& ID) const {
330 }
331 
332 void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
333  QualType ElementType, SVal Idx,
334  const MemRegion* superRegion) {
335  ID.AddInteger(MemRegion::ElementRegionKind);
336  ID.Add(ElementType);
337  ID.AddPointer(superRegion);
338  Idx.Profile(ID);
339 }
340 
341 void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const {
342  ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion);
343 }
344 
345 void FunctionCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
346  const NamedDecl *FD,
347  const MemRegion*) {
348  ID.AddInteger(MemRegion::FunctionCodeRegionKind);
349  ID.AddPointer(FD);
350 }
351 
352 void FunctionCodeRegion::Profile(llvm::FoldingSetNodeID& ID) const {
353  FunctionCodeRegion::ProfileRegion(ID, FD, superRegion);
354 }
355 
356 void BlockCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
357  const BlockDecl *BD, CanQualType,
358  const AnalysisDeclContext *AC,
359  const MemRegion*) {
360  ID.AddInteger(MemRegion::BlockCodeRegionKind);
361  ID.AddPointer(BD);
362 }
363 
364 void BlockCodeRegion::Profile(llvm::FoldingSetNodeID& ID) const {
365  BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC, superRegion);
366 }
367 
368 void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
369  const BlockCodeRegion *BC,
370  const LocationContext *LC,
371  unsigned BlkCount,
372  const MemRegion *sReg) {
373  ID.AddInteger(MemRegion::BlockDataRegionKind);
374  ID.AddPointer(BC);
375  ID.AddPointer(LC);
376  ID.AddInteger(BlkCount);
377  ID.AddPointer(sReg);
378 }
379 
380 void BlockDataRegion::Profile(llvm::FoldingSetNodeID& ID) const {
381  BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount, getSuperRegion());
382 }
383 
384 void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
385  Expr const *Ex,
386  const MemRegion *sReg) {
387  ID.AddPointer(Ex);
388  ID.AddPointer(sReg);
389 }
390 
391 void CXXTempObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const {
392  ProfileRegion(ID, Ex, getSuperRegion());
393 }
394 
395 void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
396  const CXXRecordDecl *RD,
397  bool IsVirtual,
398  const MemRegion *SReg) {
399  ID.AddPointer(RD);
400  ID.AddBoolean(IsVirtual);
401  ID.AddPointer(SReg);
402 }
403 
404 void CXXBaseObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const {
405  ProfileRegion(ID, getDecl(), isVirtual(), superRegion);
406 }
407 
408 void CXXDerivedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
409  const CXXRecordDecl *RD,
410  const MemRegion *SReg) {
411  ID.AddPointer(RD);
412  ID.AddPointer(SReg);
413 }
414 
415 void CXXDerivedObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const {
416  ProfileRegion(ID, getDecl(), superRegion);
417 }
418 
419 //===----------------------------------------------------------------------===//
420 // Region anchors.
421 //===----------------------------------------------------------------------===//
422 
423 void GlobalsSpaceRegion::anchor() {}
424 
425 void NonStaticGlobalSpaceRegion::anchor() {}
426 
427 void StackSpaceRegion::anchor() {}
428 
429 void TypedRegion::anchor() {}
430 
431 void TypedValueRegion::anchor() {}
432 
433 void CodeTextRegion::anchor() {}
434 
435 void SubRegion::anchor() {}
436 
437 //===----------------------------------------------------------------------===//
438 // Region pretty-printing.
439 //===----------------------------------------------------------------------===//
440 
441 LLVM_DUMP_METHOD void MemRegion::dump() const {
442  dumpToStream(llvm::errs());
443 }
444 
446  std::string s;
447  llvm::raw_string_ostream os(s);
448  dumpToStream(os);
449  return s;
450 }
451 
452 void MemRegion::dumpToStream(raw_ostream &os) const {
453  os << "<Unknown Region>";
454 }
455 
456 void AllocaRegion::dumpToStream(raw_ostream &os) const {
457  os << "alloca{S" << Ex->getID(getContext()) << ',' << Cnt << '}';
458 }
459 
460 void FunctionCodeRegion::dumpToStream(raw_ostream &os) const {
461  os << "code{" << getDecl()->getDeclName().getAsString() << '}';
462 }
463 
464 void BlockCodeRegion::dumpToStream(raw_ostream &os) const {
465  os << "block_code{" << static_cast<const void *>(this) << '}';
466 }
467 
468 void BlockDataRegion::dumpToStream(raw_ostream &os) const {
469  os << "block_data{" << BC;
470  os << "; ";
472  I = referenced_vars_begin(),
473  E = referenced_vars_end(); I != E; ++I)
474  os << "(" << I.getCapturedRegion() << "<-" <<
475  I.getOriginalRegion() << ") ";
476  os << '}';
477 }
478 
479 void CompoundLiteralRegion::dumpToStream(raw_ostream &os) const {
480  // FIXME: More elaborate pretty-printing.
481  os << "{ S" << CL->getID(getContext()) << " }";
482 }
483 
484 void CXXTempObjectRegion::dumpToStream(raw_ostream &os) const {
485  os << "temp_object{" << getValueType() << ", "
486  << "S" << Ex->getID(getContext()) << '}';
487 }
488 
489 void CXXBaseObjectRegion::dumpToStream(raw_ostream &os) const {
490  os << "Base{" << superRegion << ',' << getDecl()->getName() << '}';
491 }
492 
493 void CXXDerivedObjectRegion::dumpToStream(raw_ostream &os) const {
494  os << "Derived{" << superRegion << ',' << getDecl()->getName() << '}';
495 }
496 
497 void CXXThisRegion::dumpToStream(raw_ostream &os) const {
498  os << "this";
499 }
500 
501 void ElementRegion::dumpToStream(raw_ostream &os) const {
502  os << "Element{" << superRegion << ',' << Index << ',' << getElementType()
503  << '}';
504 }
505 
506 void FieldRegion::dumpToStream(raw_ostream &os) const {
507  os << superRegion << "." << *getDecl();
508 }
509 
510 void ObjCIvarRegion::dumpToStream(raw_ostream &os) const {
511  os << "Ivar{" << superRegion << ',' << *getDecl() << '}';
512 }
513 
514 void StringRegion::dumpToStream(raw_ostream &os) const {
515  assert(Str != nullptr && "Expecting non-null StringLiteral");
516  Str->printPretty(os, nullptr, PrintingPolicy(getContext().getLangOpts()));
517 }
518 
519 void ObjCStringRegion::dumpToStream(raw_ostream &os) const {
520  assert(Str != nullptr && "Expecting non-null ObjCStringLiteral");
521  Str->printPretty(os, nullptr, PrintingPolicy(getContext().getLangOpts()));
522 }
523 
524 void SymbolicRegion::dumpToStream(raw_ostream &os) const {
525  if (isa<HeapSpaceRegion>(getSuperRegion()))
526  os << "Heap";
527  os << "SymRegion{" << sym << '}';
528 }
529 
530 void NonParamVarRegion::dumpToStream(raw_ostream &os) const {
531  if (const IdentifierInfo *ID = VD->getIdentifier())
532  os << ID->getName();
533  else
534  os << "NonParamVarRegion{D" << VD->getID() << '}';
535 }
536 
537 LLVM_DUMP_METHOD void RegionRawOffset::dump() const {
538  dumpToStream(llvm::errs());
539 }
540 
541 void RegionRawOffset::dumpToStream(raw_ostream &os) const {
542  os << "raw_offset{" << getRegion() << ',' << getOffset().getQuantity() << '}';
543 }
544 
545 void CodeSpaceRegion::dumpToStream(raw_ostream &os) const {
546  os << "CodeSpaceRegion";
547 }
548 
549 void StaticGlobalSpaceRegion::dumpToStream(raw_ostream &os) const {
550  os << "StaticGlobalsMemSpace{" << CR << '}';
551 }
552 
553 void GlobalInternalSpaceRegion::dumpToStream(raw_ostream &os) const {
554  os << "GlobalInternalSpaceRegion";
555 }
556 
557 void GlobalSystemSpaceRegion::dumpToStream(raw_ostream &os) const {
558  os << "GlobalSystemSpaceRegion";
559 }
560 
561 void GlobalImmutableSpaceRegion::dumpToStream(raw_ostream &os) const {
562  os << "GlobalImmutableSpaceRegion";
563 }
564 
565 void HeapSpaceRegion::dumpToStream(raw_ostream &os) const {
566  os << "HeapSpaceRegion";
567 }
568 
569 void UnknownSpaceRegion::dumpToStream(raw_ostream &os) const {
570  os << "UnknownSpaceRegion";
571 }
572 
573 void StackArgumentsSpaceRegion::dumpToStream(raw_ostream &os) const {
574  os << "StackArgumentsSpaceRegion";
575 }
576 
577 void StackLocalsSpaceRegion::dumpToStream(raw_ostream &os) const {
578  os << "StackLocalsSpaceRegion";
579 }
580 
581 void ParamVarRegion::dumpToStream(raw_ostream &os) const {
582  const ParmVarDecl *PVD = getDecl();
583  assert(PVD &&
584  "`ParamVarRegion` support functions without `Decl` not implemented"
585  " yet.");
586  if (const IdentifierInfo *ID = PVD->getIdentifier()) {
587  os << ID->getName();
588  } else {
589  os << "ParamVarRegion{P" << PVD->getID() << '}';
590  }
591 }
592 
594  return canPrintPrettyAsExpr();
595 }
596 
598  return false;
599 }
600 
601 void MemRegion::printPretty(raw_ostream &os) const {
602  assert(canPrintPretty() && "This region cannot be printed pretty.");
603  os << "'";
604  printPrettyAsExpr(os);
605  os << "'";
606 }
607 
608 void MemRegion::printPrettyAsExpr(raw_ostream &) const {
609  llvm_unreachable("This region cannot be printed pretty.");
610 }
611 
612 bool NonParamVarRegion::canPrintPrettyAsExpr() const { return true; }
613 
614 void NonParamVarRegion::printPrettyAsExpr(raw_ostream &os) const {
615  os << getDecl()->getName();
616 }
617 
618 bool ParamVarRegion::canPrintPrettyAsExpr() const { return true; }
619 
620 void ParamVarRegion::printPrettyAsExpr(raw_ostream &os) const {
621  assert(getDecl() &&
622  "`ParamVarRegion` support functions without `Decl` not implemented"
623  " yet.");
624  os << getDecl()->getName();
625 }
626 
628  return true;
629 }
630 
631 void ObjCIvarRegion::printPrettyAsExpr(raw_ostream &os) const {
632  os << getDecl()->getName();
633 }
634 
636  return true;
637 }
638 
641 }
642 
643 void FieldRegion::printPrettyAsExpr(raw_ostream &os) const {
644  assert(canPrintPrettyAsExpr());
646  os << "." << getDecl()->getName();
647 }
648 
649 void FieldRegion::printPretty(raw_ostream &os) const {
650  if (canPrintPrettyAsExpr()) {
651  os << "\'";
652  printPrettyAsExpr(os);
653  os << "'";
654  } else {
655  os << "field " << "\'" << getDecl()->getName() << "'";
656  }
657 }
658 
661 }
662 
663 void CXXBaseObjectRegion::printPrettyAsExpr(raw_ostream &os) const {
665 }
666 
669 }
670 
671 void CXXDerivedObjectRegion::printPrettyAsExpr(raw_ostream &os) const {
673 }
674 
676  std::string VariableName;
677  std::string ArrayIndices;
678  const MemRegion *R = this;
679  SmallString<50> buf;
680  llvm::raw_svector_ostream os(buf);
681 
682  // Obtain array indices to add them to the variable name.
683  const ElementRegion *ER = nullptr;
684  while ((ER = R->getAs<ElementRegion>())) {
685  // Index is a ConcreteInt.
686  if (auto CI = ER->getIndex().getAs<nonloc::ConcreteInt>()) {
688  CI->getValue().toString(Idx);
689  ArrayIndices = (llvm::Twine("[") + Idx.str() + "]" + ArrayIndices).str();
690  }
691  // If not a ConcreteInt, try to obtain the variable
692  // name by calling 'getDescriptiveName' recursively.
693  else {
694  std::string Idx = ER->getDescriptiveName(false);
695  if (!Idx.empty()) {
696  ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str();
697  }
698  }
699  R = ER->getSuperRegion();
700  }
701 
702  // Get variable name.
703  if (R && R->canPrintPrettyAsExpr()) {
704  R->printPrettyAsExpr(os);
705  if (UseQuotes)
706  return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
707  else
708  return (llvm::Twine(os.str()) + ArrayIndices).str();
709  }
710 
711  return VariableName;
712 }
713 
715  const auto *const VR = dyn_cast<VarRegion>(this->getBaseRegion());
716  const auto *const FR = dyn_cast<FieldRegion>(this);
717 
718  // Check for more specific regions first.
719  // FieldRegion
720  if (FR) {
721  return FR->getDecl()->getSourceRange();
722  }
723  // VarRegion
724  else if (VR) {
725  return VR->getDecl()->getSourceRange();
726  }
727  // Return invalid source range (can be checked by client).
728  else
729  return {};
730 }
731 
732 //===----------------------------------------------------------------------===//
733 // MemRegionManager methods.
734 //===----------------------------------------------------------------------===//
735 
737  SValBuilder &SVB) const {
738  const auto *SR = cast<SubRegion>(MR);
739  SymbolManager &SymMgr = SVB.getSymbolManager();
740 
741  switch (SR->getKind()) {
742  case MemRegion::AllocaRegionKind:
743  case MemRegion::SymbolicRegionKind:
744  return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR));
745  case MemRegion::StringRegionKind:
746  return SVB.makeIntVal(
747  cast<StringRegion>(SR)->getStringLiteral()->getByteLength() + 1,
748  SVB.getArrayIndexType());
749  case MemRegion::CompoundLiteralRegionKind:
750  case MemRegion::CXXBaseObjectRegionKind:
751  case MemRegion::CXXDerivedObjectRegionKind:
752  case MemRegion::CXXTempObjectRegionKind:
753  case MemRegion::CXXThisRegionKind:
754  case MemRegion::ObjCIvarRegionKind:
755  case MemRegion::NonParamVarRegionKind:
756  case MemRegion::ParamVarRegionKind:
757  case MemRegion::ElementRegionKind:
758  case MemRegion::ObjCStringRegionKind: {
759  QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
760  if (isa<VariableArrayType>(Ty))
761  return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR));
762 
763  if (Ty->isIncompleteType())
764  return UnknownVal();
765 
766  return getElementExtent(Ty, SVB);
767  }
768  case MemRegion::FieldRegionKind: {
769  // Force callers to deal with bitfields explicitly.
770  if (cast<FieldRegion>(SR)->getDecl()->isBitField())
771  return UnknownVal();
772 
773  QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
774  const DefinedOrUnknownSVal Size = getElementExtent(Ty, SVB);
775 
776  // We currently don't model flexible array members (FAMs), which are:
777  // - int array[]; of IncompleteArrayType
778  // - int array[0]; of ConstantArrayType with size 0
779  // - int array[1]; of ConstantArrayType with size 1 (*)
780  // (*): Consider single element array object members as FAM candidates only
781  // if the consider-single-element-arrays-as-flexible-array-members
782  // analyzer option is true.
783  // https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
784  const auto isFlexibleArrayMemberCandidate = [this,
785  &SVB](QualType Ty) -> bool {
786  const ArrayType *AT = Ctx.getAsArrayType(Ty);
787  if (!AT)
788  return false;
789  if (isa<IncompleteArrayType>(AT))
790  return true;
791 
792  if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
794  const FAMKind StrictFlexArraysLevel =
795  Ctx.getLangOpts().getStrictFlexArraysLevel();
796  const AnalyzerOptions &Opts = SVB.getAnalyzerOptions();
797  const llvm::APInt &Size = CAT->getSize();
798 
799  if (StrictFlexArraysLevel <= FAMKind::ZeroOrIncomplete && Size.isZero())
800  return true;
801 
802  // The "-fstrict-flex-arrays" should have precedence over
803  // consider-single-element-arrays-as-flexible-array-members
804  // analyzer-config when checking single element arrays.
805  if (StrictFlexArraysLevel == FAMKind::Default) {
806  // FIXME: After clang-17 released, we should remove this branch.
807  if (Opts.ShouldConsiderSingleElementArraysAsFlexibleArrayMembers &&
808  Size.isOne())
809  return true;
810  } else {
811  // -fstrict-flex-arrays was specified, since it's not the default, so
812  // ignore analyzer-config.
813  if (StrictFlexArraysLevel <= FAMKind::OneZeroOrIncomplete &&
814  Size.isOne())
815  return true;
816  }
817  }
818  return false;
819  };
820 
821  if (isFlexibleArrayMemberCandidate(Ty))
822  return UnknownVal();
823 
824  return Size;
825  }
826  // FIXME: The following are being used in 'SimpleSValBuilder' and in
827  // 'ArrayBoundChecker::checkLocation' because there is no symbol to
828  // represent the regions more appropriately.
829  case MemRegion::BlockDataRegionKind:
830  case MemRegion::BlockCodeRegionKind:
831  case MemRegion::FunctionCodeRegionKind:
832  return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR));
833  default:
834  llvm_unreachable("Unhandled region");
835  }
836 }
837 
838 template <typename REG>
839 const REG *MemRegionManager::LazyAllocate(REG*& region) {
840  if (!region) {
841  region = A.Allocate<REG>();
842  new (region) REG(*this);
843  }
844 
845  return region;
846 }
847 
848 template <typename REG, typename ARG>
849 const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) {
850  if (!region) {
851  region = A.Allocate<REG>();
852  new (region) REG(this, a);
853  }
854 
855  return region;
856 }
857 
860  assert(STC);
861  StackLocalsSpaceRegion *&R = StackLocalsSpaceRegions[STC];
862 
863  if (R)
864  return R;
865 
866  R = A.Allocate<StackLocalsSpaceRegion>();
867  new (R) StackLocalsSpaceRegion(*this, STC);
868  return R;
869 }
870 
873  assert(STC);
874  StackArgumentsSpaceRegion *&R = StackArgumentsSpaceRegions[STC];
875 
876  if (R)
877  return R;
878 
879  R = A.Allocate<StackArgumentsSpaceRegion>();
880  new (R) StackArgumentsSpaceRegion(*this, STC);
881  return R;
882 }
883 
884 const GlobalsSpaceRegion
886  const CodeTextRegion *CR) {
887  if (!CR) {
888  if (K == MemRegion::GlobalSystemSpaceRegionKind)
889  return LazyAllocate(SystemGlobals);
890  if (K == MemRegion::GlobalImmutableSpaceRegionKind)
891  return LazyAllocate(ImmutableGlobals);
892  assert(K == MemRegion::GlobalInternalSpaceRegionKind);
893  return LazyAllocate(InternalGlobals);
894  }
895 
896  assert(K == MemRegion::StaticGlobalSpaceRegionKind);
897  StaticGlobalSpaceRegion *&R = StaticsGlobalSpaceRegions[CR];
898  if (R)
899  return R;
900 
901  R = A.Allocate<StaticGlobalSpaceRegion>();
902  new (R) StaticGlobalSpaceRegion(*this, CR);
903  return R;
904 }
905 
907  return LazyAllocate(heap);
908 }
909 
911  return LazyAllocate(unknown);
912 }
913 
915  return LazyAllocate(code);
916 }
917 
918 //===----------------------------------------------------------------------===//
919 // Constructing regions.
920 //===----------------------------------------------------------------------===//
921 
923  return getSubRegion<StringRegion>(
924  Str, cast<GlobalInternalSpaceRegion>(getGlobalsRegion()));
925 }
926 
927 const ObjCStringRegion *
929  return getSubRegion<ObjCStringRegion>(
930  Str, cast<GlobalInternalSpaceRegion>(getGlobalsRegion()));
931 }
932 
933 /// Look through a chain of LocationContexts to either find the
934 /// StackFrameContext that matches a DeclContext, or find a VarRegion
935 /// for a variable captured by a block.
936 static llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
938  const DeclContext *DC,
939  const VarDecl *VD) {
940  while (LC) {
941  if (const auto *SFC = dyn_cast<StackFrameContext>(LC)) {
942  if (cast<DeclContext>(SFC->getDecl()) == DC)
943  return SFC;
944  }
945  if (const auto *BC = dyn_cast<BlockInvocationContext>(LC)) {
946  const auto *BR = static_cast<const BlockDataRegion *>(BC->getData());
947  // FIXME: This can be made more efficient.
948  for (BlockDataRegion::referenced_vars_iterator
949  I = BR->referenced_vars_begin(),
950  E = BR->referenced_vars_end(); I != E; ++I) {
951  const TypedValueRegion *OrigR = I.getOriginalRegion();
952  if (const auto *VR = dyn_cast<VarRegion>(OrigR)) {
953  if (VR->getDecl() == VD)
954  return cast<VarRegion>(I.getCapturedRegion());
955  }
956  }
957  }
958 
959  LC = LC->getParent();
960  }
961  return (const StackFrameContext *)nullptr;
962 }
963 
965  const LocationContext *LC) {
966  const auto *PVD = dyn_cast<ParmVarDecl>(D);
967  if (PVD) {
968  unsigned Index = PVD->getFunctionScopeIndex();
969  const StackFrameContext *SFC = LC->getStackFrame();
970  const Stmt *CallSite = SFC->getCallSite();
971  if (CallSite) {
972  const Decl *D = SFC->getDecl();
973  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
974  if (Index < FD->param_size() && FD->parameters()[Index] == PVD)
975  return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index,
977  } else if (const auto *BD = dyn_cast<BlockDecl>(D)) {
978  if (Index < BD->param_size() && BD->parameters()[Index] == PVD)
979  return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index,
981  } else {
982  return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index,
984  }
985  }
986  }
987 
988  D = D->getCanonicalDecl();
989  const MemRegion *sReg = nullptr;
990 
991  if (D->hasGlobalStorage() && !D->isStaticLocal()) {
992  QualType Ty = D->getType();
993  assert(!Ty.isNull());
994  if (Ty.isConstQualified()) {
995  sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
996  } else if (Ctx.getSourceManager().isInSystemHeader(D->getLocation())) {
997  sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind);
998  } else {
999  sReg = getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind);
1000  }
1001 
1002  // Finally handle static locals.
1003  } else {
1004  // FIXME: Once we implement scope handling, we will need to properly lookup
1005  // 'D' to the proper LocationContext.
1006  const DeclContext *DC = D->getDeclContext();
1007  llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V =
1009 
1010  if (V.is<const VarRegion*>())
1011  return V.get<const VarRegion*>();
1012 
1013  const auto *STC = V.get<const StackFrameContext *>();
1014 
1015  if (!STC) {
1016  // FIXME: Assign a more sensible memory space to static locals
1017  // we see from within blocks that we analyze as top-level declarations.
1018  sReg = getUnknownRegion();
1019  } else {
1020  if (D->hasLocalStorage()) {
1021  sReg =
1022  isa<ParmVarDecl, ImplicitParamDecl>(D)
1023  ? static_cast<const MemRegion *>(getStackArgumentsRegion(STC))
1024  : static_cast<const MemRegion *>(getStackLocalsRegion(STC));
1025  }
1026  else {
1027  assert(D->isStaticLocal());
1028  const Decl *STCD = STC->getDecl();
1029  if (isa<FunctionDecl, ObjCMethodDecl>(STCD))
1030  sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
1031  getFunctionCodeRegion(cast<NamedDecl>(STCD)));
1032  else if (const auto *BD = dyn_cast<BlockDecl>(STCD)) {
1033  // FIXME: The fallback type here is totally bogus -- though it should
1034  // never be queried, it will prevent uniquing with the real
1035  // BlockCodeRegion. Ideally we'd fix the AST so that we always had a
1036  // signature.
1037  QualType T;
1038  if (const TypeSourceInfo *TSI = BD->getSignatureAsWritten())
1039  T = TSI->getType();
1040  if (T.isNull())
1041  T = getContext().VoidTy;
1042  if (!T->getAs<FunctionType>()) {
1044  T = getContext().getFunctionType(T, None, Ext);
1045  }
1047 
1048  const BlockCodeRegion *BTR =
1050  STC->getAnalysisDeclContext());
1051  sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
1052  BTR);
1053  }
1054  else {
1055  sReg = getGlobalsRegion();
1056  }
1057  }
1058  }
1059  }
1060 
1061  return getSubRegion<NonParamVarRegion>(D, sReg);
1062 }
1063 
1064 const NonParamVarRegion *
1066  const MemRegion *superR) {
1067  D = D->getCanonicalDecl();
1068  return getSubRegion<NonParamVarRegion>(D, superR);
1069 }
1070 
1071 const ParamVarRegion *
1072 MemRegionManager::getParamVarRegion(const Expr *OriginExpr, unsigned Index,
1073  const LocationContext *LC) {
1074  const StackFrameContext *SFC = LC->getStackFrame();
1075  assert(SFC);
1076  return getSubRegion<ParamVarRegion>(OriginExpr, Index,
1078 }
1079 
1080 const BlockDataRegion *
1082  const LocationContext *LC,
1083  unsigned blockCount) {
1084  const MemSpaceRegion *sReg = nullptr;
1085  const BlockDecl *BD = BC->getDecl();
1086  if (!BD->hasCaptures()) {
1087  // This handles 'static' blocks.
1088  sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
1089  }
1090  else {
1091  bool IsArcManagedBlock = Ctx.getLangOpts().ObjCAutoRefCount;
1092 
1093  // ARC managed blocks can be initialized on stack or directly in heap
1094  // depending on the implementations. So we initialize them with
1095  // UnknownRegion.
1096  if (!IsArcManagedBlock && LC) {
1097  // FIXME: Once we implement scope handling, we want the parent region
1098  // to be the scope.
1099  const StackFrameContext *STC = LC->getStackFrame();
1100  assert(STC);
1101  sReg = getStackLocalsRegion(STC);
1102  } else {
1103  // We allow 'LC' to be NULL for cases where want BlockDataRegions
1104  // without context-sensitivity.
1105  sReg = getUnknownRegion();
1106  }
1107  }
1108 
1109  return getSubRegion<BlockDataRegion>(BC, LC, blockCount, sReg);
1110 }
1111 
1112 const CXXTempObjectRegion *
1114  return getSubRegion<CXXTempObjectRegion>(
1115  Ex, getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind, nullptr));
1116 }
1117 
1118 const CompoundLiteralRegion*
1120  const LocationContext *LC) {
1121  const MemSpaceRegion *sReg = nullptr;
1122 
1123  if (CL->isFileScope())
1124  sReg = getGlobalsRegion();
1125  else {
1126  const StackFrameContext *STC = LC->getStackFrame();
1127  assert(STC);
1128  sReg = getStackLocalsRegion(STC);
1129  }
1130 
1131  return getSubRegion<CompoundLiteralRegion>(CL, sReg);
1132 }
1133 
1134 const ElementRegion*
1136  const SubRegion* superRegion,
1137  ASTContext &Ctx){
1138  QualType T = Ctx.getCanonicalType(elementType).getUnqualifiedType();
1139 
1140  llvm::FoldingSetNodeID ID;
1141  ElementRegion::ProfileRegion(ID, T, Idx, superRegion);
1142 
1143  void *InsertPos;
1144  MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
1145  auto *R = cast_or_null<ElementRegion>(data);
1146 
1147  if (!R) {
1148  R = A.Allocate<ElementRegion>();
1149  new (R) ElementRegion(T, Idx, superRegion);
1150  Regions.InsertNode(R, InsertPos);
1151  }
1152 
1153  return R;
1154 }
1155 
1156 const FunctionCodeRegion *
1158  // To think: should we canonicalize the declaration here?
1159  return getSubRegion<FunctionCodeRegion>(FD, getCodeRegion());
1160 }
1161 
1162 const BlockCodeRegion *
1164  AnalysisDeclContext *AC) {
1165  return getSubRegion<BlockCodeRegion>(BD, locTy, AC, getCodeRegion());
1166 }
1167 
1168 const SymbolicRegion *
1170  const MemSpaceRegion *MemSpace) {
1171  if (MemSpace == nullptr)
1172  MemSpace = getUnknownRegion();
1173  return getSubRegion<SymbolicRegion>(sym, MemSpace);
1174 }
1175 
1177  return getSubRegion<SymbolicRegion>(Sym, getHeapRegion());
1178 }
1179 
1180 const FieldRegion*
1182  const SubRegion* superRegion){
1183  return getSubRegion<FieldRegion>(d, superRegion);
1184 }
1185 
1186 const ObjCIvarRegion*
1188  const SubRegion* superRegion) {
1189  return getSubRegion<ObjCIvarRegion>(d, superRegion);
1190 }
1191 
1192 const CXXTempObjectRegion*
1194  LocationContext const *LC) {
1195  const StackFrameContext *SFC = LC->getStackFrame();
1196  assert(SFC);
1197  return getSubRegion<CXXTempObjectRegion>(E, getStackLocalsRegion(SFC));
1198 }
1199 
1200 /// Checks whether \p BaseClass is a valid virtual or direct non-virtual base
1201 /// class of the type of \p Super.
1202 static bool isValidBaseClass(const CXXRecordDecl *BaseClass,
1203  const TypedValueRegion *Super,
1204  bool IsVirtual) {
1205  BaseClass = BaseClass->getCanonicalDecl();
1206 
1207  const CXXRecordDecl *Class = Super->getValueType()->getAsCXXRecordDecl();
1208  if (!Class)
1209  return true;
1210 
1211  if (IsVirtual)
1212  return Class->isVirtuallyDerivedFrom(BaseClass);
1213 
1214  for (const auto &I : Class->bases()) {
1215  if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass)
1216  return true;
1217  }
1218 
1219  return false;
1220 }
1221 
1222 const CXXBaseObjectRegion *
1224  const SubRegion *Super,
1225  bool IsVirtual) {
1226  if (isa<TypedValueRegion>(Super)) {
1227  assert(isValidBaseClass(RD, cast<TypedValueRegion>(Super), IsVirtual));
1228  (void)&isValidBaseClass;
1229 
1230  if (IsVirtual) {
1231  // Virtual base regions should not be layered, since the layout rules
1232  // are different.
1233  while (const auto *Base = dyn_cast<CXXBaseObjectRegion>(Super))
1234  Super = cast<SubRegion>(Base->getSuperRegion());
1235  assert(Super && !isa<MemSpaceRegion>(Super));
1236  }
1237  }
1238 
1239  return getSubRegion<CXXBaseObjectRegion>(RD, IsVirtual, Super);
1240 }
1241 
1242 const CXXDerivedObjectRegion *
1244  const SubRegion *Super) {
1245  return getSubRegion<CXXDerivedObjectRegion>(RD, Super);
1246 }
1247 
1248 const CXXThisRegion*
1250  const LocationContext *LC) {
1251  const auto *PT = thisPointerTy->getAs<PointerType>();
1252  assert(PT);
1253  // Inside the body of the operator() of a lambda a this expr might refer to an
1254  // object in one of the parent location contexts.
1255  const auto *D = dyn_cast<CXXMethodDecl>(LC->getDecl());
1256  // FIXME: when operator() of lambda is analyzed as a top level function and
1257  // 'this' refers to a this to the enclosing scope, there is no right region to
1258  // return.
1259  while (!LC->inTopFrame() && (!D || D->isStatic() ||
1260  PT != D->getThisType()->getAs<PointerType>())) {
1261  LC = LC->getParent();
1262  D = dyn_cast<CXXMethodDecl>(LC->getDecl());
1263  }
1264  const StackFrameContext *STC = LC->getStackFrame();
1265  assert(STC);
1266  return getSubRegion<CXXThisRegion>(PT, getStackArgumentsRegion(STC));
1267 }
1268 
1269 const AllocaRegion*
1271  const LocationContext *LC) {
1272  const StackFrameContext *STC = LC->getStackFrame();
1273  assert(STC);
1274  return getSubRegion<AllocaRegion>(E, cnt, getStackLocalsRegion(STC));
1275 }
1276 
1278  const MemRegion *R = this;
1279  const auto *SR = dyn_cast<SubRegion>(this);
1280 
1281  while (SR) {
1282  R = SR->getSuperRegion();
1283  SR = dyn_cast<SubRegion>(R);
1284  }
1285 
1286  return dyn_cast<MemSpaceRegion>(R);
1287 }
1288 
1290  return isa<StackSpaceRegion>(getMemorySpace());
1291 }
1292 
1294  return isa<StackLocalsSpaceRegion>(getMemorySpace());
1295 }
1296 
1298  return isa<StackArgumentsSpaceRegion>(getMemorySpace());
1299 }
1300 
1302  return isa<StackArgumentsSpaceRegion, GlobalsSpaceRegion>(getMemorySpace());
1303 }
1304 
1305 // Strips away all elements and fields.
1306 // Returns the base region of them.
1308  const MemRegion *R = this;
1309  while (true) {
1310  switch (R->getKind()) {
1311  case MemRegion::ElementRegionKind:
1312  case MemRegion::FieldRegionKind:
1313  case MemRegion::ObjCIvarRegionKind:
1314  case MemRegion::CXXBaseObjectRegionKind:
1315  case MemRegion::CXXDerivedObjectRegionKind:
1316  R = cast<SubRegion>(R)->getSuperRegion();
1317  continue;
1318  default:
1319  break;
1320  }
1321  break;
1322  }
1323  return R;
1324 }
1325 
1326 // Returns the region of the root class of a C++ class hierarchy.
1328  const MemRegion *R = this;
1329  while (const auto *BR = dyn_cast<CXXBaseObjectRegion>(R))
1330  R = BR->getSuperRegion();
1331  return R;
1332 }
1333 
1335  return false;
1336 }
1337 
1338 //===----------------------------------------------------------------------===//
1339 // View handling.
1340 //===----------------------------------------------------------------------===//
1341 
1342 const MemRegion *MemRegion::StripCasts(bool StripBaseAndDerivedCasts) const {
1343  const MemRegion *R = this;
1344  while (true) {
1345  switch (R->getKind()) {
1346  case ElementRegionKind: {
1347  const auto *ER = cast<ElementRegion>(R);
1348  if (!ER->getIndex().isZeroConstant())
1349  return R;
1350  R = ER->getSuperRegion();
1351  break;
1352  }
1353  case CXXBaseObjectRegionKind:
1354  case CXXDerivedObjectRegionKind:
1355  if (!StripBaseAndDerivedCasts)
1356  return R;
1357  R = cast<TypedValueRegion>(R)->getSuperRegion();
1358  break;
1359  default:
1360  return R;
1361  }
1362  }
1363 }
1364 
1366  const auto *SubR = dyn_cast<SubRegion>(this);
1367 
1368  while (SubR) {
1369  if (const auto *SymR = dyn_cast<SymbolicRegion>(SubR))
1370  return SymR;
1371  SubR = dyn_cast<SubRegion>(SubR->getSuperRegion());
1372  }
1373  return nullptr;
1374 }
1375 
1377  int64_t offset = 0;
1378  const ElementRegion *ER = this;
1379  const MemRegion *superR = nullptr;
1380  ASTContext &C = getContext();
1381 
1382  // FIXME: Handle multi-dimensional arrays.
1383 
1384  while (ER) {
1385  superR = ER->getSuperRegion();
1386 
1387  // FIXME: generalize to symbolic offsets.
1388  SVal index = ER->getIndex();
1389  if (auto CI = index.getAs<nonloc::ConcreteInt>()) {
1390  // Update the offset.
1391  int64_t i = CI->getValue().getSExtValue();
1392 
1393  if (i != 0) {
1394  QualType elemType = ER->getElementType();
1395 
1396  // If we are pointing to an incomplete type, go no further.
1397  if (elemType->isIncompleteType()) {
1398  superR = ER;
1399  break;
1400  }
1401 
1402  int64_t size = C.getTypeSizeInChars(elemType).getQuantity();
1403  if (auto NewOffset = llvm::checkedMulAdd(i, size, offset)) {
1404  offset = *NewOffset;
1405  } else {
1406  LLVM_DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
1407  << "offset overflowing, returning unknown\n");
1408 
1409  return nullptr;
1410  }
1411  }
1412 
1413  // Go to the next ElementRegion (if any).
1414  ER = dyn_cast<ElementRegion>(superR);
1415  continue;
1416  }
1417 
1418  return nullptr;
1419  }
1420 
1421  assert(superR && "super region cannot be NULL");
1422  return RegionRawOffset(superR, CharUnits::fromQuantity(offset));
1423 }
1424 
1425 /// Returns true if \p Base is an immediate base class of \p Child
1426 static bool isImmediateBase(const CXXRecordDecl *Child,
1427  const CXXRecordDecl *Base) {
1428  assert(Child && "Child must not be null");
1429  // Note that we do NOT canonicalize the base class here, because
1430  // ASTRecordLayout doesn't either. If that leads us down the wrong path,
1431  // so be it; at least we won't crash.
1432  for (const auto &I : Child->bases()) {
1433  if (I.getType()->getAsCXXRecordDecl() == Base)
1434  return true;
1435  }
1436 
1437  return false;
1438 }
1439 
1440 static RegionOffset calculateOffset(const MemRegion *R) {
1441  const MemRegion *SymbolicOffsetBase = nullptr;
1442  int64_t Offset = 0;
1443 
1444  while (true) {
1445  switch (R->getKind()) {
1446  case MemRegion::CodeSpaceRegionKind:
1447  case MemRegion::StackLocalsSpaceRegionKind:
1448  case MemRegion::StackArgumentsSpaceRegionKind:
1449  case MemRegion::HeapSpaceRegionKind:
1450  case MemRegion::UnknownSpaceRegionKind:
1451  case MemRegion::StaticGlobalSpaceRegionKind:
1452  case MemRegion::GlobalInternalSpaceRegionKind:
1453  case MemRegion::GlobalSystemSpaceRegionKind:
1454  case MemRegion::GlobalImmutableSpaceRegionKind:
1455  // Stores can bind directly to a region space to set a default value.
1456  assert(Offset == 0 && !SymbolicOffsetBase);
1457  goto Finish;
1458 
1459  case MemRegion::FunctionCodeRegionKind:
1460  case MemRegion::BlockCodeRegionKind:
1461  case MemRegion::BlockDataRegionKind:
1462  // These will never have bindings, but may end up having values requested
1463  // if the user does some strange casting.
1464  if (Offset != 0)
1465  SymbolicOffsetBase = R;
1466  goto Finish;
1467 
1468  case MemRegion::SymbolicRegionKind:
1469  case MemRegion::AllocaRegionKind:
1470  case MemRegion::CompoundLiteralRegionKind:
1471  case MemRegion::CXXThisRegionKind:
1472  case MemRegion::StringRegionKind:
1473  case MemRegion::ObjCStringRegionKind:
1474  case MemRegion::NonParamVarRegionKind:
1475  case MemRegion::ParamVarRegionKind:
1476  case MemRegion::CXXTempObjectRegionKind:
1477  // Usual base regions.
1478  goto Finish;
1479 
1480  case MemRegion::ObjCIvarRegionKind:
1481  // This is a little strange, but it's a compromise between
1482  // ObjCIvarRegions having unknown compile-time offsets (when using the
1483  // non-fragile runtime) and yet still being distinct, non-overlapping
1484  // regions. Thus we treat them as "like" base regions for the purposes
1485  // of computing offsets.
1486  goto Finish;
1487 
1488  case MemRegion::CXXBaseObjectRegionKind: {
1489  const auto *BOR = cast<CXXBaseObjectRegion>(R);
1490  R = BOR->getSuperRegion();
1491 
1492  QualType Ty;
1493  bool RootIsSymbolic = false;
1494  if (const auto *TVR = dyn_cast<TypedValueRegion>(R)) {
1495  Ty = TVR->getDesugaredValueType(R->getContext());
1496  } else if (const auto *SR = dyn_cast<SymbolicRegion>(R)) {
1497  // If our base region is symbolic, we don't know what type it really is.
1498  // Pretend the type of the symbol is the true dynamic type.
1499  // (This will at least be self-consistent for the life of the symbol.)
1500  Ty = SR->getPointeeStaticType();
1501  RootIsSymbolic = true;
1502  }
1503 
1504  const CXXRecordDecl *Child = Ty->getAsCXXRecordDecl();
1505  if (!Child) {
1506  // We cannot compute the offset of the base class.
1507  SymbolicOffsetBase = R;
1508  } else {
1509  if (RootIsSymbolic) {
1510  // Base layers on symbolic regions may not be type-correct.
1511  // Double-check the inheritance here, and revert to a symbolic offset
1512  // if it's invalid (e.g. due to a reinterpret_cast).
1513  if (BOR->isVirtual()) {
1514  if (!Child->isVirtuallyDerivedFrom(BOR->getDecl()))
1515  SymbolicOffsetBase = R;
1516  } else {
1517  if (!isImmediateBase(Child, BOR->getDecl()))
1518  SymbolicOffsetBase = R;
1519  }
1520  }
1521  }
1522 
1523  // Don't bother calculating precise offsets if we already have a
1524  // symbolic offset somewhere in the chain.
1525  if (SymbolicOffsetBase)
1526  continue;
1527 
1528  CharUnits BaseOffset;
1529  const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(Child);
1530  if (BOR->isVirtual())
1531  BaseOffset = Layout.getVBaseClassOffset(BOR->getDecl());
1532  else
1533  BaseOffset = Layout.getBaseClassOffset(BOR->getDecl());
1534 
1535  // The base offset is in chars, not in bits.
1536  Offset += BaseOffset.getQuantity() * R->getContext().getCharWidth();
1537  break;
1538  }
1539 
1540  case MemRegion::CXXDerivedObjectRegionKind: {
1541  // TODO: Store the base type in the CXXDerivedObjectRegion and use it.
1542  goto Finish;
1543  }
1544 
1545  case MemRegion::ElementRegionKind: {
1546  const auto *ER = cast<ElementRegion>(R);
1547  R = ER->getSuperRegion();
1548 
1549  QualType EleTy = ER->getValueType();
1550  if (EleTy->isIncompleteType()) {
1551  // We cannot compute the offset of the base class.
1552  SymbolicOffsetBase = R;
1553  continue;
1554  }
1555 
1556  SVal Index = ER->getIndex();
1558  Index.getAs<nonloc::ConcreteInt>()) {
1559  // Don't bother calculating precise offsets if we already have a
1560  // symbolic offset somewhere in the chain.
1561  if (SymbolicOffsetBase)
1562  continue;
1563 
1564  int64_t i = CI->getValue().getSExtValue();
1565  // This type size is in bits.
1566  Offset += i * R->getContext().getTypeSize(EleTy);
1567  } else {
1568  // We cannot compute offset for non-concrete index.
1569  SymbolicOffsetBase = R;
1570  }
1571  break;
1572  }
1573  case MemRegion::FieldRegionKind: {
1574  const auto *FR = cast<FieldRegion>(R);
1575  R = FR->getSuperRegion();
1576  assert(R);
1577 
1578  const RecordDecl *RD = FR->getDecl()->getParent();
1579  if (RD->isUnion() || !RD->isCompleteDefinition()) {
1580  // We cannot compute offset for incomplete type.
1581  // For unions, we could treat everything as offset 0, but we'd rather
1582  // treat each field as a symbolic offset so they aren't stored on top
1583  // of each other, since we depend on things in typed regions actually
1584  // matching their types.
1585  SymbolicOffsetBase = R;
1586  }
1587 
1588  // Don't bother calculating precise offsets if we already have a
1589  // symbolic offset somewhere in the chain.
1590  if (SymbolicOffsetBase)
1591  continue;
1592 
1593  // Get the field number.
1594  unsigned idx = 0;
1595  for (RecordDecl::field_iterator FI = RD->field_begin(),
1596  FE = RD->field_end(); FI != FE; ++FI, ++idx) {
1597  if (FR->getDecl() == *FI)
1598  break;
1599  }
1600  const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(RD);
1601  // This is offset in bits.
1602  Offset += Layout.getFieldOffset(idx);
1603  break;
1604  }
1605  }
1606  }
1607 
1608  Finish:
1609  if (SymbolicOffsetBase)
1610  return RegionOffset(SymbolicOffsetBase, RegionOffset::Symbolic);
1611  return RegionOffset(R, Offset);
1612 }
1613 
1615  if (!cachedOffset)
1616  cachedOffset = calculateOffset(this);
1617  return *cachedOffset;
1618 }
1619 
1620 //===----------------------------------------------------------------------===//
1621 // BlockDataRegion
1622 //===----------------------------------------------------------------------===//
1623 
1624 std::pair<const VarRegion *, const VarRegion *>
1625 BlockDataRegion::getCaptureRegions(const VarDecl *VD) {
1627  const VarRegion *VR = nullptr;
1628  const VarRegion *OriginalVR = nullptr;
1629 
1630  if (!VD->hasAttr<BlocksAttr>() && VD->hasLocalStorage()) {
1631  VR = MemMgr.getNonParamVarRegion(VD, this);
1632  OriginalVR = MemMgr.getVarRegion(VD, LC);
1633  }
1634  else {
1635  if (LC) {
1636  VR = MemMgr.getVarRegion(VD, LC);
1637  OriginalVR = VR;
1638  }
1639  else {
1640  VR = MemMgr.getNonParamVarRegion(VD, MemMgr.getUnknownRegion());
1641  OriginalVR = MemMgr.getVarRegion(VD, LC);
1642  }
1643  }
1644  return std::make_pair(VR, OriginalVR);
1645 }
1646 
1647 void BlockDataRegion::LazyInitializeReferencedVars() {
1648  if (ReferencedVars)
1649  return;
1650 
1652  const auto &ReferencedBlockVars = AC->getReferencedBlockVars(BC->getDecl());
1653  auto NumBlockVars =
1654  std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end());
1655 
1656  if (NumBlockVars == 0) {
1657  ReferencedVars = (void*) 0x1;
1658  return;
1659  }
1660 
1662  llvm::BumpPtrAllocator &A = MemMgr.getAllocator();
1663  BumpVectorContext BC(A);
1664 
1665  using VarVec = BumpVector<const MemRegion *>;
1666 
1667  auto *BV = A.Allocate<VarVec>();
1668  new (BV) VarVec(BC, NumBlockVars);
1669  auto *BVOriginal = A.Allocate<VarVec>();
1670  new (BVOriginal) VarVec(BC, NumBlockVars);
1671 
1672  for (const auto *VD : ReferencedBlockVars) {
1673  const VarRegion *VR = nullptr;
1674  const VarRegion *OriginalVR = nullptr;
1675  std::tie(VR, OriginalVR) = getCaptureRegions(VD);
1676  assert(VR);
1677  assert(OriginalVR);
1678  BV->push_back(VR, BC);
1679  BVOriginal->push_back(OriginalVR, BC);
1680  }
1681 
1682  ReferencedVars = BV;
1683  OriginalVars = BVOriginal;
1684 }
1685 
1686 BlockDataRegion::referenced_vars_iterator
1688  const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars();
1689 
1690  auto *Vec = static_cast<BumpVector<const MemRegion *> *>(ReferencedVars);
1691 
1692  if (Vec == (void*) 0x1)
1693  return BlockDataRegion::referenced_vars_iterator(nullptr, nullptr);
1694 
1695  auto *VecOriginal =
1696  static_cast<BumpVector<const MemRegion *> *>(OriginalVars);
1697 
1698  return BlockDataRegion::referenced_vars_iterator(Vec->begin(),
1699  VecOriginal->begin());
1700 }
1701 
1704  const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars();
1705 
1706  auto *Vec = static_cast<BumpVector<const MemRegion *> *>(ReferencedVars);
1707 
1708  if (Vec == (void*) 0x1)
1709  return BlockDataRegion::referenced_vars_iterator(nullptr, nullptr);
1710 
1711  auto *VecOriginal =
1712  static_cast<BumpVector<const MemRegion *> *>(OriginalVars);
1713 
1715  VecOriginal->end());
1716 }
1717 
1720  E = referenced_vars_end();
1721  I != E; ++I) {
1722  if (I.getCapturedRegion() == R)
1723  return I.getOriginalRegion();
1724  }
1725  return nullptr;
1726 }
1727 
1728 //===----------------------------------------------------------------------===//
1729 // RegionAndSymbolInvalidationTraits
1730 //===----------------------------------------------------------------------===//
1731 
1733  InvalidationKinds IK) {
1734  SymTraitsMap[Sym] |= IK;
1735 }
1736 
1738  InvalidationKinds IK) {
1739  assert(MR);
1740  if (const auto *SR = dyn_cast<SymbolicRegion>(MR))
1741  setTrait(SR->getSymbol(), IK);
1742  else
1743  MRTraitsMap[MR] |= IK;
1744 }
1745 
1747  InvalidationKinds IK) const {
1748  const_symbol_iterator I = SymTraitsMap.find(Sym);
1749  if (I != SymTraitsMap.end())
1750  return I->second & IK;
1751 
1752  return false;
1753 }
1754 
1756  InvalidationKinds IK) const {
1757  if (!MR)
1758  return false;
1759 
1760  if (const auto *SR = dyn_cast<SymbolicRegion>(MR))
1761  return hasTrait(SR->getSymbol(), IK);
1762 
1763  const_region_iterator I = MRTraitsMap.find(MR);
1764  if (I != MRTraitsMap.end())
1765  return I->second & IK;
1766 
1767  return false;
1768 }
clang::ento::MemRegionManager::getNonParamVarRegion
const NonParamVarRegion * getNonParamVarRegion(const VarDecl *VD, const MemRegion *superR)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
Definition: MemRegion.cpp:1065
clang::ento::CXXThisRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:277
clang::ento::ObjCStringRegion
The region associated with an ObjCStringLiteral.
Definition: MemRegion.h:853
AnalyzerOptions.h
clang::BlockDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:4369
clang::RecordDecl::field_begin
field_iterator field_begin() const
Definition: Decl.cpp:4754
clang::ento::MemRegionManager::getObjCIvarRegion
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
Definition: MemRegion.cpp:1187
clang::ASTRecordLayout::getFieldOffset
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:200
clang::ento::FunctionCodeRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:460
clang::ento::MemRegionManager::getStackArgumentsRegion
const StackArgumentsSpaceRegion * getStackArgumentsRegion(const StackFrameContext *STC)
getStackArgumentsRegion - Retrieve the memory region associated with function/method arguments of the...
Definition: MemRegion.cpp:872
clang::ento::FieldRegion::canPrintPretty
bool canPrintPretty() const override
Returns true if this region can be printed in a user-friendly way.
Definition: MemRegion.cpp:635
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
DynamicExtent.h
clang::DeclContext::specific_decl_iterator
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2198
clang::ento::SValBuilder::getAnalyzerOptions
const AnalyzerOptions & getAnalyzerOptions() const
Definition: SValBuilder.h:158
clang::ento::SVal::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: SVals.h:114
clang::LocationContext
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
Definition: AnalysisDeclContext.h:215
clang::LocationContext::getStackFrame
const StackFrameContext * getStackFrame() const
Definition: AnalysisDeclContext.cpp:463
clang::ento::CXXBaseObjectRegion::canPrintPrettyAsExpr
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:659
SVals.h
clang::ento::MemRegionManager::getCodeRegion
const CodeSpaceRegion * getCodeRegion()
Definition: MemRegion.cpp:914
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::ento::MemRegion::getMemRegionManager
virtual MemRegionManager & getMemRegionManager() const =0
clang::ento::CXXDerivedObjectRegion::getDecl
const LLVM_ATTRIBUTE_RETURNS_NONNULL CXXRecordDecl * getDecl() const
Definition: MemRegion.h:1319
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:560
clang::VarDecl::hasGlobalStorage
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:1173
clang::ento::FieldRegion::canPrintPrettyAsExpr
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:639
clang::ento::CXXTempObjectRegion::getValueType
QualType getValueType() const override
Definition: MemRegion.h:1247
clang::ento::MemRegionManager::getCompoundLiteralRegion
const CompoundLiteralRegion * getCompoundLiteralRegion(const CompoundLiteralExpr *CL, const LocationContext *LC)
getCompoundLiteralRegion - Retrieve the region associated with a given CompoundLiteral.
Definition: MemRegion.cpp:1119
clang::VarDecl::getCanonicalDecl
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2183
clang::QualType::isConstQualified
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:6694
clang::ento::NonLoc
Definition: SVals.h:266
clang::ento::BlockDataRegion::referenced_vars_begin
referenced_vars_iterator referenced_vars_begin() const
Definition: MemRegion.cpp:1687
clang::ento::MemRegion::dump
void dump() const
Definition: MemRegion.cpp:441
AnalysisDeclContext.h
clang::ento::DefinedOrUnknownSVal
Definition: SVals.h:221
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1107
clang::ento::FunctionCodeRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:352
clang::ento::MemRegion::StripCasts
const LLVM_ATTRIBUTE_RETURNS_NONNULL MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
Definition: MemRegion.cpp:1342
clang::ento::MemRegion::hasStackParametersStorage
bool hasStackParametersStorage() const
Definition: MemRegion.cpp:1297
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
calculateOffset
static RegionOffset calculateOffset(const MemRegion *R)
Definition: MemRegion.cpp:1440
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
Attr.h
clang::ASTRecordLayout::getBaseClassOffset
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:249
clang::AnalysisDeclContext
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Definition: AnalysisDeclContext.h:72
clang::ento::MemRegionManager::getSymbolicHeapRegion
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
Definition: MemRegion.cpp:1176
clang::ento::ElementRegion::getIndex
NonLoc getIndex() const
Definition: MemRegion.h:1209
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2930
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1712
DeclCXX.h
clang::ASTContext::getFunctionType
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1561
clang::ento::CompoundLiteralRegion
CompoundLiteralRegion - A memory region representing a compound literal.
Definition: MemRegion.h:890
SymbolManager.h
clang::ento::NonParamVarRegion::canPrintPrettyAsExpr
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:612
clang::ento::CXXDerivedObjectRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:415
clang::ento::CompoundLiteralRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:257
clang::ento::MemSpaceRegion
MemSpaceRegion - A memory region that represents a "memory space"; for example, the set of global var...
Definition: MemRegion.h:204
clang::ento::SValBuilder::getArrayIndexType
QualType getArrayIndexType() const
Definition: SValBuilder.h:145
clang::ento::StaticGlobalSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:549
clang::ento::MemRegionManager::getBlockDataRegion
const BlockDataRegion * getBlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc, unsigned blockCount)
getBlockDataRegion - Get the memory region associated with an instance of a block.
Definition: MemRegion.cpp:1081
clang::ento::BlockDataRegion::getCodeRegion
const LLVM_ATTRIBUTE_RETURNS_NONNULL BlockCodeRegion * getCodeRegion() const
Definition: MemRegion.h:701
clang::ento::ObjCIvarRegion
Definition: MemRegion.h:1136
llvm::Optional
Definition: LLVM.h:40
clang::ento::MemRegion::hasGlobalsOrParametersStorage
bool hasGlobalsOrParametersStorage() const
Definition: MemRegion.cpp:1301
clang::ento::MemRegionManager::getUnknownRegion
const UnknownSpaceRegion * getUnknownRegion()
getUnknownRegion - Retrieve the memory region associated with unknown memory space.
Definition: MemRegion.cpp:910
clang::ento::SubRegion::isSubRegionOf
bool isSubRegionOf(const MemRegion *R) const override
Check if the region is a subregion of the given region.
Definition: MemRegion.cpp:134
clang::ento::GlobalSystemSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:557
clang::StackFrameContext
It represents a stack frame of the call stack (based on CallEvent).
Definition: AnalysisDeclContext.h:299
SourceManager.h
clang::ento::MemRegionManager::getHeapRegion
const HeapSpaceRegion * getHeapRegion()
getHeapRegion - Retrieve the memory region associated with the generic "heap".
Definition: MemRegion.cpp:906
clang::ento::StackSpaceRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:218
clang::ento::nonloc::ConcreteInt
Value representing integer constant.
Definition: SVals.h:330
clang::ento::MemRegionManager::getCXXDerivedObjectRegion
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
Definition: MemRegion.cpp:1243
clang::ento::UnknownVal
Definition: SVals.h:236
clang::ento::StackLocalsSpaceRegion
Definition: MemRegion.h:411
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
clang::ento::MemRegionManager::getFunctionCodeRegion
const FunctionCodeRegion * getFunctionCodeRegion(const NamedDecl *FD)
Definition: MemRegion.cpp:1157
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3675
clang::ento::ElementRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:341
clang::ento::MemRegionManager::getVarRegion
const VarRegion * getVarRegion(const VarDecl *VD, const LocationContext *LC)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
Definition: MemRegion.cpp:964
clang::ento::StaticGlobalSpaceRegion::getCodeRegion
const LLVM_ATTRIBUTE_RETURNS_NONNULL CodeTextRegion * getCodeRegion() const
Definition: MemRegion.h:277
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:721
clang::ento::CXXThisRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:497
clang::ento::ElementRegion::getElementType
QualType getElementType() const
Definition: MemRegion.h:1213
clang::ento::HeapSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:565
clang::ento::DeclRegion
Definition: MemRegion.h:924
clang::ento::BlockCodeRegion
BlockCodeRegion - A region that represents code texts of blocks (closures).
Definition: MemRegion.h:627
clang::ento::FunctionCodeRegion::getDecl
const NamedDecl * getDecl() const
Definition: MemRegion.h:608
clang::ento::SVal::getAs
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type.
Definition: SVals.h:104
Decl.h
clang::ento::MemRegionManager::getCXXBaseObjectRegion
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
Definition: MemRegion.cpp:1223
DeclObjC.h
Offset
unsigned Offset
Definition: Format.cpp:2717
clang::ento::ParamVarRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:317
clang::ento::MemRegion
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:95
clang::ento::RegionOffset
Represent a region's offset within the top level base region.
Definition: MemRegion.h:62
clang::ASTContext::getBlockPointerType
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
Definition: ASTContext.cpp:3433
PrettyPrinter.h
clang::CompoundLiteralExpr::isFileScope
bool isFileScope() const
Definition: Expr.h:3437
clang::ento::MemRegionManager::getAllocaRegion
const AllocaRegion * getAllocaRegion(const Expr *Ex, unsigned Cnt, const LocationContext *LC)
getAllocaRegion - Retrieve a region associated with a call to alloca().
Definition: MemRegion.cpp:1270
clang::ento::MemRegionManager::getFieldRegion
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
Definition: MemRegion.cpp:1181
clang::ento::UnknownSpaceRegion
Definition: MemRegion.h:373
clang::ento::CodeSpaceRegion
CodeSpaceRegion - The memory space that holds the executable code of functions and blocks.
Definition: MemRegion.h:227
clang::ento::BlockCodeRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:364
clang::ento::CXXBaseObjectRegion::getDecl
const LLVM_ATTRIBUTE_RETURNS_NONNULL CXXRecordDecl * getDecl() const
Definition: MemRegion.h:1276
isImmediateBase
static bool isImmediateBase(const CXXRecordDecl *Child, const CXXRecordDecl *Base)
Returns true if Base is an immediate base class of Child.
Definition: MemRegion.cpp:1426
V
#define V(N, I)
Definition: ASTContext.h:3235
clang::ento::CXXBaseObjectRegion::getValueType
QualType getValueType() const override
Definition: MemRegion.cpp:175
clang::ento::CXXBaseObjectRegion::printPrettyAsExpr
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition: MemRegion.cpp:663
clang::ento::CompoundLiteralRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:479
clang::ento::RegionAndSymbolInvalidationTraits::hasTrait
bool hasTrait(SymbolRef Sym, InvalidationKinds IK) const
Definition: MemRegion.cpp:1746
clang::ento::MemRegion::getContext
ASTContext & getContext() const
Definition: MemRegion.h:1561
clang::ento::FieldRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:281
clang::ento::MemRegionManager::getCXXThisRegion
const CXXThisRegion * getCXXThisRegion(QualType thisPointerTy, const LocationContext *LC)
getCXXThisRegion - Retrieve the [artificial] region associated with the parameter 'this'.
Definition: MemRegion.cpp:1249
clang::ento::ObjCIvarRegion::getValueType
QualType getValueType() const override
Definition: MemRegion.cpp:171
clang::ento::MemRegion::getSymbolicBase
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region.
Definition: MemRegion.cpp:1365
clang::Stmt::printPretty
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
Definition: StmtPrinter.cpp:2737
clang::BlockDecl
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4283
clang::ento::ParamVarRegion::canPrintPrettyAsExpr
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:618
clang::ento::BlockDataRegion::referenced_vars_iterator
Definition: MemRegion.h:708
clang::ento::NonParamVarRegion
Definition: MemRegion.h:972
clang::VarDecl::isStaticLocal
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition: Decl.h:1155
clang::ento::ParamVarRegion::printPrettyAsExpr
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition: MemRegion.cpp:620
clang::ASTContext::getAsArrayType
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Definition: ASTContext.cpp:6873
clang::CharUnits::fromQuantity
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
clang::ento::BlockCodeRegion::getAnalysisDeclContext
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
Definition: MemRegion.h:657
clang::ento::MemRegionManager::getBlockCodeRegion
const BlockCodeRegion * getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
Definition: MemRegion.cpp:1163
clang::ObjCStringLiteral
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:52
clang::ento::AllocaRegion
AllocaRegion - A region that represents an untyped blob of bytes created by a call to 'alloca'.
Definition: MemRegion.h:474
clang::ento::RegionAndSymbolInvalidationTraits::setTrait
void setTrait(SymbolRef Sym, InvalidationKinds IK)
Definition: MemRegion.cpp:1732
clang::ento::MemRegionManager::getStaticSize
DefinedOrUnknownSVal getStaticSize(const MemRegion *MR, SValBuilder &SVB) const
Definition: MemRegion.cpp:736
clang::ento::AllocaRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:253
clang::LocationContext::inTopFrame
virtual bool inTopFrame() const
Definition: AnalysisDeclContext.cpp:473
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3012
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:29
clang::DeclarationName::getAsString
std::string getAsString() const
Retrieve the human-readable string for this name.
Definition: DeclarationName.cpp:235
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::ento::RegionAndSymbolInvalidationTraits::InvalidationKinds
InvalidationKinds
Describes different invalidation traits.
Definition: MemRegion.h:1583
clang::ento::CXXTempObjectRegion
Definition: MemRegion.h:1228
clang::ento::MemRegion::isSubRegionOf
virtual bool isSubRegionOf(const MemRegion *R) const
Check if the region is a subregion of the given region.
Definition: MemRegion.cpp:1334
clang::ento::MemSpaceRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:214
clang::ento::MemRegionManager::getElementRegion
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type,...
Definition: MemRegion.cpp:1135
clang::ento::BlockDataRegion
BlockDataRegion - A region that represents a block instance.
Definition: MemRegion.h:674
IdentifierTable.h
clang::ento::VarRegion
Definition: MemRegion.h:940
clang::ento::NonParamVarRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:530
Type.h
clang::ento::StringRegion
StringRegion - Region associated with a StringLiteral.
Definition: MemRegion.h:819
Expr.h
llvm::SmallString
Definition: LLVM.h:37
clang::ento::CXXTempObjectRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:484
ASTContext.h
BumpVector.h
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::ento::FieldRegion::getDecl
const LLVM_ATTRIBUTE_RETURNS_NONNULL FieldDecl * getDecl() const override
Definition: MemRegion.h:1115
clang::StringLiteral
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1776
clang::ento::UnknownSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:569
clang::ento::CodeSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:545
clang::ento::MemRegion::printPretty
virtual void printPretty(raw_ostream &os) const
Print the region for use in diagnostics.
Definition: MemRegion.cpp:601
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2528
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1760
clang::ento::BlockCodeRegion::getDecl
const LLVM_ATTRIBUTE_RETURNS_NONNULL BlockDecl * getDecl() const
Definition: MemRegion.h:652
clang::ento::RegionRawOffset::getOffset
CharUnits getOffset() const
Definition: MemRegion.h:1179
clang::TagDecl::isUnion
bool isUnion() const
Definition: Decl.h:3629
clang::ento::MemRegion::getKind
Kind getKind() const
Definition: MemRegion.h:173
isValidBaseClass
static bool isValidBaseClass(const CXXRecordDecl *BaseClass, const TypedValueRegion *Super, bool IsVirtual)
Checks whether BaseClass is a valid virtual or direct non-virtual base class of the type of Super.
Definition: MemRegion.cpp:1202
clang::ento::MemRegion::hasStackNonParametersStorage
bool hasStackNonParametersStorage() const
Definition: MemRegion.cpp:1293
clang::CanQual< Type >
clang::ento::ElementRegion
ElementRegion is used to represent both array elements and casts.
Definition: MemRegion.h:1189
clang::ento::FieldRegion
Definition: MemRegion.h:1096
Base
clang::ento::CXXTempObjectRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:391
clang::ento::RegionRawOffset::dump
void dump() const
Definition: MemRegion.cpp:537
clang::ento::MemRegion::getAsOffset
RegionOffset getAsOffset() const
Compute the offset within the top level memory object.
Definition: MemRegion.cpp:1614
clang::ento::MemRegion::Kind
Kind
Definition: MemRegion.h:97
clang::TagDecl::isCompleteDefinition
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3528
clang::ento::NonParamVarRegion::printPrettyAsExpr
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition: MemRegion.cpp:614
clang::ento::SymbolicRegion
SymbolicRegion - A special, "non-concrete" region.
Definition: MemRegion.h:770
clang::ento::ObjCIvarRegion::printPrettyAsExpr
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition: MemRegion.cpp:631
clang::ento::MemRegion::canPrintPrettyAsExpr
virtual bool canPrintPrettyAsExpr() const
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:597
clang::ento::getElementExtent
DefinedOrUnknownSVal getElementExtent(QualType Ty, SValBuilder &SVB)
CharUnits.h
clang::ASTRecordLayout::getVBaseClassOffset
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:259
clang::ento::NonParamVarRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:305
clang::ento::ObjCStringRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:519
clang::ento::MemRegionManager::getParamVarRegion
const ParamVarRegion * getParamVarRegion(const Expr *OriginExpr, unsigned Index, const LocationContext *LC)
getParamVarRegion - Retrieve or create the memory region associated with a specified CallExpr,...
Definition: MemRegion.cpp:1072
clang::BlockDecl::hasCaptures
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition: Decl.h:4402
clang::ento::SValBuilder
Definition: SValBuilder.h:53
clang::ento::CXXBaseObjectRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:489
clang::CompoundLiteralExpr
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3410
clang::LocationContext::getParent
const LocationContext * getParent() const
It might return null.
Definition: AnalysisDeclContext.h:247
clang::ento::StackArgumentsSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:573
clang::ento::MemRegion::getAs
const RegionTy * getAs() const
Definition: MemRegion.h:1337
clang::ASTRecordLayout
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::ento::MemRegion::getMemorySpace
const LLVM_ATTRIBUTE_RETURNS_NONNULL MemSpaceRegion * getMemorySpace() const
Definition: MemRegion.cpp:1277
clang::ento::MemRegion::hasStackStorage
bool hasStackStorage() const
Definition: MemRegion.cpp:1289
clang::ento::CXXDerivedObjectRegion::canPrintPrettyAsExpr
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:667
clang::Stmt::getID
int64_t getID(const ASTContext &Context) const
Definition: Stmt.cpp:360
clang::ento::RegionOffset::Symbolic
static const int64_t Symbolic
Definition: MemRegion.h:72
clang::ento::ElementRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:501
clang::ento::HeapSpaceRegion
Definition: MemRegion.h:359
SValBuilder.h
clang::ento::GlobalsSpaceRegion
Definition: MemRegion.h:241
clang::ento::CodeTextRegion
Definition: MemRegion.h:562
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
clang::LangOptions::StrictFlexArraysLevelKind
StrictFlexArraysLevelKind
Definition: LangOptions.h:369
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1923
clang::ento::MemRegionManager::getCXXTempObjectRegion
const CXXTempObjectRegion * getCXXTempObjectRegion(Expr const *Ex, LocationContext const *LC)
Definition: MemRegion.cpp:1193
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:802
clang::ento::ParamVarRegion::getIndex
unsigned getIndex() const
Definition: MemRegion.h:1042
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::ento::StackArgumentsSpaceRegion
Definition: MemRegion.h:425
clang::StackFrameContext::getCallSite
const Stmt * getCallSite() const
Definition: AnalysisDeclContext.h:325
clang::ento::FunctionCodeRegion
FunctionCodeRegion - A region that represents code texts of function.
Definition: MemRegion.h:580
clang::ento::StringRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:514
clang::ento::SValBuilder::makeIntVal
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
Definition: SValBuilder.h:269
clang::ento::MemRegionManager::getStackLocalsRegion
const StackLocalsSpaceRegion * getStackLocalsRegion(const StackFrameContext *STC)
getStackLocalsRegion - Retrieve the memory region associated with the specified stack frame.
Definition: MemRegion.cpp:859
clang::ento::MemRegionManager::getStringRegion
const StringRegion * getStringRegion(const StringLiteral *Str)
Definition: MemRegion.cpp:922
LLVM.h
clang::AnalyzerOptions
Stores options for the analyzer from the command line.
Definition: AnalyzerOptions.h:150
clang::ento::BlockDataRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:468
clang::ento::RegionRawOffset
Definition: MemRegion.h:1168
clang::ento::BlockDataRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:380
clang::ento::VarRegion::getStackFrame
const StackFrameContext * getStackFrame() const
It might return null.
Definition: MemRegion.cpp:159
getStackOrCaptureRegionForDeclContext
static llvm::PointerUnion< const StackFrameContext *, const VarRegion * > getStackOrCaptureRegionForDeclContext(const LocationContext *LC, const DeclContext *DC, const VarDecl *VD)
Look through a chain of LocationContexts to either find the StackFrameContext that matches a DeclCont...
Definition: MemRegion.cpp:937
clang::ento::ParamVarRegion::getOriginExpr
const LLVM_ATTRIBUTE_RETURNS_NONNULL Expr * getOriginExpr() const
Definition: MemRegion.h:1041
clang::ento::GlobalInternalSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:553
clang::ento::SymbolicRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:328
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::ento::BlockDataRegion::referenced_vars_end
referenced_vars_iterator referenced_vars_end() const
Definition: MemRegion.cpp:1703
clang::RecordDecl::field_end
field_iterator field_end() const
Definition: Decl.h:4212
clang::ento::StackSpaceRegion::getStackFrame
const LLVM_ATTRIBUTE_RETURNS_NONNULL StackFrameContext * getStackFrame() const
Definition: MemRegion.h:401
clang::ento::MemRegion::getMostDerivedObjectRegion
const LLVM_ATTRIBUTE_RETURNS_NONNULL MemRegion * getMostDerivedObjectRegion() const
Recursively retrieve the region of the most derived class instance of regions of C++ base class insta...
Definition: MemRegion.cpp:1327
clang::ento::FieldRegion::printPrettyAsExpr
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition: MemRegion.cpp:643
clang::ento::MemRegionManager::getObjCStringRegion
const ObjCStringRegion * getObjCStringRegion(const ObjCStringLiteral *Str)
Definition: MemRegion.cpp:928
clang::ento::SymbolicRegion::ProfileRegion
static void ProfileRegion(llvm::FoldingSetNodeID &ID, SymbolRef sym, const MemRegion *superRegion)
Definition: MemRegion.cpp:321
clang::ento::MemRegionManager
Definition: MemRegion.h:1353
clang::ento::nonloc::SymbolVal
Represents symbolic expression that isn't a location.
Definition: SVals.h:305
clang::ento::GlobalImmutableSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:561
clang::ento::RegionRawOffset::getRegion
const MemRegion * getRegion() const
Definition: MemRegion.h:1182
clang::AnalysisDeclContext::getReferencedBlockVars
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
Definition: AnalysisDeclContext.cpp:664
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2769
clang::ento::NonParamVarRegion::getDecl
const LLVM_ATTRIBUTE_RETURNS_NONNULL VarDecl * getDecl() const override
Definition: MemRegion.h:996
clang::CanQual::getUnqualifiedType
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Definition: CanonicalType.h:619
clang::ento::ParamVarRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:581
clang::ento::BlockCodeRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:464
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::FunctionProtoType::ExtProtoInfo
Extra information about a function prototype.
Definition: Type.h:4099
clang
Definition: CalledOnceCheck.h:17
hlsl::int64_t
long int64_t
Definition: hlsl_basic_types.h:26
clang::ento::FieldRegion::printPretty
void printPretty(raw_ostream &os) const override
Print the region for use in diagnostics.
Definition: MemRegion.cpp:649
distance
float __ovld __cnfn distance(float, float)
Returns the distance between p0 and p1.
clang::ento::MemRegionManager::getCXXStaticTempObjectRegion
const CXXTempObjectRegion * getCXXStaticTempObjectRegion(const Expr *Ex)
Create a CXXTempObjectRegion for temporaries which are lifetime-extended by static references.
Definition: MemRegion.cpp:1113
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::ObjCIvarDecl
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1921
clang::ento::SubRegion::getMemRegionManager
MemRegionManager & getMemRegionManager() const override
Definition: MemRegion.cpp:147
clang::ento::MemRegion::printPrettyAsExpr
virtual void printPrettyAsExpr(raw_ostream &os) const
Print the region as expression.
Definition: MemRegion.cpp:608
clang::ento::MemRegionManager::getContext
ASTContext & getContext()
Definition: MemRegion.h:1378
clang::CXXRecordDecl::getCanonicalDecl
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:502
clang::SourceManager::isInSystemHeader
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
Definition: SourceManager.h:1504
clang::ento::ParamVarRegion::getValueType
QualType getValueType() const override
Definition: MemRegion.cpp:183
clang::ento::BlockDataRegion::MemRegionManager
friend class MemRegionManager
Definition: MemRegion.h:675
MemRegion.h
clang::ento::SymbolManager::getExtentSymbol
const SymbolExtent * getExtentSymbol(const SubRegion *R)
Definition: SymbolManager.cpp:219
clang::ento::CXXBaseObjectRegion::isVirtual
bool isVirtual() const
Definition: MemRegion.h:1277
clang::ento::StaticGlobalSpaceRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:223
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6593
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
clang::ento::SubRegion::getSuperRegion
const LLVM_ATTRIBUTE_RETURNS_NONNULL MemRegion * getSuperRegion() const
Definition: MemRegion.h:455
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:320
clang::ento::MemRegion::getDescriptiveName
std::string getDescriptiveName(bool UseQuotes=true) const
Get descriptive name for memory region.
Definition: MemRegion.cpp:675
clang::ento::CXXDerivedObjectRegion::printPrettyAsExpr
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition: MemRegion.cpp:671
clang::ento::SValBuilder::getSymbolManager
SymbolManager & getSymbolManager()
Definition: SValBuilder.h:152
clang::ento::MemRegion::dumpToStream
virtual void dumpToStream(raw_ostream &os) const
Definition: MemRegion.cpp:452
clang::BlockDecl::getSignatureAsWritten
TypeSourceInfo * getSignatureAsWritten() const
Definition: Decl.h:4366
clang::ento::StaticGlobalSpaceRegion
The region of the static variables within the current CodeTextRegion scope.
Definition: MemRegion.h:261
clang::ento::CXXThisRegion
CXXThisRegion - Represents the region for the implicit 'this' parameter in a call to a C++ method.
Definition: MemRegion.h:1064
clang::ento::MemRegion::~MemRegion
virtual ~MemRegion()
clang::ento::SVal
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition: SVals.h:73
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::ento::ObjCIvarRegion::canPrintPrettyAsExpr
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition: MemRegion.cpp:627
clang::ento::MemRegionManager::getGlobalsRegion
const GlobalsSpaceRegion * getGlobalsRegion(MemRegion::Kind K=MemRegion::GlobalInternalSpaceRegionKind, const CodeTextRegion *R=nullptr)
getGlobalsRegion - Retrieve the memory region associated with global variables.
Definition: MemRegion.cpp:885
clang::ento::RegionRawOffset::dumpToStream
void dumpToStream(raw_ostream &os) const
Definition: MemRegion.cpp:541
clang::ento::CXXDerivedObjectRegion::getValueType
QualType getValueType() const override
Definition: MemRegion.cpp:179
clang::ento::SubRegion
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:442
clang::ento::CXXDerivedObjectRegion
Definition: MemRegion.h:1299
clang::ento::MemRegionManager::getSymbolicRegion
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym, const MemSpaceRegion *MemSpace=nullptr)
Retrieve or create a "symbolic" memory region.
Definition: MemRegion.cpp:1169
clang::ento::StackLocalsSpaceRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:577
clang::ento::AllocaRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:456
clang::ento::MemRegion::getBaseRegion
const LLVM_ATTRIBUTE_RETURNS_NONNULL MemRegion * getBaseRegion() const
Definition: MemRegion.cpp:1307
clang::ento::CXXBaseObjectRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:404
clang::BumpVectorContext
Definition: BumpVector.h:32
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:712
clang::ento::ObjCIvarRegion::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.cpp:293
clang::ento::MemRegionManager::~MemRegionManager
~MemRegionManager()
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::ento::CXXDerivedObjectRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:493
clang::VarDecl::hasLocalStorage
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Definition: Decl.h:1131
clang::ento::SymbolicRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:524
clang::ento::BlockDataRegion::getOriginalRegion
const VarRegion * getOriginalRegion(const VarRegion *VR) const
Return the original region for a captured region, if one exists.
Definition: MemRegion.cpp:1718
clang::ento::MemRegion::getString
std::string getString() const
Get a string representation of a region for debug use.
Definition: MemRegion.cpp:445
clang::ento::MemRegion::canPrintPretty
virtual bool canPrintPretty() const
Returns true if this region can be printed in a user-friendly way.
Definition: MemRegion.cpp:593
clang::Type::isIncompleteType
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2235
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::ento::ObjCIvarRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:510
clang::Decl::getID
int64_t getID() const
Definition: DeclBase.cpp:1027
clang::ento::FieldRegion::dumpToStream
void dumpToStream(raw_ostream &os) const override
Definition: MemRegion.cpp:506
clang::ento::ObjCIvarRegion::getDecl
const LLVM_ATTRIBUTE_RETURNS_NONNULL ObjCIvarDecl * getDecl() const override
Definition: MemRegion.cpp:169
clang::LocationContext::getDecl
const Decl * getDecl() const
Definition: AnalysisDeclContext.h:251
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3983
clang::ento::SymbolManager
Definition: SymbolManager.h:481
clang::ento::SubRegion::superRegion
const MemRegion * superRegion
Definition: MemRegion.h:446
clang::ento::VarRegion::getDecl
const VarDecl * getDecl() const override=0
clang::BumpVector
Definition: BumpVector.h:59
clang::ento::MemRegion::sourceRange
SourceRange sourceRange() const
Retrieve source range from memory region.
Definition: MemRegion.cpp:714
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:791
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
clang::ento::ElementRegion::getAsArrayOffset
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
Definition: MemRegion.cpp:1376
RecordLayout.h
clang::ento::ParamVarRegion::getDecl
const ParmVarDecl * getDecl() const override
TODO: What does this return?
Definition: MemRegion.cpp:190
clang::ento::ParamVarRegion
ParamVarRegion - Represents a region for paremters.
Definition: MemRegion.h:1024
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:441
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274