Go to the documentation of this file.
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"
38 static constexpr
unsigned PastEndMark = (
unsigned)-1;
39 static constexpr
unsigned RootPtrMark = (
unsigned)-1;
56 if (
Base == RootPtrMark)
68 unsigned Field = Offset + Off;
69 return Pointer(Pointee, Field, Field);
79 if (
Base == RootPtrMark)
80 return Pointer(Pointee, 0, Offset == 0 ? Offset : PastEndMark);
98 return Pointer(Pointee, Offset, Offset);
105 return Pointer(Pointee, NewBase, NewBase);
126 return Pointer(Pointee, RootPtrMark, 0);
129 unsigned Next =
Base - getInlineDesc()->
Offset;
133 return Pointer(Pointee, Next, Offset);
137 bool isZero()
const {
return Pointee ==
nullptr; }
149 if (
Base == RootPtrMark) {
150 assert(Offset == PastEndMark &&
"cannot get base of a block");
153 assert(Offset ==
Base &&
"not an inner field");
154 unsigned NewBase =
Base - getInlineDesc()->
Offset;
155 return Pointer(Pointee, NewBase, NewBase);
159 if (
Base == RootPtrMark) {
160 assert(Offset != 0 && Offset != PastEndMark &&
"not an array element");
163 assert(Offset !=
Base &&
"not an array element");
169 if (
Base == 0 ||
Base == RootPtrMark)
171 return getInlineDesc()->
Desc;
179 if (
Base == RootPtrMark)
188 assert(Offset != PastEndMark &&
"invalid offset");
189 if (
Base == RootPtrMark)
193 if (Offset !=
Base) {
199 return Offset -
Base - Adjust;
214 return (
Base == 0 ||
Base == RootPtrMark) && Offset == 0;
277 template <
typename T> T &
deref()
const {
278 assert(
isLive() &&
"Invalid pointer");
279 return *
reinterpret_cast<T *
>(Pointee->
data() + Offset);
283 template <
typename T> T &
elem(
unsigned I)
const {
284 return reinterpret_cast<T *
>(Pointee->
data())[I];
300 void print(llvm::raw_ostream &OS)
const {
301 OS <<
"{" <<
Base <<
", " << Offset <<
", ";
320 assert(
Offset != 0 &&
"Not a nested pointer");
325 InitMap *&getInitMap()
const {
326 return *
reinterpret_cast<InitMap **
>(Pointee->
data() +
Base);
330 Block *Pointee =
nullptr;
Descriptor for a dead block.
void initialize() const
Initializes a field.
unsigned getNumElems() const
Returns the number of elements.
const bool IsConst
Flag indicating if the block is mutable.
T & deref() const
Dereferences the pointer, if it's live.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
bool inPrimitiveArray() const
Checks if the structure is a primitive array.
Record * getRecord() const
Returns the record descriptor of a class.
size_t getSize() const
Returns the total size of the innermost field.
char * data()
Returns a pointer to the stored data.
Encodes a location in the source.
A (possibly-)qualified type.
bool isMutable() const
Checks if the field is mutable.
size_t elemSize() const
Returns the element size of the innermost field.
Represents a member of a struct/union/class.
bool isTemporary() const
Checks if the block is temporary.
unsigned getOffset() const
Returns the offset into an array.
unsigned IsBase
Flag indicating if the field is an embedded base class.
const bool IsArray
Flag indicating if the block is an array.
Pointer getArray() const
Returns the parent array.
SourceLocation getDeclLoc() const
Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
unsigned IsConst
Flag indicating if the storage is constant or not.
static bool hasSameArray(const Pointer &A, const Pointer &B)
Checks if two pointers can be subtracted.
bool isField() const
Checks if the item is a field in an object.
bool isTemporary() const
Checks if the storage is temporary.
A pointer to a memory block, live or dead.
Pointer expand() const
Expands a pointer to the containing array, undoing narrowing.
bool isRoot() const
Pointer points directly to a block.
Bitfield tracking the initialisation status of elements of primitive arrays.
static bool hasSameBase(const Pointer &A, const Pointer &B)
Checks if two pointers are comparable.
bool isStaticTemporary() const
Checks if the storage is a static temporary.
unsigned Offset
Offset inside the structure/array.
T & elem(unsigned I) const
Dereferences a primitive element.
bool isStatic() const
Checks if the block has static storage duration.
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
void activate() const
Activats a field.
unsigned IsActive
Flag indicating if the field is the active member of a union.
unsigned IsMutable
Flag indicating if the field is mutable (if in a record).
bool isLive() const
Checks if the pointer is live.
A memory block, either on the stack or in the heap.
PrimType
Enumeration of the primitive types of the VM.
bool isConst() const
Checks if an object or a subfield is mutable.
Pointer atIndex(unsigned Idx) const
Offsets a pointer inside an array.
bool isArrayElement() const
Checks if the pointer points to an array.
QualType getType() const
Returns the type of the innermost field.
bool isExtern() const
Checks if the block is extern.
bool isUnknownSizeArray() const
Checks if the descriptor is of an array of unknown size.
unsigned getByteOffset() const
Returns the byte offset from the start.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
Record *const ElemRecord
Pointer to the record, if block contains records.
void print(llvm::raw_ostream &OS) const
Prints the pointer.
bool inArray() const
Checks if the innermost field is an array.
const FieldDecl * asFieldDecl() const
void deactivate() const
Deactivates an entire strurcutre.
Inline descriptor embedded in structures and arrays.
bool isUnion() const
Checks if the object is a union.
llvm::Optional< unsigned > getDeclID() const
Returns the declaration ID.
SourceLocation getLocation() const
bool isZero() const
Checks if the pointer is null.
bool isBaseClass() const
Checks if a structure is a base class.
InterpSize getSize() const
Returns the size of the block.
Describes a memory block created by an allocation site.
bool isInitialized() const
Checks if an object was initialized.
Descriptor * Desc
Pointer to the stack slot descriptor.
bool isActive() const
Checks if the object is active.
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
APValue toAPValue() const
Converts the pointer to an APValue.
bool IsDead
Flag indicating if the pointer is dead.
bool isExtern() const
Checks if the storage is extern.
const FieldDecl * getField() const
Returns the field information.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
unsigned getSize() const
Returns the size of the object without metadata.
bool isStatic() const
Checks if the storage is static.
int64_t getIndex() const
Returns the index into an array.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
llvm::Optional< unsigned > getDeclID() const
Returns the declaration ID.
void operator=(const Pointer &P)
Structure/Class descriptor.
unsigned getElemSize() const
returns the size of an element when the structure is viewed as an array.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
Pointer narrow() const
Restricts the scope of an array element pointer.
Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool isOnePastEnd() const
Checks if the index is one past end.