13 #ifndef LLVM_CLANG_AST_INTERP_POINTER_H 14 #define LLVM_CLANG_AST_INTERP_POINTER_H 22 #include "llvm/ADT/PointerUnion.h" 23 #include "llvm/Support/raw_ostream.h" 41 static constexpr
unsigned PastEndMark = (unsigned)-1;
42 static constexpr
unsigned RootPtrMark = (unsigned)-1;
59 if (
Base == RootPtrMark)
71 unsigned Field = Offset + Off;
72 return Pointer(Pointee, Field, Field);
82 if (
Base == RootPtrMark)
83 return Pointer(Pointee, 0, Offset == 0 ? Offset : PastEndMark);
101 return Pointer(Pointee, Offset, Offset);
108 return Pointer(Pointee, NewBase, NewBase);
129 return Pointer(Pointee, RootPtrMark, 0);
132 unsigned Next =
Base - getInlineDesc()->
Offset;
136 return Pointer(Pointee, Next, Offset);
140 bool isZero()
const {
return Pointee ==
nullptr; }
152 if (
Base == RootPtrMark) {
153 assert(Offset == PastEndMark &&
"cannot get base of a block");
156 assert(Offset ==
Base &&
"not an inner field");
157 unsigned NewBase =
Base - getInlineDesc()->
Offset;
158 return Pointer(Pointee, NewBase, NewBase);
162 if (
Base == RootPtrMark) {
163 assert(Offset != 0 && Offset != PastEndMark &&
"not an array element");
166 assert(Offset !=
Base &&
"not an array element");
172 if (
Base == 0 ||
Base == RootPtrMark)
174 return getInlineDesc()->
Desc;
182 if (
Base == RootPtrMark)
191 assert(Offset != PastEndMark &&
"invalid offset");
192 if (
Base == RootPtrMark)
196 if (Offset !=
Base) {
202 return Offset -
Base - Adjust;
217 return (
Base == 0 ||
Base == RootPtrMark) && Offset == 0;
280 template <
typename T> T &
deref()
const {
281 assert(
isLive() &&
"Invalid pointer");
282 return *
reinterpret_cast<T *
>(Pointee->
data() + Offset);
286 template <
typename T> T &
elem(
unsigned I)
const {
287 return reinterpret_cast<T *
>(Pointee->
data())[I];
303 void print(llvm::raw_ostream &OS)
const {
304 OS <<
"{" <<
Base <<
", " << Offset <<
", ";
323 assert(Offset != 0 &&
"Not a nested pointer");
333 Block *Pointee =
nullptr;
unsigned IsMutable
Flag indicating if the field is mutable (if in a record).
Descriptor for a dead block.
A (possibly-)qualified type.
unsigned getElemSize() const
returns the size of an element when the structure is viewed as an array.
bool isMutable() const
Checks if the field is mutable.
void initialize() const
Initializes a field.
unsigned IsActive
Flag indicating if the field is the active member of a union.
size_t getSize() const
Returns the total size of the innermost field.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
constexpr XRayInstrMask Function
Descriptor * Desc
Pointer to the stack slot descriptor.
void activate() const
Activats a field.
const FieldDecl * asFieldDecl() const
Pointer atIndex(unsigned Idx) const
Offsets a pointer inside an array.
A pointer to a memory block, live or dead.
Represents a member of a struct/union/class.
Bitfield tracking the initialisation status of elements of primitive arrays.
A memory block, either on the stack or in the heap.
bool IsDead
Flag indicating if the pointer is dead.
bool inPrimitiveArray() const
Checks if the structure is a primitive array.
Structure/Class descriptor.
bool isStatic() const
Checks if the storage is static.
Inline descriptor embedded in structures and arrays.
PrimType
Enumeration of the primitive types of the VM.
unsigned getSize() const
Returns the size of the object without metadata.
unsigned getOffset() const
Returns the offset into an array.
bool isRoot() const
Pointer points directly to a block.
void operator=(const Pointer &P)
const bool IsConst
Flag indicating if the block is mutable.
InterpSize getSize() const
Returns the size of the block.
static bool hasSameBase(const Pointer &A, const Pointer &B)
Checks if two pointers are comparable.
bool isActive() const
Checks if the object is active.
Describes a memory block created by an allocation site.
QualType getType() const
Returns the type of the innermost field.
bool isExtern() const
Checks if the block is extern.
unsigned getByteOffset() const
Returns the byte offset from the start.
size_t elemSize() const
Returns the element size of the innermost field.
llvm::Optional< unsigned > getDeclID() const
Returns the declaration ID.
bool isField() const
Checks if the item is a field in an object.
unsigned IsBase
Flag indicating if the field is an embedded base class.
void deactivate() const
Deactivates an entire strurcutre.
bool isUnion() const
Checks if the object is a union.
Pointer expand() const
Expands a pointer to the containing array, undoing narrowing.
bool isTemporary() const
Checks if the block is temporary.
bool inArray() const
Checks if the innermost field is an array.
bool isStaticTemporary() const
Checks if the storage is a static temporary.
unsigned IsConst
Flag indicating if the storage is constant or not.
unsigned getNumElems() const
Returns the number of elements.
bool isArrayElement() const
Checks if the pointer points to an array.
Pointer narrow() const
Restricts the scope of an array element pointer.
char * data()
Returns a pointer to the stored data.
Encodes a location in the source.
const bool IsArray
Flag indicating if the block is an array.
bool isExtern() const
Checks if the storage is extern.
llvm::Optional< unsigned > getDeclID() const
Returns the declaration ID.
Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool isStatic() const
Checks if the block has static storage duration.
static bool hasSameArray(const Pointer &A, const Pointer &B)
Checks if two pointers can be subtracted.
SourceLocation getLocation() const
bool isTemporary() const
Checks if the storage is temporary.
bool isBaseClass() const
Checks if a structure is a base class.
SourceLocation getDeclLoc() const
Dataflow Directional Tag Classes.
Pointer getArray() const
Returns the parent array.
bool isLive() const
Checks if the pointer is live.
bool isInitialized() const
Checks if an object was initialized.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
void print(llvm::raw_ostream &OS) const
Prints the pointer.
int64_t getIndex() const
Returns the index into an array.
T & deref() const
Dereferences the pointer, if it's live.
bool isOnePastEnd() const
Checks if the index is one past end.
Record * getRecord() const
Returns the record descriptor of a class.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
const FieldDecl * getField() const
Returns the field information.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
bool isZero() const
Checks if the pointer is null.
Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
bool isConst() const
Checks if an object or a subfield is mutable.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
bool isUnknownSizeArray() const
Checks if the descriptor is of an array of unknown size.
T & elem(unsigned I) const
Dereferences a primitive element.
Record *const ElemRecord
Pointer to the record, if block contains records.
APValue toAPValue() const
Converts the pointer to an APValue.
unsigned Offset
Offset inside the structure/array.
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.