25 :
Pointer(Pointee, Pointee->getDescriptor()->getMetadataSize(),
26 Pointee->getDescriptor()->getMetadataSize()) {}
29 :
Pointer(Pointee, BaseAndOffset, BaseAndOffset) {}
32 : Offset(
P.Offset), PointeeStorage(
P.PointeeStorage),
33 StorageKind(
P.StorageKind) {
36 PointeeStorage.BS.Pointee->addPointer(
this);
41 assert((
Base == RootPtrMark ||
Base %
alignof(
void *) == 0) &&
"wrong base");
43 PointeeStorage.BS = {Pointee,
Base};
46 Pointee->addPointer(
this);
50 : Offset(
P.Offset), PointeeStorage(
P.PointeeStorage),
51 StorageKind(
P.StorageKind) {
54 PointeeStorage.BS.Pointee->replacePointer(&
P,
this);
61 if (
Block *Pointee = PointeeStorage.BS.Pointee) {
62 Pointee->removePointer(
this);
72 Block *Old = PointeeStorage.BS.Pointee;
73 if (WasBlockPointer && Old) {
74 PointeeStorage.BS.Pointee->removePointer(
this);
79 StorageKind =
P.StorageKind;
82 if (
P.isBlockPointer()) {
83 PointeeStorage.BS =
P.PointeeStorage.BS;
84 PointeeStorage.BS.Pointee =
P.PointeeStorage.BS.Pointee;
86 if (PointeeStorage.BS.Pointee)
87 PointeeStorage.BS.Pointee->addPointer(
this);
88 }
else if (
P.isIntegralPointer()) {
89 PointeeStorage.Int =
P.PointeeStorage.Int;
90 }
else if (
P.isFunctionPointer()) {
91 PointeeStorage.Fn =
P.PointeeStorage.Fn;
93 assert(
false &&
"Unhandled storage kind");
102 Block *Old = PointeeStorage.BS.Pointee;
103 if (WasBlockPointer && Old) {
104 PointeeStorage.BS.Pointee->removePointer(
this);
109 StorageKind =
P.StorageKind;
112 if (
P.isBlockPointer()) {
113 PointeeStorage.BS =
P.PointeeStorage.BS;
114 PointeeStorage.BS.Pointee =
P.PointeeStorage.BS.Pointee;
116 if (PointeeStorage.BS.Pointee)
117 PointeeStorage.BS.Pointee->addPointer(
this);
118 }
else if (
P.isIntegralPointer()) {
119 PointeeStorage.Int =
P.PointeeStorage.Int;
120 }
else if (
P.isFunctionPointer()) {
121 PointeeStorage.Fn =
P.PointeeStorage.Fn;
123 assert(
false &&
"Unhandled storage kind");
146 else if (
const auto *
E = Desc->
asExpr())
149 llvm_unreachable(
"Invalid allocation type");
160 if (FD->getParent()->isInvalidDecl())
163 unsigned FieldIndex = FD->getFieldIndex();
189 bool IsVirtual =
false;
193 if (
const auto *BaseOrMember = Desc->
asDecl()) {
194 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
197 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
203 cast<CXXRecordDecl>(BaseRecord->
getDecl()));
215 llvm_unreachable(
"Invalid field type");
228 std::reverse(
Path.begin(),
Path.end());
235 OS << PointeeStorage.BS.Pointee <<
" (";
237 const Block *B = PointeeStorage.BS.Pointee;
241 OS <<
"rootptr(" << PointeeStorage.BS.Base <<
"), ";
243 OS << PointeeStorage.BS.Base <<
", ";
248 OS << Offset <<
", ";
256 OS << PointeeStorage.Int.Value <<
", " << PointeeStorage.Int.Desc;
281 assert(PointeeStorage.BS.Pointee &&
282 "Cannot check if null pointer was initialized");
286 if (
isStatic() && PointeeStorage.BS.Base == 0)
297 return IM->second->isElementInitialized(
getIndex());
311 assert(PointeeStorage.BS.Pointee &&
"Cannot initialize null pointer");
324 if (
isStatic() && PointeeStorage.BS.Base == 0)
334 std::make_pair(
false, std::make_shared<InitMap>(Desc->
getNumElems()));
342 if (IM->second->initializeElement(
getIndex())) {
350 assert(PointeeStorage.BS.Base != 0 &&
351 "Only composite fields can be initialised");
357 assert(PointeeStorage.BS.Base != 0 &&
358 "Only composite fields can be initialised");
383 if (A.StorageKind != B.StorageKind)
398 assert(!ResultType.
isNull());
401 Composite = [&Composite, &Ctx, &ASTCtx](
QualType Ty,
const Pointer &Ptr,
404 Ty = AT->getValueType();
407 if (Ptr.isDummy() || !Ptr.isLive() || !Ptr.isBlockPointer() ||
412 if (std::optional<PrimType>
T = Ctx.
classify(Ty)) {
417 if (
const auto *RT = Ty->getAs<
RecordType>()) {
418 const auto *
Record = Ptr.getRecord();
419 assert(
Record &&
"Missing record descriptor");
422 if (RT->getDecl()->isUnion()) {
427 QualType FieldTy = F.Decl->getType();
429 if (std::optional<PrimType>
T = Ctx.
classify(FieldTy)) {
432 Ok &= Composite(FieldTy, FP,
Value);
446 for (
unsigned I = 0; I < NF; ++I) {
448 QualType FieldTy = FD->Decl->getType();
452 if (std::optional<PrimType>
T = Ctx.
classify(FieldTy)) {
455 Ok &= Composite(FieldTy, FP,
Value);
459 for (
unsigned I = 0; I < NB; ++I) {
463 Ok &= Composite(BaseTy, BP, R.getStructBase(I));
466 for (
unsigned I = 0; I < NV; ++I) {
470 Ok &= Composite(VirtBaseTy, VP, R.getStructBase(NB + I));
476 if (Ty->isIncompleteArrayType()) {
481 if (
const auto *AT = Ty->getAsArrayTypeUnsafe()) {
482 const size_t NumElems = Ptr.getNumElems();
483 QualType ElemTy = AT->getElementType();
487 for (
unsigned I = 0; I < NumElems; ++I) {
490 if (std::optional<PrimType>
T = Ctx.
classify(ElemTy)) {
493 Ok &= Composite(ElemTy, EP.
narrow(), Slot);
501 QualType ElemTy = CT->getElementType();
504 std::optional<PrimType> ElemT = Ctx.
classify(ElemTy);
507 auto V1 = Ptr.atIndex(0).deref<T>();
508 auto V2 = Ptr.atIndex(1).deref<T>();
509 R =
APValue(V1.toAPSInt(), V2.toAPSInt());
521 if (
const auto *VT = Ty->getAs<
VectorType>()) {
522 assert(Ptr.getFieldDesc()->isPrimitiveArray());
523 QualType ElemTy = VT->getElementType();
527 Values.reserve(VT->getNumElements());
528 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
530 Values.push_back(Ptr.atIndex(I).deref<
T>().toAPValue(ASTCtx));
534 assert(Values.size() == VT->getNumElements());
535 R =
APValue(Values.data(), Values.size());
539 llvm_unreachable(
"invalid value to return");
551 if (std::optional<PrimType>
T = Ctx.
classify(ResultType)) {
#define INT_TYPE_SWITCH(Expr, B)
#define TYPE_SWITCH(Expr, B)
static uint64_t getFieldOffset(const ASTContext &C, const FieldDecl *FD)
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
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
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.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
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.
unsigned getSize() const
Returns the size of the block.
std::byte * rawData()
Returns a pointer to the raw data, including metadata.
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
APValue toAPValue(const ASTContext &) 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.
unsigned getNumElems() const
Returns the number of elements.
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 isArrayRoot() const
Whether this array refers to an array, but not to the first element.
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
bool isRoot() const
Pointer points directly to a block.
const Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
APValue toAPValue(const ASTContext &ASTCtx) const
Converts the pointer to an APValue.
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.
bool isPastEnd() const
Checks if the pointer points past the end of the object.
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
bool isBlockPointer() const
std::optional< APValue > toRValue(const Context &Ctx, QualType ResultType) const
Converts the pointer to an APValue that is an rvalue.
const FunctionPointer & asFunctionPointer() const
const Block * block() const
bool isFunctionPointer() const
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool isVirtualBaseClass() const
const BlockPointer & asBlockPointer() const
void initialize() const
Initializes a field.
bool isField() const
Checks if the item is a field in an object.
const Record * getRecord() const
Returns the record descriptor of a class.
Structure/Class descriptor.
const RecordDecl * getDecl() const
Returns the underlying declaration.
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 FieldDecl * asFieldDecl() const
const Expr * asExpr() const
Descriptor used for global variables.
GlobalInitState InitState
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.