13#ifndef LLVM_CLANG_AST_INTERP_INTERP_H
14#define LLVM_CLANG_AST_INTERP_INTERP_H
35#include "llvm/ADT/APFloat.h"
36#include "llvm/ADT/APSInt.h"
37#include "llvm/ADT/ScopeExit.h"
44#if !defined(__aarch64__) && !defined(__i386__) && \
45 !__has_feature(address_sanitizer) && \
46 __has_cpp_attribute(clang::preserve_none)
47#define PRESERVE_NONE [[clang::preserve_none]]
55using APSInt = llvm::APSInt;
93 bool WillBeActivated =
false);
119 uint32_t VarArgSize);
121 uint32_t VarArgSize);
123 uint32_t VarArgSize);
131 bool TargetIsUCharOrByte);
150template <ShiftDir Dir,
typename LT,
typename RT>
153 if (RHS.isNegative()) {
155 S.
CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
164 const APSInt Val = RHS.toAPSInt();
166 S.
CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty <<
Bits;
172 if (LHS.isSigned() && !S.
getLangOpts().CPlusPlus20) {
175 if (LHS.isNegative()) {
177 S.
CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
180 }
else if (LHS.toUnsigned().countLeadingZeros() <
181 static_cast<unsigned>(RHS)) {
183 S.
CCEDiag(E, diag::note_constexpr_lshift_discards);
201 if (!LHS.isNumber() || !RHS.isNumber())
207 if constexpr (std::is_same_v<T, Floating>) {
208 S.
CCEDiag(Op, diag::note_expr_divide_by_zero)
209 << Op->getRHS()->getSourceRange();
213 S.
FFDiag(Op, diag::note_expr_divide_by_zero)
214 << Op->getRHS()->getSourceRange();
218 if constexpr (!std::is_same_v<T, FixedPoint>) {
219 if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
220 APSInt LHSInt = LHS.toAPSInt();
222 (-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
225 S.
CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->
getType();
235 APFloat::opStatus Status,
FPOptions FPO);
257template <PrimType Name, class T = typename PrimConv<Name>::T>
304 template <typename U>
class OpAP>
309 assert(LHS.isNumber() && RHS.isNumber());
325 if constexpr (std::is_same_v<T, FixedPoint>)
341 .toString(Trunc, 10,
Result.isSigned(),
false,
355template <
typename T,
template <
typename U>
class Op>
357 assert(!LHS.isNumber() || !RHS.isNumber());
361 typename T::ReprT Offset;
363 if (LHS.isNumber()) {
364 Number =
static_cast<typename T::ReprT
>(LHS);
366 Offset = RHS.getOffset();
367 Kind = RHS.getKind();
369 assert(RHS.isNumber());
370 Number =
static_cast<typename T::ReprT
>(RHS);
372 Offset = LHS.getOffset();
373 Kind = LHS.getKind();
380template <PrimType Name, class T = typename PrimConv<Name>::T>
382 const T &RHS = S.
Stk.
pop<T>();
383 const T &LHS = S.
Stk.
pop<T>();
384 const unsigned Bits = RHS.bitWidth() + 1;
387 if (LHS.isNumber() != RHS.isNumber())
389 else if (LHS.isNumber() && RHS.isNumber())
409template <PrimType Name, class T = typename PrimConv<Name>::T>
411 const T &RHS = S.
Stk.
pop<T>();
412 const T &LHS = S.
Stk.
pop<T>();
413 const unsigned Bits = RHS.bitWidth() + 1;
422 ?
reinterpret_cast<const Expr *
>(LHS.getPtr())
425 ?
reinterpret_cast<const Expr *
>(RHS.getPtr())
427 if (!isa_and_nonnull<AddrLabelExpr>(A) ||
428 !isa_and_nonnull<AddrLabelExpr>(B))
433 if (LHSAddrExpr->getLabel()->getDeclContext() !=
434 RHSAddrExpr->getLabel()->getDeclContext())
437 S.
Stk.
push<T>(LHSAddrExpr, RHSAddrExpr);
441 if (!LHS.isNumber() && RHS.isNumber())
443 else if (LHS.isNumber() && RHS.isNumber())
463template <PrimType Name, class T = typename PrimConv<Name>::T>
465 const T &RHS = S.
Stk.
pop<T>();
466 const T &LHS = S.
Stk.
pop<T>();
467 const unsigned Bits = RHS.bitWidth() * 2;
470 if (!LHS.isNumber() || !RHS.isNumber())
490template <PrimType Name, class T = typename PrimConv<Name>::T>
496 if constexpr (std::is_same_v<T, Floating>) {
502 APFloat ResR(A.getSemantics());
503 APFloat ResI(A.getSemantics());
514 Result.initializeAllElements();
517 const T &LHSR = LHS.elem<T>(0);
518 const T &LHSI = LHS.elem<T>(1);
519 const T &RHSR = RHS.
elem<T>(0);
520 const T &RHSI = RHS.
elem<T>(1);
521 unsigned Bits = LHSR.bitWidth();
527 if (T::mul(LHSR, RHSR,
Bits, &A))
533 if (T::mul(LHSI, RHSI,
Bits, &B))
542 if (T::mul(LHSR, RHSI,
Bits, &A))
544 if (T::mul(LHSI, RHSR,
Bits, &B))
552 Result.initializeAllElements();
558template <PrimType Name, class T = typename PrimConv<Name>::T>
564 if constexpr (std::is_same_v<T, Floating>) {
570 APFloat ResR(A.getSemantics());
571 APFloat ResI(A.getSemantics());
583 Result.initializeAllElements();
586 const T &LHSR = LHS.elem<T>(0);
587 const T &LHSI = LHS.elem<T>(1);
588 const T &RHSR = RHS.
elem<T>(0);
589 const T &RHSI = RHS.
elem<T>(1);
590 unsigned Bits = LHSR.bitWidth();
592 if (RHSR.isZero() && RHSI.isZero()) {
594 S.
FFDiag(E, diag::note_expr_divide_by_zero);
605 if (T::mul(RHSR, RHSR,
Bits, &A) || T::mul(RHSI, RHSI,
Bits, &B)) {
612 if (T::add(A, B,
Bits, &Den))
617 S.
FFDiag(E, diag::note_expr_divide_by_zero);
622 T &ResultR =
Result.elem<T>(0);
623 T &ResultI =
Result.elem<T>(1);
628 if (T::mul(LHSR, RHSR,
Bits, &A) || T::mul(LHSI, RHSI,
Bits, &B))
630 if (T::add(A, B,
Bits, &ResultR))
632 if (T::div(ResultR, Den,
Bits, &ResultR))
636 if (T::mul(LHSI, RHSR,
Bits, &A) || T::mul(LHSR, RHSI,
Bits, &B))
638 if (T::sub(A, B,
Bits, &ResultI))
640 if (T::div(ResultI, Den,
Bits, &ResultI))
642 Result.initializeAllElements();
651template <PrimType Name, class T = typename PrimConv<Name>::T>
653 const T &RHS = S.
Stk.
pop<T>();
654 const T &LHS = S.
Stk.
pop<T>();
655 unsigned Bits = RHS.bitWidth();
658 if (!LHS.isNumber() || !RHS.isNumber())
676template <PrimType Name, class T = typename PrimConv<Name>::T>
678 const T &RHS = S.
Stk.
pop<T>();
679 const T &LHS = S.
Stk.
pop<T>();
680 unsigned Bits = RHS.bitWidth();
683 if (!LHS.isNumber() || !RHS.isNumber())
701template <PrimType Name, class T = typename PrimConv<Name>::T>
703 const T &RHS = S.
Stk.
pop<T>();
704 const T &LHS = S.
Stk.
pop<T>();
705 unsigned Bits = RHS.bitWidth();
708 if (!LHS.isNumber() || !RHS.isNumber())
726template <PrimType Name, class T = typename PrimConv<Name>::T>
728 const T &RHS = S.
Stk.
pop<T>();
729 const T &LHS = S.
Stk.
pop<T>();
730 const unsigned Bits = RHS.bitWidth() * 2;
749template <PrimType Name, class T = typename PrimConv<Name>::T>
751 const T &RHS = S.
Stk.
pop<T>();
752 const T &LHS = S.
Stk.
pop<T>();
753 const unsigned Bits = RHS.bitWidth() * 2;
767 if constexpr (std::is_same_v<T, FixedPoint>) {
806template <PrimType Name, class T = typename PrimConv<Name>::T>
810 if constexpr (std::is_same_v<T, Floating>) {
829 "don't expect other types to fail at constexpr negation");
840 NegatedValue.trunc(
Result.bitWidth())
841 .toString(Trunc, 10,
Result.isSigned(),
false,
861template <
typename T, IncDecOp Op, PushVal DoPush>
871 if constexpr (std::is_same_v<T, Boolean>) {
880 if (!
Value.isNumber())
892 if (!T::increment(
Value, &
Result) || !CanOverflow) {
900 if (!T::decrement(
Value, &
Result) || !CanOverflow) {
929 APResult.trunc(
Result.bitWidth())
930 .toString(Trunc, 10,
Result.isSigned(),
false,
943template <PrimType Name, class T = typename PrimConv<Name>::T>
955template <PrimType Name, class T = typename PrimConv<Name>::T>
971template <PrimType Name, class T = typename PrimConv<Name>::T>
982template <PrimType Name, class T = typename PrimConv<Name>::T>
995template <PrimType Name, class T = typename PrimConv<Name>::T>
1006template <PrimType Name, class T = typename PrimConv<Name>::T>
1008 uint32_t BitWidth) {
1023template <PrimType Name, class T = typename PrimConv<Name>::T>
1034template <PrimType Name, class T = typename PrimConv<Name>::T>
1036 uint32_t BitWidth) {
1050template <PrimType Name, class T = typename PrimConv<Name>::T>
1061template <PrimType Name, class T = typename PrimConv<Name>::T>
1063 uint32_t BitWidth) {
1074template <PrimType Name, class T = typename PrimConv<Name>::T>
1084template <PrimType Name, class T = typename PrimConv<Name>::T>
1086 uint32_t BitWidth) {
1096template <IncDecOp Op, PushVal DoPush>
1106 llvm::APFloat::opStatus Status;
1159template <PrimType Name, class T = typename PrimConv<Name>::T>
1161 const T &Val = S.
Stk.
pop<T>();
1167 if (!T::comp(Val, &
Result)) {
1180template <
typename T>
1182 assert((!std::is_same_v<T, MemberPointer>) &&
1183 "Non-equality comparisons on member pointer types should already be "
1184 "rejected in Sema.");
1186 const T &RHS = S.
Stk.
pop<T>();
1187 const T &LHS = S.
Stk.
pop<T>();
1190 if (!LHS.isNumber() || !RHS.isNumber())
1194 S.
Stk.
push<BoolT>(BoolT::from(
Fn(LHS.compare(RHS))));
1198template <
typename T>
1213 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1221 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1228 if (std::optional<std::pair<Pointer, Pointer>> Split =
1230 const FieldDecl *LF = Split->first.getField();
1231 const FieldDecl *RF = Split->second.getField();
1235 diag::note_constexpr_pointer_comparison_differing_access)
1248 return (
Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
1249 Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
1250 Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
1251 Builtin == Builtin::BI__builtin_function_start);
1263 if (LHS.isZero() && RHS.
isZero()) {
1269 for (
const auto &P : {LHS, RHS}) {
1274 S.
FFDiag(Loc, diag::note_constexpr_pointer_weak_comparison)
1296 S.
FFDiag(Loc, diag::note_constexpr_literal_comparison)
1304 size_t A = LHS.computeOffsetForComparison(S.
getASTContext());
1315 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
1319 if (RHS.
isOnePastEnd() && !LHS.isOnePastEnd() && !LHS.isZero() &&
1320 LHS.isBlockPointer() && LHS.getOffset() == 0) {
1322 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
1329 for (
const auto &P : {LHS, RHS}) {
1332 if (BothNonNull && P.pointsToLiteral()) {
1333 const Expr *E = P.getDeclDesc()->asExpr();
1336 S.
FFDiag(Loc, diag::note_constexpr_literal_comparison);
1339 if (
const auto *CE = dyn_cast<CallExpr>(E);
1342 S.
FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
1346 }
else if (BothNonNull && P.isIntegralPointer()) {
1348 S.
FFDiag(Loc, diag::note_constexpr_pointer_constant_comparison)
1357 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_zero_sized)
1375 for (
const auto &MP : {LHS, RHS}) {
1378 S.
FFDiag(Loc, diag::note_constexpr_mem_pointer_weak_comparison)
1379 << MP.getMemberFunction();
1387 if (LHS.
isZero() && RHS.isZero()) {
1391 if (LHS.
isZero() || RHS.isZero()) {
1397 for (
const auto &MP : {LHS, RHS}) {
1401 S.
CCEDiag(Loc, diag::note_constexpr_compare_virtual_mem_ptr) << MD;
1409template <PrimType Name, class T = typename PrimConv<Name>::T>
1416template <PrimType Name, class T = typename PrimConv<Name>::T>
1418 const T &RHS = S.
Stk.
pop<T>();
1419 const T &LHS = S.
Stk.
pop<T>();
1423 if constexpr (std::is_same_v<T, Pointer>) {
1426 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1434 const auto *CmpValueInfo =
1436 assert(CmpValueInfo);
1437 assert(CmpValueInfo->hasValidIntValue());
1441template <PrimType Name, class T = typename PrimConv<Name>::T>
1448template <PrimType Name, class T = typename PrimConv<Name>::T>
1455template <PrimType Name, class T = typename PrimConv<Name>::T>
1463template <PrimType Name, class T = typename PrimConv<Name>::T>
1470template <PrimType Name, class T = typename PrimConv<Name>::T>
1482template <PrimType Name, class T = typename PrimConv<Name>::T>
1488template <PrimType Name, class T = typename PrimConv<Name>::T>
1495template <PrimType TopName, PrimType BottomName>
1500 const auto &Top = S.
Stk.
pop<TopT>();
1501 const auto &Bottom = S.
Stk.
pop<BottomT>();
1513template <PrimType Name, class T = typename PrimConv<Name>::T>
1517 Result.copy(Arg.toAPSInt());
1522 if constexpr (std::is_same_v<T, uint16_t>) {
1524 }
else if constexpr (std::is_same_v<T, int16_t>) {
1526 }
else if constexpr (std::is_same_v<T, uint32_t>) {
1528 }
else if constexpr (std::is_same_v<T, int32_t>) {
1530 }
else if constexpr (std::is_same_v<T, uint64_t>) {
1532 }
else if constexpr (std::is_same_v<T, int64_t>) {
1553template <PrimType Name, class T = typename PrimConv<Name>::T>
1571template <PrimType Name, class T = typename PrimConv<Name>::T>
1577template <PrimType Name, class T = typename PrimConv<Name>::T>
1586template <PrimType Name, class T = typename PrimConv<Name>::T>
1594template <PrimType Name, class T = typename PrimConv<Name>::T>
1604 S.
Stk.
push<T>(Field.deref<T>());
1608template <PrimType Name, class T = typename PrimConv<Name>::T>
1620 Field.deref<T>() =
Value;
1626template <PrimType Name, class T = typename PrimConv<Name>::T>
1636 S.
Stk.
push<T>(Field.deref<T>());
1640template <PrimType Name, class T = typename PrimConv<Name>::T>
1650 S.
Stk.
push<T>(Field.deref<T>());
1654template <PrimType Name, class T = typename PrimConv<Name>::T>
1665 Field.deref<T>() =
Value;
1669template <PrimType Name, class T = typename PrimConv<Name>::T>
1681template <PrimType Name, class T = typename PrimConv<Name>::T>
1692template <PrimType Name, class T = typename PrimConv<Name>::T>
1698template <PrimType Name, class T = typename PrimConv<Name>::T>
1704 if constexpr (std::is_same_v<T, Floating>) {
1706 if (!Val.singleWord()) {
1707 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
1708 Val.take(NewMemory);
1711 }
else if constexpr (std::is_same_v<T, MemberPointer>) {
1715 for (
unsigned I = 0; I != PathLength; ++I) {
1716 NewPath[I] = Val.getPathEntry(I);
1718 Val.takePath(NewPath);
1720 auto &Val = P.
deref<T>();
1721 if (!Val.singleWord()) {
1722 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
1723 Val.take(NewMemory);
1734template <PrimType Name, class T = typename PrimConv<Name>::T>
1766template <PrimType Name, class T = typename PrimConv<Name>::T>
1773 if (!
This.isDereferencable())
1777 assert(Field.canBeInitialized());
1778 Field.deref<T>() = S.
Stk.
pop<T>();
1783template <PrimType Name, class T = typename PrimConv<Name>::T>
1790 if (!
This.isDereferencable())
1794 assert(Field.canBeInitialized());
1795 Field.deref<T>() = S.
Stk.
pop<T>();
1801template <PrimType Name, class T = typename PrimConv<Name>::T>
1803 uint32_t FieldBitWidth) {
1809 if (!
This.isDereferencable())
1813 assert(Field.canBeInitialized());
1817 if (!
Value.isNumber())
1821 Field.deref<T>() =
Value.truncate(FieldBitWidth);
1826template <PrimType Name, class T = typename PrimConv<Name>::T>
1828 uint32_t FieldOffset, uint32_t FieldBitWidth) {
1834 if (!
This.isDereferencable())
1838 assert(Field.canBeInitialized());
1842 if (!
Value.isNumber())
1846 Field.deref<T>() =
Value.truncate(FieldBitWidth);
1855template <PrimType Name, class T = typename PrimConv<Name>::T>
1859 if (!Ptr.isDereferencable())
1873template <PrimType Name, class T = typename PrimConv<Name>::T>
1877 if (!Ptr.isDereferencable())
1891template <PrimType Name, class T = typename PrimConv<Name>::T>
1893 uint32_t FieldBitWidth) {
1896 if (!Ptr.isDereferencable())
1900 if (!
Value.isNumber())
1910 unsigned BitWidth = std::min(FieldBitWidth,
Value.bitWidth());
1913 if constexpr (T::isSigned())
1915 Value.toAPSInt().trunc(BitWidth).sextOrTrunc(
Value.bitWidth()));
1918 Value.toAPSInt().trunc(BitWidth).zextOrTrunc(
Value.bitWidth()));
1920 Field.deref<T>() =
Result;
1922 Field.deref<T>() =
Value.truncate(FieldBitWidth);
1928template <PrimType Name, class T = typename PrimConv<Name>::T>
1930 uint32_t FieldBitWidth) {
1933 if (!Ptr.isDereferencable())
1937 if (!
Value.isNumber())
1947 unsigned BitWidth = std::min(FieldBitWidth,
Value.bitWidth());
1950 if constexpr (T::isSigned())
1952 Value.toAPSInt().trunc(BitWidth).sextOrTrunc(
Value.bitWidth()));
1955 Value.toAPSInt().trunc(BitWidth).zextOrTrunc(
Value.bitWidth()));
1957 Field.deref<T>() =
Result;
1959 Field.deref<T>() =
Value.truncate(FieldBitWidth);
1999bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off);
2002bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off);
2003bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
bool NullOK);
2005bool GetPtrDerivedPop(InterpState &S, CodePtr OpPC, uint32_t Off,
bool NullOK,
2006 const Type *TargetType);
2071 diag::note_constexpr_dereferencing_null);
2080 const Record::Base *VirtBase =
Base.getRecord()->getVirtualBase(
Decl);
2109template <PrimType Name, class T = typename PrimConv<Name>::T>
2122template <PrimType Name, class T = typename PrimConv<Name>::T>
2135template <PrimType Name, class T = typename PrimConv<Name>::T>
2141 if (Ptr.canBeInitialized())
2143 Ptr.deref<T>() =
Value;
2147template <PrimType Name, class T = typename PrimConv<Name>::T>
2153 if (Ptr.canBeInitialized())
2155 Ptr.deref<T>() =
Value;
2178template <PrimType Name, class T = typename PrimConv<Name>::T>
2185 if (Ptr.canBeInitialized()) {
2193template <PrimType Name, class T = typename PrimConv<Name>::T>
2200 if (Ptr.canBeInitialized()) {
2208template <PrimType Name, class T = typename PrimConv<Name>::T>
2215 if (Ptr.canBeInitialized())
2217 if (
const auto *FD = Ptr.getField())
2218 Ptr.deref<T>() =
Value.truncate(FD->getBitWidthValue());
2220 Ptr.deref<T>() =
Value;
2224template <PrimType Name, class T = typename PrimConv<Name>::T>
2230 if (Ptr.canBeInitialized())
2232 if (
const auto *FD = Ptr.getField())
2233 Ptr.deref<T>() =
Value.truncate(FD->getBitWidthValue());
2235 Ptr.deref<T>() =
Value;
2239template <PrimType Name, class T = typename PrimConv<Name>::T>
2246 if (Ptr.canBeInitialized()) {
2250 if (
const auto *FD = Ptr.getField())
2251 Ptr.
deref<T>() =
Value.truncate(FD->getBitWidthValue());
2253 Ptr.deref<T>() =
Value;
2257template <PrimType Name, class T = typename PrimConv<Name>::T>
2264 if (Ptr.canBeInitialized()) {
2268 if (
const auto *FD = Ptr.getField())
2269 Ptr.
deref<T>() =
Value.truncate(FD->getBitWidthValue());
2271 Ptr.deref<T>() =
Value;
2275template <PrimType Name, class T = typename PrimConv<Name>::T>
2282 new (&Ptr.deref<T>()) T(
Value);
2286template <PrimType Name, class T = typename PrimConv<Name>::T>
2293 new (&Ptr.deref<T>()) T(
Value);
2300template <PrimType Name, class T = typename PrimConv<Name>::T>
2305 if (Ptr.isConstexprUnknown())
2314 if (Idx == 0 && !Desc->
isArray()) {
2316 new (&Ptr.deref<T>()) T(
Value);
2326 S.
FFDiag(Loc, diag::note_constexpr_access_past_end)
2331 Ptr.initializeElement(Idx);
2332 new (&Ptr.elem<T>(Idx)) T(
Value);
2337template <PrimType Name, class T = typename PrimConv<Name>::T>
2342 if (Ptr.isConstexprUnknown())
2351 if (Idx == 0 && !Desc->
isArray()) {
2353 new (&Ptr.deref<T>()) T(
Value);
2363 S.
FFDiag(Loc, diag::note_constexpr_access_past_end)
2368 Ptr.initializeElement(Idx);
2369 new (&Ptr.elem<T>(Idx)) T(
Value);
2382 return DoMemcpy(S, OpPC, Src, Dest);
2396 if (std::optional<Pointer> Ptr = MP.toPointer(S.
Ctx)) {
2407template <
class T, ArithOp Op>
2409 const T &Offset,
const Pointer &Ptr,
2410 bool IsPointerArith =
false) {
2412 if (Offset.isZero())
2419 return std::nullopt;
2424 return std::nullopt;
2429 uint64_t O =
static_cast<uint64_t
>(Offset) * Ptr.
elemSize();
2435 uint64_t O =
static_cast<uint64_t
>(Offset);
2447 return std::nullopt;
2452 uint64_t MaxIndex =
static_cast<uint64_t
>(Ptr.
getNumElems());
2461 auto DiagInvalidOffset = [&]() ->
void {
2462 const unsigned Bits = Offset.bitWidth();
2463 APSInt APOffset(Offset.toAPSInt().extend(
Bits + 2),
false);
2467 (Op ==
ArithOp::Add) ? (APIndex + APOffset) : (APIndex - APOffset);
2469 << NewIndex <<
static_cast<int>(!Ptr.
inArray()) << MaxIndex;
2474 uint64_t IOffset =
static_cast<uint64_t
>(Offset);
2475 uint64_t MaxOffset = MaxIndex - Index;
2479 if (Offset.isNegative() && (Offset.isMin() || -IOffset > Index))
2480 DiagInvalidOffset();
2483 if (Offset.isPositive() && IOffset > MaxOffset)
2484 DiagInvalidOffset();
2487 if (Offset.isPositive() && Index < IOffset)
2488 DiagInvalidOffset();
2491 if (Offset.isNegative() && (Offset.isMin() || -IOffset > MaxOffset))
2492 DiagInvalidOffset();
2497 return std::nullopt;
2500 int64_t WideIndex =
static_cast<int64_t
>(Index);
2501 int64_t WideOffset =
static_cast<int64_t
>(Offset);
2504 Result = WideIndex + WideOffset;
2506 Result = WideIndex - WideOffset;
2520template <PrimType Name, class T = typename PrimConv<Name>::T>
2522 const T &Offset = S.
Stk.
pop<T>();
2526 S, OpPC, Offset, Ptr,
true)) {
2533template <PrimType Name, class T = typename PrimConv<Name>::T>
2535 const T &Offset = S.
Stk.
pop<T>();
2539 S, OpPC, Offset, Ptr,
true)) {
2546template <ArithOp Op>
2562 OneT One = OneT::from(1);
2563 if (std::optional<Pointer>
Result =
2593template <PrimType Name, class T = typename PrimConv<Name>::T>
2602 if (!LHSAddrExpr || !RHSAddrExpr) {
2604 diag::note_constexpr_pointer_arith_unspecified)
2614 S.
Stk.
push<T>(LHSAddrExpr, RHSAddrExpr);
2623 diag::note_constexpr_pointer_arith_unspecified)
2629 if (ElemSizeIsZero) {
2631 while (
auto *AT = dyn_cast<ArrayType>(PtrT))
2632 PtrT = AT->getElementType();
2637 diag::note_constexpr_pointer_subtraction_zero_size)
2658 int64_t R64 = A64 - B64;
2659 if (
static_cast<int64_t
>(T::from(R64)) != R64)
2691 auto In = S.
Stk.
pop<T>();
2705 if (!(U::bitWidth() >= 32 && U::bitWidth() <= In.bitWidth()))
2717 llvm::RoundingMode RM) {
2727 FixedPointSemantics::getFromOpaqueInt(FPS);
2742template <PrimType Name, class T = typename PrimConv<Name>::T>
2744 T Source = S.
Stk.
pop<T>();
2747 if (!Source.isNumber())
2754 APInt SourceInt = Source.toAPSInt().extOrTrunc(BitWidth);
2761template <PrimType Name, class T = typename PrimConv<Name>::T>
2763 T Source = S.
Stk.
pop<T>();
2766 if (!Source.isNumber())
2773 APInt SourceInt = Source.toAPSInt().extOrTrunc(BitWidth);
2780template <PrimType Name, class T = typename PrimConv<Name>::T>
2782 const llvm::fltSemantics *Sem, uint32_t FPOI) {
2783 const T &From = S.
Stk.
pop<T>();
2786 if (!From.isNumber())
2790 APSInt FromAP = From.toAPSInt();
2801template <PrimType Name, class T = typename PrimConv<Name>::T>
2805 if constexpr (std::is_same_v<T, Boolean>) {
2814 if ((Status & APFloat::opStatus::opInvalidOp)) {
2833 uint32_t BitWidth, uint32_t FPOI) {
2840 if ((Status & APFloat::opStatus::opInvalidOp) && F.
isFinite() &&
2855 uint32_t BitWidth, uint32_t FPOI) {
2862 if ((Status & APFloat::opStatus::opInvalidOp) && F.
isFinite() &&
2877 const Pointer &Ptr,
unsigned BitWidth);
2882template <PrimType Name, class T = typename PrimConv<Name>::T>
2888 if constexpr (std::is_same_v<T, Boolean>) {
2903 PtrVal = Ptr.
block();
2906 S.
Stk.
push<T>(Kind, PtrVal, 0);
2919template <PrimType Name, class T = typename PrimConv<Name>::T>
2953 const llvm::fltSemantics *Sem) {
2956 Result.copy(Fixed.toFloat(Sem));
2961template <PrimType Name, class T = typename PrimConv<Name>::T>
2966 APSInt Int = Fixed.toInt(T::bitWidth(), T::isSigned(), &Overflow);
2977 S.
CCEDiag(E, diag::note_constexpr_invalid_cast)
2978 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
2987 bool HasValidResult = !Ptr.isZero();
2989 if (HasValidResult) {
2996 E->getType()->getPointeeType()))
2999 S.
CCEDiag(E, diag::note_constexpr_invalid_void_star_cast)
3000 << E->getSubExpr()->getType() << S.
getLangOpts().CPlusPlus26
3001 << Ptr.getType().getCanonicalType() << E->getType()->getPointeeType();
3004 S.
CCEDiag(E, diag::note_constexpr_invalid_cast)
3005 << diag::ConstexprInvalidCastKind::CastFrom <<
"'void *'"
3010 S.
CCEDiag(E, diag::note_constexpr_invalid_cast)
3011 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
3022template <PrimType Name, class T = typename PrimConv<Name>::T>
3030 if (!
Result.singleWord())
3031 std::memset(
Result.Memory, 0,
Result.numWords() *
sizeof(uint64_t));
3038 if (!
Result.singleWord())
3039 std::memset(
Result.Memory, 0,
Result.numWords() *
sizeof(uint64_t));
3044template <PrimType Name, class T = typename PrimConv<Name>::T>
3053template <PrimType Name, class T = typename PrimConv<Name>::T>
3055 const auto &P = S.
Stk.
pop<T>();
3075 if (!
This.isDummy()) {
3077 if (!
This.isTypeidPointer()) {
3078 [[maybe_unused]]
const Record *R =
This.getRecord();
3080 R =
This.narrow().getRecord();
3083 assert(R->getDecl() ==
3105template <
class LT,
class RT, ShiftDir Dir>
3109 const unsigned Bits = LHS.bitWidth();
3113 RT::bitAnd(RHS, RT::from(LHS.bitWidth() - 1, RHS.bitWidth()),
3114 RHS.bitWidth(), &RHS);
3116 if (RHS.isNegative()) {
3120 S.
CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
3124 RHS = RHS.isMin() ? RT(APSInt::getMaxValue(RHS.bitWidth(),
false)) : -RHS;
3128 S, OpPC, LHS, RHS,
Result);
3140 typename LT::AsUnsigned R;
3141 unsigned MaxShiftAmount = LHS.bitWidth() - 1;
3143 if (
Compare(RHS, RT::from(MaxShiftAmount, RHS.bitWidth())) ==
3145 if (LHS.isNegative())
3146 R = LT::AsUnsigned::zero(LHS.bitWidth());
3148 RHS = RT::from(LHS.countLeadingZeros(), RHS.bitWidth());
3149 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
3150 LT::AsUnsigned::from(RHS,
Bits),
Bits, &R);
3152 }
else if (LHS.isNegative()) {
3154 R = LT::AsUnsigned::zero(LHS.bitWidth());
3157 typename LT::AsUnsigned LHSU = LT::AsUnsigned::from(-LHS);
3158 LT::AsUnsigned::shiftLeft(LHSU, LT::AsUnsigned::from(RHS,
Bits),
Bits,
3164 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
3165 LT::AsUnsigned::from(RHS,
Bits),
Bits, &R);
3172 if (
Compare(RHS, RT::from(MaxShiftAmount, RHS.bitWidth())) ==
3174 R = LT::AsUnsigned::from(-1);
3178 LT::shiftRight(LHS, LT::from(RHS,
Bits),
Bits, &A);
3179 R = LT::AsUnsigned::from(A);
3187template <
class LT,
class RT, ShiftDir Dir>
3190 const unsigned Bits = LHS.getBitWidth();
3195 APSInt(llvm::APInt(RHS.getBitWidth(),
static_cast<uint64_t
>(
Bits - 1)),
3198 if (RHS.isNegative()) {
3202 S.
CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS;
3207 S, OpPC, LHS, -RHS,
Result);
3231template <PrimType NameL, PrimType NameR>
3235 auto RHS = S.
Stk.
pop<RT>();
3243 RHS.toAPSInt(), &
Result);
3250template <PrimType NameL, PrimType NameR>
3254 auto RHS = S.
Stk.
pop<RT>();
3262 RHS.toAPSInt(), &
Result);
3272 llvm::FixedPointSemantics LHSSema = LHS.
getSemantics();
3274 unsigned ShiftBitWidth =
3275 LHSSema.getWidth() - (
unsigned)LHSSema.hasUnsignedPadding() - 1;
3280 if (RHS.isNegative()) {
3283 }
else if (
static_cast<unsigned>(RHS.toAPSInt().getLimitedValue(
3284 ShiftBitWidth)) != RHS.toAPSInt()) {
3286 S.
CCEDiag(E, diag::note_constexpr_large_shift)
3287 << RHS.toAPSInt() << E->
getType() << ShiftBitWidth;
3310 S.
FFDiag(EndLoc, diag::note_constexpr_no_return);
3341template <PrimType Name, class T = typename PrimConv<Name>::T>
3343 const T &Offset = S.
Stk.
pop<T>();
3346 if (!Ptr.isZero() && !Offset.isZero()) {
3351 if (Offset.isZero()) {
3352 if (
const Descriptor *Desc = Ptr.getFieldDesc();
3353 Desc && Desc->
isArray() && Ptr.getIndex() == 0) {
3361 assert(!Offset.isZero());
3363 if (std::optional<Pointer>
Result =
3372template <PrimType Name, class T = typename PrimConv<Name>::T>
3374 const T &Offset = S.
Stk.
pop<T>();
3377 if (!Ptr.isZero() && !Offset.isZero()) {
3382 if (Offset.isZero()) {
3383 if (
const Descriptor *Desc = Ptr.getFieldDesc();
3384 Desc && Desc->
isArray() && Ptr.getIndex() == 0) {
3392 assert(!Offset.isZero());
3394 if (std::optional<Pointer>
Result =
3402template <PrimType Name, class T = typename PrimConv<Name>::T>
3414template <PrimType Name, class T = typename PrimConv<Name>::T>
3426template <PrimType Name, class T = typename PrimConv<Name>::T>
3428 uint32_t DestIndex, uint32_t Size) {
3432 if (SrcPtr.isDummy() || DestPtr.
isDummy())
3438 const Descriptor *SrcDesc = SrcPtr.getFieldDesc();
3444 for (uint32_t I = 0; I != Size; ++I) {
3450 DestPtr.
elem<T>(DestIndex + I) = SrcPtr.elem<T>(SrcIndex + I);
3477 S.
FFDiag(E, diag::note_constexpr_unsupported_unsized_array);
3488template <PrimType Name, class T = typename PrimConv<Name>::T>
3490 const T &IntVal = S.
Stk.
pop<T>();
3493 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
3498 if (IntVal.getOffset() != 0)
3504 if (IntVal.getOffset() != 0)
3507 const Block *B = (
const Block *)IntVal.getPtr();
3534 S.
FFDiag(Loc, diag::note_constexpr_stmt_expr_unsupported)
3621 diag::note_constexpr_access_volatile_type)
3633 S.
CCEDiag(E, diag::note_constexpr_non_const_vectorelements) << ArgRange;
3641 diag::note_constexpr_pseudo_destructor);
3653 S.
CCEDiag(Loc, diag::note_constexpr_assumption_failed);
3657template <PrimType Name, class T = typename PrimConv<Name>::T>
3661 ArrayIndices.emplace_back(
3673template <PrimType Name, class T = typename PrimConv<Name>::T>
3675 const T &Arg = S.
Stk.
peek<T>();
3680 S.
CCEDiag(Loc, diag::note_non_null_attribute_failed);
3686 const APSInt &
Value);
3688template <PrimType Name, class T = typename PrimConv<Name>::T>
3701template <PrimType TIn, PrimType TOut>
3707 const FromT &OldPtr = S.
Stk.
pop<FromT>();
3709 if constexpr (std::is_same_v<FromT, FunctionPointer> &&
3710 std::is_same_v<ToT, Pointer>) {
3713 }
else if constexpr (std::is_same_v<FromT, Pointer> &&
3714 std::is_same_v<ToT, FunctionPointer>) {
3715 if (OldPtr.isFunctionPointer()) {
3717 OldPtr.getByteOffset());
3722 S.
Stk.
push<ToT>(ToT(OldPtr.getIntegerRepresentation(),
nullptr));
3759template <PrimType Name, class SizeT = typename PrimConv<Name>::T>
3774 if (NumElements.isNegative()) {
3784 if (!
CheckArraySize(S, OpPC,
static_cast<uint64_t
>(NumElements)))
3788 Block *B = Allocator.
allocate(Source, T,
static_cast<size_t>(NumElements),
3791 if (NumElements.isZero())
3798template <PrimType Name, class SizeT = typename PrimConv<Name>::T>
3817 assert(NumElements.isPositive());
3819 if (!
CheckArraySize(S, OpPC,
static_cast<uint64_t
>(NumElements)))
3823 Block *B = Allocator.
allocate(ElementDesc,
static_cast<size_t>(NumElements),
3826 if (NumElements.isZero())
3834bool Free(InterpState &S, CodePtr OpPC,
bool DeleteIsArrayForm,
3835 bool IsGlobalDelete);
3849 std::optional<uint64_t> ArraySize = std::nullopt);
3851template <PrimType Name, class T = typename PrimConv<Name>::T>
3853 const auto &Size = S.
Stk.
pop<T>();
3858template <PrimType Name, class T = typename PrimConv<Name>::T>
3860 uint32_t ResultBitWidth,
const llvm::fltSemantics *Sem,
3861 const Type *TargetType) {
3867 if constexpr (std::is_same_v<T, Pointer>) {
3870 diag::note_constexpr_bit_cast_invalid_type)
3871 <<
true <<
false << 1 ;
3877 }
else if constexpr (std::is_same_v<T, MemberPointer>) {
3879 diag::note_constexpr_bit_cast_invalid_type)
3880 <<
true <<
false << 2 ;
3884 size_t BuffSize = ResultBitWidth / 8;
3886 bool HasIndeterminateBits =
false;
3888 Bits FullBitWidth(ResultBitWidth);
3889 Bits BitWidth = FullBitWidth;
3891 if constexpr (std::is_same_v<T, Floating>) {
3893 BitWidth =
Bits(llvm::APFloatBase::getSizeInBits(*Sem));
3896 if (!
DoBitCast(S, OpPC, FromPtr, Buff.data(), BitWidth, FullBitWidth,
3897 HasIndeterminateBits))
3900 if (!
CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
3903 if constexpr (std::is_same_v<T, Floating>) {
3910 T::bitcastFromMemory(Buff.data(), ResultBitWidth, &
Result);
3912 }
else if constexpr (std::is_same_v<T, Boolean>) {
3916 auto Val =
static_cast<unsigned int>(Buff[0]);
3919 diag::note_constexpr_bit_cast_unrepresentable_value)
3923 S.
Stk.
push<T>(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
3926 S.
Stk.
push<T>(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
3937 if (D->isPrimitiveArray() && FromPtr.
isArrayRoot())
3950bool GetTypeid(InterpState &S, CodePtr OpPC,
const Type *TypePtr,
3951 const Type *TypeInfoType);
3953bool DiagTypeid(InterpState &S, CodePtr OpPC);
3965 if constexpr (std::is_pointer<T>::value) {
3966 uint32_t ID = OpPC.
read<uint32_t>();
3969 return OpPC.
read<T>();
3979 OpPC +=
align(F.bytesToSerialize());
3988 assert(
Result.bitWidth() == BitWidth);
4000 assert(
Result.bitWidth() == BitWidth);
Defines the clang::ASTContext interface.
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)
Result
Implement __builtin_bit_cast and related operations.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
bool hasSimilarType(QualType T1, QualType T2) const
Determine if two types are similar, according to the C++ rules.
AddrLabelExpr - The GNU address of label extension, representing &&label.
LabelDecl * getLabel() const
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]).
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
ComparisonCategoryResult makeWeakResult(ComparisonCategoryResult Res) const
Converts the specified result kind into the correct result kind for this category.
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getLocation() const
DeclContext * getDeclContext()
AccessSpecifier getAccess() 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...
static FPOptions getFromOpaqueInt(storage_type Value)
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Represents a function declaration or definition.
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
unsigned getNumExpressions() const
A (possibly-)qualified type.
QualType withVolatile() const
bool isWrapType() const
Returns true if it is a OverflowBehaviorType of Wrap kind.
Represents a struct/union/class.
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.
bool isNullPtrType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
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.
bool isExtern() const
Checks if the block is extern.
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.
Block * allocate(const Descriptor *D, unsigned EvalID, Form AllocForm)
Allocate ONE element of the given descriptor.
Wrapper around fixed point types.
llvm::FixedPointSemantics getSemantics() const
static bool shiftRight(const FixedPoint A, const FixedPoint B, unsigned OpBits, FixedPoint *R)
static FixedPoint deserialize(const std::byte *Buff)
static bool shiftLeft(const FixedPoint A, const FixedPoint B, unsigned OpBits, FixedPoint *R)
static FixedPoint from(const APSInt &I, llvm::FixedPointSemantics Sem, bool *Overflow)
size_t bytesToSerialize() const
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
static APFloat::opStatus div(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
static llvm::APFloatBase::Semantics deserializeSemantics(const std::byte *Buff)
void copy(const APFloat &F)
static APFloat::opStatus fromIntegral(APSInt Val, const llvm::fltSemantics &Sem, llvm::RoundingMode RM, Floating *Result)
static APFloat::opStatus sub(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
static APFloat::opStatus increment(const Floating &A, llvm::RoundingMode RM, Floating *R)
static APFloat::opStatus add(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
static void deserialize(const std::byte *Buff, Floating *Result)
static APFloat::opStatus mul(const Floating &A, const Floating &B, llvm::RoundingMode RM, Floating *R)
void toSemantics(const llvm::fltSemantics *Sem, llvm::RoundingMode RM, Floating *Result) const
const llvm::fltSemantics & getSemantics() const
static APFloat::opStatus decrement(const Floating &A, llvm::RoundingMode RM, Floating *R)
APFloat::opStatus convertToInteger(APSInt &Result) const
static void bitcastFromMemory(const std::byte *Buff, const llvm::fltSemantics &Sem, Floating *Result)
APFloat getAPFloat() const
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
bool hasRVO() const
Checks if the first argument is a RVO pointer.
If an IntegralAP is constructed from Memory, it DOES NOT OWN THAT MEMORY.
static uint32_t deserializeSize(const std::byte *Buff)
static void deserialize(const std::byte *Buff, IntegralAP< Signed > *Result)
void copy(const APInt &V)
Wrapper around numeric types.
static std::enable_if_t<!std::is_same_v< ValT, IntegralKind >, Integral > from(ValT V, unsigned NumBits=0)
Frame storing local variables.
static void free(InterpFrame *F)
const Expr * getExpr(CodePtr PC) const
bool isLocalEnabled(unsigned Idx) const
void setParam(unsigned Index, const T &Value)
Mutates a local copy of a parameter.
InterpFrame * Caller
The frame of the previous function.
SourceInfo getSource(CodePtr PC) const
Map a location to a source.
CodePtr getRetPC() const
Returns the return address of the frame.
void enableLocal(unsigned Idx)
Block * getLocalBlock(unsigned Offset) const
SourceLocation getLocation(CodePtr PC) const
const Pointer & getThis() const
Returns the 'this' pointer.
unsigned MSVCConstexprAllowed
const Function * getFunction() const
Returns the current function.
size_t getFrameOffset() const
Returns the offset on the stack at which the frame starts.
SourceRange getRange(CodePtr PC) const
void setLocal(unsigned Offset, const T &Value)
Mutates a local variable.
bool isBottomFrame() const
bool hasThisPointer() const
Pointer getLocalPointer(unsigned Offset) const
Returns a pointer to a local variables.
unsigned getDepth() const
const T & getParam(unsigned Index) const
Returns the value of an argument.
const Pointer & getRVOPtr() const
Returns the RVO pointer, if the Function has one.
Pointer getParamPointer(unsigned Offset)
Returns a pointer to an argument - lazily creates a block.
const FunctionDecl * getCallee() const override
Returns the caller.
void initScope(unsigned Idx)
T pop()
Returns the value from the top of the stack and removes it.
void push(Tys &&...Args)
Constructs a value in place on the top of the stack.
void dump() const
dump the stack contents to stderr.
size_t size() const
Returns the size of the stack in bytes.
void discard()
Discards the top value from the stack.
T & peek() const
Returns a reference to the value on the top of the stack.
SmallVectorImpl< PartialDiagnosticAt > * PrevDiags
Things needed to do speculative execution.
DynamicAllocator & getAllocator()
Context & Ctx
Interpreter Context.
Floating allocFloat(const llvm::fltSemantics &Sem)
const unsigned EvalID
ID identifying this evaluation.
llvm::SmallVector< std::pair< const Expr *, const LifetimeExtendedTemporaryDecl * > > SeenGlobalTemporaries
InterpStack & Stk
Temporary stack.
bool maybeDiagnoseDanglingAllocations()
Diagnose any dynamic allocations that haven't been freed yet.
const VarDecl * EvaluatingDecl
Declaration we're initializing/evaluting, if any.
InterpFrame * Current
The current frame.
std::optional< bool > ConstantContextOverride
T allocAP(unsigned BitWidth)
unsigned SpeculationDepth
StdAllocatorCaller getStdAllocatorCaller(StringRef Name) const
bool inConstantContext() const
Program & P
Reference to the module containing all bytecode.
unsigned getPathLength() const
Return the length of the cast path.
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.
Pointer stripBaseCasts() const
Strip base casts from this Pointer.
bool isInitialized() const
Checks if an object was initialized.
bool pointsToLabel() const
Whether this points to a block created for an AddrLabelExpr.
bool isZeroSizeArray() const
Checks if the pointer is pointing to a zero-size array.
Pointer atIndex(uint64_t Idx) const
Offsets a pointer inside an array.
bool isDummy() const
Checks if the pointer points to a dummy value.
const AddrLabelExpr * getPointedToLabel() const
Returns the AddrLabelExpr the Pointer points to, if any.
int64_t getIndex() const
Returns the index into an array.
bool canDeref(PrimType T) const
Checks whether the pointer can be dereferenced to the given PrimType.
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.
static std::optional< std::pair< Pointer, Pointer > > computeSplitPoint(const Pointer &A, const Pointer &B)
bool isIntegralPointer() const
QualType getType() const
Returns the type of the innermost field.
bool pointsToStringLiteral() const
bool isArrayRoot() const
Whether this array refers to an array, but not to the first element.
size_t computeOffsetForComparison(const ASTContext &ASTCtx) const
Compute an integer that can be used to compare this pointer to another one.
bool inArray() const
Checks if the innermost field is an array.
T & elem(unsigned I) const
Dereferences the element at index I.
uint64_t getByteOffset() const
Returns the byte offset from the start.
bool isTypeidPointer() const
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.
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 FunctionPointer & asFunctionPointer() const
const Block * block() const
bool isFunctionPointer() const
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
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.
void initializeElement(unsigned Index) const
Initialized the given element of a primitive array.
const Record * getRecord() const
Returns the record descriptor of a class.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
Pointer getPtrGlobal(unsigned Idx) const
Returns a pointer to a global.
const void * getNativePointer(unsigned Idx) const
Returns the value of a marshalled native pointer.
Structure/Class descriptor.
bool isAnonymousUnion() const
Checks if the record is an anonymous union.
Describes the statement/declaration an opcode was generated from.
bool checkingForUndefinedBehavior() const
Are we checking an expression for overflow?
Expr::EvalStatus & getEvalStatus() const
DiagnosticBuilder report(SourceLocation Loc, diag::kind DiagId)
Directly reports a diagnostic message.
OptionalDiagnostic FFDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation could not be folded (FF => FoldFailure)
bool noteSideEffect() const
Note that we have had a side-effect, and determine whether we should keep evaluating.
ASTContext & getASTContext() const
bool noteUndefinedBehavior() const
Note that we hit something that was technically undefined behavior, but that we can evaluate past it ...
OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation does not produce a C++11 core constant expression.
const LangOptions & getLangOpts() const
bool checkingPotentialConstantExpression() const
Are we checking whether the expression is a potential constant expression?
bool arePotentiallyOverlappingStringLiterals(const Pointer &LHS, const Pointer &RHS)
static bool ShiftFixedPoint(InterpState &S, CodePtr OpPC, bool Left)
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 CheckDestruction(InterpState &S, CodePtr OpPC)
bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index)
bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool PopCC(InterpState &S, CodePtr OpPC)
bool ArrayElem(InterpState &S, CodePtr OpPC, uint32_t Index)
bool GT(InterpState &S, CodePtr OpPC)
bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be initialized.
static bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth, uint32_t FPOI)
bool GetMemberPtrBase(InterpState &S, CodePtr OpPC)
bool GetThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool PreInc(InterpState &S, CodePtr OpPC, bool CanOverflow)
bool NarrowPtr(InterpState &S, CodePtr OpPC)
bool CheckFunctionDecl(InterpState &S, CodePtr OpPC, const FunctionDecl *FD)
Opcode. Check if the function decl can be called at compile time.
bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool BitCastPrim(InterpState &S, CodePtr OpPC, bool TargetIsUCharOrByte, uint32_t ResultBitWidth, const llvm::fltSemantics *Sem, const Type *TargetType)
Floating ReadArg< Floating >(InterpState &S, CodePtr &OpPC)
bool Incf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool SideEffect(InterpState &S, CodePtr OpPC)
static bool ZeroIntAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS, LT *Result)
bool EndLifetimePop(InterpState &S, CodePtr OpPC)
Ends the lifetime of the pop'd pointer.
bool Sub(InterpState &S, CodePtr OpPC)
bool GetTypeidPtr(InterpState &S, CodePtr OpPC, const Type *TypeInfoType)
bool Mulf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
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 LT(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 BitCast(InterpState &S, CodePtr OpPC)
bool LoadPop(InterpState &S, CodePtr OpPC)
bool Null(InterpState &S, CodePtr OpPC, uint64_t Value, const Descriptor *Desc)
bool CheckGlobalLoad(InterpState &S, CodePtr OpPC, const Block *B)
Checks a direct load of a primitive value from a global or local variable.
PRESERVE_NONE bool NoRet(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
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 EndLifetime(InterpState &S, CodePtr OpPC)
Ends the lifetime of the peek'd pointer.
bool GetTypeid(InterpState &S, CodePtr OpPC, const Type *TypePtr, const Type *TypeInfoType)
Typeid support.
bool InitBitFieldActivate(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
bool Dup(InterpState &S, CodePtr OpPC)
bool SetField(InterpState &S, CodePtr OpPC, uint32_t I)
bool CheckNonNullArg(InterpState &S, CodePtr OpPC)
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}...
bool InitBitField(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
static bool IncDecPtrHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool FinishInitActivate(InterpState &S, CodePtr OpPC)
bool GetPtrLocal(InterpState &S, CodePtr OpPC, uint32_t I)
bool Addf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
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.
static bool IsOpaqueConstantCall(const CallExpr *E)
bool CheckDecl(InterpState &S, CodePtr OpPC, const VarDecl *VD)
bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, unsigned BitWidth)
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 StoreActivate(InterpState &S, CodePtr OpPC)
bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK, bool WillActivate)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
bool StartThisLifetime1(InterpState &S, CodePtr OpPC)
PRESERVE_NONE bool EndSpeculation(InterpState &S, CodePtr &OpPC)
bool GetFnPtr(InterpState &S, CodePtr OpPC, const Function *Func)
bool InitThisBitFieldActivate(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
bool FinishInitActivatePop(InterpState &S, CodePtr OpPC)
bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I)
Same as GetGlobal, but without the checks.
bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if Ptr is a one-past-the-end pointer.
bool GetPtrGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
static bool Activate(InterpState &S, CodePtr OpPC)
bool handleFixedPointOverflow(InterpState &S, CodePtr OpPC, const FixedPoint &FP)
PRESERVE_NONE bool RetVoid(InterpState &S, CodePtr &PC)
bool Mulc(InterpState &S, CodePtr OpPC)
constexpr bool isIntegralOrPointer()
bool ArrayElemPtr(InterpState &S, CodePtr OpPC)
bool NE(InterpState &S, CodePtr OpPC)
bool handleReference(InterpState &S, CodePtr OpPC, Block *B)
bool CheckBitCast(InterpState &S, CodePtr OpPC, const Type *TargetType, bool SrcIsVoidPtr)
bool GetIntPtr(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
llvm::FixedPointSemantics FixedPointSemantics
bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a value can be loaded from a block.
static bool FnPtrCast(InterpState &S, CodePtr OpPC)
static bool ZeroIntAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool Shl(InterpState &S, CodePtr OpPC)
bool RVOPtr(InterpState &S, CodePtr OpPC)
bool CastPointerIntegral(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
bool DecfPop(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E, ArrayRef< int64_t > ArrayIndices, int64_t &IntResult)
Interpret an offsetof operation.
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 CheckBCPResult(InterpState &S, const Pointer &Ptr)
bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is in range.
bool CastAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool ExpandPtr(InterpState &S, CodePtr OpPC)
bool Store(InterpState &S, CodePtr OpPC)
bool Divc(InterpState &S, CodePtr OpPC)
bool DoBitCastPtr(InterpState &S, CodePtr OpPC, const Pointer &FromPtr, Pointer &ToPtr)
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 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 GetPtrParam(InterpState &S, CodePtr OpPC, uint32_t Index)
bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn)
T ReadArg(InterpState &S, CodePtr &OpPC)
bool PreDecBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is live and accessible.
bool CastFloatingIntegral(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool ArrayDecay(InterpState &S, CodePtr OpPC)
Just takes a pointer and checks if it's an incomplete array type.
bool PushCC(InterpState &S, CodePtr OpPC, bool Value)
bool GetPtrDerivedPop(InterpState &S, CodePtr OpPC, uint32_t Off, bool NullOK, const Type *TargetType)
bool DiagTypeid(InterpState &S, CodePtr OpPC)
bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
This is not used by any of the opcodes directly.
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 CopyMemberPtrPath(InterpState &S, CodePtr OpPC, const RecordDecl *Entry, bool IsDerived)
Just append the given Entry to the MemberPointer's path.
bool CheckRefInit(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.
bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS, unsigned Bits)
Checks if the shift operation is legal.
static bool handleOverflow(InterpState &S, CodePtr OpPC, const T &SrcValue)
bool PushIgnoreDiags(InterpState &S, CodePtr OpPC)
FixedPoint ReadArg< FixedPoint >(InterpState &S, CodePtr &OpPC)
static bool CastFloatingFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS)
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED, const APSInt &Value)
bool CastMemberPtrDerivedPop(InterpState &S, CodePtr OpPC, int32_t Off, const RecordDecl *BaseDecl)
BaseToDerivedMemberPointer.
@ BlockAddress
A pointer to an interp::Block.
@ AddrLabelDiff
Difference between two AddrLabelExpr.
@ Number
Just a number, nothing else.
@ Address
A pointer to a ValueDecl.
@ LabelAddress
A pointer to a AddrLabelExpr.
@ FunctionAddress
A pointer to a FunctionDecl.
bool PopIgnoreDiags(InterpState &S, CodePtr OpPC)
bool LE(InterpState &S, CodePtr OpPC)
bool isConstexprUnknown(const Block *B)
bool CheckNewTypeMismatchArray(InterpState &S, CodePtr OpPC, const Expr *E)
bool Unsupported(InterpState &S, CodePtr OpPC)
Just emit a diagnostic.
bool InvalidDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR, bool InitializerFailed)
bool DecPop(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value decreased by ...
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 CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result, APFloat::opStatus Status, FPOptions FPO)
Checks if the result of a floating-point operation is valid in the current context.
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 PushMSVCCE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
bool DecPopBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
bool SetThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool StoreBitFieldPop(InterpState &S, CodePtr OpPC)
bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CanOverflow, UnsignedOrNone BitWidth=std::nullopt)
bool GetParam(InterpState &S, CodePtr OpPC, uint32_t Index)
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
static bool DecPtr(InterpState &S, CodePtr OpPC)
constexpr bool needsAlloc()
static bool CheckAllocations(InterpState &S, CodePtr OpPC)
bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index)
bool ToMemberPtr(InterpState &S, CodePtr OpPC)
static bool CastIntegralFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS)
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 CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E, std::optional< uint64_t > ArraySize)
Check if the initializer and storage types of a placement-new expression match.
bool GetMemberPtr(InterpState &S, CodePtr OpPC, const ValueDecl *D)
bool InitThisBitField(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
bool Dump(InterpState &S, CodePtr OpPC)
bool SizelessVectorElementSize(InterpState &S, CodePtr OpPC)
static bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr)
bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T)
bool StartThisLifetime(InterpState &S, CodePtr OpPC)
bool IsNonNull(InterpState &S, CodePtr OpPC)
bool GetPtrThisField(InterpState &S, CodePtr OpPC, uint32_t Off)
bool CtorCheck(InterpState &S, CodePtr OpPC)
Abort without a diagnostic if we're checking for a potential constant expression and this is not the ...
bool ConstFloat(InterpState &S, CodePtr OpPC, const Floating &F)
bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the array is offsetable.
bool InitThisFieldActivate(InterpState &S, CodePtr OpPC, uint32_t I)
bool IncBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, unsigned BitWidth)
bool SubPtr(InterpState &S, CodePtr OpPC, bool ElemSizeIsZero)
1) Pops a Pointer from the stack.
bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off)
bool SetParam(InterpState &S, CodePtr OpPC, uint32_t I)
bool StoreActivatePop(InterpState &S, CodePtr OpPC)
bool GetMemberPtrDecl(InterpState &S, CodePtr OpPC)
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
static bool CastFixedPointFloating(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem)
bool Divf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool GetRefLocal(InterpState &S, CodePtr OpPC, uint32_t I)
bool CheckThis(InterpState &S, CodePtr OpPC)
Checks the 'this' pointer.
bool FinishInitGlobal(InterpState &S, CodePtr OpPC)
bool DecayPtr(InterpState &S, CodePtr OpPC)
OldPtr -> Integer -> NewPtr.
static bool ActivateThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool GetPtrVirtBasePop(InterpState &S, CodePtr OpPC, const RecordDecl *D)
bool StorePop(InterpState &S, CodePtr OpPC)
void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC, const Function *Func)
bool CheckIntegralAddressCast(InterpState &S, CodePtr OpPC, unsigned BitWidth)
bool SetLocal(InterpState &S, CodePtr OpPC, uint32_t I)
1) Pops the value from the stack.
bool FinishInit(InterpState &S, CodePtr OpPC)
bool InvalidStore(InterpState &S, CodePtr OpPC, const Type *T)
static bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth, uint32_t FPOI)
bool CastMemberPtrBasePop(InterpState &S, CodePtr OpPC, int32_t Off, const RecordDecl *BaseDecl)
DerivedToBaseMemberPointer.
bool Mul(InterpState &S, CodePtr OpPC)
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)
bool DecBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool PreIncBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
bool Dec(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value decreased by ...
bool StoreBitFieldActivate(InterpState &S, CodePtr OpPC)
bool CheckPseudoDtor(InterpState &S, CodePtr OpPC)
bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm, bool IsGlobalDelete)
bool PreDec(InterpState &S, CodePtr OpPC, bool CanOverflow)
bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E)
bool CheckArraySize(InterpState &S, CodePtr OpPC, uint64_t NumElems)
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE, uint32_t BuiltinID)
bool CheckLocalLoad(InterpState &S, CodePtr OpPC, const Block *B)
bool FinishInitPop(InterpState &S, CodePtr OpPC)
bool Neg(InterpState &S, CodePtr OpPC)
bool StartSpeculation(InterpState &S, CodePtr OpPC)
bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the variable has externally defined storage.
std::optional< Pointer > OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, const Pointer &Ptr, bool IsPointerArith=false)
bool BitOr(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
llvm::function_ref< bool(ComparisonCategoryResult)> CompareFn
bool Inv(InterpState &S, CodePtr OpPC)
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool WillBeActivated)
Checks if a value can be stored in a block.
bool Load(InterpState &S, CodePtr OpPC)
bool SetGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool Cast(InterpState &S, CodePtr OpPC)
bool StoreBitFieldActivatePop(InterpState &S, CodePtr OpPC)
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool EQ(InterpState &S, CodePtr OpPC)
bool IncfPop(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off, bool NullOK)
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 Add(InterpState &S, CodePtr OpPC)
bool CmpHelperEQ< MemberPointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
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 DiagnoseUninitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
bool IncPop(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
constexpr bool isIntegerType(PrimType T)
static bool AddSubNonNumber(InterpState &S, CodePtr OpPC, T LHS, T RHS)
bool Memcpy(InterpState &S, CodePtr OpPC)
bool GE(InterpState &S, CodePtr OpPC)
bool DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, std::byte *Buff, Bits BitWidth, Bits FullBitWidth, bool &HasIndeterminateBits)
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize, const CallExpr *CE)
bool CmpHelperEQ< Pointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
static bool CastFixedPointIntegral(InterpState &S, CodePtr OpPC)
PRESERVE_NONE bool Ret(InterpState &S, CodePtr &PC)
bool MarkDestroyed(InterpState &S, CodePtr OpPC)
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
bool CastIntegralFloating(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem, uint32_t FPOI)
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 CastFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS)
bool PopMSVCCE(InterpState &S, CodePtr OpPC)
bool EnableLocal(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 Subf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool GetPtrThisVirtBase(InterpState &S, CodePtr OpPC, const RecordDecl *D)
bool GetLocalEnabled(InterpState &S, CodePtr OpPC, uint32_t I)
bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal)
bool DoShiftAP(InterpState &S, CodePtr OpPC, const APSInt &LHS, APSInt RHS, LT *Result)
A version of DoShift that works on IntegralAP.
bool CastMemberPtrPtr(InterpState &S, CodePtr OpPC)
bool InitFieldActivate(InterpState &S, CodePtr OpPC, uint32_t I)
bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool IncPopBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
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 Invalid(InterpState &S, CodePtr OpPC)
bool CmpHelper< Pointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
bool Decf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool Assume(InterpState &S, CodePtr OpPC)
bool GetPtrThisBase(InterpState &S, CodePtr OpPC, uint32_t Off)
bool IncDecFloatHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr, uint32_t FPOI)
static bool IsConstantContext(InterpState &S, CodePtr OpPC)
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.
bool isa(CodeGen::Address addr)
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.
OptionalUnsigned< unsigned > UnsignedOrNone
@ ConstantFold
Fold the expression to a constant.
U cast(CodeGen::Address addr)
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
size_t getQuantity() const
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 getNumElems() const
Returns the number of elements stored in the block.
unsigned getSize() const
Returns the size of the object without metadata.
const Decl * asDecl() const
bool isUnknownSizeArray() const
Checks if the descriptor is of an array of unknown size.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
const Expr * asExpr() const
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
Mapping from primitive types to their representation.