13#ifndef LLVM_CLANG_AST_INTERP_POINTER_H
14#define LLVM_CLANG_AST_INTERP_POINTER_H
23#include "llvm/Support/raw_ostream.h"
51 unsigned Offset)
const;
94 static constexpr unsigned PastEndMark = ~0u;
95 static constexpr unsigned RootPtrMark = ~0u;
106 : Offset(Offset), StorageKind(
Storage::
Int),
Int{Desc, Address} {}
108 : Offset(Offset), StorageKind(
Storage::
Fn),
Fn(F) {}
112 Typeid.TypeInfoType = TypeInfoType;
122 if (P.StorageKind != StorageKind)
148 return Fn.getIntegerRepresentation() + Offset;
149 return reinterpret_cast<uint64_t
>(
BS.Pointee) + Offset;
163 if (
BS.Base == RootPtrMark)
176 unsigned Field = Offset + Off;
177 return Pointer(
BS.Pointee, Field, Field);
183 assert(Offset >= Off);
184 unsigned O = Offset - Off;
199 if (
Base == RootPtrMark)
201 Offset == 0 ? Offset : PastEndMark);
208 if (Offset !=
Base) {
214 return Pointer(
BS.Pointee, Offset, Offset);
241 if (
BS.Base != Offset)
248 unsigned Next =
BS.Base - getInlineDesc()->Offset;
252 : getDescriptor(
Next)->Desc;
260 switch (StorageKind) {
262 return Int.Value == 0 && Offset == 0;
264 return BS.Pointee ==
nullptr;
270 llvm_unreachable(
"Unknown clang::interp::Storage enum");
276 return BS.Pointee && !
BS.Pointee->isDead();
295 return BS.Pointee->Desc;
313 if (
BS.Base == RootPtrMark) {
314 assert(Offset == PastEndMark &&
"cannot get base of a block");
317 unsigned NewBase =
BS.Base - getInlineDesc()->Offset;
318 return Pointer(
BS.Pointee, NewBase, NewBase);
322 if (
BS.Base == RootPtrMark) {
323 assert(Offset != 0 && Offset != PastEndMark &&
"not an array element");
326 assert(Offset !=
BS.Base &&
"not an array element");
337 return getInlineDesc()->Desc;
345 return Fn.getFunction()->getDecl()->getType();
351 return AT->getElementType();
353 return CT->getElementType();
355 return CT->getElementType();
367 return Int.Desc->getElemSize();
370 if (
BS.Base == RootPtrMark)
382 assert(Offset != PastEndMark &&
"invalid offset");
384 if (
BS.Base == RootPtrMark)
388 if (Offset !=
BS.Base) {
394 return Offset -
BS.Base - Adjust;
409 return getInlineDesc()->InUnion;
445 return (
BS.Base ==
BS.Pointee->getDescriptor()->getMetadataSize() ||
453 return BS.Pointee &&
BS.Base > 0;
483 return ElemDesc ? ElemDesc->
ElemRecord :
nullptr;
488 return FD->asFieldDecl();
495 return BS.Pointee &&
BS.Pointee->isExtern();
503 return BS.Pointee->isStatic();
509 return BS.Pointee->isTemporary();
517 return BS.Pointee->isDynamic();
528 return !
isRoot() && getInlineDesc()->IsFieldMutable;
538 return BS.Pointee->isWeak();
544 return isRoot() || getInlineDesc()->IsActive;
549 return isField() && getInlineDesc()->IsVirtualBase;
556 if (
const Block *Pointee =
BS.Pointee)
557 return Pointee->isDummy();
570 return isRoot() ?
false : getInlineDesc()->IsConstInMutable;
584 return BS.Pointee->getDeclID();
592 return Int.Value + Offset;
613 return BS.Pointee->rawData() + Offset;
652 return !
isZero() && Offset >
BS.Pointee->getSize();
663 return Desc->isZeroSizeArray();
669 assert(
isLive() &&
"Invalid pointer");
673 assert(Offset +
sizeof(
T) <=
BS.Pointee->getDescriptor()->getAllocSize());
676 return *
reinterpret_cast<T *
>(
BS.Pointee->rawData() +
BS.Base +
679 return *
reinterpret_cast<T *
>(
BS.Pointee->rawData() + Offset);
684 template <
typename T>
T &
elem(
unsigned I)
const {
685 assert(
isLive() &&
"Invalid pointer");
693 unsigned ReadOffset =
BS.Base +
sizeof(
InitMapPtr) + ElemByteOffset;
694 assert(ReadOffset +
sizeof(
T) <=
695 BS.Pointee->getDescriptor()->getAllocSize());
697 return *
reinterpret_cast<T *
>(
BS.Pointee->rawData() + ReadOffset);
734 return getInlineDesc()->LifeState;
758 if (Offset <
Other.Offset)
760 if (Offset >
Other.Offset)
773 static std::optional<std::pair<Pointer, Pointer>>
782 void print(llvm::raw_ostream &OS)
const;
802 assert(
BS.Base <=
BS.Pointee->getSize());
804 return getDescriptor(
BS.Base);
809 assert(Offset != 0 &&
"Not a nested pointer");
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a member of a struct/union/class.
A (possibly-)qualified type.
Encodes a location in the source.
The base class of the type hierarchy.
A memory block, either on the stack or in the heap.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
std::byte * rawData()
Returns a pointer to the raw data, including metadata.
Holds all information required to evaluate constexpr code in a module.
Descriptor for a dead block.
const Function * getFunction() const
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
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.
UnsignedOrNone getDeclID() const
Returns the declaration ID.
void deactivate() const
Deactivates an entire strurcutre.
bool isVolatile() const
Checks if an object or a subfield is volatile.
bool isInitialized() const
Checks if an object was initialized.
bool isStatic() const
Checks if the storage is static.
bool isDynamic() const
Checks if the storage has been dynamically allocated.
bool isZeroSizeArray() const
Checks if the pointer is pointing to a zero-size array.
bool isElementInitialized(unsigned Index) const
Like isInitialized(), but for primitive arrays.
Pointer atIndex(uint64_t Idx) const
Offsets a pointer inside an array.
bool isDummy() const
Checks if the pointer points to a dummy value.
Pointer atFieldSub(unsigned Off) const
Subtract the given offset from the current Base and Offset of the pointer.
bool inPrimitiveArray() const
Checks if the structure is a primitive array.
void print(llvm::raw_ostream &OS) const
Prints the pointer.
bool isExtern() const
Checks if the storage is extern.
int64_t getIndex() const
Returns the index into an array.
friend class MemberPointer
bool isActive() const
Checks if the object is active.
bool isConst() const
Checks if an object or a subfield is mutable.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
T & deref() const
Dereferences the pointer, if it's live.
Pointer(IntPointer &&IntPtr)
bool isMutable() const
Checks if the field is mutable.
bool isConstInMutable() const
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.
static std::optional< std::pair< Pointer, Pointer > > computeSplitPoint(const Pointer &A, const Pointer &B)
const TypeidPointer & asTypeidPointer() const
bool isIntegralPointer() const
QualType getType() const
Returns the type of the innermost field.
bool operator==(const Pointer &P) const
Equality operators are just for tests.
bool isArrayElement() const
Checks if the pointer points to an array.
void initializeAllElements() const
Initialize all elements of a primitive array at once.
bool pointsToStringLiteral() const
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.
bool inArray() const
Checks if the innermost field is an array.
bool isStaticTemporary() const
Checks if the storage is a static temporary.
Pointer(const Type *TypePtr, const Type *TypeInfoType, uint64_t Offset=0)
T & elem(unsigned I) const
Dereferences the element at index I.
bool pointsToLiteral() const
Whether this points to a block that's been created for a "literal lvalue", i.e.
Pointer(uint64_t Address, const Descriptor *Desc, uint64_t Offset=0)
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
uint64_t getByteOffset() const
Returns the byte offset from the start.
bool isTypeidPointer() const
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.
Pointer & operator=(const Pointer &P)
ComparisonCategoryResult compare(const Pointer &Other) const
Compare two pointers.
const IntPointer & asIntPointer() const
bool isRoot() const
Pointer points directly to a block.
const Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
const Record * getElemRecord() const
Returns the element record type, if this is a non-primive array.
static bool pointToSameBlock(const Pointer &A, const Pointer &B)
Checks if both given pointers point to the same block.
APValue toAPValue(const ASTContext &ASTCtx) const
Converts the pointer to an APValue.
unsigned getOffset() const
Returns the offset into an array.
friend class DynamicAllocator
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.
uint64_t getIntegerRepresentation() const
bool isPastEnd() const
Checks if the pointer points past the end of the object.
Pointer(const Function *F, uint64_t Offset=0)
const FieldDecl * getField() const
Returns the field information.
Pointer expand() const
Expands a pointer to the containing array, undoing narrowing.
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
bool isDereferencable() const
Whether this block can be read from at all.
void startLifetime() const
bool isBlockPointer() const
bool operator!=(const Pointer &P) const
std::optional< APValue > toRValue(const Context &Ctx, QualType ResultType) const
Converts the pointer to an APValue that is an rvalue.
size_t getSize() const
Returns the total size of the innermost field.
bool isTemporary() const
Checks if the storage is temporary.
const FunctionPointer & asFunctionPointer() const
bool allElementsInitialized() const
SourceLocation getDeclLoc() const
const Block * block() const
bool isFunctionPointer() const
Pointer getDeclPtr() const
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool isVirtualBaseClass() const
bool isBaseClass() const
Checks if a structure is a base class.
size_t elemSize() const
Returns the element size of the innermost field.
bool canBeInitialized() const
If this pointer has an InlineDescriptor we can use to initialize.
Lifetime getLifetime() const
size_t computeOffsetForComparison() const
Compute an integer that can be used to compare this pointer to another one.
const BlockPointer & asBlockPointer() const
void initialize() const
Initializes a field.
const std::byte * getRawAddress() const
If backed by actual data (i.e.
bool isField() const
Checks if the item is a field in an object.
void initializeElement(unsigned Index) const
Initialized the given element of a primitive array.
const Record * getRecord() const
Returns the record descriptor of a class.
Structure/Class descriptor.
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
std::optional< std::pair< bool, std::shared_ptr< InitMap > > > InitMapPtr
The JSON file list parser is used to communicate input to InstallAPI.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
const FunctionProtoType * T
@ Other
Other implicit parameter.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Pointer * Prev
Previous link in the pointer chain.
Pointer * Next
Next link in the pointer chain.
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.
const bool IsConst
Flag indicating if the block is mutable.
unsigned getSize() const
Returns the size of the object without metadata.
const DeclTy & getSource() const
const Decl * asDecl() const
const Descriptor *const ElemDesc
Descriptor of the array element.
SourceLocation getLocation() const
bool isUnknownSizeArray() const
Checks if the descriptor is of an array of unknown size.
unsigned getElemSize() const
returns the size of an element when the structure is viewed as an array.
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 Record *const ElemRecord
Pointer to the record, if block contains records.
Descriptor used for global variables.
Inline descriptor embedded in structures and arrays.
std::optional< IntPointer > atOffset(const ASTContext &ASTCtx, unsigned Offset) const
IntPointer baseCast(const ASTContext &ASTCtx, unsigned BaseOffset) const
const Type * TypeInfoType