clang 20.0.0git
Public Member Functions | Static Public Member Functions | Friends | List of all members
clang::interp::Pointer Class Reference

A pointer to a memory block, live or dead. More...

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/AST/ByteCode/Pointer.h"

Public Member Functions

 Pointer ()
 
 Pointer (IntPointer &&IntPtr)
 
 Pointer (Block *B)
 
 Pointer (Block *B, uint64_t BaseAndOffset)
 
 Pointer (const Pointer &P)
 
 Pointer (Pointer &&P)
 
 Pointer (uint64_t Address, const Descriptor *Desc, uint64_t Offset=0)
 
 Pointer (const Function *F, uint64_t Offset=0)
 
 ~Pointer ()
 
void operator= (const Pointer &P)
 
void operator= (Pointer &&P)
 
bool operator== (const Pointer &P) const
 Equality operators are just for tests.
 
bool operator!= (const Pointer &P) const
 
APValue toAPValue (const ASTContext &ASTCtx) const
 Converts the pointer to an APValue.
 
std::string toDiagnosticString (const ASTContext &Ctx) const
 Converts the pointer to a string usable in diagnostics.
 
uint64_t getIntegerRepresentation () const
 
std::optional< APValuetoRValue (const Context &Ctx, QualType ResultType) const
 Converts the pointer to an APValue that is an rvalue.
 
Pointer atIndex (uint64_t Idx) const
 Offsets a pointer inside an array.
 
Pointer atField (unsigned Off) const
 Creates a pointer to a field.
 
Pointer atFieldSub (unsigned Off) const
 Subtract the given offset from the current Base and Offset of the pointer.
 
Pointer narrow () const
 Restricts the scope of an array element pointer.
 
Pointer expand () const
 Expands a pointer to the containing array, undoing narrowing.
 
bool isZero () const
 Checks if the pointer is null.
 
bool isLive () const
 Checks if the pointer is live.
 
bool isField () const
 Checks if the item is a field in an object.
 
const DescriptorgetDeclDesc () const
 Accessor for information about the declaration site.
 
SourceLocation getDeclLoc () const
 
DeclTy getSource () const
 Returns the expression or declaration the pointer has been created for.
 
Pointer getBase () const
 Returns a pointer to the object of which this pointer is a field.
 
Pointer getArray () const
 Returns the parent array.
 
const DescriptorgetFieldDesc () const
 Accessors for information about the innermost field.
 
QualType getType () const
 Returns the type of the innermost field.
 
Pointer getDeclPtr () const
 
size_t elemSize () const
 Returns the element size of the innermost field.
 
size_t getSize () const
 Returns the total size of the innermost field.
 
unsigned getOffset () const
 Returns the offset into an array.
 
bool isArrayRoot () const
 Whether this array refers to an array, but not to the first element.
 
bool inArray () const
 Checks if the innermost field is an array.
 
bool inUnion () const
 
bool inPrimitiveArray () const
 Checks if the structure is a primitive array.
 
bool isUnknownSizeArray () const
 Checks if the structure is an array of unknown size.
 
bool isArrayElement () const
 Checks if the pointer points to an array.
 
bool isRoot () const
 Pointer points directly to a block.
 
bool canBeInitialized () const
 If this pointer has an InlineDescriptor we can use to initialize.
 
const BlockPointerasBlockPointer () const
 
const IntPointerasIntPointer () const
 
const FunctionPointerasFunctionPointer () const
 
bool isBlockPointer () const
 
bool isIntegralPointer () const
 
bool isFunctionPointer () const
 
const RecordgetRecord () const
 Returns the record descriptor of a class.
 
const RecordgetElemRecord () const
 Returns the element record type, if this is a non-primive array.
 
const FieldDeclgetField () const
 Returns the field information.
 
bool isUnion () const
 Checks if the object is a union.
 
bool isExtern () const
 Checks if the storage is extern.
 
bool isStatic () const
 Checks if the storage is static.
 
bool isTemporary () const
 Checks if the storage is temporary.
 
bool isStaticTemporary () const
 Checks if the storage is a static temporary.
 
bool isMutable () const
 Checks if the field is mutable.
 
bool isWeak () const
 
bool isInitialized () const
 Checks if an object was initialized.
 
