clang 18.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/Interp/Pointer.h"

Public Member Functions

 Pointer ()
 
 Pointer (Block *B)
 
 Pointer (Block *B, unsigned BaseAndOffset)
 
 Pointer (const Pointer &P)
 
 Pointer (Pointer &&P)
 
 ~Pointer ()
 
void operator= (const Pointer &P)
 
void operator= (Pointer &&P)
 
APValue toAPValue () const
 Converts the pointer to an APValue.
 
std::string toDiagnosticString (const ASTContext &Ctx) const
 Converts the pointer to a string usable in diagnostics.
 
unsigned getIntegerRepresentation () const
 
APValue toRValue (const Context &Ctx) const
 Converts the pointer to an APValue that is an rvalue.
 
Pointer atIndex (unsigned 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.
 
DescriptorgetDeclDesc () const
 Accessor for information about the declaration site.
 
SourceLocation getDeclLoc () const
 
Pointer getBase () const
 Returns a pointer to the object of which this pointer is a field.
 
Pointer getArray () const
 Returns the parent array.
 
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 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.
 
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 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 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 isElementPastEnd () const
 Checks if the pointer is an out-of-bounds element pointer.
 
template<typename T >
T & deref () const
 Dereferences the pointer, if it's live.
 
template<typename T >
T & elem (unsigned I) const
 Dereferences a primitive element.
 
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.
 

Friends

class Block
 
class DeadBlock
 

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 65 of file Pointer.h.

Constructor & Destructor Documentation

◆ Pointer() [1/5]

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

Definition at line 71 of file Pointer.h.

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

◆ Pointer() [2/5]

Pointer::Pointer ( Block B)

Definition at line 22 of file Pointer.cpp.

◆ Pointer() [3/5]

Pointer::Pointer ( Block B,
unsigned  BaseAndOffset 
)

Definition at line 24 of file Pointer.cpp.

◆ Pointer() [4/5]

Pointer::Pointer ( const Pointer P)

Definition at line 27 of file Pointer.cpp.

◆ Pointer() [5/5]

Pointer::Pointer ( Pointer &&  P)

Definition at line 29 of file Pointer.cpp.

References P, and clang::interp::Block::replacePointer().

◆ ~Pointer()

Pointer::~Pointer ( )

Member Function Documentation

◆ activate()

void Pointer::activate ( ) const

Activats a field.

Definition at line 208 of file Pointer.cpp.

References clang::interp::InlineDescriptor::IsActive.

◆ 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 114 of file Pointer.h.

References Pointer().

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

◆ atIndex()

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

◆ block()

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

Definition at line 323 of file Pointer.h.

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

◆ compare()

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

Compare two pointers.

Definition at line 366 of file Pointer.h.

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

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

◆ deactivate()

void Pointer::deactivate ( ) const

Deactivates an entire strurcutre.

Definition at line 214 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 353 of file Pointer.h.

References clang::interp::Block::data(), and getNumElems().

◆ elemSize()

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

Returns the element size of the innermost field.

Definition at line 232 of file Pointer.h.

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

Referenced by atIndex(), getIndex(), and getNumElems().

◆ expand()

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

◆ getArray()

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

Returns the parent array.

Definition at line 206 of file Pointer.h.

References 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 196 of file Pointer.h.

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

Referenced by CheckActive(), and toAPValue().

◆ getByteOffset()

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

Returns the byte offset from the start.

Definition at line 316 of file Pointer.h.

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

◆ getDeclDesc()

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

Accessor for information about the declaration site.

Definition at line 192 of file Pointer.h.

References clang::interp::Block::Desc.

Referenced by atIndex(), clang::interp::CallVirt(), clang::interp::CheckExtern(), CheckTemporary(), elemSize(), expand(), getDeclLoc(), getFieldDesc(), isConst(), and toAPValue().

◆ getDeclID()

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

Returns the declaration ID.

Definition at line 313 of file Pointer.h.

References clang::interp::Block::getDeclID().

Referenced by CheckGlobal(), and CheckTemporary().

◆ getDeclLoc()

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

Definition at line 193 of file Pointer.h.

References getDeclDesc(), and clang::interp::Descriptor::getLocation().

Referenced by clang::interp::CheckLive(), and CheckTemporary().

◆ getDeclPtr()

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

Definition at line 229 of file Pointer.h.

References Pointer().

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

◆ getElemRecord()

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

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

Definition at line 278 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 282 of file Pointer.h.

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

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

◆ getFieldDesc()

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

◆ getIndex()

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

◆ getIntegerRepresentation()

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

Definition at line 87 of file Pointer.h.

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

◆ getNumElems()

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

Returns the number of elements.

Definition at line 321 of file Pointer.h.

References elemSize(), and getSize().

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

◆ getOffset()

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

Returns the offset into an array.

Definition at line 241 of file Pointer.h.

References getFieldDesc().

Referenced by getIndex(), and isOnePastEnd().

◆ getRecord()

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

Returns the record descriptor of a class.

Definition at line 276 of file Pointer.h.

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

Referenced by clang::interp::CheckFieldsInitialized(), clang::interp::SetThreeWayComparisonField(), and toRValue().

◆ getSize()

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

Returns the total size of the innermost field.

Definition at line 238 of file Pointer.h.

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

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

◆ 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 222 of file Pointer.cpp.

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

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

◆ hasSameBase()

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

Checks if two pointers are comparable.

Definition at line 218 of file Pointer.cpp.

Referenced by clang::interp::CmpHelper< Pointer >(), clang::interp::CmpHelperEQ< Pointer >(), compare(), and hasSameArray().

◆ inArray()

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

Checks if the innermost field is an array.

Definition at line 261 of file Pointer.h.

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

Referenced by clang::interp::CmpHelperEQ< Pointer >(), 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 263 of file Pointer.h.

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

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

◆ isActive()

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

Checks if the object is active.

Definition at line 303 of file Pointer.h.

References clang::interp::InlineDescriptor::IsActive.

Referenced by CheckActive().

◆ isArrayElement()

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

Checks if the pointer points to an array.

Definition at line 269 of file Pointer.h.

Referenced by 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 258 of file Pointer.h.

References inArray().

Referenced by deref().

◆ isBaseClass()

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

Checks if a structure is a base class.

Definition at line 305 of file Pointer.h.

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

◆ isConst()

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

Checks if an object or a subfield is mutable.

Definition at line 308 of file Pointer.h.

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

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

◆ isElementPastEnd()

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

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

Definition at line 340 of file Pointer.h.

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

◆ isExtern()

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

Checks if the storage is extern.

Definition at line 288 of file Pointer.h.

References clang::interp::Block::isExtern().

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

◆ isField()

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

Checks if the item is a field in an object.

Definition at line 189 of file Pointer.h.

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

◆ isInitialized()

bool Pointer::isInitialized ( ) const

◆ isLive()

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

Checks if the pointer is live.

Definition at line 187 of file Pointer.h.

References clang::interp::Block::IsDead.

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

◆ isMutable()

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

Checks if the field is mutable.

Definition at line 297 of file Pointer.h.

References clang::interp::InlineDescriptor::IsFieldMutable.

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

◆ isOnePastEnd()

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

Checks if the index is one past end.

Definition at line 335 of file Pointer.h.

References getOffset(), getSize(), and isElementPastEnd().

Referenced by clang::interp::CheckRange(), clang::interp::CheckSubobject(), narrow(), and toAPValue().

◆ isRoot()

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

Pointer points directly to a block.

Definition at line 271 of file Pointer.h.

Referenced by clang::interp::CmpHelperEQ< Pointer >().

◆ isStatic()

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

Checks if the storage is static.

Definition at line 290 of file Pointer.h.

References clang::interp::Block::isStatic().

Referenced by CheckGlobal(), initialize(), isInitialized(), and isStaticTemporary().

◆ isStaticTemporary()

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

Checks if the storage is a static temporary.

Definition at line 294 of file Pointer.h.

References isStatic(), and isTemporary().

Referenced by CheckTemporary().

◆ isTemporary()

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

Checks if the storage is temporary.

Definition at line 292 of file Pointer.h.

References clang::interp::Block::isTemporary().

Referenced by clang::interp::CheckLive(), and isStaticTemporary().

◆ 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 265 of file Pointer.h.

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

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

◆ isZero()

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

Checks if the pointer is null.

Definition at line 185 of file Pointer.h.

Referenced by clang::interp::CheckLive(), clang::interp::CheckNull(), clang::interp::CmpHelperEQ< Pointer >(), narrow(), and toAPValue().

◆ narrow()

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

◆ operator=() [1/2]

void Pointer::operator= ( const Pointer P)

◆ operator=() [2/2]

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

◆ print()

void clang::interp::Pointer::print ( llvm::raw_ostream &  OS) const
inline

Prints the pointer.

Definition at line 384 of file Pointer.h.

◆ toAPValue()

APValue Pointer::toAPValue ( ) const

◆ toDiagnosticString()

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

Converts the pointer to a string usable in diagnostics.

Definition at line 153 of file Pointer.cpp.

References clang::APValue::getAsString(), getType(), and toAPValue().

Referenced by clang::interp::CmpHelper< Pointer >().

◆ toRValue()

APValue Pointer::toRValue ( const Context Ctx) const

Friends And Related Function Documentation

◆ Block

friend class Block
friend

Definition at line 404 of file Pointer.h.

◆ DeadBlock

friend class DeadBlock
friend

Definition at line 405 of file Pointer.h.


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