diff options
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpBlock.h')
-rw-r--r-- | clang/lib/AST/ByteCode/InterpBlock.h | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBlock.h b/clang/lib/AST/ByteCode/InterpBlock.h index 5162223..7ded1e8 100644 --- a/clang/lib/AST/ByteCode/InterpBlock.h +++ b/clang/lib/AST/ByteCode/InterpBlock.h @@ -42,21 +42,32 @@ enum PrimType : unsigned; /// the data size and the metadata size. /// class Block final { +private: + static constexpr uint8_t ExternFlag = 1 << 0; + static constexpr uint8_t DeadFlag = 1 << 1; + static constexpr uint8_t WeakFlag = 1 << 2; + static constexpr uint8_t DummyFlag = 1 << 3; + public: /// Creates a new block. Block(unsigned EvalID, const std::optional<unsigned> &DeclID, const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false, - bool IsWeak = false) - : EvalID(EvalID), DeclID(DeclID), IsStatic(IsStatic), IsExtern(IsExtern), - IsDynamic(false), IsWeak(IsWeak), Desc(Desc) { + bool IsWeak = false, bool IsDummy = false) + : Desc(Desc), DeclID(DeclID), EvalID(EvalID), IsStatic(IsStatic) { assert(Desc); + AccessFlags |= (ExternFlag * IsExtern); + AccessFlags |= (WeakFlag * IsWeak); + AccessFlags |= (DummyFlag * IsDummy); } Block(unsigned EvalID, const Descriptor *Desc, bool IsStatic = false, - bool IsExtern = false, bool IsWeak = false) - : EvalID(EvalID), DeclID((unsigned)-1), IsStatic(IsStatic), - IsExtern(IsExtern), IsDynamic(false), IsWeak(IsWeak), Desc(Desc) { + bool IsExtern = false, bool IsWeak = false, bool IsDummy = false) + : Desc(Desc), DeclID((unsigned)-1), EvalID(EvalID), IsStatic(IsStatic), + IsDynamic(false) { assert(Desc); + AccessFlags |= (ExternFlag * IsExtern); + AccessFlags |= (WeakFlag * IsWeak); + AccessFlags |= (DummyFlag * IsDummy); } /// Returns the block's descriptor. @@ -64,13 +75,15 @@ public: /// Checks if the block has any live pointers. bool hasPointers() const { return Pointers; } /// Checks if the block is extern. - bool isExtern() const { return IsExtern; } + bool isExtern() const { return AccessFlags & ExternFlag; } /// Checks if the block has static storage duration. bool isStatic() const { return IsStatic; } /// Checks if the block is temporary. bool isTemporary() const { return Desc->IsTemporary; } - bool isWeak() const { return IsWeak; } + bool isWeak() const { return AccessFlags & WeakFlag; } bool isDynamic() const { return IsDynamic; } + bool isDummy() const { return AccessFlags & DummyFlag; } + bool isDead() const { return AccessFlags & DeadFlag; } /// Returns the size of the block. unsigned getSize() const { return Desc->getAllocSize(); } /// Returns the declaration ID. @@ -103,6 +116,10 @@ public: return reinterpret_cast<const std::byte *>(this) + sizeof(Block); } + template <typename T> T deref() const { + return *reinterpret_cast<const T *>(data()); + } + /// Invokes the constructor. void invokeCtor() { assert(!IsInitialized); @@ -126,6 +143,8 @@ public: void dump() const { dump(llvm::errs()); } void dump(llvm::raw_ostream &OS) const; + bool isAccessible() const { return AccessFlags == 0; } + private: friend class Pointer; friend class DeadBlock; @@ -133,10 +152,13 @@ private: friend class DynamicAllocator; Block(unsigned EvalID, const Descriptor *Desc, bool IsExtern, bool IsStatic, - bool IsWeak, bool IsDead) - : EvalID(EvalID), IsStatic(IsStatic), IsExtern(IsExtern), IsDead(true), - IsDynamic(false), IsWeak(IsWeak), Desc(Desc) { + bool IsWeak, bool IsDummy, bool IsDead) + : Desc(Desc), EvalID(EvalID), IsStatic(IsStatic) { assert(Desc); + AccessFlags |= (ExternFlag * IsExtern); + AccessFlags |= (DeadFlag * IsDead); + AccessFlags |= (WeakFlag * IsWeak); + AccessFlags |= (DummyFlag * IsDummy); } /// Deletes a dead block at the end of its lifetime. @@ -150,27 +172,23 @@ private: bool hasPointer(const Pointer *P) const; #endif - const unsigned EvalID = ~0u; + /// Pointer to the stack slot descriptor. + const Descriptor *Desc; /// Start of the chain of pointers. Pointer *Pointers = nullptr; /// Unique identifier of the declaration. std::optional<unsigned> DeclID; + const unsigned EvalID = ~0u; /// Flag indicating if the block has static storage duration. bool IsStatic = false; - /// Flag indicating if the block is an extern. - bool IsExtern = false; - /// Flag indicating if the pointer is dead. This is only ever - /// set once, when converting the Block to a DeadBlock. - bool IsDead = false; /// Flag indicating if the block contents have been initialized /// via invokeCtor. bool IsInitialized = false; /// Flag indicating if this block has been allocated via dynamic /// memory allocation (e.g. malloc). bool IsDynamic = false; - bool IsWeak = false; - /// Pointer to the stack slot descriptor. - const Descriptor *Desc; + /// AccessFlags containing IsExtern, IsDead, IsWeak, and IsDummy bits. + uint8_t AccessFlags = 0; }; /// Descriptor for a dead block. |