Lines Matching refs:S

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