Lines Matching defs:S

21 static unsigned callArgSize(const InterpState &S, const CallExpr *C) {
25 O += align(primSize(*S.getContext().classify(E)));
38 PrimType getIntPrimType(const InterpState &S) {
39 const TargetInfo &TI = S.getCtx().getTargetInfo();
49 PrimType getLongPrimType(const InterpState &S) {
50 const TargetInfo &TI = S.getCtx().getTargetInfo();
74 static void pushInteger(InterpState &S, const APSInt &Val, QualType QT) {
77 std::optional<PrimType> T = S.getContext().classify(QT);
82 INT_TYPE_SWITCH(*T, { S.Stk.push<T>(T::from(V)); });
86 INT_TYPE_SWITCH(*T, { S.Stk.push<T>(T::from(V)); });
91 static void pushInteger(InterpState &S, T Val, QualType QT) {
93 pushInteger(S, APSInt(Val, !std::is_signed_v<T>), QT);
95 pushInteger(S,
107 static bool retPrimValue(InterpState &S, CodePtr OpPC, APValue &Result,
110 return RetVoid(S, OpPC, Result);
114 return Ret<X>(S, OpPC, Result);
134 static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
139 if (S.inConstantContext() && !S.checkingPotentialConstantExpression() &&
140 Frame->Caller && S.getEvalStatus().Diag) {
149 S.report(E->getExprLoc(),
154 S.report(E->getExprLoc(),
160 S.Stk.push<Boolean>(Boolean::from(S.inConstantContext()));
164 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
170 if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
185 if (!CheckRange(S, OpPC, PA, AK_Read) ||
186 !CheckRange(S, OpPC, PB, AK_Read)) {
203 pushInteger(S, Result, Call->getType());
207 static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
212 if (!CheckArray(S, OpPC, StrPtr))
215 if (!CheckLive(S, OpPC, StrPtr, AK_Read))
218 if (!CheckDummy(S, OpPC, StrPtr, AK_Read))
227 if (!CheckRange(S, OpPC, ElemPtr, AK_Read))
235 pushInteger(S, Len, Call->getType());
240 static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
245 if (!CheckLoad(S, OpPC, Arg))
257 if (!CheckLoad(S, OpPC, Elem))
273 S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
276 if (S.getCtx().getTargetInfo().isNan2008()) {
297 S.Stk.push<Floating>(Result);
301 static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
304 S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
306 S.Stk.push<Floating>(Floating::getInf(TargetSemantics));
310 static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
318 S.Stk.push<Floating>(Floating(Copy));
323 static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC,
338 S.Stk.push<Floating>(Result);
342 static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
358 S.Stk.push<Floating>(Result);
365 static bool interp__builtin_isnan(InterpState &S, CodePtr OpPC,
368 const Floating &Arg = S.Stk.peek<Floating>();
370 pushInteger(S, Arg.isNan(), Call->getType());
374 static bool interp__builtin_issignaling(InterpState &S, CodePtr OpPC,
378 const Floating &Arg = S.Stk.peek<Floating>();
380 pushInteger(S, Arg.isSignaling(), Call->getType());
384 static bool interp__builtin_isinf(InterpState &S, CodePtr OpPC,
387 const Floating &Arg = S.Stk.peek<Floating>();
391 pushInteger(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0, Call->getType());
393 pushInteger(S, Arg.isInf(), Call->getType());
397 static bool interp__builtin_isfinite(InterpState &S, CodePtr OpPC,
400 const Floating &Arg = S.Stk.peek<Floating>();
402 pushInteger(S, Arg.isFinite(), Call->getType());
406 static bool interp__builtin_isnormal(InterpState &S, CodePtr OpPC,
409 const Floating &Arg = S.Stk.peek<Floating>();
411 pushInteger(S, Arg.isNormal(), Call->getType());
415 static bool interp__builtin_issubnormal(InterpState &S, CodePtr OpPC,
419 const Floating &Arg = S.Stk.peek<Floating>();
421 pushInteger(S, Arg.isDenormal(), Call->getType());
425 static bool interp__builtin_iszero(InterpState &S, CodePtr OpPC,
428 const Floating &Arg = S.Stk.peek<Floating>();
430 pushInteger(S, Arg.isZero(), Call->getType());
436 static bool interp__builtin_isfpclass(InterpState &S, CodePtr OpPC,
440 PrimType FPClassArgT = *S.getContext().classify(Call->getArg(1)->getType());
441 APSInt FPClassArg = peekToAPSInt(S.Stk, FPClassArgT);
443 S.Stk.peek<Floating>(align(primSize(FPClassArgT) + primSize(PT_Float)));
447 pushInteger(S, Result, Call->getType());
453 static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
457 const Floating &Val = S.Stk.peek<Floating>();
477 unsigned IntSize = primSize(getIntPrimType(S));
481 APSInt I = peekToAPSInt(S.Stk, getIntPrimType(S), Offset);
482 pushInteger(S, I, Call->getType());
491 static bool interp__builtin_fabs(InterpState &S, CodePtr OpPC,
496 S.Stk.push<Floating>(Floating::abs(Val));
500 static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
504 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
505 APSInt Val = peekToAPSInt(S.Stk, ArgT);
506 pushInteger(S, Val.popcount(), Call->getType());
510 static bool interp__builtin_parity(InterpState &S, CodePtr OpPC,
513 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
514 APSInt Val = peekToAPSInt(S.Stk, ArgT);
515 pushInteger(S, Val.popcount() % 2, Call->getType());
519 static bool interp__builtin_clrsb(InterpState &S, CodePtr OpPC,
522 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
523 APSInt Val = peekToAPSInt(S.Stk, ArgT);
524 pushInteger(S, Val.getBitWidth() - Val.getSignificantBits(), Call->getType());
528 static bool interp__builtin_bitreverse(InterpState &S, CodePtr OpPC,
532 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
533 APSInt Val = peekToAPSInt(S.Stk, ArgT);
534 pushInteger(S, Val.reverseBits(), Call->getType());
538 static bool interp__builtin_classify_type(InterpState &S, CodePtr OpPC,
547 EvaluateBuiltinClassifyType(Arg->getType(), S.getLangOpts());
549 pushInteger(S, ReturnVal, Call->getType());
555 static bool interp__builtin_expect(InterpState &S, CodePtr OpPC,
563 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
564 unsigned Offset = align(primSize(getLongPrimType(S))) * 2;
568 APSInt Val = peekToAPSInt(S.Stk, ArgT, Offset);
569 pushInteger(S, Val, Call->getType());
574 static bool interp__builtin_rotate(InterpState &S, CodePtr OpPC,
578 PrimType AmountT = *S.getContext().classify(Call->getArg(1)->getType());
579 PrimType ValueT = *S.getContext().classify(Call->getArg(0)->getType());
581 APSInt Amount = peekToAPSInt(S.Stk, AmountT);
583 S.Stk, ValueT, align(primSize(AmountT)) + align(primSize(ValueT)));
593 pushInteger(S, Result, Call->getType());
597 static bool interp__builtin_ffs(InterpState &S, CodePtr OpPC,
600 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
601 APSInt Value = peekToAPSInt(S.Stk, ArgT);
604 pushInteger(S, N == Value.getBitWidth() ? 0 : N + 1, Call->getType());
608 static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
613 PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
616 const FunctionPointer &Arg = S.Stk.peek<FunctionPointer>();
617 S.Stk.push<FunctionPointer>(Arg);
619 const Pointer &Arg = S.Stk.peek<Pointer>();
620 S.Stk.push<Pointer>(Arg);
627 static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
631 PrimType ArgT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
633 TYPE_SWITCH(ArgT, const T &Arg = S.Stk.peek<T>(); S.Stk.push<T>(Arg););
638 static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
642 PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
643 APSInt Arg = peekToAPSInt(S.Stk, ArgT);
646 S.getCtx().getTargetInfo().getEHDataRegisterNumber(Arg.getZExtValue());
647 pushInteger(S, Result, Call->getType());
652 static bool noopPointer(InterpState &S, CodePtr OpPC, const InterpFrame *Frame,
654 const Pointer &Arg = S.Stk.peek<Pointer>();
655 S.Stk.push<Pointer>(Arg);
660 static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
664 Pointer &ResultPtr = S.Stk.peek<Pointer>();
669 PrimType RHST = *S.getContext().classify(Call->getArg(1)->getType());
670 PrimType LHST = *S.getContext().classify(Call->getArg(0)->getType());
671 APSInt RHS = peekToAPSInt(S.Stk, RHST,
673 APSInt LHS = peekToAPSInt(S.Stk, LHST,
677 PrimType ResultT = *S.getContext().classify(ResultType);
690 uint64_t ResultSize = S.getCtx().getTypeSize(ResultType);
750 APSInt Temp = Result.extOrTrunc(S.getCtx().getTypeSize(ResultType));
762 S.Stk.push<Boolean>(Overflow);
767 static bool interp__builtin_carryop(InterpState &S, CodePtr OpPC,
772 PrimType LHST = *S.getContext().classify(Call->getArg(0)->getType());
773 PrimType RHST = *S.getContext().classify(Call->getArg(1)->getType());
774 PrimType CarryT = *S.getContext().classify(Call->getArg(2)->getType());
775 APSInt RHS = peekToAPSInt(S.Stk, RHST,
779 peekToAPSInt(S.Stk, LHST,
783 S.Stk, LHST, align(primSize(PT_Ptr)) + align(primSize(CarryT)));
817 Pointer &CarryOutPtr = S.Stk.peek<Pointer>();
819 PrimType CarryOutT = *S.getContext().classify(CarryOutType);
824 pushInteger(S, Result, Call->getType());
828 static bool interp__builtin_clz(InterpState &S, CodePtr OpPC,
831 unsigned CallSize = callArgSize(S, Call);
833 PrimType ValT = *S.getContext().classify(Call->getArg(0));
834 const APSInt &Val = peekToAPSInt(S.Stk, ValT, CallSize);
846 PrimType FallbackT = *S.getContext().classify(Call->getArg(1));
847 const APSInt &Fallback = peekToAPSInt(S.Stk, FallbackT);
848 pushInteger(S, Fallback, Call->getType());
856 pushInteger(S, Val.countl_zero(), Call->getType());
860 static bool interp__builtin_ctz(InterpState &S, CodePtr OpPC,
863 unsigned CallSize = callArgSize(S, Call);
864 PrimType ValT = *S.getContext().classify(Call->getArg(0));
865 const APSInt &Val = peekToAPSInt(S.Stk, ValT, CallSize);
871 PrimType FallbackT = *S.getContext().classify(Call->getArg(1));
872 const APSInt &Fallback = peekToAPSInt(S.Stk, FallbackT);
873 pushInteger(S, Fallback, Call->getType());
879 pushInteger(S, Val.countr_zero(), Call->getType());
883 static bool interp__builtin_bswap(InterpState &S, CodePtr OpPC,
886 PrimType ReturnT = *S.getContext().classify(Call->getType());
887 PrimType ValT = *S.getContext().classify(Call->getArg(0));
888 const APSInt &Val = peekToAPSInt(S.Stk, ValT);
892 { S.Stk.push<T>(T::from(Val.byteSwap().getZExtValue())); });
899 static bool interp__builtin_atomic_lock_free(InterpState &S, CodePtr OpPC,
905 PrimType ValT = *S.getContext().classify(Call->getArg(0));
909 const APSInt &SizeVal = peekToAPSInt(S.Stk, ValT, SizeValOffset);
911 auto returnBool = [&S](bool Value) -> bool {
912 S.Stk.push<Boolean>(Value);
930 S.getCtx().getTargetInfo().getMaxAtomicInlineWidth();
931 if (Size <= S.getCtx().toCharUnitsFromBits(InlineWidthBits)) {
941 const Pointer &Ptr = S.Stk.peek<Pointer>();
952 S.getCtx().getTypeAlignInChars(PointeeType) >= Size)
964 static bool interp__builtin_complex(InterpState &S, CodePtr OpPC,
968 const Floating &Arg2 = S.Stk.peek<Floating>();
969 const Floating &Arg1 = S.Stk.peek<Floating>(align(primSize(PT_Float)) * 2);
970 Pointer &Result = S.Stk.peek<Pointer>(align(primSize(PT_Float)) * 2 +
987 static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
992 unsigned CallSize = callArgSize(S, Call);
994 PrimType AlignmentT = *S.Ctx.classify(Call->getArg(1));
995 const APSInt &Alignment = peekToAPSInt(S.Stk, AlignmentT);
998 S.FFDiag(Call, diag::note_constexpr_invalid_alignment) << Alignment;
1001 unsigned SrcWidth = S.getCtx().getIntWidth(Call->getArg(0)->getType());
1004 S.FFDiag(Call, diag::note_constexpr_alignment_too_big)
1011 PrimType FirstArgT = *S.Ctx.classify(Call->getArg(0));
1014 const APSInt &Src = peekToAPSInt(S.Stk, FirstArgT, CallSize);
1019 pushInteger(S, AlignedVal, Call->getType());
1022 pushInteger(S, AlignedVal, Call->getType());
1024 assert(*S.Ctx.classify(Call->getType()) == PT_Bool);
1025 S.Stk.push<Boolean>((Src & (Align - 1)) == 0);
1031 const Pointer &Ptr = S.Stk.peek<Pointer>(CallSize);
1036 S.getCtx().getDeclAlign(Ptr.getDeclDesc()->asValueDecl());
1042 S.Stk.push<Boolean>(true);
1051 S.Stk.push<Boolean>(false);
1055 S.FFDiag(Call->getArg(0), diag::note_constexpr_alignment_compute)
1066 S.Stk.push<Pointer>(Ptr);
1084 S.Stk.push<Pointer>(Ptr.atIndex(NewOffset.getQuantity()));
1089 S.FFDiag(Call->getArg(0), diag::note_constexpr_alignment_adjust) << Alignment;
1093 static bool interp__builtin_os_log_format_buffer_size(InterpState &S,
1099 analyze_os_log::computeOSLogBufferLayout(S.getCtx(), Call, Layout);
1100 pushInteger(S, Layout.size().getQuantity(), Call->getType());
1105 InterpState &S, CodePtr OpPC, const InterpFrame *Frame,
1107 const auto &Ptr = S.Stk.peek<Pointer>();
1112 pushInteger(S, Result, Call->getType());
1116 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
1118 const InterpFrame *Frame = S.Current;
1121 std::optional<PrimType> ReturnT = S.getContext().classify(Call);
1125 if (!interp__builtin_is_constant_evaluated(S, OpPC, Frame, Call))
1132 if (!interp__builtin_strcmp(S, OpPC, Frame, Call))
1136 if (!interp__builtin_strlen(S, OpPC, Frame, Call))
1144 if (!interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/false))
1152 if (!interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/true))
1166 if (!interp__builtin_inf(S, OpPC, Frame, F))
1173 if (!interp__builtin_copysign(S, OpPC, Frame, F))
1182 if (!interp__builtin_fmin(S, OpPC, Frame, F))
1191 if (!interp__builtin_fmax(S, OpPC, Frame, F))
1196 if (!interp__builtin_isnan(S, OpPC, Frame, F, Call))
1200 if (!interp__builtin_issignaling(S, OpPC, Frame, F, Call))
1205 if (!interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/false, Call))
1210 if (!interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/true, Call))
1215 if (!interp__builtin_isfinite(S, OpPC, Frame, F, Call))
1219 if (!interp__builtin_isnormal(S, OpPC, Frame, F, Call))
1223 if (!interp__builtin_issubnormal(S, OpPC, Frame, F, Call))
1227 if (!interp__builtin_iszero(S, OpPC, Frame, F, Call))
1231 if (!interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
1235 if (!interp__builtin_fpclassify(S, OpPC, Frame, F, Call))
1243 if (!interp__builtin_fabs(S, OpPC, Frame, F))
1254 if (!interp__builtin_popcount(S, OpPC, Frame, F, Call))
1261 if (!interp__builtin_parity(S, OpPC, Frame, F, Call))
1268 if (!interp__builtin_clrsb(S, OpPC, Frame, F, Call))
1276 if (!interp__builtin_bitreverse(S, OpPC, Frame, F, Call))
1281 if (!interp__builtin_classify_type(S, OpPC, Frame, F, Call))
1287 if (!interp__builtin_expect(S, OpPC, Frame, F, Call))
1300 if (!interp__builtin_rotate(S, OpPC, Frame, F, Call, /*Right=*/false))
1313 if (!interp__builtin_rotate(S, OpPC, Frame, F, Call, /*Right=*/true))
1320 if (!interp__builtin_ffs(S, OpPC, Frame, F, Call))
1326 if (!interp__builtin_addressof(S, OpPC, Frame, F, Call))
1335 if (!interp__builtin_move(S, OpPC, Frame, F, Call))
1340 if (!interp__builtin_eh_return_data_regno(S, OpPC, Frame, F, Call))
1345 if (!noopPointer(S, OpPC, Frame, F, Call))
1370 if (!interp__builtin_overflowop(S, OpPC, Frame, F, Call))
1384 if (!interp__builtin_carryop(S, OpPC, Frame, F, Call))
1396 if (!interp__builtin_clz(S, OpPC, Frame, F, Call))
1405 if (!interp__builtin_ctz(S, OpPC, Frame, F, Call))
1412 if (!interp__builtin_bswap(S, OpPC, Frame, F, Call))
1419 if (!interp__builtin_atomic_lock_free(S, OpPC, Frame, F, Call))
1424 if (!interp__builtin_complex(S, OpPC, Frame, F, Call))
1431 if (!interp__builtin_is_aligned_up_down(S, OpPC, Frame, F, Call))
1436 if (!interp__builtin_os_log_format_buffer_size(S, OpPC, Frame, F, Call))
1441 if (!interp__builtin_ptrauth_string_discriminator(S, OpPC, Frame, F, Call))
1446 S.FFDiag(S.Current->getLocation(OpPC),
1448 << S.Current->getRange(OpPC);
1453 return retPrimValue(S, OpPC, Dummy, ReturnT);
1456 bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,
1476 const ASTRecordLayout &RL = S.getCtx().getASTRecordLayout(RD);
1479 Result += S.getCtx().toCharUnitsFromBits(RL.getFieldOffset(FieldIndex));
1487 const ArrayType *AT = S.getCtx().getAsArrayType(CurrentType);
1491 CharUnits ElementSize = S.getCtx().getTypeSizeInChars(CurrentType);
1508 const ASTRecordLayout &RL = S.getCtx().getASTRecordLayout(RD);
1530 bool SetThreeWayComparisonField(InterpState &S, CodePtr OpPC,
1539 PrimType FieldT = *S.getContext().classify(FieldPtr.getType());
1547 bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) {
1575 if (std::optional<PrimType> FT = S.Ctx.classify(F.Decl->getType())) {
1581 return Invalid(S, OpPC);
1589 return Invalid(S, OpPC);