13#ifndef LLVM_CLANG_AST_INTERP_INTERPSTATE_H
14#define LLVM_CLANG_AST_INTERP_INTERPSTATE_H
68 return Parent.getEvalStatus();
72 return Ctx.getASTContext().getLangOpts();
77 return Parent.keepEvaluatingAfterFailure();
80 return Parent.keepEvaluatingAfterSideEffect();
83 return Parent.noteUndefinedBehavior();
88 Parent.setActiveDiagnostic(Flag);
91 Parent.setFoldFailureDiagnostic(Flag);
102 return M->getSource(F, PC);
104 assert(F &&
"Function cannot be null");
114 Alloc = std::make_unique<DynamicAllocator>();
127 void *
allocate(
size_t Size,
unsigned Align = 8)
const {
136 template <
typename T>
T allocAP(
unsigned BitWidth) {
137 unsigned NumWords = APInt::getNumWords(BitWidth);
140 uint64_t *Mem = (uint64_t *)this->
allocate(NumWords *
sizeof(uint64_t));
142 return T(Mem, BitWidth);
147 return Floating(llvm::APFloatBase::SemanticsToEnum(Sem));
150 APInt::getNumWords(llvm::APFloatBase::getSizeInBits(Sem));
151 uint64_t *Mem = (uint64_t *)this->
allocate(NumWords *
sizeof(uint64_t));
153 return Floating(Mem, llvm::APFloatBase::SemanticsToEnum(Sem));
166 std::unique_ptr<DynamicAllocator> Alloc;
189 std::pair<const Expr *, const LifetimeExtendedTemporaryDecl *>>
196 mutable std::optional<llvm::BumpPtrAllocator>
Allocator;
202 : Ctx(Ctx), OldCC(Ctx.ConstantContextOverride) {
206 Ctx.ConstantContextOverride =
Value;
210 Ctx.ConstantContextOverride = OldCC;
216 std::optional<bool> OldCC;
Implements a partial diagnostic which may not be emitted.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
This represents one expression.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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.
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.
Base class for stack frames, shared between VM and walker.
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Frame storing local variables.
Stack frame storing temporaries and parameters.
InterpStateCCOverride(InterpState &Ctx, bool Value)
const Frame * getBottomFrame() const override
SmallVectorImpl< PartialDiagnosticAt > * PrevDiags
Things needed to do speculative execution.
std::optional< llvm::BumpPtrAllocator > Allocator
unsigned getCallStackDepth() override
Expr::EvalStatus & getEvalStatus() const override
InterpFrame BottomFrame
Bottom function frame.
Context & getContext() const
bool keepEvaluatingAfterFailure() const override
bool noteUndefinedBehavior() override
DynamicAllocator & getAllocator()
Context & Ctx
Interpreter Context.
void * allocate(size_t Size, unsigned Align=8) const
Floating allocFloat(const llvm::fltSemantics &Sem)
llvm::SmallVector< const Block * > InitializingBlocks
List of blocks we're currently running either constructors or destructors for.
ASTContext & getASTContext() const override
SourceInfo getSource(const Function *F, CodePtr PC) const override
Delegates source mapping to the mapper.
Frame * getCurrentFrame() override
InterpState(const InterpState &)=delete
llvm::SmallVector< std::pair< const Expr *, const LifetimeExtendedTemporaryDecl * > > SeenGlobalTemporaries
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 keepEvaluatingAfterSideEffect() const override
bool noteSideEffect() override
const VarDecl * EvaluatingDecl
Declaration we're initializing/evaluting, if any.
InterpFrame * Current
The current frame.
InterpState(State &Parent, Program &P, InterpStack &Stk, Context &Ctx, SourceMapper *M=nullptr)
bool hasActiveDiagnostic() override
std::optional< bool > ConstantContextOverride
void setActiveDiagnostic(bool Flag) override
void setFoldFailureDiagnostic(bool Flag) override
InterpState & operator=(const InterpState &)=delete
friend class InterpStateCCOverride
T * allocate(size_t Num=1) const
void deallocate(Block *B)
Deallocates a pointer.
T allocAP(unsigned BitWidth)
const LangOptions & getLangOpts() const
void setEvalLocation(SourceLocation SL)
unsigned SpeculationDepth
friend class EvaluationResult
StdAllocatorCaller getStdAllocatorCaller(StringRef Name) const
bool inConstantContext() const
bool hasPriorDiagnostic() override
Program & P
Reference to the module containing all bytecode.
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.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * 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...