clang 22.0.0git
clang::interp::Context Class Referencefinal

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

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/AST/ByteCode/Context.h"

Public Member Functions

 Context (ASTContext &Ctx)
 Initialises the constexpr VM.
 ~Context ()
 Cleans up the constexpr VM.
bool isPotentialConstantExpr (State &Parent, const FunctionDecl *FD)
 Checks if a function is a potential constant expression.
void isPotentialConstantExprUnevaluated (State &Parent, const Expr *E, const FunctionDecl *FD)
bool evaluateAsRValue (State &Parent, const Expr *E, APValue &Result)
 Evaluates a toplevel expression as an rvalue.
bool evaluate (State &Parent, const Expr *E, APValue &Result, ConstantExprKind Kind)
 Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion.
bool evaluateAsInitializer (State &Parent, const VarDecl *VD, const Expr *Init, APValue &Result)
 Evaluates a toplevel initializer.
bool evaluateCharRange (State &Parent, const Expr *SizeExpr, const Expr *PtrExpr, APValue &Result)
bool evaluateCharRange (State &Parent, const Expr *SizeExpr, const Expr *PtrExpr, std::string &Result)
bool evaluateStrlen (State &Parent, const Expr *E, uint64_t &Result)
 Evalute.
ASTContextgetASTContext () const
 Returns the AST context.
const LangOptionsgetLangOpts () const
 Returns the language options.
unsigned getCharBit () const
 Returns CHAR_BIT.
const llvm::fltSemantics & getFloatSemantics (QualType T) const
 Return the floating-point semantics for T.
uint32_t getBitWidth (QualType T) const
 Return the size of T in bits.
OptPrimType classify (QualType T) const
 Classifies a type.
OptPrimType classify (const Expr *E) const
 Classifies an expression.
bool canClassify (QualType T)
bool canClassify (const Expr *E)
const CXXMethodDeclgetOverridingFunction (const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const
const FunctiongetOrCreateFunction (const FunctionDecl *FuncDecl)
const FunctiongetOrCreateObjCBlock (const BlockExpr *E)
ProgramgetProgram () const
 Returns the program. This is only needed for unittests.
unsigned collectBaseOffset (const RecordDecl *BaseDecl, const RecordDecl *DerivedDecl) const
const RecordgetRecord (const RecordDecl *D) const
unsigned getEvalID () const

Static Public Member Functions

static bool shouldBeGloballyIndexed (const ValueDecl *VD)
 Returns whether we should create a global variable for the given ValueDecl.
static bool isUnevaluatedBuiltin (unsigned ID)
 Unevaluated builtins don't get their arguments put on the stack automatically.

Detailed Description

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

Definition at line 41 of file Context.h.

Constructor & Destructor Documentation

◆ Context()

Context::Context ( ASTContext & Ctx)

Initialises the constexpr VM.

Definition at line 25 of file Context.cpp.

References Context().

Referenced by Context().

◆ ~Context()

Context::~Context ( )

Cleans up the constexpr VM.

Definition at line 34 of file Context.cpp.

Member Function Documentation

◆ canClassify() [1/2]

bool clang::interp::Context::canClassify ( const Expr * E)
inline

Definition at line 110 of file Context.h.

References canClassify(), clang::Expr::getType(), and clang::Expr::isGLValue().

◆ canClassify() [2/2]

bool clang::interp::Context::canClassify ( QualType T)
inline

Definition at line 97 of file Context.h.

References classify(), and clang::T.

Referenced by canClassify(), clang::interp::CheckArrayInitialized(), and getOrCreateFunction().

◆ classify() [1/2]

OptPrimType clang::interp::Context::classify ( const Expr * E) const
inline

Classifies an expression.

Definition at line 89 of file Context.h.

References classify(), clang::Expr::getType(), clang::Expr::isGLValue(), and clang::interp::PT_Ptr.

◆ classify() [2/2]

OptPrimType Context::classify ( QualType T) const

Classifies a type.

Definition at line 310 of file Context.cpp.

References classify(), integralTypeToPrimTypeS(), integralTypeToPrimTypeU(), clang::interp::PT_Bool, clang::interp::PT_FixedPoint, clang::interp::PT_Float, clang::interp::PT_MemberPtr, clang::interp::PT_Ptr, and clang::T.

Referenced by clang::interp::CallPtr(), canClassify(), clang::interp::CheckNonNullArgs(), classify(), classify(), clang::interp::copyRecord(), enumerateData(), getOrCreateFunction(), getOrCreateObjCBlock(), clang::interp::interp__builtin_abs(), clang::interp::interp__builtin_addressof(), clang::interp::interp__builtin_assume(), clang::interp::interp__builtin_assume_aligned(), clang::interp::interp__builtin_atomic_lock_free(), clang::interp::interp__builtin_bitreverse(), clang::interp::interp__builtin_blend(), clang::interp::interp__builtin_bswap(), clang::interp::interp__builtin_c11_atomic_is_lock_free(), clang::interp::interp__builtin_carryop(), clang::interp::interp__builtin_clrsb(), clang::interp::interp__builtin_clz(), clang::interp::interp__builtin_ctz(), clang::interp::interp__builtin_eh_return_data_regno(), clang::interp::interp__builtin_elementwise_abs(), clang::interp::interp__builtin_elementwise_countzeroes(), clang::interp::interp__builtin_elementwise_int_binop(), clang::interp::interp__builtin_elementwise_maxmin(), clang::interp::interp__builtin_elementwise_popcount(), clang::interp::interp__builtin_elementwise_triop(), clang::interp::interp__builtin_expect(), clang::interp::interp__builtin_ffs(), clang::interp::interp__builtin_fpclassify(), clang::interp::interp__builtin_ia32_addcarry_subborrow(), clang::interp::interp__builtin_ia32_bextr(), clang::interp::interp__builtin_ia32_bzhi(), clang::interp::interp__builtin_ia32_lzcnt(), clang::interp::interp__builtin_ia32_pdep(), clang::interp::interp__builtin_ia32_pext(), clang::interp::interp__builtin_ia32_pmul(), clang::interp::interp__builtin_ia32_tzcnt(), clang::interp::interp__builtin_is_aligned_up_down(), clang::interp::interp__builtin_isfpclass(), clang::interp::interp__builtin_memchr(), clang::interp::interp__builtin_memcmp(), clang::interp::interp__builtin_memcpy(), clang::interp::interp__builtin_object_size(), clang::interp::interp__builtin_operator_new(), clang::interp::interp__builtin_overflowop(), clang::interp::interp__builtin_parity(), clang::interp::interp__builtin_popcount(), clang::interp::interp__builtin_rotate(), clang::interp::interp__builtin_select(), clang::interp::interp__builtin_strcmp(), clang::interp::interp__builtin_vector_reduce(), clang::interp::popArg(), clang::interp::pushInteger(), clang::interp::SetThreeWayComparisonField(), and clang::interp::Pointer::toRValue().

◆ collectBaseOffset()

unsigned Context::collectBaseOffset ( const RecordDecl * BaseDecl,
const RecordDecl * DerivedDecl ) const

◆ evaluate()

bool Context::evaluate ( State & Parent,
const Expr * E,
APValue & Result,
ConstantExprKind Kind )

Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion.

Definition at line 99 of file Context.cpp.

References clang::C, and clang::Result.

Referenced by clang::Expr::EvaluateAsConstantExpr(), and clang::Expr::EvaluateAsLValue().

◆ evaluateAsInitializer()

bool Context::evaluateAsInitializer ( State & Parent,
const VarDecl * VD,
const Expr * Init,
APValue & Result )

◆ evaluateAsRValue()

bool Context::evaluateAsRValue ( State & Parent,
const Expr * E,
APValue & Result )

Evaluates a toplevel expression as an rvalue.

Definition at line 69 of file Context.cpp.

References clang::C, clang::Expr::isGLValue(), and clang::Result.

Referenced by EvaluateAsRValue().

◆ evaluateCharRange() [1/2]

bool Context::evaluateCharRange ( State & Parent,
const Expr * SizeExpr,
const Expr * PtrExpr,
APValue & Result )

Definition at line 223 of file Context.cpp.

References clang::Result.

Referenced by EvaluateCharRangeAsStringImpl().

◆ evaluateCharRange() [2/2]

bool Context::evaluateCharRange ( State & Parent,
const Expr * SizeExpr,
const Expr * PtrExpr,
std::string & Result )

Definition at line 231 of file Context.cpp.

References clang::Result.

◆ evaluateStrlen()

◆ getASTContext()

ASTContext & clang::interp::Context::getASTContext ( ) const
inline

◆ getBitWidth()

uint32_t clang::interp::Context::getBitWidth ( QualType T) const
inline

Return the size of T in bits.

Definition at line 83 of file Context.h.

References clang::T.

◆ getCharBit()

unsigned Context::getCharBit ( ) const

Returns CHAR_BIT.

Definition at line 389 of file Context.cpp.

◆ getEvalID()

◆ getFloatSemantics()

const llvm::fltSemantics & Context::getFloatSemantics ( QualType T) const

Return the floating-point semantics for T.

Simple wrapper around getFloatTypeSemantics() to make code a little shorter.

Definition at line 395 of file Context.cpp.

References clang::T.

◆ getLangOpts()

const LangOptions & Context::getLangOpts ( ) const

Returns the language options.

Definition at line 276 of file Context.cpp.

Referenced by clang::interp::interp__builtin_elementwise_triop_fp().

◆ getOrCreateFunction()

◆ getOrCreateObjCBlock()

◆ getOverridingFunction()

◆ getProgram()

Program & clang::interp::Context::getProgram ( ) const
inline

Returns the program. This is only needed for unittests.

Definition at line 134 of file Context.h.

Referenced by clang::interp::MemberPointer::toFunctionPointer().

◆ getRecord()

const Record * Context::getRecord ( const RecordDecl * D) const

Definition at line 624 of file Context.cpp.

Referenced by clang::interp::MemberPointer::toPointer().

◆ isPotentialConstantExpr()

bool Context::isPotentialConstantExpr ( State & Parent,
const FunctionDecl * FD )

Checks if a function is a potential constant expression.

Definition at line 36 of file Context.cpp.

References clang::Func, and getOrCreateFunction().

Referenced by clang::Expr::isPotentialConstantExpr().

◆ isPotentialConstantExprUnevaluated()

void Context::isPotentialConstantExprUnevaluated ( State & Parent,
const Expr * E,
const FunctionDecl * FD )

Definition at line 56 of file Context.cpp.

References clang::C.

Referenced by clang::Expr::isPotentialConstantExprUnevaluated().

◆ isUnevaluatedBuiltin()

bool Context::isUnevaluatedBuiltin ( unsigned ID)
static

Unevaluated builtins don't get their arguments put on the stack automatically.

They instead operate on the AST of their Call Expression. Similar information is available via ASTContext::BuiltinInfo, but that is not correct for our use cases.

Definition at line 628 of file Context.cpp.

Referenced by clang::interp::Compiler< Emitter >::VisitBuiltinCallExpr().

◆ shouldBeGloballyIndexed()

bool clang::interp::Context::shouldBeGloballyIndexed ( const ValueDecl * VD)
inlinestatic

The documentation for this class was generated from the following files: