23 :
Pointer(Pointee, Pointee->getDescriptor()->getMetadataSize(),
24 Pointee->getDescriptor()->getMetadataSize()) {}
27 :
Pointer(Pointee, BaseAndOffset, BaseAndOffset) {}
30 : Offset(
P.Offset), PointeeStorage(
P.PointeeStorage),
31 StorageKind(
P.StorageKind) {
34 PointeeStorage.BS.Pointee->addPointer(
this);
39 assert((
Base == RootPtrMark ||
Base %
alignof(
void *) == 0) &&
"wrong base");
41 PointeeStorage.BS = {Pointee,
Base};
48 : Offset(
P.Offset), PointeeStorage(
P.PointeeStorage),
49 StorageKind(
P.StorageKind) {
52 PointeeStorage.BS.Pointee->replacePointer(&
P,
this);
59 if (PointeeStorage.BS.Pointee) {
60 PointeeStorage.BS.Pointee->removePointer(
this);
61 PointeeStorage.BS.Pointee->cleanup();
68 assert(
P.StorageKind == StorageKind);
71 StorageKind =
P.StorageKind;
73 Block *Old = PointeeStorage.BS.Pointee;
74 if (WasBlockPointer && PointeeStorage.BS.Pointee)
75 PointeeStorage.BS.Pointee->removePointer(
this);
78 PointeeStorage.BS =
P.PointeeStorage.BS;
80 if (PointeeStorage.BS.Pointee)
81 PointeeStorage.BS.Pointee->addPointer(
this);
83 if (WasBlockPointer && Old)
87 PointeeStorage.Int =
P.PointeeStorage.Int;
89 assert(
false &&
"Unhandled storage kind");
95 assert(
P.StorageKind == StorageKind);
98 StorageKind =
P.StorageKind;
100 Block *Old = PointeeStorage.BS.Pointee;
101 if (WasBlockPointer && PointeeStorage.BS.Pointee)
102 PointeeStorage.BS.Pointee->removePointer(
this);
105 PointeeStorage.BS =
P.PointeeStorage.BS;
107 if (PointeeStorage.BS.Pointee)
108 PointeeStorage.BS.Pointee->addPointer(
this);
110 if (WasBlockPointer && Old)
114 PointeeStorage.Int =
P.PointeeStorage.Int;
116 assert(
false &&
"Unhandled storage kind");
137 else if (
const auto *E = Desc->
asExpr())
140 llvm_unreachable(
"Invalid allocation type");
159 bool IsVirtual =
false;
163 if (
const auto *BaseOrMember = Desc->
asDecl()) {
168 llvm_unreachable(
"Invalid field type");
176 std::reverse(Path.begin(), Path.end());
178 return APValue(
Base, Offset, Path, IsOnePastEnd,
false);
182 OS << PointeeStorage.BS.Pointee <<
" (";
186 if (PointeeStorage.BS.Base == RootPtrMark)
189 OS << PointeeStorage.BS.Base <<
", ";
191 if (Offset == PastEndMark)
194 OS << Offset <<
", ";
197 OS << PointeeStorage.BS.Pointee->getSize();
202 OS << PointeeStorage.Int.Value <<
", " << PointeeStorage.Int.Desc;
221 assert(PointeeStorage.BS.Pointee &&
222 "Cannot check if null pointer was initialized");
226 if (
isStatic() && PointeeStorage.BS.Base == 0)
237 return IM->second->isElementInitialized(
getIndex());
241 return PointeeStorage.BS.Base == 0 || getInlineDesc()->
IsInitialized;
248 assert(PointeeStorage.BS.Pointee &&
"Cannot initialize null pointer");
254 if (
isStatic() && PointeeStorage.BS.Base == 0)
264 std::make_pair(
false, std::make_shared<InitMap>(Desc->
getNumElems()));
272 if (IM->second->initializeElement(
getIndex())) {
280 assert(PointeeStorage.BS.Base != 0 &&
281 "Only composite fields can be initialised");
287 assert(PointeeStorage.BS.Base != 0 &&
288 "Only composite fields can be initialised");
321 Ty = AT->getValueType();
324 if (Ptr.isDummy() || !Ptr.isLive() ||
325 (!Ptr.isUnknownSizeArray() && Ptr.isOnePastEnd()))
329 if (std::optional<PrimType>
T = Ctx.
classify(Ty)) {
334 if (
const auto *RT = Ty->getAs<
RecordType>()) {
335 const auto *
Record = Ptr.getRecord();
336 assert(
Record &&
"Missing record descriptor");
339 if (RT->getDecl()->isUnion()) {
344 QualType FieldTy = F.Decl->getType();
346 if (std::optional<PrimType>
T = Ctx.
classify(FieldTy)) {
349 Ok &= Composite(FieldTy, FP,
Value);
362 for (
unsigned I = 0; I < NF; ++I) {
364 QualType FieldTy = FD->Decl->getType();
368 if (std::optional<PrimType>
T = Ctx.
classify(FieldTy)) {
371 Ok &= Composite(FieldTy, FP,
Value);
375 for (
unsigned I = 0; I < NB; ++I) {
379 Ok &= Composite(BaseTy, BP, R.getStructBase(I));
382 for (
unsigned I = 0; I < NV; ++I) {
386 Ok &= Composite(VirtBaseTy, VP, R.getStructBase(NB + I));
392 if (Ty->isIncompleteArrayType()) {
397 if (
const auto *AT = Ty->getAsArrayTypeUnsafe()) {
398 const size_t NumElems = Ptr.getNumElems();
399 QualType ElemTy = AT->getElementType();
403 for (
unsigned I = 0; I < NumElems; ++I) {
406 if (std::optional<PrimType>
T = Ctx.
classify(ElemTy)) {
409 Ok &= Composite(ElemTy, EP.
narrow(), Slot);
417 QualType ElemTy = CT->getElementType();
420 std::optional<PrimType> ElemT = Ctx.
classify(ElemTy);
423 auto V1 = Ptr.atIndex(0).deref<T>();
424 auto V2 = Ptr.atIndex(1).deref<T>();
425 R =
APValue(V1.toAPSInt(), V2.toAPSInt());
437 if (
const auto *VT = Ty->getAs<
VectorType>()) {
438 assert(Ptr.getFieldDesc()->isPrimitiveArray());
439 QualType ElemTy = VT->getElementType();
443 Values.reserve(VT->getNumElements());
444 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
446 Values.push_back(Ptr.atIndex(I).deref<
T>().toAPValue());
450 assert(Values.size() == VT->getNumElements());
451 R =
APValue(Values.data(), Values.size());
455 llvm_unreachable(
"invalid value to return");
#define INT_TYPE_SWITCH(Expr, B)
#define TYPE_SWITCH(Expr, B)
A non-discriminated union of a base, field, or array index.
static LValuePathEntry ArrayIndex(uint64_t Index)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
APValue & getArrayInitializedElt(unsigned I)
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getRecordType(const RecordDecl *Decl) const
CharUnits - This is an opaque type for sizes expressed in character units.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Complex values, per C99 6.2.5p11.
This represents one expression.
Represents a member of a struct/union/class.
A (possibly-)qualified type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isFloatingType() const
Represents a GCC generic vector type.
A memory block, either on the stack or in the heap.
void addPointer(Pointer *P)
Pointer chain management.
void cleanup()
Deletes a dead block at the end of its lifetime.
Holds all information required to evaluate constexpr code in a module.
ASTContext & getASTContext() const
Returns the AST context.
std::optional< PrimType > classify(QualType T) const
Classifies a type.
const APFloat & getAPFloat() const
A pointer to a memory block, live or dead.
static bool hasSameBase(const Pointer &A, const Pointer &B)
Checks if two pointers are comparable.
Pointer narrow() const
Restricts the scope of an array element pointer.
void deactivate() const
Deactivates an entire strurcutre.
bool isInitialized() const
Checks if an object was initialized.
bool isStatic() const
Checks if the storage is static.
Pointer atIndex(uint64_t Idx) const
Offsets a pointer inside an array.
bool isDummy() const
Checks if the pointer points to a dummy value.
void print(llvm::raw_ostream &OS) const
Prints the pointer.
int64_t getIndex() const
Returns the index into an array.
bool isActive() const
Checks if the object is active.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
T & deref() const
Dereferences the pointer, if it's live.
DeclTy getSource() const
Returns the expression or declaration the pointer has been created for.
Pointer getArray() const
Returns the parent array.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
void activate() const
Activats a field.
void operator=(const Pointer &P)
bool isIntegralPointer() const
QualType getType() const
Returns the type of the innermost field.
bool isArrayElement() const
Checks if the pointer points to an array.
bool isLive() const
Checks if the pointer is live.
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
std::string toDiagnosticString(const ASTContext &Ctx) const
Converts the pointer to a string usable in diagnostics.
bool isZero() const
Checks if the pointer is null.
const IntPointer & asIntPointer() const
const Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
bool isOnePastEnd() const
Checks if the index is one past end.
static bool hasSameArray(const Pointer &A, const Pointer &B)
Checks if two pointers can be subtracted.
std::optional< APValue > toRValue(const Context &Ctx) const
Converts the pointer to an APValue that is an rvalue.
bool isBlockPointer() const
APValue toAPValue() const
Converts the pointer to an APValue.
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
const BlockPointer & asBlockPointer() const
void initialize() const
Initializes a field.
bool isField() const
Checks if the item is a field in an object.
Structure/Class descriptor.
unsigned getNumBases() const
const Field * getField(const FieldDecl *FD) const
Returns a field.
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
unsigned getNumFields() const
unsigned getNumVirtualBases() const
llvm::iterator_range< const_field_iter > fields() const
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
std::optional< std::pair< bool, std::shared_ptr< InitMap > > > InitMapPtr
PrimType
Enumeration of the primitive types of the VM.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
unsigned Base
Start of the current subfield.
Block * Pointee
The block the pointer is pointing to.
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
const ValueDecl * asValueDecl() const
const Decl * asDecl() const
const bool IsArray
Flag indicating if the block is an array.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
const Expr * asExpr() const
unsigned IsActive
Flag indicating if the field is the active member of a union.
unsigned IsInitialized
For primitive fields, it indicates if the field was initialized.