bool isActive () const
 Checks if the object is active.
 
bool isBaseClass () const
 Checks if a structure is a base class.
 
bool isVirtualBaseClass () const
 
bool isDummy () const
 Checks if the pointer points to a dummy value.
 
bool isConst () const
 Checks if an object or a subfield is mutable.
 
std::optional< unsignedgetDeclID () const
 Returns the declaration ID.
 
unsigned getByteOffset () const
 Returns the byte offset from the start.
 
unsigned getNumElems () const
 Returns the number of elements.
 
const Blockblock () const
 
int64_t getIndex () const
 Returns the index into an array.
 
bool isOnePastEnd () const
 Checks if the index is one past end.
 
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 isZeroSizeArray () const
 Checks if the pointer is pointing to a zero-size array.
 
template<typename T >
Tderef () const
 Dereferences the pointer, if it's live.
 
template<typename T >
Telem (unsigned I) const
 Dereferences a primitive element.
 
bool isDereferencable () const
 Whether this block can be read from at all.
 
void initialize () const
 Initializes a field.
 
void activate () const
 Activats a field.
 
void deactivate () const
 Deactivates an entire strurcutre.
 
ComparisonCategoryResult compare (const Pointer &Other) const
 Compare two pointers.
 
void print (llvm::raw_ostream &OS) const
 Prints the pointer.
 

Static Public Member Functions

static bool hasSameBase (const Pointer &A, const Pointer &B)
 Checks if two pointers are comparable.
 
static bool hasSameArray (const Pointer &A, const Pointer &B)
 Checks if two pointers can be subtracted.
 
static bool pointToSameBlock (const Pointer &A, const Pointer &B)
 Checks if both given pointers point to the same block.
 

Friends

class Block
 
class DeadBlock
 
class MemberPointer
 
class InterpState
 
struct InitMap
 
class DynamicAllocator
 

Detailed Description

A pointer to a memory block, live or dead.

This object can be allocated into interpreter stack frames. If pointing to a live block, it is a link in the chain of pointers pointing to the block.

In the simplest form, a Pointer has a Block* (the pointee) and both Base and Offset are 0, which means it will point to raw data.

The Base field is used to access metadata about the data. For primitive arrays, the Base is followed by an InitMap. In a variety of cases, the Base is preceded by an InlineDescriptor, which is used to track the initialization state, among other things.

The Offset field is used to access the actual data. In other words, the data the pointer decribes can be found at Pointee->rawData() + Pointer.Offset.

Pointee Offset │ │ │ │ ▼ ▼ ┌───────┬────────────┬─────────┬────────────────────────────┐ │ Block │ InlineDesc │ InitMap │ Actual Data │ └───────┴────────────┴─────────┴────────────────────────────┘ ▲ │ │ Base

Definition at line 82 of file Pointer.h.

Constructor & Destructor Documentation

◆ Pointer() [1/8]

clang::interp::Pointer::Pointer ( )
inline

Definition at line 88 of file Pointer.h.

References clang::interp::Int.

Referenced by atField(), atFieldSub(), atIndex(), expand(), getArray(), getBase(), getDeclPtr(), and narrow().

◆ Pointer() [2/8]

clang::interp::Pointer::Pointer ( IntPointer &&  IntPtr)
inline

Definition at line 93 of file Pointer.h.

◆ Pointer() [3/8]

Pointer::Pointer ( Block B)

Definition at line 25 of file Pointer.cpp.

◆ Pointer() [4/8]

Pointer::Pointer ( Block B,
uint64_t  BaseAndOffset 
)

Definition at line 29 of file Pointer.cpp.

◆ Pointer() [5/8]

Pointer::Pointer ( const Pointer P)

Definition at line 32 of file Pointer.cpp.

References isBlockPointer().

◆ Pointer() [6/8]

Pointer::Pointer ( Pointer &&  P)

Definition at line 50 of file Pointer.cpp.

References clang::interp::Block, and P.

◆ Pointer() [7/8]

clang::interp::Pointer::Pointer ( uint64_t  Address,
const Descriptor Desc,
uint64_t  Offset = 0 
)
inline

Definition at line 100 of file Pointer.h.

◆ Pointer() [8/8]

