Lines Matching defs:S
34 static bool RetValue(InterpState &S, CodePtr &Pt, APValue &Result) {
42 static bool Jmp(InterpState &S, CodePtr &PC, int32_t Offset) {
47 static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset) {
48 if (S.Stk.pop<bool>()) {
54 static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset) {
55 if (!S.Stk.pop<bool>()) {
61 static void diagnoseMissingInitializer(InterpState &S, CodePtr OpPC,
63 const SourceInfo &E = S.Current->getSource(OpPC);
64 S.FFDiag(E, diag::note_constexpr_var_init_unknown, 1) << VD;
65 S.Note(VD->getLocation(), diag::note_declared_at) << VD->getSourceRange();
68 static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
70 static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
72 const SourceInfo &E = S.Current->getSource(OpPC);
75 if (S.getLangOpts().CPlusPlus11) {
76 S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
77 S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
79 S.FFDiag(E);
85 diagnoseNonConstVariable(S, OpPC, D);
88 diagnoseMissingInitializer(S, OpPC, VD);
93 static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
95 if (!S.getLangOpts().CPlusPlus)
98 const SourceInfo &Loc = S.Current->getSource(OpPC);
102 diagnoseMissingInitializer(S, OpPC, VD);
112 S.FFDiag(Loc, diag::note_constexpr_ltor_non_const_int, 1) << VD;
113 S.Note(VD->getLocation(), diag::note_declared_at);
117 S.FFDiag(Loc,
118 S.getLangOpts().CPlusPlus11 ? diag::note_constexpr_ltor_non_constexpr
122 S.Note(VD->getLocation(), diag::note_declared_at);
125 static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
151 const SourceInfo &Loc = S.Current->getSource(OpPC);
152 S.FFDiag(Loc, diag::note_constexpr_access_inactive_union_member)
157 static bool CheckTemporary(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
166 if (S.P.getCurrentDecl() == ID)
169 const SourceInfo &E = S.Current->getSource(OpPC);
170 S.FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK;
171 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
177 static bool CheckGlobal(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
182 if (S.P.getCurrentDecl() == ID)
185 S.FFDiag(S.Current->getLocation(OpPC), diag::note_constexpr_modify_global);
193 static void popArg(InterpState &S, const Expr *Arg) {
194 PrimType Ty = S.getContext().classify(Arg).value_or(PT_Ptr);
195 TYPE_SWITCH(Ty, S.Stk.discard<T>());
198 void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC) {
199 assert(S.Current);
200 const Function *CurFunc = S.Current->getFunction();
210 cast<CallExpr>(S.Current->Caller->getExpr(S.Current->getRetPC()));
213 popArg(S, A);
218 if (S.Current->Caller && CurFunc->isVariadic()) {
225 const Expr *CallSite = S.Current->Caller->getExpr(S.Current->getRetPC());
239 popArg(S, A);
245 S.Current->popArgs();
248 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
253 (Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl))
256 if (!S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus) {
258 diagnoseNonConstVariable(S, OpPC, VD);
263 bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
266 const SourceInfo &E = S.Current->getSource(OpPC);
267 S.FFDiag(E, diag::note_constexpr_unsized_array_indexed);
271 bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
274 const auto &Src = S.Current->getSource(OpPC);
277 S.FFDiag(Src, diag::note_constexpr_null_subobject) << CSK_Field;
279 S.FFDiag(Src, diag::note_constexpr_access_null) << AK;
285 const auto &Src = S.Current->getSource(OpPC);
288 S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp;
291 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
293 S.Note(Ptr.getDeclLoc(), diag::note_declared_at);
301 bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
304 auto IsConstType = [&S](const VarDecl *VD) -> bool {
309 if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11)
327 D && D->hasGlobalStorage() && D != S.EvaluatingDecl && !IsConstType(D)) {
328 diagnoseNonConstVariable(S, OpPC, D);
329 return S.inConstantContext();
335 static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
338 return CheckConstant(S, OpPC, Ptr.getDeclDesc());
341 bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
345 const SourceInfo &Loc = S.Current->getSource(OpPC);
346 S.FFDiag(Loc, diag::note_constexpr_null_subobject)
347 << CSK << S.Current->getRange(OpPC);
352 bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
356 const SourceInfo &Loc = S.Current->getSource(OpPC);
357 S.FFDiag(Loc, diag::note_constexpr_access_past_end)
358 << AK << S.Current->getRange(OpPC);
362 bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
366 const SourceInfo &Loc = S.Current->getSource(OpPC);
367 S.FFDiag(Loc, diag::note_constexpr_past_end_subobject)
368 << CSK << S.Current->getRange(OpPC);
372 bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
377 const SourceInfo &Loc = S.Current->getSource(OpPC);
378 S.FFDiag(Loc, diag::note_constexpr_past_end_subobject)
379 << CSK << S.Current->getRange(OpPC);
383 bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
393 const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
397 S.CCEDiag(E, diag::note_constexpr_invalid_downcast)
403 bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
412 if (S.Current->getFunction()) {
413 for (const InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
426 const SourceInfo &Loc = S.Current->getSource(OpPC);
427 S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
431 bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
438 if (S.getLangOpts().CPlusPlus14 &&
439 Ptr.block()->getEvalID() == S.Ctx.getEvalID())
442 const SourceInfo &Loc = S.Current->getSource(OpPC);
444 S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK_Read << Field;
445 S.Note(Field->getLocation(), diag::note_declared_at);
449 bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
462 const SourceInfo &Loc = S.Current->getSource(OpPC);
463 if (S.getLangOpts().CPlusPlus)
464 S.FFDiag(Loc, diag::note_constexpr_access_volatile_type) << AK << PtrType;
466 S.FFDiag(Loc);
470 bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
479 const SourceInfo &Loc = S.Current->getSource(OpPC);
481 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
482 S.Note(VD->getLocation(), diag::note_declared_at);
484 diagnoseMissingInitializer(S, OpPC, VD);
489 if (!S.checkingPotentialConstantExpression()) {
490 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit)
491 << AK << /*uninitialized=*/true << S.Current->getRange(OpPC);
496 bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
500 assert(S.getLangOpts().CPlusPlus);
503 VD->mightBeUsableInConstantExpressions(S.getCtx())) ||
504 (S.getLangOpts().OpenCL && !S.getLangOpts().CPlusPlus11 &&
505 !VD->hasICEInitializer(S.getCtx()))) {
506 const SourceInfo &Loc = S.Current->getSource(OpPC);
507 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
508 S.Note(VD->getLocation(), diag::note_declared_at);
513 bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
515 if (!CheckLive(S, OpPC, Ptr, AK))
517 if (!CheckConstant(S, OpPC, Ptr))
520 if (!CheckDummy(S, OpPC, Ptr, AK))
522 if (!CheckExtern(S, OpPC, Ptr))
524 if (!CheckRange(S, OpPC, Ptr, AK))
526 if (!CheckActive(S, OpPC, Ptr, AK))
528 if (!CheckInitialized(S, OpPC, Ptr, AK))
530 if (!CheckTemporary(S, OpPC, Ptr, AK))
532 if (!CheckMutable(S, OpPC, Ptr))
534 if (!CheckVolatile(S, OpPC, Ptr, AK))
539 bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
540 if (!CheckLive(S, OpPC, Ptr, AK_Assign))
542 if (!CheckDummy(S, OpPC, Ptr, AK_Assign))
544 if (!CheckExtern(S, OpPC, Ptr))
546 if (!CheckRange(S, OpPC, Ptr, AK_Assign))
548 if (!CheckGlobal(S, OpPC, Ptr))
550 if (!CheckConst(S, OpPC, Ptr))
555 bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
556 if (!CheckLive(S, OpPC, Ptr, AK_MemberCall))
559 if (!CheckExtern(S, OpPC, Ptr))
561 if (!CheckRange(S, OpPC, Ptr, AK_MemberCall))
567 bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
568 if (!CheckLive(S, OpPC, Ptr, AK_Assign))
570 if (!CheckRange(S, OpPC, Ptr, AK_Assign))
575 bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
577 if (F->isVirtual() && !S.getLangOpts().CPlusPlus20) {
578 const SourceLocation &Loc = S.Current->getLocation(OpPC);
579 S.CCEDiag(Loc, diag::note_constexpr_virtual_call);
591 const SourceLocation &Loc = S.Current->getLocation(OpPC);
592 if (S.getLangOpts().CPlusPlus11) {
612 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
614 S.Note(DiagDecl->getLocation(), diag::note_declared_at);
621 S.checkingPotentialConstantExpression())
630 S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
632 S.Note(DiagDecl->getLocation(), diag::note_declared_at);
635 S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
641 bool CheckCallDepth(InterpState &S, CodePtr OpPC) {
642 if ((S.Current->getDepth() + 1) > S.getLangOpts().ConstexprCallDepth) {
643 S.FFDiag(S.Current->getSource(OpPC),
645 << S.getLangOpts().ConstexprCallDepth;
652 bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This) {
656 const SourceInfo &Loc = S.Current->getSource(OpPC);
662 if (S.getLangOpts().CPlusPlus11)
663 S.FFDiag(Loc, diag::note_constexpr_this) << IsImplicit;
665 S.FFDiag(Loc);
670 bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD) {
673 const SourceInfo &E = S.Current->getSource(OpPC);
674 S.FFDiag(E, diag::note_constexpr_pure_virtual_call, 1) << MD;
675 S.Note(MD->getLocation(), diag::note_declared_at);
679 bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result,
681 const SourceInfo &E = S.Current->getSource(OpPC);
688 S.CCEDiag(E, diag::note_constexpr_float_arithmetic)
689 << /*NaN=*/true << S.Current->getRange(OpPC);
690 return S.noteUndefinedBehavior();
695 if (S.inConstantContext())
698 FPOptions FPO = E.asExpr()->getFPFeaturesInEffect(S.Ctx.getLangOpts());
704 S.FFDiag(E, diag::note_constexpr_dynamic_rounding);
712 S.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
719 S.FFDiag(E);
726 bool CheckDynamicMemoryAllocation(InterpState &S, CodePtr OpPC) {
727 if (S.getLangOpts().CPlusPlus20)
730 const SourceInfo &E = S.Current->getSource(OpPC);
731 S.CCEDiag(E, diag::note_constexpr_new);
735 bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool NewWasArray,
747 TypeToDiagnose = S.getCtx().getConstantArrayType(
753 const SourceInfo &E = S.Current->getSource(OpPC);
754 S.FFDiag(E, diag::note_constexpr_new_delete_mismatch)
756 S.Note(NewExpr->getExprLoc(), diag::note_constexpr_dynamic_alloc_here)
761 bool CheckDeleteSource(InterpState &S, CodePtr OpPC, const Expr *Source,
767 const SourceInfo &Loc = S.Current->getSource(OpPC);
768 S.FFDiag(Loc, diag::note_constexpr_delete_not_heap_alloc)
769 << Ptr.toDiagnosticString(S.getCtx());
772 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
774 S.Note(Ptr.getDeclLoc(), diag::note_declared_at);
780 bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR) {
782 return diagnoseUnknownDecl(S, OpPC, D);
785 bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
796 return diagnoseUnknownDecl(S, OpPC, D);
799 if (S.getLangOpts().CPlusPlus11) {
800 const SourceInfo &E = S.Current->getSource(OpPC);
801 S.FFDiag(E, diag::note_constexpr_modify_global);
806 bool CheckNonNullArgs(InterpState &S, CodePtr OpPC, const Function *F,
814 const Pointer &ArgPtr = S.Stk.peek<Pointer>(ArgSize - Offset);
816 const SourceLocation &Loc = S.Current->getLocation(OpPC);
817 S.CCEDiag(Loc, diag::note_non_null_attribute_failed);
822 Offset += align(primSize(S.Ctx.classify(Arg).value_or(PT_Ptr)));
833 static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
844 if (!runRecordDestructor(S, OpPC, BasePtr.atField(Field.Offset), D))
850 if (!runRecordDestructor(S, OpPC, BasePtr.atIndex(I).narrow(),
860 const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
864 S.Stk.push<Pointer>(BasePtr);
865 if (!Call(S, OpPC, DtorFunc, 0))
871 if (!runRecordDestructor(S, OpPC, BasePtr.atField(Base.Offset), Base.Desc))
878 bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
893 if (!runRecordDestructor(S, OpPC, RP.atIndex(I).narrow(), ElemDesc))
900 return runRecordDestructor(S, OpPC, Pointer(const_cast<Block *>(B)), Desc);
903 void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,
908 if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr())
916 const SourceLocation &Loc = S.Current->getLocation(OpPC);
917 S.report(Loc, diag::warn_constexpr_unscoped_enum_out_of_range)
921 const SourceLocation &Loc = S.Current->getLocation(OpPC);
922 S.report(Loc, diag::warn_constexpr_unscoped_enum_out_of_range)
932 bool Interpret(InterpState &S, APValue &Result) {
937 const InterpFrame *StartFrame = S.Current;
938 assert(!S.Current->isRoot());
939 CodePtr PC = S.Current->getPC();