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