clang::interp::Pointer::Pointer ( const Function F,
uint64_t  Offset = 0 
)
inline

Definition at line 105 of file Pointer.h.

◆ ~Pointer()

Pointer::~Pointer ( )

Definition at line 58 of file Pointer.cpp.

References isBlockPointer().

Member Function Documentation

◆ activate()

void Pointer::activate ( ) const

◆ asBlockPointer()

const BlockPointer & clang::interp::Pointer::asBlockPointer ( ) const
inline

◆ asFunctionPointer()

const FunctionPointer & clang::interp::Pointer::asFunctionPointer ( ) const
inline

Definition at line 451 of file Pointer.h.

References isFunctionPointer().

Referenced by atIndex(), getIntegerRepresentation(), getSource(), isZero(), print(), and toAPValue().

◆ asIntPointer()

const IntPointer & clang::interp::Pointer::asIntPointer ( ) const
inline

◆ atField()

Pointer clang::interp::Pointer::atField ( unsigned  Off) const
inline

◆ atFieldSub()

Pointer clang::interp::Pointer::atFieldSub ( unsigned  Off) const
inline

Subtract the given offset from the current Base and Offset of the pointer.

Definition at line 176 of file Pointer.h.

References asBlockPointer(), and Pointer().

Referenced by clang::interp::GetPtrDerivedPop().

◆ atIndex()

Pointer clang::interp::Pointer::atIndex ( uint64_t  Idx) const
inline

◆ block()

const Block * clang::interp::Pointer::block ( ) const
inline

◆ canBeInitialized()

bool clang::interp::Pointer::canBeInitialized ( ) const
inline

If this pointer has an InlineDescriptor we can use to initialize.

Definition at line 436 of file Pointer.h.

References asBlockPointer(), clang::interp::BlockPointer::Base, isBlockPointer(), and clang::interp::BlockPointer::Pointee.

Referenced by clang::interp::FinishInit(), and clang::interp::FinishInitPop().

◆ compare()

ComparisonCategoryResult clang::interp::Pointer::compare ( const Pointer Other) const
inline

Compare two pointers.

Definition at line 666 of file Pointer.h.

References clang::Equal, clang::Greater, hasSameBase(), clang::Less, clang::Other, and clang::Unordered.

Referenced by clang::interp::CMP3().

◆ deactivate()

void Pointer::deactivate ( ) const

Deactivates an entire strurcutre.

Definition at line 431 of file Pointer.cpp.

Referenced by clang::interp::GetPtrActiveField().

◆ deref()

template<typename T >
T & clang::interp::Pointer::deref ( ) const
inline

◆ elem()

template<typename T >
T & clang::interp::Pointer::elem ( unsigned  I) const
inline

Dereferences a primitive element.

Definition at line 639 of file Pointer.h.

References asBlockPointer(), clang::interp::Block::data(), getNumElems(), isBlockPointer(), clang::interp::BlockPointer::Pointee, and clang::T.

◆ elemSize()

size_t clang::interp::Pointer::elemSize ( ) const
inline

◆ expand()

Pointer clang::interp::Pointer::expand ( ) const
inline

◆ getArray()

Pointer clang::interp::Pointer::getArray ( ) const
inline

Returns the parent array.

Definition at line 317 of file Pointer.h.

References asBlockPointer(), and Pointer().

Referenced by toAPValue().

◆ getBase()

Pointer clang::interp::Pointer::getBase ( ) const
inline

Returns a pointer to the object of which this pointer is a field.

Definition at line 308 of file Pointer.h.

References asBlockPointer(), clang::interp::BlockPointer::Base, clang::interp::InlineDescriptor::Offset, and Pointer().

Referenced by activate(), clang::interp::CallVirt(), CheckActive(), and toAPValue().

◆ getByteOffset()

unsigned clang::interp::Pointer::getByteOffset ( ) const
inline

◆ getDeclDesc()

const Descriptor * clang::interp::Pointer::getDeclDesc ( ) const
inline

◆ getDeclID()

std::optional< unsigned > clang::interp::Pointer::getDeclID ( ) const
inline

Returns the declaration ID.

Definition at line 545 of file Pointer.h.

References asBlockPointer(), clang::interp::Block::getDeclID(), isBlockPointer(), and clang::interp::BlockPointer::Pointee.

