clang 24.0.0git
clang::interp::Context Class Referencefinal

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

#include "/work/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 (const EvalSettings &Settings, const FunctionDecl *FD)
 Checks if a function is a potential constant expression.
void isPotentialConstantExprUnevaluated (const EvalSettings &Settings, const Expr *E, const FunctionDecl *FD)
bool evaluateAsRValue (const EvalSettings &Settings, const Expr *E, APValue &Result)
 Evaluates a toplevel expression as an rvalue.
bool evaluate (const EvalSettings &Settings, const Expr *E, APValue &Result)
 Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion.
bool evaluateAsInitializer (const EvalSettings &Settings, const VarDecl *VD, const Expr *Init, APValue &Result)
 Evaluates a toplevel initializer.
void registerRedecl (const VarDecl *VD, const APValue &V)
bool evaluateDestruction (const EvalSettings &Settings, const VarDecl *VD, APValue Value)
 Evaluates the destruction of a variable.
bool evaluateCharRange (const EvalSettings &Settings, const Expr *SizeExpr, const Expr *PtrExpr, APValue &Result)
bool evaluateCharRange (const EvalSettings &Settings, const Expr *SizeExpr, const Expr *PtrExpr, std::string &Result)
bool evaluateString (const EvalSettings &Settings, const Expr *E, std::string &Result)
 Evaluate.
std::optional< uint64_t > evaluateStrlen (const EvalSettings &Settings, const Expr *E)
 Evalute.
std::optional< uint64_t > tryEvaluateObjectSize (const EvalSettings &Settings, const Expr *E, unsigned Kind, bool IsDynamic)
 If.
std::optional< bool > evaluateWithSubstitution (const EvalSettings &Settings, const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition)
ASTContext & getASTContext () const
 Returns the AST context.
