clang  15.0.0git
APValue.cpp
Go to the documentation of this file.
1 //===--- APValue.cpp - Union class for APFloat/APSInt/Complex -------------===//
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 implements the APValue class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/APValue.h"
14 #include "Linkage.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/CharUnits.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/ExprCXX.h"
20 #include "clang/AST/Type.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/raw_ostream.h"
23 using namespace clang;
24 
25 /// The identity of a type_info object depends on the canonical unqualified
26 /// type only.
28  : T(T->getCanonicalTypeUnqualified().getTypePtr()) {}
29 
30 void TypeInfoLValue::print(llvm::raw_ostream &Out,
31  const PrintingPolicy &Policy) const {
32  Out << "typeid(";
33  QualType(getType(), 0).print(Out, Policy);
34  Out << ")";
35 }
36 
37 static_assert(
39  alignof(Type),
40  "Type is insufficiently aligned");
41 
42 APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
43  : Ptr(P ? cast<ValueDecl>(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
44 APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
45  : Ptr(P), Local{I, V} {}
46 
48  QualType Type) {
50  Base.Ptr = LV;
51  Base.DynamicAllocType = Type.getAsOpaquePtr();
52  return Base;
53 }
54 
58  Base.Ptr = LV;
59  Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
60  return Base;
61 }
62 
64  if (!*this) return QualType();
65  if (const ValueDecl *D = dyn_cast<const ValueDecl*>()) {
66  // FIXME: It's unclear where we're supposed to take the type from, and
67  // this actually matters for arrays of unknown bound. Eg:
68  //
69  // extern int arr[]; void f() { extern int arr[3]; };
70  // constexpr int *p = &arr[1]; // valid?
71  //
72  // For now, we take the most complete type we can find.
73  for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
74  Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())) {
75  QualType T = Redecl->getType();
76  if (!T->isIncompleteArrayType())
77  return T;
78  }
79  return D->getType();
80  }
81 
82  if (is<TypeInfoLValue>())
83  return getTypeInfoType();
84 
85  if (is<DynamicAllocLValue>())
86  return getDynamicAllocType();
87 
88  const Expr *Base = get<const Expr*>();
89 
90  // For a materialized temporary, the type of the temporary we materialized
91  // may not be the type of the expression.
92  if (const MaterializeTemporaryExpr *MTE =
93  clang::dyn_cast<MaterializeTemporaryExpr>(Base)) {
96  const Expr *Temp = MTE->getSubExpr();
97  const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHSs,
98  Adjustments);
99  // Keep any cv-qualifiers from the reference if we generated a temporary
100  // for it directly. Otherwise use the type after adjustment.
101  if (!Adjustments.empty())
102  return Inner->getType();
103  }
104 
105  return Base->getType();
106 }
107 
109  return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0
110  : Local.CallIndex;
111 }
112 
114  return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0 : Local.Version;
115 }
116 
118  assert(is<TypeInfoLValue>() && "not a type_info lvalue");
119  return QualType::getFromOpaquePtr(TypeInfoType);
120 }
121 
123  assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
124  return QualType::getFromOpaquePtr(DynamicAllocType);
125 }
126 
127 void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128  ID.AddPointer(Ptr.getOpaqueValue());
129  if (is<TypeInfoLValue>() || is<DynamicAllocLValue>())
130  return;
131  ID.AddInteger(Local.CallIndex);
132  ID.AddInteger(Local.Version);
133 }
134 
135 namespace clang {
137  const APValue::LValueBase &RHS) {
138  if (LHS.Ptr != RHS.Ptr)
139  return false;
140  if (LHS.is<TypeInfoLValue>() || LHS.is<DynamicAllocLValue>())
141  return true;
142  return LHS.Local.CallIndex == RHS.Local.CallIndex &&
143  LHS.Local.Version == RHS.Local.Version;
144 }
145 }
146 
148  if (const Decl *D = BaseOrMember.getPointer())
149  BaseOrMember.setPointer(D->getCanonicalDecl());
150  Value = reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue());
151 }
152 
153 void APValue::LValuePathEntry::Profile(llvm::FoldingSetNodeID &ID) const {
154  ID.AddInteger(Value);
155 }
156 
158  ArrayRef<LValuePathEntry> Path, QualType ElemTy)
159  : ElemTy((const void *)ElemTy.getTypePtrOrNull()), Path(Path) {}
160 
162  return QualType::getFromOpaquePtr(ElemTy);
163 }
164 
165 namespace {
166  struct LVBase {
169  unsigned PathLength;
170  bool IsNullPtr : 1;
171  bool IsOnePastTheEnd : 1;
172  };
173 }
174 
176  return Ptr.getOpaqueValue();
177 }
178 
180  return Ptr.isNull();
181 }
182 
183 APValue::LValueBase::operator bool () const {
184  return static_cast<bool>(Ptr);
185 }
186 
190  B.Ptr = DenseMapInfo<const ValueDecl*>::getEmptyKey();
191  return B;
192 }
193 
197  B.Ptr = DenseMapInfo<const ValueDecl*>::getTombstoneKey();
198  return B;
199 }
200 
201 namespace clang {
202 llvm::hash_code hash_value(const APValue::LValueBase &Base) {
203  if (Base.is<TypeInfoLValue>() || Base.is<DynamicAllocLValue>())
204  return llvm::hash_value(Base.getOpaqueValue());
205  return llvm::hash_combine(Base.getOpaqueValue(), Base.getCallIndex(),
206  Base.getVersion());
207 }
208 }
209 
212  return hash_value(Base);
213 }
214 
216  const clang::APValue::LValueBase &LHS,
217  const clang::APValue::LValueBase &RHS) {
218  return LHS == RHS;
219 }
220 
221 struct APValue::LV : LVBase {
222  static const unsigned InlinePathSpace =
223  (DataSize - sizeof(LVBase)) / sizeof(LValuePathEntry);
224 
225  /// Path - The sequence of base classes, fields and array indices to follow to
226  /// walk from Base to the subobject. When performing GCC-style folding, there
227  /// may not be such a path.
228  union {
229  LValuePathEntry Path[InlinePathSpace];
231  };
232 
233  LV() { PathLength = (unsigned)-1; }
234  ~LV() { resizePath(0); }
235 
236  void resizePath(unsigned Length) {
237  if (Length == PathLength)
238  return;
239  if (hasPathPtr())
240  delete [] PathPtr;
241  PathLength = Length;
242  if (hasPathPtr())
243  PathPtr = new LValuePathEntry[Length];
244  }
245 
246  bool hasPath() const { return PathLength != (unsigned)-1; }
247  bool hasPathPtr() const { return hasPath() && PathLength > InlinePathSpace; }
248 
249  LValuePathEntry *getPath() { return hasPathPtr() ? PathPtr : Path; }
250  const LValuePathEntry *getPath() const {
251  return hasPathPtr() ? PathPtr : Path;
252  }
253 };
254 
255 namespace {
256  struct MemberPointerBase {
257  llvm::PointerIntPair<const ValueDecl*, 1, bool> MemberAndIsDerivedMember;
258  unsigned PathLength;
259  };
260 }
261 
262 struct APValue::MemberPointerData : MemberPointerBase {
263  static const unsigned InlinePathSpace =
264  (DataSize - sizeof(MemberPointerBase)) / sizeof(const CXXRecordDecl*);
265  typedef const CXXRecordDecl *PathElem;
266  union {
267  PathElem Path[InlinePathSpace];
268  PathElem *PathPtr;
269  };
270 
271  MemberPointerData() { PathLength = 0; }
272  ~MemberPointerData() { resizePath(0); }
273 
274  void resizePath(unsigned Length) {
275  if (Length == PathLength)
276  return;
277  if (hasPathPtr())
278  delete [] PathPtr;
279  PathLength = Length;
280  if (hasPathPtr())
281  PathPtr = new PathElem[Length];
282  }
283 
284  bool hasPathPtr() const { return PathLength > InlinePathSpace; }
285 
286  PathElem *getPath() { return hasPathPtr() ? PathPtr : Path; }
287  const PathElem *getPath() const {
288  return hasPathPtr() ? PathPtr : Path;
289  }
290 };
291 
292 // FIXME: Reduce the malloc traffic here.
293 
294 APValue::Arr::Arr(unsigned NumElts, unsigned Size) :
295  Elts(new APValue[NumElts + (NumElts != Size ? 1 : 0)]),
296  NumElts(NumElts), ArrSize(Size) {}
297 APValue::Arr::~Arr() { delete [] Elts; }
298 
299 APValue::StructData::StructData(unsigned NumBases, unsigned NumFields) :
300  Elts(new APValue[NumBases+NumFields]),
301  NumBases(NumBases), NumFields(NumFields) {}
302 APValue::StructData::~StructData() {
303  delete [] Elts;
304 }
305 
306 APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
307 APValue::UnionData::~UnionData () {
308  delete Value;
309 }
310 
311 APValue::APValue(const APValue &RHS) : Kind(None) {
312  switch (RHS.getKind()) {
313  case None:
314  case Indeterminate:
315  Kind = RHS.getKind();
316  break;
317  case Int:
318  MakeInt();
319  setInt(RHS.getInt());
320  break;
321  case Float:
322  MakeFloat();
323  setFloat(RHS.getFloat());
324  break;
325  case FixedPoint: {
326  APFixedPoint FXCopy = RHS.getFixedPoint();
327  MakeFixedPoint(std::move(FXCopy));
328  break;
329  }
330  case Vector:
331  MakeVector();
332  setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
333  RHS.getVectorLength());
334  break;
335  case ComplexInt:
336  MakeComplexInt();
338  break;
339  case ComplexFloat:
340  MakeComplexFloat();
342  break;
343  case LValue:
344  MakeLValue();
345  if (RHS.hasLValuePath())
347  RHS.isLValueOnePastTheEnd(), RHS.isNullPointer());
348  else
350  RHS.isNullPointer());
351  break;
352  case Array:
353  MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
354  for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I)
356  if (RHS.hasArrayFiller())
357  getArrayFiller() = RHS.getArrayFiller();
358  break;
359  case Struct:
360  MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields());
361  for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I)
362  getStructBase(I) = RHS.getStructBase(I);
363  for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I)
364  getStructField(I) = RHS.getStructField(I);
365  break;
366  case Union:
367  MakeUnion();
368  setUnion(RHS.getUnionField(), RHS.getUnionValue());
369  break;
370  case MemberPointer:
371  MakeMemberPointer(RHS.getMemberPointerDecl(),
373  RHS.getMemberPointerPath());
374  break;
375  case AddrLabelDiff:
376  MakeAddrLabelDiff();
378  break;
379  }
380 }
381 
382 APValue::APValue(APValue &&RHS) : Kind(RHS.Kind), Data(RHS.Data) {
383  RHS.Kind = None;
384 }
385 
387  if (this != &RHS)
388  *this = APValue(RHS);
389  return *this;
390 }
391 
393  if (Kind != None && Kind != Indeterminate)
394  DestroyDataAndMakeUninit();
395  Kind = RHS.Kind;
396  Data = RHS.Data;
397  RHS.Kind = None;
398  return *this;
399 }
400 
401 void APValue::DestroyDataAndMakeUninit() {
402  if (Kind == Int)
403  ((APSInt *)(char *)&Data)->~APSInt();
404  else if (Kind == Float)
405  ((APFloat *)(char *)&Data)->~APFloat();
406  else if (Kind == FixedPoint)
407  ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
408  else if (Kind == Vector)
409  ((Vec *)(char *)&Data)->~Vec();
410  else if (Kind == ComplexInt)
411  ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
412  else if (Kind == ComplexFloat)
413  ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
414  else if (Kind == LValue)
415  ((LV *)(char *)&Data)->~LV();
416  else if (Kind == Array)
417  ((Arr *)(char *)&Data)->~Arr();
418  else if (Kind == Struct)
419  ((StructData *)(char *)&Data)->~StructData();
420  else if (Kind == Union)
421  ((UnionData *)(char *)&Data)->~UnionData();
422  else if (Kind == MemberPointer)
423  ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
424  else if (Kind == AddrLabelDiff)
425  ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
426  Kind = None;
427 }
428 
429 bool APValue::needsCleanup() const {
430  switch (getKind()) {
431  case None:
432  case Indeterminate:
433  case AddrLabelDiff:
434  return false;
435  case Struct:
436  case Union:
437  case Array:
438  case Vector:
439  return true;
440  case Int:
441  return getInt().needsCleanup();
442  case Float:
443  return getFloat().needsCleanup();
444  case FixedPoint:
445  return getFixedPoint().getValue().needsCleanup();
446  case ComplexFloat:
447  assert(getComplexFloatImag().needsCleanup() ==
449  "In _Complex float types, real and imaginary values always have the "
450  "same size.");
451  return getComplexFloatReal().needsCleanup();
452  case ComplexInt:
453  assert(getComplexIntImag().needsCleanup() ==
455  "In _Complex int types, real and imaginary values must have the "
456  "same size.");
457  return getComplexIntReal().needsCleanup();
458  case LValue:
459  return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
460  case MemberPointer:
461  return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
462  }
463  llvm_unreachable("Unknown APValue kind!");
464 }
465 
466 void APValue::swap(APValue &RHS) {
467  std::swap(Kind, RHS.Kind);
468  std::swap(Data, RHS.Data);
469 }
470 
471 /// Profile the value of an APInt, excluding its bit-width.
472 static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
473  for (unsigned I = 0, N = V.getBitWidth(); I < N; I += 32)
474  ID.AddInteger((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), I));
475 }
476 
477 void APValue::Profile(llvm::FoldingSetNodeID &ID) const {
478  // Note that our profiling assumes that only APValues of the same type are
479  // ever compared. As a result, we don't consider collisions that could only
480  // happen if the types are different. (For example, structs with different
481  // numbers of members could profile the same.)
482 
483  ID.AddInteger(Kind);
484 
485  switch (Kind) {
486  case None:
487  case Indeterminate:
488  return;
489 
490  case AddrLabelDiff:
491  ID.AddPointer(getAddrLabelDiffLHS()->getLabel()->getCanonicalDecl());
492  ID.AddPointer(getAddrLabelDiffRHS()->getLabel()->getCanonicalDecl());
493  return;
494 
495  case Struct:
496  for (unsigned I = 0, N = getStructNumBases(); I != N; ++I)
498  for (unsigned I = 0, N = getStructNumFields(); I != N; ++I)
500  return;
501 
502  case Union:
503  if (!getUnionField()) {
504  ID.AddInteger(0);
505  return;
506  }
507  ID.AddInteger(getUnionField()->getFieldIndex() + 1);
509  return;
510 
511  case Array: {
512  if (getArraySize() == 0)
513  return;
514 
515  // The profile should not depend on whether the array is expanded or
516  // not, but we don't want to profile the array filler many times for
517  // a large array. So treat all equal trailing elements as the filler.
518  // Elements are profiled in reverse order to support this, and the
519  // first profiled element is followed by a count. For example:
520  //
521  // ['a', 'c', 'x', 'x', 'x'] is profiled as
522  // [5, 'x', 3, 'c', 'a']
523  llvm::FoldingSetNodeID FillerID;
526  .Profile(FillerID);
527  ID.AddNodeID(FillerID);
528  unsigned NumFillers = getArraySize() - getArrayInitializedElts();
529  unsigned N = getArrayInitializedElts();
530 
531  // Count the number of elements equal to the last one. This loop ends
532  // by adding an integer indicating the number of such elements, with
533  // N set to the number of elements left to profile.
534  while (true) {
535  if (N == 0) {
536  // All elements are fillers.
537  assert(NumFillers == getArraySize());
538  ID.AddInteger(NumFillers);
539  break;
540  }
541 
542  // No need to check if the last element is equal to the last
543  // element.
544  if (N != getArraySize()) {
545  llvm::FoldingSetNodeID ElemID;
546  getArrayInitializedElt(N - 1).Profile(ElemID);
547  if (ElemID != FillerID) {
548  ID.AddInteger(NumFillers);
549  ID.AddNodeID(ElemID);
550  --N;
551  break;
552  }
553  }
554 
555  // This is a filler.
556  ++NumFillers;
557  --N;
558  }
559 
560  // Emit the remaining elements.
561  for (; N != 0; --N)
563  return;
564  }
565 
566  case Vector:
567  for (unsigned I = 0, N = getVectorLength(); I != N; ++I)
568  getVectorElt(I).Profile(ID);
569  return;
570 
571  case Int:
573  return;
574 
575  case Float:
576  profileIntValue(ID, getFloat().bitcastToAPInt());
577  return;
578 
579  case FixedPoint:
581  return;
582 
583  case ComplexFloat:
584  profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
585  profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
586  return;
587 
588  case ComplexInt:
591  return;
592 
593  case LValue:
595  ID.AddInteger(getLValueOffset().getQuantity());
596  ID.AddInteger((isNullPointer() ? 1 : 0) |
597  (isLValueOnePastTheEnd() ? 2 : 0) |
598  (hasLValuePath() ? 4 : 0));
599  if (hasLValuePath()) {
600  ID.AddInteger(getLValuePath().size());
601  // For uniqueness, we only need to profile the entries corresponding
602  // to union members, but we don't have the type here so we don't know
603  // how to interpret the entries.
604  for (LValuePathEntry E : getLValuePath())
605  E.Profile(ID);
606  }
607  return;
608 
609  case MemberPointer:
610  ID.AddPointer(getMemberPointerDecl());
611  ID.AddInteger(isMemberPointerToDerivedMember());
612  for (const CXXRecordDecl *D : getMemberPointerPath())
613  ID.AddPointer(D);
614  return;
615  }
616 
617  llvm_unreachable("Unknown APValue kind!");
618 }
619 
620 static double GetApproxValue(const llvm::APFloat &F) {
621  llvm::APFloat V = F;
622  bool ignored;
623  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
624  &ignored);
625  return V.convertToDouble();
626 }
627 
628 static bool TryPrintAsStringLiteral(raw_ostream &Out,
629  const PrintingPolicy &Policy,
630  const ArrayType *ATy,
631  ArrayRef<APValue> Inits) {
632  if (Inits.empty())
633  return false;
634 
635  QualType Ty = ATy->getElementType();
636  if (!Ty->isAnyCharacterType())
637  return false;
638 
639  // Nothing we can do about a sequence that is not null-terminated
640  if (!Inits.back().getInt().isZero())
641  return false;
642  else
643  Inits = Inits.drop_back();
644 
646  Buf.push_back('"');
647 
648  // Better than printing a two-digit sequence of 10 integers.
649  constexpr size_t MaxN = 36;
650  StringRef Ellipsis;
651  if (Inits.size() > MaxN && !Policy.EntireContentsOfLargeArray) {
652  Ellipsis = "[...]";
653  Inits =
654  Inits.take_front(std::min(MaxN - Ellipsis.size() / 2, Inits.size()));
655  }
656 
657  for (auto &Val : Inits) {
658  int64_t Char64 = Val.getInt().getExtValue();
659  if (!isASCII(Char64))
660  return false; // Bye bye, see you in integers.
661  auto Ch = static_cast<unsigned char>(Char64);
662  // The diagnostic message is 'quoted'
663  StringRef Escaped = escapeCStyle<EscapeChar::SingleAndDouble>(Ch);
664  if (Escaped.empty()) {
665  if (!isPrintable(Ch))
666  return false;
667  Buf.emplace_back(Ch);
668  } else {
669  Buf.append(Escaped);
670  }
671  }
672 
673  Buf.append(Ellipsis);
674  Buf.push_back('"');
675 
676  if (Ty->isWideCharType())
677  Out << 'L';
678  else if (Ty->isChar8Type())
679  Out << "u8";
680  else if (Ty->isChar16Type())
681  Out << 'u';
682  else if (Ty->isChar32Type())
683  Out << 'U';
684 
685  Out << Buf;
686  return true;
687 }
688 
689 void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
690  QualType Ty) const {
691  printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
692 }
693 
694 void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
695  QualType Ty, const ASTContext *Ctx) const {
696  // There are no objects of type 'void', but values of this type can be
697  // returned from functions.
698  if (Ty->isVoidType()) {
699  Out << "void()";
700  return;
701  }
702 
703  switch (getKind()) {
704  case APValue::None:
705  Out << "<out of lifetime>";
706  return;
708  Out << "<uninitialized>";
709  return;
710  case APValue::Int:
711  if (Ty->isBooleanType())
712  Out << (getInt().getBoolValue() ? "true" : "false");
713  else
714  Out << getInt();
715  return;
716  case APValue::Float:
717  Out << GetApproxValue(getFloat());
718  return;
719  case APValue::FixedPoint:
720  Out << getFixedPoint();
721  return;
722  case APValue::Vector: {
723  Out << '{';
724  QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
725  getVectorElt(0).printPretty(Out, Policy, ElemTy, Ctx);
726  for (unsigned i = 1; i != getVectorLength(); ++i) {
727  Out << ", ";
728  getVectorElt(i).printPretty(Out, Policy, ElemTy, Ctx);
729  }
730  Out << '}';
731  return;
732  }
733  case APValue::ComplexInt:
734  Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
735  return;
737  Out << GetApproxValue(getComplexFloatReal()) << "+"
738  << GetApproxValue(getComplexFloatImag()) << "i";
739  return;
740  case APValue::LValue: {
741  bool IsReference = Ty->isReferenceType();
742  QualType InnerTy
743  = IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType();
744  if (InnerTy.isNull())
745  InnerTy = Ty;
746 
748  if (!Base) {
749  if (isNullPointer()) {
750  Out << (Policy.Nullptr ? "nullptr" : "0");
751  } else if (IsReference) {
752  Out << "*(" << InnerTy.stream(Policy) << "*)"
754  } else {
755  Out << "(" << Ty.stream(Policy) << ")"
757  }
758  return;
759  }
760 
761  if (!hasLValuePath()) {
762  // No lvalue path: just print the offset.
764  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
765  CharUnits::Zero())
766  : CharUnits::Zero();
767  if (!O.isZero()) {
768  if (IsReference)
769  Out << "*(";
770  if (S.isZero() || O % S) {
771  Out << "(char*)";
772  S = CharUnits::One();
773  }
774  Out << '&';
775  } else if (!IsReference) {
776  Out << '&';
777  }
778 
779  if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
780  Out << *VD;
781  else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
782  TI.print(Out, Policy);
783  } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
784  Out << "{*new "
785  << Base.getDynamicAllocType().stream(Policy) << "#"
786  << DA.getIndex() << "}";
787  } else {
788  assert(Base.get<const Expr *>() != nullptr &&
789  "Expecting non-null Expr");
790  Base.get<const Expr*>()->printPretty(Out, nullptr, Policy);
791  }
792 
793  if (!O.isZero()) {
794  Out << " + " << (O / S);
795  if (IsReference)
796  Out << ')';
797  }
798  return;
799  }
800 
801  // We have an lvalue path. Print it out nicely.
802  if (!IsReference)
803  Out << '&';
804  else if (isLValueOnePastTheEnd())
805  Out << "*(&";
806 
807  QualType ElemTy = Base.getType();
808  if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
809  Out << *VD;
810  } else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
811  TI.print(Out, Policy);
812  } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
813  Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
814  << DA.getIndex() << "}";
815  } else {
816  const Expr *E = Base.get<const Expr*>();
817  assert(E != nullptr && "Expecting non-null Expr");
818  E->printPretty(Out, nullptr, Policy);
819  }
820 
822  const CXXRecordDecl *CastToBase = nullptr;
823  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
824  if (ElemTy->isRecordType()) {
825  // The lvalue refers to a class type, so the next path entry is a base
826  // or member.
827  const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
828  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
829  CastToBase = RD;
830  // Leave ElemTy referring to the most-derived class. The actual type
831  // doesn't matter except for array types.
832  } else {
833  const ValueDecl *VD = cast<ValueDecl>(BaseOrMember);
834  Out << ".";
835  if (CastToBase)
836  Out << *CastToBase << "::";
837  Out << *VD;
838  ElemTy = VD->getType();
839  }
840  } else {
841  // The lvalue must refer to an array.
842  Out << '[' << Path[I].getAsArrayIndex() << ']';
843  ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
844  }
845  }
846 
847  // Handle formatting of one-past-the-end lvalues.
848  if (isLValueOnePastTheEnd()) {
849  // FIXME: If CastToBase is non-0, we should prefix the output with
850  // "(CastToBase*)".
851  Out << " + 1";
852  if (IsReference)
853  Out << ')';
854  }
855  return;
856  }
857  case APValue::Array: {
858  const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
859  unsigned N = getArrayInitializedElts();
860  if (N != 0 && TryPrintAsStringLiteral(Out, Policy, AT,
861  {&getArrayInitializedElt(0), N}))
862  return;
863  QualType ElemTy = AT->getElementType();
864  Out << '{';
865  unsigned I = 0;
866  switch (N) {
867  case 0:
868  for (; I != N; ++I) {
869  Out << ", ";
870  if (I == 10 && !Policy.EntireContentsOfLargeArray) {
871  Out << "...}";
872  return;
873  }
874  LLVM_FALLTHROUGH;
875  default:
876  getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
877  }
878  }
879  Out << '}';
880  return;
881  }
882  case APValue::Struct: {
883  Out << '{';
884  const RecordDecl *RD = Ty->castAs<RecordType>()->getDecl();
885  bool First = true;
886  if (unsigned N = getStructNumBases()) {
887  const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
889  for (unsigned I = 0; I != N; ++I, ++BI) {
890  assert(BI != CD->bases_end());
891  if (!First)
892  Out << ", ";
893  getStructBase(I).printPretty(Out, Policy, BI->getType(), Ctx);
894  First = false;
895  }
896  }
897  for (const auto *FI : RD->fields()) {
898  if (!First)
899  Out << ", ";
900  if (FI->isUnnamedBitfield()) continue;
901  getStructField(FI->getFieldIndex()).
902  printPretty(Out, Policy, FI->getType(), Ctx);
903  First = false;
904  }
905  Out << '}';
906  return;
907  }
908  case APValue::Union:
909  Out << '{';
910  if (const FieldDecl *FD = getUnionField()) {
911  Out << "." << *FD << " = ";
912  getUnionValue().printPretty(Out, Policy, FD->getType(), Ctx);
913  }
914  Out << '}';
915  return;
917  // FIXME: This is not enough to unambiguously identify the member in a
918  // multiple-inheritance scenario.
919  if (const ValueDecl *VD = getMemberPointerDecl()) {
920  Out << '&' << *cast<CXXRecordDecl>(VD->getDeclContext()) << "::" << *VD;
921  return;
922  }
923  Out << "0";
924  return;
926  Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
927  Out << " - ";
928  Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
929  return;
930  }
931  llvm_unreachable("Unknown APValue kind!");
932 }
933 
935  std::string Result;
936  llvm::raw_string_ostream Out(Result);
937  printPretty(Out, Ctx, Ty);
938  Out.flush();
939  return Result;
940 }
941 
942 bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
943  const ASTContext &Ctx) const {
944  if (isInt()) {
945  Result = getInt();
946  return true;
947  }
948 
949  if (isLValue() && isNullPointer()) {
950  Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
951  return true;
952  }
953 
954  if (isLValue() && !getLValueBase()) {
955  Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
956  return true;
957  }
958 
959  return false;
960 }
961 
963  assert(isLValue() && "Invalid accessor");
964  return ((const LV *)(const void *)&Data)->Base;
965 }
966 
968  assert(isLValue() && "Invalid accessor");
969  return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
970 }
971 
973  assert(isLValue() && "Invalid accessor");
974  return ((LV *)(void *)&Data)->Offset;
975 }
976 
978  assert(isLValue() && "Invalid accessor");
979  return ((const LV *)(const char *)&Data)->hasPath();
980 }
981 
983  assert(isLValue() && hasLValuePath() && "Invalid accessor");
984  const LV &LVal = *((const LV *)(const char *)&Data);
985  return llvm::makeArrayRef(LVal.getPath(), LVal.PathLength);
986 }
987 
988 unsigned APValue::getLValueCallIndex() const {
989  assert(isLValue() && "Invalid accessor");
990  return ((const LV *)(const char *)&Data)->Base.getCallIndex();
991 }
992 
993 unsigned APValue::getLValueVersion() const {
994  assert(isLValue() && "Invalid accessor");
995  return ((const LV *)(const char *)&Data)->Base.getVersion();
996 }
997 
999  assert(isLValue() && "Invalid usage");
1000  return ((const LV *)(const char *)&Data)->IsNullPtr;
1001 }
1002 
1004  bool IsNullPtr) {
1005  assert(isLValue() && "Invalid accessor");
1006  LV &LVal = *((LV *)(char *)&Data);
1007  LVal.Base = B;
1008  LVal.IsOnePastTheEnd = false;
1009  LVal.Offset = O;
1010  LVal.resizePath((unsigned)-1);
1011  LVal.IsNullPtr = IsNullPtr;
1012 }
1013 
1015 APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
1016  bool IsOnePastTheEnd, bool IsNullPtr) {
1017  assert(isLValue() && "Invalid accessor");
1018  LV &LVal = *((LV *)(char *)&Data);
1019  LVal.Base = B;
1020  LVal.IsOnePastTheEnd = IsOnePastTheEnd;
1021  LVal.Offset = O;
1022  LVal.IsNullPtr = IsNullPtr;
1023  LVal.resizePath(Size);
1024  return {LVal.getPath(), Size};
1025 }
1026 
1028  ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
1029  bool IsNullPtr) {
1031  setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
1032  if (Path.size()) {
1033  memcpy(InternalPath.data(), Path.data(),
1034  Path.size() * sizeof(LValuePathEntry));
1035  }
1036 }
1037 
1038 void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
1039  assert(isUnion() && "Invalid accessor");
1040  ((UnionData *)(char *)&Data)->Field =
1041  Field ? Field->getCanonicalDecl() : nullptr;
1042  *((UnionData *)(char *)&Data)->Value = Value;
1043 }
1044 
1046  assert(isMemberPointer() && "Invalid accessor");
1047  const MemberPointerData &MPD =
1048  *((const MemberPointerData *)(const char *)&Data);
1049  return MPD.MemberAndIsDerivedMember.getPointer();
1050 }
1051 
1053  assert(isMemberPointer() && "Invalid accessor");
1054  const MemberPointerData &MPD =
1055  *((const MemberPointerData *)(const char *)&Data);
1056  return MPD.MemberAndIsDerivedMember.getInt();
1057 }
1058 
1060  assert(isMemberPointer() && "Invalid accessor");
1061  const MemberPointerData &MPD =
1062  *((const MemberPointerData *)(const char *)&Data);
1063  return llvm::makeArrayRef(MPD.getPath(), MPD.PathLength);
1064 }
1065 
1066 void APValue::MakeLValue() {
1067  assert(isAbsent() && "Bad state change");
1068  static_assert(sizeof(LV) <= DataSize, "LV too big");
1069  new ((void *)(char *)&Data) LV();
1070  Kind = LValue;
1071 }
1072 
1073 void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1074  assert(isAbsent() && "Bad state change");
1075  new ((void *)(char *)&Data) Arr(InitElts, Size);
1076  Kind = Array;
1077 }
1078 
1079 MutableArrayRef<APValue::LValuePathEntry>
1080 setLValueUninit(APValue::LValueBase B, const CharUnits &O, unsigned Size,
1081  bool OnePastTheEnd, bool IsNullPtr);
1082 
1083 MutableArrayRef<const CXXRecordDecl *>
1084 APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
1085  unsigned Size) {
1086  assert(isAbsent() && "Bad state change");
1087  MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1088  Kind = MemberPointer;
1089  MPD->MemberAndIsDerivedMember.setPointer(
1090  Member ? cast<ValueDecl>(Member->getCanonicalDecl()) : nullptr);
1091  MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1092  MPD->resizePath(Size);
1093  return {MPD->getPath(), MPD->PathLength};
1094 }
1095 
1096 void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1098  MutableArrayRef<const CXXRecordDecl *> InternalPath =
1099  setMemberPointerUninit(Member, IsDerivedMember, Path.size());
1100  for (unsigned I = 0; I != Path.size(); ++I)
1101  InternalPath[I] = Path[I]->getCanonicalDecl();
1102 }
1103 
1104 LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1105  LVComputationKind computation) {
1107 
1108  auto MergeLV = [&](LinkageInfo MergeLV) {
1109  LV.merge(MergeLV);
1110  return LV.getLinkage() == InternalLinkage;
1111  };
1112  auto Merge = [&](const APValue &V) {
1113  return MergeLV(getLVForValue(V, computation));
1114  };
1115 
1116  switch (V.getKind()) {
1117  case APValue::None:
1119  case APValue::Int:
1120  case APValue::Float:
1121  case APValue::FixedPoint:
1122  case APValue::ComplexInt:
1123  case APValue::ComplexFloat:
1124  case APValue::Vector:
1125  break;
1126 
1128  // Even for an inline function, it's not reasonable to treat a difference
1129  // between the addresses of labels as an external value.
1130  return LinkageInfo::internal();
1131 
1132  case APValue::Struct: {
1133  for (unsigned I = 0, N = V.getStructNumBases(); I != N; ++I)
1134  if (Merge(V.getStructBase(I)))
1135  break;
1136  for (unsigned I = 0, N = V.getStructNumFields(); I != N; ++I)
1137  if (Merge(V.getStructField(I)))
1138  break;
1139  break;
1140  }
1141 
1142  case APValue::Union:
1143  if (V.getUnionField())
1144  Merge(V.getUnionValue());
1145  break;
1146 
1147  case APValue::Array: {
1148  for (unsigned I = 0, N = V.getArrayInitializedElts(); I != N; ++I)
1149  if (Merge(V.getArrayInitializedElt(I)))
1150  break;
1151  if (V.hasArrayFiller())
1152  Merge(V.getArrayFiller());
1153  break;
1154  }
1155 
1156  case APValue::LValue: {
1157  if (!V.getLValueBase()) {
1158  // Null or absolute address: this is external.
1159  } else if (const auto *VD =
1160  V.getLValueBase().dyn_cast<const ValueDecl *>()) {
1161  if (VD && MergeLV(getLVForDecl(VD, computation)))
1162  break;
1163  } else if (const auto TI = V.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1164  if (MergeLV(getLVForType(*TI.getType(), computation)))
1165  break;
1166  } else if (const Expr *E = V.getLValueBase().dyn_cast<const Expr *>()) {
1167  // Almost all expression bases are internal. The exception is
1168  // lifetime-extended temporaries.
1169  // FIXME: These should be modeled as having the
1170  // LifetimeExtendedTemporaryDecl itself as the base.
1171  // FIXME: If we permit Objective-C object literals in template arguments,
1172  // they should not imply internal linkage.
1173  auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E);
1174  if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1175  return LinkageInfo::internal();
1176  if (MergeLV(getLVForDecl(MTE->getExtendingDecl(), computation)))
1177  break;
1178  } else {
1179  assert(V.getLValueBase().is<DynamicAllocLValue>() &&
1180  "unexpected LValueBase kind");
1181  return LinkageInfo::internal();
1182  }
1183  // The lvalue path doesn't matter: pointers to all subobjects always have
1184  // the same visibility as pointers to the complete object.
1185  break;
1186  }
1187 
1189  if (const NamedDecl *D = V.getMemberPointerDecl())
1190  MergeLV(getLVForDecl(D, computation));
1191  // Note that we could have a base-to-derived conversion here to a member of
1192  // a derived class with less linkage/visibility. That's covered by the
1193  // linkage and visibility of the value's type.
1194  break;
1195  }
1196 
1197  return LV;
1198 }
clang::APValue::setComplexInt
void setComplexInt(APSInt R, APSInt I)
Definition: APValue.h:597
clang::PrintingPolicy::EntireContentsOfLargeArray
unsigned EntireContentsOfLargeArray
Whether to print the entire array initializers, especially on non-type template parameters,...
Definition: PrettyPrinter.h:292
clang::InternalLinkage
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
profileIntValue
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V)
Profile the value of an APInt, excluding its bit-width.
Definition: APValue.cpp:472
clang::APValue::LV::hasPath
bool hasPath() const
Definition: APValue.cpp:246
clang::APValue::LValuePathEntry::LValuePathEntry
LValuePathEntry()
Definition: APValue.h:214
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6838
clang::PrintingPolicy::Nullptr
unsigned Nullptr
Whether we should use 'nullptr' rather than '0' as a null pointer constant.
Definition: PrettyPrinter.h:197
clang::APValue::getKind
ValueKind getKind() const
Definition: APValue.h:387
clang::APValue::LValueBase
Definition: APValue.h:146
clang::CXXBaseSpecifier::getType
QualType getType() const
Retrieves the type of the base class.
Definition: DeclCXX.h:245
clang::isPrintable
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
Definition: CharInfo.h:145
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::APValue::getLValueOffset
CharUnits & getLValueOffset()
Definition: APValue.cpp:972
clang::APValue::LValueBase::getCallIndex
unsigned getCallIndex() const
Definition: APValue.cpp:108
clang::APValue::operator=
APValue & operator=(const APValue &RHS)
Definition: APValue.cpp:386
clang::APValue::getStructNumFields
unsigned getStructNumFields() const
Definition: APValue.h:534
clang::APValue::LValueBase::is
bool is() const
Definition: APValue.h:161
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::APValue::MemberPointerData::MemberPointerData
MemberPointerData()
Definition: APValue.cpp:271
clang::APValue::LValueBase::getTypeInfoType
QualType getTypeInfoType() const
Definition: APValue.cpp:117
clang::APValue::FixedPoint
@ FixedPoint
Definition: APValue.h:134
clang::APValue::getLValuePath
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:982
clang::APValue::MemberPointerData::PathElem
const typedef CXXRecordDecl * PathElem
Definition: APValue.cpp:265
clang::APValue::setUnion
void setUnion(const FieldDecl *Field, const APValue &Value)
Definition: APValue.cpp:1038
llvm::SmallVector
Definition: LLVM.h:38
clang::APValue::getInt
APSInt & getInt()
Definition: APValue.h:415
clang::APValue::isLValueOnePastTheEnd
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:967
GetApproxValue
static double GetApproxValue(const llvm::APFloat &F)
Definition: APValue.cpp:620
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6696
clang::Type::isWideCharType
bool isWideCharType() const
Definition: Type.cpp:1970
clang::APValue::getFixedPoint
APFixedPoint & getFixedPoint()
Definition: APValue.h:437
clang::APValue::Struct
@ Struct
Definition: APValue.h:140
clang::APValue::setComplexFloat
void setComplexFloat(APFloat R, APFloat I)
Definition: APValue.h:604
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:675
llvm::DenseMapInfo< clang::APValue::LValueBase >::isEqual
static bool isEqual(const clang::APValue::LValueBase &LHS, const clang::APValue::LValueBase &RHS)
Definition: APValue.cpp:215
clang::cast
U cast(CodeGen::Address addr)
Definition: Address.h:174
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2855
clang::APValue::LV::LV
LV()
Definition: APValue.cpp:233
DeclCXX.h
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1549
clang::APValue::LValueBase::getOpaqueValue
void * getOpaqueValue() const
Definition: APValue.cpp:175
clang::APValue::ComplexFloat
@ ComplexFloat
Definition: APValue.h:136
clang::APValue::LV::~LV
~LV()
Definition: APValue.cpp:234
clang::APValue::needsCleanup
bool needsCleanup() const
Returns whether the object performed allocations.
Definition: APValue.cpp:429
clang::ComparisonCategoryType::First
@ First
clang::APValue::getArraySize
unsigned getArraySize() const
Definition: APValue.h:525
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7037
llvm::DenseMapInfo< clang::APValue::LValueBase >::getTombstoneKey
static clang::APValue::LValueBase getTombstoneKey()
Definition: APValue.cpp:195
clang::APValue::LValueBase::getDynamicAllocType
QualType getDynamicAllocType() const
Definition: APValue.cpp:122
clang::APValue::None
@ None
There is no such object (it's outside its lifetime).
Definition: APValue.h:129
clang::APValue::LValueBase::getDynamicAlloc
static LValueBase getDynamicAlloc(DynamicAllocLValue LV, QualType Type)
Definition: APValue.cpp:47
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
clang::QualType::stream
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1079
clang::CXXRecordDecl::bases_end
base_class_iterator bases_end()
Definition: DeclCXX.h:605
clang::APValue::getMemberPointerDecl
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1045
clang::LVComputationKind
Kinds of LV computation.
Definition: Linkage.h:29
clang::APValue::LV::hasPathPtr
bool hasPathPtr() const
Definition: APValue.cpp:247
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1500
getValue
static SVal getValue(SVal val, SValBuilder &svalBuilder)
Definition: ArrayBoundCheckerV2.cpp:277
clang::APValue::LValueBase::getType
QualType getType() const
Definition: APValue.cpp:63
Offset
unsigned Offset
Definition: Format.cpp:2553
clang::APValue::LV
Definition: APValue.cpp:221
clang::APValue::MemberPointerData::getPath
const PathElem * getPath() const
Definition: APValue.cpp:287
APSInt
llvm::APSInt APSInt
Definition: ByteCodeEmitter.cpp:19
llvm::DenseMapInfo< clang::APValue::LValueBase >::getHashValue
static unsigned getHashValue(const clang::APValue::LValueBase &Base)
Definition: APValue.cpp:210
clang::hash_value
llvm::hash_code hash_value(const clang::SanitizerMask &Arg)
Definition: Sanitizers.cpp:68
clang::TypeInfo
Definition: ASTContext.h:178
clang::Expr::skipRValueSubobjectAdjustments
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
Definition: Expr.cpp:81
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::LinkageInfo::merge
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition: Visibility.h:132
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6760
V
#define V(N, I)
Definition: ASTContext.h:3176
clang::APValue::getComplexFloatReal
APFloat & getComplexFloatReal()
Definition: APValue.h:461
clang::APValue::MemberPointerData::getPath
PathElem * getPath()
Definition: APValue.cpp:286
Linkage.h
min
__DEVICE__ int min(int __a, int __b)
Definition: __clang_cuda_math.h:197
clang::LinkageInfo::internal
static LinkageInfo internal()
Definition: Visibility.h:70
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4647
clang::APValue::hasLValuePath
bool hasLValuePath() const
Definition: APValue.cpp:977
clang::TypeInfoLValue::getType
const Type * getType() const
Definition: APValue.h:51
clang::APValue::LValuePathSerializationHelper::LValuePathSerializationHelper
LValuePathSerializationHelper(ArrayRef< LValuePathEntry >, QualType)
Definition: APValue.cpp:157
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:2635
clang::APValue::Union
@ Union
Definition: APValue.h:141
clang::Type::isAnyCharacterType
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1997
clang::APValue::LValueBase::getTypeInfo
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition: APValue.cpp:55
clang::VectorType
Represents a GCC generic vector type.
Definition: Type.h:3242
clang::ASTContext::getTargetNullPointerValue
uint64_t getTargetNullPointerValue(QualType QT) const
Get target-dependent integer value for null pointer which is used for constant folding.
Definition: ASTContext.cpp:11988
clang::MaterializeTemporaryExpr
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4479
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
clang::APValue::Array
@ Array
Definition: APValue.h:139
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2896
clang::DeclaratorContext::Member
@ Member
clang::hash_value
llvm::hash_code hash_value(const APValue::LValueBase &Base)
Definition: APValue.cpp:202
clang::APValue::getStructNumBases
unsigned getStructNumBases() const
Definition: APValue.h:530
clang::APValue::getStructBase
APValue & getStructBase(unsigned i)
Definition: APValue.h:538
clang::APValue::LV::getPath
const LValuePathEntry * getPath() const
Definition: APValue.cpp:250
APValue.h
clang::Type::isChar8Type
bool isChar8Type() const
Definition: Type.cpp:1977
clang::APValue::LV::getPath
LValuePathEntry * getPath()
Definition: APValue.cpp:249
clang::APValue::getComplexIntReal
APSInt & getComplexIntReal()
Definition: APValue.h:445
clang::CharUnits::One
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition: CharUnits.h:58
clang::index::SymbolKind::Field
@ Field
uintptr_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c-base.h:139
clang::APValue::getLValueCallIndex
unsigned getLValueCallIndex() const
Definition: APValue.cpp:988
Type.h
Expr.h
llvm::SmallString
Definition: LLVM.h:37
bool
#define bool
Definition: stdbool.h:20
ASTContext.h
clang::APValue::getVectorElt
APValue & getVectorElt(unsigned I)
Definition: APValue.h:489
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::LinkageInfo
Definition: Visibility.h:52
clang::SD_FullExpression
@ SD_FullExpression
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:309
clang::APValue::getUnionField
const FieldDecl * getUnionField() const
Definition: APValue.h:555
setLValueUninit
MutableArrayRef< APValue::LValuePathEntry > setLValueUninit(APValue::LValueBase B, const CharUnits &O, unsigned Size, bool OnePastTheEnd, bool IsNullPtr)
clang::APValue::LValue
@ LValue
Definition: APValue.h:137
clang::CharUnits::Zero
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
clang::APValue::hasArrayFiller
bool hasArrayFiller() const
Definition: APValue.h:510
ExprCXX.h
Base
clang::APValue::LValueBase::isNull
bool isNull() const
Definition: APValue.cpp:179
clang::APValue::getArrayInitializedElt
APValue & getArrayInitializedElt(unsigned I)
Definition: APValue.h:502
clang::APValue::getAsString
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Definition: APValue.cpp:934
clang::APValue::isInt
bool isInt() const
Definition: APValue.h:393
clang::format::hash_combine
static void hash_combine(std::size_t &seed, const T &v)
Definition: UnwrappedLineParser.cpp:743
clang::APValue::setLValue
void setLValue(LValueBase B, const CharUnits &O, NoLValuePath, bool IsNullPtr)
Definition: APValue.cpp:1003
CharUnits.h
clang::APValue::getLValueVersion
unsigned getLValueVersion() const
Definition: APValue.cpp:993
clang::APValue::Indeterminate
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:131
clang::APValue::AddrLabelDiff
@ AddrLabelDiff
Definition: APValue.h:143
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7310
clang::APValue::isUnion
bool isUnion() const
Definition: APValue.h:402
clang::APValue::getArrayFiller
APValue & getArrayFiller()
Definition: APValue.h:513
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::APValue::swap
void swap(APValue &RHS)
Swaps the contents of this and the given APValue.
Definition: APValue.cpp:466
clang::APValue::setAddrLabelDiff
void setAddrLabelDiff(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr)
Definition: APValue.h:617
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::APValue::LV::resizePath
void resizePath(unsigned Length)
Definition: APValue.cpp:236
clang::APValue::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
Definition: APValue.cpp:477
clang::APValue::printPretty
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Definition: APValue.cpp:689
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:674
TryPrintAsStringLiteral
static bool TryPrintAsStringLiteral(raw_ostream &Out, const PrintingPolicy &Policy, const ArrayType *ATy, ArrayRef< APValue > Inits)
Definition: APValue.cpp:628
clang::DynamicAllocLValue
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
clang::CharUnits::isZero
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition: CharUnits.h:116
getCanonicalDecl
static const Decl * getCanonicalDecl(const Decl *D)
Definition: IndexingContext.cpp:297
clang::APValue::setVector
void setVector(const APValue *E, unsigned N)
Definition: APValue.h:592
clang::APValue::MemberPointerData
Definition: APValue.cpp:262
clang::Type::isIncompleteArrayType
bool isIncompleteArrayType() const
Definition: Type.h:6822
clang::ASTContext::getPrintingPolicy
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:708
clang::RecordDecl::fields
field_range fields() const
Definition: Decl.h:4127
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:740
clang::APValue::ComplexInt
@ ComplexInt
Definition: APValue.h:135
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::APValue::MemberPointerData::PathPtr
PathElem * PathPtr
Definition: APValue.cpp:268
clang::APValue::getLValueBase
const LValueBase getLValueBase() const
Definition: APValue.cpp:962
clang::APValue::isAbsent
bool isAbsent() const
Definition: APValue.h:389
clang::APValue::setInt
void setInt(APSInt I)
Definition: APValue.h:580
clang::LinkageInfo::getLinkage
Linkage getLinkage() const
Definition: Visibility.h:83
clang::APValue::getStructField
APValue & getStructField(unsigned i)
Definition: APValue.h:543
clang::APValue::getUnionValue
APValue & getUnionValue()
Definition: APValue.h:559
clang::APValue::getFloat
APFloat & getFloat()
Definition: APValue.h:429
clang::TypeInfoLValue
Symbolic representation of typeid(T) for some type T.
Definition: APValue.h:44
clang::ASTContext::MakeIntValue
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const
Make an APSInt of the appropriate width and signedness for the given Value and integer Type.
Definition: ASTContext.h:2919
clang::APValue::Vector
@ Vector
Definition: APValue.h:138
clang::APValue::isNullPointer
bool isNullPointer() const
Definition: APValue.cpp:998
clang::APValue::isMemberPointer
bool isMemberPointer() const
Definition: APValue.h:403
clang::APValue::getComplexIntImag
APSInt & getComplexIntImag()
Definition: APValue.h:453
clang::APValue::toIntegralConstant
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition: APValue.cpp:942
clang::QualType::getFromOpaquePtr
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:722
clang::APValue::MemberPointerData::resizePath
void resizePath(unsigned Length)
Definition: APValue.cpp:274
clang::Type::isBooleanType
bool isBooleanType() const
Definition: Type.h:7153
clang::APValue::LValueBase::LValueBase
LValueBase()
Definition: APValue.h:152
clang::APValue::LV::PathPtr
LValuePathEntry * PathPtr
Definition: APValue.cpp:230
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::LinkageInfo::external
static LinkageInfo external()
Definition: Visibility.h:67
clang::Type::castAsArrayTypeUnsafe
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition: Type.h:7319
clang::Builtin::ID
ID
Definition: Builtins.h:51
clang::APValue::getAddrLabelDiffRHS
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:575
clang
Definition: CalledOnceCheck.h:17
clang::TypeInfoLValue::TypeInfoLValue
TypeInfoLValue()
Definition: APValue.h:48
llvm::DenseMapInfo< clang::APValue::LValueBase >::getEmptyKey
static clang::APValue::LValueBase getEmptyKey()
Definition: APValue.cpp:188
clang::APValue::LValueBase::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: APValue.cpp:127
clang::APValue::MemberPointerData::~MemberPointerData
~MemberPointerData()
Definition: APValue.cpp:272
clang::APValue::getComplexFloatImag
APFloat & getComplexFloatImag()
Definition: APValue.h:469
clang::APValue::Int
@ Int
Definition: APValue.h:132
clang::CXXRecordDecl::bases_begin
base_class_iterator bases_begin()
Definition: DeclCXX.h:603
clang::CXXBaseSpecifier
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
clang::APValue::BaseOrMemberType
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition: APValue.h:205
clang::APValue::getVectorLength
unsigned getVectorLength() const
Definition: APValue.h:497
clang::APValue::MemberPointerData::hasPathPtr
bool hasPathPtr() const
Definition: APValue.cpp:284
unsigned
clang::APValue::LValueBase::Local
LocalState Local
Definition: APValue.h:195
clang::APValue::getMemberPointerPath
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1059
llvm::PointerLikeTypeTraits
Definition: DeclGroup.h:139
clang::APValue::isLValue
bool isLValue() const
Definition: APValue.h:398
clang::APValue::NoLValuePath
Definition: APValue.h:249
clang::APValue::setFloat
void setFloat(APFloat F)
Definition: APValue.h:584
clang::APValue::isMemberPointerToDerivedMember
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1052
clang::APValue::MemberPointer
@ MemberPointer
Definition: APValue.h:142
clang::ASTContext::getTypeSizeInCharsIfKnown
Optional< CharUnits > getTypeSizeInCharsIfKnown(QualType Ty) const
Definition: ASTContext.h:2304
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::QualType::print
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: TypePrinter.cpp:2288
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
clang::LinkageComputer::getLVForDecl
LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation)
getLVForDecl - Get the linkage and visibility for the given declaration.
Definition: Decl.cpp:1496
clang::APValue::APValue
APValue()
Definition: APValue.h:309
clang::APValue::LValuePathSerializationHelper::getType
QualType getType()
Definition: APValue.cpp:161
clang::ArrayType::getElementType
QualType getElementType() const
Definition: Type.h:2917
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::APValue::getArrayInitializedElts
unsigned getArrayInitializedElts() const
Definition: APValue.h:521
clang::Type::isChar16Type
bool isChar16Type() const
Definition: Type.cpp:1983
clang::APValue::LValueBase::getVersion
unsigned getVersion() const
Definition: APValue.cpp:113
clang::APValue::LValuePathEntry
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:208
GCCTypeClass::None
@ None
clang::AddrLabelExpr::getLabel
LabelDecl * getLabel() const
Definition: Expr.h:4327
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3901
clang::Type::isChar32Type
bool isChar32Type() const
Definition: Type.cpp:1989
clang::APValue::LValuePathEntry::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: APValue.cpp:153
clang::operator==
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition: CallGraph.h:207
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
clang::isASCII
LLVM_READNONE bool isASCII(char c)
Returns true if a byte is an ASCII character.
Definition: CharInfo.h:42
clang::APValue::getAddrLabelDiffLHS
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:571
clang::APValue::Float
@ Float
Definition: APValue.h:133
clang::TypeInfoLValue::print
void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const
Definition: APValue.cpp:30
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274