Referenced by CheckGlobal(), and CheckTemporary().

◆ getDeclLoc()

SourceLocation clang::interp::Pointer::getDeclLoc ( ) const
inline

◆ getDeclPtr()

Pointer clang::interp::Pointer::getDeclPtr ( ) const
inline

Definition at line 352 of file Pointer.h.

References asBlockPointer(), and Pointer().

Referenced by clang::interp::CheckDowncast().

◆ getElemRecord()

const Record * clang::interp::Pointer::getElemRecord ( ) const
inline

Returns the element record type, if this is a non-primive array.

Definition at line 463 of file Pointer.h.

References clang::interp::Descriptor::ElemDesc, clang::interp::Descriptor::ElemRecord, and getFieldDesc().

Referenced by clang::interp::CheckArrayInitialized().

◆ getField()

const FieldDecl * clang::interp::Pointer::getField ( ) const
inline

Returns the field information.

Definition at line 468 of file Pointer.h.

References clang::interp::Descriptor::asFieldDecl(), and getFieldDesc().

Referenced by CheckActive(), clang::interp::CheckArrayInitialized(), and clang::interp::CheckMutable().

◆ getFieldDesc()

const Descriptor * clang::interp::Pointer::getFieldDesc ( ) const
inline

◆ getIndex()

int64_t clang::interp::Pointer::getIndex ( ) const
inline

◆ getIntegerRepresentation()

uint64_t clang::interp::Pointer::getIntegerRepresentation ( ) const
inline

◆ getNumElems()

unsigned clang::interp::Pointer::getNumElems ( ) const
inline

Returns the number of elements.

Definition at line 563 of file Pointer.h.

References elemSize(), getSize(), and isBlockPointer().

Referenced by elem(), clang::interp::interp__builtin_nan(), clang::interp::OffsetHelper(), clang::interp::SubPtr(), and toAPValue().

◆ getOffset()

unsigned clang::interp::Pointer::getOffset ( ) const
inline

Returns the offset into an array.

Definition at line 375 of file Pointer.h.

References asBlockPointer(), clang::interp::BlockPointer::Base, getFieldDesc(), and isBlockPointer().

Referenced by clang::interp::CmpHelperEQ< Pointer >(), getIndex(), and isOnePastEnd().

◆ getRecord()

const Record * clang::interp::Pointer::getRecord ( ) const
inline

◆ getSize()

size_t clang::interp::Pointer::getSize ( ) const
inline

Returns the total size of the innermost field.

Definition at line 369 of file Pointer.h.

References getFieldDesc(), clang::interp::Descriptor::getSize(), and isBlockPointer().

Referenced by atIndex(), expand(), getNumElems(), and isOnePastEnd().

◆ getSource()

DeclTy clang::interp::Pointer::getSource ( ) const
inline

◆ getType()

QualType clang::interp::Pointer::getType ( ) const
inline

◆ hasSameArray()

bool Pointer::hasSameArray ( const Pointer A,
const Pointer B 
)
static

Checks if two pointers can be subtracted.

Definition at line 460 of file Pointer.cpp.

References clang::interp::BlockPointer::Base, BS, getFieldDesc(), hasSameBase(), and clang::interp::Descriptor::IsArray.

◆ hasSameBase()

bool Pointer::hasSameBase ( const Pointer A,
const Pointer B 
)
static

◆ inArray()

bool clang::interp::Pointer::inArray ( ) const
inline

Checks if the innermost field is an array.

Definition at line 398 of file Pointer.h.

References getFieldDesc(), clang::interp::Descriptor::IsArray, and isBlockPointer().

Referenced by isArrayElement(), isArrayRoot(), and clang::interp::OffsetHelper().

◆ initialize()

void Pointer::initialize ( ) const

◆ inPrimitiveArray()

bool clang::interp::Pointer::inPrimitiveArray ( ) const
inline

Checks if the structure is a primitive array.

Definition at line 410 of file Pointer.h.

References getFieldDesc(), isBlockPointer(), and clang::interp::Descriptor::isPrimitiveArray().

Referenced by expand(), getType(), and narrow().

◆ inUnion()

bool clang::interp::Pointer::inUnion ( ) const
inline

Definition at line 403 of file Pointer.h.

