21#include "llvm/Support/SaveAndRestore.h"
32 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
33 CE && CE->hasAPValueResult() &&
35 return CE->getResultAsAPSInt().getBoolValue();
57 if (NumElems > std::numeric_limits<unsigned>::max())
59 uint64_t Limit = LangOpts.ConstexprStepLimit;
60 return Limit != 0 && NumElems > Limit;
76 llvm_unreachable(
"Shouldn't be called");
142 this->
Ctx->emitDestroy(*
Idx, E);
149 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
150 this->
Ctx->Descriptors.emplace_back();
152 if constexpr (!std::is_same_v<Emitter, EvalEmitter>)
153 this->
Ctx->emitInitScope(*
Idx, {});
167 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
168 this->
Ctx->Descriptors.emplace_back();
169 if constexpr (!std::is_same_v<Emitter, EvalEmitter>)
170 this->
Ctx->emitInitScope(*
Idx, {});
181 if (
Local.Desc->hasTrivialDtor())
184 if (!
Local.EnabledByDefault) {
185 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
186 if (!this->
Ctx->emitGetLocalEnabled(
Local.Offset, E))
188 if (!this->
Ctx->jumpFalse(EndLabel, E))
191 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
194 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
197 this->
Ctx->fallthrough(EndLabel);
198 this->
Ctx->emitLabel(EndLabel);
200 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
202 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
221 if (
const auto *OVE =
222 llvm::dyn_cast_if_present<OpaqueValueExpr>(
Local.Desc->asExpr())) {
223 this->
Ctx->OpaqueExprs.erase(OVE);
235 OldArrayIndex = Ctx->ArrayIndex;
236 Ctx->ArrayIndex = Index;
243 std::optional<uint64_t> OldArrayIndex;
251 if (!Ctx->SourceLocDefaultExpr) {
253 Ctx->SourceLocDefaultExpr = DefaultExpr;
259 Ctx->SourceLocDefaultExpr =
nullptr;
264 bool Enabled =
false;
270 Ctx->InitStack.push_back(std::move(
Link));
282 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
285 Ctx->InitStackActive = OldValue || Active;
291 this->Ctx->InitStackActive = OldValue;
293 Ctx->InitStack.pop_back();
307 OldInitializingDecl(
Ctx->InitializingDecl) {
308 Ctx->InitializingDecl = VD;
313 this->
Ctx->InitializingDecl = OldInitializingDecl;
314 this->
Ctx->InitStack.pop_back();
319 const VarDecl *OldInitializingDecl;
327 bool NewInitializing,
bool NewToLValue)
328 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
329 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
330 Ctx->DiscardResult = NewDiscardResult;
331 Ctx->Initializing = NewInitializing;
332 Ctx->ToLValue = NewToLValue;
336 Ctx->DiscardResult = OldDiscardResult;
337 Ctx->Initializing = OldInitializing;
338 Ctx->ToLValue = OldToLValue;
345 bool OldDiscardResult;
346 bool OldInitializing;
350template <
class Emitter>
354 return Ctx->emitThis(E);
357 return Ctx->emitGetPtrFieldPop(
Offset, E);
359 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
361 return Ctx->emitGetPtrLocal(
Offset, E);
365 if (!Ctx->emitConstUint32(
Offset, E))
367 return Ctx->emitArrayElemPtrPopUint32(E);
369 return Ctx->emitRVOPtr(E);
373 llvm_unreachable(
"Unhandled InitLink kind");
389 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
390 assert(LI.Name != Name);
393 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
414 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
416 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
417 assert(LI.Name != Name);
420 this->Ctx->CaseLabels = std::move(CaseLabels);
421 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
423 DefaultLabel, Ctx->VarScope);
427 this->Ctx->CaseLabels = std::move(OldCaseLabels);
428 this->Ctx->LabelInfoStack.pop_back();
433 CaseMap OldCaseLabels;
444 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
447 Ctx->LocOverride = NewValue;
452 Ctx->LocOverride = OldFlag;
457 std::optional<SourceInfo> OldFlag;
464template <
class Emitter>
472 case CK_LValueToRValue: {
480 if (!this->
visit(SubExpr))
482 return this->emitLoadPopL(E);
492 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
498 if (
auto GlobalIndex =
P.getGlobal(D))
499 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
500 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
501 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
502 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
503 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
504 return this->emitGetParam(*SubExprT, It->second.Index, E);
516 if (!this->emitGetPtrLocal(*LocalIndex, E))
520 if (!this->
visit(SubExpr))
524 return this->emitLoadPop(*SubExprT, E);
529 return this->emitMemcpy(E);
532 case CK_DerivedToBaseMemberPointer: {
543 ->getMostRecentCXXRecordDecl();
545 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
546 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
548 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
556 case CK_BaseToDerivedMemberPointer: {
567 ->getMostRecentCXXRecordDecl();
571 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
573 PathI != PathE; ++PathI) {
574 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
575 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
577 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
584 assert(ToDecl != CurDecl);
585 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
587 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
593 case CK_UncheckedDerivedToBase:
594 case CK_DerivedToBase: {
599 if (
const auto *PT = dyn_cast<PointerType>(Ty))
600 return PT->getPointeeType()->getAsCXXRecordDecl();
601 return Ty->getAsCXXRecordDecl();
608 if (B->isVirtual()) {
609 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
611 CurType = B->getType();
613 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
614 if (!this->emitGetPtrBasePop(
617 CurType = B->getType();
624 case CK_BaseToDerived: {
627 unsigned DerivedOffset =
633 return this->emitGetPtrDerivedPop(DerivedOffset,
638 case CK_FloatingCast: {
641 return this->emitVectorConversion(E->
getSubExpr(), E);
645 if (!this->
visit(SubExpr))
647 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
651 case CK_IntegralToFloating: {
653 return this->emitVectorConversion(E->
getSubExpr(), E);
656 if (!this->
visit(SubExpr))
658 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
659 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
660 TargetSemantics, getFPOptions(E), E);
663 case CK_FloatingToBoolean: {
665 return this->emitVectorConversion(E->
getSubExpr(), E);
669 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
670 return this->emitConstBool(FL->getValue().isNonZero(), E);
671 if (!this->
visit(SubExpr))
673 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
676 case CK_FloatingToIntegral: {
678 return this->emitVectorConversion(E->
getSubExpr(), E);
681 if (!this->
visit(SubExpr))
685 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
688 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
691 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
694 case CK_NullToPointer:
695 case CK_NullToMemberPointer: {
698 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
703 case CK_PointerToIntegral: {
704 if (!this->
visit(SubExpr))
710 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
716 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
718 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
719 return this->emitCastPointerIntegral(
T, E);
722 case CK_ArrayToPointerDecay: {
723 if (!this->
visit(SubExpr))
725 return this->emitArrayDecay(E);
728 case CK_IntegralToPointer: {
730 assert(IntType->isIntegralOrEnumerationType());
731 if (!this->
visit(SubExpr))
745 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
748 case CK_AtomicToNonAtomic:
749 case CK_ConstructorConversion:
750 case CK_FunctionToPointerDecay:
751 case CK_NonAtomicToAtomic:
753 case CK_UserDefinedConversion:
754 case CK_CPointerToObjCPointerCast:
757 case CK_AddressSpaceConversion: {
761 if (!this->
visit(SubExpr))
766 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
773 return this->emitPopPtr(E);
791 return this->emitBuiltinBitCast(E);
806 if (!this->
visit(SubExpr))
814 return this->emitFnPtrCast(E);
822 if (!this->
visit(SubExpr))
824 return this->emitDecayPtr(*FromT, *ToT, E);
826 case CK_IntegralToBoolean:
827 case CK_FixedPointToBoolean: {
829 return this->emitVectorConversion(E->
getSubExpr(), E);
835 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
836 return this->emitConst(IL->getValue(), E);
837 if (!this->
visit(SubExpr))
842 case CK_IntegralCast:
844 return this->emitVectorConversion(E->
getSubExpr(), E);
846 case CK_BooleanToSignedIntegral: {
853 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
858 if (!this->emitConst(IL->getValue(), SubExpr))
861 if (!this->
visit(SubExpr))
869 if (!ED->isFixed()) {
870 if (!this->emitCheckEnumValue(*FromT, ED, E))
876 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
879 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
884 if (!this->emitCast(*FromT, *ToT, E))
887 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
888 return this->emitNeg(*ToT, E);
892 case CK_PointerToBoolean:
893 if (!this->
visit(SubExpr))
895 return this->emitIsNonNullPtr(E);
897 case CK_MemberPointerToBoolean:
898 if (!this->
visit(SubExpr))
900 return this->emitIsNonNullMemberPtr(E);
902 case CK_IntegralComplexToBoolean:
903 case CK_FloatingComplexToBoolean: {
904 if (!this->
visit(SubExpr))
906 return this->emitComplexBoolCast(SubExpr);
909 case CK_IntegralComplexToReal:
910 case CK_FloatingComplexToReal:
911 return this->emitComplexReal(SubExpr);
913 case CK_IntegralRealToComplex:
914 case CK_FloatingRealToComplex: {
921 if (!this->emitGetPtrLocal(*LocalIndex, E))
930 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
932 return this->emitInitElem(
T, 1, SubExpr);
935 case CK_IntegralComplexCast:
936 case CK_FloatingComplexCast:
937 case CK_IntegralComplexToFloatingComplex:
938 case CK_FloatingComplexToIntegralComplex: {
945 if (!this->emitGetPtrLocal(*LocalIndex, E))
952 unsigned SubExprOffset =
954 if (!this->
visit(SubExpr))
956 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
964 for (
unsigned I = 0; I != 2; ++I) {
965 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
967 if (!this->emitArrayElemPop(SourceElemT, I, E))
971 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
975 if (!this->emitInitElem(DestElemT, I, E))
981 case CK_VectorSplat: {
992 if (!this->emitGetPtrLocal(*LocalIndex, E))
998 unsigned ElemOffset =
1002 if (!this->
visit(SubExpr))
1007 if (!this->emitSetLocal(ElemT, ElemOffset, E))
1010 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
1011 if (!this->emitGetLocal(ElemT, ElemOffset, E))
1013 if (!this->emitInitElem(ElemT, I, E))
1020 case CK_HLSLVectorTruncation: {
1025 if (!this->
visit(SubExpr))
1027 return this->emitArrayElemPop(*ResultT, 0, E);
1036 if (!this->emitGetPtrLocal(*LocalIndex, E))
1041 if (!this->
visit(SubExpr))
1043 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1047 case CK_IntegralToFixedPoint: {
1048 if (!this->
visit(SubExpr))
1052 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1057 return this->emitPopFixedPoint(E);
1060 case CK_FloatingToFixedPoint: {
1061 if (!this->
visit(SubExpr))
1065 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1066 if (!this->emitCastFloatingFixedPoint(Sem, E))
1069 return this->emitPopFixedPoint(E);
1072 case CK_FixedPointToFloating: {
1073 if (!this->
visit(SubExpr))
1075 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1076 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1079 return this->emitPopFloat(E);
1082 case CK_FixedPointToIntegral: {
1083 if (!this->
visit(SubExpr))
1086 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1089 return this->emitPop(IntegralT, E);
1092 case CK_FixedPointCast: {
1093 if (!this->
visit(SubExpr))
1096 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1097 if (!this->emitCastFixedPoint(Sem, E))
1100 return this->emitPopFixedPoint(E);
1108 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1110 case CK_LValueBitCast:
1115 case CK_HLSLArrayRValue: {
1122 if (!this->emitGetPtrLocal(*LocalIndex, E))
1125 if (!this->
visit(SubExpr))
1127 return this->emitMemcpy(E);
1130 case CK_HLSLMatrixTruncation: {
1135 if (!this->
visit(SubExpr))
1137 return this->emitArrayElemPop(*ResultT, 0, E);
1146 if (!this->emitGetPtrLocal(*LocalIndex, E))
1151 if (!this->
visit(SubExpr))
1153 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1157 case CK_HLSLAggregateSplatCast: {
1167 if (!this->emitGetPtrLocal(*LocalIndex, E))
1174 unsigned SrcOffset =
1177 if (!this->
visit(SubExpr))
1179 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1183 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1186 case CK_HLSLElementwiseCast: {
1197 unsigned SrcPtrOffset =
1199 if (!this->
visit(SubExpr))
1201 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1205 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1207 if (Elements.empty())
1210 const HLSLFlatElement &Src = Elements[0];
1211 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1213 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1220 if (!this->emitGetPtrLocal(*LocalIndex, E))
1224 unsigned SrcOffset =
1226 if (!this->
visit(SubExpr))
1228 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1232 unsigned ElemCount = countHLSLFlatElements(DestType);
1235 Elements.reserve(ElemCount);
1236 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1241 assert(Elements.size() == ElemCount &&
1242 "Source type has fewer scalar elements than the destination type");
1244 return emitHLSLConstructAggregate(DestType, Elements, E);
1251 const Record::Field *RF = R->getField(UnionField);
1254 if (!this->
visit(SubExpr))
1256 if (RF->isBitField())
1257 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1259 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1262 if (!this->emitGetPtrField(RF->Offset, E))
1264 if (!this->emitActivate(E))
1270 return this->emitInvalid(E);
1272 llvm_unreachable(
"Unhandled clang::CastKind enum");
1275template <
class Emitter>
1277 return this->emitBuiltinBitCast(E);
1280template <
class Emitter>
1285 return this->emitConst(
LE->getValue(),
LE);
1288template <
class Emitter>
1294 return this->emitFloat(F, E);
1297template <
class Emitter>
1307 if (!this->emitGetPtrLocal(*LocalIndex, E))
1314 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1316 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1321template <
class Emitter>
1329 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1334template <
class Emitter>
1339template <
class Emitter>
1366 return this->emitComplexComparison(LHS, RHS, E);
1374 if (!this->
visit(LHS))
1377 if (!this->
visit(RHS))
1380 if (!this->emitToMemberPtr(E))
1386 if (!this->emitCastMemberPtrPtr(E))
1403 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1409 if (!this->emitGetPtrLocal(*ResultIndex, E))
1416 return this->emitCMP3(*
LT, CmpInfo, E);
1419 if (!
LT || !RT || !
T)
1429 return this->visitAssignment(LHS, RHS, E);
1436 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1440 return this->emitPopBool(E);
1442 return this->emitCast(
PT_Bool, *
T, E);
1446 auto Discard = [
this,
T, E](
bool Result) {
1454 return MaybeCastToBool(this->emitEQ(*
LT, E));
1456 return MaybeCastToBool(this->emitNE(*
LT, E));
1458 return MaybeCastToBool(this->emitLT(*
LT, E));
1460 return MaybeCastToBool(this->emitLE(*
LT, E));
1462 return MaybeCastToBool(this->emitGT(*
LT, E));
1464 return MaybeCastToBool(this->emitGE(*
LT, E));
1467 return Discard(this->emitSubf(getFPOptions(E), E));
1468 return Discard(this->emitSub(*
T, E));
1471 return Discard(this->emitAddf(getFPOptions(E), E));
1472 return Discard(this->emitAdd(*
T, E));
1475 return Discard(this->emitMulf(getFPOptions(E), E));
1476 return Discard(this->emitMul(*
T, E));
1478 return Discard(this->emitRem(*
T, E));
1481 return Discard(this->emitDivf(getFPOptions(E), E));
1482 return Discard(this->emitDiv(*
T, E));
1484 return Discard(this->emitBitAnd(*
T, E));
1486 return Discard(this->emitBitOr(*
T, E));
1488 return Discard(this->emitShl(*
LT, *RT, E));
1490 return Discard(this->emitShr(*
LT, *RT, E));
1492 return Discard(this->emitBitXor(*
T, E));
1495 llvm_unreachable(
"Already handled earlier");
1500 llvm_unreachable(
"Unhandled binary op");
1505template <
class Emitter>
1511 if ((Op != BO_Add && Op != BO_Sub) ||
1522 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1523 if (!this->
visit(E))
1526 return this->emitDecayPtr(
T,
PT_Ptr, E);
1535 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1543 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1546 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1553 if (!visitAsPointer(RHS, *RT))
1555 if (!this->
visit(LHS))
1559 if (!visitAsPointer(LHS, *
LT))
1561 if (!this->
visit(RHS))
1572 if (!this->emitAddOffset(OffsetType, E))
1576 if (!this->emitSubOffset(OffsetType, E))
1585 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1590 return this->emitPop(ExprT, E);
1594template <
class Emitter>
1603 LabelTy LabelTrue = this->getLabel();
1604 LabelTy LabelEnd = this->getLabel();
1608 if (!this->jumpTrue(LabelTrue, E))
1613 if (!this->jump(LabelEnd, E))
1616 this->emitLabel(LabelTrue);
1617 this->emitConstBool(
true, E);
1618 this->fallthrough(LabelEnd);
1619 this->emitLabel(LabelEnd);
1622 assert(Op == BO_LAnd);
1625 LabelTy LabelFalse = this->getLabel();
1626 LabelTy LabelEnd = this->getLabel();
1630 if (!this->jumpFalse(LabelFalse, E))
1635 if (!this->jump(LabelEnd, E))
1638 this->emitLabel(LabelFalse);
1639 this->emitConstBool(
false, E);
1640 this->fallthrough(LabelEnd);
1641 this->emitLabel(LabelEnd);
1645 return this->emitPopBool(E);
1650 return this->emitCast(
PT_Bool,
T, E);
1655template <
class Emitter>
1662 if (!this->emitGetPtrLocal(*LocalIndex, E))
1671 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1672 unsigned ResultOffset = ~0u;
1678 if (!this->emitDupPtr(E))
1680 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1685 LHSType = AT->getValueType();
1688 RHSType = AT->getValueType();
1697 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1702 if (!this->
visit(LHS))
1704 if (!this->
visit(RHS))
1706 if (!this->emitMulc(ElemT, E))
1709 return this->emitPopPtr(E);
1713 if (Op == BO_Div && RHSIsComplex) {
1720 if (!LHSIsComplex) {
1725 LHSOffset = *LocalIndex;
1727 if (!this->emitGetPtrLocal(LHSOffset, E))
1730 if (!this->
visit(LHS))
1733 if (!this->emitInitElem(ElemT, 0, E))
1736 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1738 if (!this->emitInitElem(ElemT, 1, E))
1741 if (!this->
visit(LHS))
1745 if (!this->
visit(RHS))
1747 if (!this->emitDivc(ElemT, E))
1750 return this->emitPopPtr(E);
1757 if (!this->
visit(LHS))
1759 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1764 if (!this->
visit(LHS))
1766 if (!this->emitSetLocal(LHST, LHSOffset, E))
1774 if (!this->
visit(RHS))
1776 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1781 if (!this->
visit(RHS))
1783 if (!this->emitSetLocal(RHST, RHSOffset, E))
1790 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1791 unsigned ElemIndex,
unsigned Offset,
1792 const Expr *E) ->
bool {
1794 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1796 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1799 if (ElemIndex == 0 || !LoadZero)
1806 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1809 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1816 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1819 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1822 if (!this->emitAddf(getFPOptions(E), E))
1825 if (!this->emitAdd(ResultElemT, E))
1830 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1833 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1836 if (!this->emitSubf(getFPOptions(E), E))
1839 if (!this->emitSub(ResultElemT, E))
1844 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1847 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1851 if (!this->emitMulf(getFPOptions(E), E))
1854 if (!this->emitMul(ResultElemT, E))
1859 assert(!RHSIsComplex);
1860 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1863 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1867 if (!this->emitDivf(getFPOptions(E), E))
1870 if (!this->emitDiv(ResultElemT, E))
1881 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1884 if (!this->emitPop(ResultElemT, E))
1889 return this->emitPopPtr(E);
1895template <
class Emitter>
1900 "Comma op should be handled in VisitBinaryOperator");
1904 LHSType = AT->getValueType();
1907 RHSType = AT->getValueType();
1921 if (!this->emitGetPtrLocal(*LocalIndex, E))
1930 PrimType ElemT = this->classifyVectorElementType(LHSType);
1931 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1935 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1938 if (!this->
visit(LHS))
1940 if (!this->
visit(RHS))
1942 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1945 return this->emitPopPtr(E);
1950 unsigned LHSOffset =
1952 if (!this->
visit(LHS))
1954 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1958 unsigned RHSOffset =
1960 if (!this->
visit(RHS))
1962 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1974 if (NeedIntPromot) {
1976 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1981 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1982 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1984 if (!this->emitArrayElemPop(ElemT, Index, E))
1987 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1989 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1991 }
else if (NeedIntPromot) {
1992 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1998#define EMIT_ARITH_OP(OP) \
2000 if (ElemT == PT_Float) { \
2001 if (!this->emit##OP##f(getFPOptions(E), E)) \
2004 if (!this->emit##OP(ElemT, E)) \
2010 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
2011 if (!getElem(LHSOffset, ElemT, I))
2013 if (!getElem(RHSOffset, RHSElemT, I))
2025 if (!this->emitRem(ElemT, E))
2029 if (!this->emitBitAnd(OpT, E))
2033 if (!this->emitBitOr(OpT, E))
2037 if (!this->emitBitXor(OpT, E))
2041 if (!this->emitShl(OpT, RHSElemT, E))
2045 if (!this->emitShr(OpT, RHSElemT, E))
2049 if (!this->emitEQ(ElemT, E))
2053 if (!this->emitNE(ElemT, E))
2057 if (!this->emitLE(ElemT, E))
2061 if (!this->emitLT(ElemT, E))
2065 if (!this->emitGE(ElemT, E))
2069 if (!this->emitGT(ElemT, E))
2074 if (!this->emitBitAnd(ResultElemT, E))
2079 if (!this->emitBitOr(ResultElemT, E))
2083 return this->emitInvalid(E);
2092 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2094 if (!this->emitNeg(ResultElemT, E))
2100 if (NeedIntPromot &&
2101 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2105 if (!this->emitInitElem(ResultElemT, I, E))
2114template <
class Emitter>
2124 auto LHSSemaInt = LHSSema.toOpaqueInt();
2126 auto RHSSemaInt = RHSSema.toOpaqueInt();
2128 if (!this->
visit(LHS))
2136 if (!this->
visit(RHS))
2145 auto ConvertResult = [&](
bool R) ->
bool {
2149 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2150 if (ResultSema != CommonSema)
2151 return this->emitCastFixedPoint(ResultSema, E);
2155 auto MaybeCastToBool = [&](
bool Result) {
2160 return this->emitPop(
T, E);
2162 return this->emitCast(
PT_Bool,
T, E);
2168 return MaybeCastToBool(this->emitEQFixedPoint(E));
2170 return MaybeCastToBool(this->emitNEFixedPoint(E));
2172 return MaybeCastToBool(this->emitLTFixedPoint(E));
2174 return MaybeCastToBool(this->emitLEFixedPoint(E));
2176 return MaybeCastToBool(this->emitGTFixedPoint(E));
2178 return MaybeCastToBool(this->emitGEFixedPoint(E));
2180 return ConvertResult(this->emitAddFixedPoint(E));
2182 return ConvertResult(this->emitSubFixedPoint(E));
2184 return ConvertResult(this->emitMulFixedPoint(E));
2186 return ConvertResult(this->emitDivFixedPoint(E));
2188 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2190 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2193 return this->emitInvalid(E);
2196 llvm_unreachable(
"unhandled binop opcode");
2199template <
class Emitter>
2208 if (!this->
visit(SubExpr))
2210 if (!this->emitNegFixedPoint(E))
2213 return this->emitPopFixedPoint(E);
2219 llvm_unreachable(
"Unhandled unary opcode");
2222template <
class Emitter>
2231 return this->visitZeroInitializer(*
T, QT, E);
2244 return this->visitZeroRecordInitializer(R, E);
2251 return this->visitZeroArrayInitializer(QT, E);
2255 QualType ElemQT = ComplexTy->getElementType();
2257 for (
unsigned I = 0; I < 2; ++I) {
2258 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2260 if (!this->emitInitElem(ElemT, I, E))
2267 unsigned NumVecElements = VecT->getNumElements();
2268 QualType ElemQT = VecT->getElementType();
2271 for (
unsigned I = 0; I < NumVecElements; ++I) {
2272 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2274 if (!this->emitInitElem(ElemT, I, E))
2281 unsigned NumElems = MT->getNumElementsFlattened();
2282 QualType ElemQT = MT->getElementType();
2285 for (
unsigned I = 0; I != NumElems; ++I) {
2286 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2288 if (!this->emitInitElem(ElemT, I, E))
2297template <
class Emitter>
2310 for (
const Expr *SubExpr : {LHS, RHS}) {
2311 if (!this->
visit(SubExpr)) {
2318 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2319 if (!this->emitExpandPtr(E))
2330 return this->emitError(E);
2333 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2337 if (!this->emitArrayElemPtrPop(*IndexT, E))
2340 return this->emitPopPtr(E);
2346 return this->emitLoadPop(*
T, E);
2349template <
class Emitter>
2351 const Expr *ArrayFiller,
const Expr *E) {
2356 QT = AT->getValueType();
2359 if (
Inits.size() == 0)
2361 return this->emitInvalid(E);
2374 if (
Inits.size() == 0)
2375 return this->visitZeroInitializer(*
T, QT, E);
2376 assert(
Inits.size() == 1);
2390 if (!this->emitGetPtrLocal(*LocalIndex, E))
2405 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2411 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2420 bool BitField = FieldToInit->isBitField();
2422 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2423 FieldToInit->bitWidth(), E);
2425 return this->emitInitBitField(
T, FieldToInit->Offset,
2426 FieldToInit->bitWidth(), E);
2428 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2429 return this->emitInitField(
T, FieldToInit->Offset, E);
2432 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2440 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2443 if (
Activate && !this->emitActivate(E))
2446 if (!this->emitStartInit(
Init))
2453 if (
Inits.size() == 0) {
2454 if (!this->visitZeroRecordInitializer(R, E))
2459 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2460 FToInit = ILE->getInitializedFieldInUnion();
2464 const Record::Field *FieldToInit = R->getField(FToInit);
2466 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2469 if (!initCompositeField(FieldToInit,
Init,
true))
2473 return this->emitFinishInit(E);
2476 assert(!R->isUnion());
2477 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2479 const Record::Base *B = R->getBase(BI);
2482 if (!this->emitGetPtrBase(B->Offset,
Init))
2488 unsigned FieldIndex = 0;
2489 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2490 const Record::Field *FieldToInit = R->getField(FieldIndex);
2491 if (FieldToInit->isUnnamedBitField()) {
2506 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2508 }
else if (!initCompositeField(FieldToInit,
Init)) {
2516 assert(R->getNumVirtualBases() == 0);
2518 return this->emitFinishInit(E);
2523 Ctx.getASTContext().getAsConstantArrayType(QT);
2528 !this->emitCheckArrayDestSize(NumElems, E))
2531 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2535 unsigned ElementIndex = 0;
2537 if (
const auto *EmbedS =
2538 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2546 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2547 getFPOptions(E), E))
2553 return this->emitInitElem(TargetT, ElemIndex, IL);
2555 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2571 for (; ElementIndex != NumElems; ++ElementIndex) {
2577 return this->emitFinishInit(E);
2581 unsigned NumInits =
Inits.size();
2586 QualType ElemQT = ComplexTy->getElementType();
2588 if (NumInits == 0) {
2590 for (
unsigned I = 0; I < 2; ++I) {
2591 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2593 if (!this->emitInitElem(ElemT, I, E))
2596 }
else if (NumInits == 2) {
2597 unsigned InitIndex = 0;
2602 if (!this->emitInitElem(ElemT, InitIndex, E))
2611 unsigned NumVecElements = VecT->getNumElements();
2612 assert(NumVecElements >=
Inits.size());
2614 QualType ElemQT = VecT->getElementType();
2618 unsigned InitIndex = 0;
2625 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2626 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2627 InitVecT->getNumElements(), E))
2629 InitIndex += InitVecT->getNumElements();
2631 if (!this->emitInitElem(ElemT, InitIndex, E))
2637 assert(InitIndex <= NumVecElements);
2640 for (; InitIndex != NumVecElements; ++InitIndex) {
2641 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2643 if (!this->emitInitElem(ElemT, InitIndex, E))
2650 unsigned NumElems = MT->getNumElementsFlattened();
2651 assert(
Inits.size() == NumElems);
2653 QualType ElemQT = MT->getElementType();
2659 for (
unsigned I = 0; I != NumElems; ++I) {
2662 if (!this->emitInitElem(ElemT, I, E))
2673template <
class Emitter>
2680 return this->emitInitElem(*InitT, ElemIndex,
Init);
2686 if (!this->emitConstUint32(ElemIndex,
Init))
2688 if (!this->emitArrayElemPtrUint32(
Init))
2693template <
class Emitter>
2696 bool Activate,
bool IsOperatorCall) {
2698 llvm::BitVector NonNullArgs;
2699 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2702 bool ExplicitMemberFn =
false;
2703 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2704 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2706 unsigned ArgIndex = 0;
2707 for (
const Expr *Arg : Args) {
2709 if (!this->
visit(Arg))
2717 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2718 if (DeclIndex < FuncDecl->getNumParams())
2719 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2728 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2736 if (!this->emitActivate(Arg))
2740 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2743 if (!this->emitCheckNonNullArg(ArgT, Arg))
2754template <
class Emitter>
2759template <
class Emitter>
2765template <
class Emitter>
2771template <
class Emitter>
2789template <
class Emitter>
2791 auto It = E->
begin();
2792 return this->
visit(*It);
2796 UnaryExprOrTypeTrait Kind) {
2797 bool AlignOfReturnsPreferred =
2804 T = Ref->getPointeeType();
2806 if (
T.getQualifiers().hasUnaligned())
2812 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2818template <
class Emitter>
2822 UnaryExprOrTypeTrait Kind = E->
getKind();
2825 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2831 ArgType = Ref->getPointeeType();
2837 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2838 return this->emitInvalid(E);
2840 if (Kind == UETT_SizeOf)
2849 return this->emitConst(Size.getQuantity(), E);
2852 if (Kind == UETT_CountOf) {
2858 if (
const auto *CAT =
2862 return this->emitConst(CAT->getSize(), E);
2872 if (VAT->getElementType()->isArrayType()) {
2873 std::optional<APSInt> Res =
2875 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2880 return this->emitConst(*Res, E);
2885 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2905 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2908 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2918 return this->emitConst(Size.getQuantity(), E);
2921 if (Kind == UETT_VectorElements) {
2926 return this->emitConst(VT->getNumElements(), E);
2928 return this->emitSizelessVectorElementSize(E);
2931 if (Kind == UETT_VecStep) {
2933 unsigned N = VT->getNumElements();
2940 return this->emitConst(N, E);
2942 return this->emitConst(1, E);
2945 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2954 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2956 return this->emitInvalid(E);
2958 return this->emitConst(
2967template <
class Emitter>
2976 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2981 if (VD->getInit() && !VD->getInit()->isValueDependent())
2982 VD->evaluateValue();
2983 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2984 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2986 if (
Member->getType()->isReferenceType())
2987 return this->emitLoadPopPtr(E);
2996 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2997 MD && !MD->isStatic()) {
3001 if (!this->
discard(Base) && !this->emitSideEffect(E))
3016 const Record::Field *F = R->getField(FD);
3020 const auto maybeLoadValue = [&]() ->
bool {
3024 return this->emitLoadPop(*
T, E);
3029 if (F->Decl->getType()->isReferenceType())
3030 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3031 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3034template <
class Emitter>
3044template <
class Emitter>
3054 return this->emitCheckArraySize(Size, E);
3060 if (!this->
visit(Common))
3062 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3076 for (
size_t I = 0; I != Size; ++I) {
3088template <
class Emitter>
3103 return this->emitGetLocal(SubExprT, It->second, E);
3106 if (!this->
visit(SourceExpr))
3113 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3122 return this->emitGetLocal(SubExprT, LocalIndex, E);
3126template <
class Emitter>
3139 bool IsBcpCall =
false;
3140 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3141 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3145 LabelTy LabelEnd = this->getLabel();
3146 LabelTy LabelFalse = this->getLabel();
3149 if (!this->emitPushIgnoreDiags(E))
3157 if (this->checkingForUndefinedBehavior()) {
3160 if (!this->
discard(FalseExpr))
3177 if (!this->jumpFalse(LabelFalse, E))
3182 if (!this->jump(LabelEnd, E))
3184 this->emitLabel(LabelFalse);
3188 this->fallthrough(LabelEnd);
3189 this->emitLabel(LabelEnd);
3192 return this->emitPopIgnoreDiags(E);
3196template <
class Emitter>
3202 return this->emitGetStringPtr(E, E);
3206 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3207 assert(CAT &&
"a string literal that's not a constant array?");
3212 unsigned N = std::min(ArraySize, E->
getLength());
3215 for (
unsigned I = 0; I != N; ++I) {
3218 if (CharWidth == 1) {
3219 this->emitConstSint8(CodeUnit, E);
3220 this->emitInitElemSint8(I, E);
3221 }
else if (CharWidth == 2) {
3222 this->emitConstUint16(CodeUnit, E);
3223 this->emitInitElemUint16(I, E);
3224 }
else if (CharWidth == 4) {
3225 this->emitConstUint32(CodeUnit, E);
3226 this->emitInitElemUint32(I, E);
3228 llvm_unreachable(
"unsupported character width");
3233 for (
unsigned I = N; I != ArraySize; ++I) {
3234 if (CharWidth == 1) {
3235 this->emitConstSint8(0, E);
3236 this->emitInitElemSint8(I, E);
3237 }
else if (CharWidth == 2) {
3238 this->emitConstUint16(0, E);
3239 this->emitInitElemUint16(I, E);
3240 }
else if (CharWidth == 4) {
3241 this->emitConstUint32(0, E);
3242 this->emitInitElemUint32(I, E);
3244 llvm_unreachable(
"unsupported character width");
3251template <
class Emitter>
3255 return this->emitDummyPtr(E, E);
3258template <
class Emitter>
3260 auto &A =
Ctx.getASTContext();
3269template <
class Emitter>
3277 auto &A =
Ctx.getASTContext();
3281 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3282 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3288 return this->emitGetStringPtr(SL, E);
3291template <
class Emitter>
3295 return this->emitConst(E->
getValue(), E);
3298template <
class Emitter>
3320 if (!this->emitLoad(LHST, E))
3323 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3324 LHSComputationType, E))
3336 unsigned TempOffset =
3338 if (!this->emitSetLocal(*RT, TempOffset, E))
3344 if (!this->emitLoad(LHST, E))
3348 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3349 LHSComputationType, E))
3353 if (!this->emitGetLocal(*RT, TempOffset, E))
3359 if (!this->emitAddf(getFPOptions(E), E))
3363 if (!this->emitSubf(getFPOptions(E), E))
3367 if (!this->emitMulf(getFPOptions(E), E))
3371 if (!this->emitDivf(getFPOptions(E), E))
3382 return this->emitStorePop(LHST, E);
3383 return this->emitStore(LHST, E);
3386template <
class Emitter>
3395 if (Op != BO_AddAssign && Op != BO_SubAssign)
3404 if (!this->emitLoad(*
LT, LHS))
3410 if (Op == BO_AddAssign) {
3411 if (!this->emitAddOffset(*RT, E))
3414 if (!this->emitSubOffset(*RT, E))
3419 return this->emitStorePopPtr(E);
3420 return this->emitStorePtr(E);
3423template <
class Emitter>
3436 if (!
Ctx.getLangOpts().CPlusPlus14)
3437 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3439 if (!
LT || !RT || !ResultT || !LHSComputationT)
3456 if (!this->emitLoad(*
LT, E))
3458 if (
LT != LHSComputationT &&
3459 !this->emitIntegralCast(*
LT, *LHSComputationT,
3473 unsigned TempOffset =
3476 if (!this->emitSetLocal(*RT, TempOffset, E))
3483 if (!this->emitLoad(*
LT, E))
3485 if (
LT != LHSComputationT &&
3486 !this->emitIntegralCast(*
LT, *LHSComputationT,
3491 if (!this->emitGetLocal(*RT, TempOffset, E))
3498 if (!this->emitAdd(*LHSComputationT, E))
3502 if (!this->emitSub(*LHSComputationT, E))
3506 if (!this->emitMul(*LHSComputationT, E))
3510 if (!this->emitDiv(*LHSComputationT, E))
3514 if (!this->emitRem(*LHSComputationT, E))
3518 if (!this->emitShl(*LHSComputationT, *RT, E))
3522 if (!this->emitShr(*LHSComputationT, *RT, E))
3526 if (!this->emitBitAnd(*LHSComputationT, E))
3530 if (!this->emitBitXor(*LHSComputationT, E))
3534 if (!this->emitBitOr(*LHSComputationT, E))
3538 llvm_unreachable(
"Unimplemented compound assign operator");
3542 if (ResultT != LHSComputationT &&
3543 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3549 return this->emitStoreBitFieldPop(*ResultT, E);
3550 return this->emitStorePop(*ResultT, E);
3553 return this->emitStoreBitField(*ResultT, E);
3554 return this->emitStore(*ResultT, E);
3557template <
class Emitter>
3565template <
class Emitter>
3580 if (!
Ctx.getLangOpts().CPlusPlus11)
3587 for (
const Expr *LHS : CommaLHSs) {
3602 if (this->constantFolding())
3613 if (!this->
visit(Inner))
3618 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3621 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3624 return this->emitGetPtrGlobal(*GlobalIndex, E);
3627 if (!this->checkLiteralType(Inner))
3630 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3636 return this->emitInitGlobalTempComp(TempDecl, E);
3649 unsigned LocalIndex =
3651 if (!this->VarScope->LocalsAlwaysEnabled &&
3652 !this->emitEnableLocal(LocalIndex, E))
3655 if (!this->
visit(Inner))
3657 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3660 return this->emitGetPtrLocal(LocalIndex, E);
3663 if (!this->checkLiteralType(Inner))
3670 if (!this->VarScope->LocalsAlwaysEnabled &&
3671 !this->emitEnableLocal(*LocalIndex, E))
3674 if (!this->emitGetPtrLocal(*LocalIndex, E))
3681template <
class Emitter>
3692 if (!this->
visit(SubExpr))
3696 return this->emitPopPtr(E);
3700template <
class Emitter>
3721 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3726 if (
P.isGlobalInitialized(*GlobalIndex))
3732 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3744 unsigned LocalIndex;
3748 LocalIndex = *MaybeIndex;
3752 if (!this->emitGetPtrLocal(LocalIndex, E))
3756 return this->
visit(
Init) && this->emitInit(*
T, E);
3760template <
class Emitter>
3771 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3775 if (!R || R->getNumFields() == 0)
3777 const Record::Field *Field = R->getField(0
U);
3782 return this->emitInitField(*Field->T, Field->Offset, E);
3789template <
class Emitter>
3793 return this->emitConst(E->
getValue(), E);
3796template <
class Emitter>
3809 for (
const Record::Field &F : R->fields()) {
3811 if (!
Init ||
Init->containsErrors())
3819 if (!this->emitInitField(*
T, F.Offset, E))
3822 if (!this->emitGetPtrField(F.Offset, E))
3833template <
class Emitter>
3839 return this->emitGetStringPtr(E, E);
3843template <
class Emitter>
3848 return this->emitInvalid(E);
3851template <
class Emitter>
3865 if (!this->emitInvalidCast(
CastKind,
false, E))
3873 bool Fatal = (ToT != FromT);
3880template <
class Emitter>
3882 if (!
Ctx.getLangOpts().CPlusPlus20) {
3903 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3908 return this->emitPopPtr(E);
3912template <
class Emitter>
3918 return this->emitConstBool(E->
getValue(), E);
3921template <
class Emitter>
3926 if (
T->isRecordType()) {
3940 if (!this->emitGetPtrLocal(*LocalIndex, E))
3948 T->getAsCXXRecordDecl()))
3958 if (!this->visitZeroRecordInitializer(R, E))
3969 if (!this->emitDefaultInit(Ctor, E))
3972 return this->emitPopPtr(E);
3980 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3982 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3983 if (!this->emitCheckFunctionDecl(Ctor, E))
3994 assert(
Func->hasThisPointer());
3995 assert(!
Func->hasRVO());
3999 if (!this->emitDupPtr(E))
4003 for (
const auto *Arg : E->
arguments()) {
4004 if (!this->
visit(Arg))
4008 if (
Func->isVariadic()) {
4009 uint32_t VarArgSize = 0;
4010 unsigned NumParams =
Func->getNumWrittenParams();
4011 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
4015 if (!this->emitCallVar(
Func, VarArgSize, E))
4018 if (!this->emitCall(
Func, 0, E)) {
4023 (void)this->emitPopPtr(E);
4029 return this->emitPopPtr(E);
4033 if (
T->isArrayType()) {
4038 if (!this->emitDupPtr(E))
4042 initArrayDimension = [&](
QualType T) ->
bool {
4043 if (!
T->isArrayType()) {
4045 for (
const auto *Arg : E->
arguments()) {
4046 if (!this->
visit(Arg))
4050 return this->emitCall(
Func, 0, E);
4054 Ctx.getASTContext().getAsConstantArrayType(
T);
4060 return this->emitCheckArraySize(NumElems, E);
4061 for (uint64_t I = 0; I != NumElems; ++I) {
4062 if (!this->emitConstUint64(I, E))
4064 if (!this->emitArrayElemPtrUint64(E))
4066 if (!initArrayDimension(ElemTy))
4069 return this->emitPopPtr(E);
4072 return initArrayDimension(E->
getType());
4078template <
class Emitter>
4088 assert(Val.
isInt());
4090 return this->emitConst(I, E);
4097 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4098 return this->
visit(LValueExpr);
4113 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4117 const APValue &
V = UGCD->getValue();
4118 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4119 const Record::Field *F = R->getField(I);
4120 const APValue &FieldValue =
V.getStructField(I);
4124 if (!this->emitInitField(*F->T, F->Offset, E))
4132template <
class Emitter>
4138 for (
unsigned I = 0; I != N; ++I) {
4145 if (!this->
discard(ArrayIndexExpr))
4151 if (!this->
visit(ArrayIndexExpr))
4153 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4157 if (!this->
visit(ArrayIndexExpr))
4161 if (!this->emitCast(IndexT,
PT_Sint64, E))
4171 return this->emitOffsetOf(
T, E, E);
4174template <
class Emitter>
4183 return this->visitZeroInitializer(*
T, Ty, E);
4190 if (!this->emitGetPtrLocal(*LocalIndex, E))
4198 ElemQT = CT->getElementType();
4201 NumElems = VT->getNumElements();
4202 ElemQT = VT->getElementType();
4208 for (
unsigned I = 0; I != NumElems; ++I) {
4209 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4211 if (!this->emitInitElem(ElemT, I, E))
4220template <
class Emitter>
4225template <
class Emitter>
4231template <
class Emitter>
4236template <
class Emitter>
4241 return this->emitConst(E->
getValue(), E);
4244template <
class Emitter>
4266 unsigned ParamIndex = 0;
4270 if (!this->emitGetParam(PT, ParamIndex, E))
4275 return this->emitCall(F, 0, E);
4280template <
class Emitter>
4288 const Expr *PlacementDest =
nullptr;
4289 bool IsNoThrow =
false;
4294 if (PlacementArgs != 0) {
4303 if (PlacementArgs == 1) {
4305 if (OperatorNew->isReservedGlobalPlacementOperator()) {
4306 if (!this->emitCheckPlacementNew(E, E))
4308 PlacementDest = Arg1;
4312 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4319 return this->emitInvalidNewDeleteExpr(E, E);
4323 return this->emitInvalid(E);
4325 }
else if (!OperatorNew
4326 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4327 return this->emitInvalidNewDeleteExpr(E, E);
4330 if (!PlacementDest) {
4335 Desc =
P.createDescriptor(E, *ElemT);
4337 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4344 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4348 const Expr *Stripped = *ArraySizeExpr;
4349 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4350 Stripped = ICE->getSubExpr())
4351 if (ICE->getCastKind() != CK_NoOp &&
4352 ICE->getCastKind() != CK_IntegralCast)
4360 if (!this->
visit(Stripped))
4362 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4365 if (PlacementDest) {
4366 if (!this->
visit(PlacementDest))
4368 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4370 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4373 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4378 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4382 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4389 size_t StaticInitElems = 0;
4390 const Expr *DynamicInit =
nullptr;
4394 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4395 StaticInitElems = CAT->getZExtSize();
4400 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4401 if (ILE->hasArrayFiller())
4402 DynamicInit = ILE->getArrayFiller();
4421 const Function *CtorFunc =
nullptr;
4422 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4426 }
else if (!DynamicInit && !ElemT)
4429 LabelTy EndLabel = this->getLabel();
4430 LabelTy StartLabel = this->getLabel();
4435 if (!this->emitDupPtr(E))
4437 if (!this->emitIsNonNullPtr(E))
4439 if (!this->jumpFalse(EndLabel, E))
4446 if (!this->emitConst(StaticInitElems,
SizeT, E))
4448 if (!this->emitSetLocal(
SizeT, Iter, E))
4451 this->fallthrough(StartLabel);
4452 this->emitLabel(StartLabel);
4454 if (!this->emitGetLocal(
SizeT, Iter, E))
4456 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4458 if (!this->emitLT(
SizeT, E))
4460 if (!this->jumpFalse(EndLabel, E))
4464 if (!this->emitGetLocal(
SizeT, Iter, E))
4466 if (!this->emitArrayElemPtr(
SizeT, E))
4469 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4474 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4476 if (!this->emitStorePop(*InitT, E))
4480 if (!this->visitZeroArrayInitializer(ElemType, E))
4483 }
else if (DynamicInit) {
4485 if (!this->
visit(DynamicInit))
4487 if (!this->emitStorePop(*InitT, E))
4494 if (!this->visitZeroInitializer(
4498 if (!this->emitStorePop(*ElemT, E))
4502 if (!this->emitCall(CtorFunc, 0, E))
4507 if (!this->emitGetPtrLocal(Iter, E))
4509 if (!this->emitIncPop(
SizeT,
false, E))
4512 if (!this->jump(StartLabel, E))
4515 this->fallthrough(EndLabel);
4516 this->emitLabel(EndLabel);
4520 if (PlacementDest) {
4521 if (!this->
visit(PlacementDest))
4523 if (!this->emitCheckNewTypeMismatch(E, E))
4528 if (!this->emitAlloc(Desc, E))
4537 if (!this->emitInit(*ElemT, E))
4548 return this->emitPopPtr(E);
4553template <
class Emitter>
4559 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4560 return this->emitInvalidNewDeleteExpr(E, E);
4569template <
class Emitter>
4575 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4580 return this->emitGetFnPtr(
Func, E);
4583template <
class Emitter>
4587 auto canonType = [](
const Type *
T) {
4588 return T->getCanonicalTypeUnqualified().getTypePtr();
4596 return this->emitGetTypeid(
4600 return this->emitGetTypeid(
4609 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4615 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4618 return this->emitPopPtr(E);
4622template <
class Emitter>
4626 return this->emitDummyPtr(E, E);
4627 return this->emitError(E);
4630template <
class Emitter>
4633 return this->emitDummyPtr(E, E);
4634 return this->emitError(E);
4637template <
class Emitter>
4644 assert(
false &&
"null reflection can't be constructed from parsing a "
4645 "reflection operand");
4653 assert(
false &&
"unknown or unimplemented reflection entities");
4657template <
class Emitter>
4659 assert(
Ctx.getLangOpts().CPlusPlus);
4660 return this->emitConstBool(E->
getValue(), E);
4663template <
class Emitter>
4675 return this->emitDummyPtr(GuidDecl, E);
4680 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4689 assert(
V.isStruct());
4690 assert(
V.getStructNumBases() == 0);
4694 return this->emitFinishInit(E);
4697template <
class Emitter>
4707template <
class Emitter>
4716template <
class Emitter>
4722template <
class Emitter>
4726 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4730 if (OVE->isUnique())
4746template <
class Emitter>
4751template <
class Emitter>
4753 return this->emitError(E);
4756template <
class Emitter>
4762 return this->emitDummyPtr(E, E);
4765template <
class Emitter>
4766bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4771 QualType ElemType = VT->getElementType();
4772 PrimType ElemT = classifyPrim(ElemType);
4774 PrimType SrcElemT = classifyVectorElementType(SrcType);
4780 if (!this->emitGetPtrLocal(*LocalIndex, E))
4784 unsigned SrcOffset =
4785 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4786 if (!this->visit(Src))
4788 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4791 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4792 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4794 if (!this->emitArrayElemPop(SrcElemT, I, E))
4798 if (SrcElemT != ElemT) {
4799 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4801 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4802 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4806 if (!this->emitInitElem(ElemT, I, E))
4812template <
class Emitter>
4814 return emitVectorConversion(E->
getSrcExpr(), E);
4817template <
class Emitter>
4821 return this->emitInvalid(E);
4830 assert(NumOutputElems > 0);
4836 if (!this->emitGetPtrLocal(*LocalIndex, E))
4841 unsigned VectorOffsets[2];
4842 for (
unsigned I = 0; I != 2; ++I) {
4845 if (!this->
visit(Vecs[I]))
4847 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4850 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4852 assert(ShuffleIndex >= -1);
4853 if (ShuffleIndex == -1)
4854 return this->emitInvalidShuffleVectorIndex(I, E);
4856 assert(ShuffleIndex < (NumInputElems * 2));
4857 if (!this->emitGetLocal(
PT_Ptr,
4858 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4860 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4861 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4864 if (!this->emitInitElem(ElemT, I, E))
4869 return this->emitPopPtr(E);
4874template <
class Emitter>
4879 Base->getType()->isVectorType() ||
4885 if (Indices.size() == 1) {
4890 if (!this->emitConstUint32(Indices[0], E))
4892 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4902 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4910 if (!this->emitGetPtrLocal(*ResultIndex, E))
4918 uint32_t DstIndex = 0;
4919 for (uint32_t I : Indices) {
4920 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4922 if (!this->emitArrayElemPop(ElemT, I, E))
4924 if (!this->emitInitElem(ElemT, DstIndex, E))
4934template <
class Emitter>
4938 return this->
discard(SubExpr) && this->emitInvalid(E);
4944 return this->emitDummyPtr(E, E);
4947template <
class Emitter>
4952 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4961 if (!this->emitGetPtrLocal(*LocalIndex, E))
4965 if (!this->
visit(SubExpr))
4967 if (!this->emitConstUint8(0, E))
4969 if (!this->emitArrayElemPtrPopUint8(E))
4971 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4974 PrimType SecondFieldT = *R->getField(1u)->T;
4976 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4978 if (!this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E))
4981 return this->emitPopPtr(E);
4984 assert(SecondFieldT ==
PT_Ptr);
4986 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4988 if (!this->emitExpandPtr(E))
4992 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4995 if (!this->emitInitFieldPtr(R->getField(1u)->Offset, E))
4998 return this->emitPopPtr(E);
5002template <
class Emitter>
5017 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
5021 return this->emitUnsupported(E);
5030 return this->
Visit(E);
5037 return this->
Visit(E);
5041 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5044 if (
const auto *CE = dyn_cast<CastExpr>(E);
5046 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
5053 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5056 if (
const auto *CE = dyn_cast<CastExpr>(E);
5057 CE && (CE->getCastKind() == CK_DerivedToBase ||
5058 CE->getCastKind() == CK_UncheckedDerivedToBase ||
5059 CE->getCastKind() == CK_NoOp))
5079 if (!this->emitGetPtrLocal(*LocalIndex, E))
5089 return this->
Visit(E);
5092template <
class Emitter>
5098 return this->
Visit(E) && this->emitFinishInit(E);
5101template <
class Emitter>
5107 return this->
Visit(E) && this->emitFinishInitPop(E);
5113 return this->
Visit(E);
5124 if (!this->
visit(E))
5126 return this->emitComplexBoolCast(E);
5131 if (!this->
visit(E))
5139 return this->emitIsNonNullPtr(E);
5143 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5146 return this->emitCast(*
T,
PT_Bool, E);
5149template <
class Emitter>
5153 QT = AT->getValueType();
5157 return this->emitZeroBool(E);
5159 return this->emitZeroSint8(E);
5161 return this->emitZeroUint8(E);
5163 return this->emitZeroSint16(E);
5165 return this->emitZeroUint16(E);
5167 return this->emitZeroSint32(E);
5169 return this->emitZeroUint32(E);
5171 return this->emitZeroSint64(E);
5173 return this->emitZeroUint64(E);
5175 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5177 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5179 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5182 return this->emitNullMemberPtr(0,
nullptr, E);
5184 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5185 return this->emitFloat(F, E);
5188 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5194 llvm_unreachable(
"unknown primitive type");
5197template <
class Emitter>
5198bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5200 bool IsCompleteClass) {
5204 for (
const Record::Field &Field :
R->fields()) {
5205 if (Field.isUnnamedBitField())
5212 if (!this->visitZeroInitializer(
T, QT, E))
5215 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5219 if (!this->emitInitField(
T, Field.Offset, E))
5224 if (!this->emitGetPtrField(Field.Offset, E))
5231 if (!this->visitZeroInitializer(
T, ET, E))
5233 if (!this->emitInitElem(
T, I, E))
5238 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5241 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5249 if (!this->emitFinishInitActivatePop(E))
5253 if (!this->emitFinishInitPop(E))
5257 for (
const Record::Base &B :
R->bases()) {
5258 if (!this->emitGetPtrBase(B.Offset, E))
5260 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5262 if (!this->emitFinishInitPop(E))
5266 if (IsCompleteClass) {
5267 for (
const Record::Base &B :
R->virtual_bases()) {
5270 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5272 if (!this->emitFinishInitPop(E))
5280template <
class Emitter>
5281bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5282 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5283 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5288 for (
size_t I = 0; I != NumElems; ++I) {
5289 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5291 if (!this->emitInitElem(*ElemT, I, E))
5297 const Record *
R = getRecord(ElemType);
5301 for (
size_t I = 0; I != NumElems; ++I) {
5302 if (!this->emitConstUint32(I, E))
5304 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5306 if (!this->visitZeroRecordInitializer(R, E))
5308 if (!this->emitPopPtr(E))
5314 for (
size_t I = 0; I != NumElems; ++I) {
5315 if (!this->emitConstUint32(I, E))
5317 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5319 if (!this->visitZeroArrayInitializer(ElemType, E))
5321 if (!this->emitPopPtr(E))
5330template <
class Emitter>
5331bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5333 if (!canClassify(E->
getType()))
5338 if (!this->visit(LHS))
5340 if (!this->visit(RHS))
5343 if (!this->visit(RHS))
5345 if (!this->visit(LHS))
5353 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5357 bool Activates = refersToUnion(LHS);
5360 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5363 if (DiscardResult) {
5364 if (BitField && Activates)
5365 return this->emitStoreBitFieldActivatePop(RHT, E);
5367 return this->emitStoreBitFieldPop(RHT, E);
5369 return this->emitStoreActivatePop(RHT, E);
5371 return this->emitStorePop(RHT, E);
5374 auto maybeLoad = [&](
bool Result) ->
bool {
5380 return this->emitLoadPop(RHT, E);
5384 if (BitField && Activates)
5385 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5387 return maybeLoad(this->emitStoreBitField(RHT, E));
5389 return maybeLoad(this->emitStoreActivate(RHT, E));
5391 return maybeLoad(this->emitStore(RHT, E));
5394template <
class Emitter>
5395template <
typename T>
5399 return this->emitConstSint8(
Value, Info);
5401 return this->emitConstUint8(
Value, Info);
5403 return this->emitConstSint16(
Value, Info);
5405 return this->emitConstUint16(
Value, Info);
5407 return this->emitConstSint32(
Value, Info);
5409 return this->emitConstUint32(
Value, Info);
5411 return this->emitConstSint64(
Value, Info);
5413 return this->emitConstUint64(
Value, Info);
5415 return this->emitConstBool(
Value, Info);
5423 llvm_unreachable(
"Invalid integral type");
5426 llvm_unreachable(
"unknown primitive type");
5429template <
class Emitter>
5430template <
typename T>
5431bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5432 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5435template <
class Emitter>
5439 return this->emitConstIntAPS(
Value, Info);
5441 return this->emitConstIntAP(
Value, Info);
5443 if (
Value.isSigned())
5444 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5445 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5448template <
class Emitter>
5452 return this->emitConstIntAPS(
Value, Info);
5454 return this->emitConstIntAP(
Value, Info);
5457 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5458 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5461template <
class Emitter>
5462bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5463 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5466template <
class Emitter>
5481 return Local.Offset;
5484template <
class Emitter>
5489 bool IsTemporary =
false;
5493 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5494 Init = VarD->getInit();
5496 if (
const auto *E = Src.
asExpr()) {
5506 return std::nullopt;
5513 return Local.Offset;
5516template <
class Emitter>
5525 return std::nullopt;
5535 return Local.Offset;
5538template <
class Emitter>
5540 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5541 return PT->getPointeeType()->getAsCanonical<RecordType>();
5547 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5551template <
class Emitter>
5553 return P.getOrCreateRecord(RD);
5556template <
class Emitter>
5558 return Ctx.getOrCreateFunction(FD);
5561template <
class Emitter>
5567 auto maybeDestroyLocals = [&]() ->
bool {
5568 if (DestroyToplevelScope)
5569 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5570 return this->emitCheckAllocations(E);
5577 return this->emitRetVoid(E) && maybeDestroyLocals();
5585 return this->emitRet(*
T, E) && maybeDestroyLocals();
5593 if (!this->emitGetPtrLocal(*LocalOffset, E))
5601 return this->emitRetValue(E) && maybeDestroyLocals();
5604 return maybeDestroyLocals() &&
false;
5607template <
class Emitter>
5609 bool DestroyToplevelScope) {
5613 return this->
visitExpr(E, DestroyToplevelScope);
5616template <
class Emitter>
5628 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5629 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5643template <
class Emitter>
5645 bool ConstantContext) {
5648 if (!ConstantContext) {
5663 auto GlobalIndex =
P.getGlobal(VD);
5664 assert(GlobalIndex);
5666 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5669 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5677 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5679 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5682 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5692 auto GlobalIndex =
P.getGlobal(VD);
5693 assert(GlobalIndex);
5694 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5703 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5706template <
class Emitter>
5717 if (!this->isActive())
5722 if (
Init &&
Init->isValueDependent())
5726 auto checkDecl = [&]() ->
bool {
5728 return !NeedsOp || this->emitCheckDecl(VD, VD);
5735 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5738 if (
P.isGlobalInitialized(*GlobalIndex))
5742 }
else if ((GlobalIndex =
5757 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5760 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5763 if (!this->emitStartInit(
Init))
5769 if (!this->emitEndInit(
Init))
5772 return this->emitFinishInitGlobal(
Init);
5782 if (!
Init ||
Init->getType()->isVoidType())
5791 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5803 if (!this->emitCheckRefInit(
Init))
5807 return this->emitSetLocal(*VarT, Offset, VD);
5815 if (!this->emitGetPtrLocal(*Offset,
Init))
5823template <
class Emitter>
5846 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5852 return this->emitDestructionPop(D, VD);
5861 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5885template <
class Emitter>
5900 unsigned ParamIndex = 0;
5907 const Expr *Arg = Args[ParamIndex];
5908 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5910 unsigned ArgOffset =
5912 if (!this->
visit(Arg))
5914 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5920 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5932 if (
This->getType()->isPointerType()) {
5935 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5942 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5964template <
class Emitter>
5970 return this->emitConst(Val.
getInt(), ValType, Info);
5972 return this->emitFloat(Val.
getFloat(), Info);
5976 if (!this->emitGetMemberPtr(MemberDecl, Info))
5982 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5988 return this->emitNullMemberPtr(0,
nullptr, Info);
5993 return this->emitNull(ValType, 0,
nullptr, Info);
5997 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>()) {
5998 if (!this->
visit(BaseExpr))
6000 EntryType = BaseExpr->getType();
6001 }
else if (
const auto *VD =
Base.dyn_cast<
const ValueDecl *>()) {
6004 EntryType = VD->getType();
6009 ->getCanonicalTypeUnqualified()
6011 EntryType =
Base.getTypeInfoType();
6012 if (!this->emitGetTypeid(OperandType, EntryType.
getTypePtr(), Info))
6020 ?
Ctx.getASTContext().getPointerType(E->
getType())
6023 if (!this->emitConstUint64(Offset, Info))
6025 if (!this->emitGetIntPtrUint64(PtrType.
getTypePtr(), Info))
6035 uint64_t Index = Entry.getAsArrayIndex();
6038 if (!this->emitConst(Index,
PT_Uint64, Info))
6040 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
6042 EntryType = ElemType;
6049 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
6050 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
6052 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
6054 EntryType = FD->getType();
6058 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
6063 if (!this->emitGetPtrVirtBasePop(
Base, Info))
6066 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
6081 uint32_t BitWidth =
Ctx.getBitWidth(E->
getType());
6083 ? this->emitCastPointerIntegralAP(BitWidth, Info)
6084 : this->emitCastPointerIntegralAPS(BitWidth, Info);
6086 return this->emitCastPointerIntegral(ValType, Info);
6092template <
class Emitter>
6095 bool IsCompleteClass) {
6101 if (IsCompleteClass)
6108 const Record::Base *RB = R->getBase(I);
6109 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6111 if (!this->emitGetPtrBase(RB->Offset, Info))
6116 if (!this->emitFinishInitPop(Info))
6124 const Record::Field *RF = R->getField(I);
6125 QualType FieldType = RF->Decl->getType();
6130 if (!this->emitInitField(*PT, RF->Offset, Info))
6133 if (!this->emitGetPtrField(RF->Offset, Info))
6137 if (!this->emitFinishInitPop(Info))
6143 if (IsCompleteClass) {
6148 const Record::Base *RB = R->getVirtualBase(I);
6149 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6157 if (!this->emitFinishInitPop(Info))
6173 const Record::Field *RF = R->getField(UnionField);
6174 QualType FieldType = RF->Decl->getType();
6179 if (RF->isBitField())
6180 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6182 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6185 if (!this->emitGetPtrField(RF->Offset, Info))
6187 if (!this->emitActivate(Info))
6191 return this->emitPopPtr(Info);
6195 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6196 QualType ElemType = ArrType->getElementType();
6199 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6200 const APValue &Elem = A >= InitializedElems
6209 if (!this->emitInitElem(*ElemT, A, Info))
6212 if (!this->emitConstUint32(A, Info))
6214 if (!this->emitArrayElemPtrUint32(Info))
6218 if (!this->emitPopPtr(Info))
6229template <
class Emitter>
6231 if (
P.getGlobal(VD))
6236 llvm_unreachable(
"Why didn't that work?");
6240 "registerRedecl should only be called with primitive values");
6245 return this->emitInitGlobal(
T, *GlobalIndex, {});
6248template <
class Emitter>
6250 unsigned BuiltinID) {
6256 if (!
Ctx.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
6257 return this->emitInvalid(E);
6266 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6271 return this->emitConst(0, E);
6274 if (!this->emitStartSpeculation(E))
6276 LabelTy EndLabel = this->getLabel();
6277 if (!this->speculate(E, EndLabel))
6279 if (!this->emitEndSpeculation(E))
6281 this->fallthrough(EndLabel);
6289 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6290 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6291 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6292 BuiltinID == Builtin::BI__builtin_function_start) {
6295 return this->emitDummyPtr(E, E);
6306 if (!this->emitGetPtrLocal(*LocalIndex, E))
6311 switch (BuiltinID) {
6312 case Builtin::BI__builtin_object_size:
6313 case Builtin::BI__builtin_dynamic_object_size: {
6317 if (!this->
visit(Arg0))
6328 case Builtin::BI__assume:
6329 case Builtin::BI__builtin_assume:
6332 case Builtin::BI__atomic_is_lock_free:
6333 case Builtin::BI__atomic_always_lock_free: {
6344 for (
const auto *Arg : E->
arguments()) {
6345 if (!this->
visit(Arg))
6351 if (!this->emitCallBI(E, BuiltinID, E))
6369template <
class Emitter>
6390 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6391 DD && DD->isTrivial()) {
6393 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6395 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6396 this->emitPopPtr(E);
6402 bool ActivateLHS =
false;
6410 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6411 OCE && OCE->isAssignmentOp()) {
6412 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6415 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6416 if (!this->
visit(MCE->getImplicitObjectArgument()))
6423 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6441 if (!this->emitGetPtrLocal(*LocalIndex, E))
6449 if (!this->emitGetPtrLocal(*LocalIndex, E))
6453 if (!this->emitDupPtr(E))
6458 const Expr *ReversedArgs[2];
6459 bool IsAssignmentOperatorCall =
false;
6460 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6461 OCE && OCE->isAssignmentOp()) {
6465 assert(Args.size() == 2);
6466 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6468 IsAssignmentOperatorCall =
true;
6469 ReversedArgs[0] = Args[1];
6470 ReversedArgs[1] = Args[0];
6471 Args = ReversedArgs;
6478 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6479 MD && MD->isStatic()) {
6483 Args = Args.drop_front();
6487 bool Devirtualized =
false;
6490 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6498 if (!this->
visit(Callee))
6500 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6502 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6504 if (!this->emitGetMemberPtrBase(E))
6507 const auto *InstancePtr = MC->getImplicitObjectArgument();
6514 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6515 Devirtualized =
true;
6516 if (!this->
visit(Stripped))
6519 if (!this->
visit(InstancePtr))
6523 if (!this->
visit(InstancePtr))
6527 }
else if (
const auto *PD =
6528 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6529 if (!this->emitCheckPseudoDtor(E))
6537 return this->emitPseudoDtor(E);
6538 }
else if (!FuncDecl) {
6542 if (!this->
visit(Callee))
6544 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6553 if (IsAssignmentOperatorCall) {
6554 assert(Args.size() == 2);
6557 if (!this->emitFlip(Arg2T, Arg1T, E))
6571 assert(HasRVO ==
Func->hasRVO());
6573 bool HasQualifier =
false;
6574 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6575 HasQualifier = ME->hasQualifier();
6577 bool IsVirtual =
false;
6578 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6579 IsVirtual = !Devirtualized && MD->isVirtual();
6584 if (IsVirtual && !HasQualifier) {
6585 uint32_t VarArgSize = 0;
6586 unsigned NumParams =
6587 Func->getNumWrittenParams() +
6589 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6592 if (!this->emitCallVirt(
Func, VarArgSize, E))
6594 }
else if (
Func->isVariadic()) {
6595 uint32_t VarArgSize = 0;
6596 unsigned NumParams =
6597 Func->getNumWrittenParams() +
6599 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6601 if (!this->emitCallVar(
Func, VarArgSize, E))
6604 if (!this->emitCall(
Func, 0, E))
6613 uint32_t ArgSize = 0;
6614 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6620 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6622 if (!this->emitGetMemberPtrDecl(E))
6625 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6628 if (!this->emitCallPtr(ArgSize, E, E))
6639template <
class Emitter>
6646template <
class Emitter>
6653template <
class Emitter>
6658 return this->emitConstBool(E->
getValue(), E);
6661template <
class Emitter>
6667 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6668 return this->emitNullPtr(Val,
nullptr, E);
6671template <
class Emitter>
6679 return this->emitZero(
T, E);
6682template <
class Emitter>
6687 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6688 if (this->LambdaThisCapture.Offset > 0) {
6689 if (this->LambdaThisCapture.IsPtr)
6690 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6691 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6700 return this->emitThis(E);
6715 unsigned StartIndex = 0;
6716 unsigned EndIndex = 0;
6718 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6720 EndIndex = StartIndex;
6727 for (; StartIndex > 0; --StartIndex) {
6738 if (StartIndex == 0 && EndIndex == 0)
6749 assert(StartIndex <= EndIndex);
6752 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6764 case Stmt::CompoundStmtClass:
6766 case Stmt::DeclStmtClass:
6768 case Stmt::ReturnStmtClass:
6770 case Stmt::IfStmtClass:
6772 case Stmt::WhileStmtClass:
6774 case Stmt::DoStmtClass:
6776 case Stmt::ForStmtClass:
6778 case Stmt::CXXForRangeStmtClass:
6780 case Stmt::BreakStmtClass:
6782 case Stmt::ContinueStmtClass:
6784 case Stmt::SwitchStmtClass:
6786 case Stmt::CaseStmtClass:
6788 case Stmt::DefaultStmtClass:
6790 case Stmt::AttributedStmtClass:
6792 case Stmt::CXXTryStmtClass:
6794 case Stmt::NullStmtClass:
6797 case Stmt::GCCAsmStmtClass:
6798 case Stmt::MSAsmStmtClass:
6799 case Stmt::GotoStmtClass:
6800 return this->emitInvalid(S);
6801 case Stmt::LabelStmtClass:
6803 case Stmt::CXXExpansionStmtInstantiationClass:
6807 if (
const auto *E = dyn_cast<Expr>(S))
6814template <
class Emitter>
6817 for (
const auto *InnerStmt : S->
body())
6820 return Scope.destroyLocals();
6823template <
class Emitter>
6824bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6825 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6826 for (
auto *BD : DD->flat_bindings())
6827 if (
auto *KD = BD->getHoldingVar();
6828 KD && !this->visitVarDecl(KD, KD->getInit()))
6842template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6844 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6845 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6852 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6857 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6858 ICE && (ICE->getCastKind() == CK_NoOp ||
6859 ICE->getCastKind() == CK_DerivedToBase ||
6860 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6861 E = ICE->getSubExpr();
6865 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6866 const auto *ThisRecord =
6867 This->getType()->getPointeeType()->getAsRecordDecl();
6868 if (!ThisRecord->isUnion())
6871 if (
const auto *Ctor =
6872 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6873 return Ctor->getParent() == ThisRecord;
6882template <
class Emitter>
6884 bool EvaluateConditionDecl) {
6885 for (
const auto *D : DS->
decls()) {
6890 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6891 assert(ESD->getInstantiations() &&
"not expanded?");
6892 if (!this->
visitStmt(ESD->getInstantiations()))
6897 const auto *VD = dyn_cast<VarDecl>(D);
6904 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6911template <
class Emitter>
6914 return this->emitUnsupported(RS);
6920 if (!this->
visit(RE))
6926 if (RE->getType()->isVoidType()) {
6927 if (!this->
visit(RE))
6930 if (RE->containsErrors())
6935 if (!this->emitRVOPtr(RE))
6941 return this->emitRetVoid(RS);
6947 return this->emitRetVoid(RS);
6953 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6960 if (
auto *CondInit = IS->
getInit()) {
6976 return visitChildStmt(IS->
getThen());
6978 return visitChildStmt(Else);
6984 if (!this->emitIsConstantContext(IS))
6987 if (!this->emitIsConstantContext(IS))
6989 if (!this->emitInv(IS))
7003 LabelTy LabelElse = this->getLabel();
7004 LabelTy LabelEnd = this->getLabel();
7005 if (!this->jumpFalse(LabelElse, IS))
7007 if (!visitChildStmt(IS->
getThen()))
7009 if (!this->jump(LabelEnd, IS))
7011 this->emitLabel(LabelElse);
7012 if (!visitChildStmt(Else))
7014 this->emitLabel(LabelEnd);
7016 LabelTy LabelEnd = this->getLabel();
7017 if (!this->jumpFalse(LabelEnd, IS))
7019 if (!visitChildStmt(IS->
getThen()))
7021 this->emitLabel(LabelEnd);
7030template <
class Emitter>
7035 LabelTy CondLabel = this->getLabel();
7036 LabelTy EndLabel = this->getLabel();
7040 this->fallthrough(CondLabel);
7041 this->emitLabel(CondLabel);
7057 if (!this->jumpFalse(EndLabel, S))
7067 if (!this->jump(CondLabel, S))
7069 this->fallthrough(EndLabel);
7070 this->emitLabel(EndLabel);
7079 LabelTy StartLabel = this->getLabel();
7080 LabelTy EndLabel = this->getLabel();
7081 LabelTy CondLabel = this->getLabel();
7085 this->fallthrough(StartLabel);
7086 this->emitLabel(StartLabel);
7092 this->fallthrough(CondLabel);
7093 this->emitLabel(CondLabel);
7100 if (!this->jumpTrue(StartLabel, S))
7103 this->fallthrough(EndLabel);
7104 this->emitLabel(EndLabel);
7108template <
class Emitter>
7116 LabelTy EndLabel = this->getLabel();
7117 LabelTy CondLabel = this->getLabel();
7118 LabelTy IncLabel = this->getLabel();
7125 this->fallthrough(CondLabel);
7126 this->emitLabel(CondLabel);
7138 if (!this->jumpFalse(EndLabel, S))
7147 this->fallthrough(IncLabel);
7148 this->emitLabel(IncLabel);
7154 if (!this->jump(CondLabel, S))
7158 this->emitLabel(EndLabel);
7164template <
class Emitter>
7174 LabelTy EndLabel = this->getLabel();
7175 LabelTy CondLabel = this->getLabel();
7176 LabelTy IncLabel = this->getLabel();
7192 this->fallthrough(CondLabel);
7193 this->emitLabel(CondLabel);
7196 if (!this->jumpFalse(EndLabel, S))
7207 this->fallthrough(IncLabel);
7208 this->emitLabel(IncLabel);
7215 if (!this->jump(CondLabel, S))
7218 this->fallthrough(EndLabel);
7219 this->emitLabel(EndLabel);
7223template <
class Emitter>
7234 if (LI.BreakLabel) {
7235 TargetLabel = *LI.BreakLabel;
7236 BreakScope = LI.BreakOrContinueScope;
7242 if (LI.Name == TargetLoop) {
7243 TargetLabel = *LI.BreakLabel;
7244 BreakScope = LI.BreakOrContinueScope;
7255 C =
C->getParent()) {
7256 if (!
C->destroyLocals())
7260 return this->jump(*TargetLabel, S);
7263template <
class Emitter>
7274 if (LI.ContinueLabel) {
7275 TargetLabel = *LI.ContinueLabel;
7276 ContinueScope = LI.BreakOrContinueScope;
7282 if (LI.Name == TargetLoop) {
7283 TargetLabel = *LI.ContinueLabel;
7284 ContinueScope = LI.BreakOrContinueScope;
7294 C =
C->getParent()) {
7295 if (!
C->destroyLocals())
7299 return this->jump(*TargetLabel, S);
7302template <
class Emitter>
7312 LabelTy EndLabel = this->getLabel();
7317 if (
const auto *CondInit = S->
getInit())
7326 if (!this->
visit(Cond))
7328 if (!this->emitSetLocal(CondT, CondVar, S))
7338 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7341 if (CS->caseStmtIsGNURange()) {
7342 LabelTy EndOfRangeCheck = this->getLabel();
7343 const Expr *Low = CS->getLHS();
7344 const Expr *High = CS->getRHS();
7348 if (!this->emitGetLocal(CondT, CondVar, CS))
7350 if (!this->
visit(Low))
7353 if (!this->emitGE(
LT, S))
7355 if (!this->jumpFalse(EndOfRangeCheck, S))
7358 if (!this->emitGetLocal(CondT, CondVar, CS))
7360 if (!this->
visit(High))
7363 if (!this->emitLE(HT, S))
7367 this->emitLabel(EndOfRangeCheck);
7372 if (
Value->isValueDependent())
7377 if (!this->emitGetLocal(CondT, CondVar, CS))
7383 if (!this->emitEQ(ValueT, S))
7388 assert(!DefaultLabel);
7389 DefaultLabel = this->getLabel();
7396 if (!this->jump(*DefaultLabel, S))
7399 if (!this->jump(EndLabel, S))
7407 this->fallthrough(EndLabel);
7408 this->emitLabel(EndLabel);
7413template <
class Emitter>
7421 return this->emitUnsupported(S);
7426template <
class Emitter>
7433 if (LI.DefaultLabel) {
7434 DefaultLabel = *LI.DefaultLabel;
7439 this->emitLabel(DefaultLabel);
7443template <
class Emitter>
7450 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7453 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7454 !this->Ctx.getLangOpts().MSVCCompat) {
7456 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7462 const Expr *Assumption = AA->getAssumption();
7473 if (!this->emitAssume(Assumption))
7482 if (IsMSVCConstexprAttr)
7483 return this->emitPopMSVCCE(S);
7487template <
class Emitter>
7500template <
class Emitter>
7510 LabelTy EndLabel = this->getLabel();
7512 LabelTy ContinueLabel = this->getLabel();
7517 this->emitLabel(ContinueLabel);
7520 this->emitLabel(EndLabel);
7525template <
class Emitter>
7526bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7533 assert(ClosureClass->
captures().empty());
7537 "A generic lambda's static-invoker function must be a "
7538 "template specialization");
7542 llvm::FoldingSetInsertToken InsertToken;
7543 const FunctionDecl *CorrespondingCallOpSpecialization =
7545 assert(CorrespondingCallOpSpecialization);
7546 LambdaCallOp = CorrespondingCallOpSpecialization;
7550 assert(ClosureClass->
captures().empty());
7551 const Function *
Func = this->getFunction(LambdaCallOp);
7554 assert(
Func->hasThisPointer());
7557 if (
Func->hasRVO()) {
7558 if (!this->emitRVOPtr(MD))
7566 if (!this->emitNullPtr(0,
nullptr, MD))
7571 auto It = this->Params.find(PVD);
7572 assert(It != this->Params.end());
7576 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7577 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7581 if (!this->emitCall(
Func, 0, LambdaCallOp))
7586 return this->emitRet(*ReturnType, MD);
7589 return this->emitRetVoid(MD);
7592template <
class Emitter>
7593bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7594 if (Ctx.getLangOpts().CPlusPlus23)
7604 const Expr *InitExpr =
Init->getInit();
7606 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7610 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7620template <
class Emitter>
7622 assert(!ReturnType);
7625 if (!this->emitStartThisLifetime1(Ctor))
7628 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7629 const Expr *InitExpr,
7632 if (InitExpr->getType().isNull())
7636 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7639 if (!this->visit(InitExpr))
7642 if (F->isBitField())
7643 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7645 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7650 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7653 if (
Activate && !this->emitActivate(InitExpr))
7656 return this->visitInitializerPop(InitExpr);
7660 const Record *
R = this->getRecord(RD);
7663 bool IsUnion =
R->isUnion();
7673 if (!this->emitThis(Ctor))
7676 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7679 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7680 this->emitRetVoid(Ctor);
7683 unsigned FieldInits = 0;
7686 if (
R->getNumVirtualBases() > 0) {
7687 if (!this->emitThis(Ctor))
7689 LabelTy AfterVirtBasesLabel = this->getLabel();
7692 if (!this->emitIsBaseClass({}))
7694 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7697 for (
const auto *
Init : Ctor->
inits()) {
7700 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7702 assert(
R->findVirtualBase(BaseDecl));
7703 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7705 if (!this->visitInitializerPop(
Init->getInit()))
7710 this->fallthrough(AfterVirtBasesLabel);
7711 this->emitLabel(AfterVirtBasesLabel);
7713 if (!this->emitPopPtr(Ctor))
7717 for (
const auto *
Init : Ctor->
inits()) {
7721 const Expr *InitExpr =
Init->getInit();
7723 const Record::Field *F =
R->getField(
Member);
7727 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7731 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7734 if (
Init->isBaseVirtual()) {
7740 const Record::Base *B =
R->getBase(BaseDecl);
7742 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7746 if (!this->visitInitializerPop(InitExpr))
7751 unsigned ChainSize = IFD->getChainingSize();
7752 assert(ChainSize >= 2);
7754 unsigned NestedFieldOffset = 0;
7755 const Record::Field *NestedField =
nullptr;
7756 for (
unsigned I = 0; I != ChainSize; ++I) {
7758 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7759 assert(FieldRecord);
7761 NestedField = FieldRecord->
getField(FD);
7762 assert(NestedField);
7763 IsUnion = IsUnion || FieldRecord->
isUnion();
7765 NestedFieldOffset += NestedField->Offset;
7768 if (I != ChainSize - 1)
7771 assert(NestedField);
7774 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7779 unsigned InitFieldOffset = 0;
7780 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7782 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7783 assert(FieldRecord);
7784 NestedField = FieldRecord->
getField(FD);
7785 InitFieldOffset += NestedField->Offset;
7786 assert(NestedField);
7787 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7789 if (!this->emitFinishInitPop(InitExpr))
7793 InitStack.pop_back_n(ChainSize - 1);
7796 assert(
Init->isDelegatingInitializer());
7797 if (!this->emitThis(InitExpr))
7799 if (!this->visitInitializerPop(
Init->getInit()))
7803 if (!
Scope.destroyLocals())
7807 if (FieldInits !=
R->getNumFields()) {
7808 assert(FieldInits < R->getNumFields());
7810 if (!this->emitStartThisLifetime(Ctor))
7817 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7818 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7825 if (!visitStmt(Body))
7832template <
class Emitter>
7835 const Record *
R = this->getRecord(RD);
7839 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7840 if (!this->visitStmt(
Dtor->getBody()))
7844 if (!this->emitThis(
Dtor))
7847 if (!this->emitCheckDestruction(
Dtor))
7851 if (!
R->isUnion()) {
7855 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7859 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7861 if (!this->emitDestructionPop(D,
SourceInfo{}))
7866 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7867 if (
Base.R->hasTrivialDtor())
7871 if (!this->emitRecordDestructionPop(
Base.R, {}))
7875 if (
R->getNumVirtualBases() > 0) {
7876 LabelTy EndLabel = this->getLabel();
7878 if (!this->emitIsBaseClass({}))
7880 if (!this->jumpTrue(EndLabel, {}))
7883 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7884 if (
Base.R->hasTrivialDtor())
7889 if (!this->emitRecordDestructionPop(
Base.R, {}))
7893 this->fallthrough(EndLabel);
7894 this->emitLabel(EndLabel);
7897 if (!this->emitMarkDestroyed(
Dtor))
7900 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7903template <
class Emitter>
7904bool Compiler<Emitter>::compileUnionAssignmentOperator(
7906 if (!this->emitThis(MD))
7909 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7912 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7915template <
class Emitter>
7925 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7926 return this->compileConstructor(Ctor);
7927 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7928 return this->compileDestructor(
Dtor);
7931 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7936 return this->compileUnionAssignmentOperator(MD);
7939 return this->emitLambdaStaticInvokerBody(MD);
7943 if (
const auto *Body = F->
getBody())
7957 return FD->getBitWidthValue();
7960template <
class Emitter>
7976 if (!
Ctx.getLangOpts().CPlusPlus14)
7977 return this->emitInvalid(E);
7979 return this->emitError(E);
7981 if (!this->
visit(SubExpr))
7985 if (!this->emitIncPtr(E))
7992 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7993 : this->emitIncf(getFPOptions(E), E);
8005 if (!
Ctx.getLangOpts().CPlusPlus14)
8006 return this->emitInvalid(E);
8008 return this->emitError(E);
8010 if (!this->
visit(SubExpr))
8014 if (!this->emitDecPtr(E))
8021 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
8022 : this->emitDecf(getFPOptions(E), E);
8035 if (!
Ctx.getLangOpts().CPlusPlus14)
8036 return this->emitInvalid(E);
8038 return this->emitError(E);
8040 if (!this->
visit(SubExpr))
8044 if (!this->emitLoadPtr(E))
8046 if (!this->emitConstUint8(1, E))
8048 if (!this->emitAddOffsetUint8(E))
8050 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8056 return this->emitIncfPop(getFPOptions(E), E);
8066 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8067 if (!this->emitLoadFloat(E))
8069 APFloat F(TargetSemantics, 1);
8070 if (!this->emitFloat(F, E))
8073 if (!this->emitAddf(getFPOptions(E), E))
8075 if (!this->emitStoreFloat(E))
8087 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8090 if (!
Ctx.getLangOpts().CPlusPlus14)
8091 return this->emitInvalid(E);
8093 return this->emitError(E);
8095 if (!this->
visit(SubExpr))
8099 if (!this->emitLoadPtr(E))
8101 if (!this->emitConstUint8(1, E))
8103 if (!this->emitSubOffsetUint8(E))
8105 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8111 return this->emitDecfPop(getFPOptions(E), E);
8121 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8122 if (!this->emitLoadFloat(E))
8124 APFloat F(TargetSemantics, 1);
8125 if (!this->emitFloat(F, E))
8128 if (!this->emitSubf(getFPOptions(E), E))
8130 if (!this->emitStoreFloat(E))
8142 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8146 return this->emitError(E);
8149 return this->
discard(SubExpr);
8154 if (!this->emitInv(E))
8158 return this->emitCast(
PT_Bool, ET, E);
8162 return this->emitError(E);
8164 if (!this->
visit(SubExpr))
8169 return this->emitError(E);
8171 if (!this->
visit(SubExpr))
8187 if (!
Ctx.getLangOpts().CPlusPlus) {
8190 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8191 Deref && Deref->getOpcode() == UO_Deref) {
8193 return this->
discard(Deref->getSubExpr());
8194 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8199 return this->
discard(SubExpr);
8200 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8203 return this->
discard(SubExpr);
8205 if (!this->
visit(SubExpr))
8212 return this->emitNarrowPtr(E);
8217 return this->emitError(E);
8219 if (!this->
visit(SubExpr))
8233 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
8238 assert(
false &&
"Unhandled opcode");
8244template <
class Emitter>
8250 return this->
discard(SubExpr);
8253 auto prepareResult = [=]() ->
bool {
8258 return this->emitGetPtrLocal(*LocalIndex, E);
8265 unsigned SubExprOffset = ~0u;
8266 auto createTemp = [=, &SubExprOffset]() ->
bool {
8269 if (!this->
visit(SubExpr))
8271 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8275 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8276 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8278 return this->emitArrayElemPop(ElemT, Index, E);
8283 if (!prepareResult())
8287 for (
unsigned I = 0; I != 2; ++I) {
8288 if (!getElem(SubExprOffset, I))
8290 if (!this->emitNeg(ElemT, E))
8292 if (!this->emitInitElem(ElemT, I, E))
8303 if (!this->
visit(SubExpr))
8305 if (!this->emitComplexBoolCast(SubExpr))
8307 if (!this->emitInv(E))
8310 return this->emitCast(
PT_Bool, ET, E);
8314 return this->emitComplexReal(SubExpr);
8317 if (!this->
visit(SubExpr))
8321 if (!this->emitConstUint8(1, E))
8323 return this->emitArrayElemPtrPopUint8(E);
8334 if (!this->emitArrayElem(ElemT, 1, E))
8336 if (!this->emitNeg(ElemT, E))
8338 if (!this->emitInitElem(ElemT, 1, E))
8346 return this->emitInvalid(E);
8352template <
class Emitter>
8358 return this->
discard(SubExpr);
8361 if (UnaryOp == UO_Extension)
8364 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8365 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8366 return this->emitInvalid(E);
8369 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8376 if (!this->emitGetPtrLocal(*LocalIndex, E))
8381 unsigned SubExprOffset =
8383 if (!this->
visit(SubExpr))
8385 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8390 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8391 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8393 return this->emitArrayElemPop(ElemT, Index, E);
8398 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8399 if (!getElem(SubExprOffset, I))
8401 if (!this->emitNeg(ElemT, E))
8403 if (!this->emitInitElem(ElemT, I, E))
8418 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8419 if (!getElem(SubExprOffset, I))
8422 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8424 if (!this->emitInv(E))
8426 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8428 if (!this->emitNeg(ElemT, E))
8430 if (ElemT != ResultVecElemT &&
8431 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8433 if (!this->emitInitElem(ResultVecElemT, I, E))
8439 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8440 if (!getElem(SubExprOffset, I))
8443 if (!this->emitInv(E))
8446 if (!this->emitComp(ElemT, E))
8449 if (!this->emitInitElem(ElemT, I, E))
8454 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8459template <
class Emitter>
8461 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8464 return this->emitConst(ECD->getInitVal(), E);
8466 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8470 return F && this->emitGetFnPtr(F, E);
8472 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8473 TPOD = TPOD->getFirstDecl();
8477 return this->emitGetPtrGlobal(*GlobalIndex, E);
8483 return this->emitInitGlobal(*
T, *Index, E);
8486 if (!this->emitGetPtrGlobal(*Index, E))
8490 return this->emitFinishInit(E);
8502 auto maybePopPtr = [&]() ->
bool {
8504 return this->emitPopPtr(E);
8511 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8515 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8520 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8521 if (IsReference || !It->second.IsPtr)
8522 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8524 return this->emitGetPtrParam(It->second.Index, E);
8527 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8534 const unsigned Offset = It->second.Offset;
8537 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8539 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8542 if (
auto GlobalIndex =
P.getGlobal(D)) {
8544 if (!
Ctx.getLangOpts().CPlusPlus11)
8545 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8546 if (!
Ctx.getLangOpts().CPlusPlus23)
8547 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8549 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8552 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8556 auto revisit = [&](
const VarDecl *VD,
8557 bool IsConstexprUnknown =
true) ->
bool {
8559 IsConstexprUnknown);
8560 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8566 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8567 if (!this->emitPopCC(E))
8571 if (VarState.notCreated())
8579 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8581 if (
auto It = this->LambdaCaptures.find(D);
8582 It != this->LambdaCaptures.end()) {
8583 auto [Offset, IsPtr] = It->second;
8586 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8587 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8591 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8592 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8593 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8597 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8598 return this->
delegate(BD->getBinding());
8604 return this->emitDummyPtr(D, E);
8609 const auto *VD = dyn_cast<VarDecl>(D);
8611 return this->emitError(E);
8614 if (!
Ctx.getLangOpts().CPlusPlus) {
8618 return revisit(VD,
false);
8622 return this->emitDummyPtr(D, E);
8626 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8627 if (
T.isConstant(
Ctx.getASTContext()))
8629 return T->isReferenceType();
8633 typeShouldBeVisited(DeclType)) {
8635 Init && !
Init->isValueDependent()) {
8640 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8653 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8658 return revisit(VD, IsConstexprUnknown);
8659 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8660 return revisit(VD,
true);
8669 return this->emitDummyPtr(
8673template <
class Emitter>
8679template <
class Emitter>
8689 if (!
C->destroyLocals())
8695template <
class Emitter>
8696unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8699 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8701 return Ty->getAsCXXRecordDecl();
8703 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8704 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8706 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8710template <
class Emitter>
8717 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8722 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8723 getFPOptions(E), E);
8725 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8726 getFPOptions(E), E);
8730 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8735 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8737 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8741 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8745 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8746 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8753template <
class Emitter>
8756 assert(FromT != ToT);
8759 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8761 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8763 return this->emitCast(FromT, ToT, E);
8767template <
class Emitter>
8768bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8772 return this->
discard(SubExpr);
8774 if (!this->visit(SubExpr))
8777 if (!this->emitConstUint8(0, SubExpr))
8779 return this->emitArrayElemPtrPopUint8(SubExpr);
8783 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8787template <
class Emitter>
8788bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8789 assert(!DiscardResult);
8793 if (!this->emitArrayElem(ElemT, 0, E))
8796 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8799 if (!this->emitCast(ElemT,
PT_Bool, E))
8804 LabelTy LabelTrue = this->getLabel();
8805 if (!this->jumpTrue(LabelTrue, E))
8808 if (!this->emitArrayElemPop(ElemT, 1, E))
8811 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8814 if (!this->emitCast(ElemT,
PT_Bool, E))
8818 LabelTy EndLabel = this->getLabel();
8819 this->jump(EndLabel, E);
8821 this->emitLabel(LabelTrue);
8822 if (!this->emitPopPtr(E))
8824 if (!this->emitConstBool(
true, E))
8827 this->fallthrough(EndLabel);
8828 this->emitLabel(EndLabel);
8833template <
class Emitter>
8834bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8845 LHSIsComplex =
true;
8846 ElemT = classifyComplexElementType(LHS->
getType());
8847 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8848 if (!this->visit(LHS))
8850 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8853 LHSIsComplex =
false;
8855 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8856 if (!this->visit(LHS))
8858 if (!this->emitSetLocal(LHST, LHSOffset, E))
8865 RHSIsComplex =
true;
8866 ElemT = classifyComplexElementType(RHS->
getType());
8867 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8868 if (!this->visit(RHS))
8870 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8873 RHSIsComplex =
false;
8875 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8876 if (!this->visit(RHS))
8878 if (!this->emitSetLocal(RHST, RHSOffset, E))
8882 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8883 bool IsComplex) ->
bool {
8885 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8887 return this->emitArrayElemPop(ElemT, Index, E);
8889 return this->emitGetLocal(ElemT, LocalOffset, E);
8892 for (
unsigned I = 0; I != 2; ++I) {
8894 if (!getElem(LHSOffset, I, LHSIsComplex))
8896 if (!getElem(RHSOffset, I, RHSIsComplex))
8899 if (!this->emitEQ(ElemT, E))
8902 if (!this->emitCastBoolUint8(E))
8907 if (!this->emitAddUint8(E))
8909 if (!this->emitConstUint8(2, E))
8913 if (!this->emitEQUint8(E))
8916 if (!this->emitNEUint8(E))
8923 return this->emitCast(
PT_Bool, ResT, E);
8930template <
class Emitter>
8931bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8934 assert(!
R->hasTrivialDtor());
8937 const Function *DtorFunc = getFunction(
Dtor);
8940 assert(DtorFunc->hasThisPointer());
8941 assert(DtorFunc->getNumParams() == 1);
8942 return this->emitCall(DtorFunc, 0, Loc);
8947template <
class Emitter>
8948bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8960 return this->emitPopPtr(Loc);
8962 for (ssize_t I = N - 1; I >= 1; --I) {
8963 if (!this->emitConstUint64(I, Loc))
8965 if (!this->emitArrayElemPtrUint64(Loc))
8967 if (!this->emitDestructionPop(ElemDesc, Loc))
8971 if (!this->emitConstUint64(0, Loc))
8973 if (!this->emitArrayElemPtrPopUint64(Loc))
8975 return this->emitDestructionPop(ElemDesc, Loc);
8980 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8985template <
class Emitter>
8986bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8987 assert(!DiscardResult &&
"Should've been checked before");
8988 return this->emitGetOpaquePtr(D, CU, E);
8991template <
class Emitter>
8994 return this->emitConstFloat(
Floating(F), Info);
8996 APInt I = F.bitcastToAPInt();
8997 return this->emitConstFloat(
8998 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8999 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
9010template <
class Emitter>
9011bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
9024 if (!this->emitGetPtrLocal(*LocalIndex, E))
9034 if (!this->visit(SubExpr))
9036 }
else if (
OptPrimType FromT = classify(SubExpr)) {
9037 unsigned TempOffset =
9038 allocateLocalPrimitive(SubExpr, *FromT,
true);
9039 if (!this->visit(SubExpr))
9041 if (!this->emitSetLocal(*FromT, TempOffset, E))
9043 if (!this->emitGetPtrLocal(TempOffset, E))
9050 if (!this->emitBitCast(E))
9052 return DiscardResult ? this->emitPopPtr(E) :
true;
9056 const llvm::fltSemantics *TargetSemantics =
nullptr;
9058 TargetSemantics = &Ctx.getFloatSemantics(ToType);
9064 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
9066 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
9067 ResultBitWidth, TargetSemantics,
9072 return this->emitPop(*ToT, E);
9081template <
class Emitter>
9082bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
9087 unsigned NumElems = 0;
9090 NumElems = VT->getNumElements();
9091 ElemType = VT->getElementType();
9093 NumElems = MT->getNumElementsFlattened();
9094 ElemType = MT->getElementType();
9097 PrimType ElemT = classifyPrim(ElemType);
9098 for (
unsigned I = 0; I != NumElems; ++I) {
9099 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9101 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
9103 if (!this->emitInitElem(ElemT, I, E))
9113 QualType ArrElemType = CAT->getElementType();
9114 unsigned ArrSize = CAT->getZExtSize();
9117 for (
unsigned I = 0; I != ArrSize; ++I) {
9118 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9120 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9122 if (!this->emitInitElem(*ElemT, I, E))
9126 for (
unsigned I = 0; I != ArrSize; ++I) {
9127 if (!this->emitConstUint32(I, E))
9129 if (!this->emitArrayElemPtrUint32(E))
9131 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9133 if (!this->emitFinishInitPop(E))
9143 const Record *
R = getRecord(DestType);
9147 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9149 const Record::Base *B =
R->getBase(BS.getType());
9151 if (!this->emitGetPtrBase(B->Offset, E))
9153 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9155 if (!this->emitFinishInitPop(E))
9160 for (
const Record::Field &F :
R->fields()) {
9161 if (F.isUnnamedBitField())
9164 QualType FieldType = F.Decl->getType();
9166 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9168 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9170 if (F.isBitField()) {
9171 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9174 if (!this->emitInitField(*FieldT, F.Offset, E))
9178 if (!this->emitGetPtrField(F.Offset, E))
9180 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9182 if (!this->emitPopPtr(E))
9195template <
class Emitter>
9196unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9199 return VT->getNumElements();
9201 return MT->getNumElementsFlattened();
9205 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9209 const Record *
R = getRecord(Ty);
9213 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9215 Count += countHLSLFlatElements(BS.getType());
9217 for (
const Record::Field &F :
R->fields()) {
9218 if (F.isUnnamedBitField())
9220 Count += countHLSLFlatElements(F.Decl->getType());
9225 if (canClassify(Ty))
9234template <
class Emitter>
9235bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9236 QualType SrcType,
unsigned SrcOffset,
9241 auto saveToLocal = [&](
PrimType T) ->
bool {
9242 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9243 if (!this->emitSetLocal(
T, Offset, E))
9245 Elements.push_back({Offset,
T});
9251 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9252 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9253 return std::nullopt;
9258 unsigned NumElems = 0;
9261 NumElems = VT->getNumElements();
9262 ElemType = VT->getElementType();
9264 NumElems = MT->getNumElementsFlattened();
9265 ElemType = MT->getElementType();
9268 PrimType ElemT = classifyPrim(ElemType);
9269 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9270 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9272 if (!this->emitArrayElemPop(ElemT, I, E))
9274 if (!saveToLocal(ElemT))
9284 QualType ArrElemType = CAT->getElementType();
9285 unsigned ArrSize = CAT->getZExtSize();
9288 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9289 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9291 if (!this->emitArrayElemPop(*ElemT, I, E))
9293 if (!saveToLocal(*ElemT))
9297 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9298 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9300 if (!this->emitConstUint32(I, E))
9302 if (!this->emitArrayElemPtrPopUint32(E))
9307 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9318 const Record *
R = getRecord(SrcType);
9322 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9324 if (Elements.size() >= MaxElements)
9326 const Record::Base *B =
R->getBase(BS.getType());
9328 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9330 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9335 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9341 for (
const Record::Field &F :
R->fields()) {
9342 if (Elements.size() >= MaxElements)
9344 if (F.isUnnamedBitField())
9347 QualType FieldType = F.Decl->getType();
9348 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9350 if (!this->emitGetPtrFieldPop(F.Offset, E))
9354 if (!this->emitLoadPop(*FieldT, E))
9356 if (!saveToLocal(*FieldT))
9360 if (!FieldPtrOffset)
9362 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9378template <
class Emitter>
9379bool Compiler<Emitter>::emitHLSLConstructAggregate(
9385 const auto &Src = Elements[ElemIdx++];
9386 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9388 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9392 unsigned NumElems = 0;
9395 NumElems = VT->getNumElements();
9396 ElemType = VT->getElementType();
9398 NumElems = MT->getNumElementsFlattened();
9399 ElemType = MT->getElementType();
9402 PrimType DestElemT = classifyPrim(ElemType);
9403 for (
unsigned I = 0; I != NumElems; ++I) {
9404 if (!loadAndCast(DestElemT, ElemType))
9406 if (!this->emitInitElem(DestElemT, I, E))
9416 QualType ArrElemType = CAT->getElementType();
9417 unsigned ArrSize = CAT->getZExtSize();
9420 for (
unsigned I = 0; I != ArrSize; ++I) {
9421 if (!loadAndCast(*ElemT, ArrElemType))
9423 if (!this->emitInitElem(*ElemT, I, E))
9427 for (
unsigned I = 0; I != ArrSize; ++I) {
9428 if (!this->emitConstUint32(I, E))
9430 if (!this->emitArrayElemPtrUint32(E))
9432 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9434 if (!this->emitFinishInitPop(E))
9444 const Record *
R = getRecord(DestType);
9448 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9450 const Record::Base *B =
R->getBase(BS.getType());
9452 if (!this->emitGetPtrBase(B->Offset, E))
9454 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9456 if (!this->emitFinishInitPop(E))
9461 for (
const Record::Field &F :
R->fields()) {
9462 if (F.isUnnamedBitField())
9465 QualType FieldType = F.Decl->getType();
9467 if (!loadAndCast(*FieldT, FieldType))
9469 if (F.isBitField()) {
9470 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9473 if (!this->emitInitField(*FieldT, F.Offset, E))
9477 if (!this->emitGetPtrField(F.Offset, E))
9479 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9481 if (!this->emitPopPtr(E))
static bool visitAPValue(const APValue &Value, llvm::function_ref< bool(const APValue &)> Visitor)
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static bool isTrivialMemoryOperation(const CXXMethodDecl *MD)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
const Expr * ignorePointerCastsAndParens(const Expr *E)
A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. This ignores some c...
bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD)
Determine whether a type would actually be read by an lvalue-to-rvalue conversion.
unsigned ConvertBuiltinIDToX86BuiltinID(const ASTContext &Ctx, unsigned BuiltinOp)
Convert a builtin ID to the canonical x86 builtin ID the constant evaluators dispatch on in their x86...
Result
Implement __builtin_bit_cast and related operations.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() const
bool hasLValuePath() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
CharUnits & getLValueOffset()
APValue & getArrayFiller()
bool isIndeterminate() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Represents a C++26 reflect expression [expr.reflect].
ReflectionKind getKind() const
const void * getOpaqueValue() const
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
A rewritten comparison expression that was originally written using operator syntax.
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Represents the this expression in C++.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
CXXTryStmt - A C++ try block, including all handlers.
CompoundStmt * getTryBlock()
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
const FieldDecl * getTargetUnionField() const
This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits One()
Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
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.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompatibleWith(ClangABI Version) const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
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.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Symbolic representation of typeid(T) for some type T.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
bool isStoredAsComparisonResult() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
ArrayIndexScope(Compiler< Emitter > *Ctx, uint64_t Index)
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
const VarDecl * InitializingDecl
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
bool VisitCXXReflectExpr(const CXXReflectExpr *E)
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool registerRedecl(const VarDecl *VD, const APValue &V)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const VarDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * findVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
VariableScope * getParent() const
uint16_t getPointerAuthTypeDiscriminator(CodeGenModule &CGM, QualType FunctionType)
Return a type discriminator for the given function type.
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool This(InterpState &S, CodePtr OpPC)
constexpr bool isIntegerOrBoolType(PrimType T)
bool InitScope(InterpState &S, uint32_t I)
static void discard(InterpStack &Stk, PrimType T)
static bool isSideEffectFree(const Expr *E)
Check if E has side-effects.
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
static bool Activate(InterpState &S)
static bool exceedsArraySizeLimit(const LangOptions &LangOpts, uint64_t NumElems)
Whether the CheckArraySize op rejects an array with NumElems elements.
bool Init(InterpState &S, CodePtr OpPC)
bool DefaultInit(InterpState &S, CodePtr OpPC, const CXXConstructorDecl *Ctor)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
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 Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...
EvalResult is a struct with detailed info about an evaluated expression.
const ValueDecl * asValueDecl() const
const Expr * asExpr() const
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink Base(unsigned Offset)
static InitLink Decl(const ValueDecl *D)
static InitLink Temp(unsigned Offset)
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()