26#include "llvm/ADT/StringExtras.h"
31#if __has_cpp_attribute(clang::musttail)
32#define MUSTTAIL [[clang::musttail]]
33#elif __has_cpp_attribute(msvc::musttail)
34#define MUSTTAIL [[msvc::musttail]]
35#elif __has_attribute(musttail)
36#define MUSTTAIL __attribute__((musttail))
43#if defined(_MSC_VER) || defined(__powerpc__) || !defined(MUSTTAIL) || \
44 defined(__i386__) || defined(__sparc__)
47#define USE_TAILCALLS 0
49#define USE_TAILCALLS 1
53 llvm::report_fatal_error(
"Interpreter cannot return values");
84 S.
FFDiag(E, diag::note_constexpr_var_init_unknown, 1) << VD;
120 S.
FFDiag(Loc, diag::note_constexpr_access_unknown_variable, 1)
122 S.
Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
124 S.
FFDiag(Loc, diag::note_constexpr_function_param_value_unknown, 1) << D;
134 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
135 if (!VD->getAnyInitializer()) {
139 S.
FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
140 S.
Note(VD->getLocation(), diag::note_declared_at);
163 if (
const auto *VarD = dyn_cast<VarDecl>(VD);
164 VarD && VarD->getType().isConstQualified() &&
165 (VarD->isConstexpr() || !VarD->getType()->isArrayType()) &&
166 !VarD->getAnyInitializer()) {
178 S.
FFDiag(Loc, diag::note_constexpr_modify_global);
180 S.
FFDiag(Loc, diag::note_constexpr_ltor_non_const_int, 1) << VD;
187 S.
getLangOpts().CPlusPlus11 ? diag::note_constexpr_ltor_non_constexpr
188 : diag::note_constexpr_ltor_non_integral,
200 const auto *MTE = dyn_cast_if_present<MaterializeTemporaryExpr>(
212 S.
FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK;
251 S.
CCEDiag(E, diag::note_constexpr_large_shift)
273 unsigned VariadicArgSize =
275 unsigned TargetStackSize = S.
Stk.
size() - VariadicArgSize;
276 while (S.
Stk.
size() != TargetStackSize) {
286 if (
Func->hasImplicitThisPointer())
334 while (!
U.isRoot() && !
U.isActive()) {
339 if (
U.getRecord() &&
U.getRecord()->isAnonymousUnion())
346 assert(
C.getBase() ==
U);
360 if (!
U.getFieldDesc()->isUnion())
370 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(R->getDecl());
371 CXXRD && !CXXRD->hasTrivialDefaultConstructor()) {
383 assert(!
C.isActive());
384 const FieldDecl *InactiveField =
C.getField();
385 assert(InactiveField);
388 const Record *R =
U.getRecord();
389 assert(R && R->isUnion() &&
"Not a union");
392 for (
const Record::Field &F : R->fields()) {
393 PtrView Field =
U.atField(F.Offset);
394 if (Field.isActive()) {
395 ActiveField = Field.getField();
401 diag::note_constexpr_access_inactive_union_member)
402 << AK << InactiveField << !ActiveField << ActiveField;
429 S.
FFDiag(E, diag::note_constexpr_unsized_array_indexed);
441 S.
FFDiag(Src, diag::note_constexpr_access_null) << AK;
450 S.
FFDiag(Src, diag::note_constexpr_access_deleted_object) << AK;
452 S.
FFDiag(Src, diag::note_constexpr_access_uninit)
471 if (D->getType().isConstQualified())
479 if (
const auto *VD = dyn_cast_if_present<VarDecl>(S.
EvaluatingDecl);
485 if (T->isIntegralOrEnumerationType()) {
497 ? diag::note_constexpr_ltor_non_constexpr
498 : diag::note_constexpr_ltor_non_integral,
501 S.
Note(D->getLocation(), diag::note_declared_at);
508 if (T->isPointerOrReferenceType()) {
538 S.
FFDiag(Loc, diag::note_constexpr_null_subobject)
549 S.
FFDiag(Loc, diag::note_constexpr_access_past_end)
560 S.
FFDiag(Loc, diag::note_constexpr_past_end_subobject)
571 S.
FFDiag(Loc, diag::note_constexpr_past_end_subobject)
583 if (Offset < PtrOffset && (PtrOffset - Offset) >= MinOffset)
597 S.
CCEDiag(E, diag::note_constexpr_invalid_downcast)
598 << MostDerivedQT << TargetQT;
604 assert(Ptr.
isLive() &&
"Pointer is not live");
617 if (
V.block() != Ptr.
block())
619 if (!
V.getFieldDesc()->IsConst) {
634 bool FoundProblem =
false;
636 if (P.getFieldDesc()->IsConst) {
655 S.
FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
661 assert(Ptr.
isLive() &&
"Pointer is not live");
678 MutablePtr = MutablePtr.
getBase();
682 S.
FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK << Field;
683 S.
Note(Field->getLocation(), diag::note_declared_at);
715 Loc = F->getLocation();
719 Loc = VD->getLocation();
724 Loc = E->getExprLoc();
728 diag::note_constexpr_access_volatile_obj, 1)
729 << AK << DiagKind << ND;
730 S.
Note(Loc, diag::note_constexpr_volatile_here) << DiagKind;
756 VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
759 !(S.
getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType())) {
767 S.
FFDiag(Loc, diag::note_constexpr_access_uninit)
769 S.
Note(VD->getLocation(), diag::note_declared_at);
774 if (VD->getAnyInitializer()) {
776 S.
FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
777 S.
Note(VD->getLocation(), diag::note_declared_at);
817 S.
Note(VD->getLocation(), diag::note_declared_at);
848 diag::note_constexpr_access_volatile_obj, 1)
862 if (!Desc.IsInitialized)
870 diag::note_constexpr_access_volatile_obj, 1)
886 S.
FFDiag(Src, diag::note_constexpr_access_null) << AK;
938 if (
const auto *CLE =
939 dyn_cast_if_present<CompoundLiteralExpr>(Desc->
asExpr())) {
940 if (
QualType CLETy = CLE->getType();
943 diag::note_invalid_subexpr_in_const_expr)
945 S.
Note(CLE->getExprLoc(), diag::note_declared_at);
989 bool WillBeActivated) {
1020 bool IsCtor,
bool IsDtor) {
1052 StringRef Name = DiagDecl->
getName();
1054 Name ==
"__assert_rtn" || Name ==
"__assert_fail" || Name ==
"_wassert";
1057 diag::note_constexpr_assert_failed);
1064 diag::note_invalid_subexpr_in_const_expr);
1074 const auto *CD = dyn_cast<CXXConstructorDecl>(DiagDecl);
1075 if (CD && CD->isInheritingConstructor()) {
1076 const auto *Inherited = CD->getInheritedConstructor().getConstructor();
1077 if (!Inherited->isConstexpr())
1078 DiagDecl = CD = Inherited;
1083 if (CD && CD->getParent()->isInvalidDecl())
1089 if (CD && CD->isInheritingConstructor()) {
1092 << CD->getInheritedConstructor().getConstructor()->getParent();
1100 if (!IsDefined && !IsExtern && DiagDecl->
isConstexpr() &&
1110 diag::note_constexpr_invalid_function, 1)
1111 << DiagDecl->
isConstexpr() << (bool)CD << DiagDecl;
1125 S.
CCEDiag(Loc, diag::note_constexpr_virtual_call);
1153 diag::note_constexpr_depth_limit_exceeded)
1167 bool IsImplicit =
false;
1168 if (
const auto *TE = dyn_cast<CXXThisExpr>(E))
1169 IsImplicit = TE->isImplicit();
1170 S.
FFDiag(E, diag::note_constexpr_this) << IsImplicit;
1179 APFloat::opStatus Status,
FPOptions FPO) {
1186 S.
CCEDiag(E, diag::note_constexpr_float_arithmetic)
1196 if ((Status & APFloat::opInexact) &&
1201 S.
FFDiag(E, diag::note_constexpr_dynamic_rounding);
1205 if ((Status != APFloat::opOK) &&
1208 FPO.getAllowFEnvAccess())) {
1210 S.
FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
1214 if ((Status & APFloat::opStatus::opInvalidOp) &&
1230 S.
CCEDiag(E, diag::note_constexpr_new);
1237 const Expr *NewExpr) {
1238 if (AllocForm == DeleteForm)
1244 S.
FFDiag(E, diag::note_constexpr_new_delete_mismatch)
1245 <<
static_cast<int>(DeleteForm) <<
static_cast<int>(AllocForm)
1247 S.
Note(NewExpr->
getExprLoc(), diag::note_constexpr_dynamic_alloc_here)
1255 if (isa_and_nonnull<CXXNewExpr>(Source))
1258 if (
const auto *CE = dyn_cast_if_present<CallExpr>(Source);
1259 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_operator_new)
1262 if (
const auto *MCE = dyn_cast_if_present<CXXMemberCallExpr>(Source);
1263 MCE && MCE->getMethodDecl()->
getIdentifier()->isStr(
"allocate"))
1268 S.
FFDiag(Loc, diag::note_constexpr_delete_not_heap_alloc)
1288 S.
FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
1289 S.
Note(VD->getLocation(), diag::note_declared_at);
1309 S.
FFDiag(E, diag::note_constexpr_modify_global);
1315 const CallExpr *CE,
unsigned ArgSize) {
1318 unsigned Offset = 0;
1320 for (
const Expr *Arg : Args) {
1321 if (NonNullArgs[Index] && Arg->getType()->isPointerType()) {
1325 S.
CCEDiag(Loc, diag::note_non_null_attribute_failed);
1347 S.
FFDiag(Loc, diag::note_constexpr_double_destroy);
1354 assert(!
Dtor->isTrivial());
1360 return Call(S, OpPC, DtorFunc, 0);
1383 for (
int I =
static_cast<int>(N) - 1; I >= 0; --I) {
1397 return DD->isVirtual();
1402 bool IsGlobalDelete) {
1408 const Expr *Source =
nullptr;
1409 const Block *BlockToDelete =
nullptr;
1427 BlockToDelete = Ptr.
block();
1431 if (std::optional<DynamicAllocator::Form> AllocForm =
1443 if (!DeleteIsArrayForm && Ptr.
getType() != InitialType &&
1446 diag::note_constexpr_delete_base_nonvirt_dtor)
1447 << InitialType << Ptr.
getType();
1454 S.
FFDiag(Loc, diag::note_constexpr_delete_subobject)
1464 if (!DeleteIsArrayForm && !IsGlobalDelete) {
1469 return DD->isVirtual() ? DD->getOperatorDelete() :
nullptr;
1479 diag::note_constexpr_new_non_replaceable)
1486 assert(BlockToDelete);
1492 if (!Allocator.
deallocate(Source, BlockToDelete)) {
1495 S.
FFDiag(Loc, diag::note_constexpr_double_delete);
1512 S.
CCEDiag(Loc, diag::note_constexpr_unscoped_enum_out_of_range)
1513 << llvm::toString(
Value, 10) <<
Min.getSExtValue() <<
Max.getSExtValue()
1517 S.
CCEDiag(Loc, diag::note_constexpr_unscoped_enum_out_of_range)
1518 << llvm::toString(
Value, 10) <<
Min.getZExtValue() <<
Max.getZExtValue()
1549 S.
FFDiag(E, diag::note_constexpr_nonliteral) << E->
getType();
1551 S.
FFDiag(E, diag::note_invalid_subexpr_in_const_expr);
1569 if (std::optional<IntPointer> IntPtr =
1582 diag::note_constexpr_access_unreadable_object)
1609 uint32_t
Off,
bool NullOK) {
1639 return getBase(S, OpPC, Ptr.narrow(),
Off,
true);
1643 return getBase(S, OpPC, Ptr.narrow(),
Off, NullOK);
1647 const Type *TargetType) {
1671 assert(TargetRecord);
1677 << MostDerivedType <<
QualType(TargetType, 0);
1687 assert(
Func->isConstructor());
1689 if (
Func->getParentDecl()->isInvalidDecl())
1702 <<
Func->getParentDecl();
1712 S.
FFDiag(ND->getLocation(), diag::note_constexpr_destroy_out_of_lifetime)
1713 << ND->getNameAsString();
1716 diag::note_constexpr_destroy_out_of_lifetime)
1743 S.
FFDiag(E, diag::note_constexpr_modify_global);
1766 bool SrcIsVoidPtr) {
1770 if (!Ptr.isBlockPointer())
1777 bool HasValidResult = !Ptr.isZero();
1779 if (HasValidResult) {
1789 S.
CCEDiag(E, diag::note_constexpr_invalid_void_star_cast)
1790 << E->getSubExpr()->getType() << S.
getLangOpts().CPlusPlus26
1791 << Ptr.getType().getCanonicalType() << E->getType()->getPointeeType();
1794 S.
CCEDiag(E, diag::note_constexpr_invalid_cast)
1795 << diag::ConstexprInvalidCastKind::CastFrom <<
"'void *'"
1804 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
1822 uint32_t VarArgSize) {
1823 if (
Func->hasThisPointer()) {
1824 size_t ArgSize =
Func->getArgSize() + VarArgSize;
1834 Func->isLambdaCallOperator())) {
1836 Func->isDestructor()))
1844 if (!
Func->isFullyCompiled())
1860 assert(S.
Current == FrameBefore);
1871 uint32_t VarArgSize) {
1878 auto cleanup = [&]() ->
bool {
1883 bool InstancePtrTracked =
false;
1884 if (
Func->hasThisPointer()) {
1885 size_t ArgSize =
Func->getArgSize() + VarArgSize;
1902 Func->isLambdaCallOperator()) {
1903 assert(ThisPtr.
isZero());
1906 Func->isDestructor()))
1909 if (
Func->isCopyOrMoveOperator() ||
Func->isCopyOrMoveConstructor()) {
1916 if (!
Func->isConstructor() && !
Func->isDestructor() &&
1926 InstancePtrTracked = (
Func->isConstructor() ||
Func->isDestructor());
1927 if (InstancePtrTracked)
1931 if (!
Func->isFullyCompiled())
1954 if (InstancePtrTracked)
1965 assert(S.
Current == FrameBefore);
1975 auto depth = [](
PtrView V) ->
unsigned {
1977 while (!
V.isRoot()) {
1994 assert(depth(TypePtr) >= depth(InitPtr));
1995 unsigned D = depth(TypePtr) - depth(InitPtr);
1996 for (
unsigned I = 0; I != D; ++I)
2007 S.
FFDiag(E, diag::note_constexpr_polymorphic_unknown_dynamic_type)
2014 DynamicDecl =
DynamicType->getPointeeCXXRecordDecl();
2022 return DynamicDecl !=
nullptr;
2058 for (
const Record::Base &B : R->bases()) {
2061 N.Offset = *N.Offset + B.Offset;
2069 bool IsReferenceCast) {
2073 if (Ptr.isConstexprUnknown()) {
2078 S.
FFDiag(E, diag::note_constexpr_polymorphic_unknown_dynamic_type)
2083 if (!Ptr.isBlockPointer() || !Ptr.getRecord())
2086 if (!Ptr.isInitialized())
2097 assert(LimitedPtr.
block() == Ptr.block());
2104 if (TargetType->isVoidType()) {
2109 assert(!TargetType.isNull());
2110 assert(!TargetType->isVoidType());
2111 assert(TargetType->isRecordType());
2118 assert(P.getRecord());
2122 auto baseIsPrivate = [&](
PtrView P) ->
bool {
2123 if (P.isRoot() || !P.isBaseClass())
2127 getRecord(P.getBase())->isDerivedFrom(getRecord(P), Paths);
2128 assert(std::distance(Paths.
begin(), Paths.
end()) == 1);
2134 DiagPrivateBase = 0,
2137 DiagPrivateSibling = 3
2140 auto diag = [&](
int DiagKind,
QualType ResultType) ->
bool {
2142 if (!IsReferenceCast) {
2148 diag::note_constexpr_dynamic_cast_to_reference_failed)
2149 << DiagKind << ResultType <<
DynamicType << TargetType;
2158 getRecord(LimitedPtr)
2159 ->isDerivedFrom(TargetType->getAsCXXRecordDecl(), Paths);
2160 if (std::distance(Paths.
begin(), Paths.
end()) == 0 &&
2161 !typesMatch(LimitedPtr.
getType(), TargetType)) {
2162 return diag(DiagNoBase, TargetType);
2167 if (baseIsPrivate(Ptr.view()))
2168 return diag(DiagPrivateBase, Ptr.getType());
2170 std::optional<PtrView>
Result;
2172 for (
PtrView Iter = Ptr.view();;) {
2173 if (Iter.isRoot() || !Iter.isBaseClass())
2176 if (typesMatch(TargetType, Iter.getType())) {
2181 Iter = Iter.getBase();
2187 if (baseIsPrivate(*
Result))
2188 return diag(DiagPrivateBase,
Result->getType());
2195 for (
PtrView Iter = LimitedPtr;;) {
2201 Result = Iter.atField(*R.Offset);
2203 }
else if (R.Ambiguous) {
2209 Iter = Iter.getBase();
2210 if (Iter.isRoot() || !Iter.isBaseClass())
2215 return diag(DiagAmbiguous, TargetType);
2219 if (baseIsPrivate(*
Result))
2220 return diag(DiagPrivateSibling, TargetType);
2226 return diag(DiagNoBase, TargetType);
2230 uint32_t VarArgSize) {
2231 assert(
Func->hasThisPointer());
2232 assert(
Func->isVirtual());
2233 size_t ArgSize =
Func->getArgSize() + VarArgSize;
2245 assert(DynamicDecl);
2251 if (StaticDecl != DynamicDecl) {
2258 Overrider = InitialFunction;
2268 S.
Note(Callee->getLocation(), diag::note_declared_at);
2272 if (Overrider != InitialFunction) {
2285 if (
Func->getParentDecl()->isDerivedFrom(ThisFieldDecl)) {
2293 if (!
Call(S, OpPC,
Func, VarArgSize))
2298 if (Overrider != InitialFunction &&
2300 InitialFunction->getReturnType()->isPointerOrReferenceType()) {
2308 OverriderPointeeType))
2325 uint32_t BuiltinID) {
2328 if (BuiltinID == Builtin::BI__builtin_operator_new &&
2392 return CallVirt(S, OpPC, F, VarArgSize);
2394 return Call(S, OpPC, F, VarArgSize);
2401 for (
const Record::Field &Fi : R->fields()) {
2411 for (
unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
2427 if (!Ptr.isBlockPointer())
2438 if (!Ptr.isBlockPointer())
2449 for (
const Record::Field &Fi : R->fields())
2459 for (
unsigned I = 0; I != FieldDesc->getNumElems(); ++I)
2496 std::optional<uint64_t> ArraySize) {
2499 auto directBaseIsUnion = [](
const Pointer &Ptr) ->
bool {
2503 return R && R->isUnion();
2506 if (Ptr.
inUnion() && directBaseIsUnion(Ptr))
2563 NewExpr->getAllocatedType(),
2564 APInt(64,
static_cast<uint64_t
>(*ArraySize),
false),
nullptr,
2567 AllocType = NewExpr->getAllocatedType();
2570 unsigned StorageSize = 1;
2571 unsigned AllocSize = 1;
2572 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AllocType))
2573 AllocSize = CAT->getZExtSize();
2574 if (
const auto *CAT = dyn_cast<ConstantArrayType>(StorageType))
2575 StorageSize = CAT->getZExtSize();
2577 if (AllocSize > StorageSize ||
2581 diag::note_constexpr_placement_new_wrong_type)
2582 << StorageType << AllocType;
2596 if (
const auto *NewExpr = dyn_cast<CXXNewExpr>(E)) {
2597 const FunctionDecl *OperatorNew = NewExpr->getOperatorNew();
2599 if (NewExpr->getNumPlacementArgs() > 0) {
2610 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
2612 diag::note_constexpr_new_non_replaceable)
2616 NewExpr->getNumPlacementArgs() == 1 &&
2617 !OperatorNew->isReservedGlobalPlacementOperator()) {
2627 const FunctionDecl *OperatorDelete = DeleteExpr->getOperatorDelete();
2629 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
2631 diag::note_constexpr_new_non_replaceable)
2645 E->
getExprLoc(), diag::warn_fixedpoint_constant_overflow)
2648 S.
CCEDiag(E, diag::note_constexpr_overflow)
2656 diag::err_shufflevector_minus_one_is_undefined_behavior_constexpr)
2662 const Pointer &Ptr,
unsigned BitWidth) {
2664 S.
CCEDiag(E, diag::note_constexpr_invalid_cast)
2716 bool TargetIsUCharOrByte) {
2718 if (!HasIndeterminateBits)
2722 if (TargetIsUCharOrByte)
2727 S.
FFDiag(E, diag::note_constexpr_bit_cast_indet_dest)
2739 if (!ID.IsInitialized) {
2742 diag::note_constexpr_use_uninit_reference);
2759 if (!P.isBlockPointer())
2762 if (P.isConstexprUnknown()) {
2767 S.
FFDiag(E, diag::note_constexpr_polymorphic_unknown_dynamic_type)
2773 CanQualType T = P.stripBaseCasts().getType()->getCanonicalTypeUnqualified();
2779 Func && (
Func->isConstructor() ||
Func->isDestructor()) &&
2780 P.block() ==
Frame->getThis().block()) {
2782 Func->getParentDecl());
2794 S.
CCEDiag(E, diag::note_constexpr_typeid_polymorphic)
2795 << E->getExprOperand()->getType()
2796 << E->getExprOperand()->getSourceRange();
2810 StringRef LHSStr(LHSLit->getBytes());
2811 unsigned LHSLength = LHSStr.size();
2812 StringRef RHSStr(RHSLit->getBytes());
2813 unsigned RHSLength = RHSStr.size();
2815 int32_t IndexDiff = RHSOffset - LHSOffset;
2816 if (IndexDiff < 0) {
2817 if (
static_cast<int32_t
>(LHSLength) < -IndexDiff)
2819 LHSStr = LHSStr.drop_front(-IndexDiff);
2821 if (
static_cast<int32_t
>(RHSLength) < IndexDiff)
2823 RHSStr = RHSStr.drop_front(IndexDiff);
2826 unsigned ShorterCharWidth;
2829 if (LHSLength < RHSLength) {
2842 for (
unsigned NullByte : llvm::seq(ShorterCharWidth)) {
2843 if (Shorter.size() + NullByte >= Longer.size())
2845 if (Longer[Shorter.size() + NullByte])
2848 return Shorter == Longer.take_front(Shorter.size());
2855 if (!Val.singleWord()) {
2856 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
2857 Val.take(NewMemory);
2861 if (!Val.singleWord()) {
2862 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
2863 Val.take(NewMemory);
2867 if (!Val.singleWord()) {
2868 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
2869 Val.take(NewMemory);
2875 std::copy_n(Val.path(), PathLength, NewPath);
2876 Val.takePath(NewPath);
2880template <
typename T>
2883 if constexpr (std::is_same_v<T, MemberPointer>) {
2887 std::copy_n(Val.path(), PathLength, NewPath);
2888 Val.takePath(NewPath);
2890 auto &Val = Ptr.
deref<T>();
2891 if (!Val.singleWord()) {
2892 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
2893 Val.take(NewMemory);
2900 for (
const Record::Field &Fi : R->fields()) {
2901 if (Fi.Desc->isPrimitive()) {
2903 copyPrimitiveMemory<T>(S, Ptr.atField(Fi.Offset));
2913 unsigned NumElems = D->getNumElems();
2917 if (D->isPrimitiveArray()) {
2921 assert(NumElems >= 1);
2923 bool AllSingleWord =
true;
2925 if (!EP.
deref<T>().singleWord()) {
2927 AllSingleWord =
false;
2932 for (
unsigned I = 1; I != D->getNumElems(); ++I) {
2937 assert(D->isCompositeArray());
2938 for (
unsigned I = 0; I != D->getNumElems(); ++I) {
2963 S.
CCEDiag(Loc, diag::note_constexpr_invalid_cast)
2964 << diag::ConstexprInvalidCastKind::Reinterpret
2968 S.
CCEDiag(Loc, diag::note_constexpr_invalid_cast)
2969 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
2976 S.
FFDiag(E, diag::note_constexpr_access_volatile_type)
2977 <<
AK_Read << E->getSubExpr()->getType();
2985 S.
CCEDiag(Loc, diag::note_constexpr_invalid_cast)
2986 << diag::ConstexprInvalidCastKind::Dynamic;
2989 llvm_unreachable(
"Unhandled CastKind");
3016 if (MemberPtr.getPathLength() >= 2)
3017 Expected = MemberPtr.getPathEntry(MemberPtr.getPathLength() - 2);
3019 Expected = MemberPtr.getRecordDecl();
3032 unsigned OldPathLength = MemberPtr.getPathLength();
3033 unsigned NewPathLength = OldPathLength - 1;
3034 bool IsDerivedMember = NewPathLength != 0;
3036 std::copy_n(MemberPtr.path(), NewPathLength, NewPath);
3039 NewPath, IsDerivedMember));
3047 bool IsDerivedMember) {
3048 unsigned OldPathLength = MemberPtr.getPathLength();
3049 unsigned NewPathLength = OldPathLength + 1;
3052 std::copy_n(MemberPtr.path(), OldPathLength, NewPath);
3056 NewPath, IsDerivedMember));
3065 if (!Ptr.isDerivedMember() && Ptr.hasPath())
3068 bool IsDerivedMember = Ptr.isDerivedMember() || !Ptr.hasPath();
3077 if (!Ptr.isDerivedMember()) {
3094 if (!MP.isBaseCastPossible())
3105 const auto *FD = dyn_cast_if_present<FunctionDecl>(D);
3109 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
3116 if (!
Base.getRecord() ||
Base.getRecord()->getDecl() != MethodParent)
3133 unsigned NewPathLength = OldPathLength + 1;
3136 std::copy_n(MemberPtr.path(), OldPathLength, NewPath);
3140 MemberPtr.withPath(NewPathLength, NewPath, IsDerived));
3144template <
bool Signed>
3146 uint32_t BitWidth, uint32_t FPOI) {
3151 if ((Status & APFloat::opStatus::opInvalidOp) && F.
isFinite() &&
3179 return Op == OP_RetVoid || Op == OP_RetValue || Op == OP_NoRet ||
3180 Op == OP_RetSint8 || Op == OP_RetUint8 || Op == OP_RetSint16 ||
3181 Op == OP_RetUint16 || Op == OP_RetSint32 || Op == OP_RetUint32 ||
3182 Op == OP_RetSint64 || Op == OP_RetUint64 || Op == OP_RetIntAP ||
3183 Op == OP_RetIntAPS || Op == OP_RetBool || Op == OP_RetFixedPoint ||
3184 Op == OP_RetPtr || Op == OP_RetMemberPtr || Op == OP_RetFloat ||
3185 Op == OP_EndSpeculation;
3194#define GET_INTERPFN_DISPATCHERS
3195#include "Opcodes.inc"
3196#undef GET_INTERPFN_DISPATCHERS
3201#define GET_INTERPFN_LIST
3202#include "Opcodes.inc"
3203#undef GET_INTERPFN_LIST
3225 return InterpNext(S);
3253 [[maybe_unused]]
CodePtr PCBefore = S.
PC;
3254 size_t StackSizeBefore = S.
Stk.
size();
3260 assert(DepthBefore >= 1);
3263 auto SpeculativeInterp = [&S]() ->
bool {
3286 if (SpeculativeInterp()) {
3291 assert(S.
Stk.
size() == StackSizeBefore);
3297 assert(S.
Stk.
size() == StackSizeBefore);
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
static const FunctionDecl * getVirtualOperatorDelete(QualType T)
static PRESERVE_NONE bool RetValue(InterpState &S)
static bool CheckTemporary(InterpState &S, CodePtr OpPC, const Block *B, AccessKinds AK)
static bool CheckGlobal(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
static bool Jf(InterpState &S, CodePtr OpPC, int32_t Offset)
static bool Jmp(InterpState &S, CodePtr OpPC, int32_t Offset)
static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC, const ValueDecl *D, AccessKinds AK=AK_Read)
static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC, const ValueDecl *VD, AccessKinds AK=AK_Read)
static bool isModification(AccessKinds AK)
static void noteValueLocation(InterpState &S, const Block *B)
static void diagnoseMissingInitializer(InterpState &S, CodePtr OpPC, const ValueDecl *VD)
static bool Jt(InterpState &S, CodePtr OpPC, int32_t Offset)
static StringRef getIdentifier(const Token &Tok)
#define TYPE_SWITCH_ALLOC(Expr, B)
#define TYPE_SWITCH(Expr, B)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U) const
Determine whether two function types are the same, ignoring exception specifications in cases where t...
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool hasSimilarType(QualType T1, QualType T2) const
Determine if two types are similar, according to the C++ rules.
DiagnosticsEngine & getDiagnostics() const
const TargetInfo & getTargetInfo() const
CanQualType getCanonicalTagType(const TagDecl *TD) const
AccessSpecifier Access
The access along this inheritance path.
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
SourceLocation getLocation() const
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const
Calculates the [Min,Max) values the enum can store based on the NumPositiveBits and NumNegativeBits.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
LangOptions::FPExceptionModeKind getExceptionMode() const
static FPOptions getFromOpaqueInt(storage_type Value)
RoundingMode getRoundingMode() const
Represents a member of a struct/union/class.
Represents a function declaration or definition.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
QualType getReturnType() const
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
FunctionDecl * getDefinition()
Get the definition for this declaration.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
void addConst()
Add the const type qualifier to this QualType.
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Encodes a location in the source.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
CanQualType getCanonicalTypeUnqualified() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isAnyComplexType() const
bool isPointerOrReferenceType() const
bool isRecordType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isStaticDataMember() const
Determines whether this is a static data member.
A memory block, either on the stack or in the heap.
unsigned getSize() const
Returns the size of the block.
bool isExtern() const
Checks if the block is extern.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
bool isStatic() const
Checks if the block has static storage duration.
bool isTemporary() const
Checks if the block is temporary.
std::byte * rawData()
Returns a pointer to the raw data, including metadata.
bool isInitialized() const
Returns whether the data of this block has been initialized via invoking the Ctor func.
UnsignedOrNone getDeclID() const
Returns the declaration ID.
unsigned getEvalID() const
The Evaluation ID this block was created in.
bool isAccessible() const
Pointer into the code segment.
std::enable_if_t<!std::is_pointer< T >::value, T > read()
Reads data and advances the pointer.
Compilation context for expressions.
unsigned collectBaseOffset(const RecordDecl *BaseDecl, const RecordDecl *DerivedDecl) const
const Function * getOrCreateFunction(const FunctionDecl *FuncDecl)
ASTContext & getASTContext() const
Returns the AST context.
OptPrimType classify(QualType T) const
Classifies a type.
const CXXMethodDecl * getOverridingFunction(const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const
Manages dynamic memory allocations done during bytecode interpretation.
std::optional< Form > getAllocationForm(const Expr *Source) const
Checks whether the allocation done at the given source is an array allocation.
bool deallocate(const Expr *Source, const Block *BlockToDelete)
Deallocate the given source+block combination.
Wrapper around fixed point types.
std::string toDiagnosticString(const ASTContext &Ctx) const
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
APFloat::opStatus convertToInteger(APSInt &Result) const
APFloat getAPFloat() const
Base class for stack frames, shared between VM and walker.
bool hasExplicitThisPointer() const
Scope & getScope(unsigned Idx)
Returns a specific scope.
CodePtr getCodeBegin() const
Returns a pointer to the start of the code.
bool isDestructor() const
Checks if the function is a destructor.
bool isVirtual() const
Checks if the function is virtual.
bool hasNonNullAttr() const
bool isFullyCompiled() const
Checks if the function is fully done compiling.
bool isConstructor() const
Checks if the function is a constructor.
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
bool hasBody() const
Checks if the function already has a body attached.
unsigned getWrittenArgSize() const
unsigned getArgSize() const
Returns the size of the argument stack.
bool isLambdaStaticInvoker() const
Returns whether this function is a lambda static invoker, which we generate custom byte code for.
bool isValid() const
Checks if the function is valid to call.
If an IntegralAP is constructed from Memory, it DOES NOT OWN THAT MEMORY.
void copy(const APInt &V)
Wrapper around numeric types.
static std::enable_if_t<!std::is_same_v< ValT, IntegralKind >, Integral > from(ValT V, unsigned NumBits=0)
Frame storing local variables.
static void free(InterpFrame *F)
const Expr * getExpr(CodePtr PC) const
InterpFrame * Caller
The frame of the previous function.
SourceInfo getSource(CodePtr PC) const
Map a location to a source.
Block * getLocalBlock(unsigned Offset) const
SourceLocation getLocation(CodePtr PC) const
const Pointer & getThis() const
Returns the 'this' pointer.
unsigned MSVCConstexprAllowed
const Function * getFunction() const
Returns the current function.
SourceRange getRange(CodePtr PC) const
bool isBottomFrame() const
unsigned getArgSize() const
bool isRoot() const
Checks if the frame is a root frame - return should quit the interpreter.
bool hasThisPointer() const
Pointer getLocalPointer(unsigned Offset) const
Returns a pointer to a local variables.
unsigned getDepth() const
void destroy(unsigned Idx)
Invokes the destructors for a scope.
bool isStdFunction() const
static size_t allocSize(const Function *F)
Returns the number of bytes needed to allocate an InterpFrame for the given function.
void clearTo(size_t NewSize)
T pop()
Returns the value from the top of the stack and removes it.
void push(Tys &&...Args)
Constructs a value in place on the top of the stack.
size_t size() const
Returns the size of the stack in bytes.
void discard()
Discards the top value from the stack.
T & peek() const
Returns a reference to the value on the top of the stack.
bool lifetimeStartedInEvaluation(const Block *B) const
Context & getContext() const
bool initializingBlock(const Block *B) const
DynamicAllocator & getAllocator()
Context & Ctx
Interpreter Context.
bool noteStep(CodePtr OpPC)
Note that a step has been executed.
const unsigned EvalID
ID identifying this evaluation.
InterpStack & Stk
Temporary stack.
bool checkingConstantDestruction() const
Return if we're checking if a global variable has a constant destructor.
const VarDecl * EvaluatingDecl
Declaration we're initializing/evaluting, if any.
InterpFrame * Current
The current frame.
const CXXRecordDecl ** allocMemberPointerPath(unsigned Length)
llvm::SmallVector< PtrView > InitializingPtrs
List of blocks we're currently running either constructors or destructors for.
T allocAP(unsigned BitWidth)
unsigned SpeculationDepth
StdAllocatorCaller getStdAllocatorCaller(StringRef Name) const
bool inConstantContext() const
Program & P
Reference to the module containing all bytecode.
unsigned getPathLength() const
Return the length of the cast path.
PrimType value_or(PrimType PT) const
A pointer to a memory block, live or dead.
Pointer narrow() const
Restricts the scope of an array element pointer.
UnsignedOrNone getDeclID() const
Returns the declaration ID.
Pointer stripBaseCasts() const
Strip base casts from this Pointer.
bool isVolatile() const
Checks if an object or a subfield is volatile.
bool isInitialized() const
Checks if an object was initialized.
bool isStatic() const
Checks if the storage is static.
bool isDynamic() const
Checks if the storage has been dynamically allocated.
bool isZeroSizeArray() const
Checks if the pointer is pointing to a zero-size array.
Pointer atIndex(uint64_t Idx) const
Offsets a pointer inside an array.
bool isDummy() const
Checks if the pointer points to a dummy value.
Pointer atFieldSub(unsigned Off) const
Subtract the given offset from the current Base and Offset of the pointer.
bool isExtern() const
Checks if the storage is extern.
int64_t getIndex() const
Returns the index into an array.
bool isActive() const
Checks if the object is active.
bool isConst() const
Checks if an object or a subfield is mutable.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
T & deref() const
Dereferences the pointer, if it's live.
bool isMutable() const
Checks if the field is mutable.
bool isConstInMutable() const
unsigned getNumElems() const
Returns the number of elements.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
bool isIntegralPointer() const
QualType getType() const
Returns the type of the innermost field.
bool isArrayElement() const
Checks if the pointer points to an array.
bool pointsToStringLiteral() const
void initialize() const
Initializes a field.
bool isArrayRoot() const
Whether this array refers to an array, but not to the first element.
bool isLive() const
Checks if the pointer is live.
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
uint64_t getByteOffset() const
Returns the byte offset from the start.
bool isTypeidPointer() const
std::string toDiagnosticString(const ASTContext &Ctx) const
Converts the pointer to a string usable in diagnostics.
bool isZero() const
Checks if the pointer is null.
bool isConstexprUnknown() const
const IntPointer & asIntPointer() const
bool isRoot() const
Pointer points directly to a block.
const Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
void activate() const
Activates a field.
static bool pointToSameBlock(const Pointer &A, const Pointer &B)
Checks if both given pointers point to the same block.
bool isOnePastEnd() const
Checks if the index is one past end.
uint64_t getIntegerRepresentation() const
bool isPastEnd() const
Checks if the pointer points past the end of the object.
const FieldDecl * getField() const
Returns the field information.
Pointer expand() const
Expands a pointer to the containing array, undoing narrowing.
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
void startLifetime() const
Start the lifetime of this pointer.
bool isBlockPointer() const
const FunctionPointer & asFunctionPointer() const
const Block * block() const
bool isFunctionPointer() const
Pointer getDeclPtr() const
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool canBeInitialized() const
If this pointer has an InlineDescriptor we can use to initialize.
Lifetime getLifetime() const
bool isField() const
Checks if the item is a field in an object.
const Record * getRecord() const
Returns the record descriptor of a class.
UnsignedOrNone getCurrentDecl() const
Returns the current declaration ID.
Structure/Class descriptor.
const RecordDecl * getDecl() const
Returns the underlying declaration.
unsigned getNumVirtualBases() const
llvm::iterator_range< LocalVectorTy::const_reverse_iterator > locals_reverse() const
Describes the statement/declaration an opcode was generated from.
bool checkingForUndefinedBehavior() const
Are we checking an expression for overflow?
OptionalDiagnostic Note(SourceLocation Loc, diag::kind DiagId)
Add a note to a prior diagnostic.
OptionalDiagnostic FFDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation could not be folded (FF => FoldFailure)
ASTContext & getASTContext() const
bool noteUndefinedBehavior() const
Note that we hit something that was technically undefined behavior, but that we can evaluate past it ...
OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation does not produce a C++11 core constant expression.
const LangOptions & getLangOpts() const
bool checkingPotentialConstantExpression() const
Are we checking whether the expression is a potential constant expression?
Defines the clang::TargetInfo interface.
bool arePotentiallyOverlappingStringLiterals(const Pointer &LHS, const Pointer &RHS)
bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off)
bool GetMemberPtrBase(InterpState &S)
bool PseudoDtor(InterpState &S, CodePtr OpPC)
Ends the lifetime of the pop'd pointer.
static bool CheckCallDepth(InterpState &S, CodePtr OpPC)
const InterpFn InterpFunctions[]
static bool diagnoseCallableDecl(InterpState &S, CodePtr OpPC, const FunctionDecl *DiagDecl)
constexpr bool OpReturns(Opcode Op)
bool GetTypeid(InterpState &S, const Type *TypePtr, const Type *TypeInfoType)
Typeid support.
bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
static bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be initialized.
bool CheckFunctionDecl(InterpState &S, CodePtr OpPC, const FunctionDecl *FD)
Opcode. Check if the function decl can be called at compile time.
bool handleOverflow(InterpState &S, CodePtr OpPC, const T &SrcValue)
static bool appendToMemberPointer(InterpState &S, const MemberPointer &MemberPtr, int32_t BaseOffset, const RecordDecl *BaseDecl, bool IsDerivedMember)
static bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F)
bool StartThisLifetime(InterpState &S)
void cleanupAfterFunctionCall(InterpState &S, const Function *Func)
static bool runRecordDestructor(InterpState &S, CodePtr OpPC, const Pointer &BasePtr, const Descriptor *Desc)
bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc, AccessKinds AK)
Checks if the Descriptor is of a constexpr or const global variable.
bool GetTypeidPtr(InterpState &S, CodePtr OpPC, const Type *TypeInfoType)
bool LT(InterpState &S, CodePtr OpPC)
bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, uint32_t Offset)
Checks if the dowcast using the given offset is possible with the given pointer.
bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, DynamicAllocator::Form AllocForm, DynamicAllocator::Form DeleteForm, const Descriptor *D, const Expr *NewExpr)
Diagnose mismatched new[]/delete or new/delete[] pairs.
static void setLifeStateRecurse(PtrView Ptr, Lifetime L)
bool PushIgnoreDiags(InterpState &S)
bool CheckGlobalLoad(InterpState &S, CodePtr OpPC, const Block *B)
Checks a direct load of a primitive value from a global or local variable.
bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR)
We aleady know the given DeclRefExpr is invalid for some reason, now figure out why and print appropr...
bool EndLifetime(InterpState &S, CodePtr OpPC)
Ends the lifetime of the peek'd pointer.
static bool getDynamicDecl(InterpState &S, CodePtr OpPC, PtrView TypePtr, const CXXRecordDecl *&DynamicDecl)
bool CastMemberPtrDerivedPop(InterpState &S, int32_t Off, const RecordDecl *BaseDecl)
BaseToDerivedMemberPointer.
static DynamicCastResult findRecordBase(const ASTContext &Ctx, const Record *R, QualType Needle)
static bool CheckWeak(InterpState &S, CodePtr OpPC, const Block *B)
bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, unsigned BitWidth)
static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B)
bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off)
1) Peeks a Pointer 2) Pushes Pointer.atField(Off) on the stack
bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK, bool WillActivate)
static bool CheckNonNullArgs(InterpState &S, CodePtr OpPC, const Function *F, const CallExpr *CE, unsigned ArgSize)
static void finishGlobalRecurse(InterpState &S, const Pointer &Ptr)
bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if Ptr is a one-past-the-end pointer.
bool handleFixedPointOverflow(InterpState &S, CodePtr OpPC, const FixedPoint &FP)
bool PopIgnoreDiags(InterpState &S)
bool GetMemberPtrDecl(InterpState &S)
bool handleReference(InterpState &S, CodePtr OpPC, Block *B)
bool CheckBitCast(InterpState &S, CodePtr OpPC, const Type *TargetType, bool SrcIsVoidPtr)
bool CopyMemberPtrPath(InterpState &S, const RecordDecl *Entry, bool IsDerived)
Just append the given Entry to the MemberPointer's path.
static bool getField(InterpState &S, CodePtr OpPC, const Pointer &Ptr, uint32_t Off)
static void startLifetimeRecurse(PtrView Ptr)
static bool hasVirtualDestructor(QualType T)
bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a value can be loaded from a block.
static bool getBase(InterpState &S, CodePtr OpPC, const Pointer &Ptr, uint32_t Off, bool NullOK)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool CheckBCPResult(InterpState &S, const Pointer &Ptr)
PRESERVE_NONE bool EndSpeculation(InterpState &S)
bool diagnoseShiftFailure(InterpState &S, CodePtr OpPC, ShiftFailure Failure, const APSInt *Value, unsigned Bits)
bool CheckDynamicMemoryAllocation(InterpState &S, CodePtr OpPC)
Checks if dynamic memory allocation is available in the current language mode.
bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is live and accessible.
bool GetPtrDerivedPop(InterpState &S, CodePtr OpPC, uint32_t Off, bool NullOK, const Type *TargetType)
bool DiagTypeid(InterpState &S, CodePtr OpPC)
bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
This is not used by any of the opcodes directly.
static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, const Pointer &ThisPtr)
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED, const APSInt &Value)
bool isConstexprUnknown(const Block *B)
bool StartThisLifetime1(InterpState &S)
bool RVOPtr(InterpState &S)
bool InvalidDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR, bool InitializerFailed)
bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if a pointer is null.
bool CheckDeleteSource(InterpState &S, CodePtr OpPC, const Expr *Source, const Pointer &Ptr)
Check the source of the pointer passed to delete/delete[] has actually been heap allocated by us.
bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result, APFloat::opStatus Status, FPOptions FPO)
Checks if the result of a floating-point operation is valid in the current context.
PrimType
Enumeration of the primitive types of the VM.
static bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool IsCtor, bool IsDtor)
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, uint32_t BuiltinID)
Interpret a builtin function.
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
constexpr bool needsAlloc()
bool(*)(InterpState &) PRESERVE_NONE InterpFn
bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index)
bool CheckDummy(InterpState &S, CodePtr OpPC, const Block *B, AccessKinds AK)
Checks if a pointer is a dummy pointer.
static bool diagnoseOutOfLifetimeDestroy(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
static bool floatAPCast(InterpState &S, CodePtr OpPC, const Floating &F, uint32_t BitWidth, uint32_t FPOI)
bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E, std::optional< uint64_t > ArraySize)
Check if the initializer and storage types of a placement-new expression match.
bool checkDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool CheckRange(InterpState &S, CodePtr OpPC, PtrView Ptr, AccessKinds AK)
Checks if a pointer is in range.
bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T)
bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the array is offsetable.
bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off)
static void compileFunction(InterpState &S, const Function *Func)
bool CheckThis(InterpState &S, CodePtr OpPC)
Checks the 'this' pointer.
bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth, uint32_t FPOI)
bool CheckIntegralAddressCast(InterpState &S, CodePtr OpPC, unsigned BitWidth)
static void copyPrimitiveMemory(InterpState &S, const Pointer &Ptr, PrimType T)
bool Destroy(InterpState &S, CodePtr OpPC, uint32_t I)
bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr, AccessKinds AK)
Checks if a pointer points to a mutable field.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm, bool IsGlobalDelete)
bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E)
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE, uint32_t BuiltinID)
bool CheckLocalLoad(InterpState &S, CodePtr OpPC, const Block *B)
bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the variable has externally defined storage.
static bool CheckLifetime(InterpState &S, CodePtr OpPC, Lifetime LT, const Block *B, AccessKinds AK)
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool WillBeActivated)
Checks if a value can be stored in a block.
bool FinishInitGlobal(InterpState &S)
bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off, bool NullOK)
bool DiagnoseUninitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
static bool castBackMemberPointer(InterpState &S, const MemberPointer &MemberPtr, int32_t BaseOffset, const RecordDecl *BaseDecl)
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize, const CallExpr *CE)
bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth, uint32_t FPOI)
bool MarkDestroyed(InterpState &S, CodePtr OpPC)
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to const storage.
bool Interpret(InterpState &S)
Interpreter entry point.
bool GetMemberPtr(InterpState &S, const ValueDecl *D)
static PRESERVE_NONE bool BCP(InterpState &S, CodePtr OpPC, int32_t Offset, PrimType PT)
This is used to implement speculative execution via __builtin_constant_p when we generate bytecode.
bool CastMemberPtrBasePop(InterpState &S, int32_t Off, const RecordDecl *BaseDecl)
DerivedToBaseMemberPointer.
bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal)
bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestTypePtr, bool IsReferenceCast)
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ Success
Annotation was successful.
CheckSubobjectKind
The order of this enum is important for diagnostics.
@ Result
The result type of a method or function.
AccessKinds
Kinds of access we can perform on an object, for diagnostics.
OptionalUnsigned< unsigned > UnsignedOrNone
@ Off
Never emit colors regardless of the output stream.
U cast(CodeGen::Address addr)
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 int32_t
Describes a memory block created by an allocation site.
const bool IsConst
Flag indicating if the block is mutable.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const ValueDecl * asValueDecl() const
const Decl * asDecl() const
const Descriptor *const ElemDesc
Descriptor of the array element.
unsigned getMetadataSize() const
Returns the size of the metadata.
SourceLocation getLocation() const
QualType getDataType(const ASTContext &Ctx) const
unsigned getElemDataSize() const
Returns the element data size, i.e.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
const VarDecl * asVarDecl() const
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
const Expr * asExpr() const
bool isArray() const
Checks if the descriptor is of an array.
void setOffset(unsigned O)
void merge(DynamicCastResult C)
Descriptor used for global variables.
Inline descriptor embedded in structures and arrays.
std::optional< IntPointer > atOffset(const Context &Ctx, unsigned Offset) const
PtrView atField(unsigned Offset) const
const Record * getRecord() const
const Descriptor * getFieldDesc() const
const FieldDecl * getField() const
PtrView atIndex(unsigned Idx) const
void startLifetime() const
const Block * block() const
bool isOnePastEnd() const
void setLifeState(Lifetime L) const
Lifetime getLifetime() const
bool isZeroSizeArray() const
PtrView stripBaseCasts() const