References clang::interp::InlineDescriptor::InUnion, and isBlockPointer().

Referenced by activate(), and CheckActive().

◆ isActive()

bool clang::interp::Pointer::isActive ( ) const
inline

◆ isArrayElement()

bool clang::interp::Pointer::isArrayElement ( ) const
inline

Checks if the pointer points to an array.

Definition at line 422 of file Pointer.h.

References asBlockPointer(), clang::interp::BlockPointer::Base, inArray(), and isBlockPointer().

Referenced by clang::interp::Free(), and toAPValue().

◆ isArrayRoot()

bool clang::interp::Pointer::isArrayRoot ( ) const
inline

Whether this array refers to an array, but not to the first element.

Definition at line 393 of file Pointer.h.

References asBlockPointer(), clang::interp::BlockPointer::Base, and inArray().

Referenced by clang::interp::CmpHelperEQ< Pointer >(), deref(), and toAPValue().

◆ isBaseClass()

bool clang::interp::Pointer::isBaseClass ( ) const
inline

Checks if a structure is a base class.

Definition at line 522 of file Pointer.h.

References clang::interp::InlineDescriptor::IsBase, and isField().

Referenced by clang::interp::CallVirt().

◆ isBlockPointer()

bool clang::interp::Pointer::isBlockPointer ( ) const
inline

◆ isConst()

bool clang::interp::Pointer::isConst ( ) const
inline

Checks if an object or a subfield is mutable.

Definition at line 538 of file Pointer.h.

References getDeclDesc(), clang::interp::InlineDescriptor::IsConst, clang::interp::Descriptor::IsConst, isIntegralPointer(), and isRoot().

Referenced by clang::interp::CheckConst().

◆ isDereferencable()

bool clang::interp::Pointer::isDereferencable ( ) const
inline

Whether this block can be read from at all.

This is only true for block pointers that point to a valid location inside that block.

Definition at line 649 of file Pointer.h.

References isBlockPointer(), and isPastEnd().

Referenced by deref().

◆ isDummy()

bool clang::interp::Pointer::isDummy ( ) const
inline

◆ isElementPastEnd()

bool clang::interp::Pointer::isElementPastEnd ( ) const
inline

Checks if the pointer is an out-of-bounds element pointer.

Definition at line 613 of file Pointer.h.

Referenced by clang::interp::CheckRange(), expand(), isOnePastEnd(), print(), and clang::interp::SubPtr().

◆ isExtern()

bool clang::interp::Pointer::isExtern ( ) const
inline

◆ isField()

bool clang::interp::Pointer::isField ( ) const
inline

Checks if the item is a field in an object.

Definition at line 275 of file Pointer.h.

References clang::interp::Descriptor::asDecl(), getFieldDesc(), isBlockPointer(), and isRoot().

Referenced by CheckActive(), clang::interp::CheckLive(), isBaseClass(), isVirtualBaseClass(), and toAPValue().

◆ isFunctionPointer()

bool clang::interp::Pointer::isFunctionPointer ( ) const
inline

◆ isInitialized()

bool Pointer::isInitialized ( ) const

◆ isIntegralPointer()

bool clang::interp::Pointer::isIntegralPointer ( ) const
inline

◆ isLive()

bool clang::interp::Pointer::isLive ( ) const
inline

◆ isMutable()

bool clang::interp::Pointer::isMutable ( ) const
inline

Checks if the field is mutable.

Definition at line 498 of file Pointer.h.

References isBlockPointer(), clang::interp::InlineDescriptor::IsFieldMutable, and isRoot().

Referenced by clang::interp::CheckConst(), and clang::interp::CheckMutable().

◆ isOnePastEnd()

bool clang::interp::Pointer::isOnePastEnd ( ) const
inline

◆ isPastEnd()

bool clang::interp::Pointer::isPastEnd ( ) const
inline

Checks if the pointer points past the end of the object.

Definition at line 605 of file Pointer.h.

References isIntegralPointer(), and isZero().

Referenced by isDereferencable(), isOnePastEnd(), and toRValue().

◆ isRoot()

bool clang::interp::Pointer::isRoot ( ) const
inline

◆ isStatic()

bool clang::interp::Pointer::isStatic ( ) const
inline

