clang: lib/AST/ByteCode/Pointer.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_CLANG_AST_INTERP_POINTER_H

14#define LLVM_CLANG_AST_INTERP_POINTER_H

15

23#include "llvm/Support/raw_ostream.h"

24

26namespace interp {

28class DeadBlock;

30class Context;

31template <unsigned A, bool B> class Integral;

33

35inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Pointer &P);

36

38

40

42};

43

47

50};

51

55};

56

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

89private:

90 static constexpr unsigned PastEndMark = ~0u;

91 static constexpr unsigned RootPtrMark = ~0u;

92

93public:

96 PointeeStorage.Int.Value = 0;

97 PointeeStorage.Int.Desc = nullptr;

98 }

100 PointeeStorage.Int = std::move(IntPtr);

101 }

107 : Offset(Offset), StorageKind(Storage::Int) {

108 PointeeStorage.Int.Value = Address;

109 PointeeStorage.Int.Desc = Desc;

110 }

112 : Offset(Offset), StorageKind(Storage::Fn) {

114 }

115 Pointer(const Type *TypePtr, const Type *TypeInfoType, uint64_t Offset = 0)

117 PointeeStorage.Typeid.TypePtr = TypePtr;

118 PointeeStorage.Typeid.TypeInfoType = TypeInfoType;

119 }

122

125

126

128 if (P.StorageKind != StorageKind)

129 return false;

132 Offset == P.Offset;

133

137 Offset == P.Offset;

138 }

139

141

142

144

145

147

154 }

155

156

159

160

166

170 uint64_t Off = Idx * elemSize();

173 else

177 }

178

179

182 unsigned Field = Offset + Off;

184 }

185

186

187

189 assert(Offset >= Off);

190 unsigned O = Offset - Off;

192 }

193

194

197 return *this;

199

201 return *this;

202

203

206 Offset == 0 ? Offset : PastEndMark);

207

208

211 PastEndMark);

212

213

214

215

216

219 return *this;

222 }

223

224

227

228

230 return *this;

231

234 }

235

236

240

242

243 unsigned Adjust;

246 else

250 }

251

252

254 return *this;

255

258

259

264 : getDescriptor(Next)->Desc;

266 return *this;

267 return Pointer(Pointee, Next, Offset);

268 }

269

270

277 return false;

280 }

281

284 return true;

286 }

287

290 return false;

291

293 }

294

295

300 return nullptr;

301

305 }

307

308

315 }

318 }

319

320

323 assert(Offset == PastEndMark && "cannot get base of a block");

325 }

328 }

329

332 assert(Offset != 0 && Offset != PastEndMark && "not an array element");

334 }

338 }

339

340

344

347 return getInlineDesc()->Desc;

348 }

349

350

353 return QualType(PointeeStorage.Typeid.TypeInfoType, 0);

354

356

357

359 return AT->getElementType();

361 return CT->getElementType();

363 return CT->getElementType();

364 }

366 }

367

370 }

371

372

376 return 1;

378 }

379

383 }

384

388 }

389

390

392 assert(Offset != PastEndMark && "invalid offset");

395 return Offset;

396

397 unsigned Adjust = 0;

401 else

403 }

405 }

406

407

408

411 }

412

413

417 return false;

418 }

421 return getInlineDesc()->InUnion;

422 return false;

423 };

424

425

429 return false;

430 }

431

434 return false;

436 }

437

440 return false;

441

444 return true;

445

446

447

449 return true;

450

451 return false;

452 }

453

456 return true;

458 asBlockPointer().Pointee->getDescriptor()->getMetadataSize() ||

460 }

461

464 return false;

465

467 }

468

471 return PointeeStorage.BS;

472 }

475 return PointeeStorage.Int;

476 }

479 return PointeeStorage.Fn;

480 }

481

486

487

489

492 return ElemDesc ? ElemDesc->ElemRecord : nullptr;

493 }

494

496

497

499

500

504 return false;

505 }

506

509 return true;

512 }

513

518 }

519 return false;

520 }

521

526 }

527 return false;

528 }

529

531

532

535 return false;

537 }

538

541 return false;

542

545 }

546

548

551 return true;

553 }

554

558 }

559

562 return false;

563

565 return false;

566

568 }

569

570

573 return true;

575 }

576

577

582 }

583 return std::nullopt;

584 }

585

586

591 return PastEndMark;

592 return Offset;

593 }

594

595

598 return ~0u;

600 }

601

603

604

608

610 return 0;

611

612

615 return 0;

616

617 if (auto ElemSize = elemSize())

619 return 0;

620 }

621

622

625 return false;

626

628 return false;

629

631 return false;

632

635 }

636

637

640 return false;

641

642 return isZero() && Offset > PointeeStorage.BS.Pointee->getSize();

643 }

644

645

647

648

651 return false;

653 return Desc->isZeroSizeArray();

654 return false;

655 }

656

657

658 template T &deref() const {

659 assert(isLive() && "Invalid pointer");

663 assert(Offset + sizeof(T) <=

664 asBlockPointer().Pointee->getDescriptor()->getAllocSize());

665

669

671 }

672

673

674

677 return false;

679 return false;

680

681 return true;

682 }

683

684

686

688

690

691

695

696 if (Offset < Other.Offset)

698 else if (Offset > Other.Offset)

700

702 }

703

704

706

708

710

711

712

714

715

716 void print(llvm::raw_ostream &OS) const;

717

718private:

725

726

733 }

734

735

737 assert(Offset != 0 && "Not a nested pointer");

