19#include "llvm/Support/SaveAndRestore.h"
30 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
31 CE && CE->hasAPValueResult() &&
33 return CE->getResultAsAPSInt().getBoolValue();
44 OldInitializingDecl(
Ctx->InitializingDecl) {
45 Ctx->InitializingDecl = VD;
50 this->
Ctx->InitializingDecl = OldInitializingDecl;
51 this->
Ctx->InitStack.pop_back();
64 bool NewInitializing,
bool NewToLValue)
65 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
66 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
67 Ctx->DiscardResult = NewDiscardResult;
68 Ctx->Initializing = NewInitializing;
69 Ctx->ToLValue = NewToLValue;
73 Ctx->DiscardResult = OldDiscardResult;
74 Ctx->Initializing = OldInitializing;
75 Ctx->ToLValue = OldToLValue;
82 bool OldDiscardResult;
87template <
class Emitter>
91 return Ctx->emitThis(E);
94 return Ctx->emitGetPtrFieldPop(
Offset, E);
96 return Ctx->emitGetPtrLocal(
Offset, E);
100 if (!Ctx->emitConstUint32(
Offset, E))
102 return Ctx->emitArrayElemPtrPopUint32(E);
104 return Ctx->emitRVOPtr(E);
108 llvm_unreachable(
"Unhandled InitLink kind");
124 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
125 assert(LI.Name != Name);
128 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
149 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
151 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
152 assert(LI.Name != Name);
155 this->Ctx->CaseLabels = std::move(CaseLabels);
156 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
158 DefaultLabel, Ctx->VarScope);
162 this->Ctx->CaseLabels = std::move(OldCaseLabels);
163 this->Ctx->LabelInfoStack.pop_back();
168 CaseMap OldCaseLabels;
174 Ctx->InStmtExpr =
true;
192 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
195 Ctx->LocOverride = NewValue;
200 Ctx->LocOverride = OldFlag;
205 std::optional<SourceInfo> OldFlag;
212template <
class Emitter>
220 case CK_LValueToRValue: {
231 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
237 if (
auto GlobalIndex =
P.getGlobal(D))
238 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
239 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
240 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
241 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
242 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
243 return this->emitGetParam(*SubExprT, It->second.Index, E);
255 if (!this->emitGetPtrLocal(*LocalIndex, E))
259 if (!this->
visit(SubExpr))
263 return this->emitLoadPop(*SubExprT, E);
268 return this->emitMemcpy(E);
271 case CK_DerivedToBaseMemberPointer: {
282 ->getMostRecentCXXRecordDecl();
284 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
285 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
287 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
295 case CK_BaseToDerivedMemberPointer: {
306 ->getMostRecentCXXRecordDecl();
310 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
312 PathI != PathE; ++PathI) {
313 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
314 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
316 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
323 assert(ToDecl != CurDecl);
324 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
326 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
332 case CK_UncheckedDerivedToBase:
333 case CK_DerivedToBase: {
338 if (
const auto *PT = dyn_cast<PointerType>(Ty))
339 return PT->getPointeeType()->getAsCXXRecordDecl();
340 return Ty->getAsCXXRecordDecl();
347 if (B->isVirtual()) {
348 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
350 CurType = B->getType();
352 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
353 if (!this->emitGetPtrBasePop(
356 CurType = B->getType();
363 case CK_BaseToDerived: {
366 unsigned DerivedOffset =
372 return this->emitGetPtrDerivedPop(DerivedOffset,
377 case CK_FloatingCast: {
382 if (!this->
visit(SubExpr))
384 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
388 case CK_IntegralToFloating: {
391 if (!this->
visit(SubExpr))
393 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
394 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
395 TargetSemantics, getFPOptions(E), E);
398 case CK_FloatingToBoolean: {
402 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
403 return this->emitConstBool(FL->getValue().isNonZero(), E);
404 if (!this->
visit(SubExpr))
406 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
409 case CK_FloatingToIntegral: {
412 if (!this->
visit(SubExpr))
416 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
419 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
422 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
425 case CK_NullToPointer:
426 case CK_NullToMemberPointer: {
431 if (!PointeeType.
isNull()) {
433 Desc =
P.createDescriptor(SubExpr, *T);
435 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
439 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
443 case CK_PointerToIntegral: {
444 if (!this->
visit(SubExpr))
450 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
456 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
458 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
459 return this->emitCastPointerIntegral(T, E);
462 case CK_ArrayToPointerDecay: {
463 if (!this->
visit(SubExpr))
465 return this->emitArrayDecay(E);
468 case CK_IntegralToPointer: {
470 assert(IntType->isIntegralOrEnumerationType());
471 if (!this->
visit(SubExpr))
479 Desc =
P.createDescriptor(SubExpr, *T);
486 if (!this->emitGetIntPtr(T, Desc, E))
494 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
497 case CK_AtomicToNonAtomic:
498 case CK_ConstructorConversion:
499 case CK_FunctionToPointerDecay:
500 case CK_NonAtomicToAtomic:
502 case CK_UserDefinedConversion:
503 case CK_AddressSpaceConversion:
504 case CK_CPointerToObjCPointerCast:
521 return this->emitBuiltinBitCast(E);
536 if (!this->
visit(SubExpr))
544 return this->emitFnPtrCast(E);
551 if (!this->
visit(SubExpr))
553 return this->emitDecayPtr(*FromT, *ToT, E);
555 case CK_IntegralToBoolean:
556 case CK_FixedPointToBoolean: {
562 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
563 return this->emitConst(IL->getValue(), E);
564 if (!this->
visit(SubExpr))
569 case CK_BooleanToSignedIntegral:
570 case CK_IntegralCast: {
577 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
582 if (!this->emitConst(IL->getValue(), SubExpr))
585 if (!this->
visit(SubExpr))
593 if (!ED->isFixed()) {
594 if (!this->emitCheckEnumValue(*FromT, ED, E))
600 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
603 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
608 if (!this->emitCast(*FromT, *ToT, E))
611 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
612 return this->emitNeg(*ToT, E);
616 case CK_PointerToBoolean:
617 case CK_MemberPointerToBoolean: {
620 if (!this->
visit(SubExpr))
622 return this->emitIsNonNull(PtrT, E);
625 case CK_IntegralComplexToBoolean:
626 case CK_FloatingComplexToBoolean: {
627 if (!this->
visit(SubExpr))
629 return this->emitComplexBoolCast(SubExpr);
632 case CK_IntegralComplexToReal:
633 case CK_FloatingComplexToReal:
634 return this->emitComplexReal(SubExpr);
636 case CK_IntegralRealToComplex:
637 case CK_FloatingRealToComplex: {
644 if (!this->emitGetPtrLocal(*LocalIndex, E))
653 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
655 return this->emitInitElem(T, 1, SubExpr);
658 case CK_IntegralComplexCast:
659 case CK_FloatingComplexCast:
660 case CK_IntegralComplexToFloatingComplex:
661 case CK_FloatingComplexToIntegralComplex: {
668 if (!this->emitGetPtrLocal(*LocalIndex, E))
675 unsigned SubExprOffset =
677 if (!this->
visit(SubExpr))
679 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
687 for (
unsigned I = 0; I != 2; ++I) {
688 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
690 if (!this->emitArrayElemPop(SourceElemT, I, E))
694 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
698 if (!this->emitInitElem(DestElemT, I, E))
704 case CK_VectorSplat: {
715 if (!this->emitGetPtrLocal(*LocalIndex, E))
721 unsigned ElemOffset =
725 if (!this->
visit(SubExpr))
730 if (!this->emitSetLocal(ElemT, ElemOffset, E))
733 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
734 if (!this->emitGetLocal(ElemT, ElemOffset, E))
736 if (!this->emitInitElem(ElemT, I, E))
743 case CK_HLSLVectorTruncation: {
748 if (!this->
visit(SubExpr))
750 return this->emitArrayElemPop(*ResultT, 0, E);
759 if (!this->emitGetPtrLocal(*LocalIndex, E))
764 if (!this->
visit(SubExpr))
766 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
770 case CK_IntegralToFixedPoint: {
771 if (!this->
visit(SubExpr))
775 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
779 case CK_FloatingToFixedPoint: {
780 if (!this->
visit(SubExpr))
784 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
785 return this->emitCastFloatingFixedPoint(Sem, E);
787 case CK_FixedPointToFloating: {
788 if (!this->
visit(SubExpr))
790 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
791 return this->emitCastFixedPointFloating(TargetSemantics, E);
793 case CK_FixedPointToIntegral: {
794 if (!this->
visit(SubExpr))
798 case CK_FixedPointCast: {
799 if (!this->
visit(SubExpr))
802 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
803 return this->emitCastFixedPoint(Sem, E);
814 case CK_LValueBitCast:
817 case CK_HLSLArrayRValue: {
824 if (!this->emitGetPtrLocal(*LocalIndex, E))
827 if (!this->
visit(SubExpr))
829 return this->emitMemcpy(E);
832 case CK_HLSLMatrixTruncation: {
837 if (!this->
visit(SubExpr))
839 return this->emitArrayElemPop(*ResultT, 0, E);
848 if (!this->emitGetPtrLocal(*LocalIndex, E))
853 if (!this->
visit(SubExpr))
855 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
859 case CK_HLSLAggregateSplatCast: {
869 if (!this->emitGetPtrLocal(*LocalIndex, E))
879 if (!this->
visit(SubExpr))
881 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
885 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
888 case CK_HLSLElementwiseCast: {
899 unsigned SrcPtrOffset =
901 if (!this->
visit(SubExpr))
903 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
907 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
909 if (Elements.empty())
912 const HLSLFlatElement &Src = Elements[0];
913 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
915 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
922 if (!this->emitGetPtrLocal(*LocalIndex, E))
928 if (!this->
visit(SubExpr))
930 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
934 unsigned ElemCount = countHLSLFlatElements(DestType);
937 Elements.reserve(ElemCount);
938 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
943 assert(Elements.size() == ElemCount &&
944 "Source type has fewer scalar elements than the destination type");
946 return emitHLSLConstructAggregate(DestType, Elements, E);
953 const Record::Field *RF = R->getField(UnionField);
954 QualType FieldType = RF->Decl->getType();
957 if (!this->
visit(SubExpr))
959 if (RF->isBitField())
960 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
962 return this->emitInitFieldActivate(*PT, RF->Offset, E);
965 if (!this->emitGetPtrField(RF->Offset, E))
967 if (!this->emitActivate(E))
971 return this->emitPopPtr(E);
975 return this->emitInvalid(E);
977 llvm_unreachable(
"Unhandled clang::CastKind enum");
980template <
class Emitter>
982 return this->emitBuiltinBitCast(E);
985template <
class Emitter>
990 return this->emitConst(
LE->getValue(),
LE);
993template <
class Emitter>
999 return this->emitFloat(F, E);
1002template <
class Emitter>
1012 if (!this->emitGetPtrLocal(*LocalIndex, E))
1019 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1021 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1026template <
class Emitter>
1034 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1039template <
class Emitter>
1044template <
class Emitter>
1071 return this->emitComplexComparison(LHS, RHS, E);
1079 if (!this->
visit(LHS))
1082 if (!this->
visit(RHS))
1085 if (!this->emitToMemberPtr(E))
1091 if (!this->emitCastMemberPtrPtr(E))
1108 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1114 if (!this->emitGetPtrLocal(*ResultIndex, E))
1121 return this->emitCMP3(*
LT, CmpInfo, E);
1124 if (!
LT || !RT || !T)
1134 return this->visitAssignment(LHS, RHS, E);
1141 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1145 return this->emitPopBool(E);
1147 return this->emitCast(
PT_Bool, *T, E);
1151 auto Discard = [
this, T, E](
bool Result) {
1159 return MaybeCastToBool(this->emitEQ(*
LT, E));
1161 return MaybeCastToBool(this->emitNE(*
LT, E));
1163 return MaybeCastToBool(this->emitLT(*
LT, E));
1165 return MaybeCastToBool(this->emitLE(*
LT, E));
1167 return MaybeCastToBool(this->emitGT(*
LT, E));
1169 return MaybeCastToBool(this->emitGE(*
LT, E));
1172 return Discard(this->emitSubf(getFPOptions(E), E));
1173 return Discard(this->emitSub(*T, E));
1176 return Discard(this->emitAddf(getFPOptions(E), E));
1177 return Discard(this->emitAdd(*T, E));
1180 return Discard(this->emitMulf(getFPOptions(E), E));
1181 return Discard(this->emitMul(*T, E));
1183 return Discard(this->emitRem(*T, E));
1186 return Discard(this->emitDivf(getFPOptions(E), E));
1187 return Discard(this->emitDiv(*T, E));
1189 return Discard(this->emitBitAnd(*T, E));
1191 return Discard(this->emitBitOr(*T, E));
1193 return Discard(this->emitShl(*
LT, *RT, E));
1195 return Discard(this->emitShr(*
LT, *RT, E));
1197 return Discard(this->emitBitXor(*T, E));
1200 llvm_unreachable(
"Already handled earlier");
1205 llvm_unreachable(
"Unhandled binary op");
1210template <
class Emitter>
1216 if ((Op != BO_Add && Op != BO_Sub) ||
1227 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1228 if (!this->
visit(E))
1231 return this->emitDecayPtr(T,
PT_Ptr, E);
1240 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1248 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1251 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1258 if (!visitAsPointer(RHS, *RT))
1260 if (!this->
visit(LHS))
1264 if (!visitAsPointer(LHS, *
LT))
1266 if (!this->
visit(RHS))
1277 if (!this->emitAddOffset(OffsetType, E))
1281 if (!this->emitSubOffset(OffsetType, E))
1298template <
class Emitter>
1308 LabelTy LabelTrue = this->getLabel();
1309 LabelTy LabelEnd = this->getLabel();
1313 if (!this->jumpTrue(LabelTrue, E))
1318 if (!this->jump(LabelEnd, E))
1321 this->emitLabel(LabelTrue);
1322 this->emitConstBool(
true, E);
1323 this->fallthrough(LabelEnd);
1324 this->emitLabel(LabelEnd);
1327 assert(Op == BO_LAnd);
1330 LabelTy LabelFalse = this->getLabel();
1331 LabelTy LabelEnd = this->getLabel();
1335 if (!this->jumpFalse(LabelFalse, E))
1340 if (!this->jump(LabelEnd, E))
1343 this->emitLabel(LabelFalse);
1344 this->emitConstBool(
false, E);
1345 this->fallthrough(LabelEnd);
1346 this->emitLabel(LabelEnd);
1350 return this->emitPopBool(E);
1355 return this->emitCast(
PT_Bool, *T, E);
1359template <
class Emitter>
1366 if (!this->emitGetPtrLocal(*LocalIndex, E))
1375 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1376 unsigned ResultOffset = ~0u;
1382 if (!this->emitDupPtr(E))
1384 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1389 LHSType = AT->getValueType();
1392 RHSType = AT->getValueType();
1401 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1406 if (!this->
visit(LHS))
1408 if (!this->
visit(RHS))
1410 if (!this->emitMulc(ElemT, E))
1413 return this->emitPopPtr(E);
1417 if (Op == BO_Div && RHSIsComplex) {
1424 if (!LHSIsComplex) {
1429 LHSOffset = *LocalIndex;
1431 if (!this->emitGetPtrLocal(LHSOffset, E))
1434 if (!this->
visit(LHS))
1437 if (!this->emitInitElem(ElemT, 0, E))
1440 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1442 if (!this->emitInitElem(ElemT, 1, E))
1445 if (!this->
visit(LHS))
1449 if (!this->
visit(RHS))
1451 if (!this->emitDivc(ElemT, E))
1454 return this->emitPopPtr(E);
1461 if (!this->
visit(LHS))
1463 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1468 if (!this->
visit(LHS))
1470 if (!this->emitSetLocal(LHST, LHSOffset, E))
1478 if (!this->
visit(RHS))
1480 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1485 if (!this->
visit(RHS))
1487 if (!this->emitSetLocal(RHST, RHSOffset, E))
1494 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1495 unsigned ElemIndex,
unsigned Offset,
1496 const Expr *E) ->
bool {
1498 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1500 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1503 if (ElemIndex == 0 || !LoadZero)
1510 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1513 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1520 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1523 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1526 if (!this->emitAddf(getFPOptions(E), E))
1529 if (!this->emitAdd(ResultElemT, E))
1534 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1537 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1540 if (!this->emitSubf(getFPOptions(E), E))
1543 if (!this->emitSub(ResultElemT, E))
1548 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1551 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1555 if (!this->emitMulf(getFPOptions(E), E))
1558 if (!this->emitMul(ResultElemT, E))
1563 assert(!RHSIsComplex);
1564 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1567 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1571 if (!this->emitDivf(getFPOptions(E), E))
1574 if (!this->emitDiv(ResultElemT, E))
1585 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1588 if (!this->emitPop(ResultElemT, E))
1593 return this->emitPopPtr(E);
1599template <
class Emitter>
1604 "Comma op should be handled in VisitBinaryOperator");
1618 if (!this->emitGetPtrLocal(*LocalIndex, E))
1632 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1635 if (!this->
visit(LHS))
1637 if (!this->
visit(RHS))
1639 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1642 return this->emitPopPtr(E);
1647 unsigned LHSOffset =
1649 if (!this->
visit(LHS))
1651 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1655 unsigned RHSOffset =
1657 if (!this->
visit(RHS))
1659 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1671 if (NeedIntPromot) {
1673 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1678 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1679 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1681 if (!this->emitArrayElemPop(ElemT, Index, E))
1684 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1686 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1688 }
else if (NeedIntPromot) {
1689 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1695#define EMIT_ARITH_OP(OP) \
1697 if (ElemT == PT_Float) { \
1698 if (!this->emit##OP##f(getFPOptions(E), E)) \
1701 if (!this->emit##OP(ElemT, E)) \
1707 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1708 if (!getElem(LHSOffset, ElemT, I))
1710 if (!getElem(RHSOffset, RHSElemT, I))
1722 if (!this->emitRem(ElemT, E))
1726 if (!this->emitBitAnd(OpT, E))
1730 if (!this->emitBitOr(OpT, E))
1734 if (!this->emitBitXor(OpT, E))
1738 if (!this->emitShl(OpT, RHSElemT, E))
1742 if (!this->emitShr(OpT, RHSElemT, E))
1746 if (!this->emitEQ(ElemT, E))
1750 if (!this->emitNE(ElemT, E))
1754 if (!this->emitLE(ElemT, E))
1758 if (!this->emitLT(ElemT, E))
1762 if (!this->emitGE(ElemT, E))
1766 if (!this->emitGT(ElemT, E))
1771 if (!this->emitBitAnd(ResultElemT, E))
1776 if (!this->emitBitOr(ResultElemT, E))
1780 return this->emitInvalid(E);
1789 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1791 if (!this->emitNeg(ResultElemT, E))
1797 if (NeedIntPromot &&
1798 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1802 if (!this->emitInitElem(ResultElemT, I, E))
1811template <
class Emitter>
1821 auto LHSSemaInt = LHSSema.toOpaqueInt();
1823 auto RHSSemaInt = RHSSema.toOpaqueInt();
1825 if (!this->
visit(LHS))
1833 if (!this->
visit(RHS))
1842 auto ConvertResult = [&](
bool R) ->
bool {
1846 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1847 if (ResultSema != CommonSema)
1848 return this->emitCastFixedPoint(ResultSema, E);
1852 auto MaybeCastToBool = [&](
bool Result) {
1857 return this->emitPop(T, E);
1859 return this->emitCast(
PT_Bool, T, E);
1865 return MaybeCastToBool(this->emitEQFixedPoint(E));
1867 return MaybeCastToBool(this->emitNEFixedPoint(E));
1869 return MaybeCastToBool(this->emitLTFixedPoint(E));
1871 return MaybeCastToBool(this->emitLEFixedPoint(E));
1873 return MaybeCastToBool(this->emitGTFixedPoint(E));
1875 return MaybeCastToBool(this->emitGEFixedPoint(E));
1877 return ConvertResult(this->emitAddFixedPoint(E));
1879 return ConvertResult(this->emitSubFixedPoint(E));
1881 return ConvertResult(this->emitMulFixedPoint(E));
1883 return ConvertResult(this->emitDivFixedPoint(E));
1885 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1887 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1890 return this->emitInvalid(E);
1893 llvm_unreachable(
"unhandled binop opcode");
1896template <
class Emitter>
1905 if (!this->
visit(SubExpr))
1907 return this->emitNegFixedPoint(E);
1912 llvm_unreachable(
"Unhandled unary opcode");
1915template <
class Emitter>
1924 return this->visitZeroInitializer(*T, QT, E);
1932 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1933 CXXRD && CXXRD->getNumVBases() > 0) {
1943 return this->visitZeroRecordInitializer(R, E);
1950 return this->visitZeroArrayInitializer(QT, E);
1954 QualType ElemQT = ComplexTy->getElementType();
1956 for (
unsigned I = 0; I < 2; ++I) {
1957 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1959 if (!this->emitInitElem(ElemT, I, E))
1966 unsigned NumVecElements = VecT->getNumElements();
1967 QualType ElemQT = VecT->getElementType();
1970 for (
unsigned I = 0; I < NumVecElements; ++I) {
1971 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1973 if (!this->emitInitElem(ElemT, I, E))
1980 unsigned NumElems = MT->getNumElementsFlattened();
1981 QualType ElemQT = MT->getElementType();
1984 for (
unsigned I = 0; I != NumElems; ++I) {
1985 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1987 if (!this->emitInitElem(ElemT, I, E))
1996template <
class Emitter>
2009 for (
const Expr *SubExpr : {LHS, RHS}) {
2010 if (!this->
visit(SubExpr)) {
2017 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2018 if (!this->emitExpandPtr(E))
2029 return this->emitError(E);
2032 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2036 if (!this->emitArrayElemPtrPop(*IndexT, E))
2039 return this->emitPopPtr(E);
2045 return this->emitLoadPop(*T, E);
2048template <
class Emitter>
2050 const Expr *ArrayFiller,
const Expr *E) {
2055 QT = AT->getValueType();
2058 if (
Inits.size() == 0)
2060 return this->emitInvalid(E);
2075 if (
Inits.size() == 0)
2076 return this->visitZeroInitializer(*T, QT, E);
2077 assert(
Inits.size() == 1);
2090 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2097 bool BitField = FieldToInit->isBitField();
2099 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2100 FieldToInit->bitWidth(), E);
2102 return this->emitInitBitField(T, FieldToInit->Offset,
2103 FieldToInit->bitWidth(), E);
2105 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2106 return this->emitInitField(T, FieldToInit->Offset, E);
2109 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2117 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2120 if (
Activate && !this->emitActivate(E))
2125 return this->emitPopPtr(E);
2129 if (
Inits.size() == 0) {
2130 if (!this->visitZeroRecordInitializer(R, E))
2135 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2136 FToInit = ILE->getInitializedFieldInUnion();
2140 const Record::Field *FieldToInit = R->getField(FToInit);
2142 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2145 if (!initCompositeField(FieldToInit,
Init,
true))
2149 return this->emitFinishInit(E);
2152 assert(!R->isUnion());
2153 unsigned InitIndex = 0;
2156 while (InitIndex < R->getNumFields() &&
2157 R->getField(InitIndex)->isUnnamedBitField())
2161 const Record::Field *FieldToInit = R->getField(InitIndex);
2162 if (!initPrimitiveField(FieldToInit,
Init, *T))
2167 if (
const Record::Base *B = R->getBase(
Init->getType())) {
2168 if (!this->emitGetPtrBase(B->Offset,
Init))
2174 if (!this->emitFinishInitPop(E))
2179 const Record::Field *FieldToInit = R->getField(InitIndex);
2180 if (!initCompositeField(FieldToInit,
Init))
2186 return this->emitFinishInit(E);
2190 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2194 Ctx.getASTContext().getAsConstantArrayType(QT);
2197 if (!this->emitCheckArraySize(NumElems, E))
2201 unsigned ElementIndex = 0;
2203 if (
const auto *EmbedS =
2204 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2212 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2213 getFPOptions(E), E))
2219 return this->emitInitElem(TargetT, ElemIndex, IL);
2221 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2233 for (; ElementIndex != NumElems; ++ElementIndex) {
2239 return this->emitFinishInit(E);
2243 unsigned NumInits =
Inits.size();
2248 QualType ElemQT = ComplexTy->getElementType();
2250 if (NumInits == 0) {
2252 for (
unsigned I = 0; I < 2; ++I) {
2253 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2255 if (!this->emitInitElem(ElemT, I, E))
2258 }
else if (NumInits == 2) {
2259 unsigned InitIndex = 0;
2264 if (!this->emitInitElem(ElemT, InitIndex, E))
2273 unsigned NumVecElements = VecT->getNumElements();
2274 assert(NumVecElements >=
Inits.size());
2276 QualType ElemQT = VecT->getElementType();
2280 unsigned InitIndex = 0;
2287 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2288 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2289 InitVecT->getNumElements(), E))
2291 InitIndex += InitVecT->getNumElements();
2293 if (!this->emitInitElem(ElemT, InitIndex, E))
2299 assert(InitIndex <= NumVecElements);
2302 for (; InitIndex != NumVecElements; ++InitIndex) {
2303 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2305 if (!this->emitInitElem(ElemT, InitIndex, E))
2312 unsigned NumElems = MT->getNumElementsFlattened();
2313 assert(
Inits.size() == NumElems);
2315 QualType ElemQT = MT->getElementType();
2321 for (
unsigned I = 0; I != NumElems; ++I) {
2324 if (!this->emitInitElem(ElemT, I, E))
2335template <
class Emitter>
2342 return this->emitInitElem(*InitT, ElemIndex,
Init);
2348 if (!this->emitConstUint32(ElemIndex,
Init))
2350 if (!this->emitArrayElemPtrUint32(
Init))
2354 return this->emitFinishInitPop(
Init);
2357template <
class Emitter>
2360 bool Activate,
bool IsOperatorCall) {
2362 llvm::BitVector NonNullArgs;
2363 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2366 bool ExplicitMemberFn =
false;
2367 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2368 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2370 unsigned ArgIndex = 0;
2371 for (
const Expr *Arg : Args) {
2373 if (!this->
visit(Arg))
2381 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2382 if (DeclIndex < FuncDecl->getNumParams())
2383 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2392 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2400 if (!this->emitActivate(Arg))
2404 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2407 if (!this->emitCheckNonNullArg(ArgT, Arg))
2418template <
class Emitter>
2423template <
class Emitter>
2429template <
class Emitter>
2435template <
class Emitter>
2453template <
class Emitter>
2455 auto It = E->
begin();
2456 return this->
visit(*It);
2461 bool AlignOfReturnsPreferred =
2462 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2468 T = Ref->getPointeeType();
2470 if (T.getQualifiers().hasUnaligned())
2476 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2482template <
class Emitter>
2489 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2495 ArgType = Ref->getPointeeType();
2501 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2502 return this->emitInvalid(E);
2504 if (Kind == UETT_SizeOf)
2513 return this->emitConst(Size.getQuantity(), E);
2516 if (Kind == UETT_CountOf) {
2522 if (
const auto *CAT =
2526 return this->emitConst(CAT->getSize(), E);
2536 if (VAT->getElementType()->isArrayType()) {
2537 std::optional<APSInt> Res =
2539 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2544 return this->emitConst(*Res, E);
2549 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2569 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2572 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2582 return this->emitConst(Size.getQuantity(), E);
2585 if (Kind == UETT_VectorElements) {
2590 return this->emitConst(VT->getNumElements(), E);
2592 return this->emitSizelessVectorElementSize(E);
2595 if (Kind == UETT_VecStep) {
2597 unsigned N = VT->getNumElements();
2604 return this->emitConst(N, E);
2606 return this->emitConst(1, E);
2609 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2616 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2618 return this->emitInvalid(E);
2620 return this->emitConst(
2621 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2629template <
class Emitter>
2638 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2641 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2642 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2644 if (
Member->getType()->isReferenceType())
2645 return this->emitLoadPopPtr(E);
2652 if (!this->
discard(Base) && !this->emitSideEffect(E))
2667 const Record::Field *F = R->getField(FD);
2671 const auto maybeLoadValue = [&]() ->
bool {
2675 return this->emitLoadPop(*T, E);
2680 if (F->Decl->getType()->isReferenceType())
2681 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2682 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2685template <
class Emitter>
2695template <
class Emitter>
2709 if (!this->
visit(Common))
2711 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2725 for (
size_t I = 0; I != Size; ++I) {
2737template <
class Emitter>
2752 return this->emitGetLocal(SubExprT, It->second, E);
2755 if (!this->
visit(SourceExpr))
2762 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2771 return this->emitGetLocal(SubExprT, LocalIndex, E);
2775template <
class Emitter>
2798 bool IsBcpCall =
false;
2799 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2800 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2804 LabelTy LabelEnd = this->getLabel();
2805 LabelTy LabelFalse = this->getLabel();
2808 if (!this->emitPushIgnoreDiags(E))
2816 if (this->checkingForUndefinedBehavior()) {
2819 if (!this->
discard(FalseExpr))
2825 if (!this->jumpFalse(LabelFalse, E))
2830 if (!this->jump(LabelEnd, E))
2832 this->emitLabel(LabelFalse);
2836 this->fallthrough(LabelEnd);
2837 this->emitLabel(LabelEnd);
2840 return this->emitPopIgnoreDiags(E);
2844template <
class Emitter>
2850 unsigned StringIndex =
P.createGlobalString(E);
2851 return this->emitGetPtrGlobal(StringIndex, E);
2856 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2857 assert(CAT &&
"a string literal that's not a constant array?");
2862 unsigned N = std::min(ArraySize, E->
getLength());
2865 for (
unsigned I = 0; I != N; ++I) {
2868 if (CharWidth == 1) {
2869 this->emitConstSint8(CodeUnit, E);
2870 this->emitInitElemSint8(I, E);
2871 }
else if (CharWidth == 2) {
2872 this->emitConstUint16(CodeUnit, E);
2873 this->emitInitElemUint16(I, E);
2874 }
else if (CharWidth == 4) {
2875 this->emitConstUint32(CodeUnit, E);
2876 this->emitInitElemUint32(I, E);
2878 llvm_unreachable(
"unsupported character width");
2883 for (
unsigned I = N; I != ArraySize; ++I) {
2884 if (CharWidth == 1) {
2885 this->emitConstSint8(0, E);
2886 this->emitInitElemSint8(I, E);
2887 }
else if (CharWidth == 2) {
2888 this->emitConstUint16(0, E);
2889 this->emitInitElemUint16(I, E);
2890 }
else if (CharWidth == 4) {
2891 this->emitConstUint32(0, E);
2892 this->emitInitElemUint32(I, E);
2894 llvm_unreachable(
"unsupported character width");
2901template <
class Emitter>
2905 return this->emitDummyPtr(E, E);
2908template <
class Emitter>
2910 auto &A =
Ctx.getASTContext();
2919template <
class Emitter>
2927 auto &A =
Ctx.getASTContext();
2931 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2932 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2939 unsigned StringIndex =
P.createGlobalString(SL);
2940 return this->emitGetPtrGlobal(StringIndex, E);
2943template <
class Emitter>
2947 return this->emitConst(E->
getValue(), E);
2950template <
class Emitter>
2976 if (!this->emitSetLocal(*RT, TempOffset, E))
2982 if (!this->emitLoad(LHST, E))
2986 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2987 LHSComputationType, E))
2991 if (!this->emitGetLocal(*RT, TempOffset, E))
2996 if (!this->emitAddf(getFPOptions(E), E))
3000 if (!this->emitSubf(getFPOptions(E), E))
3004 if (!this->emitMulf(getFPOptions(E), E))
3008 if (!this->emitDivf(getFPOptions(E), E))
3019 return this->emitStorePop(LHST, E);
3020 return this->emitStore(LHST, E);
3023template <
class Emitter>
3032 if (Op != BO_AddAssign && Op != BO_SubAssign)
3041 if (!this->emitLoad(*
LT, LHS))
3047 if (Op == BO_AddAssign) {
3048 if (!this->emitAddOffset(*RT, E))
3051 if (!this->emitSubOffset(*RT, E))
3056 return this->emitStorePopPtr(E);
3057 return this->emitStorePtr(E);
3060template <
class Emitter>
3073 if (!
Ctx.getLangOpts().CPlusPlus14)
3074 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3076 if (!
LT || !RT || !ResultT || !LHSComputationT)
3101 if (!this->emitSetLocal(*RT, TempOffset, E))
3108 if (!this->emitLoad(*
LT, E))
3110 if (
LT != LHSComputationT &&
3116 if (!this->emitGetLocal(*RT, TempOffset, E))
3122 if (!this->emitAdd(*LHSComputationT, E))
3126 if (!this->emitSub(*LHSComputationT, E))
3130 if (!this->emitMul(*LHSComputationT, E))
3134 if (!this->emitDiv(*LHSComputationT, E))
3138 if (!this->emitRem(*LHSComputationT, E))
3142 if (!this->emitShl(*LHSComputationT, *RT, E))
3146 if (!this->emitShr(*LHSComputationT, *RT, E))
3150 if (!this->emitBitAnd(*LHSComputationT, E))
3154 if (!this->emitBitXor(*LHSComputationT, E))
3158 if (!this->emitBitOr(*LHSComputationT, E))
3162 llvm_unreachable(
"Unimplemented compound assign operator");
3166 if (ResultT != LHSComputationT &&
3167 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3173 return this->emitStoreBitFieldPop(*ResultT, E);
3174 return this->emitStorePop(*ResultT, E);
3177 return this->emitStoreBitField(*ResultT, E);
3178 return this->emitStore(*ResultT, E);
3181template <
class Emitter>
3189template <
class Emitter>
3204 if (!
Ctx.getLangOpts().CPlusPlus11)
3211 for (
const Expr *LHS : CommaLHSs) {
3231 if (!this->
visit(Inner))
3233 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3235 return this->emitGetPtrGlobal(*GlobalIndex, E);
3238 if (!this->checkLiteralType(Inner))
3241 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3245 return this->emitInitGlobalTempComp(TempDecl, E);
3256 unsigned LocalIndex =
3258 if (!this->VarScope->LocalsAlwaysEnabled &&
3259 !this->emitEnableLocal(LocalIndex, E))
3262 if (!this->
visit(Inner))
3264 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3267 return this->emitGetPtrLocal(LocalIndex, E);
3270 if (!this->checkLiteralType(Inner))
3277 if (!this->VarScope->LocalsAlwaysEnabled &&
3278 !this->emitEnableLocal(*LocalIndex, E))
3281 if (!this->emitGetPtrLocal(*LocalIndex, E))
3288template <
class Emitter>
3299 if (!this->
visit(SubExpr))
3303 return this->emitPopPtr(E);
3307template <
class Emitter>
3328 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3333 if (
P.isGlobalInitialized(*GlobalIndex))
3339 return this->emitInitGlobal(*T, *GlobalIndex, E);
3351 unsigned LocalIndex;
3355 LocalIndex = *MaybeIndex;
3359 if (!this->emitGetPtrLocal(LocalIndex, E))
3363 return this->
visit(
Init) && this->emitInit(*T, E);
3367template <
class Emitter>
3380template <
class Emitter>
3384 return this->emitConst(E->
getValue(), E);
3387template <
class Emitter>
3400 for (
const Record::Field &F : R->fields()) {
3402 if (!
Init ||
Init->containsErrors())
3410 if (!this->emitInitField(*T, F.Offset, E))
3413 if (!this->emitGetPtrField(F.Offset, E))
3419 if (!this->emitPopPtr(E))
3427template <
class Emitter>
3434 return this->emitGetPtrGlobal(StringIndex, E);
3440template <
class Emitter>
3445 return this->emitInvalid(E);
3448template <
class Emitter>
3474 if (PointeeToT && PointeeFromT) {
3493 bool Fatal = (ToT != FromT);
3500template <
class Emitter>
3503 if (!
Ctx.getLangOpts().CPlusPlus20) {
3511template <
class Emitter>
3517 return this->emitConstBool(E->
getValue(), E);
3520template <
class Emitter>
3525 if (T->isRecordType()) {
3539 if (!this->emitGetPtrLocal(*LocalIndex, E))
3547 T->getAsCXXRecordDecl()))
3557 if (!this->visitZeroRecordInitializer(R, E))
3569 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3571 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3572 if (!this->emitCheckFunctionDecl(Ctor, E))
3583 assert(
Func->hasThisPointer());
3584 assert(!
Func->hasRVO());
3588 if (!this->emitDupPtr(E))
3592 for (
const auto *Arg : E->
arguments()) {
3593 if (!this->
visit(Arg))
3597 if (
Func->isVariadic()) {
3598 uint32_t VarArgSize = 0;
3599 unsigned NumParams =
Func->getNumWrittenParams();
3600 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3604 if (!this->emitCallVar(
Func, VarArgSize, E))
3607 if (!this->emitCall(
Func, 0, E)) {
3612 (void)this->emitPopPtr(E);
3618 return this->emitPopPtr(E);
3619 return this->emitFinishInit(E);
3622 if (T->isArrayType()) {
3627 if (!this->emitDupPtr(E))
3631 initArrayDimension = [&](
QualType T) ->
bool {
3632 if (!T->isArrayType()) {
3634 for (
const auto *Arg : E->
arguments()) {
3635 if (!this->
visit(Arg))
3639 return this->emitCall(
Func, 0, E);
3643 Ctx.getASTContext().getAsConstantArrayType(T);
3648 for (
size_t I = 0; I != NumElems; ++I) {
3649 if (!this->emitConstUint64(I, E))
3651 if (!this->emitArrayElemPtrUint64(E))
3653 if (!initArrayDimension(ElemTy))
3656 return this->emitPopPtr(E);
3659 return initArrayDimension(E->
getType());
3665template <
class Emitter>
3675 assert(Val.
isInt());
3677 return this->emitConst(I, E);
3684 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3685 return this->
visit(LValueExpr);
3700 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3704 const APValue &
V = UGCD->getValue();
3705 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3706 const Record::Field *F = R->getField(I);
3707 const APValue &FieldValue =
V.getStructField(I);
3713 if (!this->emitInitField(FieldT, F->Offset, E))
3721template <
class Emitter>
3727 for (
unsigned I = 0; I != N; ++I) {
3734 if (!this->
discard(ArrayIndexExpr))
3739 if (!this->
visit(ArrayIndexExpr))
3743 if (!this->emitCast(IndexT,
PT_Sint64, E))
3753 return this->emitOffsetOf(T, E, E);
3756template <
class Emitter>
3765 return this->visitZeroInitializer(*T, Ty, E);
3772 if (!this->emitGetPtrLocal(*LocalIndex, E))
3777 QualType ElemQT = CT->getElementType();
3780 for (
unsigned I = 0; I != 2; ++I) {
3781 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3783 if (!this->emitInitElem(ElemT, I, E))
3795 if (!this->emitGetPtrLocal(*LocalIndex, E))
3800 QualType ElemQT = VT->getElementType();
3803 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3804 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3806 if (!this->emitInitElem(ElemT, I, E))
3815template <
class Emitter>
3820template <
class Emitter>
3826template <
class Emitter>
3831template <
class Emitter>
3836 return this->emitConst(E->
getValue(), E);
3839template <
class Emitter>
3844 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3858 unsigned ParamIndex = 0;
3862 if (!this->emitGetParam(PT, ParamIndex, E))
3867 return this->emitCall(F, 0, E);
3872template <
class Emitter>
3880 const Expr *PlacementDest =
nullptr;
3881 bool IsNoThrow =
false;
3886 if (PlacementArgs != 0) {
3895 if (PlacementArgs == 1) {
3903 if (!this->emitInvalidNewDeleteExpr(E, E))
3908 if (OperatorNew->isReservedGlobalPlacementOperator())
3909 PlacementDest = Arg1;
3913 return this->emitInvalid(E);
3915 }
else if (!OperatorNew
3916 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3917 return this->emitInvalidNewDeleteExpr(E, E);
3920 if (!PlacementDest) {
3925 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3928 Desc =
P.createDescriptor(
3931 false,
false,
false,
3937 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3941 const Expr *Stripped = *ArraySizeExpr;
3942 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3943 Stripped = ICE->getSubExpr())
3944 if (ICE->getCastKind() != CK_NoOp &&
3945 ICE->getCastKind() != CK_IntegralCast)
3953 if (!this->
visit(Stripped))
3955 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3958 if (PlacementDest) {
3959 if (!this->
visit(PlacementDest))
3961 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3963 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3966 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3971 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3975 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3982 size_t StaticInitElems = 0;
3983 const Expr *DynamicInit =
nullptr;
3987 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3988 StaticInitElems = CAT->getZExtSize();
3993 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
3994 if (ILE->hasArrayFiller())
3995 DynamicInit = ILE->getArrayFiller();
4014 const Function *CtorFunc =
nullptr;
4015 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4019 }
else if (!DynamicInit && !ElemT)
4022 LabelTy EndLabel = this->getLabel();
4023 LabelTy StartLabel = this->getLabel();
4028 if (!this->emitDupPtr(E))
4030 if (!this->emitNullPtr(0,
nullptr, E))
4032 if (!this->emitEQPtr(E))
4034 if (!this->jumpTrue(EndLabel, E))
4041 if (!this->emitConst(StaticInitElems,
SizeT, E))
4043 if (!this->emitSetLocal(
SizeT, Iter, E))
4046 this->fallthrough(StartLabel);
4047 this->emitLabel(StartLabel);
4049 if (!this->emitGetLocal(
SizeT, Iter, E))
4051 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4053 if (!this->emitLT(
SizeT, E))
4055 if (!this->jumpFalse(EndLabel, E))
4059 if (!this->emitGetLocal(
SizeT, Iter, E))
4061 if (!this->emitArrayElemPtr(
SizeT, E))
4064 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4069 if (!this->visitZeroInitializer(InitT, ElemType, E))
4071 if (!this->emitStorePop(InitT, E))
4073 }
else if (DynamicInit) {
4075 if (!this->
visit(DynamicInit))
4077 if (!this->emitStorePop(*InitT, E))
4082 if (!this->emitPopPtr(E))
4086 if (!this->visitZeroInitializer(
4090 if (!this->emitStorePop(*ElemT, E))
4094 if (!this->emitCall(CtorFunc, 0, E))
4099 if (!this->emitGetPtrLocal(Iter, E))
4101 if (!this->emitIncPop(
SizeT,
false, E))
4104 if (!this->jump(StartLabel, E))
4107 this->fallthrough(EndLabel);
4108 this->emitLabel(EndLabel);
4112 if (PlacementDest) {
4113 if (!this->
visit(PlacementDest))
4115 if (!this->emitCheckNewTypeMismatch(E, E))
4120 if (!this->emitAlloc(Desc, E))
4129 if (!this->emitInit(*ElemT, E))
4140 return this->emitPopPtr(E);
4145template <
class Emitter>
4151 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4152 return this->emitInvalidNewDeleteExpr(E, E);
4161template <
class Emitter>
4167 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4172 return this->emitGetFnPtr(
Func, E);
4175template <
class Emitter>
4179 auto canonType = [](
const Type *T) {
4180 return T->getCanonicalTypeUnqualified().getTypePtr();
4188 return this->emitGetTypeid(
4192 return this->emitGetTypeid(
4201 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4207 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4210 return this->emitPopPtr(E);
4214template <
class Emitter>
4218 return this->emitDummyPtr(E, E);
4219 return this->emitError(E);
4222template <
class Emitter>
4225 return this->emitDummyPtr(E, E);
4226 return this->emitError(E);
4229template <
class Emitter>
4231 assert(
Ctx.getLangOpts().CPlusPlus);
4232 return this->emitConstBool(E->
getValue(), E);
4235template <
class Emitter>
4247 return this->emitDummyPtr(GuidDecl, E);
4252 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4261 assert(
V.isStruct());
4262 assert(
V.getStructNumBases() == 0);
4266 return this->emitFinishInit(E);
4269template <
class Emitter>
4279template <
class Emitter>
4288template <
class Emitter>
4294template <
class Emitter>
4298 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4302 if (OVE->isUnique())
4318template <
class Emitter>
4323template <
class Emitter>
4325 return this->emitError(E);
4328template <
class Emitter>
4334 return this->emitDummyPtr(E, E);
4337template <
class Emitter>
4341 QualType ElemType = VT->getElementType();
4345 PrimType SrcElemT = classifyVectorElementType(SrcType);
4347 unsigned SrcOffset =
4349 if (!this->
visit(Src))
4351 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4354 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4355 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4357 if (!this->emitArrayElemPop(SrcElemT, I, E))
4361 if (SrcElemT != ElemT) {
4362 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4364 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4365 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4369 if (!this->emitInitElem(ElemT, I, E))
4376template <
class Emitter>
4380 return this->emitInvalid(E);
4389 assert(NumOutputElems > 0);
4395 if (!this->emitGetPtrLocal(*LocalIndex, E))
4400 unsigned VectorOffsets[2];
4401 for (
unsigned I = 0; I != 2; ++I) {
4404 if (!this->
visit(Vecs[I]))
4406 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4409 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4411 assert(ShuffleIndex >= -1);
4412 if (ShuffleIndex == -1)
4413 return this->emitInvalidShuffleVectorIndex(I, E);
4415 assert(ShuffleIndex < (NumInputElems * 2));
4416 if (!this->emitGetLocal(
PT_Ptr,
4417 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4419 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4420 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4423 if (!this->emitInitElem(ElemT, I, E))
4428 return this->emitPopPtr(E);
4433template <
class Emitter>
4438 Base->getType()->isVectorType() ||
4444 if (Indices.size() == 1) {
4449 if (!this->emitConstUint32(Indices[0], E))
4451 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4461 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4469 if (!this->emitGetPtrLocal(*ResultIndex, E))
4477 uint32_t DstIndex = 0;
4478 for (uint32_t I : Indices) {
4479 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4481 if (!this->emitArrayElemPop(ElemT, I, E))
4483 if (!this->emitInitElem(ElemT, DstIndex, E))
4493template <
class Emitter>
4497 return this->
discard(SubExpr) && this->emitInvalid(E);
4503 return this->emitDummyPtr(E, E);
4506template <
class Emitter>
4511 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4516 if (!this->
visit(SubExpr))
4518 if (!this->emitConstUint8(0, E))
4520 if (!this->emitArrayElemPtrPopUint8(E))
4522 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4527 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4529 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4531 assert(SecondFieldT ==
PT_Ptr);
4533 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4535 if (!this->emitExpandPtr(E))
4539 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4541 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4544template <
class Emitter>
4559 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4561 return this->emitUnsupported(E);
4570 return this->
Visit(E);
4577 return this->
Visit(E);
4581 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4584 if (
const auto *CE = dyn_cast<CastExpr>(E);
4586 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4593 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4596 if (
const auto *CE = dyn_cast<CastExpr>(E);
4597 CE && (CE->getCastKind() == CK_DerivedToBase ||
4598 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4599 CE->getCastKind() == CK_NoOp))
4619 if (!this->emitGetPtrLocal(*LocalIndex, E))
4629 return this->
Visit(E);
4632template <
class Emitter>
4638 return this->
Visit(E);
4644 return this->
Visit(E);
4655 if (!this->
visit(E))
4657 return this->emitComplexBoolCast(E);
4662 if (!this->
visit(E))
4670 return this->emitIsNonNullPtr(E);
4674 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4677 return this->emitCast(*T,
PT_Bool, E);
4680template <
class Emitter>
4684 QT = AT->getValueType();
4688 return this->emitZeroBool(E);
4690 return this->emitZeroSint8(E);
4692 return this->emitZeroUint8(E);
4694 return this->emitZeroSint16(E);
4696 return this->emitZeroUint16(E);
4698 return this->emitZeroSint32(E);
4700 return this->emitZeroUint32(E);
4702 return this->emitZeroSint64(E);
4704 return this->emitZeroUint64(E);
4706 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4708 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4710 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4713 return this->emitNullMemberPtr(0,
nullptr, E);
4715 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4716 return this->emitFloat(F, E);
4719 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4723 llvm_unreachable(
"unknown primitive type");
4726template <
class Emitter>
4727bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4732 for (
const Record::Field &Field :
R->fields()) {
4733 if (Field.isUnnamedBitField())
4740 if (!this->visitZeroInitializer(T, QT, E))
4743 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4747 if (!this->emitInitField(T, Field.Offset, E))
4752 if (!this->emitGetPtrField(Field.Offset, E))
4758 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4759 if (!this->visitZeroInitializer(T, ET, E))
4761 if (!this->emitInitElem(T, I, E))
4766 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4769 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4777 if (!this->emitFinishInitActivatePop(E))
4781 if (!this->emitFinishInitPop(E))
4785 for (
const Record::Base &B :
R->bases()) {
4786 if (!this->emitGetPtrBase(B.Offset, E))
4788 if (!this->visitZeroRecordInitializer(B.R, E))
4790 if (!this->emitFinishInitPop(E))
4799template <
class Emitter>
4800bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4801 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4807 for (
size_t I = 0; I != NumElems; ++I) {
4808 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4810 if (!this->emitInitElem(*ElemT, I, E))
4816 const Record *
R = getRecord(ElemType);
4820 for (
size_t I = 0; I != NumElems; ++I) {
4821 if (!this->emitConstUint32(I, E))
4823 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4825 if (!this->visitZeroRecordInitializer(R, E))
4827 if (!this->emitPopPtr(E))
4833 for (
size_t I = 0; I != NumElems; ++I) {
4834 if (!this->emitConstUint32(I, E))
4836 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4838 if (!this->visitZeroArrayInitializer(ElemType, E))
4840 if (!this->emitPopPtr(E))
4849template <
class Emitter>
4850bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4852 if (!canClassify(E->
getType()))
4855 if (!this->visit(RHS))
4857 if (!this->visit(LHS))
4864 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4868 bool Activates = refersToUnion(LHS);
4871 if (!this->emitFlip(
PT_Ptr, RHT, E))
4874 if (DiscardResult) {
4875 if (BitField && Activates)
4876 return this->emitStoreBitFieldActivatePop(RHT, E);
4878 return this->emitStoreBitFieldPop(RHT, E);
4880 return this->emitStoreActivatePop(RHT, E);
4882 return this->emitStorePop(RHT, E);
4885 auto maybeLoad = [&](
bool Result) ->
bool {
4891 return this->emitLoadPop(RHT, E);
4895 if (BitField && Activates)
4896 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4898 return maybeLoad(this->emitStoreBitField(RHT, E));
4900 return maybeLoad(this->emitStoreActivate(RHT, E));
4902 return maybeLoad(this->emitStore(RHT, E));
4905template <
class Emitter>
4906template <
typename T>
4910 return this->emitConstSint8(
Value, E);
4912 return this->emitConstUint8(
Value, E);
4914 return this->emitConstSint16(
Value, E);
4916 return this->emitConstUint16(
Value, E);
4918 return this->emitConstSint32(
Value, E);
4920 return this->emitConstUint32(
Value, E);
4922 return this->emitConstSint64(
Value, E);
4924 return this->emitConstUint64(
Value, E);
4926 return this->emitConstBool(
Value, E);
4933 llvm_unreachable(
"Invalid integral type");
4936 llvm_unreachable(
"unknown primitive type");
4939template <
class Emitter>
4940template <
typename T>
4941bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
4942 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4945template <
class Emitter>
4949 return this->emitConstIntAPS(
Value, E);
4951 return this->emitConstIntAP(
Value, E);
4953 if (
Value.isSigned())
4954 return this->emitConst(
Value.getSExtValue(), Ty, E);
4955 return this->emitConst(
Value.getZExtValue(), Ty, E);
4958template <
class Emitter>
4962 return this->emitConstIntAPS(
Value, E);
4964 return this->emitConstIntAP(
Value, E);
4967 return this->emitConst(
Value.getSExtValue(), Ty, E);
4968 return this->emitConst(
Value.getZExtValue(), Ty, E);
4971template <
class Emitter>
4972bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4973 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4976template <
class Emitter>
4989 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4990 Locals.insert({VD, Local});
4991 VarScope->addForScopeKind(Local, SC);
4992 return Local.Offset;
4995template <
class Emitter>
5000 bool IsTemporary =
false;
5001 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5004 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5005 Init = VarD->getInit();
5007 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5018 return std::nullopt;
5023 Locals.insert({Key, Local});
5024 VarScope->addForScopeKind(Local, SC);
5025 return Local.Offset;
5028template <
class Emitter>
5038 return std::nullopt;
5048 return Local.Offset;
5051template <
class Emitter>
5053 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5054 return PT->getPointeeType()->getAsCanonical<RecordType>();
5060 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5064template <
class Emitter>
5066 return P.getOrCreateRecord(RD);
5069template <
class Emitter>
5071 return Ctx.getOrCreateFunction(FD);
5074template <
class Emitter>
5078 auto maybeDestroyLocals = [&]() ->
bool {
5079 if (DestroyToplevelScope)
5080 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5081 return this->emitCheckAllocations(E);
5088 return this->emitRetVoid(E) && maybeDestroyLocals();
5096 return this->emitRet(*T, E) && maybeDestroyLocals();
5104 if (!this->emitGetPtrLocal(*LocalOffset, E))
5110 if (!this->emitFinishInit(E))
5115 return this->emitRetValue(E) && maybeDestroyLocals();
5118 return maybeDestroyLocals() &&
false;
5121template <
class Emitter>
5133 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5134 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5148template <
class Emitter>
5150 bool ConstantContext) {
5153 if (!ConstantContext) {
5167 auto GlobalIndex =
P.getGlobal(VD);
5168 assert(GlobalIndex);
5170 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5173 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5177 auto Local =
Locals.find(VD);
5178 assert(Local !=
Locals.end());
5180 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5183 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5193 auto GlobalIndex =
P.getGlobal(VD);
5194 assert(GlobalIndex);
5195 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5204 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5207template <
class Emitter>
5217 if (!this->isActive())
5222 if (
Init &&
Init->isValueDependent())
5226 auto checkDecl = [&]() ->
bool {
5228 return !NeedsOp || this->emitCheckDecl(VD, VD);
5235 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5238 if (
P.isGlobalInitialized(*GlobalIndex))
5242 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
5256 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5259 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5265 return this->emitFinishInitGlobal(
Init);
5275 if (!
Init ||
Init->getType()->isVoidType())
5284 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5288 return this->emitSetLocal(*VarT, Offset, VD);
5296 if (!this->emitGetPtrLocal(*Offset,
Init))
5302 return this->emitFinishInitPop(
Init);
5307template <
class Emitter>
5312 return this->emitConst(Val.
getInt(), ValType, E);
5315 return this->emitFloat(F, E);
5320 return this->emitGetMemberPtr(MemberDecl, E);
5321 return this->emitNullMemberPtr(0,
nullptr, E);
5326 return this->emitNull(ValType, 0,
nullptr, E);
5331 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5332 return this->
visit(BaseExpr);
5337 QualType EntryType = VD->getType();
5338 for (
auto &Entry : Path) {
5340 uint64_t Index = Entry.getAsArrayIndex();
5343 if (!this->emitConst(Index,
PT_Uint64, E))
5345 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5347 EntryType = ElemType;
5357 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5358 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5360 if (!this->emitGetPtrFieldPop(EntryOffset, E))
5362 EntryType = FD->getType();
5366 if (!this->emitGetPtrBasePop(BaseOffset,
false, E))
5368 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5380template <
class Emitter>
5388 const Record::Field *RF = R->getField(I);
5389 QualType FieldType = RF->Decl->getType();
5395 if (!this->emitInitField(*PT, RF->Offset, E))
5398 if (!this->emitGetPtrField(RF->Offset, E))
5402 if (!this->emitFinishInitPop(E))
5410 const Record::Base *RB = R->getBase(I);
5411 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5413 if (!this->emitGetPtrBase(RB->Offset, E))
5417 if (!this->emitFinishInitPop(E))
5430 const Record::Field *RF = R->getField(UnionField);
5431 QualType FieldType = RF->Decl->getType();
5436 if (RF->isBitField())
5437 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5439 return this->emitInitFieldActivate(*PT, RF->Offset, E);
5442 if (!this->emitGetPtrField(RF->Offset, E))
5444 if (!this->emitActivate(E))
5448 return this->emitPopPtr(E);
5451 const auto *ArrType = T->getAsArrayTypeUnsafe();
5452 QualType ElemType = ArrType->getElementType();
5453 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5458 if (!this->emitInitElem(*ElemT, A, E))
5461 if (!this->emitConstUint32(A, E))
5463 if (!this->emitArrayElemPtrUint32(E))
5467 if (!this->emitPopPtr(E))
5478template <
class Emitter>
5480 unsigned BuiltinID) {
5481 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5486 return this->emitConst(0, E);
5489 if (!this->emitStartSpeculation(E))
5491 LabelTy EndLabel = this->getLabel();
5492 if (!this->speculate(E, EndLabel))
5494 if (!this->emitEndSpeculation(E))
5496 this->fallthrough(EndLabel);
5504 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5505 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5506 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5507 BuiltinID == Builtin::BI__builtin_function_start) {
5510 return this->emitDummyPtr(E, E);
5521 if (!this->emitGetPtrLocal(*LocalIndex, E))
5526 switch (BuiltinID) {
5527 case Builtin::BI__builtin_object_size:
5528 case Builtin::BI__builtin_dynamic_object_size: {
5532 if (!this->
visit(Arg0))
5543 case Builtin::BI__assume:
5544 case Builtin::BI__builtin_assume:
5547 case Builtin::BI__atomic_is_lock_free:
5548 case Builtin::BI__atomic_always_lock_free: {
5559 for (
const auto *Arg : E->
arguments()) {
5560 if (!this->
visit(Arg))
5566 if (!this->emitCallBI(E, BuiltinID, E))
5575template <
class Emitter>
5594 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5595 DD && DD->isTrivial()) {
5597 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5599 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5600 this->emitPopPtr(E);
5608 bool HasRVO = !
ReturnType->isVoidType() && !T;
5616 if (!this->emitGetPtrLocal(*LocalIndex, E))
5624 if (!this->emitGetPtrLocal(*LocalIndex, E))
5628 if (!this->emitDupPtr(E))
5635 bool IsAssignmentOperatorCall =
false;
5636 bool ActivateLHS =
false;
5637 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5638 OCE && OCE->isAssignmentOp()) {
5642 assert(Args.size() == 2);
5643 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
5645 IsAssignmentOperatorCall =
true;
5646 std::reverse(Args.begin(), Args.end());
5652 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5653 MD && MD->isStatic()) {
5657 Args.erase(Args.begin());
5661 bool Devirtualized =
false;
5664 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5672 if (!this->
visit(Callee))
5674 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5676 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5678 if (!this->emitGetMemberPtrBase(E))
5681 const auto *InstancePtr = MC->getImplicitObjectArgument();
5688 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5689 Devirtualized =
true;
5690 if (!this->
visit(Stripped))
5693 if (!this->
visit(InstancePtr))
5697 if (!this->
visit(InstancePtr))
5701 }
else if (
const auto *PD =
5702 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5703 if (!this->emitCheckPseudoDtor(E))
5711 return this->emitEndLifetimePop(E);
5712 }
else if (!FuncDecl) {
5716 if (!this->
visit(Callee))
5718 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5727 if (IsAssignmentOperatorCall) {
5728 assert(Args.size() == 2);
5731 if (!this->emitFlip(Arg2T, Arg1T, E))
5745 assert(HasRVO ==
Func->hasRVO());
5747 bool HasQualifier =
false;
5748 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5749 HasQualifier = ME->hasQualifier();
5751 bool IsVirtual =
false;
5752 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5753 IsVirtual = !Devirtualized && MD->isVirtual();
5758 if (IsVirtual && !HasQualifier) {
5759 uint32_t VarArgSize = 0;
5760 unsigned NumParams =
5762 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5765 if (!this->emitCallVirt(
Func, VarArgSize, E))
5767 }
else if (
Func->isVariadic()) {
5768 uint32_t VarArgSize = 0;
5769 unsigned NumParams =
5771 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5773 if (!this->emitCallVar(
Func, VarArgSize, E))
5776 if (!this->emitCall(
Func, 0, E))
5785 uint32_t ArgSize = 0;
5786 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5792 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5794 if (!this->emitGetMemberPtrDecl(E))
5797 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5800 if (!this->emitCallPtr(ArgSize, E, E))
5811template <
class Emitter>
5818template <
class Emitter>
5825template <
class Emitter>
5830 return this->emitConstBool(E->
getValue(), E);
5833template <
class Emitter>
5839 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5840 return this->emitNullPtr(Val,
nullptr, E);
5843template <
class Emitter>
5851 return this->emitZero(T, E);
5854template <
class Emitter>
5859 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
5860 if (this->LambdaThisCapture.Offset > 0) {
5861 if (this->LambdaThisCapture.IsPtr)
5862 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5863 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5872 return this->emitThis(E);
5887 unsigned StartIndex = 0;
5888 unsigned EndIndex = 0;
5890 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5892 EndIndex = StartIndex;
5899 for (; StartIndex > 0; --StartIndex) {
5909 if (StartIndex == 0 && EndIndex == 0)
5912 assert(StartIndex < EndIndex);
5915 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5927 case Stmt::CompoundStmtClass:
5929 case Stmt::DeclStmtClass:
5931 case Stmt::ReturnStmtClass:
5933 case Stmt::IfStmtClass:
5935 case Stmt::WhileStmtClass:
5937 case Stmt::DoStmtClass:
5939 case Stmt::ForStmtClass:
5941 case Stmt::CXXForRangeStmtClass:
5943 case Stmt::BreakStmtClass:
5945 case Stmt::ContinueStmtClass:
5947 case Stmt::SwitchStmtClass:
5949 case Stmt::CaseStmtClass:
5951 case Stmt::DefaultStmtClass:
5953 case Stmt::AttributedStmtClass:
5955 case Stmt::CXXTryStmtClass:
5957 case Stmt::NullStmtClass:
5960 case Stmt::GCCAsmStmtClass:
5961 case Stmt::MSAsmStmtClass:
5962 case Stmt::GotoStmtClass:
5963 return this->emitInvalid(S);
5964 case Stmt::LabelStmtClass:
5967 if (
const auto *E = dyn_cast<Expr>(S))
5974template <
class Emitter>
5977 for (
const auto *InnerStmt : S->
body())
5980 return Scope.destroyLocals();
5983template <
class Emitter>
5984bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5985 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5986 for (
auto *BD : DD->flat_bindings())
5987 if (
auto *KD = BD->getHoldingVar();
5988 KD && !this->visitVarDecl(KD, KD->getInit()))
6002template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6004 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6005 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6012 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6017 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6018 ICE && (ICE->getCastKind() == CK_NoOp ||
6019 ICE->getCastKind() == CK_DerivedToBase ||
6020 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6021 E = ICE->getSubExpr();
6025 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6026 const auto *ThisRecord =
6027 This->getType()->getPointeeType()->getAsRecordDecl();
6028 if (!ThisRecord->isUnion())
6031 if (
const auto *Ctor =
6032 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6033 return Ctor->getParent() == ThisRecord;
6042template <
class Emitter>
6044 bool EvaluateConditionDecl) {
6045 for (
const auto *D : DS->
decls()) {
6050 const auto *VD = dyn_cast<VarDecl>(D);
6057 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6064template <
class Emitter>
6067 return this->emitUnsupported(RS);
6073 if (!this->
visit(RE))
6079 if (RE->getType()->isVoidType()) {
6080 if (!this->
visit(RE))
6083 if (RE->containsErrors())
6088 if (!this->emitRVOPtr(RE))
6092 if (!this->emitPopPtr(RE))
6096 return this->emitRetVoid(RS);
6102 return this->emitRetVoid(RS);
6108 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6115 if (
auto *CondInit = IS->
getInit()) {
6131 return visitChildStmt(IS->
getThen());
6133 return visitChildStmt(Else);
6139 if (!this->emitIsConstantContext(IS))
6142 if (!this->emitIsConstantContext(IS))
6144 if (!this->emitInv(IS))
6158 LabelTy LabelElse = this->getLabel();
6159 LabelTy LabelEnd = this->getLabel();
6160 if (!this->jumpFalse(LabelElse, IS))
6162 if (!visitChildStmt(IS->
getThen()))
6164 if (!this->jump(LabelEnd, IS))
6166 this->emitLabel(LabelElse);
6167 if (!visitChildStmt(Else))
6169 this->emitLabel(LabelEnd);
6171 LabelTy LabelEnd = this->getLabel();
6172 if (!this->jumpFalse(LabelEnd, IS))
6174 if (!visitChildStmt(IS->
getThen()))
6176 this->emitLabel(LabelEnd);
6185template <
class Emitter>
6190 LabelTy CondLabel = this->getLabel();
6191 LabelTy EndLabel = this->getLabel();
6195 this->fallthrough(CondLabel);
6196 this->emitLabel(CondLabel);
6212 if (!this->jumpFalse(EndLabel, S))
6222 if (!this->jump(CondLabel, S))
6224 this->fallthrough(EndLabel);
6225 this->emitLabel(EndLabel);
6234 LabelTy StartLabel = this->getLabel();
6235 LabelTy EndLabel = this->getLabel();
6236 LabelTy CondLabel = this->getLabel();
6240 this->fallthrough(StartLabel);
6241 this->emitLabel(StartLabel);
6247 this->fallthrough(CondLabel);
6248 this->emitLabel(CondLabel);
6255 if (!this->jumpTrue(StartLabel, S))
6258 this->fallthrough(EndLabel);
6259 this->emitLabel(EndLabel);
6263template <
class Emitter>
6271 LabelTy EndLabel = this->getLabel();
6272 LabelTy CondLabel = this->getLabel();
6273 LabelTy IncLabel = this->getLabel();
6280 this->fallthrough(CondLabel);
6281 this->emitLabel(CondLabel);
6293 if (!this->jumpFalse(EndLabel, S))
6302 this->fallthrough(IncLabel);
6303 this->emitLabel(IncLabel);
6309 if (!this->jump(CondLabel, S))
6313 this->emitLabel(EndLabel);
6319template <
class Emitter>
6329 LabelTy EndLabel = this->getLabel();
6330 LabelTy CondLabel = this->getLabel();
6331 LabelTy IncLabel = this->getLabel();
6346 this->fallthrough(CondLabel);
6347 this->emitLabel(CondLabel);
6350 if (!this->jumpFalse(EndLabel, S))
6361 this->fallthrough(IncLabel);
6362 this->emitLabel(IncLabel);
6367 if (!this->jump(CondLabel, S))
6370 this->fallthrough(EndLabel);
6371 this->emitLabel(EndLabel);
6375template <
class Emitter>
6386 if (LI.BreakLabel) {
6387 TargetLabel = *LI.BreakLabel;
6388 BreakScope = LI.BreakOrContinueScope;
6394 if (LI.Name == TargetLoop) {
6395 TargetLabel = *LI.BreakLabel;
6396 BreakScope = LI.BreakOrContinueScope;
6407 C =
C->getParent()) {
6408 if (!
C->destroyLocals())
6412 return this->jump(*TargetLabel, S);
6415template <
class Emitter>
6426 if (LI.ContinueLabel) {
6427 TargetLabel = *LI.ContinueLabel;
6428 ContinueScope = LI.BreakOrContinueScope;
6434 if (LI.Name == TargetLoop) {
6435 TargetLabel = *LI.ContinueLabel;
6436 ContinueScope = LI.BreakOrContinueScope;
6441 assert(TargetLabel);
6444 C =
C->getParent()) {
6445 if (!
C->destroyLocals())
6449 return this->jump(*TargetLabel, S);
6452template <
class Emitter>
6455 if (
Cond->containsErrors())
6461 LabelTy EndLabel = this->getLabel();
6466 if (
const auto *CondInit = S->
getInit())
6477 if (!this->emitSetLocal(CondT, CondVar, S))
6487 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6490 if (CS->caseStmtIsGNURange()) {
6491 LabelTy EndOfRangeCheck = this->getLabel();
6492 const Expr *Low = CS->getLHS();
6493 const Expr *High = CS->getRHS();
6497 if (!this->emitGetLocal(CondT, CondVar, CS))
6499 if (!this->
visit(Low))
6502 if (!this->emitGE(
LT, S))
6504 if (!this->jumpFalse(EndOfRangeCheck, S))
6507 if (!this->emitGetLocal(CondT, CondVar, CS))
6509 if (!this->
visit(High))
6512 if (!this->emitLE(HT, S))
6516 this->emitLabel(EndOfRangeCheck);
6521 if (
Value->isValueDependent())
6526 if (!this->emitGetLocal(CondT, CondVar, CS))
6532 if (!this->emitEQ(ValueT, S))
6537 assert(!DefaultLabel);
6538 DefaultLabel = this->getLabel();
6545 if (!this->jump(*DefaultLabel, S))
6548 if (!this->jump(EndLabel, S))
6556 this->fallthrough(EndLabel);
6557 this->emitLabel(EndLabel);
6562template <
class Emitter>
6569template <
class Emitter>
6576 if (LI.DefaultLabel) {
6577 DefaultLabel = *LI.DefaultLabel;
6582 this->emitLabel(DefaultLabel);
6586template <
class Emitter>
6593 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6596 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6597 !this->Ctx.getLangOpts().MSVCCompat) {
6599 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6605 const Expr *Assumption = AA->getAssumption();
6616 if (!this->emitAssume(Assumption))
6625 if (IsMSVCConstexprAttr)
6626 return this->emitPopMSVCCE(S);
6630template <
class Emitter>
6636template <
class Emitter>
6637bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6644 assert(ClosureClass->
captures().empty());
6648 "A generic lambda's static-invoker function must be a "
6649 "template specialization");
6653 void *InsertPos =
nullptr;
6654 const FunctionDecl *CorrespondingCallOpSpecialization =
6656 assert(CorrespondingCallOpSpecialization);
6657 LambdaCallOp = CorrespondingCallOpSpecialization;
6661 assert(ClosureClass->
captures().empty());
6662 const Function *
Func = this->getFunction(LambdaCallOp);
6665 assert(
Func->hasThisPointer());
6668 if (
Func->hasRVO()) {
6669 if (!this->emitRVOPtr(MD))
6677 if (!this->emitNullPtr(0,
nullptr, MD))
6682 auto It = this->Params.find(PVD);
6683 assert(It != this->Params.end());
6687 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6688 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6692 if (!this->emitCall(
Func, 0, LambdaCallOp))
6697 return this->emitRet(*ReturnType, MD);
6700 return this->emitRetVoid(MD);
6703template <
class Emitter>
6704bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6705 if (Ctx.getLangOpts().CPlusPlus23)
6715 const Expr *InitExpr =
Init->getInit();
6717 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6721 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6731template <
class Emitter>
6733 assert(!ReturnType);
6735 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6736 const Expr *InitExpr,
6739 if (InitExpr->getType().isNull())
6743 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6746 if (!this->visit(InitExpr))
6749 if (F->isBitField())
6750 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
6752 return this->emitInitThisField(*T, FieldOffset, InitExpr);
6757 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6760 if (
Activate && !this->emitActivate(InitExpr))
6763 if (!this->visitInitializer(InitExpr))
6766 return this->emitFinishInitPop(InitExpr);
6770 const Record *
R = this->getRecord(RD);
6773 bool IsUnion =
R->isUnion();
6778 if (
R->getNumFields() == 0)
6779 return this->emitRetVoid(Ctor);
6782 if (!this->emitThis(Ctor))
6785 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
6788 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6789 this->emitRetVoid(Ctor);
6793 for (
const auto *
Init : Ctor->
inits()) {
6797 const Expr *InitExpr =
Init->getInit();
6799 const Record::Field *F =
R->getField(
Member);
6803 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6806 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6809 if (
Init->isBaseVirtual()) {
6810 assert(
R->getVirtualBase(BaseDecl));
6811 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6817 const Record::Base *B =
R->getBase(BaseDecl);
6819 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6823 if (IsUnion && !this->emitActivate(InitExpr))
6826 if (!this->visitInitializer(InitExpr))
6828 if (!this->emitFinishInitPop(InitExpr))
6833 unsigned ChainSize = IFD->getChainingSize();
6834 assert(ChainSize >= 2);
6836 unsigned NestedFieldOffset = 0;
6837 const Record::Field *NestedField =
nullptr;
6838 for (
unsigned I = 0; I != ChainSize; ++I) {
6840 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6841 assert(FieldRecord);
6843 NestedField = FieldRecord->
getField(FD);
6844 assert(NestedField);
6845 IsUnion = IsUnion || FieldRecord->
isUnion();
6847 NestedFieldOffset += NestedField->Offset;
6850 if (I != ChainSize - 1)
6853 assert(NestedField);
6856 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6861 unsigned InitFieldOffset = 0;
6862 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6864 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6865 assert(FieldRecord);
6866 NestedField = FieldRecord->
getField(FD);
6867 InitFieldOffset += NestedField->Offset;
6868 assert(NestedField);
6869 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6871 if (!this->emitFinishInitPop(InitExpr))
6875 InitStack.pop_back_n(ChainSize - 1);
6878 assert(
Init->isDelegatingInitializer());
6879 if (!this->emitThis(InitExpr))
6881 if (!this->visitInitializer(
Init->getInit()))
6883 if (!this->emitPopPtr(InitExpr))
6887 if (!
Scope.destroyLocals())
6894 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
6895 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
6902 if (!visitStmt(Body))
6909template <
class Emitter>
6912 const Record *
R = this->getRecord(RD);
6917 if (!this->visitStmt(Dtor->
getBody()))
6921 if (!this->emitThis(Dtor))
6924 if (!this->emitCheckDestruction(Dtor))
6928 if (!
R->isUnion()) {
6932 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
6936 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6938 if (!this->emitDestructionPop(D,
SourceInfo{}))
6943 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
6944 if (
Base.R->hasTrivialDtor())
6948 if (!this->emitRecordDestructionPop(
Base.R, {}))
6952 if (!this->emitMarkDestroyed(Dtor))
6956 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6959template <
class Emitter>
6960bool Compiler<Emitter>::compileUnionAssignmentOperator(
6962 if (!this->emitThis(MD))
6965 if (!this->emitGetParam(
PT_Ptr, 0, MD))
6968 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6971template <
class Emitter>
6981 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6982 return this->compileConstructor(Ctor);
6983 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6984 return this->compileDestructor(Dtor);
6987 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6992 return this->compileUnionAssignmentOperator(MD);
6995 return this->emitLambdaStaticInvokerBody(MD);
6999 if (
const auto *Body = F->
getBody())
7013 return FD->getBitWidthValue();
7016template <
class Emitter>
7029 if (!
Ctx.getLangOpts().CPlusPlus14)
7030 return this->emitInvalid(E);
7032 return this->emitError(E);
7034 if (!this->
visit(SubExpr))
7038 if (!this->emitIncPtr(E))
7045 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7046 : this->emitIncf(getFPOptions(E), E);
7058 if (!
Ctx.getLangOpts().CPlusPlus14)
7059 return this->emitInvalid(E);
7061 return this->emitError(E);
7063 if (!this->
visit(SubExpr))
7067 if (!this->emitDecPtr(E))
7074 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7075 : this->emitDecf(getFPOptions(E), E);
7088 if (!
Ctx.getLangOpts().CPlusPlus14)
7089 return this->emitInvalid(E);
7091 return this->emitError(E);
7093 if (!this->
visit(SubExpr))
7097 if (!this->emitLoadPtr(E))
7099 if (!this->emitConstUint8(1, E))
7101 if (!this->emitAddOffsetUint8(E))
7103 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7109 return this->emitIncfPop(getFPOptions(E), E);
7119 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7120 if (!this->emitLoadFloat(E))
7122 APFloat F(TargetSemantics, 1);
7123 if (!this->emitFloat(F, E))
7126 if (!this->emitAddf(getFPOptions(E), E))
7128 if (!this->emitStoreFloat(E))
7140 return E->
isGLValue() || this->emitLoadPop(*T, E);
7143 if (!
Ctx.getLangOpts().CPlusPlus14)
7144 return this->emitInvalid(E);
7146 return this->emitError(E);
7148 if (!this->
visit(SubExpr))
7152 if (!this->emitLoadPtr(E))
7154 if (!this->emitConstUint8(1, E))
7156 if (!this->emitSubOffsetUint8(E))
7158 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7164 return this->emitDecfPop(getFPOptions(E), E);
7174 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7175 if (!this->emitLoadFloat(E))
7177 APFloat F(TargetSemantics, 1);
7178 if (!this->emitFloat(F, E))
7181 if (!this->emitSubf(getFPOptions(E), E))
7183 if (!this->emitStoreFloat(E))
7195 return E->
isGLValue() || this->emitLoadPop(*T, E);
7199 return this->emitError(E);
7202 return this->
discard(SubExpr);
7207 if (!this->emitInv(E))
7211 return this->emitCast(
PT_Bool, ET, E);
7215 return this->emitError(E);
7217 if (!this->
visit(SubExpr))
7219 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7222 return this->emitError(E);
7224 if (!this->
visit(SubExpr))
7239 return this->
discard(SubExpr);
7241 if (!this->
visit(SubExpr))
7248 return this->emitNarrowPtr(E);
7253 return this->emitError(E);
7255 if (!this->
visit(SubExpr))
7257 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7269 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7274 assert(
false &&
"Unhandled opcode");
7280template <
class Emitter>
7286 return this->
discard(SubExpr);
7289 auto prepareResult = [=]() ->
bool {
7294 return this->emitGetPtrLocal(*LocalIndex, E);
7301 unsigned SubExprOffset = ~0u;
7302 auto createTemp = [=, &SubExprOffset]() ->
bool {
7305 if (!this->
visit(SubExpr))
7307 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7311 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7312 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7314 return this->emitArrayElemPop(ElemT, Index, E);
7319 if (!prepareResult())
7323 for (
unsigned I = 0; I != 2; ++I) {
7324 if (!getElem(SubExprOffset, I))
7326 if (!this->emitNeg(ElemT, E))
7328 if (!this->emitInitElem(ElemT, I, E))
7339 if (!this->
visit(SubExpr))
7341 if (!this->emitComplexBoolCast(SubExpr))
7343 if (!this->emitInv(E))
7346 return this->emitCast(
PT_Bool, ET, E);
7350 return this->emitComplexReal(SubExpr);
7353 if (!this->
visit(SubExpr))
7357 if (!this->emitConstUint8(1, E))
7359 return this->emitArrayElemPtrPopUint8(E);
7370 if (!this->emitArrayElem(ElemT, 1, E))
7372 if (!this->emitNeg(ElemT, E))
7374 if (!this->emitInitElem(ElemT, 1, E))
7382 return this->emitInvalid(E);
7388template <
class Emitter>
7394 return this->
discard(SubExpr);
7397 if (UnaryOp == UO_Extension)
7400 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7401 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7402 return this->emitInvalid(E);
7405 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7412 if (!this->emitGetPtrLocal(*LocalIndex, E))
7417 unsigned SubExprOffset =
7419 if (!this->
visit(SubExpr))
7421 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7426 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7427 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7429 return this->emitArrayElemPop(ElemT, Index, E);
7434 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7435 if (!getElem(SubExprOffset, I))
7437 if (!this->emitNeg(ElemT, E))
7439 if (!this->emitInitElem(ElemT, I, E))
7454 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7455 if (!getElem(SubExprOffset, I))
7458 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7460 if (!this->emitInv(E))
7462 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7464 if (!this->emitNeg(ElemT, E))
7466 if (ElemT != ResultVecElemT &&
7467 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7469 if (!this->emitInitElem(ResultVecElemT, I, E))
7475 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7476 if (!getElem(SubExprOffset, I))
7479 if (!this->emitInv(E))
7482 if (!this->emitComp(ElemT, E))
7485 if (!this->emitInitElem(ElemT, I, E))
7490 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7495template <
class Emitter>
7500 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7501 return this->emitConst(ECD->getInitVal(), E);
7502 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7504 return F && this->emitGetFnPtr(F, E);
7506 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7511 return this->emitInitGlobal(*T, *Index, E);
7514 if (!this->emitGetPtrGlobal(*Index, E))
7518 return this->emitFinishInit(E);
7533 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7534 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7539 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7540 if (IsReference || !It->second.IsPtr)
7541 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7543 return this->emitGetPtrParam(It->second.Index, E);
7546 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7552 const unsigned Offset = It->second.Offset;
7555 return this->emitGetRefLocal(Offset, E);
7557 return this->emitGetPtrLocal(Offset, E);
7560 if (
auto GlobalIndex =
P.getGlobal(D)) {
7562 if (!
Ctx.getLangOpts().CPlusPlus11)
7563 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7564 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7567 return this->emitGetPtrGlobal(*GlobalIndex, E);
7571 auto revisit = [&](
const VarDecl *VD,
7572 bool IsConstexprUnknown =
true) ->
bool {
7574 IsConstexprUnknown);
7579 if (!this->emitPopCC(E))
7582 if (VarState.notCreated())
7590 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7592 if (
auto It = this->LambdaCaptures.find(D);
7593 It != this->LambdaCaptures.end()) {
7594 auto [Offset, IsPtr] = It->second;
7597 return this->emitGetThisFieldPtr(Offset, E);
7598 return this->emitGetPtrThisField(Offset, E);
7602 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7603 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7604 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7608 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7609 return this->
visit(BD->getBinding());
7613 return this->emitDummyPtr(D, E);
7617 const auto *VD = dyn_cast<VarDecl>(D);
7619 return this->emitError(E);
7622 if (!
Ctx.getLangOpts().CPlusPlus) {
7625 return revisit(VD,
false);
7626 return this->emitDummyPtr(D, E);
7630 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7631 if (T.isConstant(
Ctx.getASTContext()))
7633 return T->isReferenceType();
7637 typeShouldBeVisited(DeclType)) {
7639 Init && !
Init->isValueDependent()) {
7645 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7659 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7664 return revisit(VD, IsConstexprUnknown);
7665 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7666 return revisit(VD,
true);
7673 return this->emitDummyPtr(D, E);
7676template <
class Emitter>
7684 if (!
C->destroyLocals())
7690template <
class Emitter>
7691unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7694 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7696 return Ty->getAsCXXRecordDecl();
7698 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7699 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7701 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7705template <
class Emitter>
7712 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7717 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7718 getFPOptions(E), E);
7720 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7721 getFPOptions(E), E);
7725 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7730 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7732 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7736 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7740 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7741 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7748template <
class Emitter>
7751 assert(FromT != ToT);
7754 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7756 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7758 return this->emitCast(FromT, ToT, E);
7762template <
class Emitter>
7763bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7767 return this->
discard(SubExpr);
7769 if (!this->visit(SubExpr))
7772 if (!this->emitConstUint8(0, SubExpr))
7774 return this->emitArrayElemPtrPopUint8(SubExpr);
7778 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7782template <
class Emitter>
7783bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7784 assert(!DiscardResult);
7788 if (!this->emitArrayElem(ElemT, 0, E))
7791 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7794 if (!this->emitCast(ElemT,
PT_Bool, E))
7799 LabelTy LabelTrue = this->getLabel();
7800 if (!this->jumpTrue(LabelTrue, E))
7803 if (!this->emitArrayElemPop(ElemT, 1, E))
7806 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7809 if (!this->emitCast(ElemT,
PT_Bool, E))
7813 LabelTy EndLabel = this->getLabel();
7814 this->jump(EndLabel, E);
7816 this->emitLabel(LabelTrue);
7817 if (!this->emitPopPtr(E))
7819 if (!this->emitConstBool(
true, E))
7822 this->fallthrough(EndLabel);
7823 this->emitLabel(EndLabel);
7828template <
class Emitter>
7829bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7840 LHSIsComplex =
true;
7841 ElemT = classifyComplexElementType(LHS->
getType());
7842 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7843 if (!this->visit(LHS))
7845 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7848 LHSIsComplex =
false;
7850 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7851 if (!this->visit(LHS))
7853 if (!this->emitSetLocal(LHST, LHSOffset, E))
7860 RHSIsComplex =
true;
7861 ElemT = classifyComplexElementType(RHS->
getType());
7862 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7863 if (!this->visit(RHS))
7865 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7868 RHSIsComplex =
false;
7870 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7871 if (!this->visit(RHS))
7873 if (!this->emitSetLocal(RHST, RHSOffset, E))
7877 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7878 bool IsComplex) ->
bool {
7880 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7882 return this->emitArrayElemPop(ElemT, Index, E);
7884 return this->emitGetLocal(ElemT, LocalOffset, E);
7887 for (
unsigned I = 0; I != 2; ++I) {
7889 if (!getElem(LHSOffset, I, LHSIsComplex))
7891 if (!getElem(RHSOffset, I, RHSIsComplex))
7894 if (!this->emitEQ(ElemT, E))
7897 if (!this->emitCastBoolUint8(E))
7902 if (!this->emitAddUint8(E))
7904 if (!this->emitConstUint8(2, E))
7908 if (!this->emitEQUint8(E))
7911 if (!this->emitNEUint8(E))
7918 return this->emitCast(
PT_Bool, ResT, E);
7925template <
class Emitter>
7926bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7929 assert(!
R->hasTrivialDtor());
7932 const Function *DtorFunc = getFunction(Dtor);
7935 assert(DtorFunc->hasThisPointer());
7936 assert(DtorFunc->getNumParams() == 1);
7937 return this->emitCall(DtorFunc, 0, Loc);
7942template <
class Emitter>
7943bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7955 return this->emitPopPtr(Loc);
7957 for (ssize_t I = N - 1; I >= 1; --I) {
7958 if (!this->emitConstUint64(I, Loc))
7960 if (!this->emitArrayElemPtrUint64(Loc))
7962 if (!this->emitDestructionPop(ElemDesc, Loc))
7966 if (!this->emitConstUint64(0, Loc))
7968 if (!this->emitArrayElemPtrPopUint64(Loc))
7970 return this->emitDestructionPop(ElemDesc, Loc);
7975 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7980template <
class Emitter>
7981bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7982 assert(!DiscardResult &&
"Should've been checked before");
7983 unsigned DummyID = P.getOrCreateDummy(D);
7985 if (!this->emitGetPtrGlobal(DummyID, E))
7993 return this->emitDecayPtr(
PT_Ptr, PT, E);
7999template <
class Emitter>
8000bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
8002 return this->emitConstFloat(
Floating(F), E);
8004 APInt I = F.bitcastToAPInt();
8005 return this->emitConstFloat(
8006 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8007 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8018template <
class Emitter>
8019bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8032 if (!this->emitGetPtrLocal(*LocalIndex, E))
8042 if (!this->visit(SubExpr))
8044 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8045 unsigned TempOffset =
8046 allocateLocalPrimitive(SubExpr, *FromT,
true);
8047 if (!this->visit(SubExpr))
8049 if (!this->emitSetLocal(*FromT, TempOffset, E))
8051 if (!this->emitGetPtrLocal(TempOffset, E))
8058 if (!this->emitBitCast(E))
8060 return DiscardResult ? this->emitPopPtr(E) :
true;
8064 const llvm::fltSemantics *TargetSemantics =
nullptr;
8066 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8072 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8074 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8075 ResultBitWidth, TargetSemantics,
8080 return this->emitPop(*ToT, E);
8089template <
class Emitter>
8090bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8095 unsigned NumElems = 0;
8098 NumElems = VT->getNumElements();
8099 ElemType = VT->getElementType();
8101 NumElems = MT->getNumElementsFlattened();
8102 ElemType = MT->getElementType();
8105 PrimType ElemT = classifyPrim(ElemType);
8106 for (
unsigned I = 0; I != NumElems; ++I) {
8107 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8109 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8111 if (!this->emitInitElem(ElemT, I, E))
8121 QualType ArrElemType = CAT->getElementType();
8122 unsigned ArrSize = CAT->getZExtSize();
8125 for (
unsigned I = 0; I != ArrSize; ++I) {
8126 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8128 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8130 if (!this->emitInitElem(*ElemT, I, E))
8134 for (
unsigned I = 0; I != ArrSize; ++I) {
8135 if (!this->emitConstUint32(I, E))
8137 if (!this->emitArrayElemPtrUint32(E))
8139 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8141 if (!this->emitFinishInitPop(E))
8151 const Record *
R = getRecord(DestType);
8155 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8157 const Record::Base *B =
R->getBase(BS.getType());
8159 if (!this->emitGetPtrBase(B->Offset, E))
8161 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8163 if (!this->emitFinishInitPop(E))
8168 for (
const Record::Field &F :
R->fields()) {
8169 if (F.isUnnamedBitField())
8172 QualType FieldType = F.Decl->getType();
8174 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8176 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8178 if (F.isBitField()) {
8179 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8182 if (!this->emitInitField(*FieldT, F.Offset, E))
8186 if (!this->emitGetPtrField(F.Offset, E))
8188 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8190 if (!this->emitPopPtr(E))
8203template <
class Emitter>
8204unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8207 return VT->getNumElements();
8209 return MT->getNumElementsFlattened();
8213 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8217 const Record *
R = getRecord(Ty);
8221 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8223 Count += countHLSLFlatElements(BS.getType());
8225 for (
const Record::Field &F :
R->fields()) {
8226 if (F.isUnnamedBitField())
8228 Count += countHLSLFlatElements(F.Decl->getType());
8233 if (canClassify(Ty))
8242template <
class Emitter>
8243bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8244 QualType SrcType,
unsigned SrcOffset,
8249 auto saveToLocal = [&](
PrimType T) ->
bool {
8250 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8251 if (!this->emitSetLocal(T, Offset, E))
8253 Elements.push_back({Offset, T});
8259 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8260 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8261 return std::nullopt;
8266 unsigned NumElems = 0;
8269 NumElems = VT->getNumElements();
8270 ElemType = VT->getElementType();
8272 NumElems = MT->getNumElementsFlattened();
8273 ElemType = MT->getElementType();
8276 PrimType ElemT = classifyPrim(ElemType);
8277 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8278 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8280 if (!this->emitArrayElemPop(ElemT, I, E))
8282 if (!saveToLocal(ElemT))
8292 QualType ArrElemType = CAT->getElementType();
8293 unsigned ArrSize = CAT->getZExtSize();
8296 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8297 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8299 if (!this->emitArrayElemPop(*ElemT, I, E))
8301 if (!saveToLocal(*ElemT))
8305 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8306 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8308 if (!this->emitConstUint32(I, E))
8310 if (!this->emitArrayElemPtrPopUint32(E))
8315 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8326 const Record *
R = getRecord(SrcType);
8330 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8332 if (Elements.size() >= MaxElements)
8334 const Record::Base *B =
R->getBase(BS.getType());
8336 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8338 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8343 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8349 for (
const Record::Field &F :
R->fields()) {
8350 if (Elements.size() >= MaxElements)
8352 if (F.isUnnamedBitField())
8355 QualType FieldType = F.Decl->getType();
8356 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8358 if (!this->emitGetPtrFieldPop(F.Offset, E))
8362 if (!this->emitLoadPop(*FieldT, E))
8364 if (!saveToLocal(*FieldT))
8368 if (!FieldPtrOffset)
8370 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8386template <
class Emitter>
8387bool Compiler<Emitter>::emitHLSLConstructAggregate(
8393 const auto &Src = Elements[ElemIdx++];
8394 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8396 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8400 unsigned NumElems = 0;
8403 NumElems = VT->getNumElements();
8404 ElemType = VT->getElementType();
8406 NumElems = MT->getNumElementsFlattened();
8407 ElemType = MT->getElementType();
8410 PrimType DestElemT = classifyPrim(ElemType);
8411 for (
unsigned I = 0; I != NumElems; ++I) {
8412 if (!loadAndCast(DestElemT, ElemType))
8414 if (!this->emitInitElem(DestElemT, I, E))
8424 QualType ArrElemType = CAT->getElementType();
8425 unsigned ArrSize = CAT->getZExtSize();
8428 for (
unsigned I = 0; I != ArrSize; ++I) {
8429 if (!loadAndCast(*ElemT, ArrElemType))
8431 if (!this->emitInitElem(*ElemT, I, E))
8435 for (
unsigned I = 0; I != ArrSize; ++I) {
8436 if (!this->emitConstUint32(I, E))
8438 if (!this->emitArrayElemPtrUint32(E))
8440 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8442 if (!this->emitFinishInitPop(E))
8452 const Record *
R = getRecord(DestType);
8456 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8458 const Record::Base *B =
R->getBase(BS.getType());
8460 if (!this->emitGetPtrBase(B->Offset, E))
8462 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
8464 if (!this->emitFinishInitPop(E))
8469 for (
const Record::Field &F :
R->fields()) {
8470 if (F.isUnnamedBitField())
8473 QualType FieldType = F.Decl->getType();
8475 if (!loadAndCast(*FieldT, FieldType))
8477 if (F.isBitField()) {
8478 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8481 if (!this->emitInitField(*FieldT, F.Offset, E))
8485 if (!this->emitGetPtrField(F.Offset, E))
8487 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
8489 if (!this->emitPopPtr(E))
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 const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
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
unsigned getStructNumBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
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 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]).
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.
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
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
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.
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
DoStmt - This represents a 'do/while' stmt.
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, void *&InsertPos)
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()
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.
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.
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
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...
uint32_t getCodeUnit(size_t i) const
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.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() 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.
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 isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
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
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.
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.
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
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 visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool visitAPValueInitializer(const APValue &Val, const Expr *E, QualType T)
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)
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)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E)
Visit an APValue.
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
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 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)
const ValueDecl * InitializingDecl
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 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.
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 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.
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)
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 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)
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)
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 ValueDecl *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.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
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 * getBase(unsigned I) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
Describes the statement/declaration an opcode was generated from.
StmtExprScope(Compiler< Emitter > *Ctx)
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.
Compiler< Emitter > * Ctx
Compiler instance.
virtual void addLocal(Scope::Local Local)
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
static bool Activate(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool InitScope(InterpState &S, CodePtr OpPC, uint32_t I)
constexpr bool isIntegerOrBoolType(PrimType T)
static void discard(InterpStack &Stk, PrimType T)
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
bool Init(InterpState &S, CodePtr OpPC)
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)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ 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
U cast(CodeGen::Address addr)
int const char * function
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.
static constexpr MetadataSize InlineDescMD
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 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()