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");
158 bool IsVirtual =
false;
162 if (
const auto *BaseOrMember = Desc->
asDecl()) {
167 llvm_unreachable(
"Invalid field type");
175 std::reverse(Path.begin(), Path.end());
177 return APValue(
Base, Offset, Path, IsOnePastEnd,
false);
181 OS << PointeeStorage.BS.Pointee <<
" (";
185 if (PointeeStorage.BS.Base == RootPtrMark)
188 OS << PointeeStorage.BS.Base <<
", ";
190 if (Offset == PastEndMark)
193 OS << Offset <<
", ";
196 OS << PointeeStorage.BS.Pointee->getSize();
201 OS << PointeeStorage.Int.Value <<
", " << PointeeStorage.Int.Desc;
220 assert(PointeeStorage.BS.Pointee &&
221 "Cannot check if null pointer was initialized");
225 if (
isStatic() && PointeeStorage.BS.Base == 0)
236 return IM->second->isElementInitialized(
getIndex());
240 return PointeeStorage.BS.Base == 0 || getInlineDesc()->
IsInitialized;
247 assert(PointeeStorage.BS.Pointee &&
"Cannot initialize null pointer");
253 if (
isStatic() && PointeeStorage.BS.Base == 0)
263 std::make_pair(
false, std::make_shared<InitMap>(Desc->
getNumElems()));
271 if (IM->second->initializeElement(
getIndex())) {
279 assert(PointeeStorage.BS.Base != 0 &&
280 "Only composite fields can be initialised");
286 assert(PointeeStorage.BS.Base != 0 &&
287 "Only composite fields can be initialised");
320 Ty = AT->getValueType();
323 if (Ptr.isDummy() || !Ptr.isLive() ||
324 (!Ptr.isUnknownSizeArray() && Ptr.isOnePastEnd()))
328 if (std::optional<PrimType>
T = Ctx.
classify(Ty)) {
333 if (
const auto *RT = Ty->getAs<
RecordType>()) {
334 const auto *
Record = Ptr.getRecord();
335 assert(
Record &&
"Missing record descriptor");
338 if (RT->getDecl()->isUnion()) {
343 QualType FieldTy = F.Decl->getType();
345 if (std::optional<PrimType>
T = Ctx.
classify(FieldTy)) {
348 Ok &= Composite(FieldTy, FP,
Value);
361 for (
unsigned I = 0; I < NF; ++I) {
363 QualType FieldTy = FD->Decl->getType();
367 if (std::optional<PrimType>
T = Ctx.
classify(FieldTy)) {
370 Ok &= Composite(FieldTy, FP,
Value);
374 for (
unsigned I = 0; I < NB; ++I) {
378 Ok &= Composite(BaseTy, BP, R.getStructBase(I));
381 for (
unsigned I = 0; I < NV; ++I) {
385 Ok &= Composite(VirtBaseTy, VP, R.getStructBase(NB + I));
391 if (Ty->isIncompleteArrayType()) {
396 if (
const auto *AT = Ty->getAsArrayTypeUnsafe()) {
397 const size_t NumElems = Ptr.getNumElems();
398 QualType ElemTy = AT->getElementType();
402 for (
unsigned I = 0; I < NumElems; ++I) {
405 if (std::optional<PrimType>
T = Ctx.
classify(ElemTy)) {
408 Ok &= Composite(ElemTy, EP.
narrow(), Slot);
416 QualType ElemTy = CT->getElementType();
419 std::optional<PrimType> ElemT = Ctx.
classify(ElemTy);
422 auto V1 = Ptr.atIndex(0).deref<T>();
423 auto V2 = Ptr.atIndex(1).deref<T>();
424 R =
APValue(V1.toAPSInt(), V2.toAPSInt());
436 if (
const auto *VT = Ty->getAs<
VectorType>()) {
437 assert(Ptr.getFieldDesc()->isPrimitiveArray());
438 QualType ElemTy = VT->getElementType();
442 Values.reserve(VT->getNumElements());
443 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
445 Values.push_back(Ptr.atIndex(I).deref<
T>().toAPValue());
449 assert(Values.size() == VT->getNumElements());
450 R =
APValue(Values.data(), Values.size());
454 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.
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.
Pointer atIndex(unsigned Idx) const
Offsets a pointer inside 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.