13#ifndef LLVM_CLANG_AST_INTERP_INTERPSTATE_H
14#define LLVM_CLANG_AST_INTERP_INTERPSTATE_H
89 Alloc = std::make_unique<DynamicAllocator>(*Allocator);
102 void *
allocate(
size_t Size,
unsigned Align = 8)
const {
105 return Allocator->Allocate(Size, Align);
111 template <
typename T>
T allocAP(
unsigned BitWidth) {
112 unsigned NumWords = APInt::getNumWords(BitWidth);
115 uint64_t *Mem = (uint64_t *)this->
allocate(NumWords *
sizeof(uint64_t));
117 return T(Mem, BitWidth);
122 return Floating(llvm::APFloatBase::SemanticsToEnum(Sem));
125 APInt::getNumWords(llvm::APFloatBase::getSizeInBits(Sem));
126 uint64_t *Mem = (uint64_t *)this->
allocate(NumWords *
sizeof(uint64_t));
128 return Floating(Mem, llvm::APFloatBase::SemanticsToEnum(Sem));
152 PP[NewLength - 1] = NewEntry;
166 return diagnoseStepLimitExceeded(OpPC);
204 template <
typename... Ts>
207 assert(FrameSize < std::numeric_limits<unsigned>::max());
208 InterpFrame *NewFrame =
new (FrameAlloc.reserve(FrameSize))
221 FrameAlloc.pop(CurrentSize);
233 mutable std::optional<llvm::BumpPtrAllocator> Allocator;
235 std::unique_ptr<DynamicAllocator> Alloc;
237 bool diagnoseStepLimitExceeded(
CodePtr OpPC);
279 std::pair<const Expr *, const LifetimeExtendedTemporaryDecl *>>
290 : Ctx(Ctx), OldCC(Ctx.ConstantContextOverride) {
294 Ctx.ConstantContextOverride =
Value;
298 Ctx.ConstantContextOverride = OldCC;
304 std::optional<bool> OldCC;
Represents a C++ struct/union/class.
This represents one expression.
A (possibly-)qualified type.
Encodes a location in the source.
Represents a variable declaration or definition.
A memory block, either on the stack or in the heap.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
unsigned getEvalID() const
The Evaluation ID this block was created in.
Pointer into the code segment.
Holds all information required to evaluate constexpr code in a module.
Descriptor for a dead block.
Manages dynamic memory allocations done during bytecode interpretation.
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
Allocator for function frames.
Base class for stack frames, shared between VM and walker.
Frame storing local variables.
static size_t allocSize(const Function *F)
Returns the number of bytes needed to allocate an InterpFrame for the given function.
Stack frame storing temporaries and parameters.
InterpStateCCOverride(InterpState &Ctx, bool Value)
SmallVectorImpl< PartialDiagnosticAt > * PrevDiags
Things needed to do speculative execution.
bool lifetimeStartedInEvaluation(const Block *B) const
unsigned getCallStackDepth() override
InterpFrame BottomFrame
Bottom function frame.
Context & getContext() const
bool initializingBlock(const Block *B) const
DynamicAllocator & getAllocator()
void resetCurrentFrame()
Free resources associated with the current frame and set the caller to be the new current frame.
InterpState(const State &Parent, Program &P, InterpStack &Stk, FrameAllocator &FrameAlloc, Context &Ctx, SourceMapper *M=nullptr)
Context & Ctx
Interpreter Context.
void * allocate(size_t Size, unsigned Align=8) const
Floating allocFloat(const llvm::fltSemantics &Sem)
const unsigned EvalID
ID identifying this evaluation.
bool noteStep(CodePtr OpPC)
Note that a step has been executed.
SourceInfo getSource(CodePtr PC) const
Delegates source mapping to the mapper.
InterpState(const InterpState &)=delete
bool stepsLeft() const override
llvm::SmallVector< std::pair< const Expr *, const LifetimeExtendedTemporaryDecl * > > SeenGlobalTemporaries
InterpFrame * allocFrame(const Function *F, Ts &&...Args)
Allocate memory and create a new InterpFrame for the given function.
InterpStack & Stk
Temporary stack.
bool maybeDiagnoseDanglingAllocations()
Diagnose any dynamic allocations that haven't been freed yet.
SourceLocation EvalLocation
Source location of the evaluating expression.
bool checkingConstantDestruction() const
Return if we're checking if a global variable has a constant destructor.
unsigned StepsLeft
Steps left during evaluation.
const VarDecl * EvaluatingDecl
Declaration we're initializing/evaluting, if any.
bool checkingConstantDestruction(const Pointer &Ptr) const
Return if we're checking if a global variable has a constant destructor and the given pointer is poin...
InterpFrame * Current
The current frame.
PointerPathEntry * allocPointerPath(unsigned Length, const PointerPathEntry *OldPP)
const CXXRecordDecl ** allocMemberPointerPath(unsigned Length)
const Frame * getCurrentFrame() override
std::optional< bool > ConstantContextOverride
const bool InfiniteSteps
Whether infinite evaluation steps have been requested.
InterpState & operator=(const InterpState &)=delete
friend class InterpStateCCOverride
T * allocate(size_t Num=1) const
void deallocate(Block *B)
Deallocates a pointer.
PointerPathEntry * extendPointerPath(unsigned NewLength, const PointerPathEntry *OldPP, PointerPathEntry NewEntry)
Allocate a new pointer path of Length NewLength.
llvm::SmallVector< PtrView > InitializingPtrs
List of blocks we're currently running either constructors or destructors for.
T allocAP(unsigned BitWidth)
void setEvalLocation(SourceLocation SL)
unsigned SpeculationDepth
friend class EvaluationResult
StdAllocatorCaller getStdAllocatorCaller(StringRef Name) const
bool checkingConstantDestruction(const VarDecl *VD) const
bool inConstantContext() const
Program & P
Reference to the module containing all bytecode.
A pointer to a memory block, live or dead.
The program contains and links the bytecode for all functions.
Describes the statement/declaration an opcode was generated from.
Interface for classes which map locations to sources.
Expr::EvalStatus & getEvalStatus() const
State(ASTContext &ASTCtx, Expr::EvalStatus &EvalStatus)
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
EvalStatus is a struct with detailed info about an evaluation in progress.
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
const VarDecl * asVarDecl() const