13#ifndef LLVM_CLANG_AST_INTERP_INTERP_H
14#define LLVM_CLANG_AST_INTERP_INTERP_H
16#include "../ExprConstShared.h"
32#include "llvm/ADT/APFloat.h"
33#include "llvm/ADT/APSInt.h"
39using APSInt = llvm::APSInt;
44 R =
V.toAPValue(S.getCtx());
49bool CheckExtern(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
52bool CheckArray(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
55bool CheckLive(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
59bool CheckDummy(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
63bool CheckNull(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
67bool CheckRange(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
71bool CheckRange(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
75bool CheckSubobject(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
80bool CheckDowncast(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
84bool CheckConst(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
87bool CheckConstant(InterpState &S, CodePtr OpPC,
const Descriptor *Desc);
90bool CheckMutable(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
93bool CheckLoad(InterpState &S, CodePtr OpPC,
const Pointer &Ptr,
102bool CheckStore(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
105bool CheckInvoke(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
108bool CheckInit(InterpState &S, CodePtr OpPC,
const Pointer &Ptr);
111bool CheckCallable(InterpState &S, CodePtr OpPC,
const Function *F);
118bool CheckThis(InterpState &S, CodePtr OpPC,
const Pointer &
This);
125 const CallExpr *CE,
unsigned ArgSize);
133 bool DeleteIsArray,
const Descriptor *
D,
134 const Expr *NewExpr);
144 const Pointer &Ptr,
const APSInt &IntValue);
147bool DoMemcpy(InterpState &S, CodePtr OpPC,
const Pointer &Src, Pointer &Dest);
150template <
typename LT,
typename RT>
153 if (RHS.isNegative()) {
155 S.CCEDiag(
Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
156 if (!S.noteUndefinedBehavior())
162 if (Bits > 1 && RHS >= RT::from(Bits, RHS.bitWidth())) {
163 const Expr *
E = S.Current->getExpr(OpPC);
164 const APSInt Val = RHS.toAPSInt();
166 S.CCEDiag(
E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
167 if (!S.noteUndefinedBehavior())
171 if (LHS.isSigned() && !S.
getLangOpts().CPlusPlus20) {
172 const Expr *
E = S.Current->getExpr(OpPC);
175 if (LHS.isNegative()) {
176 S.CCEDiag(
E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
177 if (!S.noteUndefinedBehavior())
179 }
else if (LHS.toUnsigned().countLeadingZeros() <
180 static_cast<unsigned>(RHS)) {
181 S.CCEDiag(
E, diag::note_constexpr_lshift_discards);
182 if (!S.noteUndefinedBehavior())
197 const auto *Op = cast<BinaryOperator>(S.Current->getExpr(OpPC));
198 if constexpr (std::is_same_v<T, Floating>) {
199 S.CCEDiag(Op, diag::note_expr_divide_by_zero)
200 << Op->getRHS()->getSourceRange();
204 S.FFDiag(Op, diag::note_expr_divide_by_zero)
205 << Op->getRHS()->getSourceRange();
209 if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
210 APSInt LHSInt = LHS.toAPSInt();
212 (-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
214 const Expr *
E = S.Current->getExpr(OpPC);
215 S.CCEDiag(
Loc, diag::note_constexpr_overflow) << Trunc <<
E->
getType();
221template <
typename SizeT>
223 unsigned ElemSize,
bool IsNoThrow) {
232 if (NumElements->toAPSInt().getActiveBits() >
234 *NumElements > MaxElements) {
237 S.FFDiag(
Loc, diag::note_constexpr_new_too_large)
238 << NumElements->toDiagnosticString(S.getCtx());
248 APFloat::opStatus Status);
264inline bool Invalid(InterpState &S, CodePtr OpPC);
274template <PrimType Name, class T = typename PrimConv<Name>::T>
276 const T &
Ret = S.Stk.pop<
T>();
281 if constexpr (std::is_same_v<T, Pointer>) {
286 if (!
Ret.isZero() && !
Ret.isLive())
291 assert(S.Current->getFrameOffset() == S.Stk.size() &&
"Invalid frame");
292 if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
296 PC = S.Current->getRetPC();
310 assert(S.Current->getFrameOffset() == S.Stk.size() &&
"Invalid frame");
312 if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
316 PC = S.Current->getRetPC();
331 template <typename U>
class OpAP>
336 if (!OpFW(LHS, RHS, Bits, &
Result)) {
345 APSInt Value = OpAP<APSInt>()(LHS.toAPSInt(Bits), RHS.toAPSInt(Bits));
348 const Expr *
E = S.Current->getExpr(OpPC);
350 if (S.checkingForUndefinedBehavior()) {
356 S.report(
Loc, diag::warn_integer_constant_overflow)
360 S.CCEDiag(
E, diag::note_constexpr_overflow) <<
Value <<
Type;
362 if (!S.noteUndefinedBehavior()) {
370template <PrimType Name, class T = typename PrimConv<Name>::T>
372 const T &RHS = S.Stk.pop<
T>();
373 const T &LHS = S.Stk.pop<
T>();
374 const unsigned Bits = RHS.bitWidth() + 1;
375 return AddSubMulHelper<T, T::add, std::plus>(S, OpPC, Bits, LHS, RHS);
388template <PrimType Name, class T = typename PrimConv<Name>::T>
390 const T &RHS = S.Stk.pop<
T>();
391 const T &LHS = S.Stk.pop<
T>();
392 const unsigned Bits = RHS.bitWidth() + 1;
393 return AddSubMulHelper<T, T::sub, std::minus>(S, OpPC, Bits, LHS, RHS);
406template <PrimType Name, class T = typename PrimConv<Name>::T>
408 const T &RHS = S.Stk.pop<
T>();
409 const T &LHS = S.Stk.pop<
T>();
410 const unsigned Bits = RHS.bitWidth() * 2;
411 return AddSubMulHelper<T, T::mul, std::multiplies>(S, OpPC, Bits, LHS, RHS);
424template <PrimType Name, class T = typename PrimConv<Name>::T>
430 if constexpr (std::is_same_v<T, Floating>) {
436 APFloat ResR(A.getSemantics());
437 APFloat ResI(A.getSemantics());
442 Result.atIndex(0).initialize();
444 Result.atIndex(1).initialize();
448 const T &LHSR = LHS.atIndex(0).deref<
T>();
449 const T &LHSI = LHS.atIndex(1).deref<
T>();
452 unsigned Bits = LHSR.bitWidth();
456 if (T::mul(LHSR, RHSR, Bits, &A))
459 if (T::mul(LHSI, RHSI, Bits, &B))
461 if (T::sub(A, B, Bits, &
Result.atIndex(0).deref<
T>()))
463 Result.atIndex(0).initialize();
466 if (T::mul(LHSR, RHSI, Bits, &A))
468 if (T::mul(LHSI, RHSR, Bits, &B))
470 if (T::add(A, B, Bits, &
Result.atIndex(1).deref<
T>()))
472 Result.atIndex(1).initialize();
479template <PrimType Name, class T = typename PrimConv<Name>::T>
485 if constexpr (std::is_same_v<T, Floating>) {
491 APFloat ResR(A.getSemantics());
492 APFloat ResI(A.getSemantics());
497 Result.atIndex(0).initialize();
499 Result.atIndex(1).initialize();
503 const T &LHSR = LHS.atIndex(0).deref<
T>();
504 const T &LHSI = LHS.atIndex(1).deref<
T>();
507 unsigned Bits = LHSR.bitWidth();
508 const T Zero = T::from(0, Bits);
513 S.FFDiag(
E, diag::note_expr_divide_by_zero);
519 if (T::mul(RHSR, RHSR, Bits, &A) || T::mul(RHSI, RHSI, Bits, &B))
522 if (T::add(A, B, Bits, &Den))
526 T &ResultR =
Result.atIndex(0).deref<
T>();
527 T &ResultI =
Result.atIndex(1).deref<
T>();
529 if (T::mul(LHSR, RHSR, Bits, &A) || T::mul(LHSI, RHSI, Bits, &B))
531 if (T::add(A, B, Bits, &ResultR))
533 if (T::div(ResultR, Den, Bits, &ResultR))
535 Result.atIndex(0).initialize();
538 if (T::mul(LHSI, RHSR, Bits, &A) || T::mul(LHSR, RHSI, Bits, &B))
540 if (T::sub(A, B, Bits, &ResultI))
542 if (T::div(ResultI, Den, Bits, &ResultI))
544 Result.atIndex(1).initialize();
554template <PrimType Name, class T = typename PrimConv<Name>::T>
556 const T &RHS = S.Stk.pop<
T>();
557 const T &LHS = S.Stk.pop<
T>();
559 unsigned Bits = RHS.bitWidth();
561 if (!T::bitAnd(LHS, RHS, Bits, &
Result)) {
571template <PrimType Name, class T = typename PrimConv<Name>::T>
573 const T &RHS = S.Stk.pop<
T>();
574 const T &LHS = S.Stk.pop<
T>();
576 unsigned Bits = RHS.bitWidth();
578 if (!T::bitOr(LHS, RHS, Bits, &
Result)) {
588template <PrimType Name, class T = typename PrimConv<Name>::T>
590 const T &RHS = S.Stk.pop<
T>();
591 const T &LHS = S.Stk.pop<
T>();
593 unsigned Bits = RHS.bitWidth();
595 if (!T::bitXor(LHS, RHS, Bits, &
Result)) {
605template <PrimType Name, class T = typename PrimConv<Name>::T>
607 const T &RHS = S.Stk.pop<
T>();
608 const T &LHS = S.Stk.pop<
T>();
613 const unsigned Bits = RHS.bitWidth() * 2;
615 if (!T::rem(LHS, RHS, Bits, &
Result)) {
625template <PrimType Name, class T = typename PrimConv<Name>::T>
627 const T &RHS = S.Stk.pop<
T>();
628 const T &LHS = S.Stk.pop<
T>();
633 const unsigned Bits = RHS.bitWidth() * 2;
635 if (!T::div(LHS, RHS, Bits, &
Result)) {
660 const auto &Val = S.Stk.pop<
Boolean>();
669template <PrimType Name, class T = typename PrimConv<Name>::T>
671 const T &
Value = S.Stk.pop<
T>();
680 "don't expect other types to fail at constexpr negation");
684 const Expr *
E = S.Current->getExpr(OpPC);
687 if (S.checkingForUndefinedBehavior()) {
689 NegatedValue.trunc(
Result.bitWidth())
693 S.report(
Loc, diag::warn_integer_constant_overflow)
698 S.CCEDiag(
E, diag::note_constexpr_overflow) << NegatedValue <<
Type;
699 return S.noteUndefinedBehavior();
711template <
typename T, IncDecOp Op, PushVal DoPush>
715 if constexpr (std::is_same_v<T, Boolean>) {
740 unsigned Bits =
Value.bitWidth() + 1;
743 APResult = ++
Value.toAPSInt(Bits);
745 APResult = --
Value.toAPSInt(Bits);
748 const Expr *
E = S.Current->getExpr(OpPC);
750 if (S.checkingForUndefinedBehavior()) {
752 APResult.trunc(
Result.bitWidth())
756 S.report(
Loc, diag::warn_integer_constant_overflow)
761 S.CCEDiag(
E, diag::note_constexpr_overflow) << APResult <<
Type;
762 return S.noteUndefinedBehavior();
769template <PrimType Name, class T = typename PrimConv<Name>::T>
775 return IncDecHelper<T, IncDecOp::Inc, PushVal::Yes>(S, OpPC, Ptr);
781template <PrimType Name, class T = typename PrimConv<Name>::T>
787 return IncDecHelper<T, IncDecOp::Inc, PushVal::No>(S, OpPC, Ptr);
794template <PrimType Name, class T = typename PrimConv<Name>::T>
800 return IncDecHelper<T, IncDecOp::Dec, PushVal::Yes>(S, OpPC, Ptr);
806template <PrimType Name, class T = typename PrimConv<Name>::T>
812 return IncDecHelper<T, IncDecOp::Dec, PushVal::No>(S, OpPC, Ptr);
815template <IncDecOp Op, PushVal DoPush>
817 llvm::RoundingMode RM) {
824 llvm::APFloat::opStatus Status;
840 return IncDecFloatHelper<IncDecOp::Inc, PushVal::Yes>(S, OpPC, Ptr, RM);
848 return IncDecFloatHelper<IncDecOp::Inc, PushVal::No>(S, OpPC, Ptr, RM);
856 return IncDecFloatHelper<IncDecOp::Dec, PushVal::Yes>(S, OpPC, Ptr, RM);
864 return IncDecFloatHelper<IncDecOp::Dec, PushVal::No>(S, OpPC, Ptr, RM);
869template <PrimType Name, class T = typename PrimConv<Name>::T>
871 const T &Val = S.Stk.pop<
T>();
873 if (!T::comp(Val, &
Result)) {
889 assert((!std::is_same_v<T, MemberPointer>) &&
890 "Non-equality comparisons on member pointer types should already be "
891 "rejected in Sema.");
893 const T &RHS = S.Stk.pop<
T>();
894 const T &LHS = S.Stk.pop<
T>();
895 S.Stk.push<BoolT>(BoolT::from(
Fn(LHS.compare(RHS))));
901 return CmpHelper<T>(S, OpPC,
Fn);
912 S.FFDiag(
Loc, diag::note_constexpr_pointer_comparison_unspecified)
914 << RHS.toDiagnosticString(S.getCtx());
925 for (
const auto &FP : {LHS, RHS}) {
928 S.FFDiag(
Loc, diag::note_constexpr_pointer_weak_comparison)
929 << FP.toDiagnosticString(S.getCtx());
946 S.FFDiag(
Loc, diag::note_constexpr_pointer_comparison_unspecified)
947 << LHS.toDiagnosticString(S.getCtx())
951 unsigned VL = LHS.getByteOffset();
953 S.Stk.push<BoolT>(BoolT::from(
Fn(
Compare(VL, VR))));
964 if (LHS.isZero() && RHS.
isZero()) {
970 for (
const auto &
P : {LHS, RHS}) {
975 S.FFDiag(
Loc, diag::note_constexpr_pointer_weak_comparison)
976 <<
P.toDiagnosticString(S.getCtx());
985 S.FFDiag(
Loc, diag::note_constexpr_pointer_comparison_past_end)
986 << LHS.toDiagnosticString(S.getCtx());
988 }
else if (RHS.
isOnePastEnd() && !LHS.isOnePastEnd() && !LHS.isZero() &&
989 LHS.getOffset() == 0) {
991 S.FFDiag(
Loc, diag::note_constexpr_pointer_comparison_past_end)
999 unsigned VL = LHS.getByteOffset();
1006 if (!LHS.isZero() && LHS.isArrayRoot())
1007 VL = LHS.atIndex(0).getByteOffset();
1011 S.Stk.push<BoolT>(BoolT::from(
Fn(
Compare(VL, VR))));
1024 for (
const auto &MP : {LHS, RHS}) {
1027 S.FFDiag(
Loc, diag::note_constexpr_mem_pointer_weak_comparison) << MD;
1035 if (LHS.
isZero() && RHS.isZero()) {
1039 if (LHS.
isZero() || RHS.isZero()) {
1045 for (
const auto &MP : {LHS, RHS}) {
1049 S.CCEDiag(
Loc, diag::note_constexpr_compare_virtual_mem_ptr) << MD;
1057template <PrimType Name, class T = typename PrimConv<Name>::T>
1064template <PrimType Name, class T = typename PrimConv<Name>::T>
1066 const T &RHS = S.Stk.pop<
T>();
1067 const T &LHS = S.Stk.pop<
T>();
1074 S.FFDiag(
Loc, diag::note_constexpr_pointer_comparison_unspecified)
1075 << LHS.toDiagnosticString(S.getCtx())
1076 << RHS.toDiagnosticString(S.getCtx());
1081 const auto *CmpValueInfo =
1083 assert(CmpValueInfo);
1084 assert(CmpValueInfo->hasValidIntValue());
1088template <PrimType Name, class T = typename PrimConv<Name>::T>
1095template <PrimType Name, class T = typename PrimConv<Name>::T>
1102template <PrimType Name, class T = typename PrimConv<Name>::T>
1110template <PrimType Name, class T = typename PrimConv<Name>::T>
1117template <PrimType Name, class T = typename PrimConv<Name>::T>
1129template <PrimType Name, class T = typename PrimConv<Name>::T>
1131 const T RHS = S.Stk.pop<
T>();
1132 const T LHS = S.Stk.pop<
T>();
1133 const T Value = S.Stk.pop<
T>();
1135 S.Stk.push<
bool>(LHS <=
Value &&
Value <= RHS);
1143template <PrimType Name, class T = typename PrimConv<Name>::T>
1145 S.Stk.push<
T>(S.Stk.peek<
T>());
1149template <PrimType Name, class T = typename PrimConv<Name>::T>
1156template <PrimType TopName, PrimType BottomName>
1161 const auto &Top = S.Stk.pop<TopT>();
1162 const auto &Bottom = S.Stk.pop<BottomT>();
1164 S.Stk.push<TopT>(Top);
1165 S.Stk.push<BottomT>(Bottom);
1174template <PrimType Name, class T = typename PrimConv<Name>::T>
1184template <PrimType Name, class T = typename PrimConv<Name>::T>
1186 const Pointer &Ptr = S.Current->getLocalPointer(I);
1189 S.Stk.push<
T>(Ptr.
deref<
T>());
1196template <PrimType Name, class T = typename PrimConv<Name>::T>
1198 S.Current->setLocal<
T>(I, S.Stk.pop<
T>());
1202template <PrimType Name, class T = typename PrimConv<Name>::T>
1204 if (S.checkingPotentialConstantExpression()) {
1207 S.Stk.push<
T>(S.Current->getParam<
T>(I));
1211template <PrimType Name, class T = typename PrimConv<Name>::T>
1213 S.Current->setParam<
T>(I, S.Stk.pop<
T>());
1219template <PrimType Name, class T = typename PrimConv<Name>::T>
1229 S.Stk.push<
T>(Field.deref<
T>());
1233template <PrimType Name, class T = typename PrimConv<Name>::T>
1235 const T &
Value = S.Stk.pop<
T>();
1241 const Pointer &Field = Obj.atField(I);
1245 Field.deref<
T>() =
Value;
1251template <PrimType Name, class T = typename PrimConv<Name>::T>
1261 S.Stk.push<
T>(Field.deref<
T>());
1265template <PrimType Name, class T = typename PrimConv<Name>::T>
1267 if (S.checkingPotentialConstantExpression())
1275 S.Stk.push<
T>(Field.deref<
T>());
1279template <PrimType Name, class T = typename PrimConv<Name>::T>
1281 if (S.checkingPotentialConstantExpression())
1283 const T &
Value = S.Stk.pop<
T>();
1290 Field.deref<
T>() =
Value;
1294template <PrimType Name, class T = typename PrimConv<Name>::T>
1296 const Pointer &Ptr = S.P.getPtrGlobal(I);
1307 S.Stk.push<
T>(Ptr.
deref<
T>());
1312template <PrimType Name, class T = typename PrimConv<Name>::T>
1314 const Pointer &Ptr = S.P.getPtrGlobal(I);
1317 S.Stk.push<
T>(Ptr.
deref<
T>());
1321template <PrimType Name, class T = typename PrimConv<Name>::T>
1327template <PrimType Name, class T = typename PrimConv<Name>::T>
1329 const Pointer &
P = S.P.getGlobal(I);
1330 P.deref<
T>() = S.Stk.pop<
T>();
1338template <PrimType Name, class T = typename PrimConv<Name>::T>
1341 const Pointer &Ptr = S.P.getGlobal(I);
1343 const T Value = S.Stk.peek<
T>();
1350 S.SeenGlobalTemporaries.push_back(
1353 Ptr.
deref<
T>() = S.Stk.pop<
T>();
1367 S.SeenGlobalTemporaries.push_back(
1368 std::make_pair(
P.getDeclDesc()->asExpr(), Temp));
1370 if (std::optional<APValue> APV =
1379template <PrimType Name, class T = typename PrimConv<Name>::T>
1381 if (S.checkingPotentialConstantExpression())
1387 Field.deref<
T>() = S.Stk.pop<
T>();
1395template <PrimType Name, class T = typename PrimConv<Name>::T>
1397 uint32_t FieldOffset) {
1398 assert(F->isBitField());
1399 if (S.checkingPotentialConstantExpression())
1405 const auto &
Value = S.Stk.pop<
T>();
1406 Field.deref<
T>() =
Value.truncate(F->Decl->getBitWidthValue(S.getCtx()));
1414template <PrimType Name, class T = typename PrimConv<Name>::T>
1416 const T &
Value = S.Stk.pop<
T>();
1418 Field.deref<
T>() =
Value;
1424template <PrimType Name, class T = typename PrimConv<Name>::T>
1426 assert(F->isBitField());
1427 const T &
Value = S.Stk.pop<
T>();
1429 Field.deref<
T>() =
Value.truncate(F->Decl->getBitWidthValue(S.getCtx()));
1440 S.Stk.push<
Pointer>(S.Current->getLocalPointer(I));
1445 if (S.checkingPotentialConstantExpression()) {
1448 S.Stk.push<
Pointer>(S.Current->getParamPointer(I));
1453 S.Stk.push<
Pointer>(S.P.getPtrGlobal(I));
1462 if (S.
getLangOpts().CPlusPlus && S.inConstantContext() &&
1490 if (S.
getLangOpts().CPlusPlus && S.inConstantContext() &&
1516 if (S.checkingPotentialConstantExpression())
1534 S.Stk.push<
Pointer>(std::move(Field));
1539 if (S.checkingPotentialConstantExpression())
1547 S.Stk.push<
Pointer>(std::move(Field));
1597 if (S.checkingPotentialConstantExpression())
1632 while (
Base.isBaseClass())
1635 const Record::Base *VirtBase =
Base.getRecord()->getVirtualBase(
Decl);
1636 S.Stk.push<
Pointer>(
Base.atField(VirtBase->Offset));
1652 if (S.checkingPotentialConstantExpression())
1664template <PrimType Name, class T = typename PrimConv<Name>::T>
1671 S.Stk.push<
T>(Ptr.
deref<
T>());
1675template <PrimType Name, class T = typename PrimConv<Name>::T>
1682 S.Stk.push<
T>(Ptr.
deref<
T>());
1686template <PrimType Name, class T = typename PrimConv<Name>::T>
1688 const T &
Value = S.Stk.pop<
T>();
1692 if (Ptr.canBeInitialized()) {
1700template <PrimType Name, class T = typename PrimConv<Name>::T>
1702 const T &
Value = S.Stk.pop<
T>();
1706 if (Ptr.canBeInitialized()) {
1714template <PrimType Name, class T = typename PrimConv<Name>::T>
1716 const T &
Value = S.Stk.pop<
T>();
1720 if (Ptr.canBeInitialized())
1722 if (
const auto *FD = Ptr.getField())
1723 Ptr.deref<
T>() =
Value.truncate(FD->getBitWidthValue(S.getCtx()));
1729template <PrimType Name, class T = typename PrimConv<Name>::T>
1731 const T &
Value = S.Stk.pop<
T>();
1735 if (Ptr.canBeInitialized())
1737 if (
const auto *FD = Ptr.getField())
1738 Ptr.deref<
T>() =
Value.truncate(FD->getBitWidthValue(S.getCtx()));
1744template <PrimType Name, class T = typename PrimConv<Name>::T>
1746 const T &
Value = S.Stk.pop<
T>();
1753 new (&Ptr.deref<
T>())
T(
Value);
1757template <PrimType Name, class T = typename PrimConv<Name>::T>
1759 const T &
Value = S.Stk.pop<
T>();
1764 new (&Ptr.deref<
T>())
T(
Value);
1771template <PrimType Name, class T = typename PrimConv<Name>::T>
1773 const T &
Value = S.Stk.pop<
T>();
1775 if (Ptr.isUnknownSizeArray())
1780 new (&Ptr.deref<
T>())
T(
Value);
1785template <PrimType Name, class T = typename PrimConv<Name>::T>
1787 const T &
Value = S.Stk.pop<
T>();
1789 if (Ptr.isUnknownSizeArray())
1794 new (&Ptr.deref<
T>())
T(
Value);
1805 return DoMemcpy(S, OpPC, Src, Dest);
1819 if (std::optional<Pointer> Ptr = MP.toPointer(S.Ctx)) {
1830template <
class T, ArithOp Op>
1834 if (Offset.isZero()) {
1853 uint64_t O =
static_cast<uint64_t
>(Offset) * Ptr.
elemSize();
1861 uint64_t MaxIndex =
static_cast<uint64_t
>(Ptr.
getNumElems());
1870 auto DiagInvalidOffset = [&]() ->
void {
1871 const unsigned Bits = Offset.bitWidth();
1872 APSInt APOffset(Offset.toAPSInt().extend(Bits + 2),
false);
1876 (Op ==
ArithOp::Add) ? (APIndex + APOffset) : (APIndex - APOffset);
1877 S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
1878 << NewIndex <<
static_cast<int>(!Ptr.
inArray()) << MaxIndex;
1883 uint64_t IOffset =
static_cast<uint64_t
>(Offset);
1884 uint64_t MaxOffset = MaxIndex - Index;
1888 if (Offset.isNegative() && (Offset.isMin() || -IOffset > Index))
1889 DiagInvalidOffset();
1892 if (Offset.isPositive() && IOffset > MaxOffset)
1893 DiagInvalidOffset();
1896 if (Offset.isPositive() && Index < IOffset)
1897 DiagInvalidOffset();
1900 if (Offset.isNegative() && (Offset.isMin() || -IOffset > MaxOffset))
1901 DiagInvalidOffset();
1909 int64_t WideIndex =
static_cast<int64_t
>(Index);
1910 int64_t WideOffset =
static_cast<int64_t
>(Offset);
1913 Result = WideIndex + WideOffset;
1915 Result = WideIndex - WideOffset;
1930template <PrimType Name, class T = typename PrimConv<Name>::T>
1932 const T &Offset = S.Stk.pop<
T>();
1934 return OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr);
1937template <PrimType Name, class T = typename PrimConv<Name>::T>
1939 const T &Offset = S.Stk.pop<
T>();
1941 return OffsetHelper<T, ArithOp::Sub>(S, OpPC, Offset, Ptr);
1944template <ArithOp Op>
1960 OneT One = OneT::from(1);
1961 if (!OffsetHelper<OneT, Op>(S, OpPC, One,
P))
1975 return IncDecPtrHelper<ArithOp::Add>(S, OpPC, Ptr);
1984 return IncDecPtrHelper<ArithOp::Sub>(S, OpPC, Ptr);
1990template <PrimType Name, class T = typename PrimConv<Name>::T>
1995 for (
const Pointer &
P : {LHS, RHS}) {
1996 if (
P.isZeroSizeArray()) {
1998 while (
auto *AT = dyn_cast<ArrayType>(PtrT))
1999 PtrT = AT->getElementType();
2001 QualType ArrayTy = S.getCtx().getConstantArrayType(
2003 S.FFDiag(S.Current->getSource(OpPC),
2004 diag::note_constexpr_pointer_subtraction_zero_size)
2021 if (LHS.
isZero() && RHS.isZero()) {
2028 T B = RHS.isElementPastEnd() ? T::from(RHS.getNumElems())
2029 : T::from(RHS.getIndex());
2030 return AddSubMulHelper<T, T::sub, std::minus>(S, OpPC, A.bitWidth(), A, B);
2038 S.Current->destroy(I);
2043 S.Current->initScope(I);
2054 S.Stk.push<
U>(U::from(S.Stk.pop<
T>()));
2061 llvm::RoundingMode RM) {
2070template <PrimType Name, class T = typename PrimConv<Name>::T>
2077template <PrimType Name, class T = typename PrimConv<Name>::T>
2084template <PrimType Name, class T = typename PrimConv<Name>::T>
2086 const llvm::fltSemantics *Sem,
2087 llvm::RoundingMode RM) {
2088 const T &From = S.Stk.pop<
T>();
2089 APSInt FromAP = From.toAPSInt();
2098template <PrimType Name, class T = typename PrimConv<Name>::T>
2102 if constexpr (std::is_same_v<T, Boolean>) {
2111 if ((Status & APFloat::opStatus::opInvalidOp)) {
2112 const Expr *
E = S.Current->getExpr(OpPC);
2115 S.CCEDiag(
E, diag::note_constexpr_overflow) << F.
getAPFloat() <<
Type;
2116 if (S.noteUndefinedBehavior()) {
2129 uint32_t BitWidth) {
2136 if ((Status & APFloat::opStatus::opInvalidOp) && F.
isFinite()) {
2137 const Expr *
E = S.Current->getExpr(OpPC);
2140 S.CCEDiag(
E, diag::note_constexpr_overflow) << F.
getAPFloat() <<
Type;
2141 return S.noteUndefinedBehavior();
2149 uint32_t BitWidth) {
2156 if ((Status & APFloat::opStatus::opInvalidOp) && F.
isFinite()) {
2157 const Expr *
E = S.Current->getExpr(OpPC);
2160 S.CCEDiag(
E, diag::note_constexpr_overflow) << F.
getAPFloat() <<
Type;
2161 return S.noteUndefinedBehavior();
2168template <PrimType Name, class T = typename PrimConv<Name>::T>
2176 S.CCEDiag(
E, diag::note_constexpr_invalid_cast)
2177 << 2 << S.
getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2184 uint32_t BitWidth) {
2191 S.CCEDiag(
E, diag::note_constexpr_invalid_cast)
2192 << 2 << S.
getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2200 uint32_t BitWidth) {
2207 S.CCEDiag(
E, diag::note_constexpr_invalid_cast)
2208 << 2 << S.
getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2216 const auto &Ptr = S.Stk.peek<
Pointer>();
2219 bool HasValidResult = !Ptr.
isZero();
2221 if (HasValidResult) {
2225 S.CCEDiag(
E, diag::note_constexpr_invalid_cast)
2226 << 3 <<
"'void *'" << S.Current->getRange(OpPC);
2230 S.CCEDiag(
E, diag::note_constexpr_invalid_cast)
2231 << 2 << S.
getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2241template <PrimType Name, class T = typename PrimConv<Name>::T>
2243 S.Stk.push<
T>(T::zero());
2257template <PrimType Name, class T = typename PrimConv<Name>::T>
2260 S.Stk.push<
T>(0, Desc);
2270 if (S.checkingPotentialConstantExpression()) {
2279 if (!
This.isDummy()) {
2280 assert(isa<CXXMethodDecl>(S.Current->getFunction()->getDecl()));
2281 assert(
This.getRecord());
2283 This.getRecord()->getDecl() ==
2284 cast<CXXMethodDecl>(S.Current->getFunction()->getDecl())->getParent());
2292 assert(S.Current->getFunction()->hasRVO());
2293 if (S.checkingPotentialConstantExpression())
2295 S.Stk.push<
Pointer>(S.Current->getRVOPtr());
2304template <
class LT,
class RT, ShiftDir Dir>
2306 const unsigned Bits = LHS.bitWidth();
2310 RT::bitAnd(RHS, RT::from(LHS.bitWidth() - 1, RHS.bitWidth()),
2311 RHS.bitWidth(), &RHS);
2313 if (RHS.isNegative()) {
2317 S.CCEDiag(
Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
2318 if (!S.noteUndefinedBehavior())
2327 if (LHS.isNegative() && !S.
getLangOpts().CPlusPlus20) {
2333 S.CCEDiag(
Loc, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
2334 if (!S.noteUndefinedBehavior())
2345 typename LT::AsUnsigned R;
2347 if (RHS > RT::from(Bits - 1, RHS.bitWidth()))
2348 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
2349 LT::AsUnsigned::from(Bits - 1), Bits, &R);
2351 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
2352 LT::AsUnsigned::from(RHS, Bits), Bits, &R);
2354 if (RHS > RT::from(Bits - 1, RHS.bitWidth()))
2355 LT::AsUnsigned::shiftRight(LT::AsUnsigned::from(LHS),
2356 LT::AsUnsigned::from(Bits - 1), Bits, &R);
2358 LT::AsUnsigned::shiftRight(LT::AsUnsigned::from(LHS),
2359 LT::AsUnsigned::from(RHS, Bits), Bits, &R);
2364 if (LHS.isSigned() && LHS.isNegative()) {
2365 typename LT::AsUnsigned SignBit;
2366 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(1, Bits),
2367 LT::AsUnsigned::from(Bits - 1, Bits), Bits,
2369 LT::AsUnsigned::bitOr(R, SignBit, Bits, &R);
2373 S.Stk.push<
LT>(LT::from(R));
2377template <PrimType NameL, PrimType NameR>
2381 auto RHS = S.Stk.pop<RT>();
2382 auto LHS = S.Stk.pop<
LT>();
2384 return DoShift<LT, RT, ShiftDir::Right>(S, OpPC, LHS, RHS);
2387template <PrimType NameL, PrimType NameR>
2391 auto RHS = S.Stk.pop<RT>();
2392 auto LHS = S.Stk.pop<
LT>();
2394 return DoShift<LT, RT, ShiftDir::Left>(S, OpPC, LHS, RHS);
2403 S.FFDiag(EndLoc, diag::note_constexpr_no_return);
2431template <PrimType Name, class T = typename PrimConv<Name>::T>
2433 const T &Offset = S.Stk.pop<
T>();
2436 if (!Ptr.isZero() && !Offset.isZero()) {
2441 if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
2447template <PrimType Name, class T = typename PrimConv<Name>::T>
2449 const T &Offset = S.Stk.pop<
T>();
2452 if (!Ptr.isZero() && !Offset.isZero()) {
2457 if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
2463template <PrimType Name, class T = typename PrimConv<Name>::T>
2474template <PrimType Name, class T = typename PrimConv<Name>::T>
2485template <PrimType Name, class T = typename PrimConv<Name>::T>
2487 uint32_t DestIndex, uint32_t Size) {
2488 const auto &SrcPtr = S.Stk.pop<
Pointer>();
2489 const auto &DestPtr = S.Stk.peek<
Pointer>();
2491 for (uint32_t I = 0; I != Size; ++I) {
2523 S.FFDiag(
E, diag::note_constexpr_unsupported_unsized_array);
2529 uint32_t VarArgSize) {
2530 if (
Func->hasThisPointer()) {
2531 size_t ArgSize =
Func->getArgSize() + VarArgSize;
2539 if (!(S.Current->getFunction() &&
2540 S.Current->getFunction()->isLambdaStaticInvoker() &&
2541 Func->isLambdaCallOperator())) {
2546 if (S.checkingPotentialConstantExpression())
2556 auto NewFrame = std::make_unique<InterpFrame>(S,
Func, OpPC, VarArgSize);
2558 S.Current = NewFrame.get();
2566 assert(S.Current == FrameBefore);
2572 S.Current = FrameBefore;
2579 uint32_t VarArgSize) {
2580 if (
Func->hasThisPointer()) {
2581 size_t ArgSize =
Func->getArgSize() + VarArgSize;
2590 if (!(S.Current->getFunction() &&
2591 S.Current->getFunction()->isLambdaStaticInvoker() &&
2592 Func->isLambdaCallOperator())) {
2601 if (
Func->hasThisPointer() && S.checkingPotentialConstantExpression())
2607 auto NewFrame = std::make_unique<InterpFrame>(S,
Func, OpPC, VarArgSize);
2609 S.Current = NewFrame.get();
2617 assert(S.Current == FrameBefore);
2623 S.Current = FrameBefore;
2628 uint32_t VarArgSize) {
2629 assert(
Func->hasThisPointer());
2630 assert(
Func->isVirtual());
2631 size_t ArgSize =
Func->getArgSize() + VarArgSize;
2643 DynamicDecl =
DynamicType->getPointeeCXXRecordDecl();
2647 assert(DynamicDecl);
2649 const auto *StaticDecl = cast<CXXRecordDecl>(
Func->getParentDecl());
2650 const auto *InitialFunction = cast<CXXMethodDecl>(
Func->getDecl());
2651 const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction(
2652 DynamicDecl, StaticDecl, InitialFunction);
2654 if (Overrider != InitialFunction) {
2659 const Expr *
E = S.Current->getExpr(OpPC);
2663 Func = S.getContext().getOrCreateFunction(Overrider);
2666 ThisPtr.getFieldDesc()->getType()->getAsCXXRecordDecl();
2667 if (
Func->getParentDecl()->isDerivedFrom(ThisFieldDecl)) {
2671 while (ThisPtr.isBaseClass())
2672 ThisPtr = ThisPtr.getBase();
2676 if (!
Call(S, OpPC,
Func, VarArgSize))
2681 if (Overrider != InitialFunction &&
2683 InitialFunction->getReturnType()->isPointerOrReferenceType()) {
2692 unsigned Offset = S.getContext().collectBaseOffset(
2703 auto NewFrame = std::make_unique<InterpFrame>(S,
Func, PC);
2706 S.Current = NewFrame.get();
2712 S.Current = FrameBefore;
2722 const auto *
E = cast<CallExpr>(S.Current->getExpr(OpPC));
2723 S.FFDiag(
E, diag::note_constexpr_null_callee)
2728 if (!FuncPtr.
isValid() || !F->getDecl())
2735 if (S.Ctx.classify(F->getDecl()->getReturnType()) !=
2736 S.Ctx.classify(CE->
getType()))
2740 if (F->hasNonNullAttr()) {
2745 assert(ArgSize >= F->getWrittenArgSize());
2746 uint32_t VarArgSize = ArgSize - F->getWrittenArgSize();
2750 if (F->isThisPointerExplicit())
2754 return CallVirt(S, OpPC, F, VarArgSize);
2756 return Call(S, OpPC, F, VarArgSize);
2765template <PrimType Name, class T = typename PrimConv<Name>::T>
2767 const T &IntVal = S.Stk.pop<
T>();
2769 S.Stk.push<
Pointer>(
static_cast<uint64_t
>(IntVal), Desc);
2781 S.Stk.push<
Pointer>(MP.getBase());
2788 const auto *FD = cast<FunctionDecl>(MP.getDecl());
2789 const auto *
Func = S.getContext().getOrCreateFunction(FD);
2799 S.FFDiag(
Loc, diag::note_invalid_subexpr_in_const_expr)
2800 << S.Current->getRange(OpPC);
2806 S.FFDiag(
Loc, diag::note_constexpr_stmt_expr_unsupported)
2807 << S.Current->getRange(OpPC);
2821 S.CCEDiag(
Loc, diag::note_constexpr_invalid_cast)
2822 <<
static_cast<unsigned>(Kind) << S.Current->getRange(OpPC);
2835 if (S.inConstantContext()) {
2836 const SourceRange &ArgRange = S.Current->getRange(OpPC);
2837 const Expr *
E = S.Current->getExpr(OpPC);
2838 S.CCEDiag(
E, diag::note_constexpr_non_const_vectorelements) << ArgRange;
2844 const auto Val = S.Stk.pop<
Boolean>();
2851 S.CCEDiag(
Loc, diag::note_constexpr_assumption_failed);
2855template <PrimType Name, class T = typename PrimConv<Name>::T>
2858 for (
size_t I = 0; I !=
E->getNumExpressions(); ++I)
2859 ArrayIndices.emplace_back(S.Stk.pop<int64_t>());
2865 S.Stk.push<
T>(T::from(
Result));
2870template <PrimType Name, class T = typename PrimConv<Name>::T>
2872 const T &Arg = S.Stk.peek<
T>();
2877 S.CCEDiag(
Loc, diag::note_non_null_attribute_failed);
2885template <PrimType Name, class T = typename PrimConv<Name>::T>
2889 const APSInt Val = S.Stk.peek<
T>().toAPSInt();
2891 if (S.inConstantContext())
2897template <PrimType TIn, PrimType TOut>
2903 const FromT &OldPtr = S.Stk.pop<FromT>();
2905 if constexpr (std::is_same_v<FromT, FunctionPointer> &&
2906 std::is_same_v<ToT, Pointer>) {
2907 S.Stk.push<
Pointer>(OldPtr.getFunction());
2911 S.Stk.push<ToT>(ToT(OldPtr.getIntegerRepresentation(),
nullptr));
2923 if (VD == S.EvaluatingDecl)
2927 S.CCEDiag(VD->
getLocation(), diag::note_constexpr_static_local)
2941 Block *B = Allocator.allocate(Desc, S.Ctx.getEvalID());
2949template <PrimType Name, class SizeT = typename PrimConv<Name>::T>
2955 SizeT NumElements = S.Stk.pop<SizeT>();
2961 S.Stk.push<
Pointer>(0,
nullptr);
2966 Block *B = Allocator.allocate(Source,
T,
static_cast<size_t>(NumElements),
2974template <PrimType Name, class SizeT = typename PrimConv<Name>::T>
2980 SizeT NumElements = S.Stk.pop<SizeT>();
2987 S.Stk.push<
Pointer>(0, ElementDesc);
2992 Block *B = Allocator.allocate(ElementDesc,
static_cast<size_t>(NumElements),
3001bool RunDestructors(InterpState &S, CodePtr OpPC,
const Block *B);
3006 const Expr *Source =
nullptr;
3007 const Block *BlockToDelete =
nullptr;
3019 S.FFDiag(
Loc, diag::note_constexpr_delete_subobject)
3025 BlockToDelete = Ptr.
block();
3031 assert(BlockToDelete);
3038 bool WasArrayAlloc = Allocator.isArrayAllocation(Source);
3041 if (!Allocator.deallocate(Source, BlockToDelete, S)) {
3044 S.FFDiag(
Loc, diag::note_constexpr_double_delete);
3069 if (S.EvaluatingDecl)
3072 if (S.Current->getFunction() && S.Current->getFunction()->isConstructor() &&
3073 S.Current->getThis().getDeclDesc()->asDecl() == S.EvaluatingDecl)
3076 const Expr *
E = S.Current->getExpr(OpPC);
3078 S.FFDiag(
E, diag::note_constexpr_nonliteral) <<
E->
getType();
3080 S.FFDiag(
E, diag::note_invalid_subexpr_in_const_expr);
3089 if constexpr (std::is_pointer<T>::value) {
3090 uint32_t ID = OpPC.
read<uint32_t>();
3091 return reinterpret_cast<T>(S.P.getNativePointer(ID));
3093 return OpPC.
read<
T>();
3104inline IntegralAP<false> ReadArg<IntegralAP<false>>(InterpState &S,
3107 OpPC +=
align(I.bytesToSerialize());
3112inline IntegralAP<true> ReadArg<IntegralAP<true>>(InterpState &S,
3115 OpPC +=
align(I.bytesToSerialize());
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
void HandleComplexComplexDiv(APFloat A, APFloat B, APFloat C, APFloat D, APFloat &ResR, APFloat &ResI)
void HandleComplexComplexMul(APFloat A, APFloat B, APFloat C, APFloat D, APFloat &ResR, APFloat &ResI)
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
ComparisonCategoryResult makeWeakResult(ComparisonCategoryResult Res) const
Converts the specified result kind into the correct result kind for this category.
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
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...
QualType getReturnType() const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
APValue * getOrCreateValue(bool MayCreate) const
Get the storage for the constant value of a materialized temporary of static storage duration.
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
A (possibly-)qualified type.
Represents a struct/union/class.
const LangOptions & getLangOpts() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
The base class of the type hierarchy.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isPointerOrReferenceType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
ThreadStorageClassSpecifier getTSCSpec() const
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
bool isUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value can be used in a constant expression, according to the releva...
A memory block, either on the stack or in the heap.
unsigned getSize() const
Returns the size of the block.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
Wrapper around boolean types.
static Boolean from(T Value)
Pointer into the code segment.
std::enable_if_t<!std::is_pointer< T >::value, T > read()
Reads data and advances the pointer.
Manages dynamic memory allocations done during bytecode interpretation.
static APFloat::opStatus div(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
static Floating deserialize(const std::byte *Buff)
static APFloat::opStatus sub(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
const APFloat & getAPFloat() const
static APFloat::opStatus increment(const Floating &A, llvm::RoundingMode RM, Floating *R)
static APFloat::opStatus fromIntegral(APSInt Val, const llvm::fltSemantics &Sem, llvm::RoundingMode RM, Floating &Result)
Floating toSemantics(const llvm::fltSemantics *Sem, llvm::RoundingMode RM) const
size_t bytesToSerialize() const
static APFloat::opStatus add(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
static APFloat::opStatus mul(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
static APFloat::opStatus decrement(const Floating &A, llvm::RoundingMode RM, Floating *R)
APFloat::opStatus convertToInteger(APSInt &Result) const
const Function * getFunction() const
ComparisonCategoryResult compare(const FunctionPointer &RHS) const
std::string toDiagnosticString(const ASTContext &Ctx) const
static IntegralAP< Signed > deserialize(const std::byte *Buff)
static IntegralAP zero(int32_t BitWidth)
static IntegralAP from(T Value, unsigned NumBits=0)
Wrapper around numeric types.
Frame storing local variables.
ComparisonCategoryResult compare(const MemberPointer &RHS) const
A pointer to a memory block, live or dead.
static bool hasSameBase(const Pointer &A, const Pointer &B)
Checks if two pointers are comparable.
Pointer narrow() const
Restricts the scope of an array element pointer.
void deactivate() const
Deactivates an entire strurcutre.
bool isInitialized() const
Checks if an object was initialized.
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.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
T & deref() const
Dereferences the pointer, if it's live.
unsigned getNumElems() const
Returns the number of elements.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
void activate() const
Activats a field.
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 isArrayRoot() const
Whether this array refers to an array, but not to the first element.
bool inArray() const
Checks if the innermost field is an array.
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
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.
ComparisonCategoryResult compare(const Pointer &Other) const
Compare two pointers.
const IntPointer & asIntPointer() const
bool isRoot() const
Pointer points directly to a block.
const Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
unsigned getOffset() const
Returns the offset into an array.
bool isOnePastEnd() const
Checks if the index is one past end.
uint64_t getIntegerRepresentation() const
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.
bool isBlockPointer() const
const Block * block() const
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool isBaseClass() const
Checks if a structure is a base class.
size_t elemSize() const
Returns the element size of the innermost field.
bool canBeInitialized() const
If this pointer has an InlineDescriptor we can use to initialize.
const BlockPointer & asBlockPointer() const
void initialize() const
Initializes a field.
unsigned getByteOffset() const
Returns the byte offset from the start.
Describes the statement/declaration an opcode was generated from.
bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS, unsigned Bits)
Checks if the shift operation is legal.
bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off)
bool InitPop(InterpState &S, CodePtr OpPC)
bool Shr(InterpState &S, CodePtr OpPC)
bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I, const LifetimeExtendedTemporaryDecl *Temp)
1) Converts the value on top of the stack to an APValue 2) Sets that APValue on \Temp 3) Initializes ...
bool IncPop(InterpState &S, CodePtr OpPC)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index)
bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off)
bool Subf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool ArrayElem(InterpState &S, CodePtr OpPC, uint32_t Index)
bool GT(InterpState &S, CodePtr OpPC)
bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be initialized.
bool GetMemberPtrBase(InterpState &S, CodePtr OpPC)
bool DecPop(InterpState &S, CodePtr OpPC)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value decreased by ...
bool GetThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool NarrowPtr(InterpState &S, CodePtr OpPC)
bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B)
bool GetMemberPtrBasePop(InterpState &S, CodePtr OpPC, int32_t Off)
bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool Interpret(InterpState &S, APValue &Result)
Interpreter entry point.
Floating ReadArg< Floating >(InterpState &S, CodePtr &OpPC)
static bool ZeroIntAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool Incf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool GetParam(InterpState &S, CodePtr OpPC, uint32_t I)
bool InitElemPop(InterpState &S, CodePtr OpPC, uint32_t Idx)
The same as InitElem, but pops the pointer as well.
bool StoreBitField(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 LoadPop(InterpState &S, CodePtr OpPC)
bool DecfPop(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
static bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
static bool IncPtr(InterpState &S, CodePtr OpPC)
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 Dup(InterpState &S, CodePtr OpPC)
bool CheckCallDepth(InterpState &S, CodePtr OpPC)
Checks if calling the currently active function would exceed the allowed call depth.
bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This)
Checks the 'this' pointer.
bool SetField(InterpState &S, CodePtr OpPC, uint32_t I)
bool CheckNonNullArg(InterpState &S, CodePtr OpPC)
bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E, llvm::ArrayRef< int64_t > ArrayIndices, int64_t &Result)
Interpret an offsetof operation.
bool SetThreeWayComparisonField(InterpState &S, CodePtr OpPC, const Pointer &Ptr, const APSInt &IntValue)
Sets the given integral value to the pointer, which is of a std::{weak,partial,strong}_ordering type.
static bool IncDecPtrHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool GetPtrLocal(InterpState &S, CodePtr OpPC, uint32_t I)
static bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS)
Checks if Div/Rem operation on LHS and RHS is valid.
bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
Checks if the Descriptor is of a constexpr or const global variable.
bool CheckDecl(InterpState &S, CodePtr OpPC, const VarDecl *VD)
bool AddSubMulHelper(InterpState &S, CodePtr OpPC, unsigned Bits, const T &LHS, const T &RHS)
bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off)
1) Peeks a Pointer 2) Pushes Pointer.atField(Off) on the stack
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to a mutable field.
bool GetFnPtr(InterpState &S, CodePtr OpPC, const Function *Func)
bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I)
Same as GetGlobal, but without the checks.
bool GetPtrActiveThisField(InterpState &S, CodePtr OpPC, uint32_t Off)
bool SubPtr(InterpState &S, CodePtr OpPC)
1) Pops a Pointer from the stack.
bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if Ptr is a one-past-the-end pointer.
static bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool GetPtrGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool Mulc(InterpState &S, CodePtr OpPC)
bool ArrayElemPtr(InterpState &S, CodePtr OpPC)
bool NE(InterpState &S, CodePtr OpPC)
bool NoRet(InterpState &S, CodePtr OpPC)
bool GetIntPtr(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a value can be loaded from a block.
static bool ZeroIntAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool Addf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool Shl(InterpState &S, CodePtr OpPC)
bool RVOPtr(InterpState &S, CodePtr OpPC)
bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
bool CastPointerIntegral(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
bool SubOffset(InterpState &S, CodePtr OpPC)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool BitXor(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is in range.
bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
bool CastAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool ExpandPtr(InterpState &S, CodePtr OpPC)
bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD)
Checks if a method is pure virtual.
bool Store(InterpState &S, CodePtr OpPC)
bool Divc(InterpState &S, CodePtr OpPC)
bool GetField(InterpState &S, CodePtr OpPC, uint32_t I)
1) Peeks a pointer on the stack 2) Pushes the value of the pointer's field on the stack
bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC)
bool This(InterpState &S, CodePtr OpPC)
bool InitScope(InterpState &S, CodePtr OpPC, uint32_t I)
bool Mulf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool CheckDynamicMemoryAllocation(InterpState &S, CodePtr OpPC)
Checks if dynamic memory allocation is available in the current language mode.
bool InitField(InterpState &S, CodePtr OpPC, uint32_t I)
1) Pops the value from the stack 2) Peeks a pointer from the stack 3) Pushes the value to field I of ...
bool IncDecFloatHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr, llvm::RoundingMode RM)
bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex, uint32_t DestIndex, uint32_t Size)
bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn)
llvm::function_ref< bool(ComparisonCategoryResult)> CompareFn
T ReadArg(InterpState &S, CodePtr &OpPC)
bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is live and accessible.
bool ArrayDecay(InterpState &S, CodePtr OpPC)
Just takes a pointer and checks if it's an incomplete array type.
bool InitGlobalTempComp(InterpState &S, CodePtr OpPC, const LifetimeExtendedTemporaryDecl *Temp)
1) Converts the value on top of the stack to an APValue 2) Sets that APValue on \Temp 3) Initialized ...
bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool CastFloatingIntegral(InterpState &S, CodePtr OpPC)
bool GetLocal(InterpState &S, CodePtr OpPC, uint32_t I)
bool OffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E)
bool BitAnd(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED, const APSInt &Value)
bool CastIntegralFloating(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem, llvm::RoundingMode RM)
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
bool Zero(InterpState &S, CodePtr OpPC)
bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F, uint32_t FieldOffset)
bool Unsupported(InterpState &S, CodePtr OpPC)
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be stored in a block.
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 CastFP(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem, llvm::RoundingMode RM)
1) Pops a Floating from the stack.
ComparisonCategoryResult Compare(const T &X, const T &Y)
Helper to compare two comparable types.
bool SetThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool StoreBitFieldPop(InterpState &S, CodePtr OpPC)
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
static bool DecPtr(InterpState &S, CodePtr OpPC)
bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
bool ToMemberPtr(InterpState &S, CodePtr OpPC)
bool Rem(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
bool VirtBaseHelper(InterpState &S, CodePtr OpPC, const RecordDecl *Decl, const Pointer &Ptr)
bool IncfPop(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool Dump(InterpState &S, CodePtr OpPC)
bool SizelessVectorElementSize(InterpState &S, CodePtr OpPC)
bool Null(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
static bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
static bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr)
bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T)
bool GetPtrThisField(InterpState &S, CodePtr OpPC, uint32_t Off)
bool GetPtrActiveField(InterpState &S, CodePtr OpPC, uint32_t Off)
bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the array is offsetable.
bool Decf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Check if a global variable is initialized.
bool GetPtrDerivedPop(InterpState &S, CodePtr OpPC, uint32_t Off)
bool CheckNonNullArgs(InterpState &S, CodePtr OpPC, const Function *F, const CallExpr *CE, unsigned ArgSize)
Checks if all the arguments annotated as 'nonnull' are in fact not null.
bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off)
bool SetParam(InterpState &S, CodePtr OpPC, uint32_t I)
bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is a dummy pointer.
bool GetMemberPtrDecl(InterpState &S, CodePtr OpPC)
bool CmpHelper< FunctionPointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
Function pointers cannot be compared in an ordered way.
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
bool DecayPtr(InterpState &S, CodePtr OpPC)
OldPtr -> Integer -> NewPtr.
bool GetPtrVirtBasePop(InterpState &S, CodePtr OpPC, const RecordDecl *D)
bool StorePop(InterpState &S, CodePtr OpPC)
void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC)
bool CallBI(InterpState &S, CodePtr &PC, const Function *Func, const CallExpr *CE)
bool SetLocal(InterpState &S, CodePtr OpPC, uint32_t I)
1) Pops the value from the stack.
bool FinishInit(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS)
bool InitElem(InterpState &S, CodePtr OpPC, uint32_t Idx)
1) Pops the value from the stack 2) Peeks a pointer and gets its index \Idx 3) Sets the value on the ...
bool Destroy(InterpState &S, CodePtr OpPC, uint32_t I)
bool Pop(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool InitBitField(InterpState &S, CodePtr OpPC, const Record::Field *F)
bool GetMemberPtr(InterpState &S, CodePtr OpPC, const Decl *D)
bool InvalidDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR)
bool FinishInitPop(InterpState &S, CodePtr OpPC)
bool ReturnValue(const InterpState &S, const T &V, APValue &R)
Convert a value to an APValue.
bool InRange(InterpState &S, CodePtr OpPC)
bool CmpHelperEQ< FunctionPointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
bool Neg(InterpState &S, CodePtr OpPC)
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, const CallExpr *Call)
Interpret a builtin function.
bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the variable has externally defined storage.
bool Divf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM)
bool BitOr(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
bool Inv(InterpState &S, CodePtr OpPC)
bool Load(InterpState &S, CodePtr OpPC)
bool SetGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool Cast(InterpState &S, CodePtr OpPC)
bool EQ(InterpState &S, CodePtr OpPC)
bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool NewWasArray, bool DeleteIsArray, const Descriptor *D, const Expr *NewExpr)
Diagnose mismatched new[]/delete or new/delete[] pairs.
bool GetFieldPop(InterpState &S, CodePtr OpPC, uint32_t I)
1) Pops a pointer from the stack 2) Pushes the value of the pointer's field on the stack
bool CmpHelperEQ< MemberPointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F)
Checks if a method can be called.
bool AddOffset(InterpState &S, CodePtr OpPC)
bool Const(InterpState &S, CodePtr OpPC, const T &Arg)
bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest)
Copy the contents of Src into Dest.
bool Memcpy(InterpState &S, CodePtr OpPC)
bool GE(InterpState &S, CodePtr OpPC)
bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements, unsigned ElemSize, bool IsNoThrow)
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize, const CallExpr *CE)
bool CmpHelperEQ< Pointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
constexpr bool isIntegralType(PrimType T)
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
bool CmpHelper(InterpState &S, CodePtr OpPC, CompareFn Fn)
bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to const storage.
bool GetPtrParam(InterpState &S, CodePtr OpPC, uint32_t I)
bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc, bool IsNoThrow)
bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool GetPtrThisVirtBase(InterpState &S, CodePtr OpPC, const RecordDecl *D)
bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal)
Same here, but only for casts.
bool CastMemberPtrPtr(InterpState &S, CodePtr OpPC)
bool RetVoid(InterpState &S, CodePtr &PC, APValue &Result)
bool Flip(InterpState &S, CodePtr OpPC)
[Value1, Value2] -> [Value2, Value1]
bool CMP3(InterpState &S, CodePtr OpPC, const ComparisonCategoryInfo *CmpInfo)
bool CastAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
Like Cast(), but we cast to an arbitrary-bitwidth integral, so we need to know what bitwidth the resu...
bool CmpHelper< Pointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
bool Assume(InterpState &S, CodePtr OpPC)
bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a method can be invoked on an object.
bool GetPtrThisBase(InterpState &S, CodePtr OpPC, uint32_t Off)
static bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm)
bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result, APFloat::opStatus Status)
Checks if the result of a floating-point operation is valid in the current context.
bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, const Pointer &Ptr)
bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source, bool IsNoThrow)
bool CheckEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED)
The JSON file list parser is used to communicate input to InstallAPI.
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
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.
const FunctionProtoType * T
unsigned Base
Start of the current subfield.
Block * Pointee
The block the pointer is pointing to.
Describes a memory block created by an allocation site.
unsigned getSize() const
Returns the size of the object without metadata.
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
const Expr * asExpr() const
Inline descriptor embedded in structures and arrays.
IntPointer atOffset(const ASTContext &ASTCtx, unsigned Offset) const
Mapping from primitive types to their representation.