742 1;

743 }

744

745

751 }

752

753

754 uint64_t Offset = 0;

755

756

758

760

761 union {

766 } PointeeStorage;

768};

769

771 P.print(OS);

772 return OS;

773}

774

775}

776}

777

778#endif

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

Represents a member of a struct/union/class.

A (possibly-)qualified type.

Encodes a location in the source.

The base class of the type hierarchy.

A memory block, either on the stack or in the heap.

bool isExtern() const

Checks if the block is extern.

const Descriptor * getDescriptor() const

Returns the block's descriptor.

bool isStatic() const

Checks if the block has static storage duration.

bool isTemporary() const

Checks if the block is temporary.

std::byte * rawData()

Returns a pointer to the raw data, including metadata.

std::optional< unsigned > getDeclID() const

Returns the declaration ID.

Holds all information required to evaluate constexpr code in a module.

Descriptor for a dead block.

Manages dynamic memory allocations done during bytecode interpretation.

const Function * getFunction() const

uint64_t getIntegerRepresentation() const

const FunctionDecl * getDecl() const

Returns the original FunctionDecl.

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 isDynamic() const

Checks if the storage has been dynamically allocated.

bool isZeroSizeArray() const

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

Pointer atIndex(uint64_t Idx) const

Offsets a pointer inside an array.

bool isDummy() const

Checks if the pointer points to a dummy value.

Pointer atFieldSub(unsigned Off) const

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

bool inPrimitiveArray() const

Checks if the structure is a primitive array.

void print(llvm::raw_ostream &OS) const

Prints the pointer.

bool isExtern() const

Checks if the storage is extern.

int64_t getIndex() const

Returns the index into 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.

Pointer(IntPointer &&IntPtr)

bool isMutable() const

Checks if the field is mutable.

DeclTy getSource() const

Returns the expression or declaration the pointer has been created for.

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)

bool isIntegralPointer() const

QualType getType() const

Returns the type of the innermost field.

bool operator==(const Pointer &P) const

Equality operators are just for tests.

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.

Pointer(const Type *TypePtr, const Type *TypeInfoType, uint64_t Offset=0)

bool pointsToLiteral() const

Whether this points to a block that's been created for a "literal lvalue", i.e.

Pointer(uint64_t Address, const Descriptor *Desc, uint64_t Offset=0)

Pointer getBase() const

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

uint64_t getByteOffset() const

Returns the byte offset from the start.

bool isTypeidPointer() const

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

Converts the pointer to a string usable in diagnostics.

bool isZero() const

Checks if the pointer is null.

ComparisonCategoryResult compare(const Pointer &Other) const

Compare two pointers.

const IntPointer & asIntPointer() const

bool isRoot() const

Pointer points directly to a block.

const Descriptor * getDeclDesc() const

Accessor for information about the declaration site.

const Record * getElemRecord() const

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

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

Checks if both given pointers point to the same block.

APValue toAPValue(const ASTContext &ASTCtx) const

Converts the pointer to an APValue.

unsigned getOffset() const

Returns the offset into an array.

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.

uint64_t getIntegerRepresentation() const

bool isPastEnd() const

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

Pointer(const Function *F, uint64_t Offset=0)

const FieldDecl * getField() const

Returns the field information.

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.

bool isDereferencable() const

Whether this block can be read from at all.

bool isBlockPointer() const

bool operator!=(const Pointer &P) const

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

Converts the pointer to an APValue that is an rvalue.

size_t getSize() const

Returns the total size of the innermost field.

bool isTemporary() const

Checks if the storage is temporary.

const FunctionPointer & asFunctionPointer() const

SourceLocation getDeclLoc() const

const Block * block() const

bool isFunctionPointer() const

Pointer getDeclPtr() const

const Descriptor * getFieldDesc() const

Accessors for information about the innermost field.

bool isVirtualBaseClass() const

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.

bool canBeInitialized() const

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

const BlockPointer & asBlockPointer() const

void initialize() const

Initializes a field.

bool isField() const

Checks if the item is a field in an object.

const Record * getRecord() const

Returns the record descriptor of a class.

Structure/Class descriptor.

std::optional< std::pair< bool, std::shared_ptr< InitMap > > > InitMapPtr

PrimType

Enumeration of the primitive types of the VM.

llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)

llvm::PointerUnion< const Decl *, const Expr * > DeclTy

The JSON file list parser is used to communicate input to InstallAPI.

ComparisonCategoryResult

An enumeration representing the possible results of a three-way comparison.

const FunctionProtoType * T

@ Other

Other implicit parameter.

unsigned Base

Start of the current subfield.

Block * Pointee

The block the pointer is pointing to.

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.

const DeclTy & getSource() const

const Decl * asDecl() const

const Descriptor *const ElemDesc

Descriptor of the array element.

bool isDummy() const

Checks if this is a dummy descriptor.

unsigned getMetadataSize() const

Returns the size of the 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.

bool isPrimitiveArray() const

Checks if the descriptor is of an array of primitives.

const FieldDecl * asFieldDecl() const

const Record *const ElemRecord

Pointer to the record, if block contains records.

Descriptor used for global variables.

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 IsVirtualBase

Flag inidcating if the field is a virtual base class.

unsigned InUnion

Flat indicating if this field is in a union (even if nested).

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).

IntPointer baseCast(const ASTContext &ASTCtx, unsigned BaseOffset) const

IntPointer atOffset(const ASTContext &ASTCtx, unsigned Offset) const

const Type * TypeInfoType