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();
780 return this->emitPopFixedPoint(E);
783 case CK_FloatingToFixedPoint: {
784 if (!this->
visit(SubExpr))
788 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
789 if (!this->emitCastFloatingFixedPoint(Sem, E))
792 return this->emitPopFixedPoint(E);
795 case CK_FixedPointToFloating: {
796 if (!this->
visit(SubExpr))
798 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
799 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
802 return this->emitPopFloat(E);
805 case CK_FixedPointToIntegral: {
806 if (!this->
visit(SubExpr))
809 if (!this->emitCastFixedPointIntegral(IntegralT, E))
812 return this->emitPop(IntegralT, E);
815 case CK_FixedPointCast: {
816 if (!this->
visit(SubExpr))
819 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
820 if (!this->emitCastFixedPoint(Sem, E))
823 return this->emitPopFixedPoint(E);
835 case CK_LValueBitCast:
838 case CK_HLSLArrayRValue: {
845 if (!this->emitGetPtrLocal(*LocalIndex, E))
848 if (!this->
visit(SubExpr))
850 return this->emitMemcpy(E);
853 case CK_HLSLMatrixTruncation: {
858 if (!this->
visit(SubExpr))
860 return this->emitArrayElemPop(*ResultT, 0, E);
869 if (!this->emitGetPtrLocal(*LocalIndex, E))
874 if (!this->
visit(SubExpr))
876 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
880 case CK_HLSLAggregateSplatCast: {
890 if (!this->emitGetPtrLocal(*LocalIndex, E))
900 if (!this->
visit(SubExpr))
902 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
906 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
909 case CK_HLSLElementwiseCast: {
920 unsigned SrcPtrOffset =
922 if (!this->
visit(SubExpr))
924 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
928 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
930 if (Elements.empty())
933 const HLSLFlatElement &Src = Elements[0];
934 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
936 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
943 if (!this->emitGetPtrLocal(*LocalIndex, E))
949 if (!this->
visit(SubExpr))
951 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
955 unsigned ElemCount = countHLSLFlatElements(DestType);
958 Elements.reserve(ElemCount);
959 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
964 assert(Elements.size() == ElemCount &&
965 "Source type has fewer scalar elements than the destination type");
967 return emitHLSLConstructAggregate(DestType, Elements, E);
974 const Record::Field *RF = R->getField(UnionField);
975 QualType FieldType = RF->Decl->getType();
978 if (!this->
visit(SubExpr))
980 if (RF->isBitField())
981 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
983 return this->emitInitFieldActivate(*PT, RF->Offset, E);
986 if (!this->emitGetPtrField(RF->Offset, E))
988 if (!this->emitActivate(E))
994 return this->emitInvalid(E);
996 llvm_unreachable(
"Unhandled clang::CastKind enum");
999template <
class Emitter>
1001 return this->emitBuiltinBitCast(E);
1004template <
class Emitter>
1009 return this->emitConst(
LE->getValue(),
LE);
1012template <
class Emitter>
1018 return this->emitFloat(F, E);
1021template <
class Emitter>
1031 if (!this->emitGetPtrLocal(*LocalIndex, E))
1038 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1040 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1045template <
class Emitter>
1053 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1058template <
class Emitter>
1063template <
class Emitter>
1090 return this->emitComplexComparison(LHS, RHS, E);
1098 if (!this->
visit(LHS))
1101 if (!this->
visit(RHS))
1104 if (!this->emitToMemberPtr(E))
1110 if (!this->emitCastMemberPtrPtr(E))
1127 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1133 if (!this->emitGetPtrLocal(*ResultIndex, E))
1140 return this->emitCMP3(*
LT, CmpInfo, E);
1143 if (!
LT || !RT || !T)
1153 return this->visitAssignment(LHS, RHS, E);
1160 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1164 return this->emitPopBool(E);
1166 return this->emitCast(
PT_Bool, *T, E);
1170 auto Discard = [
this, T, E](
bool Result) {
1178 return MaybeCastToBool(this->emitEQ(*
LT, E));
1180 return MaybeCastToBool(this->emitNE(*
LT, E));
1182 return MaybeCastToBool(this->emitLT(*
LT, E));
1184 return MaybeCastToBool(this->emitLE(*
LT, E));
1186 return MaybeCastToBool(this->emitGT(*
LT, E));
1188 return MaybeCastToBool(this->emitGE(*
LT, E));
1191 return Discard(this->emitSubf(getFPOptions(E), E));
1192 return Discard(this->emitSub(*T, E));
1195 return Discard(this->emitAddf(getFPOptions(E), E));
1196 return Discard(this->emitAdd(*T, E));
1199 return Discard(this->emitMulf(getFPOptions(E), E));
1200 return Discard(this->emitMul(*T, E));
1202 return Discard(this->emitRem(*T, E));
1205 return Discard(this->emitDivf(getFPOptions(E), E));
1206 return Discard(this->emitDiv(*T, E));
1208 return Discard(this->emitBitAnd(*T, E));
1210 return Discard(this->emitBitOr(*T, E));
1212 return Discard(this->emitShl(*
LT, *RT, E));
1214 return Discard(this->emitShr(*
LT, *RT, E));
1216 return Discard(this->emitBitXor(*T, E));
1219 llvm_unreachable(
"Already handled earlier");
1224 llvm_unreachable(
"Unhandled binary op");
1229template <
class Emitter>
1235 if ((Op != BO_Add && Op != BO_Sub) ||
1246 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1247 if (!this->
visit(E))
1250 return this->emitDecayPtr(T,
PT_Ptr, E);
1259 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1267 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1270 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1277 if (!visitAsPointer(RHS, *RT))
1279 if (!this->
visit(LHS))
1283 if (!visitAsPointer(LHS, *
LT))
1285 if (!this->
visit(RHS))
1296 if (!this->emitAddOffset(OffsetType, E))
1300 if (!this->emitSubOffset(OffsetType, E))
1317template <
class Emitter>
1327 LabelTy LabelTrue = this->getLabel();
1328 LabelTy LabelEnd = this->getLabel();
1332 if (!this->jumpTrue(LabelTrue, E))
1337 if (!this->jump(LabelEnd, E))
1340 this->emitLabel(LabelTrue);
1341 this->emitConstBool(
true, E);
1342 this->fallthrough(LabelEnd);
1343 this->emitLabel(LabelEnd);
1346 assert(Op == BO_LAnd);
1349 LabelTy LabelFalse = this->getLabel();
1350 LabelTy LabelEnd = this->getLabel();
1354 if (!this->jumpFalse(LabelFalse, E))
1359 if (!this->jump(LabelEnd, E))
1362 this->emitLabel(LabelFalse);
1363 this->emitConstBool(
false, E);
1364 this->fallthrough(LabelEnd);
1365 this->emitLabel(LabelEnd);
1369 return this->emitPopBool(E);
1374 return this->emitCast(
PT_Bool, *T, E);
1378template <
class Emitter>
1385 if (!this->emitGetPtrLocal(*LocalIndex, E))
1394 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1395 unsigned ResultOffset = ~0u;
1401 if (!this->emitDupPtr(E))
1403 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1408 LHSType = AT->getValueType();
1411 RHSType = AT->getValueType();
1420 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1425 if (!this->
visit(LHS))
1427 if (!this->
visit(RHS))
1429 if (!this->emitMulc(ElemT, E))
1432 return this->emitPopPtr(E);
1436 if (Op == BO_Div && RHSIsComplex) {
1443 if (!LHSIsComplex) {
1448 LHSOffset = *LocalIndex;
1450 if (!this->emitGetPtrLocal(LHSOffset, E))
1453 if (!this->
visit(LHS))
1456 if (!this->emitInitElem(ElemT, 0, E))
1459 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1461 if (!this->emitInitElem(ElemT, 1, E))
1464 if (!this->
visit(LHS))
1468 if (!this->
visit(RHS))
1470 if (!this->emitDivc(ElemT, E))
1473 return this->emitPopPtr(E);
1480 if (!this->
visit(LHS))
1482 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1487 if (!this->
visit(LHS))
1489 if (!this->emitSetLocal(LHST, LHSOffset, E))
1497 if (!this->
visit(RHS))
1499 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1504 if (!this->
visit(RHS))
1506 if (!this->emitSetLocal(RHST, RHSOffset, E))
1513 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1514 unsigned ElemIndex,
unsigned Offset,
1515 const Expr *E) ->
bool {
1517 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1519 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1522 if (ElemIndex == 0 || !LoadZero)
1529 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1532 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1539 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1542 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1545 if (!this->emitAddf(getFPOptions(E), E))
1548 if (!this->emitAdd(ResultElemT, E))
1553 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1556 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1559 if (!this->emitSubf(getFPOptions(E), E))
1562 if (!this->emitSub(ResultElemT, E))
1567 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1570 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1574 if (!this->emitMulf(getFPOptions(E), E))
1577 if (!this->emitMul(ResultElemT, E))
1582 assert(!RHSIsComplex);
1583 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1586 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1590 if (!this->emitDivf(getFPOptions(E), E))
1593 if (!this->emitDiv(ResultElemT, E))
1604 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1607 if (!this->emitPop(ResultElemT, E))
1612 return this->emitPopPtr(E);
1618template <
class Emitter>
1623 "Comma op should be handled in VisitBinaryOperator");
1637 if (!this->emitGetPtrLocal(*LocalIndex, E))
1651 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1654 if (!this->
visit(LHS))
1656 if (!this->
visit(RHS))
1658 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1661 return this->emitPopPtr(E);
1666 unsigned LHSOffset =
1668 if (!this->
visit(LHS))
1670 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1674 unsigned RHSOffset =
1676 if (!this->
visit(RHS))
1678 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1690 if (NeedIntPromot) {
1692 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1697 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1698 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1700 if (!this->emitArrayElemPop(ElemT, Index, E))
1703 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1705 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1707 }
else if (NeedIntPromot) {
1708 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1714#define EMIT_ARITH_OP(OP) \
1716 if (ElemT == PT_Float) { \
1717 if (!this->emit##OP##f(getFPOptions(E), E)) \
1720 if (!this->emit##OP(ElemT, E)) \
1726 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1727 if (!getElem(LHSOffset, ElemT, I))
1729 if (!getElem(RHSOffset, RHSElemT, I))
1741 if (!this->emitRem(ElemT, E))
1745 if (!this->emitBitAnd(OpT, E))
1749 if (!this->emitBitOr(OpT, E))
1753 if (!this->emitBitXor(OpT, E))
1757 if (!this->emitShl(OpT, RHSElemT, E))
1761 if (!this->emitShr(OpT, RHSElemT, E))
1765 if (!this->emitEQ(ElemT, E))
1769 if (!this->emitNE(ElemT, E))
1773 if (!this->emitLE(ElemT, E))
1777 if (!this->emitLT(ElemT, E))
1781 if (!this->emitGE(ElemT, E))
1785 if (!this->emitGT(ElemT, E))
1790 if (!this->emitBitAnd(ResultElemT, E))
1795 if (!this->emitBitOr(ResultElemT, E))
1799 return this->emitInvalid(E);
1808 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1810 if (!this->emitNeg(ResultElemT, E))
1816 if (NeedIntPromot &&
1817 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1821 if (!this->emitInitElem(ResultElemT, I, E))
1830template <
class Emitter>
1840 auto LHSSemaInt = LHSSema.toOpaqueInt();
1842 auto RHSSemaInt = RHSSema.toOpaqueInt();
1844 if (!this->
visit(LHS))
1852 if (!this->
visit(RHS))
1861 auto ConvertResult = [&](
bool R) ->
bool {
1865 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1866 if (ResultSema != CommonSema)
1867 return this->emitCastFixedPoint(ResultSema, E);
1871 auto MaybeCastToBool = [&](
bool Result) {
1876 return this->emitPop(T, E);
1878 return this->emitCast(
PT_Bool, T, E);
1884 return MaybeCastToBool(this->emitEQFixedPoint(E));
1886 return MaybeCastToBool(this->emitNEFixedPoint(E));
1888 return MaybeCastToBool(this->emitLTFixedPoint(E));
1890 return MaybeCastToBool(this->emitLEFixedPoint(E));
1892 return MaybeCastToBool(this->emitGTFixedPoint(E));
1894 return MaybeCastToBool(this->emitGEFixedPoint(E));
1896 return ConvertResult(this->emitAddFixedPoint(E));
1898 return ConvertResult(this->emitSubFixedPoint(E));
1900 return ConvertResult(this->emitMulFixedPoint(E));
1902 return ConvertResult(this->emitDivFixedPoint(E));
1904 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1906 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1909 return this->emitInvalid(E);
1912 llvm_unreachable(
"unhandled binop opcode");
1915template <
class Emitter>
1924 if (!this->
visit(SubExpr))
1926 if (!this->emitNegFixedPoint(E))
1929 return this->emitPopFixedPoint(E);
1935 llvm_unreachable(
"Unhandled unary opcode");
1938template <
class Emitter>
1947 return this->visitZeroInitializer(*T, QT, E);
1955 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1956 CXXRD && CXXRD->getNumVBases() > 0) {
1966 return this->visitZeroRecordInitializer(R, E);
1973 return this->visitZeroArrayInitializer(QT, E);
1977 QualType ElemQT = ComplexTy->getElementType();
1979 for (
unsigned I = 0; I < 2; ++I) {
1980 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1982 if (!this->emitInitElem(ElemT, I, E))
1989 unsigned NumVecElements = VecT->getNumElements();
1990 QualType ElemQT = VecT->getElementType();
1993 for (
unsigned I = 0; I < NumVecElements; ++I) {
1994 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1996 if (!this->emitInitElem(ElemT, I, E))
2003 unsigned NumElems = MT->getNumElementsFlattened();
2004 QualType ElemQT = MT->getElementType();
2007 for (
unsigned I = 0; I != NumElems; ++I) {
2008 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2010 if (!this->emitInitElem(ElemT, I, E))
2019template <
class Emitter>
2032 for (
const Expr *SubExpr : {LHS, RHS}) {
2033 if (!this->
visit(SubExpr)) {
2040 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2041 if (!this->emitExpandPtr(E))
2052 return this->emitError(E);
2055 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2059 if (!this->emitArrayElemPtrPop(*IndexT, E))
2062 return this->emitPopPtr(E);
2068 return this->emitLoadPop(*T, E);
2071template <
class Emitter>
2073 const Expr *ArrayFiller,
const Expr *E) {
2078 QT = AT->getValueType();
2081 if (
Inits.size() == 0)
2083 return this->emitInvalid(E);
2098 if (
Inits.size() == 0)
2099 return this->visitZeroInitializer(*T, QT, E);
2100 assert(
Inits.size() == 1);
2113 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2120 bool BitField = FieldToInit->isBitField();
2122 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2123 FieldToInit->bitWidth(), E);
2125 return this->emitInitBitField(T, FieldToInit->Offset,
2126 FieldToInit->bitWidth(), E);
2128 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2129 return this->emitInitField(T, FieldToInit->Offset, E);
2132 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2140 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2143 if (
Activate && !this->emitActivate(E))
2150 if (
Inits.size() == 0) {
2151 if (!this->visitZeroRecordInitializer(R, E))
2156 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2157 FToInit = ILE->getInitializedFieldInUnion();
2161 const Record::Field *FieldToInit = R->getField(FToInit);
2163 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2166 if (!initCompositeField(FieldToInit,
Init,
true))
2170 return this->emitFinishInit(E);
2173 assert(!R->isUnion());
2174 unsigned InitIndex = 0;
2177 while (InitIndex < R->getNumFields() &&
2178 R->getField(InitIndex)->isUnnamedBitField())
2189 const Record::Field *FieldToInit = R->getField(InitIndex);
2190 if (!initPrimitiveField(FieldToInit,
Init, *T))
2195 if (
const Record::Base *B = R->getBase(
Init->getType())) {
2196 if (!this->emitGetPtrBase(B->Offset,
Init))
2204 const Record::Field *FieldToInit = R->getField(InitIndex);
2205 if (!initCompositeField(FieldToInit,
Init))
2211 return this->emitFinishInit(E);
2216 Ctx.getASTContext().getAsConstantArrayType(QT);
2219 if (
Initializing && !this->emitCheckArrayDestSize(NumElems, E))
2222 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2226 unsigned ElementIndex = 0;
2228 if (
const auto *EmbedS =
2229 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2237 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2238 getFPOptions(E), E))
2244 return this->emitInitElem(TargetT, ElemIndex, IL);
2246 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2262 for (; ElementIndex != NumElems; ++ElementIndex) {
2268 return this->emitFinishInit(E);
2272 unsigned NumInits =
Inits.size();
2277 QualType ElemQT = ComplexTy->getElementType();
2279 if (NumInits == 0) {
2281 for (
unsigned I = 0; I < 2; ++I) {
2282 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2284 if (!this->emitInitElem(ElemT, I, E))
2287 }
else if (NumInits == 2) {
2288 unsigned InitIndex = 0;
2293 if (!this->emitInitElem(ElemT, InitIndex, E))
2302 unsigned NumVecElements = VecT->getNumElements();
2303 assert(NumVecElements >=
Inits.size());
2305 QualType ElemQT = VecT->getElementType();
2309 unsigned InitIndex = 0;
2316 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2317 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2318 InitVecT->getNumElements(), E))
2320 InitIndex += InitVecT->getNumElements();
2322 if (!this->emitInitElem(ElemT, InitIndex, E))
2328 assert(InitIndex <= NumVecElements);
2331 for (; InitIndex != NumVecElements; ++InitIndex) {
2332 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2334 if (!this->emitInitElem(ElemT, InitIndex, E))
2341 unsigned NumElems = MT->getNumElementsFlattened();
2342 assert(
Inits.size() == NumElems);
2344 QualType ElemQT = MT->getElementType();
2350 for (
unsigned I = 0; I != NumElems; ++I) {
2353 if (!this->emitInitElem(ElemT, I, E))
2364template <
class Emitter>
2371 return this->emitInitElem(*InitT, ElemIndex,
Init);
2377 if (!this->emitConstUint32(ElemIndex,
Init))
2379 if (!this->emitArrayElemPtrUint32(
Init))
2384template <
class Emitter>
2387 bool Activate,
bool IsOperatorCall) {
2389 llvm::BitVector NonNullArgs;
2390 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2393 bool ExplicitMemberFn =
false;
2394 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2395 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2397 unsigned ArgIndex = 0;
2398 for (
const Expr *Arg : Args) {
2400 if (!this->
visit(Arg))
2408 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2409 if (DeclIndex < FuncDecl->getNumParams())
2410 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2419 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2427 if (!this->emitActivate(Arg))
2431 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2434 if (!this->emitCheckNonNullArg(ArgT, Arg))
2445template <
class Emitter>
2450template <
class Emitter>
2456template <
class Emitter>
2462template <
class Emitter>
2480template <
class Emitter>
2482 auto It = E->
begin();
2483 return this->
visit(*It);
2488 bool AlignOfReturnsPreferred =
2489 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2495 T = Ref->getPointeeType();
2497 if (T.getQualifiers().hasUnaligned())
2503 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2509template <
class Emitter>
2516 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2522 ArgType = Ref->getPointeeType();
2528 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2529 return this->emitInvalid(E);
2531 if (Kind == UETT_SizeOf)
2540 return this->emitConst(Size.getQuantity(), E);
2543 if (Kind == UETT_CountOf) {
2549 if (
const auto *CAT =
2553 return this->emitConst(CAT->getSize(), E);
2563 if (VAT->getElementType()->isArrayType()) {
2564 std::optional<APSInt> Res =
2566 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2571 return this->emitConst(*Res, E);
2576 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2596 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2599 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2609 return this->emitConst(Size.getQuantity(), E);
2612 if (Kind == UETT_VectorElements) {
2617 return this->emitConst(VT->getNumElements(), E);
2619 return this->emitSizelessVectorElementSize(E);
2622 if (Kind == UETT_VecStep) {
2624 unsigned N = VT->getNumElements();
2631 return this->emitConst(N, E);
2633 return this->emitConst(1, E);
2636 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2643 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2645 return this->emitInvalid(E);
2647 return this->emitConst(
2648 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2656template <
class Emitter>
2665 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2668 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2669 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2671 if (
Member->getType()->isReferenceType())
2672 return this->emitLoadPopPtr(E);
2681 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2682 MD && !MD->isStatic()) {
2686 if (!this->
discard(Base) && !this->emitSideEffect(E))
2701 const Record::Field *F = R->getField(FD);
2705 const auto maybeLoadValue = [&]() ->
bool {
2709 return this->emitLoadPop(*T, E);
2714 if (F->Decl->getType()->isReferenceType())
2715 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2716 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2719template <
class Emitter>
2729template <
class Emitter>
2743 if (!this->
visit(Common))
2745 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2759 for (
size_t I = 0; I != Size; ++I) {
2771template <
class Emitter>
2786 return this->emitGetLocal(SubExprT, It->second, E);
2789 if (!this->
visit(SourceExpr))
2796 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2805 return this->emitGetLocal(SubExprT, LocalIndex, E);
2809template <
class Emitter>
2832 bool IsBcpCall =
false;
2833 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2834 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2838 LabelTy LabelEnd = this->getLabel();
2839 LabelTy LabelFalse = this->getLabel();
2842 if (!this->emitPushIgnoreDiags(E))
2850 if (this->checkingForUndefinedBehavior()) {
2853 if (!this->
discard(FalseExpr))
2859 if (!this->jumpFalse(LabelFalse, E))
2864 if (!this->jump(LabelEnd, E))
2866 this->emitLabel(LabelFalse);
2870 this->fallthrough(LabelEnd);
2871 this->emitLabel(LabelEnd);
2874 return this->emitPopIgnoreDiags(E);
2878template <
class Emitter>
2884 unsigned StringIndex =
P.createGlobalString(E);
2885 return this->emitGetPtrGlobal(StringIndex, E);
2890 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2891 assert(CAT &&
"a string literal that's not a constant array?");
2896 unsigned N = std::min(ArraySize, E->
getLength());
2899 for (
unsigned I = 0; I != N; ++I) {
2902 if (CharWidth == 1) {
2903 this->emitConstSint8(CodeUnit, E);
2904 this->emitInitElemSint8(I, E);
2905 }
else if (CharWidth == 2) {
2906 this->emitConstUint16(CodeUnit, E);
2907 this->emitInitElemUint16(I, E);
2908 }
else if (CharWidth == 4) {
2909 this->emitConstUint32(CodeUnit, E);
2910 this->emitInitElemUint32(I, E);
2912 llvm_unreachable(
"unsupported character width");
2917 for (
unsigned I = N; I != ArraySize; ++I) {
2918 if (CharWidth == 1) {
2919 this->emitConstSint8(0, E);
2920 this->emitInitElemSint8(I, E);
2921 }
else if (CharWidth == 2) {
2922 this->emitConstUint16(0, E);
2923 this->emitInitElemUint16(I, E);
2924 }
else if (CharWidth == 4) {
2925 this->emitConstUint32(0, E);
2926 this->emitInitElemUint32(I, E);
2928 llvm_unreachable(
"unsupported character width");
2935template <
class Emitter>
2939 return this->emitDummyPtr(E, E);
2942template <
class Emitter>
2944 auto &A =
Ctx.getASTContext();
2953template <
class Emitter>
2961 auto &A =
Ctx.getASTContext();
2965 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2966 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2973 unsigned StringIndex =
P.createGlobalString(SL);
2974 return this->emitGetPtrGlobal(StringIndex, E);
2977template <
class Emitter>
2981 return this->emitConst(E->
getValue(), E);
2984template <
class Emitter>
3010 if (!this->emitSetLocal(*RT, TempOffset, E))
3016 if (!this->emitLoad(LHST, E))
3020 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3021 LHSComputationType, E))
3025 if (!this->emitGetLocal(*RT, TempOffset, E))
3030 if (!this->emitAddf(getFPOptions(E), E))
3034 if (!this->emitSubf(getFPOptions(E), E))
3038 if (!this->emitMulf(getFPOptions(E), E))
3042 if (!this->emitDivf(getFPOptions(E), E))
3053 return this->emitStorePop(LHST, E);
3054 return this->emitStore(LHST, E);
3057template <
class Emitter>
3066 if (Op != BO_AddAssign && Op != BO_SubAssign)
3075 if (!this->emitLoad(*
LT, LHS))
3081 if (Op == BO_AddAssign) {
3082 if (!this->emitAddOffset(*RT, E))
3085 if (!this->emitSubOffset(*RT, E))
3090 return this->emitStorePopPtr(E);
3091 return this->emitStorePtr(E);
3094template <
class Emitter>
3107 if (!
Ctx.getLangOpts().CPlusPlus14)
3108 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3110 if (!
LT || !RT || !ResultT || !LHSComputationT)
3135 if (!this->emitSetLocal(*RT, TempOffset, E))
3142 if (!this->emitLoad(*
LT, E))
3144 if (
LT != LHSComputationT &&
3150 if (!this->emitGetLocal(*RT, TempOffset, E))
3156 if (!this->emitAdd(*LHSComputationT, E))
3160 if (!this->emitSub(*LHSComputationT, E))
3164 if (!this->emitMul(*LHSComputationT, E))
3168 if (!this->emitDiv(*LHSComputationT, E))
3172 if (!this->emitRem(*LHSComputationT, E))
3176 if (!this->emitShl(*LHSComputationT, *RT, E))
3180 if (!this->emitShr(*LHSComputationT, *RT, E))
3184 if (!this->emitBitAnd(*LHSComputationT, E))
3188 if (!this->emitBitXor(*LHSComputationT, E))
3192 if (!this->emitBitOr(*LHSComputationT, E))
3196 llvm_unreachable(
"Unimplemented compound assign operator");
3200 if (ResultT != LHSComputationT &&
3201 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3207 return this->emitStoreBitFieldPop(*ResultT, E);
3208 return this->emitStorePop(*ResultT, E);
3211 return this->emitStoreBitField(*ResultT, E);
3212 return this->emitStore(*ResultT, E);
3215template <
class Emitter>
3223template <
class Emitter>
3238 if (!
Ctx.getLangOpts().CPlusPlus11)
3245 for (
const Expr *LHS : CommaLHSs) {
3267 if (!this->
visit(Inner))
3272 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3275 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3278 return this->emitGetPtrGlobal(*GlobalIndex, E);
3281 if (!this->checkLiteralType(Inner))
3284 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3290 return this->emitInitGlobalTempComp(TempDecl, E);
3303 unsigned LocalIndex =
3305 if (!this->VarScope->LocalsAlwaysEnabled &&
3306 !this->emitEnableLocal(LocalIndex, E))
3309 if (!this->
visit(Inner))
3311 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3314 return this->emitGetPtrLocal(LocalIndex, E);
3317 if (!this->checkLiteralType(Inner))
3324 if (!this->VarScope->LocalsAlwaysEnabled &&
3325 !this->emitEnableLocal(*LocalIndex, E))
3328 if (!this->emitGetPtrLocal(*LocalIndex, E))
3335template <
class Emitter>
3346 if (!this->
visit(SubExpr))
3350 return this->emitPopPtr(E);
3354template <
class Emitter>
3375 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3380 if (
P.isGlobalInitialized(*GlobalIndex))
3386 return this->emitInitGlobal(*T, *GlobalIndex, E);
3398 unsigned LocalIndex;
3402 LocalIndex = *MaybeIndex;
3406 if (!this->emitGetPtrLocal(LocalIndex, E))
3410 return this->
visit(
Init) && this->emitInit(*T, E);
3414template <
class Emitter>
3427template <
class Emitter>
3431 return this->emitConst(E->
getValue(), E);
3434template <
class Emitter>
3447 for (
const Record::Field &F : R->fields()) {
3449 if (!
Init ||
Init->containsErrors())
3457 if (!this->emitInitField(*T, F.Offset, E))
3460 if (!this->emitGetPtrField(F.Offset, E))
3471template <
class Emitter>
3478 return this->emitGetPtrGlobal(StringIndex, E);
3484template <
class Emitter>
3489 return this->emitInvalid(E);
3492template <
class Emitter>
3518 if (PointeeToT && PointeeFromT) {
3537 bool Fatal = (ToT != FromT);
3544template <
class Emitter>
3547 if (!
Ctx.getLangOpts().CPlusPlus20) {
3555template <
class Emitter>
3561 return this->emitConstBool(E->
getValue(), E);
3564template <
class Emitter>
3569 if (T->isRecordType()) {
3583 if (!this->emitGetPtrLocal(*LocalIndex, E))
3591 T->getAsCXXRecordDecl()))
3601 if (!this->visitZeroRecordInitializer(R, E))
3613 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3615 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3616 if (!this->emitCheckFunctionDecl(Ctor, E))
3627 assert(
Func->hasThisPointer());
3628 assert(!
Func->hasRVO());
3632 if (!this->emitDupPtr(E))
3636 for (
const auto *Arg : E->
arguments()) {
3637 if (!this->
visit(Arg))
3641 if (
Func->isVariadic()) {
3642 uint32_t VarArgSize = 0;
3643 unsigned NumParams =
Func->getNumWrittenParams();
3644 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3648 if (!this->emitCallVar(
Func, VarArgSize, E))
3651 if (!this->emitCall(
Func, 0, E)) {
3656 (void)this->emitPopPtr(E);
3662 return this->emitPopPtr(E);
3666 if (T->isArrayType()) {
3671 if (!this->emitDupPtr(E))
3675 initArrayDimension = [&](
QualType T) ->
bool {
3676 if (!T->isArrayType()) {
3678 for (
const auto *Arg : E->
arguments()) {
3679 if (!this->
visit(Arg))
3683 return this->emitCall(
Func, 0, E);
3687 Ctx.getASTContext().getAsConstantArrayType(T);
3692 for (
size_t I = 0; I != NumElems; ++I) {
3693 if (!this->emitConstUint64(I, E))
3695 if (!this->emitArrayElemPtrUint64(E))
3697 if (!initArrayDimension(ElemTy))
3700 return this->emitPopPtr(E);
3703 return initArrayDimension(E->
getType());
3709template <
class Emitter>
3719 assert(Val.
isInt());
3721 return this->emitConst(I, E);
3728 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3729 return this->
visit(LValueExpr);
3744 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3748 const APValue &
V = UGCD->getValue();
3749 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3750 const Record::Field *F = R->getField(I);
3751 const APValue &FieldValue =
V.getStructField(I);
3757 if (!this->emitInitField(FieldT, F->Offset, E))
3765template <
class Emitter>
3771 for (
unsigned I = 0; I != N; ++I) {
3778 if (!this->
discard(ArrayIndexExpr))
3783 if (!this->
visit(ArrayIndexExpr))
3787 if (!this->emitCast(IndexT,
PT_Sint64, E))
3797 return this->emitOffsetOf(T, E, E);
3800template <
class Emitter>
3809 return this->visitZeroInitializer(*T, Ty, E);
3816 if (!this->emitGetPtrLocal(*LocalIndex, E))
3821 QualType ElemQT = CT->getElementType();
3824 for (
unsigned I = 0; I != 2; ++I) {
3825 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3827 if (!this->emitInitElem(ElemT, I, E))
3839 if (!this->emitGetPtrLocal(*LocalIndex, E))
3844 QualType ElemQT = VT->getElementType();
3847 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3848 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3850 if (!this->emitInitElem(ElemT, I, E))
3859template <
class Emitter>
3864template <
class Emitter>
3870template <
class Emitter>
3875template <
class Emitter>
3880 return this->emitConst(E->
getValue(), E);
3883template <
class Emitter>
3888 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3902 unsigned ParamIndex = 0;
3906 if (!this->emitGetParam(PT, ParamIndex, E))
3911 return this->emitCall(F, 0, E);
3916template <
class Emitter>
3924 const Expr *PlacementDest =
nullptr;
3925 bool IsNoThrow =
false;
3930 if (PlacementArgs != 0) {
3939 if (PlacementArgs == 1) {
3947 if (!this->emitInvalidNewDeleteExpr(E, E))
3952 if (OperatorNew->isReservedGlobalPlacementOperator())
3953 PlacementDest = Arg1;
3957 return this->emitInvalid(E);
3959 }
else if (!OperatorNew
3960 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3961 return this->emitInvalidNewDeleteExpr(E, E);
3964 if (!PlacementDest) {
3969 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3972 Desc =
P.createDescriptor(
3975 false,
false,
false,
3981 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3985 const Expr *Stripped = *ArraySizeExpr;
3986 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3987 Stripped = ICE->getSubExpr())
3988 if (ICE->getCastKind() != CK_NoOp &&
3989 ICE->getCastKind() != CK_IntegralCast)
3997 if (!this->
visit(Stripped))
3999 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4002 if (PlacementDest) {
4003 if (!this->
visit(PlacementDest))
4005 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4007 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4010 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4015 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4019 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4026 size_t StaticInitElems = 0;
4027 const Expr *DynamicInit =
nullptr;
4031 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4032 StaticInitElems = CAT->getZExtSize();
4037 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4038 if (ILE->hasArrayFiller())
4039 DynamicInit = ILE->getArrayFiller();
4058 const Function *CtorFunc =
nullptr;
4059 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4063 }
else if (!DynamicInit && !ElemT)
4066 LabelTy EndLabel = this->getLabel();
4067 LabelTy StartLabel = this->getLabel();
4072 if (!this->emitDupPtr(E))
4074 if (!this->emitNullPtr(0,
nullptr, E))
4076 if (!this->emitEQPtr(E))
4078 if (!this->jumpTrue(EndLabel, E))
4085 if (!this->emitConst(StaticInitElems,
SizeT, E))
4087 if (!this->emitSetLocal(
SizeT, Iter, E))
4090 this->fallthrough(StartLabel);
4091 this->emitLabel(StartLabel);
4093 if (!this->emitGetLocal(
SizeT, Iter, E))
4095 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4097 if (!this->emitLT(
SizeT, E))
4099 if (!this->jumpFalse(EndLabel, E))
4103 if (!this->emitGetLocal(
SizeT, Iter, E))
4105 if (!this->emitArrayElemPtr(
SizeT, E))
4108 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4113 if (!this->visitZeroInitializer(InitT, ElemType, E))
4115 if (!this->emitStorePop(InitT, E))
4117 }
else if (DynamicInit) {
4119 if (!this->
visit(DynamicInit))
4121 if (!this->emitStorePop(*InitT, E))
4128 if (!this->visitZeroInitializer(
4132 if (!this->emitStorePop(*ElemT, E))
4136 if (!this->emitCall(CtorFunc, 0, E))
4141 if (!this->emitGetPtrLocal(Iter, E))
4143 if (!this->emitIncPop(
SizeT,
false, E))
4146 if (!this->jump(StartLabel, E))
4149 this->fallthrough(EndLabel);
4150 this->emitLabel(EndLabel);
4154 if (PlacementDest) {
4155 if (!this->
visit(PlacementDest))
4157 if (!this->emitCheckNewTypeMismatch(E, E))
4162 if (!this->emitAlloc(Desc, E))
4171 if (!this->emitInit(*ElemT, E))
4182 return this->emitPopPtr(E);
4187template <
class Emitter>
4193 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4194 return this->emitInvalidNewDeleteExpr(E, E);
4203template <
class Emitter>
4209 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4214 return this->emitGetFnPtr(
Func, E);
4217template <
class Emitter>
4221 auto canonType = [](
const Type *T) {
4222 return T->getCanonicalTypeUnqualified().getTypePtr();
4230 return this->emitGetTypeid(
4234 return this->emitGetTypeid(
4243 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4249 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4252 return this->emitPopPtr(E);
4256template <
class Emitter>
4260 return this->emitDummyPtr(E, E);
4261 return this->emitError(E);
4264template <
class Emitter>
4267 return this->emitDummyPtr(E, E);
4268 return this->emitError(E);
4271template <
class Emitter>
4273 assert(
Ctx.getLangOpts().CPlusPlus);
4274 return this->emitConstBool(E->
getValue(), E);
4277template <
class Emitter>
4289 return this->emitDummyPtr(GuidDecl, E);
4294 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4303 assert(
V.isStruct());
4304 assert(
V.getStructNumBases() == 0);
4308 return this->emitFinishInit(E);
4311template <
class Emitter>
4321template <
class Emitter>
4330template <
class Emitter>
4336template <
class Emitter>
4340 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4344 if (OVE->isUnique())
4360template <
class Emitter>
4365template <
class Emitter>
4367 return this->emitError(E);
4370template <
class Emitter>
4376 return this->emitDummyPtr(E, E);
4379template <
class Emitter>
4383 QualType ElemType = VT->getElementType();
4387 PrimType SrcElemT = classifyVectorElementType(SrcType);
4389 unsigned SrcOffset =
4391 if (!this->
visit(Src))
4393 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4396 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4397 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4399 if (!this->emitArrayElemPop(SrcElemT, I, E))
4403 if (SrcElemT != ElemT) {
4404 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4406 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4407 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4411 if (!this->emitInitElem(ElemT, I, E))
4418template <
class Emitter>
4422 return this->emitInvalid(E);
4431 assert(NumOutputElems > 0);
4437 if (!this->emitGetPtrLocal(*LocalIndex, E))
4442 unsigned VectorOffsets[2];
4443 for (
unsigned I = 0; I != 2; ++I) {
4446 if (!this->
visit(Vecs[I]))
4448 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4451 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4453 assert(ShuffleIndex >= -1);
4454 if (ShuffleIndex == -1)
4455 return this->emitInvalidShuffleVectorIndex(I, E);
4457 assert(ShuffleIndex < (NumInputElems * 2));
4458 if (!this->emitGetLocal(
PT_Ptr,
4459 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4461 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4462 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4465 if (!this->emitInitElem(ElemT, I, E))
4470 return this->emitPopPtr(E);
4475template <
class Emitter>
4480 Base->getType()->isVectorType() ||
4486 if (Indices.size() == 1) {
4491 if (!this->emitConstUint32(Indices[0], E))
4493 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4503 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4511 if (!this->emitGetPtrLocal(*ResultIndex, E))
4519 uint32_t DstIndex = 0;
4520 for (uint32_t I : Indices) {
4521 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4523 if (!this->emitArrayElemPop(ElemT, I, E))
4525 if (!this->emitInitElem(ElemT, DstIndex, E))
4535template <
class Emitter>
4539 return this->
discard(SubExpr) && this->emitInvalid(E);
4545 return this->emitDummyPtr(E, E);
4548template <
class Emitter>
4553 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4558 if (!this->
visit(SubExpr))
4560 if (!this->emitConstUint8(0, E))
4562 if (!this->emitArrayElemPtrPopUint8(E))
4564 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4569 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4571 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4573 assert(SecondFieldT ==
PT_Ptr);
4575 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4577 if (!this->emitExpandPtr(E))
4581 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4583 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4586template <
class Emitter>
4601 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4603 return this->emitUnsupported(E);
4612 return this->
Visit(E);
4619 return this->
Visit(E);
4623 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4626 if (
const auto *CE = dyn_cast<CastExpr>(E);
4628 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4635 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4638 if (
const auto *CE = dyn_cast<CastExpr>(E);
4639 CE && (CE->getCastKind() == CK_DerivedToBase ||
4640 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4641 CE->getCastKind() == CK_NoOp))
4661 if (!this->emitGetPtrLocal(*LocalIndex, E))
4671 return this->
Visit(E);
4674template <
class Emitter>
4680 return this->
Visit(E) && this->emitFinishInit(E);
4683template <
class Emitter>
4689 return this->
Visit(E) && this->emitFinishInitPop(E);
4695 return this->
Visit(E);
4706 if (!this->
visit(E))
4708 return this->emitComplexBoolCast(E);
4713 if (!this->
visit(E))
4721 return this->emitIsNonNullPtr(E);
4725 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4728 return this->emitCast(*T,
PT_Bool, E);
4731template <
class Emitter>
4735 QT = AT->getValueType();
4739 return this->emitZeroBool(E);
4741 return this->emitZeroSint8(E);
4743 return this->emitZeroUint8(E);
4745 return this->emitZeroSint16(E);
4747 return this->emitZeroUint16(E);
4749 return this->emitZeroSint32(E);
4751 return this->emitZeroUint32(E);
4753 return this->emitZeroSint64(E);
4755 return this->emitZeroUint64(E);
4757 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4759 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4761 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4764 return this->emitNullMemberPtr(0,
nullptr, E);
4766 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4767 return this->emitFloat(F, E);
4770 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
4774 llvm_unreachable(
"unknown primitive type");
4777template <
class Emitter>
4778bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4783 for (
const Record::Field &Field :
R->fields()) {
4784 if (Field.isUnnamedBitField())
4791 if (!this->visitZeroInitializer(T, QT, E))
4794 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4798 if (!this->emitInitField(T, Field.Offset, E))
4803 if (!this->emitGetPtrField(Field.Offset, E))
4809 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4810 if (!this->visitZeroInitializer(T, ET, E))
4812 if (!this->emitInitElem(T, I, E))
4817 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4820 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4828 if (!this->emitFinishInitActivatePop(E))
4832 if (!this->emitFinishInitPop(E))
4836 for (
const Record::Base &B :
R->bases()) {
4837 if (!this->emitGetPtrBase(B.Offset, E))
4839 if (!this->visitZeroRecordInitializer(B.R, E))
4841 if (!this->emitFinishInitPop(E))
4850template <
class Emitter>
4851bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4852 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4858 for (
size_t I = 0; I != NumElems; ++I) {
4859 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4861 if (!this->emitInitElem(*ElemT, I, E))
4867 const Record *
R = getRecord(ElemType);
4871 for (
size_t I = 0; I != NumElems; ++I) {
4872 if (!this->emitConstUint32(I, E))
4874 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4876 if (!this->visitZeroRecordInitializer(R, E))
4878 if (!this->emitPopPtr(E))
4884 for (
size_t I = 0; I != NumElems; ++I) {
4885 if (!this->emitConstUint32(I, E))
4887 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4889 if (!this->visitZeroArrayInitializer(ElemType, E))
4891 if (!this->emitPopPtr(E))
4900template <
class Emitter>
4901bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4903 if (!canClassify(E->
getType()))
4906 if (!this->visit(RHS))
4908 if (!this->visit(LHS))
4915 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4919 bool Activates = refersToUnion(LHS);
4922 if (!this->emitFlip(
PT_Ptr, RHT, E))
4925 if (DiscardResult) {
4926 if (BitField && Activates)
4927 return this->emitStoreBitFieldActivatePop(RHT, E);
4929 return this->emitStoreBitFieldPop(RHT, E);
4931 return this->emitStoreActivatePop(RHT, E);
4933 return this->emitStorePop(RHT, E);
4936 auto maybeLoad = [&](
bool Result) ->
bool {
4942 return this->emitLoadPop(RHT, E);
4946 if (BitField && Activates)
4947 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4949 return maybeLoad(this->emitStoreBitField(RHT, E));
4951 return maybeLoad(this->emitStoreActivate(RHT, E));
4953 return maybeLoad(this->emitStore(RHT, E));
4956template <
class Emitter>
4957template <
typename T>
4961 return this->emitConstSint8(
Value, E);
4963 return this->emitConstUint8(
Value, E);
4965 return this->emitConstSint16(
Value, E);
4967 return this->emitConstUint16(
Value, E);
4969 return this->emitConstSint32(
Value, E);
4971 return this->emitConstUint32(
Value, E);
4973 return this->emitConstSint64(
Value, E);
4975 return this->emitConstUint64(
Value, E);
4977 return this->emitConstBool(
Value, E);
4984 llvm_unreachable(
"Invalid integral type");
4987 llvm_unreachable(
"unknown primitive type");
4990template <
class Emitter>
4991template <
typename T>
4992bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
4993 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4996template <
class Emitter>
5000 return this->emitConstIntAPS(
Value, E);
5002 return this->emitConstIntAP(
Value, E);
5004 if (
Value.isSigned())
5005 return this->emitConst(
Value.getSExtValue(), Ty, E);
5006 return this->emitConst(
Value.getZExtValue(), Ty, E);
5009template <
class Emitter>
5013 return this->emitConstIntAPS(
Value, E);
5015 return this->emitConstIntAP(
Value, E);
5018 return this->emitConst(
Value.getSExtValue(), Ty, E);
5019 return this->emitConst(
Value.getZExtValue(), Ty, E);
5022template <
class Emitter>
5023bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5024 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5027template <
class Emitter>
5040 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5041 Locals.insert({VD, Local});
5042 VarScope->addForScopeKind(Local, SC);
5043 return Local.Offset;
5046template <
class Emitter>
5051 bool IsTemporary =
false;
5052 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5055 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5056 Init = VarD->getInit();
5058 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5069 return std::nullopt;
5074 Locals.insert({Key, Local});
5075 VarScope->addForScopeKind(Local, SC);
5076 return Local.Offset;
5079template <
class Emitter>
5089 return std::nullopt;
5099 return Local.Offset;
5102template <
class Emitter>
5104 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5105 return PT->getPointeeType()->getAsCanonical<RecordType>();
5111 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5115template <
class Emitter>
5117 return P.getOrCreateRecord(RD);
5120template <
class Emitter>
5122 return Ctx.getOrCreateFunction(FD);
5125template <
class Emitter>
5129 auto maybeDestroyLocals = [&]() ->
bool {
5130 if (DestroyToplevelScope)
5131 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5132 return this->emitCheckAllocations(E);
5139 return this->emitRetVoid(E) && maybeDestroyLocals();
5147 return this->emitRet(*T, E) && maybeDestroyLocals();
5155 if (!this->emitGetPtrLocal(*LocalOffset, E))
5163 return this->emitRetValue(E) && maybeDestroyLocals();
5166 return maybeDestroyLocals() &&
false;
5169template <
class Emitter>
5171 bool DestroyToplevelScope) {
5175 return this->
visitExpr(E, DestroyToplevelScope);
5178template <
class Emitter>
5190 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5191 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5205template <
class Emitter>
5207 bool ConstantContext) {
5210 if (!ConstantContext) {
5224 auto GlobalIndex =
P.getGlobal(VD);
5225 assert(GlobalIndex);
5227 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5230 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5234 auto Local =
Locals.find(VD);
5235 assert(Local !=
Locals.end());
5237 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5240 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5250 auto GlobalIndex =
P.getGlobal(VD);
5251 assert(GlobalIndex);
5252 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5261 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5264template <
class Emitter>
5275 if (!this->isActive())
5280 if (
Init &&
Init->isValueDependent())
5284 auto checkDecl = [&]() ->
bool {
5286 return !NeedsOp || this->emitCheckDecl(VD, VD);
5293 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5296 if (
P.isGlobalInitialized(*GlobalIndex))
5300 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
5314 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5317 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5320 if (!this->emitStartInit(
Init))
5326 if (!this->emitEndInit(
Init))
5329 return this->emitFinishInitGlobal(
Init);
5339 if (!
Init ||
Init->getType()->isVoidType())
5348 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5360 if (!this->emitCheckRefInit(
Init))
5364 return this->emitSetLocal(*VarT, Offset, VD);
5372 if (!this->emitGetPtrLocal(*Offset,
Init))
5380template <
class Emitter>
5385 return this->emitConst(Val.
getInt(), ValType, E);
5388 return this->emitFloat(F, E);
5393 if (!this->emitGetMemberPtr(MemberDecl, E))
5399 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, E))
5405 return this->emitNullMemberPtr(0,
nullptr, E);
5410 return this->emitNull(ValType, 0,
nullptr, E);
5415 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5416 return this->
visit(BaseExpr);
5421 QualType EntryType = VD->getType();
5422 for (
auto &Entry : Path) {
5424 uint64_t Index = Entry.getAsArrayIndex();
5427 if (!this->emitConst(Index,
PT_Uint64, E))
5429 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5431 EntryType = ElemType;
5441 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5442 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5444 if (!this->emitGetPtrFieldPop(EntryOffset, E))
5446 EntryType = FD->getType();
5450 if (!this->emitGetPtrBasePop(BaseOffset,
false, E))
5452 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5464template <
class Emitter>
5472 const Record::Field *RF = R->getField(I);
5473 QualType FieldType = RF->Decl->getType();
5479 if (!this->emitInitField(*PT, RF->Offset, E))
5482 if (!this->emitGetPtrField(RF->Offset, E))
5486 if (!this->emitFinishInitPop(E))
5494 const Record::Base *RB = R->getBase(I);
5495 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5497 if (!this->emitGetPtrBase(RB->Offset, E))
5501 if (!this->emitFinishInitPop(E))
5514 const Record::Field *RF = R->getField(UnionField);
5515 QualType FieldType = RF->Decl->getType();
5520 if (RF->isBitField())
5521 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5523 return this->emitInitFieldActivate(*PT, RF->Offset, E);
5526 if (!this->emitGetPtrField(RF->Offset, E))
5528 if (!this->emitActivate(E))
5532 return this->emitPopPtr(E);
5535 const auto *ArrType = T->getAsArrayTypeUnsafe();
5536 QualType ElemType = ArrType->getElementType();
5537 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5542 if (!this->emitInitElem(*ElemT, A, E))
5545 if (!this->emitConstUint32(A, E))
5547 if (!this->emitArrayElemPtrUint32(E))
5551 if (!this->emitPopPtr(E))
5562template <
class Emitter>
5564 unsigned BuiltinID) {
5565 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5570 return this->emitConst(0, E);
5573 if (!this->emitStartSpeculation(E))
5575 LabelTy EndLabel = this->getLabel();
5576 if (!this->speculate(E, EndLabel))
5578 if (!this->emitEndSpeculation(E))
5580 this->fallthrough(EndLabel);
5588 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5589 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5590 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5591 BuiltinID == Builtin::BI__builtin_function_start) {
5594 return this->emitDummyPtr(E, E);
5605 if (!this->emitGetPtrLocal(*LocalIndex, E))
5610 switch (BuiltinID) {
5611 case Builtin::BI__builtin_object_size:
5612 case Builtin::BI__builtin_dynamic_object_size: {
5616 if (!this->
visit(Arg0))
5627 case Builtin::BI__assume:
5628 case Builtin::BI__builtin_assume:
5631 case Builtin::BI__atomic_is_lock_free:
5632 case Builtin::BI__atomic_always_lock_free: {
5643 for (
const auto *Arg : E->
arguments()) {
5644 if (!this->
visit(Arg))
5650 if (!this->emitCallBI(E, BuiltinID, E))
5659template <
class Emitter>
5678 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5679 DD && DD->isTrivial()) {
5681 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5683 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5684 this->emitPopPtr(E);
5692 bool HasRVO = !
ReturnType->isVoidType() && !T;
5700 if (!this->emitGetPtrLocal(*LocalIndex, E))
5708 if (!this->emitGetPtrLocal(*LocalIndex, E))
5712 if (!this->emitDupPtr(E))
5719 bool IsAssignmentOperatorCall =
false;
5720 bool ActivateLHS =
false;
5721 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5722 OCE && OCE->isAssignmentOp()) {
5726 assert(Args.size() == 2);
5727 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
5729 IsAssignmentOperatorCall =
true;
5730 std::reverse(Args.begin(), Args.end());
5736 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5737 MD && MD->isStatic()) {
5741 Args.erase(Args.begin());
5745 bool Devirtualized =
false;
5748 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5756 if (!this->
visit(Callee))
5758 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5760 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5762 if (!this->emitGetMemberPtrBase(E))
5765 const auto *InstancePtr = MC->getImplicitObjectArgument();
5772 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5773 Devirtualized =
true;
5774 if (!this->
visit(Stripped))
5777 if (!this->
visit(InstancePtr))
5781 if (!this->
visit(InstancePtr))
5785 }
else if (
const auto *PD =
5786 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5787 if (!this->emitCheckPseudoDtor(E))
5795 return this->emitEndLifetimePop(E);
5796 }
else if (!FuncDecl) {
5800 if (!this->
visit(Callee))
5802 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5811 if (IsAssignmentOperatorCall) {
5812 assert(Args.size() == 2);
5815 if (!this->emitFlip(Arg2T, Arg1T, E))
5829 assert(HasRVO ==
Func->hasRVO());
5831 bool HasQualifier =
false;
5832 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5833 HasQualifier = ME->hasQualifier();
5835 bool IsVirtual =
false;
5836 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5837 IsVirtual = !Devirtualized && MD->isVirtual();
5842 if (IsVirtual && !HasQualifier) {
5843 uint32_t VarArgSize = 0;
5844 unsigned NumParams =
5846 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5849 if (!this->emitCallVirt(
Func, VarArgSize, E))
5851 }
else if (
Func->isVariadic()) {
5852 uint32_t VarArgSize = 0;
5853 unsigned NumParams =
5855 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5857 if (!this->emitCallVar(
Func, VarArgSize, E))
5860 if (!this->emitCall(
Func, 0, E))
5869 uint32_t ArgSize = 0;
5870 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5876 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5878 if (!this->emitGetMemberPtrDecl(E))
5881 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5884 if (!this->emitCallPtr(ArgSize, E, E))
5895template <
class Emitter>
5902template <
class Emitter>
5909template <
class Emitter>
5914 return this->emitConstBool(E->
getValue(), E);
5917template <
class Emitter>
5923 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5924 return this->emitNullPtr(Val,
nullptr, E);
5927template <
class Emitter>
5935 return this->emitZero(T, E);
5938template <
class Emitter>
5943 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
5944 if (this->LambdaThisCapture.Offset > 0) {
5945 if (this->LambdaThisCapture.IsPtr)
5946 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5947 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5956 return this->emitThis(E);
5971 unsigned StartIndex = 0;
5972 unsigned EndIndex = 0;
5974 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5976 EndIndex = StartIndex;
5983 for (; StartIndex > 0; --StartIndex) {
5993 if (StartIndex == 0 && EndIndex == 0)
5996 assert(StartIndex < EndIndex);
5999 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6011 case Stmt::CompoundStmtClass:
6013 case Stmt::DeclStmtClass:
6015 case Stmt::ReturnStmtClass:
6017 case Stmt::IfStmtClass:
6019 case Stmt::WhileStmtClass:
6021 case Stmt::DoStmtClass:
6023 case Stmt::ForStmtClass:
6025 case Stmt::CXXForRangeStmtClass:
6027 case Stmt::BreakStmtClass:
6029 case Stmt::ContinueStmtClass:
6031 case Stmt::SwitchStmtClass:
6033 case Stmt::CaseStmtClass:
6035 case Stmt::DefaultStmtClass:
6037 case Stmt::AttributedStmtClass:
6039 case Stmt::CXXTryStmtClass:
6041 case Stmt::NullStmtClass:
6044 case Stmt::GCCAsmStmtClass:
6045 case Stmt::MSAsmStmtClass:
6046 case Stmt::GotoStmtClass:
6047 return this->emitInvalid(S);
6048 case Stmt::LabelStmtClass:
6051 if (
const auto *E = dyn_cast<Expr>(S))
6058template <
class Emitter>
6061 for (
const auto *InnerStmt : S->
body())
6064 return Scope.destroyLocals();
6067template <
class Emitter>
6068bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6069 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6070 for (
auto *BD : DD->flat_bindings())
6071 if (
auto *KD = BD->getHoldingVar();
6072 KD && !this->visitVarDecl(KD, KD->getInit()))
6086template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6088 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6089 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6096 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6101 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6102 ICE && (ICE->getCastKind() == CK_NoOp ||
6103 ICE->getCastKind() == CK_DerivedToBase ||
6104 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6105 E = ICE->getSubExpr();
6109 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6110 const auto *ThisRecord =
6111 This->getType()->getPointeeType()->getAsRecordDecl();
6112 if (!ThisRecord->isUnion())
6115 if (
const auto *Ctor =
6116 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6117 return Ctor->getParent() == ThisRecord;
6126template <
class Emitter>
6128 bool EvaluateConditionDecl) {
6129 for (
const auto *D : DS->
decls()) {
6134 const auto *VD = dyn_cast<VarDecl>(D);
6141 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6148template <
class Emitter>
6151 return this->emitUnsupported(RS);
6157 if (!this->
visit(RE))
6163 if (RE->getType()->isVoidType()) {
6164 if (!this->
visit(RE))
6167 if (RE->containsErrors())
6172 if (!this->emitRVOPtr(RE))
6178 return this->emitRetVoid(RS);
6184 return this->emitRetVoid(RS);
6190 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6197 if (
auto *CondInit = IS->
getInit()) {
6213 return visitChildStmt(IS->
getThen());
6215 return visitChildStmt(Else);
6221 if (!this->emitIsConstantContext(IS))
6224 if (!this->emitIsConstantContext(IS))
6226 if (!this->emitInv(IS))
6240 LabelTy LabelElse = this->getLabel();
6241 LabelTy LabelEnd = this->getLabel();
6242 if (!this->jumpFalse(LabelElse, IS))
6244 if (!visitChildStmt(IS->
getThen()))
6246 if (!this->jump(LabelEnd, IS))
6248 this->emitLabel(LabelElse);
6249 if (!visitChildStmt(Else))
6251 this->emitLabel(LabelEnd);
6253 LabelTy LabelEnd = this->getLabel();
6254 if (!this->jumpFalse(LabelEnd, IS))
6256 if (!visitChildStmt(IS->
getThen()))
6258 this->emitLabel(LabelEnd);
6267template <
class Emitter>
6272 LabelTy CondLabel = this->getLabel();
6273 LabelTy EndLabel = this->getLabel();
6277 this->fallthrough(CondLabel);
6278 this->emitLabel(CondLabel);
6294 if (!this->jumpFalse(EndLabel, S))
6304 if (!this->jump(CondLabel, S))
6306 this->fallthrough(EndLabel);
6307 this->emitLabel(EndLabel);
6316 LabelTy StartLabel = this->getLabel();
6317 LabelTy EndLabel = this->getLabel();
6318 LabelTy CondLabel = this->getLabel();
6322 this->fallthrough(StartLabel);
6323 this->emitLabel(StartLabel);
6329 this->fallthrough(CondLabel);
6330 this->emitLabel(CondLabel);
6337 if (!this->jumpTrue(StartLabel, S))
6340 this->fallthrough(EndLabel);
6341 this->emitLabel(EndLabel);
6345template <
class Emitter>
6353 LabelTy EndLabel = this->getLabel();
6354 LabelTy CondLabel = this->getLabel();
6355 LabelTy IncLabel = this->getLabel();
6362 this->fallthrough(CondLabel);
6363 this->emitLabel(CondLabel);
6375 if (!this->jumpFalse(EndLabel, S))
6384 this->fallthrough(IncLabel);
6385 this->emitLabel(IncLabel);
6391 if (!this->jump(CondLabel, S))
6395 this->emitLabel(EndLabel);
6401template <
class Emitter>
6411 LabelTy EndLabel = this->getLabel();
6412 LabelTy CondLabel = this->getLabel();
6413 LabelTy IncLabel = this->getLabel();
6428 this->fallthrough(CondLabel);
6429 this->emitLabel(CondLabel);
6432 if (!this->jumpFalse(EndLabel, S))
6443 this->fallthrough(IncLabel);
6444 this->emitLabel(IncLabel);
6449 if (!this->jump(CondLabel, S))
6452 this->fallthrough(EndLabel);
6453 this->emitLabel(EndLabel);
6457template <
class Emitter>
6468 if (LI.BreakLabel) {
6469 TargetLabel = *LI.BreakLabel;
6470 BreakScope = LI.BreakOrContinueScope;
6476 if (LI.Name == TargetLoop) {
6477 TargetLabel = *LI.BreakLabel;
6478 BreakScope = LI.BreakOrContinueScope;
6489 C =
C->getParent()) {
6490 if (!
C->destroyLocals())
6494 return this->jump(*TargetLabel, S);
6497template <
class Emitter>
6508 if (LI.ContinueLabel) {
6509 TargetLabel = *LI.ContinueLabel;
6510 ContinueScope = LI.BreakOrContinueScope;
6516 if (LI.Name == TargetLoop) {
6517 TargetLabel = *LI.ContinueLabel;
6518 ContinueScope = LI.BreakOrContinueScope;
6523 assert(TargetLabel);
6526 C =
C->getParent()) {
6527 if (!
C->destroyLocals())
6531 return this->jump(*TargetLabel, S);
6534template <
class Emitter>
6537 if (
Cond->containsErrors())
6543 LabelTy EndLabel = this->getLabel();
6548 if (
const auto *CondInit = S->
getInit())
6559 if (!this->emitSetLocal(CondT, CondVar, S))
6569 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6572 if (CS->caseStmtIsGNURange()) {
6573 LabelTy EndOfRangeCheck = this->getLabel();
6574 const Expr *Low = CS->getLHS();
6575 const Expr *High = CS->getRHS();
6579 if (!this->emitGetLocal(CondT, CondVar, CS))
6581 if (!this->
visit(Low))
6584 if (!this->emitGE(
LT, S))
6586 if (!this->jumpFalse(EndOfRangeCheck, S))
6589 if (!this->emitGetLocal(CondT, CondVar, CS))
6591 if (!this->
visit(High))
6594 if (!this->emitLE(HT, S))
6598 this->emitLabel(EndOfRangeCheck);
6603 if (
Value->isValueDependent())
6608 if (!this->emitGetLocal(CondT, CondVar, CS))
6614 if (!this->emitEQ(ValueT, S))
6619 assert(!DefaultLabel);
6620 DefaultLabel = this->getLabel();
6627 if (!this->jump(*DefaultLabel, S))
6630 if (!this->jump(EndLabel, S))
6638 this->fallthrough(EndLabel);
6639 this->emitLabel(EndLabel);
6644template <
class Emitter>
6651template <
class Emitter>
6658 if (LI.DefaultLabel) {
6659 DefaultLabel = *LI.DefaultLabel;
6664 this->emitLabel(DefaultLabel);
6668template <
class Emitter>
6675 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6678 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6679 !this->Ctx.getLangOpts().MSVCCompat) {
6681 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6687 const Expr *Assumption = AA->getAssumption();
6698 if (!this->emitAssume(Assumption))
6707 if (IsMSVCConstexprAttr)
6708 return this->emitPopMSVCCE(S);
6712template <
class Emitter>
6718template <
class Emitter>
6719bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6726 assert(ClosureClass->
captures().empty());
6730 "A generic lambda's static-invoker function must be a "
6731 "template specialization");
6735 void *InsertPos =
nullptr;
6736 const FunctionDecl *CorrespondingCallOpSpecialization =
6738 assert(CorrespondingCallOpSpecialization);
6739 LambdaCallOp = CorrespondingCallOpSpecialization;
6743 assert(ClosureClass->
captures().empty());
6744 const Function *
Func = this->getFunction(LambdaCallOp);
6747 assert(
Func->hasThisPointer());
6750 if (
Func->hasRVO()) {
6751 if (!this->emitRVOPtr(MD))
6759 if (!this->emitNullPtr(0,
nullptr, MD))
6764 auto It = this->Params.find(PVD);
6765 assert(It != this->Params.end());
6769 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6770 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6774 if (!this->emitCall(
Func, 0, LambdaCallOp))
6779 return this->emitRet(*ReturnType, MD);
6782 return this->emitRetVoid(MD);
6785template <
class Emitter>
6786bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6787 if (Ctx.getLangOpts().CPlusPlus23)
6797 const Expr *InitExpr =
Init->getInit();
6799 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6803 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6813template <
class Emitter>
6815 assert(!ReturnType);
6818 if (!this->emitStartThisLifetime1(Ctor))
6821 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6822 const Expr *InitExpr,
6825 if (InitExpr->getType().isNull())
6829 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6832 if (!this->visit(InitExpr))
6835 if (F->isBitField())
6836 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
6838 return this->emitInitThisField(*T, FieldOffset, InitExpr);
6843 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6846 if (
Activate && !this->emitActivate(InitExpr))
6849 return this->visitInitializerPop(InitExpr);
6853 const Record *
R = this->getRecord(RD);
6856 bool IsUnion =
R->isUnion();
6866 if (!this->emitThis(Ctor))
6869 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
6872 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6873 this->emitRetVoid(Ctor);
6876 unsigned FieldInits = 0;
6878 for (
const auto *
Init : Ctor->
inits()) {
6882 const Expr *InitExpr =
Init->getInit();
6884 const Record::Field *F =
R->getField(
Member);
6888 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6892 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6895 if (
Init->isBaseVirtual()) {
6896 assert(
R->getVirtualBase(BaseDecl));
6897 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6903 const Record::Base *B =
R->getBase(BaseDecl);
6905 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6909 if (IsUnion && !this->emitActivate(InitExpr))
6912 if (!this->visitInitializerPop(InitExpr))
6917 unsigned ChainSize = IFD->getChainingSize();
6918 assert(ChainSize >= 2);
6920 unsigned NestedFieldOffset = 0;
6921 const Record::Field *NestedField =
nullptr;
6922 for (
unsigned I = 0; I != ChainSize; ++I) {
6924 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6925 assert(FieldRecord);
6927 NestedField = FieldRecord->
getField(FD);
6928 assert(NestedField);
6929 IsUnion = IsUnion || FieldRecord->
isUnion();
6931 NestedFieldOffset += NestedField->Offset;
6934 if (I != ChainSize - 1)
6937 assert(NestedField);
6940 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6945 unsigned InitFieldOffset = 0;
6946 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6948 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6949 assert(FieldRecord);
6950 NestedField = FieldRecord->
getField(FD);
6951 InitFieldOffset += NestedField->Offset;
6952 assert(NestedField);
6953 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6955 if (!this->emitFinishInitPop(InitExpr))
6959 InitStack.pop_back_n(ChainSize - 1);
6962 assert(
Init->isDelegatingInitializer());
6963 if (!this->emitThis(InitExpr))
6965 if (!this->visitInitializerPop(
Init->getInit()))
6969 if (!
Scope.destroyLocals())
6973 if (FieldInits !=
R->getNumFields()) {
6974 assert(FieldInits < R->getNumFields());
6976 if (!this->emitStartThisLifetime(Ctor))
6983 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
6984 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
6991 if (!visitStmt(Body))
6998template <
class Emitter>
7001 const Record *
R = this->getRecord(RD);
7006 if (!this->visitStmt(Dtor->
getBody()))
7010 if (!this->emitThis(Dtor))
7013 if (!this->emitCheckDestruction(Dtor))
7017 if (!
R->isUnion()) {
7021 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7025 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7027 if (!this->emitDestructionPop(D,
SourceInfo{}))
7032 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7033 if (
Base.R->hasTrivialDtor())
7037 if (!this->emitRecordDestructionPop(
Base.R, {}))
7041 if (!this->emitMarkDestroyed(Dtor))
7045 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
7048template <
class Emitter>
7049bool Compiler<Emitter>::compileUnionAssignmentOperator(
7051 if (!this->emitThis(MD))
7054 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7057 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7060template <
class Emitter>
7070 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7071 return this->compileConstructor(Ctor);
7072 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
7073 return this->compileDestructor(Dtor);
7076 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7081 return this->compileUnionAssignmentOperator(MD);
7084 return this->emitLambdaStaticInvokerBody(MD);
7088 if (
const auto *Body = F->
getBody())
7102 return FD->getBitWidthValue();
7105template <
class Emitter>
7118 if (!
Ctx.getLangOpts().CPlusPlus14)
7119 return this->emitInvalid(E);
7121 return this->emitError(E);
7123 if (!this->
visit(SubExpr))
7127 if (!this->emitIncPtr(E))
7134 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7135 : this->emitIncf(getFPOptions(E), E);
7147 if (!
Ctx.getLangOpts().CPlusPlus14)
7148 return this->emitInvalid(E);
7150 return this->emitError(E);
7152 if (!this->
visit(SubExpr))
7156 if (!this->emitDecPtr(E))
7163 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7164 : this->emitDecf(getFPOptions(E), E);
7177 if (!
Ctx.getLangOpts().CPlusPlus14)
7178 return this->emitInvalid(E);
7180 return this->emitError(E);
7182 if (!this->
visit(SubExpr))
7186 if (!this->emitLoadPtr(E))
7188 if (!this->emitConstUint8(1, E))
7190 if (!this->emitAddOffsetUint8(E))
7192 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7198 return this->emitIncfPop(getFPOptions(E), E);
7208 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7209 if (!this->emitLoadFloat(E))
7211 APFloat F(TargetSemantics, 1);
7212 if (!this->emitFloat(F, E))
7215 if (!this->emitAddf(getFPOptions(E), E))
7217 if (!this->emitStoreFloat(E))
7229 return E->
isGLValue() || this->emitLoadPop(*T, E);
7232 if (!
Ctx.getLangOpts().CPlusPlus14)
7233 return this->emitInvalid(E);
7235 return this->emitError(E);
7237 if (!this->
visit(SubExpr))
7241 if (!this->emitLoadPtr(E))
7243 if (!this->emitConstUint8(1, E))
7245 if (!this->emitSubOffsetUint8(E))
7247 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7253 return this->emitDecfPop(getFPOptions(E), E);
7263 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7264 if (!this->emitLoadFloat(E))
7266 APFloat F(TargetSemantics, 1);
7267 if (!this->emitFloat(F, E))
7270 if (!this->emitSubf(getFPOptions(E), E))
7272 if (!this->emitStoreFloat(E))
7284 return E->
isGLValue() || this->emitLoadPop(*T, E);
7288 return this->emitError(E);
7291 return this->
discard(SubExpr);
7296 if (!this->emitInv(E))
7300 return this->emitCast(
PT_Bool, ET, E);
7304 return this->emitError(E);
7306 if (!this->
visit(SubExpr))
7308 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7311 return this->emitError(E);
7313 if (!this->
visit(SubExpr))
7328 return this->
discard(SubExpr);
7330 if (!this->
visit(SubExpr))
7337 return this->emitNarrowPtr(E);
7342 return this->emitError(E);
7344 if (!this->
visit(SubExpr))
7346 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7358 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7363 assert(
false &&
"Unhandled opcode");
7369template <
class Emitter>
7375 return this->
discard(SubExpr);
7378 auto prepareResult = [=]() ->
bool {
7383 return this->emitGetPtrLocal(*LocalIndex, E);
7390 unsigned SubExprOffset = ~0u;
7391 auto createTemp = [=, &SubExprOffset]() ->
bool {
7394 if (!this->
visit(SubExpr))
7396 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7400 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7401 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7403 return this->emitArrayElemPop(ElemT, Index, E);
7408 if (!prepareResult())
7412 for (
unsigned I = 0; I != 2; ++I) {
7413 if (!getElem(SubExprOffset, I))
7415 if (!this->emitNeg(ElemT, E))
7417 if (!this->emitInitElem(ElemT, I, E))
7428 if (!this->
visit(SubExpr))
7430 if (!this->emitComplexBoolCast(SubExpr))
7432 if (!this->emitInv(E))
7435 return this->emitCast(
PT_Bool, ET, E);
7439 return this->emitComplexReal(SubExpr);
7442 if (!this->
visit(SubExpr))
7446 if (!this->emitConstUint8(1, E))
7448 return this->emitArrayElemPtrPopUint8(E);
7459 if (!this->emitArrayElem(ElemT, 1, E))
7461 if (!this->emitNeg(ElemT, E))
7463 if (!this->emitInitElem(ElemT, 1, E))
7471 return this->emitInvalid(E);
7477template <
class Emitter>
7483 return this->
discard(SubExpr);
7486 if (UnaryOp == UO_Extension)
7489 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7490 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7491 return this->emitInvalid(E);
7494 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7501 if (!this->emitGetPtrLocal(*LocalIndex, E))
7506 unsigned SubExprOffset =
7508 if (!this->
visit(SubExpr))
7510 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7515 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7516 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7518 return this->emitArrayElemPop(ElemT, Index, E);
7523 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7524 if (!getElem(SubExprOffset, I))
7526 if (!this->emitNeg(ElemT, E))
7528 if (!this->emitInitElem(ElemT, I, E))
7543 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7544 if (!getElem(SubExprOffset, I))
7547 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7549 if (!this->emitInv(E))
7551 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7553 if (!this->emitNeg(ElemT, E))
7555 if (ElemT != ResultVecElemT &&
7556 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7558 if (!this->emitInitElem(ResultVecElemT, I, E))
7564 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7565 if (!getElem(SubExprOffset, I))
7568 if (!this->emitInv(E))
7571 if (!this->emitComp(ElemT, E))
7574 if (!this->emitInitElem(ElemT, I, E))
7579 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7584template <
class Emitter>
7589 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7590 return this->emitConst(ECD->getInitVal(), E);
7591 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7593 return F && this->emitGetFnPtr(F, E);
7595 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7600 return this->emitInitGlobal(*T, *Index, E);
7603 if (!this->emitGetPtrGlobal(*Index, E))
7607 return this->emitFinishInit(E);
7622 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7623 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7628 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7629 if (IsReference || !It->second.IsPtr)
7630 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7632 return this->emitGetPtrParam(It->second.Index, E);
7635 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7641 const unsigned Offset = It->second.Offset;
7644 return this->emitGetRefLocal(Offset, E);
7646 return this->emitGetPtrLocal(Offset, E);
7649 if (
auto GlobalIndex =
P.getGlobal(D)) {
7651 if (!
Ctx.getLangOpts().CPlusPlus11)
7652 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7653 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7656 return this->emitGetPtrGlobal(*GlobalIndex, E);
7660 auto revisit = [&](
const VarDecl *VD,
7661 bool IsConstexprUnknown =
true) ->
bool {
7663 IsConstexprUnknown);
7668 if (!this->emitPopCC(E))
7671 if (VarState.notCreated())
7679 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7681 if (
auto It = this->LambdaCaptures.find(D);
7682 It != this->LambdaCaptures.end()) {
7683 auto [Offset, IsPtr] = It->second;
7686 return this->emitGetThisFieldPtr(Offset, E);
7687 return this->emitGetPtrThisField(Offset, E);
7691 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7692 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7693 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7697 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7698 return this->
visit(BD->getBinding());
7702 return this->emitDummyPtr(D, E);
7706 const auto *VD = dyn_cast<VarDecl>(D);
7708 return this->emitError(E);
7711 if (!
Ctx.getLangOpts().CPlusPlus) {
7715 return revisit(VD,
false);
7716 return this->emitDummyPtr(D, E);
7720 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7721 if (T.isConstant(
Ctx.getASTContext()))
7723 return T->isReferenceType();
7727 typeShouldBeVisited(DeclType)) {
7729 Init && !
Init->isValueDependent()) {
7735 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7749 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7754 return revisit(VD, IsConstexprUnknown);
7755 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7756 return revisit(VD,
true);
7763 return this->emitDummyPtr(D, E);
7766template <
class Emitter>
7772template <
class Emitter>
7783 if (!
C->destroyLocals())
7789template <
class Emitter>
7790unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7793 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7795 return Ty->getAsCXXRecordDecl();
7797 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7798 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7800 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7804template <
class Emitter>
7811 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7816 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7817 getFPOptions(E), E);
7819 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7820 getFPOptions(E), E);
7824 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7829 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7831 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7835 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7839 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7840 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7847template <
class Emitter>
7850 assert(FromT != ToT);
7853 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7855 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7857 return this->emitCast(FromT, ToT, E);
7861template <
class Emitter>
7862bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7866 return this->
discard(SubExpr);
7868 if (!this->visit(SubExpr))
7871 if (!this->emitConstUint8(0, SubExpr))
7873 return this->emitArrayElemPtrPopUint8(SubExpr);
7877 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7881template <
class Emitter>
7882bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7883 assert(!DiscardResult);
7887 if (!this->emitArrayElem(ElemT, 0, E))
7890 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7893 if (!this->emitCast(ElemT,
PT_Bool, E))
7898 LabelTy LabelTrue = this->getLabel();
7899 if (!this->jumpTrue(LabelTrue, E))
7902 if (!this->emitArrayElemPop(ElemT, 1, E))
7905 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7908 if (!this->emitCast(ElemT,
PT_Bool, E))
7912 LabelTy EndLabel = this->getLabel();
7913 this->jump(EndLabel, E);
7915 this->emitLabel(LabelTrue);
7916 if (!this->emitPopPtr(E))
7918 if (!this->emitConstBool(
true, E))
7921 this->fallthrough(EndLabel);
7922 this->emitLabel(EndLabel);
7927template <
class Emitter>
7928bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7939 LHSIsComplex =
true;
7940 ElemT = classifyComplexElementType(LHS->
getType());
7941 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7942 if (!this->visit(LHS))
7944 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7947 LHSIsComplex =
false;
7949 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7950 if (!this->visit(LHS))
7952 if (!this->emitSetLocal(LHST, LHSOffset, E))
7959 RHSIsComplex =
true;
7960 ElemT = classifyComplexElementType(RHS->
getType());
7961 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7962 if (!this->visit(RHS))
7964 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7967 RHSIsComplex =
false;
7969 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7970 if (!this->visit(RHS))
7972 if (!this->emitSetLocal(RHST, RHSOffset, E))
7976 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7977 bool IsComplex) ->
bool {
7979 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7981 return this->emitArrayElemPop(ElemT, Index, E);
7983 return this->emitGetLocal(ElemT, LocalOffset, E);
7986 for (
unsigned I = 0; I != 2; ++I) {
7988 if (!getElem(LHSOffset, I, LHSIsComplex))
7990 if (!getElem(RHSOffset, I, RHSIsComplex))
7993 if (!this->emitEQ(ElemT, E))
7996 if (!this->emitCastBoolUint8(E))
8001 if (!this->emitAddUint8(E))
8003 if (!this->emitConstUint8(2, E))
8007 if (!this->emitEQUint8(E))
8010 if (!this->emitNEUint8(E))
8017 return this->emitCast(
PT_Bool, ResT, E);
8024template <
class Emitter>
8025bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8028 assert(!
R->hasTrivialDtor());
8031 const Function *DtorFunc = getFunction(Dtor);
8034 assert(DtorFunc->hasThisPointer());
8035 assert(DtorFunc->getNumParams() == 1);
8036 return this->emitCall(DtorFunc, 0, Loc);
8041template <
class Emitter>
8042bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8054 return this->emitPopPtr(Loc);
8056 for (ssize_t I = N - 1; I >= 1; --I) {
8057 if (!this->emitConstUint64(I, Loc))
8059 if (!this->emitArrayElemPtrUint64(Loc))
8061 if (!this->emitDestructionPop(ElemDesc, Loc))
8065 if (!this->emitConstUint64(0, Loc))
8067 if (!this->emitArrayElemPtrPopUint64(Loc))
8069 return this->emitDestructionPop(ElemDesc, Loc);
8074 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8079template <
class Emitter>
8080bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
8081 assert(!DiscardResult &&
"Should've been checked before");
8082 unsigned DummyID = P.getOrCreateDummy(D);
8084 if (!this->emitGetPtrGlobal(DummyID, E))
8092 return this->emitDecayPtr(
PT_Ptr, PT, E);
8098template <
class Emitter>
8099bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
8101 return this->emitConstFloat(
Floating(F), E);
8103 APInt I = F.bitcastToAPInt();
8104 return this->emitConstFloat(
8105 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8106 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8117template <
class Emitter>
8118bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8131 if (!this->emitGetPtrLocal(*LocalIndex, E))
8141 if (!this->visit(SubExpr))
8143 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8144 unsigned TempOffset =
8145 allocateLocalPrimitive(SubExpr, *FromT,
true);
8146 if (!this->visit(SubExpr))
8148 if (!this->emitSetLocal(*FromT, TempOffset, E))
8150 if (!this->emitGetPtrLocal(TempOffset, E))
8157 if (!this->emitBitCast(E))
8159 return DiscardResult ? this->emitPopPtr(E) :
true;
8163 const llvm::fltSemantics *TargetSemantics =
nullptr;
8165 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8171 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8173 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8174 ResultBitWidth, TargetSemantics,
8179 return this->emitPop(*ToT, E);
8188template <
class Emitter>
8189bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8194 unsigned NumElems = 0;
8197 NumElems = VT->getNumElements();
8198 ElemType = VT->getElementType();
8200 NumElems = MT->getNumElementsFlattened();
8201 ElemType = MT->getElementType();
8204 PrimType ElemT = classifyPrim(ElemType);
8205 for (
unsigned I = 0; I != NumElems; ++I) {
8206 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8208 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8210 if (!this->emitInitElem(ElemT, I, E))
8220 QualType ArrElemType = CAT->getElementType();
8221 unsigned ArrSize = CAT->getZExtSize();
8224 for (
unsigned I = 0; I != ArrSize; ++I) {
8225 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8227 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8229 if (!this->emitInitElem(*ElemT, I, E))
8233 for (
unsigned I = 0; I != ArrSize; ++I) {
8234 if (!this->emitConstUint32(I, E))
8236 if (!this->emitArrayElemPtrUint32(E))
8238 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8240 if (!this->emitFinishInitPop(E))
8250 const Record *
R = getRecord(DestType);
8254 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8256 const Record::Base *B =
R->getBase(BS.getType());
8258 if (!this->emitGetPtrBase(B->Offset, E))
8260 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8262 if (!this->emitFinishInitPop(E))
8267 for (
const Record::Field &F :
R->fields()) {
8268 if (F.isUnnamedBitField())
8271 QualType FieldType = F.Decl->getType();
8273 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8275 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8277 if (F.isBitField()) {
8278 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8281 if (!this->emitInitField(*FieldT, F.Offset, E))
8285 if (!this->emitGetPtrField(F.Offset, E))
8287 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8289 if (!this->emitPopPtr(E))
8302template <
class Emitter>
8303unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8306 return VT->getNumElements();
8308 return MT->getNumElementsFlattened();
8312 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8316 const Record *
R = getRecord(Ty);
8320 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8322 Count += countHLSLFlatElements(BS.getType());
8324 for (
const Record::Field &F :
R->fields()) {
8325 if (F.isUnnamedBitField())
8327 Count += countHLSLFlatElements(F.Decl->getType());
8332 if (canClassify(Ty))
8341template <
class Emitter>
8342bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8343 QualType SrcType,
unsigned SrcOffset,
8348 auto saveToLocal = [&](
PrimType T) ->
bool {
8349 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8350 if (!this->emitSetLocal(T, Offset, E))
8352 Elements.push_back({Offset, T});
8358 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8359 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8360 return std::nullopt;
8365 unsigned NumElems = 0;
8368 NumElems = VT->getNumElements();
8369 ElemType = VT->getElementType();
8371 NumElems = MT->getNumElementsFlattened();
8372 ElemType = MT->getElementType();
8375 PrimType ElemT = classifyPrim(ElemType);
8376 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8377 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8379 if (!this->emitArrayElemPop(ElemT, I, E))
8381 if (!saveToLocal(ElemT))
8391 QualType ArrElemType = CAT->getElementType();
8392 unsigned ArrSize = CAT->getZExtSize();
8395 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8396 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8398 if (!this->emitArrayElemPop(*ElemT, I, E))
8400 if (!saveToLocal(*ElemT))
8404 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8405 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8407 if (!this->emitConstUint32(I, E))
8409 if (!this->emitArrayElemPtrPopUint32(E))
8414 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8425 const Record *
R = getRecord(SrcType);
8429 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8431 if (Elements.size() >= MaxElements)
8433 const Record::Base *B =
R->getBase(BS.getType());
8435 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8437 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8442 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8448 for (
const Record::Field &F :
R->fields()) {
8449 if (Elements.size() >= MaxElements)
8451 if (F.isUnnamedBitField())
8454 QualType FieldType = F.Decl->getType();
8455 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8457 if (!this->emitGetPtrFieldPop(F.Offset, E))
8461 if (!this->emitLoadPop(*FieldT, E))
8463 if (!saveToLocal(*FieldT))
8467 if (!FieldPtrOffset)
8469 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8485template <
class Emitter>
8486bool Compiler<Emitter>::emitHLSLConstructAggregate(
8492 const auto &Src = Elements[ElemIdx++];
8493 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8495 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8499 unsigned NumElems = 0;
8502 NumElems = VT->getNumElements();
8503 ElemType = VT->getElementType();
8505 NumElems = MT->getNumElementsFlattened();
8506 ElemType = MT->getElementType();
8509 PrimType DestElemT = classifyPrim(ElemType);
8510 for (
unsigned I = 0; I != NumElems; ++I) {
8511 if (!loadAndCast(DestElemT, ElemType))
8513 if (!this->emitInitElem(DestElemT, I, E))
8523 QualType ArrElemType = CAT->getElementType();
8524 unsigned ArrSize = CAT->getZExtSize();
8527 for (
unsigned I = 0; I != ArrSize; ++I) {
8528 if (!loadAndCast(*ElemT, ArrElemType))
8530 if (!this->emitInitElem(*ElemT, I, E))
8534 for (
unsigned I = 0; I != ArrSize; ++I) {
8535 if (!this->emitConstUint32(I, E))
8537 if (!this->emitArrayElemPtrUint32(E))
8539 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8541 if (!this->emitFinishInitPop(E))
8551 const Record *
R = getRecord(DestType);
8555 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8557 const Record::Base *B =
R->getBase(BS.getType());
8559 if (!this->emitGetPtrBase(B->Offset, E))
8561 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
8563 if (!this->emitFinishInitPop(E))
8568 for (
const Record::Field &F :
R->fields()) {
8569 if (F.isUnnamedBitField())
8572 QualType FieldType = F.Decl->getType();
8574 if (!loadAndCast(*FieldT, FieldType))
8576 if (F.isBitField()) {
8577 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8580 if (!this->emitInitField(*FieldT, F.Offset, E))
8584 if (!this->emitGetPtrField(F.Offset, E))
8586 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
8588 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)
Result
Implement __builtin_bit_cast and related operations.
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
bool isMemberPointerToDerivedMember() const
unsigned getStructNumBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool 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
InitListExpr * getUpdater() 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() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
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 visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool 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 visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
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 VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
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()