|
clang 22.0.0git
|
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 (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 | evaluateString (State &Parent, const Expr *E, std::string &Result) |
| Evaluate. | |
| 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 29 of file Context.cpp.
References Context().
Referenced by Context().
| Context::~Context | ( | ) |
Cleans up the constexpr VM.
Definition at line 38 of file Context.cpp.
Definition at line 114 of file Context.h.
References canClassify(), clang::Expr::getType(), and clang::Expr::isGLValue().
Definition at line 101 of file Context.h.
References classify(), and clang::T.
Referenced by canClassify(), clang::interp::CheckArrayInitialized(), and getOrCreateFunction().
|
inline |
Classifies an expression.
Definition at line 93 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 363 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_addressof(), clang::interp::interp__builtin_assume(), 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_maxmin(), clang::interp::interp__builtin_elementwise_popcount(), 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_movmsk_op(), clang::interp::interp__builtin_ia32_phminposuw(), clang::interp::interp__builtin_ia32_pmul(), clang::interp::interp__builtin_ia32_pternlog(), clang::interp::interp__builtin_ia32_shuffle_generic(), clang::interp::interp__builtin_ia32_test_op(), clang::interp::interp__builtin_ia32_vpconflict(), 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_new(), clang::interp::interp__builtin_overflowop(), clang::interp::interp__builtin_strcmp(), clang::interp::interp__builtin_vector_reduce(), clang::interp::interp__builtin_x86_pack(), clang::interp::interp_builtin_horizontal_int_binop(), clang::interp::popArg(), clang::interp::popToAPSInt(), clang::interp::popToAPSInt(), clang::interp::pushInteger(), clang::interp::SetThreeWayComparisonField(), and clang::interp::Pointer::toRValue().
| unsigned Context::collectBaseOffset | ( | const RecordDecl * | BaseDecl, |
| const RecordDecl * | DerivedDecl ) const |
Definition at line 643 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 103 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 132 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 73 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 227 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 235 of file Context.cpp.
References clang::Result.
Evaluate.
| E | and if it can be evaluated to a null-terminated string, copy the result into |
| Result. |
Definition at line 243 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::Pointer::isConst(), clang::interp::Descriptor::isPrimitiveArray(), clang::Result, and clang::T.
Referenced by clang::Expr::tryEvaluateString().
Evalute.
| E | and if it can be evaluated to a string literal, run strlen() on it. |
Definition at line 289 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::Pointer::isDummy(), clang::interp::Descriptor::isPrimitiveArray(), clang::interp::Pointer::isUnknownSizeArray(), clang::Result, and clang::T.
Referenced by clang::Expr::tryEvaluateStrLen().
|
inline |
Returns the AST context.
Definition at line 79 of file Context.h.
Referenced by enumerateData(), getOrCreateFunction(), clang::interp::GetTypeidPtr(), clang::interp::readPointerToBuffer(), and clang::interp::Pointer::toRValue().
|
inline |
| unsigned Context::getCharBit | ( | ) | const |
Returns CHAR_BIT.
Definition at line 442 of file Context.cpp.
|
inline |
Definition at line 145 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 448 of file Context.cpp.
References clang::T.
| const LangOptions & Context::getLangOpts | ( | ) | const |
Returns the language options.
Definition at line 329 of file Context.cpp.
Referenced by clang::interp::interp__builtin_elementwise_triop_fp(), and clang::interp::interp_builtin_horizontal_fp_binop().
| const Function * Context::getOrCreateFunction | ( | const FunctionDecl * | FuncDecl | ) |
Definition at line 500 of file Context.cpp.
References clang::interp::align(), canClassify(), classify(), clang::Func, clang::Type::getAs(), getASTContext(), clang::FieldDecl::getParent(), clang::FunctionDecl::getReturnType(), clang::ValueDecl::getType(), 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 601 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 464 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 138 of file Context.h.
Referenced by clang::interp::MemberPointer::toFunctionPointer().
| const Record * Context::getRecord | ( | const RecordDecl * | D | ) | const |
Definition at line 674 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 40 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 60 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 678 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 130 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().