◆ isStaticTemporary()

bool clang::interp::Pointer::isStaticTemporary ( ) const
inline

Checks if the storage is a static temporary.

Definition at line 495 of file Pointer.h.

References isStatic(), and isTemporary().

Referenced by CheckTemporary().

◆ isTemporary()

bool clang::interp::Pointer::isTemporary ( ) const
inline

◆ isUnion()

bool clang::interp::Pointer::isUnion ( ) const

Checks if the object is a union.

◆ isUnknownSizeArray()

bool clang::interp::Pointer::isUnknownSizeArray ( ) const
inline

Checks if the structure is an array of unknown size.

Definition at line 416 of file Pointer.h.

References getFieldDesc(), isBlockPointer(), and clang::interp::Descriptor::isUnknownSizeArray().

Referenced by clang::interp::ArrayDecay(), clang::interp::CheckArray(), isOnePastEnd(), narrow(), and toAPValue().

◆ isVirtualBaseClass()

bool clang::interp::Pointer::isVirtualBaseClass ( ) const
inline

Definition at line 523 of file Pointer.h.

References isField(), and clang::interp::InlineDescriptor::IsVirtualBase.

Referenced by toAPValue().

◆ isWeak()

bool clang::interp::Pointer::isWeak ( ) const
inline

Definition at line 504 of file Pointer.h.

References getDeclDesc(), and isBlockPointer().

◆ isZero()

bool clang::interp::Pointer::isZero ( ) const
inline

◆ isZeroSizeArray()

bool clang::interp::Pointer::isZeroSizeArray ( ) const
inline

Checks if the pointer is pointing to a zero-size array.

Definition at line 616 of file Pointer.h.

References getFieldDesc().

Referenced by isOnePastEnd().

◆ narrow()

Pointer clang::interp::Pointer::narrow ( ) const
inline

◆ operator!=()

bool clang::interp::Pointer::operator!= ( const Pointer P) const
inline

Definition at line 128 of file Pointer.h.

References P.

◆ operator=() [1/2]

void Pointer::operator= ( const Pointer P)

Definition at line 69 of file Pointer.cpp.

References isBlockPointer(), and P.

◆ operator=() [2/2]

void Pointer::operator= ( Pointer &&  P)

Definition at line 104 of file Pointer.cpp.

References isBlockPointer(), and P.

◆ operator==()

bool clang::interp::Pointer::operator== ( const Pointer P) const
inline

◆ pointToSameBlock()

bool Pointer::pointToSameBlock ( const Pointer A,
const Pointer B 
)
static

Checks if both given pointers point to the same block.

Definition at line 454 of file Pointer.cpp.

References block(), and isBlockPointer().

Referenced by clang::interp::runRecordDestructor().

◆ print()

void Pointer::print ( llvm::raw_ostream &  OS) const

◆ toAPValue()

APValue Pointer::toAPValue ( const ASTContext ASTCtx) const

◆ toDiagnosticString()

std::string Pointer::toDiagnosticString ( const ASTContext Ctx) const

◆ toRValue()

std::optional< APValue > Pointer::toRValue ( const Context Ctx,
QualType  ResultType 
) const

Friends And Related Function Documentation

◆ Block

friend class Block
friend

Definition at line 689 of file Pointer.h.

◆ DeadBlock

friend class DeadBlock
friend

Definition at line 690 of file Pointer.h.

◆ DynamicAllocator

friend class DynamicAllocator
friend

Definition at line 694 of file Pointer.h.

◆ InitMap

friend struct InitMap
friend

Definition at line 693 of file Pointer.h.

◆ InterpState

friend class InterpState
friend

Definition at line 692 of file Pointer.h.

◆ MemberPointer

friend class MemberPointer
friend

Definition at line 691 of file Pointer.h.

Member Data Documentation

◆ BS

BlockPointer clang::interp::Pointer::BS

Definition at line 732 of file Pointer.h.

Referenced by clang::interp::DynamicAllocator::cleanup(), and hasSameArray().

◆ Fn

FunctionPointer clang::interp::Pointer::Fn

Definition at line 734 of file Pointer.h.

◆ Int

IntPointer clang::interp::Pointer::Int

Definition at line 733 of file Pointer.h.


The documentation for this class was generated from the following files: