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"
63 static constexpr unsigned PastEndMark = ~0u;
64 static constexpr unsigned RootPtrMark = ~0u;
82 if (
Base == RootPtrMark)
94 unsigned Field = Offset + Off;
95 return Pointer(Pointee, Field, Field);
105 if (
Base == RootPtrMark)
106 return Pointer(Pointee, 0, Offset == 0 ? Offset : PastEndMark);
124 return Pointer(Pointee, Offset, Offset);
131 return Pointer(Pointee, NewBase, NewBase);
152 return Pointer(Pointee, RootPtrMark, 0);
155 unsigned Next =
Base - getInlineDesc()->
Offset;
159 return Pointer(Pointee, Next, Offset);
163 bool isZero()
const {
return Pointee ==
nullptr; }
175 if (
Base == RootPtrMark) {
176 assert(Offset == PastEndMark &&
"cannot get base of a block");
179 assert(Offset ==
Base &&
"not an inner field");
180 unsigned NewBase =
Base - getInlineDesc()->
Offset;
181 return Pointer(Pointee, NewBase, NewBase);
185 if (
Base == RootPtrMark) {
186 assert(Offset != 0 && Offset != PastEndMark &&
"not an array element");
189 assert(Offset !=
Base &&
"not an array element");
195 if (
Base == 0 ||
Base == RootPtrMark)
197 return getInlineDesc()->
Desc;
205 if (
Base == RootPtrMark)
214 assert(Offset != PastEndMark &&
"invalid offset");
215 if (
Base == RootPtrMark)
219 if (Offset !=
Base) {
225 return Offset -
Base - Adjust;
244 return (
Base == 0 ||
Base == RootPtrMark) && Offset == 0;
313 template <
typename T> T &
deref()
const {
314 assert(
isLive() &&
"Invalid pointer");
316 return *
reinterpret_cast<T *
>(Pointee->
rawData() +
Base +
319 return *
reinterpret_cast<T *
>(Pointee->
rawData() + Offset);
323 template <
typename T> T &
elem(
unsigned I)
const {
324 return reinterpret_cast<T *
>(Pointee->
rawData())[I];
341 OS << Pointee <<
" {" <<
Base <<
", " << Offset <<
", ";
360 assert(
Offset != 0 &&
"Not a nested pointer");
366 InitMap *&getInitMap()
const {
367 return *
reinterpret_cast<InitMap **
>(Pointee->
rawData() +
Base);
371 Block *Pointee =
nullptr;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Represents a member of a struct/union/class.
A (possibly-)qualified type.
Encodes a location in the source.
A memory block, either on the stack or in the heap.
unsigned getSize() const
Returns the size of the block.
bool isExtern() const
Checks if the block is extern.
Descriptor * Desc
Pointer to the stack slot descriptor.
bool isStatic() const
Checks if the block has static storage duration.
bool isTemporary() const
Checks if the block is temporary.
bool IsDead
Flag indicating if the pointer is dead.
char * rawData()
Returns a pointer to the raw data, including metadata.
std::optional< unsigned > getDeclID() const
Returns the declaration ID.
Descriptor for a dead block.
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 inPrimitiveArray() const
Checks if the structure is a primitive array.
bool isExtern() const
Checks if the storage is extern.
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.
bool isConst() const
Checks if an object or a subfield is mutable.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
bool isUnion() const
Checks if the object is a union.
T & deref() const
Dereferences the pointer, if it's live.
bool isMutable() const
Checks if the field is mutable.
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)
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.
bool inArray() const
Checks if the innermost field is an array.
bool isStaticTemporary() const
Checks if the storage is a static temporary.
Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
T & elem(unsigned I) const
Dereferences a primitive element.
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
bool isZero() const
Checks if the pointer is null.
bool isRoot() const
Pointer points directly to a block.
unsigned getOffset() const
Returns the offset into an array.
Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
Record * getElemRecord() const
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.
const FieldDecl * getField() const
Returns the field information.
void print(llvm::raw_ostream &OS) const
Prints the pointer.
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.
Record * getRecord() const
Returns the record descriptor of a class.
size_t getSize() const
Returns the total size of the innermost field.
bool isTemporary() const
Checks if the storage is temporary.
SourceLocation getDeclLoc() const
APValue toAPValue() const
Converts the pointer to an APValue.
std::optional< unsigned > getDeclID() const
Returns the declaration ID.
bool isBaseClass() const
Checks if a structure is a base class.
size_t elemSize() const
Returns the element size of the innermost field.
void initialize() const
Initializes a field.
bool isField() const
Checks if the item is a field in an object.
unsigned getByteOffset() const
Returns the byte offset from the start.
Structure/Class descriptor.
PrimType
Enumeration of the primitive types of the VM.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
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.
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.
Descriptor *const ElemDesc
Descriptor of the array element.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
const FieldDecl * asFieldDecl() const
Record *const ElemRecord
Pointer to the record, if block contains records.
Bitfield tracking the initialisation status of elements of primitive arrays.
Inline descriptor embedded in structures and arrays.
unsigned IsActive
Flag indicating if the field is the active member of a union.
unsigned IsBase
Flag indicating if the field is an embedded base class.
unsigned Offset
Offset inside the structure/array.
unsigned IsConst
Flag indicating if the storage is constant or not.
unsigned IsFieldMutable
Flag indicating if the field is mutable (if in a record).