13#ifndef LLVM_CLANG_AST_INTERP_INTERP_H
14#define LLVM_CLANG_AST_INTERP_INTERP_H
36#include "llvm/ADT/APFloat.h"
37#include "llvm/ADT/APSInt.h"
38#include "llvm/Support/Compiler.h"
45#if !defined(__aarch64__) && !defined(__i386__) && \
46 !__has_feature(address_sanitizer) && \
47 __has_cpp_attribute(clang::preserve_none)
48#define PRESERVE_NONE [[clang::preserve_none]]
56using APSInt = llvm::APSInt;
80 std::optional<uint64_t> NumElems = std::nullopt,
111 uint32_t VarArgSize);
113 uint32_t VarArgSize);
115 uint32_t VarArgSize);
123 bool TargetIsUCharOrByte);
137 bool IsReferenceCast);
154 const APSInt *
Value =
nullptr,
158template <ShiftDir Dir,
typename LT,
typename RT>
161 if (RHS.isNegative()) {
176 if (LHS.isSigned() && !S.
getLangOpts().CPlusPlus20) {
179 if (LHS.isNegative()) {
184 }
else if (LHS.toUnsigned().countLeadingZeros() <
185 static_cast<unsigned>(RHS)) {
203 if (!LHS.isNumber() || !RHS.isNumber())
209 if constexpr (std::is_same_v<T, Floating>) {
210 S.
CCEDiag(Op, diag::note_expr_divide_by_zero)
211 << Op->getRHS()->getSourceRange();
215 S.
FFDiag(Op, diag::note_expr_divide_by_zero)
216 << Op->getRHS()->getSourceRange();
220 if constexpr (!std::is_same_v<T, FixedPoint>) {
221 if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
222 APSInt LHSInt = LHS.toAPSInt();
224 (-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
227 S.
CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->
getType();
248 APFloat::opStatus Status,
FPOptions FPO);
253bool CheckFloatStatus(InterpState &S, CodePtr OpPC, APFloat::opStatus Status,
275template <PrimType Name, class T = typename PrimConv<Name>::T>
314 template <typename U>
class OpAP>
319 assert(LHS.isNumber() && RHS.isNumber());
335 if constexpr (std::is_same_v<T, FixedPoint>)
351 .toString(Trunc, 10,
Result.isSigned(),
false,
365template <
typename T,
template <
typename U>
class Op>
367 assert(!LHS.isNumber() || !RHS.isNumber());
371 typename T::ReprT Offset;
373 if (LHS.isNumber()) {
377 Number =
static_cast<typename T::ReprT
>(LHS);
379 Offset = RHS.getOffset();
380 Kind = RHS.getKind();
382 assert(RHS.isNumber());
386 Number =
static_cast<typename T::ReprT
>(RHS);
388 Offset = LHS.getOffset();
389 Kind = LHS.getKind();
396template <PrimType Name, class T = typename PrimConv<Name>::T>
400 const unsigned Bits = RHS.bitWidth() + 1;
403 if (LHS.isNumber() != RHS.isNumber())
405 else if (LHS.isNumber() && RHS.isNumber())
425template <PrimType Name, class T = typename PrimConv<Name>::T>
429 const unsigned Bits = RHS.bitWidth() + 1;
438 ?
reinterpret_cast<const Expr *
>(LHS.getPtr())
441 ?
reinterpret_cast<const Expr *
>(RHS.getPtr())
443 if (!isa_and_nonnull<AddrLabelExpr>(A) ||
444 !isa_and_nonnull<AddrLabelExpr>(B))
449 if (LHSAddrExpr->getLabel()->getDeclContext() !=
450 RHSAddrExpr->getLabel()->getDeclContext())
453 S.
Stk.
push<
T>(LHSAddrExpr, RHSAddrExpr);
457 if (!LHS.isNumber() && RHS.isNumber())
459 else if (LHS.isNumber() && RHS.isNumber())
479template <PrimType Name, class T = typename PrimConv<Name>::T>
483 const unsigned Bits = RHS.bitWidth() * 2;
486 if (!LHS.isNumber() || !RHS.isNumber())
506template <PrimType Name, class T = typename PrimConv<Name>::T>
512 if constexpr (std::is_same_v<T, Floating>) {
518 APFloat ResR(A.getSemantics());
519 APFloat ResI(A.getSemantics());
530 Result.initializeAllElements();
533 const T &LHSR = LHS.elem<
T>(0);
534 const T &LHSI = LHS.elem<
T>(1);
535 const T &RHSR = RHS.
elem<
T>(0);
536 const T &RHSI = RHS.
elem<
T>(1);
537 unsigned Bits = LHSR.bitWidth();
540 if (!LHSR.isNumber() || !LHSI.isNumber() || !RHSR.isNumber() ||
548 if (T::mul(LHSR, RHSR,
Bits, &A))
554 if (T::mul(LHSI, RHSI,
Bits, &B))
563 if (T::mul(LHSR, RHSI,
Bits, &A))
565 if (T::mul(LHSI, RHSR,
Bits, &B))
573 Result.initializeAllElements();
579template <PrimType Name, class T = typename PrimConv<Name>::T>
585 if constexpr (std::is_same_v<T, Floating>) {
591 APFloat ResR(A.getSemantics());
592 APFloat ResI(A.getSemantics());
604 Result.initializeAllElements();
607 const T &LHSR = LHS.elem<
T>(0);
608 const T &LHSI = LHS.elem<
T>(1);
609 const T &RHSR = RHS.
elem<
T>(0);
610 const T &RHSI = RHS.
elem<
T>(1);
611 unsigned Bits = LHSR.bitWidth();
613 if (RHSR.isZero() && RHSI.isZero()) {
615 S.
FFDiag(E, diag::note_expr_divide_by_zero);
626 if (T::mul(RHSR, RHSR,
Bits, &A) || T::mul(RHSI, RHSI,
Bits, &B)) {
633 if (T::add(A, B,
Bits, &Den))
638 S.
FFDiag(E, diag::note_expr_divide_by_zero);
649 if (T::mul(LHSR, RHSR,
Bits, &A) || T::mul(LHSI, RHSI,
Bits, &B))
651 if (T::add(A, B,
Bits, &ResultR))
653 if (T::div(ResultR, Den,
Bits, &ResultR))
657 if (T::mul(LHSI, RHSR,
Bits, &A) || T::mul(LHSR, RHSI,
Bits, &B))
659 if (T::sub(A, B,
Bits, &ResultI))
661 if (T::div(ResultI, Den,
Bits, &ResultI))
663 Result.initializeAllElements();
672template <PrimType Name, class T = typename PrimConv<Name>::T>
676 unsigned Bits = RHS.bitWidth();
679 if (!LHS.isNumber() || !RHS.isNumber())
697template <PrimType Name, class T = typename PrimConv<Name>::T>
701 unsigned Bits = RHS.bitWidth();
704 if (!LHS.isNumber() || !RHS.isNumber())
722template <PrimType Name, class T = typename PrimConv<Name>::T>
726 unsigned Bits = RHS.bitWidth();
729 if (!LHS.isNumber() || !RHS.isNumber())
747template <PrimType Name, class T = typename PrimConv<Name>::T>
751 const unsigned Bits = RHS.bitWidth() * 2;
770template <PrimType Name, class T = typename PrimConv<Name>::T>
774 const unsigned Bits = RHS.bitWidth() * 2;
788 if constexpr (std::is_same_v<T, FixedPoint>) {
827template <PrimType Name, class T = typename PrimConv<Name>::T>
831 if constexpr (std::is_same_v<T, Floating>) {
850 "don't expect other types to fail at constexpr negation");
861 NegatedValue.trunc(
Result.bitWidth())
862 .toString(Trunc, 10,
Result.isSigned(),
false,
882template <
typename T, IncDecOp Op, PushVal DoPush>
885 assert(!Ptr.isDummy());
887 if constexpr (std::is_same_v<T, Boolean>) {
892 const T &
Value = Ptr.deref<
T>();
896 if (!
Value.isNumber())
908 if (!T::increment(
Value, &
Result) || !CanOverflow) {
910 Ptr.deref<
T>() =
Result.truncate(*BitWidth);
916 if (!T::decrement(
Value, &
Result) || !CanOverflow) {
918 Ptr.deref<
T>() =
Result.truncate(*BitWidth);
945 APResult.trunc(
Result.bitWidth())
946 .toString(Trunc, 10,
Result.isSigned(),
false,
959template <PrimType Name, class T = typename PrimConv<Name>::T>
971template <PrimType Name, class T = typename PrimConv<Name>::T>
987template <PrimType Name, class T = typename PrimConv<Name>::T>
998template <PrimType Name, class T = typename PrimConv<Name>::T>
1000 uint32_t BitWidth) {
1011template <PrimType Name, class T = typename PrimConv<Name>::T>
1022template <PrimType Name, class T = typename PrimConv<Name>::T>
1024 uint32_t BitWidth) {
1039template <PrimType Name, class T = typename PrimConv<Name>::T>
1050template <PrimType Name, class T = typename PrimConv<Name>::T>
1052 uint32_t BitWidth) {
1066template <PrimType Name, class T = typename PrimConv<Name>::T>
1077template <PrimType Name, class T = typename PrimConv<Name>::T>
1079 uint32_t BitWidth) {
1090template <PrimType Name, class T = typename PrimConv<Name>::T>
1100template <PrimType Name, class T = typename PrimConv<Name>::T>
1102 uint32_t BitWidth) {
1112template <IncDecOp Op, PushVal DoPush>
1122 llvm::APFloat::opStatus Status;
1175template <PrimType Name, class T = typename PrimConv<Name>::T>
1183 if (!T::comp(Val, &
Result)) {
1196template <
typename T>
1198 assert((!std::is_same_v<T, MemberPointer>) &&
1199 "Non-equality comparisons on member pointer types should already be "
1200 "rejected in Sema.");
1206 if (!LHS.isNumber() || !RHS.isNumber())
1210 S.
Stk.
push<BoolT>(BoolT::from(
Fn(LHS.compare(RHS))));
1214template <
typename T>
1229 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1242 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1250 if (std::optional<std::pair<PtrView, PtrView>> Split =
1252 const FieldDecl *LF = Split->first.getField();
1253 const FieldDecl *RF = Split->second.getField();
1256 diag::note_constexpr_pointer_comparison_base_classes);
1259 diag::note_constexpr_pointer_comparison_base_field)
1260 << Split->first.getRecord()->getDecl() << RF->
getParent() << RF;
1263 diag::note_constexpr_pointer_comparison_base_field)
1264 << Split->second.getRecord()->getDecl() << LF->
getParent() << LF;
1268 diag::note_constexpr_pointer_comparison_differing_access)
1290 if (LHS.isZero() && RHS.
isZero()) {
1296 for (
const auto &P : {LHS, RHS}) {
1301 S.
FFDiag(Loc, diag::note_constexpr_pointer_weak_comparison)
1308 if (RHS.
isZero() || LHS.isZero()) {
1313 assert(!LHS.isZero());
1328 std::optional<size_t> A = LHS.computeOffsetForComparison(S.
getASTContext());
1341 diag::note_constexpr_literal_comparison)
1349 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
1355 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
1361 for (
const auto &P : {LHS, RHS}) {
1364 if (P.pointsToLiteral()) {
1365 const Expr *E = P.getRootExpr();
1368 S.
FFDiag(Loc, diag::note_constexpr_literal_comparison);
1371 if (
const auto *CE = dyn_cast<CallExpr>(E);
1374 S.
FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
1378 }
else if (P.isIntegralPointer()) {
1380 S.
FFDiag(Loc, diag::note_constexpr_pointer_constant_comparison)
1389 S.
FFDiag(Loc, diag::note_constexpr_pointer_comparison_zero_sized)
1398 diag::note_constexpr_pointer_comparison_unspecified)
1416 for (
const auto &MP : {LHS, RHS}) {
1419 S.
FFDiag(Loc, diag::note_constexpr_mem_pointer_weak_comparison)
1420 << MP.getMemberFunction();
1428 if (LHS.
isZero() && RHS.isZero()) {
1432 if (LHS.
isZero() || RHS.isZero()) {
1438 for (
const auto &MP : {LHS, RHS}) {
1442 S.
CCEDiag(Loc, diag::note_constexpr_compare_virtual_mem_ptr) << MD;
1450template <PrimType Name, class T = typename PrimConv<Name>::T>
1457template <PrimType Name, class T = typename PrimConv<Name>::T>
1464 if constexpr (std::is_same_v<T, Pointer>) {
1467 diag::note_constexpr_pointer_comparison_unspecified)
1472 std::optional<size_t> LHSOffset =
1474 std::optional<size_t> RHSOffset =
1476 if (!LHSOffset || !RHSOffset)
1479 if (LHSOffset < RHSOffset)
1481 else if (LHSOffset > RHSOffset)
1486 CmpResult = LHS.compare(RHS);
1490 const auto *CmpValueInfo =
1492 assert(CmpValueInfo);
1493 assert(CmpValueInfo->hasValidIntValue());
1497template <PrimType Name, class T = typename PrimConv<Name>::T>
1504template <PrimType Name, class T = typename PrimConv<Name>::T>
1511template <PrimType Name, class T = typename PrimConv<Name>::T>
1519template <PrimType Name, class T = typename PrimConv<Name>::T>
1526template <PrimType Name, class T = typename PrimConv<Name>::T>
1538template <PrimType Name, class T = typename PrimConv<Name>::T>
1544template <PrimType Name, class T = typename PrimConv<Name>::T>
1555 const auto &Top = S.
Stk.
pop<TopT>();
1556 const auto &Bottom = S.
Stk.
pop<BottomT>();
1568template <PrimType Name, class T = typename PrimConv<Name>::T>
1572 Result.copy(Arg.toAPSInt());
1577 if constexpr (std::is_same_v<T, uint16_t>) {
1579 }
else if constexpr (std::is_same_v<T, int16_t>) {
1581 }
else if constexpr (std::is_same_v<T, uint32_t>) {
1583 }
else if constexpr (std::is_same_v<T, int32_t>) {
1585 }
else if constexpr (std::is_same_v<T, uint64_t>) {
1587 }
else if constexpr (std::is_same_v<T, int64_t>) {
1608template <PrimType Name, class T = typename PrimConv<Name>::T>
1618bool PseudoDtor(InterpState &S, CodePtr OpPC);
1627template <PrimType Name, class T = typename PrimConv<Name>::T>
1633template <PrimType Name, class T = typename PrimConv<Name>::T>
1642template <PrimType Name, class T = typename PrimConv<Name>::T>
1650template <PrimType Name, class T = typename PrimConv<Name>::T>
1676template <PrimType Name, class T = typename PrimConv<Name>::T>
1700template <PrimType Name, class T = typename PrimConv<Name>::T>
1708 if (!
This.isBlockPointer())
1718template <PrimType Name, class T = typename PrimConv<Name>::T>
1730template <PrimType Name, class T = typename PrimConv<Name>::T>
1741template <PrimType Name, class T = typename PrimConv<Name>::T>
1747template <PrimType Name, class T = typename PrimConv<Name>::T>
1753 if constexpr (std::is_same_v<T, Floating>) {
1755 if (!Val.singleWord()) {
1756 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
1757 Val.take(NewMemory);
1760 }
else if constexpr (std::is_same_v<T, MemberPointer>) {
1764 for (
unsigned I = 0; I != PathLength; ++I) {
1765 NewPath[I] = Val.getPathEntry(I);
1767 Val.takePath(NewPath);
1768 }
else if constexpr (std::is_same_v<T, Pointer>) {
1770 if (Val.isOpaquePointer() && Val.asOpaquePointer().PathLength != 0) {
1777 Val.getByteOffset());
1781 auto &Val = P.
deref<
T>();
1782 if (!Val.singleWord()) {
1783 uint64_t *NewMemory =
new (S.
P) uint64_t[Val.numWords()];
1784 Val.take(NewMemory);
1795template <PrimType Name, class T = typename PrimConv<Name>::T>
1803 assert(Ptr.getRootExpr());
1825template <PrimType Name, class T = typename PrimConv<Name>::T>
1832 if (!
This.isDereferencable())
1841template <PrimType Name, class T = typename PrimConv<Name>::T>
1848 if (!
This.isDereferencable())
1858template <PrimType Name, class T = typename PrimConv<Name>::T>
1860 uint32_t FieldBitWidth) {
1866 if (!
This.isDereferencable())
1873 if (!
Value.isNumber())
1877 Field.deref<
T>() =
Value.truncate(FieldBitWidth);
1882template <PrimType Name, class T = typename PrimConv<Name>::T>
1884 uint32_t FieldOffset, uint32_t FieldBitWidth) {
1890 if (!
This.isDereferencable())
1897 if (!
Value.isNumber())
1901 Field.deref<
T>() =
Value.truncate(FieldBitWidth);
1910template <PrimType Name, class T = typename PrimConv<Name>::T>
1914 if (!Ptr.isDereferencable())
1922 const Pointer &Field = Ptr.atField(I);
1923 Field.deref<
T>() =
Value;
1928template <PrimType Name, class T = typename PrimConv<Name>::T>
1932 if (!Ptr.isDereferencable())
1939 const Pointer &Field = Ptr.atField(I);
1940 Field.deref<
T>() =
Value;
1946template <PrimType Name, class T = typename PrimConv<Name>::T>
1948 uint32_t FieldBitWidth) {
1951 if (!Ptr.isDereferencable())
1955 if (!
Value.isNumber())
1963 const Pointer &Field = Ptr.atField(FieldOffset);
1965 unsigned BitWidth = std::min(FieldBitWidth,
Value.bitWidth());
1968 if constexpr (T::isSigned())
1970 Value.toAPSInt().trunc(BitWidth).sextOrTrunc(
Value.bitWidth()));
1973 Value.toAPSInt().trunc(BitWidth).zextOrTrunc(
Value.bitWidth()));
1977 Field.deref<
T>() =
Value.truncate(FieldBitWidth);
1983template <PrimType Name, class T = typename PrimConv<Name>::T>
1985 uint32_t FieldBitWidth) {
1988 if (!Ptr.isDereferencable())
1992 if (!
Value.isNumber())
2000 const Pointer &Field = Ptr.atField(FieldOffset);
2002 unsigned BitWidth = std::min(FieldBitWidth,
Value.bitWidth());
2005 if constexpr (T::isSigned())
2007 Value.toAPSInt().trunc(BitWidth).sextOrTrunc(
Value.bitWidth()));
2010 Value.toAPSInt().trunc(BitWidth).zextOrTrunc(
Value.bitWidth()));
2014 Field.deref<
T>() =
Value.truncate(FieldBitWidth);
2082bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t
Off,
bool NullOK);
2085 const Type *TargetType,
const Type *FinalType);
2093 if (!
This.isBlockPointer())
2146 diag::note_constexpr_dereferencing_null);
2188template <PrimType Name, class T = typename PrimConv<Name>::T>
2193 if (!Ptr.canDeref(Name))
2199template <PrimType Name, class T = typename PrimConv<Name>::T>
2204 if (!Ptr.canDeref(Name))
2217 bool Failed =
false;
2220 if (!Ptr.isBlockPointer())
2222 if (!Failed && !Ptr.canDeref(
PT_Ptr))
2227 if (Ptr.isOpaquePointer()) {
2230 if (!Ptr.asOpaquePointer().Base.getType()->isPointerType())
2235 Ptr.getByteOffset());
2240 if (!Ptr.isBlockPointer())
2250template <PrimType Name, class T = typename PrimConv<Name>::T>
2256 if (!Ptr.canDeref(Name))
2263template <PrimType Name, class T = typename PrimConv<Name>::T>
2269 if (!Ptr.canDeref(Name))
2289 Ptr.atField(I).activate();
2293template <PrimType Name, class T = typename PrimConv<Name>::T>
2306template <PrimType Name, class T = typename PrimConv<Name>::T>
2319template <PrimType Name, class T = typename PrimConv<Name>::T>
2327 if (
const auto *FD = Ptr.getField())
2328 Ptr.deref<
T>() =
Value.truncate(FD->getBitWidthValue());
2334template <PrimType Name, class T = typename PrimConv<Name>::T>
2341 if (
const auto *FD = Ptr.getField())
2342 Ptr.deref<
T>() =
Value.truncate(FD->getBitWidthValue());
2348template <PrimType Name, class T = typename PrimConv<Name>::T>
2357 if (
const auto *FD = Ptr.getField())
2358 Ptr.deref<
T>() =
Value.truncate(FD->getBitWidthValue());
2364template <PrimType Name, class T = typename PrimConv<Name>::T>
2373 if (
const auto *FD = Ptr.getField())
2374 Ptr.deref<
T>() =
Value.truncate(FD->getBitWidthValue());
2380template <PrimType Name, class T = typename PrimConv<Name>::T>
2387 new (&Ptr.deref<
T>())
T(
Value);
2391template <PrimType Name, class T = typename PrimConv<Name>::T>
2398 new (&Ptr.deref<
T>())
T(
Value);
2405template <PrimType Name, class T = typename PrimConv<Name>::T>
2410 if (Ptr.isConstexprUnknown())
2419 if (Idx == 0 && !Desc->
isArray()) {
2421 new (&Ptr.deref<
T>())
T(
Value);
2431 S.
FFDiag(Loc, diag::note_constexpr_access_past_end)
2436 Ptr.initializeElement(Idx);
2437 new (&Ptr.elem<
T>(Idx))
T(
Value);
2442template <PrimType Name, class T = typename PrimConv<Name>::T>
2447 if (Ptr.isConstexprUnknown())
2456 if (Idx == 0 && !Desc->
isArray()) {
2458 new (&Ptr.deref<
T>())
T(
Value);
2468 S.
FFDiag(Loc, diag::note_constexpr_access_past_end)
2473 Ptr.initializeElement(Idx);
2474 new (&Ptr.elem<
T>(Idx))
T(
Value);
2489 if (std::optional<Pointer> Ptr = MP.toPointer(S.
Ctx)) {
2496bool Memcpy(InterpState &S, CodePtr OpPC);
2504template <
class T, ArithOp Op>
2506 const T &Offset,
const Pointer &Ptr,
2507 bool IsPointerArith =
false) {
2509 if (Offset.isZero())
2516 return std::nullopt;
2521 return std::nullopt;
2524 if (Ptr.isIntegralPointer()) {
2525 uint64_t
V = Ptr.getIntegerRepresentation();
2526 QualType ElemType = Ptr.asIntPointer().getPointeeType();
2531 uint64_t O =
static_cast<uint64_t
>(Offset) * ElemSize;
2533 return Pointer(
V + O, Ptr.asIntPointer().getType());
2535 return Pointer(
V - O, Ptr.asIntPointer().getType());
2536 }
else if (Ptr.isFunctionPointer()) {
2537 uint64_t O =
static_cast<uint64_t
>(Offset);
2540 N = Ptr.getByteOffset() + O;
2542 N = Ptr.getByteOffset() - O;
2546 return Pointer(Ptr.asFunctionPointer().Func, N);
2547 }
else if (Ptr.isStringPointer()) {
2550 NewOffset = Ptr.getByteOffset() +
static_cast<int64_t
>(Offset);
2552 NewOffset = Ptr.getByteOffset() -
static_cast<int64_t
>(Offset);
2553 if (NewOffset < 0 ||
2554 NewOffset > (Ptr.asStringPointer().getLiteral()->getLength() + 1)) {
2556 (Ptr.asStringPointer().getLiteral()->getLength() + 1));
2557 return std::nullopt;
2559 return Pointer(Ptr.asStringPointer(), NewOffset);
2560 }
else if (!Ptr.isBlockPointer()) {
2561 return std::nullopt;
2564 assert(Ptr.isBlockPointer());
2566 uint64_t MaxIndex =
static_cast<uint64_t
>(Ptr.getNumElems());
2568 if (Ptr.isOnePastEnd())
2571 Index = Ptr.getIndex();
2575 auto DiagInvalidOffset = [&]() ->
void {
2576 const unsigned Bits = Offset.bitWidth();
2577 APSInt APOffset(Offset.toAPSInt().extend(
Bits + 2),
false);
2581 (Op ==
ArithOp::Add) ? (APIndex + APOffset) : (APIndex - APOffset);
2586 uint64_t IOffset =
static_cast<uint64_t
>(Offset);
2587 uint64_t MaxOffset = MaxIndex - Index;
2591 if (Offset.isNegative() && (Offset.isMin() || -IOffset > Index))
2592 DiagInvalidOffset();
2595 if (Offset.isPositive() && IOffset > MaxOffset)
2596 DiagInvalidOffset();
2599 if (Offset.isPositive() && Index < IOffset)
2600 DiagInvalidOffset();
2603 if (Offset.isNegative() && (Offset.isMin() || -IOffset > MaxOffset))
2604 DiagInvalidOffset();
2608 return std::nullopt;
2611 int64_t WideIndex =
static_cast<int64_t
>(Index);
2612 int64_t WideOffset =
static_cast<int64_t
>(Offset);
2615 Result = WideIndex + WideOffset;
2617 Result = WideIndex - WideOffset;
2622 if (
Result == 0 && Ptr.isOnePastEnd()) {
2623 if (Ptr.getFieldDesc()->isArray())
2624 return Ptr.atIndex(0);
2625 return Pointer(Ptr.asBlockPointer().Pointee, Ptr.asBlockPointer().Base);
2628 return Ptr.atIndex(
static_cast<uint64_t
>(
Result));
2632 const Pointer &Ptr, APSInt &&Offset,
2634template <PrimType Name, class T = typename PrimConv<Name>::T>
2639 if (Ptr.isOpaquePointer()) {
2640 if (std::optional<Pointer>
Result =
2649 S, OpPC, Offset, Ptr,
true)) {
2656template <PrimType Name, class T = typename PrimConv<Name>::T>
2661 if (Ptr.isOpaquePointer()) {
2662 if (std::optional<Pointer>
Result =
2671 S, OpPC, Offset, Ptr,
true)) {
2679 bool ConstexprUnknown) {
2684template <ArithOp Op>
2687 if (!Ptr.isDereferencable())
2700 if (std::optional<Pointer>
Result =
2709 OneT One = OneT::from(1);
2710 if (std::optional<Pointer>
Result =
2722 if (!Ptr.isInitialized())
2731 if (!Ptr.isInitialized())
2740template <PrimType Name, class T = typename PrimConv<Name>::T>
2749 if (!LHSAddrExpr || !RHSAddrExpr) {
2751 diag::note_constexpr_pointer_arith_unspecified)
2761 S.
Stk.
push<
T>(LHSAddrExpr, RHSAddrExpr);
2770 diag::note_constexpr_pointer_arith_unspecified)
2776 if (ElemSize == 0) {
2781 diag::note_constexpr_pointer_subtraction_zero_size)
2798 diag::note_constexpr_pointer_subtraction_not_same_array);
2810 (
static_cast<int64_t
>(*VL) -
static_cast<int64_t
>(*VR)) / ElemSize;
2811 if (
static_cast<int64_t
>(T::from(R64)) != R64)
2852 if (!(U::bitWidth() >= 32 && U::bitWidth() <= In.bitWidth()))
2864 llvm::RoundingMode RM) {
2874 FixedPointSemantics::getFromOpaqueInt(FPS);
2889template <PrimType Name, class T = typename PrimConv<Name>::T>
2894 if (!Source.isNumber())
2901 APInt SourceInt = Source.toAPSInt().extOrTrunc(BitWidth);
2908template <PrimType Name, class T = typename PrimConv<Name>::T>
2913 if (!Source.isNumber())
2920 APInt SourceInt = Source.toAPSInt().extOrTrunc(BitWidth);
2930template <PrimType Name, class T = typename PrimConv<Name>::T>
2933 if (Val.isNegative() || Val.getActiveBits() > 63)
2940template <PrimType Name, class T = typename PrimConv<Name>::T>
2942 const llvm::fltSemantics *Sem, uint32_t FPOI) {
2946 if (!From.isNumber())
2950 APSInt FromAP = From.toAPSInt();
2961template <PrimType Name, class T = typename PrimConv<Name>::T>
2965 if constexpr (std::is_same_v<T, Boolean>) {
2974 if ((Status & APFloat::opStatus::opInvalidOp)) {
2995 if (Ptr.isOpaquePointer()) {
3009 const Pointer &Ptr,
unsigned BitWidth);
3014template <PrimType Name, class T = typename PrimConv<Name>::T>
3020 if constexpr (std::is_same_v<T, Boolean>) {
3021 S.
Stk.
push<
T>(T::from(Ptr.getIntegerRepresentation()));
3023 if (Ptr.isBlockPointer()) {
3025 }
else if (Ptr.isOpaquePointer()) {
3026 if (
const Expr *BaseExpr = Ptr.asOpaquePointer().getBaseExpr()) {
3033 Ptr.asOpaquePointer().
Base.asVarDecl(), 0);
3036 }
else if (Ptr.isFunctionPointer()) {
3037 const void *FuncDecl = Ptr.asFunctionPointer().Func->getDecl();
3039 }
else if (Ptr.isStringPointer()) {
3041 (
const void *)Ptr.asStringPointer().getLiteral(), 0);
3043 S.
Stk.
push<
T>(T::from(Ptr.getIntegerRepresentation()));
3046 S.
Stk.
push<
T>(T::from(Ptr.getIntegerRepresentation()));
3051template <PrimType Name, class T = typename PrimConv<Name>::T>
3085 const llvm::fltSemantics *Sem) {
3088 Result.copy(Fixed.toFloat(Sem));
3093template <PrimType Name, class T = typename PrimConv<Name>::T>
3098 APSInt Int = Fixed.toInt(T::bitWidth(), T::isSigned(), &Overflow);
3109 S.
CCEDiag(E, diag::note_constexpr_invalid_cast)
3110 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
3115bool PtrPtrCast(InterpState &S, CodePtr OpPC,
bool SrcIsVoidPtr,
3116 const Type *TargetType);
3122template <PrimType Name, class T = typename PrimConv<Name>::T>
3130 if (!
Result.singleWord())
3131 std::memset(
Result.Memory, 0,
Result.numWords() *
sizeof(uint64_t));
3138 if (!
Result.singleWord())
3139 std::memset(
Result.Memory, 0,
Result.numWords() *
sizeof(uint64_t));
3144template <PrimType Name, class T = typename PrimConv<Name>::T>
3148 if constexpr (std::is_same_v<T, Pointer>)
3165template <PrimType Name, class T = typename PrimConv<Name>::T>
3167 const auto &P = S.
Stk.
pop<
T>();
3187 if (!
This.isDummy()) {
3189 if (!
This.isTypeidPointer()) {
3190 [[maybe_unused]]
const Record *R =
This.getRecord();
3192 R =
This.narrow().getRecord();
3195 assert(R->getDecl() ==
3217template <
class LT,
class RT, ShiftDir Dir>
3221 const unsigned Bits = LHS.bitWidth();
3225 RT::bitAnd(RHS, RT::from(LHS.bitWidth() - 1, RHS.bitWidth()),
3226 RHS.bitWidth(), &RHS);
3228 if (RHS.isNegative()) {
3232 S.
CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
3236 RHS = RHS.isMin() ? RT(APSInt::getMaxValue(RHS.bitWidth(),
false)) : -RHS;
3240 S, OpPC, LHS, RHS,
Result);
3252 typename LT::AsUnsigned R;
3253 unsigned MaxShiftAmount = LHS.bitWidth() - 1;
3255 if (
Compare(RHS, RT::from(MaxShiftAmount, RHS.bitWidth())) ==
3257 if (LHS.isNegative())
3258 R = LT::AsUnsigned::zero(LHS.bitWidth());
3260 RHS = RT::from(LHS.countLeadingZeros(), RHS.bitWidth());
3261 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
3262 LT::AsUnsigned::from(RHS,
Bits),
Bits, &R);
3264 }
else if (LHS.isNegative()) {
3266 R = LT::AsUnsigned::zero(LHS.bitWidth());
3269 typename LT::AsUnsigned LHSU = LT::AsUnsigned::from(-LHS);
3270 LT::AsUnsigned::shiftLeft(LHSU, LT::AsUnsigned::from(RHS,
Bits),
Bits,
3276 LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
3277 LT::AsUnsigned::from(RHS,
Bits),
Bits, &R);
3284 if (
Compare(RHS, RT::from(MaxShiftAmount, RHS.bitWidth())) ==
3286 R = LT::AsUnsigned::from(0);
3290 LT::shiftRight(LHS, LT::from(RHS,
Bits),
Bits, &A);
3291 R = LT::AsUnsigned::from(A);
3299template <
class LT,
class RT, ShiftDir Dir>
3302 const unsigned Bits = LHS.getBitWidth();
3307 APSInt(llvm::APInt(RHS.getBitWidth(),
static_cast<uint64_t
>(
Bits - 1)),
3310 if (RHS.isNegative()) {
3314 S.
CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS;
3319 S, OpPC, LHS, -(RHS.extend(RHS.getBitWidth() + 1)),
Result);
3343template <PrimType NameL, PrimType NameR>
3347 auto RHS = S.
Stk.
pop<RT>();
3355 RHS.toAPSInt(), &
Result);
3362template <PrimType NameL, PrimType NameR>
3366 auto RHS = S.
Stk.
pop<RT>();
3374 RHS.toAPSInt(), &
Result);
3384 llvm::FixedPointSemantics LHSSema = LHS.
getSemantics();
3386 unsigned ShiftBitWidth =
3387 LHSSema.getWidth() - (
unsigned)LHSSema.hasUnsignedPadding() - 1;
3392 if (RHS.isNegative()) {
3395 }
else if (
static_cast<unsigned>(RHS.toAPSInt().getLimitedValue(
3396 ShiftBitWidth)) != RHS.toAPSInt()) {
3398 S.
CCEDiag(E, diag::note_constexpr_large_shift)
3399 << RHS.toAPSInt() << E->
getType() << ShiftBitWidth;
3422 S.
FFDiag(EndLoc, diag::note_constexpr_no_return);
3438 if (Ptr.isBlockPointer())
3446template <
typename T>
3449 if (Ptr.isOpaquePointer()) {
3457 if (Offset.isZero()) {
3458 if (
const Descriptor *Desc = Ptr.getFieldDesc();
3459 Desc && Desc->isArray() && Ptr.getIndex() == 0) {
3467 assert(!Offset.isZero());
3469 if (std::optional<Pointer>
Result =
3485template <PrimType Name, class T = typename PrimConv<Name>::T>
3493template <PrimType Name, class T = typename PrimConv<Name>::T>
3501template <PrimType Name, class T = typename PrimConv<Name>::T>
3508 assert(Ptr.atIndex(Index).getFieldDesc()->getPrimType() == Name);
3513template <PrimType Name, class T = typename PrimConv<Name>::T>
3520 assert(Ptr.atIndex(Index).getFieldDesc()->getPrimType() == Name);
3525template <PrimType Name, class T = typename PrimConv<Name>::T>
3527 uint32_t DestIndex, uint32_t Size) {
3531 if (SrcPtr.isDummy() || DestPtr.
isDummy())
3537 const Descriptor *SrcDesc = SrcPtr.getFieldDesc();
3543 for (uint32_t I = 0; I != Size; ++I) {
3549 DestPtr.
elem<
T>(DestIndex + I) = SrcPtr.elem<
T>(SrcIndex + I);
3565 if (!Ptr.isZeroSizeArray()) {
3571 if (Ptr.isBlockPointer()) {
3572 if (!Ptr.isArrayRoot())
3578 if (Ptr.isStringPointer()) {
3583 if (!Ptr.isOpaquePointer()) {
3596 diag::note_constexpr_unsupported_unsized_array);
3602 APSInt(APInt::getZero(1),
true),
3607 diag::note_constexpr_unsupported_unsized_array);
3617template <PrimType Name, class T = typename PrimConv<Name>::T>
3622 << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
3627 if (IntVal.getOffset() != 0)
3633 if (IntVal.getOffset() != 0)
3636 const Block *B = (
const Block *)IntVal.getPtr();
3643 uint64_t NullValue =
3646 static_cast<uint64_t
>(IntVal) == NullValue);
3670 S.
FFDiag(Loc, diag::note_constexpr_stmt_expr_unsupported)
3677 diag::note_break_continue_label_outside_context)
3781 diag::note_constexpr_access_volatile_type)
3793 S.
CCEDiag(E, diag::note_constexpr_non_const_vectorelements) << ArgRange;
3801 diag::note_constexpr_pseudo_destructor);
3813 S.
CCEDiag(Loc, diag::note_constexpr_assumption_failed);
3817template <PrimType Name, class T = typename PrimConv<Name>::T>
3821 ArrayIndices.emplace_back(
3833template <PrimType Name, class T = typename PrimConv<Name>::T>
3840 S.
CCEDiag(Loc, diag::note_non_null_attribute_failed);
3846 const APSInt &
Value);
3848template <PrimType Name, class T = typename PrimConv<Name>::T>
3866 const FromT &OldPtr = S.
Stk.
pop<FromT>();
3868 if constexpr (std::is_same_v<FromT, FunctionPointer> &&
3869 std::is_same_v<ToT, Pointer>) {
3872 }
else if constexpr (std::is_same_v<FromT, Pointer> &&
3873 std::is_same_v<ToT, FunctionPointer>) {
3874 if (OldPtr.isFunctionPointer()) {
3876 OldPtr.getByteOffset());
3881 S.
Stk.
push<ToT>(ToT(OldPtr.getIntegerRepresentation(),
nullptr));
3911 if (!Ptr.isUnknownSizeArray() && NumElems > Ptr.getNumElems()) {
3913 << Ptr.getNumElems() << NumElems;
3934template <PrimType Name, class SizeT = typename PrimConv<Name>::T>
3949 if (NumElements.isNegative()) {
3959 if (!
CheckArraySize(S, OpPC,
static_cast<uint64_t
>(NumElements)))
3963 Block *B = Allocator.
allocate(Source,
T,
static_cast<size_t>(NumElements),
3966 if (NumElements.isZero())
3973template <PrimType Name, class SizeT = typename PrimConv<Name>::T>
3993 if (NumElements.isNegative()) {
4003 if (!
CheckArraySize(S, OpPC,
static_cast<uint64_t
>(NumElements)))
4007 Block *B = Allocator.
allocate(ElementDesc,
static_cast<size_t>(NumElements),
4010 if (NumElements.isZero())
4018bool Free(InterpState &S, CodePtr OpPC,
bool DeleteIsArrayForm,
4019 bool IsGlobalDelete);
4033 std::optional<uint64_t> ArraySize = std::nullopt);
4035template <PrimType Name, class T = typename PrimConv<Name>::T>
4037 const auto &Size = S.
Stk.
pop<
T>();
4043template <PrimType Name, class T = typename PrimConv<Name>::T>
4045 uint32_t ResultBitWidth,
const llvm::fltSemantics *Sem,
4046 const Type *TargetType) {
4052 if constexpr (std::is_same_v<T, Pointer>) {
4055 diag::note_constexpr_bit_cast_invalid_type)
4056 <<
true <<
false << 1 ;
4062 }
else if constexpr (std::is_same_v<T, MemberPointer>) {
4064 diag::note_constexpr_bit_cast_invalid_type)
4065 <<
true <<
false << 2 ;
4069 size_t BuffSize = ResultBitWidth / 8;
4071 bool HasIndeterminateBits =
false;
4073 Bits FullBitWidth(ResultBitWidth);
4074 Bits BitWidth = FullBitWidth;
4076 if constexpr (std::is_same_v<T, Floating>) {
4078 BitWidth =
Bits(llvm::APFloatBase::getSizeInBits(*Sem));
4081 if (!
DoBitCast(S, OpPC, FromPtr, Buff.data(), BitWidth, FullBitWidth,
4082 HasIndeterminateBits))
4085 if (!
CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
4088 if constexpr (std::is_same_v<T, Floating>) {
4095 T::bitcastFromMemory(Buff.data(), ResultBitWidth, &
Result);
4097 }
else if constexpr (std::is_same_v<T, Boolean>) {
4101 auto Val =
static_cast<unsigned int>(Buff[0]);
4104 diag::note_constexpr_bit_cast_unrepresentable_value)
4108 S.
Stk.
push<
T>(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
4111 S.
Stk.
push<
T>(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
4141bool DiagTypeid(InterpState &S, CodePtr OpPC);
4149 const void *Operand) {
4164 if constexpr (std::is_pointer<T>::value)
4167 return OpPC.
read<
T>();
4176 OpPC +=
align(F.bytesToSerialize());
4185 assert(
Result.bitWidth() == BitWidth);
4197 assert(
Result.bitWidth() == BitWidth);
Defines the clang::ASTContext interface.
bool isOpaqueConstantCall(const CallExpr *E)
Should this call expression be treated as forming an opaque constant?
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.
uint64_t getTargetNullPointerValue(QualType QT) const
Get target-dependent integer value for null pointer which is used for constant folding.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
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.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
AddrLabelExpr - The GNU address of label extension, representing &&label.
LabelDecl * getLabel() const
Represents a C++ constructor within a class.
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]).
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
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.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) 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.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
bool isConstexprUnknown() const
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)
Wrapper around numeric types.
static std::enable_if_t<!std::is_same_v< ValT, IntegralKind >, Integral > from(ValT V, unsigned NumBits=0)
SourceLocation getLocation(CodePtr PC) const
void setParam(unsigned Index, const T &Value)
Mutates a local copy of a parameter.
Pointer getLocalPointer(unsigned Offset) const
Returns a pointer to a local variables.
SourceInfo getSource(CodePtr PC) const
Map a location to a source.
SourceRange getRange(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.
void setLocal(unsigned Offset, const T &Value)
Mutates a local variable.
bool isBottomFrame() const
Block * getLocalBlock(unsigned Offset) const
bool hasThisPointer() const
const Expr * getExpr(CodePtr PC) const
const T & getParam(unsigned Index) const
Returns the value of an argument.
bool isLocalEnabled(unsigned Offset) const
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 enableLocal(unsigned Offset)
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
llvm::SmallVector< PtrView > InitializingPtrs
List of blocks we're currently running either constructors or destructors for.
T allocAP(unsigned BitWidth)
unsigned SpeculationDepth
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.
bool pointsToLabel() const
Whether this points to a block created for an AddrLabelExpr.
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.
bool isOpaquePointer() const
bool isStringPointer() const
T & deref() const
Dereferences the pointer, if it's live.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
QualType getType() const
Returns the type of the innermost field.
void initialize() const
Initializes a field.
std::optional< size_t > computeOffsetForComparison(const ASTContext &ASTCtx) const
Compute an integer that can be used to compare this pointer to another one.
bool isArrayRoot() const
Whether this array refers to an array, but not to the first element.
static bool elemsOfSameArray(const Pointer &A, const Pointer &B)
Checks if two pointers can be subtracted.
T & elem(unsigned I) const
Dereferences the element at index I.
std::optional< size_t > computeLayoutOffset(const ASTContext &ASTCtx) const
Compute the pointer offset as given by the ASTRecordLayout.
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.
bool isConstexprUnknown() const
bool isOnePastEnd() const
Checks if the index is one past end.
uint64_t getIntegerRepresentation() const
bool isBlockPointer() const
void initializeElement(unsigned Index) const
Initialized the given element of a primitive array.
bool isFunctionPointer() const
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
bool isBaseClass() const
Checks if a structure is a base class.
static std::optional< std::pair< PtrView, PtrView > > computeSplitPoint(const Pointer &A, const Pointer &B)
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.
Structure/Class descriptor.
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)
bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if a field from which a pointer is going to be derived is valid.
static bool ShiftFixedPoint(InterpState &S, CodePtr OpPC, bool Left)
bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off)
bool GetMemberPtrBase(InterpState &S)
bool PseudoDtor(InterpState &S, CodePtr OpPC)
Ends the lifetime of the pop'd pointer.
bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr, const Type *TargetType)
bool InitPop(InterpState &S, CodePtr OpPC)
bool Shr(InterpState &S, CodePtr OpPC)
bool CheckDestruction(InterpState &S, CodePtr OpPC)
bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index)
bool Flip(InterpState &S)
[Value1, Value2] -> [Value2, Value1]
bool GetTypeid(InterpState &S, const Type *TypePtr, const Type *TypeInfoType)
Typeid support.
bool GetLocalEnabled(InterpState &S, uint32_t I)
bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth)
bool CastAPToOffsetIndex(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.
bool GetPtrParam(InterpState &S, uint32_t Index)
bool arrayElemPtrOpaque(InterpState &S, CodePtr OpPC, const Pointer &Ptr, APSInt &&Index, bool AllowReplace)
bool GetThisField(InterpState &S, CodePtr OpPC, uint32_t I)
bool PushCC(InterpState &S, bool Value)
bool PreInc(InterpState &S, CodePtr OpPC, bool CanOverflow)
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)
std::optional< Pointer > addSubOffsetOpaque(InterpState &S, CodePtr OpPC, const Pointer &Ptr, APSInt &&Offset, ArithOp Op)
bool handleOverflow(InterpState &S, CodePtr OpPC, const T &SrcValue)
Floating ReadArg< Floating >(InterpState &S, CodePtr &OpPC)
bool GetPtrLocal(InterpState &S, uint32_t I)
bool CastAddressSpace(InterpState &S, CodePtr OpPC, uint64_t Value, const Type *Ty)
bool Incf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS, LT *Result)
bool StartThisLifetime(InterpState &S)
void cleanupAfterFunctionCall(InterpState &S, const Function *Func)
bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc, AccessKinds AK)
Checks if the Descriptor is of a constexpr or const global variable.
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 BitCast(InterpState &S, CodePtr OpPC)
bool LoadPop(InterpState &S, CodePtr OpPC)
bool SubPtr(InterpState &S, CodePtr OpPC, uint32_t ElemSize)
1) Pops a Pointer from the stack.
bool PushIgnoreDiags(InterpState &S)
bool CheckGlobalLoad(InterpState &S, CodePtr OpPC, const Block *B)
Checks a direct load of a primitive value from a global or local variable.
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.
PRESERVE_NONE bool NoRet(InterpState &S)
bool InitBitFieldActivate(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
bool CtorCheck(InterpState &S)
Abort without a diagnostic if we're checking for a potential constant expression and this is not the ...
bool CheckDeleteSource(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Check the source of the pointer passed to delete/delete[] has actually been heap allocated by us.
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 CastMemberPtrDerivedPop(InterpState &S, int32_t Off, const RecordDecl *BaseDecl)
BaseToDerivedMemberPointer.
bool InitBitField(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
static bool IncDecPtrHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
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 CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, unsigned BitWidth)
bool CheckDecl(InterpState &S, const VarDecl *VD)
bool AddSubMulHelper(InterpState &S, CodePtr OpPC, unsigned Bits, const T &LHS, const T &RHS)
bool EnableLocal(InterpState &S, uint32_t I)
bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off)
1) Peeks a Pointer 2) Pushes Pointer.atField(Off) on the stack
static bool CheckAllocations(InterpState &S)
bool StoreActivate(InterpState &S, CodePtr OpPC)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
PRESERVE_NONE bool Ret(InterpState &S)
bool InitThisBitFieldActivate(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
bool GetIntPtr(InterpState &S, CodePtr OpPC, const Type *Ty)
bool BitOr(InterpState &S)
1) Pops the RHS from the stack.
static bool CastFixedPointFloating(InterpState &S, const llvm::fltSemantics *Sem)
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 handleFixedPointOverflow(InterpState &S, CodePtr OpPC, const FixedPoint &FP)
bool PopIgnoreDiags(InterpState &S)
constexpr bool isIntegralOrPointer()
bool ArrayElemPtr(InterpState &S, CodePtr OpPC)
bool GetMemberPtrDecl(InterpState &S)
bool NE(InterpState &S, CodePtr OpPC)
bool handleReference(InterpState &S, CodePtr OpPC, Block *B)
bool StartSpeculation(InterpState &S)
bool CheckBitCast(InterpState &S, CodePtr OpPC, const Type *TargetType, bool SrcIsVoidPtr)
bool CopyMemberPtrPath(InterpState &S, const RecordDecl *Entry, bool IsDerived)
Just append the given Entry to the MemberPointer's path.
llvm::FixedPointSemantics FixedPointSemantics
static bool FnPtrCast(InterpState &S, CodePtr OpPC)
static bool ZeroIntAPS(InterpState &S, uint32_t BitWidth)
bool Shl(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 GetPtrDerivedPop(InterpState &S, CodePtr OpPC, bool NullOK, const Type *TargetType, const Type *FinalType)
bool CheckBCPResult(InterpState &S, const Pointer &Ptr)
bool SetLocal(InterpState &S, uint32_t I)
1) Pops the value from the stack.
PRESERVE_NONE bool EndSpeculation(InterpState &S)
bool diagnoseShiftFailure(InterpState &S, CodePtr OpPC, ShiftFailure Failure, const APSInt *Value, unsigned Bits)
bool GetFnPtr(InterpState &S, const Function *Func)
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 FinishInitActivate(InterpState &S)
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 LoadPopL(InterpState &S, CodePtr OpPC)
Like LoadPop above, but if any of the checks fail, we turn the pointer into an opaque pointer of appr...
bool Dump(InterpState &S)
bool FinishInitPop(InterpState &S)
bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn)
T ReadArg(InterpState &S, CodePtr &OpPC)
bool CastFP(InterpState &S, const llvm::fltSemantics *Sem, llvm::RoundingMode RM)
1) Pops a Floating from the stack.
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 GetStringPtr(InterpState &S, const Expr *Base)
bool DiagTypeid(InterpState &S, CodePtr OpPC)
bool diagnoseUninitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
This is not used by any of the opcodes directly.
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK, bool WillBeActivated)
Checks if a value can be stored in a block.
bool InitGlobalTempComp(InterpState &S, const LifetimeExtendedTemporaryDecl *Temp)
1) Converts the value on top of the stack to an APValue 2) Sets that APValue on \Temp 3) Initialized ...
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 virtBaseHelper(InterpState &S, const CXXRecordDecl *Decl, const Pointer &Ptr)
bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS, unsigned Bits)
Checks if the shift operation is legal.
bool SetParam(InterpState &S, uint32_t I)
FixedPoint ReadArg< FixedPoint >(InterpState &S, CodePtr &OpPC)
bool IsNonNull(InterpState &S)
static bool CastFloatingFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS)
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED, const APSInt &Value)
@ BlockAddress
A pointer to an interp::Block.
@ AddrLabelDiff
Difference between two AddrLabelExpr.
@ Number
Just a number, nothing else.
@ ExprAddress
A pointer to an Expr.
@ Address
A pointer to a ValueDecl.
@ LabelAddress
A pointer to a AddrLabelExpr.
@ FunctionAddress
A pointer to a FunctionDecl.
bool LE(InterpState &S, CodePtr OpPC)
bool CheckNewTypeMismatchArray(InterpState &S, CodePtr OpPC, const Expr *E)
bool StartThisLifetime1(InterpState &S)
bool RVOPtr(InterpState &S)
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 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.
ComparisonCategoryResult Compare(const T &X, const T &Y)
Helper to compare two comparable types.
PrimType
Enumeration of the primitive types of the VM.
bool DecPopBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
bool StoreBitFieldPop(InterpState &S, CodePtr OpPC)
bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CanOverflow, UnsignedOrNone BitWidth=std::nullopt)
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
bool InvalidTargetLabel(InterpState &S, CodePtr OpPC, bool IsContinue)
static bool DecPtr(InterpState &S, CodePtr OpPC)
constexpr bool needsAlloc()
bool CastAPS(InterpState &S, uint32_t BitWidth)
bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index)
bool arrayElemPtr(InterpState &S, CodePtr OpPC, const Pointer &Ptr, const T &Offset)
static bool CastIntegralFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS)
bool Rem(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
bool ExpandPtr(InterpState &S)
bool NarrowPtr(InterpState &S)
bool InitGlobalTemp(InterpState &S, 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 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 Mulc(InterpState &S)
bool checkDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool diagnoseArrayIndex(InterpState &S, CodePtr OpPC, const APSInt &Index, std::optional< uint64_t > NumElems, bool IsArray)
bool AddrOf(InterpState &S, CodePtr OpPC)
bool InitThisBitField(InterpState &S, CodePtr OpPC, uint32_t FieldOffset, uint32_t FieldBitWidth)
bool GetOpaquePtr(InterpState &S, DeclOrExpr DOE, bool ConstexprUnknown)
bool SizelessVectorElementSize(InterpState &S, CodePtr OpPC)
static bool Activate(InterpState &S)
bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T)
bool SideEffect(InterpState &S)
bool BitAnd(InterpState &S)
1) Pops the RHS from the stack.
bool GetRefGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool EndInit(InterpState &S)
PRESERVE_NONE bool RetVoid(InterpState &S)
bool GetPtrThisField(InterpState &S, CodePtr OpPC, uint32_t Off)
bool Comp(InterpState &S)
1) Pops the value from the stack.
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 CheckFloatStatus(InterpState &S, CodePtr OpPC, APFloat::opStatus Status, FPOptions FPO)
Check if the given floating-point evaluation status is allowed for compile-time constant folding duri...
bool CastAP(InterpState &S, uint32_t BitWidth)
Like Cast(), but we cast to an arbitrary-bitwidth integral, so we need to know what bitwidth the resu...
bool GetPtrVirtBasePop(InterpState &S, CodePtr OpPC, const CXXRecordDecl *D)
bool IncBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, unsigned BitWidth)
bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off)
bool ReflectValue(InterpState &S, CodePtr OpPC, ReflectionKind Kind, const void *Operand)
bool StoreActivatePop(InterpState &S, CodePtr OpPC)
bool StartInit(InterpState &S)
bool DefaultInit(InterpState &S, CodePtr OpPC, const CXXConstructorDecl *Ctor)
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.
static bool ActivateThisField(InterpState &S, uint32_t I)
bool Const(InterpState &S, const T &Arg)
bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth, uint32_t FPOI)
bool StorePop(InterpState &S, CodePtr OpPC)
bool CheckIntegralAddressCast(InterpState &S, CodePtr OpPC, unsigned BitWidth)
bool InvalidStore(InterpState &S, CodePtr OpPC, const Type *T)
bool ConstFloat(InterpState &S, const Floating &F)
bool CheckPlacementNew(InterpState &S, CodePtr OpPC, const Expr *E)
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)
static bool IsConstantContext(InterpState &S)
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 ToMemberPtr(InterpState &S)
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 BitXor(InterpState &S)
1) Pops the RHS from the stack.
bool CheckPseudoDtor(InterpState &S, CodePtr OpPC)
bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm, bool IsGlobalDelete)
bool GetPtrVirtBase(InterpState &S, CodePtr OpPC, const CXXRecordDecl *D)
bool IsBaseClass(InterpState &S)
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 InitGlobal(InterpState &S, uint32_t I)
bool CheckArrayDestSize(InterpState &S, CodePtr OpPC, size_t NumElems)
Check if the destination array we're initializing can hold the NumElems elements.
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE, uint32_t BuiltinID)
bool CheckLocalLoad(InterpState &S, CodePtr OpPC, const Block *B)
bool Neg(InterpState &S, CodePtr OpPC)
bool DecayPtr(InterpState &S)
OldPtr -> Integer -> NewPtr.
bool CheckLoad(InterpState &S, CodePtr OpPC, PtrView Ptr, AccessKinds AK)
std::optional< Pointer > OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, const Pointer &Ptr, bool IsPointerArith=false)
bool FinishInit(InterpState &S)
llvm::function_ref< bool(ComparisonCategoryResult)> CompareFn
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 FinishInitGlobal(InterpState &S)
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 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 TrivialCopy(InterpState &S, CodePtr OpPC, bool Activate, const Function *Func)
bool CmpHelperEQ< Pointer >(InterpState &S, CodePtr OpPC, CompareFn Fn)
bool PushMSVCCE(InterpState &S)
bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth, uint32_t FPOI)
static bool CastFixedPointIntegral(InterpState &S, CodePtr OpPC)
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 PopMSVCCE(InterpState &S)
bool CastFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS)
bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc, bool IsNoThrow)
bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I)
bool StartFieldInit(InterpState &S, uint32_t FieldOffset)
bool Subf(InterpState &S, CodePtr OpPC, uint32_t FPOI)
bool GetMemberPtr(InterpState &S, const ValueDecl *D)
bool CastMemberPtrBasePop(InterpState &S, int32_t Off, const RecordDecl *BaseDecl)
DerivedToBaseMemberPointer.
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 IncPopBitfield(InterpState &S, CodePtr OpPC, bool CanOverflow, uint32_t BitWidth)
bool CMP3(InterpState &S, CodePtr OpPC, const ComparisonCategoryInfo *CmpInfo)
bool GetPtrThisVirtBase(InterpState &S, CodePtr OpPC, const CXXRecordDecl *D)
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 PopCC(InterpState &S)
bool GetPtrThisBase(InterpState &S, CodePtr OpPC, uint32_t Off)
bool GetParam(InterpState &S, uint32_t Index)
bool GetPtrGlobal(InterpState &S, uint32_t I)
bool FinishInitActivatePop(InterpState &S)
bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestTypePtr, bool IsReferenceCast)
bool IncDecFloatHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr, uint32_t FPOI)
bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source, bool IsNoThrow)
bool CheckEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED)
static bool ZeroIntAP(InterpState &S, uint32_t BitWidth)
Top level wrappers for InstallAPI frontend operations.
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
const FunctionProtoType * T
@ Off
Never emit colors regardless of the output stream.
@ ConstantFold
Fold the expression to a constant.
U cast(CodeGen::Address addr)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
bool DiagEmitted
Whether any diagnostic has been emitted.
size_t getQuantity() const
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.
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.
const VarDecl * asVarDecl() const
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
OpaquePointer withFieldType(const Type *FieldTy, std::optional< bool > PastEnd=std::nullopt) const
llvm::PointerIntPair< const Type *, 2, unsigned > FieldType
const PointerPathEntry * Path
QualType getFieldType() const
bool isOnePastEnd() const
bool isUnknownSizeArray() const
OpaquePointer withPath(const PointerPathEntry *Path, unsigned PathLength, const Type *FieldTy, std::optional< bool > PastEnd=std::nullopt) const
Mapping from primitive types to their representation.
PtrView atField(unsigned Offset) const
PtrView atIndex(unsigned Idx) const