const LangOptions & getLangOpts () 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) const
bool canClassify (const Expr *E) const
const CXXMethodDecl * getOverridingFunction (const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const
const Function * getOrCreateFunction (const FunctionDecl *FuncDecl)
const Function * getOrCreateObjCBlock (const BlockExpr *E)
Program & getProgram () const
 Returns the program. This is only needed for unittests.
unsigned collectBaseOffset (const RecordDecl *BaseDecl, const RecordDecl *DerivedDecl) const
const Record * getRecord (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.

Friends

class EvalIDScope

Detailed Description

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

Definition at line 49 of file Context.h.

Constructor & Destructor Documentation

◆ Context()

Context::Context ( ASTContext & Ctx)
explicit

Initialises the constexpr VM.

Definition at line 30 of file Context.cpp.

References Context().

Referenced by Context().

◆ ~Context()

Context::~Context ( )
default

Cleans up the constexpr VM.

References clang::Condition, clang::interp::Init(), clang::Result, clang::interp::This(), and V.

Member Function Documentation

◆ canClassify() [1/2]

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

Definition at line 159 of file Context.h.

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

◆ canClassify() [2/2]

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

Definition at line 138 of file Context.h.

References classify(), and clang::T.

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

◆ classify() [1/2]

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

Classifies an expression.

Definition at line 130 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 521 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, clang::interp::PT_Reflect, and clang::T.

Referenced by clang::interp::CallPtr(), canClassify(), clang::interp::CheckNonNullArgs(), classify(), classify(), convertToBlockPointer(), enumerateData(), evaluateString(), evaluateWithSubstitution(), getOrCreateFunction(), getOrCreateObjCBlock(), clang::interp::interp__builtin_addressof(), clang::interp::interp__builtin_assume_aligned(), clang::interp::interp__builtin_carryop(), clang::interp::interp__builtin_elementwise_abs(), clang::interp::interp__builtin_elementwise_countzeroes(), clang::interp::interp__builtin_elementwise_int_binop(), clang::interp::interp__builtin_elementwise_int_unaryop(), clang::interp::interp__builtin_elementwise_maxmin(), clang::interp::interp__builtin_elementwise_triop(), clang::interp::interp__builtin_expect(), clang::interp::interp__builtin_fpclassify(), clang::interp::interp__builtin_ia32_addcarry_subborrow(), clang::interp::interp__builtin_ia32_dbpsadbw(), clang::interp::interp__builtin_ia32_gfni_affine(), clang::interp::interp__builtin_ia32_gfni_mul(), clang::interp::interp__builtin_ia32_movmsk_op(), clang::interp::interp__builtin_ia32_mpsadbw(), clang::interp::interp__builtin_ia32_multishiftqb(), clang::interp::interp__builtin_ia32_pack(), clang::interp::interp__builtin_ia32_pclmulqdq(), clang::interp::interp__builtin_ia32_phminposuw(), clang::interp::interp__builtin_ia32_pmul(), clang::interp::interp__builtin_ia32_psadbw(), clang::interp::interp__builtin_ia32_pternlog(), clang::interp::interp__builtin_ia32_shift_with_count(), clang::interp::interp__builtin_ia32_shufbitqmb_mask(), clang::interp::interp__builtin_ia32_shuffle_generic(), clang::interp::interp__builtin_ia32_test_op(), clang::interp::interp__builtin_ia32_vcvtps2ph(), clang::interp::interp__builtin_ia32_vpconflict(), clang::interp::interp__builtin_ia32_vpdp(), clang::interp::interp__builtin_infer_alloc_token(), clang::interp::interp__builtin_is_aligned_up_down(), clang::interp::interp__builtin_memchr(), clang::interp::interp__builtin_memcmp(), clang::interp::interp__builtin_operator_delete(), clang::interp::interp__builtin_operator_new(), clang::interp::interp__builtin_overflowop(), clang::interp::interp__builtin_stdc_memreverse8(), clang::interp::interp__builtin_strcmp(), clang::interp::interp__builtin_vector_reduce(), clang::interp::interp_builtin_horizontal_int_binop(), clang::interp::interp_builtin_ia32_cvt_vector_to_int(), clang::interp::popToAPSInt(), clang::interp::popToAPSInt(), clang::interp::popToUInt64(), clang::interp::pushInteger(), clang::interp::Pointer::toRValue(), and toRValue().

◆ collectBaseOffset()

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

◆ evaluate()

bool Context::evaluate ( const EvalSettings & Settings,
const Expr * E,
APValue & Result )

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

Definition at line 106 of file Context.cpp.

References clang::C, clang::interp::EvalSettings::ConstexprKind, and clang::Result.

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

◆ evaluateAsInitializer()

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

Evaluates a toplevel initializer.

Definition at line 137 of file Context.cpp.

References clang::C, clang::ValueDecl::getType(), clang::interp::Init(), clang::Type::isArrayType(), isRecordType(), and clang::Result.

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

◆ evaluateAsRValue()

◆ evaluateCharRange() [1/2]

bool Context::evaluateCharRange ( const EvalSettings & Settings,
const Expr * SizeExpr,
const Expr * PtrExpr,
APValue & Result )

Definition at line 280 of file Context.cpp.

References clang::Result.

Referenced by EvaluateCharRangeAsStringImpl().

◆ evaluateCharRange() [2/2]

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

Definition at line 289 of file Context.cpp.

References clang::Result.

◆ evaluateDestruction()

bool Context::evaluateDestruction ( const EvalSettings & Settings,
const VarDecl * VD,
APValue Value )

Evaluates the destruction of a variable.

Definition at line 170 of file Context.cpp.

References clang::C.

Referenced by clang::VarDecl::evaluateDestruction().

◆ evaluateString()

bool Context::evaluateString ( const EvalSettings & Settings,
const Expr * E,
std::string & Result )

Evaluate.

Parameters
Eand if it can be evaluated to a null-terminated string, copy the result into
Result.

Definition at line 298 of file Context.cpp.

References clang::C, classify(), INT_TYPE_SWITCH, clang::Result, and clang::T.

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

◆ evaluateStrlen()

std::optional< uint64_t > Context::evaluateStrlen ( const EvalSettings & Settings,
const Expr * E )

Evalute.

Parameters
Eand if it can be evaluated to a string literal, run strlen() on it.

Definition at line 363 of file Context.cpp.

References clang::C, clang::interp::Descriptor::getPrimType(), INT_TYPE_SWITCH, clang::interp::isIntegerType(), clang::interp::Descriptor::isPrimitiveArray(), clang::Off, clang::Result, and clang::T.

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

◆ evaluateWithSubstitution()

std::optional< bool > Context::evaluateWithSubstitution ( const EvalSettings & Settings,
const FunctionDecl * Callee,
ArrayRef< const Expr * > Args,
const Expr * This,
const Expr * Condition )

◆ getASTContext()

◆ getBitWidth()

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

Return the size of T in bits.

Definition at line 124 of file Context.h.

References clang::T.

◆ getCharBit()

unsigned Context::getCharBit ( ) const

Returns CHAR_BIT.

Definition at line 604 of file Context.cpp.

Referenced by convertToBlockPointer().

◆ getEvalID()

unsigned clang::interp::Context::getEvalID ( ) const
inline

◆ 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 610 of file Context.cpp.

References clang::T.

◆ getLangOpts()

const LangOptions & Context::getLangOpts ( ) const

◆ getOrCreateFunction()

◆ getOrCreateObjCBlock()

◆ getOverridingFunction()

◆ getProgram()

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

Returns the program. This is only needed for unittests.

Definition at line 183 of file Context.h.

◆ getRecord()

◆ isPotentialConstantExpr()

bool Context::isPotentialConstantExpr ( const EvalSettings & Settings,
const FunctionDecl * FD )

Checks if a function is a potential constant expression.

Definition at line 41 of file Context.cpp.

References clang::Func, and getOrCreateFunction().

◆ isPotentialConstantExprUnevaluated()

void Context::isPotentialConstantExprUnevaluated ( const EvalSettings & Settings,
const Expr * E,
const FunctionDecl * FD )

Definition at line 62 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 839 of file Context.cpp.

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

◆ registerRedecl()

void Context::registerRedecl ( const VarDecl * VD,
const APValue & V )

Definition at line 188 of file Context.cpp.

References clang::C, and V.

◆ shouldBeGloballyIndexed()

◆ tryEvaluateObjectSize()

std::optional< uint64_t > Context::tryEvaluateObjectSize ( const EvalSettings & Settings,
const Expr * E,
unsigned Kind,
bool IsDynamic )

If.

Parameters
Eevaluates to a pointer the number of accessible bytes past the pointer is estimated in
Resultas if evaluated by the builtin function __builtin_object_size. This is a best effort approximation, when Kind & 2 == 0 the object size is less than or equal to the estimated size, when Kind & 2 == 1 the true value is greater than or equal to the estimated size. When Kind & 1 == 1 only bytes belonging to the same subobject as the one referred to by E are considered, when Kind & 1 == 0 bytes belonging to the same storage (stack, heap allocation, global variable) are considered.

Definition at line 431 of file Context.cpp.

References clang::C, clang::interp::evaluateBuiltinObjectSize(), getASTContext(), clang::Result, and clang::T.

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

◆ EvalIDScope

friend class EvalIDScope
friend

Definition at line 200 of file Context.h.

References EvalIDScope, clang::Func, and clang::Result.

Referenced by EvalIDScope.


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