clang 17.0.0git
Go to the documentation of this file.
1//===--- InterpState.h - Interpreter state for the constexpr VM -*- C++ -*-===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9// Definition of the interpreter state and entry point.
16#include "Context.h"
17#include "Function.h"
18#include "InterpStack.h"
19#include "State.h"
20#include "clang/AST/APValue.h"
22#include "clang/AST/Expr.h"
25namespace clang {
26namespace interp {
27class Context;
28class Function;
29class InterpStack;
30class InterpFrame;
31class SourceMapper;
33/// Interpreter context.
34class InterpState final : public State, public SourceMapper {
37 SourceMapper *M = nullptr);
41 // Stack frame accessors.
42 Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
43 Frame *getCurrentFrame() override;
44 unsigned getCallStackDepth() override { return CallStackDepth; }
45 const Frame *getBottomFrame() const override {
46 return Parent.getBottomFrame();
47 }
49 // Access objects from the walker context.
50 Expr::EvalStatus &getEvalStatus() const override {
51 return Parent.getEvalStatus();
52 }
53 ASTContext &getCtx() const override { return Parent.getCtx(); }
55 // Forward status checks and updates to the walker.
56 bool checkingForUndefinedBehavior() const override {
57 return Parent.checkingForUndefinedBehavior();
58 }
59 bool keepEvaluatingAfterFailure() const override {
60 return Parent.keepEvaluatingAfterFailure();
61 }
63 return Parent.checkingPotentialConstantExpression();
64 }
65 bool noteUndefinedBehavior() override {
66 return Parent.noteUndefinedBehavior();
67 }
68 bool inConstantContext() const { return Parent.InConstantContext; }
69 bool hasActiveDiagnostic() override { return Parent.hasActiveDiagnostic(); }
70 void setActiveDiagnostic(bool Flag) override {
71 Parent.setActiveDiagnostic(Flag);
72 }
73 void setFoldFailureDiagnostic(bool Flag) override {
74 Parent.setFoldFailureDiagnostic(Flag);
75 }
76 bool hasPriorDiagnostic() override { return Parent.hasPriorDiagnostic(); }
78 /// Reports overflow and return true if evaluation should continue.
79 bool reportOverflow(const Expr *E, const llvm::APSInt &Value);
81 /// Deallocates a pointer.
82 void deallocate(Block *B);
84 /// Delegates source mapping to the mapper.
85 SourceInfo getSource(const Function *F, CodePtr PC) const override {
86 return M ? M->getSource(F, PC) : F->getSource(PC);
87 }
90 /// AST Walker state.
92 /// Dead block chain.
93 DeadBlock *DeadBlocks = nullptr;
94 /// Reference to the offset-source mapping.
95 SourceMapper *M;
98 /// Reference to the module containing all bytecode.
100 /// Temporary stack.
102 /// Interpreter Context.
104 /// The current frame.
106 /// Call stack depth.
110} // namespace interp
111} // namespace clang
NodeId Parent
Definition: ASTDiff.cpp:191
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 ...
Definition: ASTContext.h:182
This represents one expression.
Definition: Expr.h:110
A memory block, either on the stack or in the heap.
Definition: InterpBlock.h:49
Pointer into the code segment.
Definition: Source.h:26
Holds all information required to evaluate constexpr code in a module.
Definition: Context.h:35
Descriptor for a dead block.
Definition: InterpBlock.h:147
Base class for stack frames, shared between VM and walker.
Definition: Frame.h:25
Bytecode function.
Definition: Function.h:74
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Definition: Function.cpp:32
Frame storing local variables.
Definition: InterpFrame.h:29
Stack frame storing temporaries and parameters.
Definition: InterpStack.h:24
Interpreter context.
Definition: InterpState.h:34
const Frame * getBottomFrame() const override
Definition: InterpState.h:45
unsigned getCallStackDepth() override
Definition: InterpState.h:44
Expr::EvalStatus & getEvalStatus() const override
Definition: InterpState.h:50
bool keepEvaluatingAfterFailure() const override
Definition: InterpState.h:59
bool reportOverflow(const Expr *E, const llvm::APSInt &Value)
Reports overflow and return true if evaluation should continue.
Definition: InterpState.cpp:51
bool noteUndefinedBehavior() override
Definition: InterpState.h:65
Context & Ctx
Interpreter Context.
Definition: InterpState.h:103
SourceInfo getSource(const Function *F, CodePtr PC) const override
Delegates source mapping to the mapper.
Definition: InterpState.h:85
unsigned CallStackDepth
Call stack depth.
Definition: InterpState.h:107
Frame * getCurrentFrame() override
Definition: InterpState.cpp:43
InterpStack & Stk
Temporary stack.
Definition: InterpState.h:101
bool inConstantContext() const
Definition: InterpState.h:68
InterpFrame * Current
The current frame.
Definition: InterpState.h:105
bool hasActiveDiagnostic() override
Definition: InterpState.h:69
void setActiveDiagnostic(bool Flag) override
Definition: InterpState.h:70
bool checkingForUndefinedBehavior() const override
Definition: InterpState.h:56
void setFoldFailureDiagnostic(bool Flag) override
Definition: InterpState.h:73
void deallocate(Block *B)
Deallocates a pointer.
Definition: InterpState.cpp:57
ASTContext & getCtx() const override
Definition: InterpState.h:53
bool checkingPotentialConstantExpression() const override
Definition: InterpState.h:62
bool hasPriorDiagnostic() override
Definition: InterpState.h:76
Program & P
Reference to the module containing all bytecode.
Definition: InterpState.h:99
The program contains and links the bytecode for all functions.
Definition: Program.h:40
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:70
Interface for classes which map locations to sources.
Definition: Source.h:91
virtual SourceInfo getSource(const Function *F, CodePtr PC) const =0
Returns source information for a given PC in a function.
Interface for the VM to interact with the AST walker's context.
Definition: State.h:55
EvalStatus is a struct with detailed info about an evaluation in progress.
Definition: Expr.h:593