Lines Matching refs:S

31 static bool RetValue(InterpState &S, CodePtr &Pt) {  in RetValue()  argument
39 static bool Jmp(InterpState &S, CodePtr &PC, int32_t Offset) { in Jmp() argument
44 static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset) { in Jt() argument
45 if (S.Stk.pop<bool>()) { in Jt()
51 static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset) { in Jf() argument
52 if (!S.Stk.pop<bool>()) { in Jf()
64 static bool BCP(InterpState &S, CodePtr &RealPC, int32_t Offset, PrimType PT) { in BCP() argument
66 size_t StackSizeBefore = S.Stk.size(); in BCP()
68 auto SpeculativeInterp = [&S, RealPC]() -> bool { in BCP()
69 const InterpFrame *StartFrame = S.Current; in BCP()
89 const auto &Ptr = S.Stk.pop<Pointer>(); in BCP()
90 assert(S.Stk.size() == StackSizeBefore); in BCP()
91 S.Stk.push<Integral<32, true>>( in BCP()
92 Integral<32, true>::from(CheckBCPResult(S, Ptr))); in BCP()
95 TYPE_SWITCH(PT, S.Stk.pop<T>();); in BCP()
96 assert(S.Stk.size() == StackSizeBefore); in BCP()
97 S.Stk.push<Integral<32, true>>(Integral<32, true>::from(1)); in BCP()
100 if (!S.inConstantContext()) in BCP()
101 return Invalid(S, RealPC); in BCP()
103 S.Stk.clearTo(StackSizeBefore); in BCP()
104 S.Stk.push<Integral<32, true>>(Integral<32, true>::from(0)); in BCP()
128 static void diagnoseMissingInitializer(InterpState &S, CodePtr OpPC, in diagnoseMissingInitializer() argument
130 const SourceInfo &E = S.Current->getSource(OpPC); in diagnoseMissingInitializer()
131 S.FFDiag(E, diag::note_constexpr_var_init_unknown, 1) << VD; in diagnoseMissingInitializer()
132 S.Note(VD->getLocation(), diag::note_declared_at) << VD->getSourceRange(); in diagnoseMissingInitializer()
135 static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
137 static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC, in diagnoseUnknownDecl() argument
141 if (!S.diagnosing()) in diagnoseUnknownDecl()
148 const SourceInfo &Loc = S.Current->getSource(OpPC); in diagnoseUnknownDecl()
149 if (S.getLangOpts().CPlusPlus11) { in diagnoseUnknownDecl()
150 S.FFDiag(Loc, diag::note_constexpr_function_param_value_unknown) << D; in diagnoseUnknownDecl()
151 S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange(); in diagnoseUnknownDecl()
153 S.FFDiag(Loc); in diagnoseUnknownDecl()
159 diagnoseNonConstVariable(S, OpPC, D); in diagnoseUnknownDecl()
162 diagnoseMissingInitializer(S, OpPC, VD); in diagnoseUnknownDecl()
164 const SourceInfo &Loc = S.Current->getSource(OpPC); in diagnoseUnknownDecl()
165 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD; in diagnoseUnknownDecl()
166 S.Note(VD->getLocation(), diag::note_declared_at); in diagnoseUnknownDecl()
173 static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC, in diagnoseNonConstVariable() argument
175 if (!S.diagnosing()) in diagnoseNonConstVariable()
178 const SourceInfo &Loc = S.Current->getSource(OpPC); in diagnoseNonConstVariable()
179 if (!S.getLangOpts().CPlusPlus) { in diagnoseNonConstVariable()
180 S.FFDiag(Loc); in diagnoseNonConstVariable()
187 diagnoseMissingInitializer(S, OpPC, VD); in diagnoseNonConstVariable()
197 S.FFDiag(Loc, diag::note_constexpr_ltor_non_const_int, 1) << VD; in diagnoseNonConstVariable()
198 S.Note(VD->getLocation(), diag::note_declared_at); in diagnoseNonConstVariable()
202 S.FFDiag(Loc, in diagnoseNonConstVariable()
203 S.getLangOpts().CPlusPlus11 ? diag::note_constexpr_ltor_non_constexpr in diagnoseNonConstVariable()
207 S.Note(VD->getLocation(), diag::note_declared_at); in diagnoseNonConstVariable()
210 static bool CheckTemporary(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckTemporary() argument
224 if (!MTE->isUsableInConstantExpressions(S.getASTContext()) && in CheckTemporary()
225 Ptr.block()->getEvalID() != S.Ctx.getEvalID()) { in CheckTemporary()
226 const SourceInfo &E = S.Current->getSource(OpPC); in CheckTemporary()
227 S.FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK; in CheckTemporary()
228 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here); in CheckTemporary()
235 static bool CheckGlobal(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckGlobal() argument
240 if (S.P.getCurrentDecl() == ID) in CheckGlobal()
243 S.FFDiag(S.Current->getLocation(OpPC), diag::note_constexpr_modify_global); in CheckGlobal()
251 static void popArg(InterpState &S, const Expr *Arg) { in popArg() argument
252 PrimType Ty = S.getContext().classify(Arg).value_or(PT_Ptr); in popArg()
253 TYPE_SWITCH(Ty, S.Stk.discard<T>()); in popArg()
256 void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC, in cleanupAfterFunctionCall() argument
258 assert(S.Current); in cleanupAfterFunctionCall()
261 if (S.Current->Caller && Func->isVariadic()) { in cleanupAfterFunctionCall()
268 const Expr *CallSite = S.Current->Caller->getExpr(S.Current->getRetPC()); in cleanupAfterFunctionCall()
283 popArg(S, A); in cleanupAfterFunctionCall()
290 TYPE_SWITCH(Ty, S.Stk.discard<T>()); in cleanupAfterFunctionCall()
303 bool CheckBCPResult(InterpState &S, const Pointer &Ptr) { in CheckBCPResult() argument
323 bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckActive() argument
379 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckActive()
380 S.FFDiag(Loc, diag::note_constexpr_access_inactive_union_member) in CheckActive()
385 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckExtern() argument
390 (Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl)) in CheckExtern()
393 if (S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus && in CheckExtern()
398 diagnoseNonConstVariable(S, OpPC, VD); in CheckExtern()
402 bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckArray() argument
405 const SourceInfo &E = S.Current->getSource(OpPC); in CheckArray()
406 S.FFDiag(E, diag::note_constexpr_unsized_array_indexed); in CheckArray()
410 bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckLive() argument
413 const auto &Src = S.Current->getSource(OpPC); in CheckLive()
416 S.FFDiag(Src, diag::note_constexpr_null_subobject) << CSK_Field; in CheckLive()
418 S.FFDiag(Src, diag::note_constexpr_access_null) << AK; in CheckLive()
424 const auto &Src = S.Current->getSource(OpPC); in CheckLive()
427 S.FFDiag(Src, diag::note_constexpr_access_deleted_object) << AK; in CheckLive()
428 } else if (!S.checkingPotentialConstantExpression()) { in CheckLive()
430 S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp; in CheckLive()
433 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here); in CheckLive()
435 S.Note(Ptr.getDeclLoc(), diag::note_declared_at); in CheckLive()
444 bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) { in CheckConstant() argument
448 if (!D || D == S.EvaluatingDecl || D->isConstexpr()) in CheckConstant()
454 if (const auto *VD = dyn_cast_if_present<VarDecl>(S.EvaluatingDecl); in CheckConstant()
455 VD && VD->isConstexpr() && S.getLangOpts().C23) in CheckConstant()
456 return Invalid(S, OpPC); in CheckConstant()
459 bool IsConstant = T.isConstant(S.getASTContext()); in CheckConstant()
462 diagnoseNonConstVariable(S, OpPC, D); in CheckConstant()
469 if (S.getLangOpts().CPlusPlus) { in CheckConstant()
470 S.CCEDiag(S.Current->getLocation(OpPC), in CheckConstant()
471 S.getLangOpts().CPlusPlus11 in CheckConstant()
476 S.Note(D->getLocation(), diag::note_declared_at); in CheckConstant()
478 S.CCEDiag(S.Current->getLocation(OpPC)); in CheckConstant()
484 if (!T->getPointeeType().isConstant(S.getASTContext()) || in CheckConstant()
485 !S.getLangOpts().CPlusPlus11) { in CheckConstant()
486 diagnoseNonConstVariable(S, OpPC, D); in CheckConstant()
492 diagnoseNonConstVariable(S, OpPC, D); in CheckConstant()
496 static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckConstant() argument
501 return CheckConstant(S, OpPC, Ptr.getDeclDesc()); in CheckConstant()
504 bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckNull() argument
508 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckNull()
509 S.FFDiag(Loc, diag::note_constexpr_null_subobject) in CheckNull()
510 << CSK << S.Current->getRange(OpPC); in CheckNull()
515 bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckRange() argument
519 if (S.getLangOpts().CPlusPlus) { in CheckRange()
520 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckRange()
521 S.FFDiag(Loc, diag::note_constexpr_access_past_end) in CheckRange()
522 << AK << S.Current->getRange(OpPC); in CheckRange()
527 bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckRange() argument
531 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckRange()
532 S.FFDiag(Loc, diag::note_constexpr_past_end_subobject) in CheckRange()
533 << CSK << S.Current->getRange(OpPC); in CheckRange()
537 bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckSubobject() argument
542 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckSubobject()
543 S.FFDiag(Loc, diag::note_constexpr_past_end_subobject) in CheckSubobject()
544 << CSK << S.Current->getRange(OpPC); in CheckSubobject()
548 bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckDowncast() argument
558 const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC)); in CheckDowncast()
562 S.CCEDiag(E, diag::note_constexpr_invalid_downcast) in CheckDowncast()
568 bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckConst() argument
578 if (llvm::find(S.InitializingBlocks, Ptr.block())) in CheckConst()
582 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckConst()
583 S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty; in CheckConst()
587 bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckMutable() argument
594 if (S.getLangOpts().CPlusPlus14 && in CheckMutable()
595 Ptr.block()->getEvalID() == S.Ctx.getEvalID()) { in CheckMutable()
600 if (!S.inConstantContext() && isConstexprUnknown(Ptr)) in CheckMutable()
605 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckMutable()
607 S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK_Read << Field; in CheckMutable()
608 S.Note(Field->getLocation(), diag::note_declared_at); in CheckMutable()
612 static bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckVolatile() argument
619 if (!S.getLangOpts().CPlusPlus) in CheckVolatile()
620 return Invalid(S, OpPC); in CheckVolatile()
648 S.FFDiag(S.Current->getLocation(OpPC), in CheckVolatile()
651 S.Note(Loc, diag::note_constexpr_volatile_here) << DiagKind; in CheckVolatile()
655 bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckInitialized() argument
665 if (VD == S.EvaluatingDecl && in CheckInitialized()
666 !(S.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType())) { in CheckInitialized()
667 if (!S.getLangOpts().CPlusPlus14 && in CheckInitialized()
668 !VD->getType().isConstant(S.getASTContext())) { in CheckInitialized()
670 diagnoseNonConstVariable(S, OpPC, VD); in CheckInitialized()
672 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckInitialized()
674 S.FFDiag(Loc, diag::note_constexpr_access_uninit) in CheckInitialized()
681 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckInitialized()
682 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD; in CheckInitialized()
683 S.Note(VD->getLocation(), diag::note_declared_at); in CheckInitialized()
685 diagnoseMissingInitializer(S, OpPC, VD); in CheckInitialized()
690 if (!S.checkingPotentialConstantExpression()) { in CheckInitialized()
691 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit) in CheckInitialized()
692 << AK << /*uninitialized=*/true << S.Current->getRange(OpPC); in CheckInitialized()
697 static bool CheckLifetime(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckLifetime() argument
702 if (!S.checkingPotentialConstantExpression()) { in CheckLifetime()
703 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit) in CheckLifetime()
704 << AK << /*uninitialized=*/false << S.Current->getRange(OpPC); in CheckLifetime()
709 bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckGlobalInitialized() argument
713 assert(S.getLangOpts().CPlusPlus); in CheckGlobalInitialized()
716 VD->mightBeUsableInConstantExpressions(S.getASTContext())) || in CheckGlobalInitialized()
717 (S.getLangOpts().OpenCL && !S.getLangOpts().CPlusPlus11 && in CheckGlobalInitialized()
718 !VD->hasICEInitializer(S.getASTContext()))) { in CheckGlobalInitialized()
719 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckGlobalInitialized()
720 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD; in CheckGlobalInitialized()
721 S.Note(VD->getLocation(), diag::note_declared_at); in CheckGlobalInitialized()
726 static bool CheckWeak(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckWeak() argument
732 S.FFDiag(S.Current->getLocation(OpPC), diag::note_constexpr_var_init_weak) in CheckWeak()
734 S.Note(VD->getLocation(), diag::note_declared_at); in CheckWeak()
739 bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckLoad() argument
741 if (!CheckLive(S, OpPC, Ptr, AK)) in CheckLoad()
743 if (!CheckExtern(S, OpPC, Ptr)) in CheckLoad()
745 if (!CheckConstant(S, OpPC, Ptr)) in CheckLoad()
747 if (!CheckDummy(S, OpPC, Ptr, AK)) in CheckLoad()
749 if (!CheckRange(S, OpPC, Ptr, AK)) in CheckLoad()
751 if (!CheckActive(S, OpPC, Ptr, AK)) in CheckLoad()
753 if (!CheckLifetime(S, OpPC, Ptr, AK)) in CheckLoad()
755 if (!CheckInitialized(S, OpPC, Ptr, AK)) in CheckLoad()
757 if (!CheckTemporary(S, OpPC, Ptr, AK)) in CheckLoad()
759 if (!CheckWeak(S, OpPC, Ptr)) in CheckLoad()
761 if (!CheckMutable(S, OpPC, Ptr)) in CheckLoad()
763 if (!CheckVolatile(S, OpPC, Ptr, AK)) in CheckLoad()
770 bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckFinalLoad() argument
771 if (!CheckLive(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
773 if (!CheckConstant(S, OpPC, Ptr)) in CheckFinalLoad()
776 if (!CheckDummy(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
778 if (!CheckExtern(S, OpPC, Ptr)) in CheckFinalLoad()
780 if (!CheckRange(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
782 if (!CheckActive(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
784 if (!CheckLifetime(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
786 if (!CheckInitialized(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
788 if (!CheckTemporary(S, OpPC, Ptr, AK_Read)) in CheckFinalLoad()
790 if (!CheckWeak(S, OpPC, Ptr)) in CheckFinalLoad()
792 if (!CheckMutable(S, OpPC, Ptr)) in CheckFinalLoad()
797 bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckStore() argument
798 if (!CheckLive(S, OpPC, Ptr, AK_Assign)) in CheckStore()
800 if (!CheckDummy(S, OpPC, Ptr, AK_Assign)) in CheckStore()
802 if (!CheckLifetime(S, OpPC, Ptr, AK_Assign)) in CheckStore()
804 if (!CheckExtern(S, OpPC, Ptr)) in CheckStore()
806 if (!CheckRange(S, OpPC, Ptr, AK_Assign)) in CheckStore()
808 if (!CheckGlobal(S, OpPC, Ptr)) in CheckStore()
810 if (!CheckConst(S, OpPC, Ptr)) in CheckStore()
812 if (!S.inConstantContext() && isConstexprUnknown(Ptr)) in CheckStore()
817 bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckInvoke() argument
818 if (!CheckLive(S, OpPC, Ptr, AK_MemberCall)) in CheckInvoke()
821 if (!CheckExtern(S, OpPC, Ptr)) in CheckInvoke()
823 if (!CheckRange(S, OpPC, Ptr, AK_MemberCall)) in CheckInvoke()
829 bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckInit() argument
830 if (!CheckLive(S, OpPC, Ptr, AK_Assign)) in CheckInit()
832 if (!CheckRange(S, OpPC, Ptr, AK_Assign)) in CheckInit()
837 bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) { in CheckCallable() argument
839 if (F->isVirtual() && !S.getLangOpts().CPlusPlus20) { in CheckCallable()
840 const SourceLocation &Loc = S.Current->getLocation(OpPC); in CheckCallable()
841 S.CCEDiag(Loc, diag::note_constexpr_virtual_call); in CheckCallable()
845 if (S.checkingPotentialConstantExpression() && S.Current->getDepth() != 0) in CheckCallable()
859 return Invalid(S, OpPC); in CheckCallable()
862 if (S.Current->getLocation(OpPC).isMacroID() && in CheckCallable()
870 S.FFDiag(S.Current->getLocation(OpPC), in CheckCallable()
876 if (S.getLangOpts().CPlusPlus11) { in CheckCallable()
901 S.FFDiag(S.Current->getLocation(OpPC), in CheckCallable()
904 S.Note(DiagDecl->getLocation(), diag::note_declared_at); in CheckCallable()
912 S.checkingPotentialConstantExpression()) in CheckCallable()
921 S.FFDiag(S.Current->getLocation(OpPC), in CheckCallable()
926 S.Note(DiagDecl->getDefinition()->getLocation(), in CheckCallable()
929 S.Note(DiagDecl->getLocation(), diag::note_declared_at); in CheckCallable()
932 S.FFDiag(S.Current->getLocation(OpPC), in CheckCallable()
939 bool CheckCallDepth(InterpState &S, CodePtr OpPC) { in CheckCallDepth() argument
940 if ((S.Current->getDepth() + 1) > S.getLangOpts().ConstexprCallDepth) { in CheckCallDepth()
941 S.FFDiag(S.Current->getSource(OpPC), in CheckCallDepth()
943 << S.getLangOpts().ConstexprCallDepth; in CheckCallDepth()
950 bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This) { in CheckThis() argument
954 const Expr *E = S.Current->getExpr(OpPC); in CheckThis()
955 if (S.getLangOpts().CPlusPlus11) { in CheckThis()
959 S.FFDiag(E, diag::note_constexpr_this) << IsImplicit; in CheckThis()
961 S.FFDiag(E); in CheckThis()
967 bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result, in CheckFloatResult() argument
974 const SourceInfo &E = S.Current->getSource(OpPC); in CheckFloatResult()
975 S.CCEDiag(E, diag::note_constexpr_float_arithmetic) in CheckFloatResult()
976 << /*NaN=*/true << S.Current->getRange(OpPC); in CheckFloatResult()
977 return S.noteUndefinedBehavior(); in CheckFloatResult()
982 if (S.inConstantContext()) in CheckFloatResult()
989 const SourceInfo &E = S.Current->getSource(OpPC); in CheckFloatResult()
990 S.FFDiag(E, diag::note_constexpr_dynamic_rounding); in CheckFloatResult()
998 const SourceInfo &E = S.Current->getSource(OpPC); in CheckFloatResult()
999 S.FFDiag(E, diag::note_constexpr_float_arithmetic_strict); in CheckFloatResult()
1005 const SourceInfo &E = S.Current->getSource(OpPC); in CheckFloatResult()
1007 S.FFDiag(E); in CheckFloatResult()
1014 bool CheckDynamicMemoryAllocation(InterpState &S, CodePtr OpPC) { in CheckDynamicMemoryAllocation() argument
1015 if (S.getLangOpts().CPlusPlus20) in CheckDynamicMemoryAllocation()
1018 const SourceInfo &E = S.Current->getSource(OpPC); in CheckDynamicMemoryAllocation()
1019 S.CCEDiag(E, diag::note_constexpr_new); in CheckDynamicMemoryAllocation()
1023 bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, in CheckNewDeleteForms() argument
1030 QualType TypeToDiagnose = D->getDataType(S.getASTContext()); in CheckNewDeleteForms()
1032 const SourceInfo &E = S.Current->getSource(OpPC); in CheckNewDeleteForms()
1033 S.FFDiag(E, diag::note_constexpr_new_delete_mismatch) in CheckNewDeleteForms()
1036 S.Note(NewExpr->getExprLoc(), diag::note_constexpr_dynamic_alloc_here) in CheckNewDeleteForms()
1041 bool CheckDeleteSource(InterpState &S, CodePtr OpPC, const Expr *Source, in CheckDeleteSource() argument
1056 const SourceInfo &Loc = S.Current->getSource(OpPC); in CheckDeleteSource()
1057 S.FFDiag(Loc, diag::note_constexpr_delete_not_heap_alloc) in CheckDeleteSource()
1058 << Ptr.toDiagnosticString(S.getASTContext()); in CheckDeleteSource()
1061 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here); in CheckDeleteSource()
1063 S.Note(Ptr.getDeclLoc(), diag::note_declared_at); in CheckDeleteSource()
1069 bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR) { in CheckDeclRef() argument
1071 return diagnoseUnknownDecl(S, OpPC, D); in CheckDeclRef()
1074 bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in CheckDummy() argument
1085 return diagnoseUnknownDecl(S, OpPC, D); in CheckDummy()
1087 if (AK == AK_Destroy || S.getLangOpts().CPlusPlus14) { in CheckDummy()
1088 const SourceInfo &E = S.Current->getSource(OpPC); in CheckDummy()
1089 S.FFDiag(E, diag::note_constexpr_modify_global); in CheckDummy()
1094 bool CheckNonNullArgs(InterpState &S, CodePtr OpPC, const Function *F, in CheckNonNullArgs() argument
1102 const Pointer &ArgPtr = S.Stk.peek<Pointer>(ArgSize - Offset); in CheckNonNullArgs()
1104 const SourceLocation &Loc = S.Current->getLocation(OpPC); in CheckNonNullArgs()
1105 S.CCEDiag(Loc, diag::note_non_null_attribute_failed); in CheckNonNullArgs()
1110 Offset += align(primSize(S.Ctx.classify(Arg).value_or(PT_Ptr))); in CheckNonNullArgs()
1116 static bool runRecordDestructor(InterpState &S, CodePtr OpPC, in runRecordDestructor() argument
1123 if (Pointer::pointToSameBlock(BasePtr, S.Current->getThis()) && in runRecordDestructor()
1124 S.Current->getFunction()->isDestructor()) { in runRecordDestructor()
1125 const SourceInfo &Loc = S.Current->getSource(OpPC); in runRecordDestructor()
1126 S.FFDiag(Loc, diag::note_constexpr_double_destroy); in runRecordDestructor()
1133 const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor); in runRecordDestructor()
1137 S.Stk.push<Pointer>(BasePtr); in runRecordDestructor()
1138 if (!Call(S, OpPC, DtorFunc, 0)) in runRecordDestructor()
1144 static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) { in RunDestructors() argument
1162 if (!runRecordDestructor(S, OpPC, RP.atIndex(I).narrow(), ElemDesc)) in RunDestructors()
1169 return runRecordDestructor(S, OpPC, Pointer(const_cast<Block *>(B)), Desc); in RunDestructors()
1179 bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm, in Free() argument
1181 if (!CheckDynamicMemoryAllocation(S, OpPC)) in Free()
1184 DynamicAllocator &Allocator = S.getAllocator(); in Free()
1191 Pointer Ptr = S.Stk.pop<Pointer>(); in Free()
1212 if (!CheckNewDeleteForms(S, OpPC, *AllocForm, DeleteForm, BlockDesc, in Free()
1221 S.FFDiag(S.Current->getSource(OpPC), in Free()
1229 const SourceInfo &Loc = S.Current->getSource(OpPC); in Free()
1230 S.FFDiag(Loc, diag::note_constexpr_delete_subobject) in Free()
1231 << Ptr.toDiagnosticString(S.getASTContext()) << Ptr.isOnePastEnd(); in Free()
1235 if (!CheckDeleteSource(S, OpPC, Source, Ptr)) in Free()
1254 S.FFDiag(S.Current->getSource(OpPC), in Free()
1265 if (!RunDestructors(S, OpPC, BlockToDelete)) in Free()
1268 if (!Allocator.deallocate(Source, BlockToDelete, S)) { in Free()
1270 const SourceInfo &Loc = S.Current->getSource(OpPC); in Free()
1271 S.FFDiag(Loc, diag::note_constexpr_double_delete); in Free()
1278 void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED, in diagnoseEnumValue() argument
1280 if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr()) in diagnoseEnumValue()
1290 const SourceLocation &Loc = S.Current->getLocation(OpPC); in diagnoseEnumValue()
1291 S.CCEDiag(Loc, diag::note_constexpr_unscoped_enum_out_of_range) in diagnoseEnumValue()
1295 const SourceLocation &Loc = S.Current->getLocation(OpPC); in diagnoseEnumValue()
1296 S.CCEDiag(Loc, diag::note_constexpr_unscoped_enum_out_of_range) in diagnoseEnumValue()
1302 bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) { in CheckLiteralType() argument
1304 assert(!S.getLangOpts().CPlusPlus23); in CheckLiteralType()
1320 if (S.Current->getFunction() && S.Current->getFunction()->isConstructor() && in CheckLiteralType()
1321 S.Current->getThis().getDeclDesc()->asDecl() == S.EvaluatingDecl) { in CheckLiteralType()
1325 const Expr *E = S.Current->getExpr(OpPC); in CheckLiteralType()
1326 if (S.getLangOpts().CPlusPlus11) in CheckLiteralType()
1327 S.FFDiag(E, diag::note_constexpr_nonliteral) << E->getType(); in CheckLiteralType()
1329 S.FFDiag(E, diag::note_invalid_subexpr_in_const_expr); in CheckLiteralType()
1333 static bool getField(InterpState &S, CodePtr OpPC, const Pointer &Ptr, in getField() argument
1335 if (S.getLangOpts().CPlusPlus && S.inConstantContext() && in getField()
1336 !CheckNull(S, OpPC, Ptr, CSK_Field)) in getField()
1339 if (!CheckRange(S, OpPC, Ptr, CSK_Field)) in getField()
1341 if (!CheckArray(S, OpPC, Ptr)) in getField()
1343 if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) in getField()
1347 S.Stk.push<Pointer>(Ptr.asIntPointer().atOffset(S.getASTContext(), Off)); in getField()
1355 S.FFDiag(S.Current->getSource(OpPC), in getField()
1357 << AK_Read << Ptr.toDiagnosticString(S.getASTContext()); in getField()
1364 S.Stk.push<Pointer>(Ptr.atField(Off)); in getField()
1368 bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) { in GetPtrField() argument
1369 const auto &Ptr = S.Stk.peek<Pointer>(); in GetPtrField()
1370 return getField(S, OpPC, Ptr, Off); in GetPtrField()
1373 bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off) { in GetPtrFieldPop() argument
1374 const auto &Ptr = S.Stk.pop<Pointer>(); in GetPtrFieldPop()
1375 return getField(S, OpPC, Ptr, Off); in GetPtrFieldPop()
1378 static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, in checkConstructor() argument
1394 S.FFDiag(S.Current->getLocation(OpPC), diag::note_constexpr_virtual_base) in checkConstructor()
1399 bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { in CheckDestructor() argument
1400 if (!CheckLive(S, OpPC, Ptr, AK_Destroy)) in CheckDestructor()
1402 if (!CheckTemporary(S, OpPC, Ptr, AK_Destroy)) in CheckDestructor()
1404 if (!CheckRange(S, OpPC, Ptr, AK_Destroy)) in CheckDestructor()
1409 const SourceInfo &E = S.Current->getSource(OpPC); in CheckDestructor()
1410 S.FFDiag(E, diag::note_constexpr_modify_global); in CheckDestructor()
1413 return CheckActive(S, OpPC, Ptr, AK_Destroy); in CheckDestructor()
1416 static void compileFunction(InterpState &S, const Function *Func) { in compileFunction() argument
1417 Compiler<ByteCodeEmitter>(S.getContext(), S.P) in compileFunction()
1422 bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func, in CallVar() argument
1427 const Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset); in CallVar()
1433 if (!(S.Current->getFunction() && in CallVar()
1434 S.Current->getFunction()->isLambdaStaticInvoker() && in CallVar()
1436 if (!CheckInvoke(S, OpPC, ThisPtr)) in CallVar()
1440 if (S.checkingPotentialConstantExpression()) in CallVar()
1445 compileFunction(S, Func); in CallVar()
1447 if (!CheckCallable(S, OpPC, Func)) in CallVar()
1450 if (!CheckCallDepth(S, OpPC)) in CallVar()
1453 auto NewFrame = std::make_unique<InterpFrame>(S, Func, OpPC, VarArgSize); in CallVar()
1454 InterpFrame *FrameBefore = S.Current; in CallVar()
1455 S.Current = NewFrame.get(); in CallVar()
1460 if (Interpret(S)) { in CallVar()
1462 assert(S.Current == FrameBefore); in CallVar()
1468 S.Current = FrameBefore; in CallVar()
1471 bool Call(InterpState &S, CodePtr OpPC, const Function *Func, in Call() argument
1475 cleanupAfterFunctionCall(S, OpPC, Func); in Call()
1483 const Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset); in Call()
1495 if (S.Current->getFunction() && in Call()
1496 S.Current->getFunction()->isLambdaStaticInvoker() && in Call()
1500 if (!CheckInvoke(S, OpPC, ThisPtr)) in Call()
1504 !CheckActive(S, OpPC, ThisPtr, AK_MemberCall)) in Call()
1508 if (Func->isConstructor() && !checkConstructor(S, OpPC, Func, ThisPtr)) in Call()
1510 if (Func->isDestructor() && !CheckDestructor(S, OpPC, ThisPtr)) in Call()
1514 S.InitializingBlocks.push_back(ThisPtr.block()); in Call()
1518 compileFunction(S, Func); in Call()
1520 if (!CheckCallable(S, OpPC, Func)) in Call()
1526 if (Func->hasThisPointer() && S.checkingPotentialConstantExpression() && in Call()
1530 if (!CheckCallDepth(S, OpPC)) in Call()
1533 auto NewFrame = std::make_unique<InterpFrame>(S, Func, OpPC, VarArgSize); in Call()
1534 InterpFrame *FrameBefore = S.Current; in Call()
1535 S.Current = NewFrame.get(); in Call()
1537 InterpStateCCOverride CCOverride(S, Func->isImmediate()); in Call()
1541 bool Success = Interpret(S); in Call()
1544 S.InitializingBlocks.pop_back(); in Call()
1549 S.Current = FrameBefore; in Call()
1554 assert(S.Current == FrameBefore); in Call()
1558 bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, in CallVirt() argument
1564 Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset); in CallVirt()
1568 compileFunction(S, Func); in CallVirt()
1574 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_pure_virtual_call, in CallVirt()
1577 S.Note(Callee->getLocation(), diag::note_declared_at); in CallVirt()
1597 const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction( in CallVirt()
1604 if (!S.getLangOpts().CPlusPlus20 && Overrider->isVirtual()) { in CallVirt()
1605 const Expr *E = S.Current->getExpr(OpPC); in CallVirt()
1606 S.CCEDiag(E, diag::note_constexpr_virtual_call) << E->getSourceRange(); in CallVirt()
1609 Func = S.getContext().getOrCreateFunction(Overrider); in CallVirt()
1622 if (!Call(S, OpPC, Func, VarArgSize)) in CallVirt()
1638 unsigned Offset = S.getContext().collectBaseOffset( in CallVirt()
1641 return GetPtrBasePop(S, OpPC, Offset, /*IsNullOK=*/true); in CallVirt()
1647 bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE, in CallBI() argument
1652 S.checkingPotentialConstantExpression()) in CallBI()
1655 return InterpretBuiltin(S, OpPC, CE, BuiltinID); in CallBI()
1658 bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize, in CallPtr() argument
1660 const Pointer &Ptr = S.Stk.pop<Pointer>(); in CallPtr()
1663 const auto *E = cast<CallExpr>(S.Current->getExpr(OpPC)); in CallPtr()
1664 S.FFDiag(E, diag::note_constexpr_null_callee) in CallPtr()
1670 return Invalid(S, OpPC); in CallPtr()
1677 return Invalid(S, OpPC); in CallPtr()
1681 if (S.Ctx.classify(F->getDecl()->getReturnType()) != in CallPtr()
1682 S.Ctx.classify(CE->getCallReturnType(S.getASTContext()))) in CallPtr()
1687 if (!CheckNonNullArgs(S, OpPC, F, CE, ArgSize)) in CallPtr()
1700 return CallVirt(S, OpPC, F, VarArgSize); in CallPtr()
1702 return Call(S, OpPC, F, VarArgSize); in CallPtr()
1724 bool StartLifetime(InterpState &S, CodePtr OpPC) { in StartLifetime() argument
1725 const auto &Ptr = S.Stk.peek<Pointer>(); in StartLifetime()
1726 if (!CheckDummy(S, OpPC, Ptr, AK_Destroy)) in StartLifetime()
1755 bool EndLifetime(InterpState &S, CodePtr OpPC) { in EndLifetime() argument
1756 const auto &Ptr = S.Stk.peek<Pointer>(); in EndLifetime()
1757 if (!CheckDummy(S, OpPC, Ptr, AK_Destroy)) in EndLifetime()
1764 bool EndLifetimePop(InterpState &S, CodePtr OpPC) { in EndLifetimePop() argument
1765 const auto &Ptr = S.Stk.pop<Pointer>(); in EndLifetimePop()
1766 if (!CheckDummy(S, OpPC, Ptr, AK_Destroy)) in EndLifetimePop()
1772 bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E, in CheckNewTypeMismatch() argument
1774 const Pointer &Ptr = S.Stk.peek<Pointer>(); in CheckNewTypeMismatch()
1778 if (!CheckTemporary(S, OpPC, Ptr, AK_Construct)) in CheckNewTypeMismatch()
1780 if (!CheckLive(S, OpPC, Ptr, AK_Construct)) in CheckNewTypeMismatch()
1782 if (!CheckDummy(S, OpPC, Ptr, AK_Construct)) in CheckNewTypeMismatch()
1787 if (!CheckLifetime(S, OpPC, P, AK_Construct)) in CheckNewTypeMismatch()
1794 if (!CheckExtern(S, OpPC, Ptr)) in CheckNewTypeMismatch()
1796 if (!CheckRange(S, OpPC, Ptr, AK_Construct)) in CheckNewTypeMismatch()
1798 if (!CheckGlobal(S, OpPC, Ptr)) in CheckNewTypeMismatch()
1800 if (!CheckConst(S, OpPC, Ptr)) in CheckNewTypeMismatch()
1802 if (!S.inConstantContext() && isConstexprUnknown(Ptr)) in CheckNewTypeMismatch()
1805 if (!InvalidNewDeleteExpr(S, OpPC, E)) in CheckNewTypeMismatch()
1809 QualType StorageType = Ptr.getFieldDesc()->getDataType(S.getASTContext()); in CheckNewTypeMismatch()
1810 const ASTContext &ASTCtx = S.getASTContext(); in CheckNewTypeMismatch()
1831 S.FFDiag(S.Current->getLocation(OpPC), in CheckNewTypeMismatch()
1839 return CheckActive(S, OpPC, Ptr, AK_Construct); in CheckNewTypeMismatch()
1844 bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E) { in InvalidNewDeleteExpr() argument
1852 if (S.getLangOpts().CPlusPlus26 || S.Current->isStdFunction()) in InvalidNewDeleteExpr()
1854 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_new_placement) in InvalidNewDeleteExpr()
1859 S.FFDiag(S.Current->getSource(OpPC), in InvalidNewDeleteExpr()
1863 } else if (!S.getLangOpts().CPlusPlus26 && in InvalidNewDeleteExpr()
1866 if (!S.getLangOpts().CPlusPlus26) { in InvalidNewDeleteExpr()
1867 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_new_placement) in InvalidNewDeleteExpr()
1878 S.FFDiag(S.Current->getSource(OpPC), in InvalidNewDeleteExpr()
1888 bool handleFixedPointOverflow(InterpState &S, CodePtr OpPC, in handleFixedPointOverflow() argument
1890 const Expr *E = S.Current->getExpr(OpPC); in handleFixedPointOverflow()
1891 if (S.checkingForUndefinedBehavior()) { in handleFixedPointOverflow()
1892 S.getASTContext().getDiagnostics().Report( in handleFixedPointOverflow()
1894 << FP.toDiagnosticString(S.getASTContext()) << E->getType(); in handleFixedPointOverflow()
1896 S.CCEDiag(E, diag::note_constexpr_overflow) in handleFixedPointOverflow()
1897 << FP.toDiagnosticString(S.getASTContext()) << E->getType(); in handleFixedPointOverflow()
1898 return S.noteUndefinedBehavior(); in handleFixedPointOverflow()
1901 bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index) { in InvalidShuffleVectorIndex() argument
1902 const SourceInfo &Loc = S.Current->getSource(OpPC); in InvalidShuffleVectorIndex()
1903 S.FFDiag(Loc, in InvalidShuffleVectorIndex()
1909 bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC, in CheckPointerToIntegralCast() argument
1916 const SourceInfo &E = S.Current->getSource(OpPC); in CheckPointerToIntegralCast()
1917 S.CCEDiag(E, diag::note_constexpr_invalid_cast) in CheckPointerToIntegralCast()
1918 << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC); in CheckPointerToIntegralCast()
1922 if (S.getASTContext().getTargetInfo().getPointerWidth(LangAS::Default) != in CheckPointerToIntegralCast()
1924 return Invalid(S, OpPC); in CheckPointerToIntegralCast()
1929 bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth) { in CastPointerIntegralAP() argument
1930 const Pointer &Ptr = S.Stk.pop<Pointer>(); in CastPointerIntegralAP()
1932 if (!CheckPointerToIntegralCast(S, OpPC, Ptr, BitWidth)) in CastPointerIntegralAP()
1935 auto Result = S.allocAP<IntegralAP<false>>(BitWidth); in CastPointerIntegralAP()
1938 S.Stk.push<IntegralAP<false>>(Result); in CastPointerIntegralAP()
1942 bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth) { in CastPointerIntegralAPS() argument
1943 const Pointer &Ptr = S.Stk.pop<Pointer>(); in CastPointerIntegralAPS()
1945 if (!CheckPointerToIntegralCast(S, OpPC, Ptr, BitWidth)) in CastPointerIntegralAPS()
1948 auto Result = S.allocAP<IntegralAP<true>>(BitWidth); in CastPointerIntegralAPS()
1951 S.Stk.push<IntegralAP<true>>(Result); in CastPointerIntegralAPS()
1955 bool CheckBitCast(InterpState &S, CodePtr OpPC, bool HasIndeterminateBits, in CheckBitCast() argument
1965 const Expr *E = S.Current->getExpr(OpPC); in CheckBitCast()
1967 S.FFDiag(E, diag::note_constexpr_bit_cast_indet_dest) in CheckBitCast()
1968 << ExprType << S.getLangOpts().CharIsSigned << E->getSourceRange(); in CheckBitCast()
1972 bool GetTypeid(InterpState &S, CodePtr OpPC, const Type *TypePtr, in GetTypeid() argument
1974 S.Stk.push<Pointer>(TypePtr, TypeInfoType); in GetTypeid()
1978 bool GetTypeidPtr(InterpState &S, CodePtr OpPC, const Type *TypeInfoType) { in GetTypeidPtr() argument
1979 const auto &P = S.Stk.pop<Pointer>(); in GetTypeidPtr()
1988 if (S.Current->getFunction()) { in GetTypeidPtr()
1989 for (const InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) { in GetTypeidPtr()
1999 S.Stk.push<Pointer>(T->getCanonicalTypeUnqualified().getTypePtr(), in GetTypeidPtr()
2004 bool DiagTypeid(InterpState &S, CodePtr OpPC) { in DiagTypeid() argument
2005 const auto *E = cast<CXXTypeidExpr>(S.Current->getExpr(OpPC)); in DiagTypeid()
2006 S.CCEDiag(E, diag::note_constexpr_typeid_polymorphic) in DiagTypeid()
2057 static void copyPrimitiveMemory(InterpState &S, const Pointer &Ptr, in copyPrimitiveMemory() argument
2063 uint64_t *NewMemory = new (S.P) uint64_t[Val.numWords()]; in copyPrimitiveMemory()
2069 uint64_t *NewMemory = new (S.P) uint64_t[Val.numWords()]; in copyPrimitiveMemory()
2075 uint64_t *NewMemory = new (S.P) uint64_t[Val.numWords()]; in copyPrimitiveMemory()
2082 static void copyPrimitiveMemory(InterpState &S, const Pointer &Ptr) { in copyPrimitiveMemory() argument
2086 uint64_t *NewMemory = new (S.P) uint64_t[Val.numWords()]; in copyPrimitiveMemory()
2091 static void finishGlobalRecurse(InterpState &S, const Pointer &Ptr) { in finishGlobalRecurse() argument
2096 copyPrimitiveMemory<T>(S, Ptr.atField(Fi.Offset)); in finishGlobalRecurse()
2098 copyPrimitiveMemory(S, Ptr.atField(Fi.Offset), Fi.Desc->getPrimType()); in finishGlobalRecurse()
2100 finishGlobalRecurse(S, Ptr.atField(Fi.Offset)); in finishGlobalRecurse()
2119 copyPrimitiveMemory<T>(S, EP); in finishGlobalRecurse()
2127 copyPrimitiveMemory(S, EP, PT); in finishGlobalRecurse()
2133 finishGlobalRecurse(S, EP); in finishGlobalRecurse()
2139 bool FinishInitGlobal(InterpState &S, CodePtr OpPC) { in FinishInitGlobal() argument
2140 const Pointer &Ptr = S.Stk.pop<Pointer>(); in FinishInitGlobal()
2142 finishGlobalRecurse(S, Ptr); in FinishInitGlobal()
2155 bool Interpret(InterpState &S) { in Interpret() argument
2160 const InterpFrame *StartFrame = S.Current; in Interpret()
2161 assert(!S.Current->isRoot()); in Interpret()
2162 CodePtr PC = S.Current->getPC(); in Interpret()