clang 22.0.0git
|
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. | |
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) |
bool | canClassify (const Expr *E) |
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. |
Holds all information required to evaluate constexpr code in a module.
Context::Context | ( | ASTContext & | Ctx | ) |
Initialises the constexpr VM.
Definition at line 25 of file Context.cpp.
References Context().
Referenced by Context().
Context::~Context | ( | ) |
Cleans up the constexpr VM.
Definition at line 34 of file Context.cpp.
Definition at line 110 of file Context.h.
References canClassify(), clang::Expr::getType(), and clang::Expr::isGLValue().
Definition at line 97 of file Context.h.
References classify(), and clang::T.
Referenced by canClassify(), clang::interp::CheckArrayInitialized(), and getOrCreateFunction().
|
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.
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().
unsigned Context::collectBaseOffset | ( | const RecordDecl * | BaseDecl, |
const RecordDecl * | DerivedDecl ) const |
Definition at line 593 of file Context.cpp.
References clang::interp::Record::bases(), clang::cast(), and clang::interp::Record::getNumBases().
Referenced by clang::interp::CallVirt(), and clang::interp::MemberPointer::toPointer().
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().
bool Context::evaluateAsInitializer | ( | State & | Parent, |
const VarDecl * | VD, | ||
const Expr * | Init, | ||
APValue & | Result ) |
Evaluates a toplevel initializer.
Definition at line 128 of file Context.cpp.
References clang::C, clang::ValueDecl::getType(), clang::interp::Init(), clang::Type::isArrayType(), isRecordType(), clang::Result, and shouldBeGloballyIndexed().
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().
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().
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.
Evalute.
E | and if it can be evaluated to a string literal, run strlen() on it. |
Definition at line 239 of file Context.cpp.
References clang::C, clang::interp::Pointer::elem(), clang::interp::Pointer::elemSize(), clang::interp::Pointer::getFieldDesc(), clang::interp::Pointer::getIndex(), clang::interp::Pointer::getNumElems(), clang::interp::Descriptor::getPrimType(), clang::interp::Pointer::getRawAddress(), INT_TYPE_SWITCH, clang::interp::Descriptor::isPrimitiveArray(), clang::Result, and clang::T.
Referenced by clang::Expr::tryEvaluateStrLen().
|
inline |
Returns the AST context.
Definition at line 75 of file Context.h.
Referenced by enumerateData(), clang::interp::GetTypeidPtr(), clang::interp::readPointerToBuffer(), and clang::interp::Pointer::toRValue().
|
inline |
unsigned Context::getCharBit | ( | ) | const |
Returns CHAR_BIT.
Definition at line 389 of file Context.cpp.
|
inline |
Definition at line 141 of file Context.h.
Referenced by clang::interp::Alloc(), clang::interp::AllocCN(), clang::interp::AllocN(), clang::interp::CheckMutable(), CheckTemporary(), and clang::interp::interp__builtin_operator_new().
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.
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().
const Function * Context::getOrCreateFunction | ( | const FunctionDecl * | FuncDecl | ) |
Definition at line 447 of file Context.cpp.
References clang::interp::align(), clang::TemplateArgumentList::asArray(), canClassify(), clang::CXXRecordDecl::captures(), classify(), clang::FunctionTemplateDecl::findSpecialization(), clang::Func, clang::FunctionDecl::getDescribedFunctionTemplate(), clang::CXXRecordDecl::getLambdaCallOperator(), clang::FunctionDecl::getMostRecentDecl(), clang::DeclContext::getParent(), clang::FieldDecl::getParent(), clang::FunctionDecl::getReturnType(), clang::CXXRecordDecl::isGenericLambda(), clang::isLambdaCallOperator(), clang::Type::isVoidType(), clang::FunctionDecl::param_begin(), clang::FunctionDecl::param_empty(), clang::FunctionDecl::parameters(), clang::interp::primSize(), clang::interp::PT_Ptr, and clang::T.
Referenced by clang::interp::CallVirt(), clang::interp::GetMemberPtrDecl(), isPotentialConstantExpr(), and clang::interp::runRecordDestructor().
Definition at line 556 of file Context.cpp.
References clang::interp::align(), classify(), clang::Func, clang::BlockExpr::getBlockDecl(), clang::BlockDecl::hasCaptures(), clang::BlockDecl::parameters(), clang::interp::primSize(), clang::interp::PT_Ptr, and clang::T.
const CXXMethodDecl * Context::getOverridingFunction | ( | const CXXRecordDecl * | DynamicDecl, |
const CXXRecordDecl * | StaticDecl, | ||
const CXXMethodDecl * | InitialFunction ) const |
Definition at line 411 of file Context.cpp.
References clang::CXXRecordDecl::bases(), clang::CXXRecordDecl::bases_begin(), clang::Type::getAsCXXRecordDecl(), clang::CXXMethodDecl::getCorrespondingMethodDeclaredInClass(), clang::CXXRecordDecl::getNumBases(), and clang::CXXBaseSpecifier::getType().
Referenced by clang::interp::CallVirt().
|
inline |
Returns the program. This is only needed for unittests.
Definition at line 134 of file Context.h.
Referenced by clang::interp::MemberPointer::toFunctionPointer().
const Record * Context::getRecord | ( | const RecordDecl * | D | ) | const |
Definition at line 624 of file Context.cpp.
Referenced by clang::interp::MemberPointer::toPointer().
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().
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().
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().
Returns whether we should create a global variable for the given ValueDecl.
Definition at line 126 of file Context.h.
References V.
Referenced by clang::interp::Program::createGlobal(), evaluateAsInitializer(), clang::interp::Compiler< Emitter >::VisitCastExpr(), clang::interp::Compiler< Emitter >::visitDecl(), clang::interp::Compiler< Emitter >::visitDeclAndReturn(), and clang::interp::Compiler< Emitter >::visitVarDecl().