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: {
380 return this->emitVectorConversion(E->
getSubExpr(), E);
384 if (!this->
visit(SubExpr))
386 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
390 case CK_IntegralToFloating: {
392 return this->emitVectorConversion(E->
getSubExpr(), E);
395 if (!this->
visit(SubExpr))
397 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
398 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
399 TargetSemantics, getFPOptions(E), E);
402 case CK_FloatingToBoolean: {
404 return this->emitVectorConversion(E->
getSubExpr(), E);
408 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
409 return this->emitConstBool(FL->getValue().isNonZero(), E);
410 if (!this->
visit(SubExpr))
412 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
415 case CK_FloatingToIntegral: {
417 return this->emitVectorConversion(E->
getSubExpr(), E);
420 if (!this->
visit(SubExpr))
424 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
427 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
430 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
433 case CK_NullToPointer:
434 case CK_NullToMemberPointer: {
437 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
442 case CK_PointerToIntegral: {
443 if (!this->
visit(SubExpr))
449 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
455 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
457 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
458 return this->emitCastPointerIntegral(T, E);
461 case CK_ArrayToPointerDecay: {
462 if (!this->
visit(SubExpr))
464 return this->emitArrayDecay(E);
467 case CK_IntegralToPointer: {
469 assert(IntType->isIntegralOrEnumerationType());
470 if (!this->
visit(SubExpr))
484 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
487 case CK_AtomicToNonAtomic:
488 case CK_ConstructorConversion:
489 case CK_FunctionToPointerDecay:
490 case CK_NonAtomicToAtomic:
492 case CK_UserDefinedConversion:
493 case CK_AddressSpaceConversion:
494 case CK_CPointerToObjCPointerCast:
511 return this->emitBuiltinBitCast(E);
526 if (!this->
visit(SubExpr))
534 return this->emitFnPtrCast(E);
541 if (!this->
visit(SubExpr))
543 return this->emitDecayPtr(*FromT, *ToT, E);
545 case CK_IntegralToBoolean:
546 case CK_FixedPointToBoolean: {
548 return this->emitVectorConversion(E->
getSubExpr(), E);
554 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
555 return this->emitConst(IL->getValue(), E);
556 if (!this->
visit(SubExpr))
561 case CK_IntegralCast:
563 return this->emitVectorConversion(E->
getSubExpr(), E);
565 case CK_BooleanToSignedIntegral: {
572 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
577 if (!this->emitConst(IL->getValue(), SubExpr))
580 if (!this->
visit(SubExpr))
588 if (!ED->isFixed()) {
589 if (!this->emitCheckEnumValue(*FromT, ED, E))
595 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
598 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
603 if (!this->emitCast(*FromT, *ToT, E))
606 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
607 return this->emitNeg(*ToT, E);
611 case CK_PointerToBoolean:
612 case CK_MemberPointerToBoolean: {
615 if (!this->
visit(SubExpr))
617 return this->emitIsNonNull(PtrT, E);
620 case CK_IntegralComplexToBoolean:
621 case CK_FloatingComplexToBoolean: {
622 if (!this->
visit(SubExpr))
624 return this->emitComplexBoolCast(SubExpr);
627 case CK_IntegralComplexToReal:
628 case CK_FloatingComplexToReal:
629 return this->emitComplexReal(SubExpr);
631 case CK_IntegralRealToComplex:
632 case CK_FloatingRealToComplex: {
639 if (!this->emitGetPtrLocal(*LocalIndex, E))
648 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
650 return this->emitInitElem(T, 1, SubExpr);
653 case CK_IntegralComplexCast:
654 case CK_FloatingComplexCast:
655 case CK_IntegralComplexToFloatingComplex:
656 case CK_FloatingComplexToIntegralComplex: {
663 if (!this->emitGetPtrLocal(*LocalIndex, E))
670 unsigned SubExprOffset =
672 if (!this->
visit(SubExpr))
674 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
682 for (
unsigned I = 0; I != 2; ++I) {
683 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
685 if (!this->emitArrayElemPop(SourceElemT, I, E))
689 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
693 if (!this->emitInitElem(DestElemT, I, E))
699 case CK_VectorSplat: {
710 if (!this->emitGetPtrLocal(*LocalIndex, E))
716 unsigned ElemOffset =
720 if (!this->
visit(SubExpr))
725 if (!this->emitSetLocal(ElemT, ElemOffset, E))
728 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
729 if (!this->emitGetLocal(ElemT, ElemOffset, E))
731 if (!this->emitInitElem(ElemT, I, E))
738 case CK_HLSLVectorTruncation: {
743 if (!this->
visit(SubExpr))
745 return this->emitArrayElemPop(*ResultT, 0, E);
754 if (!this->emitGetPtrLocal(*LocalIndex, E))
759 if (!this->
visit(SubExpr))
761 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
765 case CK_IntegralToFixedPoint: {
766 if (!this->
visit(SubExpr))
770 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
775 return this->emitPopFixedPoint(E);
778 case CK_FloatingToFixedPoint: {
779 if (!this->
visit(SubExpr))
783 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
784 if (!this->emitCastFloatingFixedPoint(Sem, E))
787 return this->emitPopFixedPoint(E);
790 case CK_FixedPointToFloating: {
791 if (!this->
visit(SubExpr))
793 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
794 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
797 return this->emitPopFloat(E);
800 case CK_FixedPointToIntegral: {
801 if (!this->
visit(SubExpr))
804 if (!this->emitCastFixedPointIntegral(IntegralT, E))
807 return this->emitPop(IntegralT, E);
810 case CK_FixedPointCast: {
811 if (!this->
visit(SubExpr))
814 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
815 if (!this->emitCastFixedPoint(Sem, E))
818 return this->emitPopFixedPoint(E);
826 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
828 case CK_LValueBitCast:
833 case CK_HLSLArrayRValue: {
840 if (!this->emitGetPtrLocal(*LocalIndex, E))
843 if (!this->
visit(SubExpr))
845 return this->emitMemcpy(E);
848 case CK_HLSLMatrixTruncation: {
853 if (!this->
visit(SubExpr))
855 return this->emitArrayElemPop(*ResultT, 0, E);
864 if (!this->emitGetPtrLocal(*LocalIndex, E))
869 if (!this->
visit(SubExpr))
871 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
875 case CK_HLSLAggregateSplatCast: {
885 if (!this->emitGetPtrLocal(*LocalIndex, E))
895 if (!this->
visit(SubExpr))
897 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
901 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
904 case CK_HLSLElementwiseCast: {
915 unsigned SrcPtrOffset =
917 if (!this->
visit(SubExpr))
919 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
923 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
925 if (Elements.empty())
928 const HLSLFlatElement &Src = Elements[0];
929 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
931 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
938 if (!this->emitGetPtrLocal(*LocalIndex, E))
944 if (!this->
visit(SubExpr))
946 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
950 unsigned ElemCount = countHLSLFlatElements(DestType);
953 Elements.reserve(ElemCount);
954 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
959 assert(Elements.size() == ElemCount &&
960 "Source type has fewer scalar elements than the destination type");
962 return emitHLSLConstructAggregate(DestType, Elements, E);
969 const Record::Field *RF = R->getField(UnionField);
970 QualType FieldType = RF->Decl->getType();
973 if (!this->
visit(SubExpr))
975 if (RF->isBitField())
976 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
978 return this->emitInitFieldActivate(*PT, RF->Offset, E);
981 if (!this->emitGetPtrField(RF->Offset, E))
983 if (!this->emitActivate(E))
989 return this->emitInvalid(E);
991 llvm_unreachable(
"Unhandled clang::CastKind enum");
994template <
class Emitter>
996 return this->emitBuiltinBitCast(E);
999template <
class Emitter>
1004 return this->emitConst(
LE->getValue(),
LE);
1007template <
class Emitter>
1013 return this->emitFloat(F, E);
1016template <
class Emitter>
1026 if (!this->emitGetPtrLocal(*LocalIndex, E))
1033 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1035 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1040template <
class Emitter>
1048 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1053template <
class Emitter>
1058template <
class Emitter>
1085 return this->emitComplexComparison(LHS, RHS, E);
1093 if (!this->
visit(LHS))
1096 if (!this->
visit(RHS))
1099 if (!this->emitToMemberPtr(E))
1105 if (!this->emitCastMemberPtrPtr(E))
1122 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1128 if (!this->emitGetPtrLocal(*ResultIndex, E))
1135 return this->emitCMP3(*
LT, CmpInfo, E);
1138 if (!
LT || !RT || !T)
1148 return this->visitAssignment(LHS, RHS, E);
1155 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1159 return this->emitPopBool(E);
1161 return this->emitCast(
PT_Bool, *T, E);
1165 auto Discard = [
this, T, E](
bool Result) {
1173 return MaybeCastToBool(this->emitEQ(*
LT, E));
1175 return MaybeCastToBool(this->emitNE(*
LT, E));
1177 return MaybeCastToBool(this->emitLT(*
LT, E));
1179 return MaybeCastToBool(this->emitLE(*
LT, E));
1181 return MaybeCastToBool(this->emitGT(*
LT, E));
1183 return MaybeCastToBool(this->emitGE(*
LT, E));
1186 return Discard(this->emitSubf(getFPOptions(E), E));
1187 return Discard(this->emitSub(*T, E));
1190 return Discard(this->emitAddf(getFPOptions(E), E));
1191 return Discard(this->emitAdd(*T, E));
1194 return Discard(this->emitMulf(getFPOptions(E), E));
1195 return Discard(this->emitMul(*T, E));
1197 return Discard(this->emitRem(*T, E));
1200 return Discard(this->emitDivf(getFPOptions(E), E));
1201 return Discard(this->emitDiv(*T, E));
1203 return Discard(this->emitBitAnd(*T, E));
1205 return Discard(this->emitBitOr(*T, E));
1207 return Discard(this->emitShl(*
LT, *RT, E));
1209 return Discard(this->emitShr(*
LT, *RT, E));
1211 return Discard(this->emitBitXor(*T, E));
1214 llvm_unreachable(
"Already handled earlier");
1219 llvm_unreachable(
"Unhandled binary op");
1224template <
class Emitter>
1230 if ((Op != BO_Add && Op != BO_Sub) ||
1241 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1242 if (!this->
visit(E))
1245 return this->emitDecayPtr(T,
PT_Ptr, E);
1254 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1262 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1265 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1272 if (!visitAsPointer(RHS, *RT))
1274 if (!this->
visit(LHS))
1278 if (!visitAsPointer(LHS, *
LT))
1280 if (!this->
visit(RHS))
1291 if (!this->emitAddOffset(OffsetType, E))
1295 if (!this->emitSubOffset(OffsetType, E))
1312template <
class Emitter>
1322 LabelTy LabelTrue = this->getLabel();
1323 LabelTy LabelEnd = this->getLabel();
1327 if (!this->jumpTrue(LabelTrue, E))
1332 if (!this->jump(LabelEnd, E))
1335 this->emitLabel(LabelTrue);
1336 this->emitConstBool(
true, E);
1337 this->fallthrough(LabelEnd);
1338 this->emitLabel(LabelEnd);
1341 assert(Op == BO_LAnd);
1344 LabelTy LabelFalse = this->getLabel();
1345 LabelTy LabelEnd = this->getLabel();
1349 if (!this->jumpFalse(LabelFalse, E))
1354 if (!this->jump(LabelEnd, E))
1357 this->emitLabel(LabelFalse);
1358 this->emitConstBool(
false, E);
1359 this->fallthrough(LabelEnd);
1360 this->emitLabel(LabelEnd);
1364 return this->emitPopBool(E);
1369 return this->emitCast(
PT_Bool, *T, E);
1373template <
class Emitter>
1380 if (!this->emitGetPtrLocal(*LocalIndex, E))
1389 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1390 unsigned ResultOffset = ~0u;
1396 if (!this->emitDupPtr(E))
1398 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1403 LHSType = AT->getValueType();
1406 RHSType = AT->getValueType();
1415 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1420 if (!this->
visit(LHS))
1422 if (!this->
visit(RHS))
1424 if (!this->emitMulc(ElemT, E))
1427 return this->emitPopPtr(E);
1431 if (Op == BO_Div && RHSIsComplex) {
1438 if (!LHSIsComplex) {
1443 LHSOffset = *LocalIndex;
1445 if (!this->emitGetPtrLocal(LHSOffset, E))
1448 if (!this->
visit(LHS))
1451 if (!this->emitInitElem(ElemT, 0, E))
1454 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1456 if (!this->emitInitElem(ElemT, 1, E))
1459 if (!this->
visit(LHS))
1463 if (!this->
visit(RHS))
1465 if (!this->emitDivc(ElemT, E))
1468 return this->emitPopPtr(E);
1475 if (!this->
visit(LHS))
1477 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1482 if (!this->
visit(LHS))
1484 if (!this->emitSetLocal(LHST, LHSOffset, E))
1492 if (!this->
visit(RHS))
1494 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1499 if (!this->
visit(RHS))
1501 if (!this->emitSetLocal(RHST, RHSOffset, E))
1508 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1509 unsigned ElemIndex,
unsigned Offset,
1510 const Expr *E) ->
bool {
1512 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1514 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1517 if (ElemIndex == 0 || !LoadZero)
1524 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1527 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1534 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1537 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1540 if (!this->emitAddf(getFPOptions(E), E))
1543 if (!this->emitAdd(ResultElemT, E))
1548 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1551 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1554 if (!this->emitSubf(getFPOptions(E), E))
1557 if (!this->emitSub(ResultElemT, E))
1562 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1565 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1569 if (!this->emitMulf(getFPOptions(E), E))
1572 if (!this->emitMul(ResultElemT, E))
1577 assert(!RHSIsComplex);
1578 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1581 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1585 if (!this->emitDivf(getFPOptions(E), E))
1588 if (!this->emitDiv(ResultElemT, E))
1599 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1602 if (!this->emitPop(ResultElemT, E))
1607 return this->emitPopPtr(E);
1613template <
class Emitter>
1618 "Comma op should be handled in VisitBinaryOperator");
1632 if (!this->emitGetPtrLocal(*LocalIndex, E))
1646 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1649 if (!this->
visit(LHS))
1651 if (!this->
visit(RHS))
1653 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1656 return this->emitPopPtr(E);
1661 unsigned LHSOffset =
1663 if (!this->
visit(LHS))
1665 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1669 unsigned RHSOffset =
1671 if (!this->
visit(RHS))
1673 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1685 if (NeedIntPromot) {
1687 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1692 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1693 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1695 if (!this->emitArrayElemPop(ElemT, Index, E))
1698 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1700 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1702 }
else if (NeedIntPromot) {
1703 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1709#define EMIT_ARITH_OP(OP) \
1711 if (ElemT == PT_Float) { \
1712 if (!this->emit##OP##f(getFPOptions(E), E)) \
1715 if (!this->emit##OP(ElemT, E)) \
1721 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1722 if (!getElem(LHSOffset, ElemT, I))
1724 if (!getElem(RHSOffset, RHSElemT, I))
1736 if (!this->emitRem(ElemT, E))
1740 if (!this->emitBitAnd(OpT, E))
1744 if (!this->emitBitOr(OpT, E))
1748 if (!this->emitBitXor(OpT, E))
1752 if (!this->emitShl(OpT, RHSElemT, E))
1756 if (!this->emitShr(OpT, RHSElemT, E))
1760 if (!this->emitEQ(ElemT, E))
1764 if (!this->emitNE(ElemT, E))
1768 if (!this->emitLE(ElemT, E))
1772 if (!this->emitLT(ElemT, E))
1776 if (!this->emitGE(ElemT, E))
1780 if (!this->emitGT(ElemT, E))
1785 if (!this->emitBitAnd(ResultElemT, E))
1790 if (!this->emitBitOr(ResultElemT, E))
1794 return this->emitInvalid(E);
1803 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1805 if (!this->emitNeg(ResultElemT, E))
1811 if (NeedIntPromot &&
1812 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1816 if (!this->emitInitElem(ResultElemT, I, E))
1825template <
class Emitter>
1835 auto LHSSemaInt = LHSSema.toOpaqueInt();
1837 auto RHSSemaInt = RHSSema.toOpaqueInt();
1839 if (!this->
visit(LHS))
1847 if (!this->
visit(RHS))
1856 auto ConvertResult = [&](
bool R) ->
bool {
1860 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1861 if (ResultSema != CommonSema)
1862 return this->emitCastFixedPoint(ResultSema, E);
1866 auto MaybeCastToBool = [&](
bool Result) {
1871 return this->emitPop(T, E);
1873 return this->emitCast(
PT_Bool, T, E);
1879 return MaybeCastToBool(this->emitEQFixedPoint(E));
1881 return MaybeCastToBool(this->emitNEFixedPoint(E));
1883 return MaybeCastToBool(this->emitLTFixedPoint(E));
1885 return MaybeCastToBool(this->emitLEFixedPoint(E));
1887 return MaybeCastToBool(this->emitGTFixedPoint(E));
1889 return MaybeCastToBool(this->emitGEFixedPoint(E));
1891 return ConvertResult(this->emitAddFixedPoint(E));
1893 return ConvertResult(this->emitSubFixedPoint(E));
1895 return ConvertResult(this->emitMulFixedPoint(E));
1897 return ConvertResult(this->emitDivFixedPoint(E));
1899 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1901 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1904 return this->emitInvalid(E);
1907 llvm_unreachable(
"unhandled binop opcode");
1910template <
class Emitter>
1919 if (!this->
visit(SubExpr))
1921 if (!this->emitNegFixedPoint(E))
1924 return this->emitPopFixedPoint(E);
1930 llvm_unreachable(
"Unhandled unary opcode");
1933template <
class Emitter>
1942 return this->visitZeroInitializer(*T, QT, E);
1950 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1951 CXXRD && CXXRD->getNumVBases() > 0) {
1961 return this->visitZeroRecordInitializer(R, E);
1968 return this->visitZeroArrayInitializer(QT, E);
1972 QualType ElemQT = ComplexTy->getElementType();
1974 for (
unsigned I = 0; I < 2; ++I) {
1975 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1977 if (!this->emitInitElem(ElemT, I, E))
1984 unsigned NumVecElements = VecT->getNumElements();
1985 QualType ElemQT = VecT->getElementType();
1988 for (
unsigned I = 0; I < NumVecElements; ++I) {
1989 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1991 if (!this->emitInitElem(ElemT, I, E))
1998 unsigned NumElems = MT->getNumElementsFlattened();
1999 QualType ElemQT = MT->getElementType();
2002 for (
unsigned I = 0; I != NumElems; ++I) {
2003 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2005 if (!this->emitInitElem(ElemT, I, E))
2014template <
class Emitter>
2027 for (
const Expr *SubExpr : {LHS, RHS}) {
2028 if (!this->
visit(SubExpr)) {
2035 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2036 if (!this->emitExpandPtr(E))
2047 return this->emitError(E);
2050 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2054 if (!this->emitArrayElemPtrPop(*IndexT, E))
2057 return this->emitPopPtr(E);
2063 return this->emitLoadPop(*T, E);
2066template <
class Emitter>
2068 const Expr *ArrayFiller,
const Expr *E) {
2073 QT = AT->getValueType();
2076 if (
Inits.size() == 0)
2078 return this->emitInvalid(E);
2093 if (
Inits.size() == 0)
2094 return this->visitZeroInitializer(*T, QT, E);
2095 assert(
Inits.size() == 1);
2108 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2115 bool BitField = FieldToInit->isBitField();
2117 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2118 FieldToInit->bitWidth(), E);
2120 return this->emitInitBitField(T, FieldToInit->Offset,
2121 FieldToInit->bitWidth(), E);
2123 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2124 return this->emitInitField(T, FieldToInit->Offset, E);
2127 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2135 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2138 if (
Activate && !this->emitActivate(E))
2145 if (
Inits.size() == 0) {
2146 if (!this->visitZeroRecordInitializer(R, E))
2151 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2152 FToInit = ILE->getInitializedFieldInUnion();
2156 const Record::Field *FieldToInit = R->getField(FToInit);
2158 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2161 if (!initCompositeField(FieldToInit,
Init,
true))
2165 return this->emitFinishInit(E);
2168 assert(!R->isUnion());
2169 unsigned InitIndex = 0;
2172 while (InitIndex < R->getNumFields() &&
2173 R->getField(InitIndex)->isUnnamedBitField())
2184 const Record::Field *FieldToInit = R->getField(InitIndex);
2185 if (!initPrimitiveField(FieldToInit,
Init, *T))
2190 if (
const Record::Base *B = R->getBase(
Init->getType())) {
2191 if (!this->emitGetPtrBase(B->Offset,
Init))
2199 const Record::Field *FieldToInit = R->getField(InitIndex);
2200 if (!initCompositeField(FieldToInit,
Init))
2206 return this->emitFinishInit(E);
2211 Ctx.getASTContext().getAsConstantArrayType(QT);
2214 if (
Initializing && !this->emitCheckArrayDestSize(NumElems, E))
2217 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2221 unsigned ElementIndex = 0;
2223 if (
const auto *EmbedS =
2224 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2232 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2233 getFPOptions(E), E))
2239 return this->emitInitElem(TargetT, ElemIndex, IL);
2241 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2257 for (; ElementIndex != NumElems; ++ElementIndex) {
2263 return this->emitFinishInit(E);
2267 unsigned NumInits =
Inits.size();
2272 QualType ElemQT = ComplexTy->getElementType();
2274 if (NumInits == 0) {
2276 for (
unsigned I = 0; I < 2; ++I) {
2277 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2279 if (!this->emitInitElem(ElemT, I, E))
2282 }
else if (NumInits == 2) {
2283 unsigned InitIndex = 0;
2288 if (!this->emitInitElem(ElemT, InitIndex, E))
2297 unsigned NumVecElements = VecT->getNumElements();
2298 assert(NumVecElements >=
Inits.size());
2300 QualType ElemQT = VecT->getElementType();
2304 unsigned InitIndex = 0;
2311 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2312 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2313 InitVecT->getNumElements(), E))
2315 InitIndex += InitVecT->getNumElements();
2317 if (!this->emitInitElem(ElemT, InitIndex, E))
2323 assert(InitIndex <= NumVecElements);
2326 for (; InitIndex != NumVecElements; ++InitIndex) {
2327 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2329 if (!this->emitInitElem(ElemT, InitIndex, E))
2336 unsigned NumElems = MT->getNumElementsFlattened();
2337 assert(
Inits.size() == NumElems);
2339 QualType ElemQT = MT->getElementType();
2345 for (
unsigned I = 0; I != NumElems; ++I) {
2348 if (!this->emitInitElem(ElemT, I, E))
2359template <
class Emitter>
2366 return this->emitInitElem(*InitT, ElemIndex,
Init);
2372 if (!this->emitConstUint32(ElemIndex,
Init))
2374 if (!this->emitArrayElemPtrUint32(
Init))
2379template <
class Emitter>
2382 bool Activate,
bool IsOperatorCall) {
2384 llvm::BitVector NonNullArgs;
2385 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2388 bool ExplicitMemberFn =
false;
2389 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2390 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2392 unsigned ArgIndex = 0;
2393 for (
const Expr *Arg : Args) {
2395 if (!this->
visit(Arg))
2403 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2404 if (DeclIndex < FuncDecl->getNumParams())
2405 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2414 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2422 if (!this->emitActivate(Arg))
2426 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2429 if (!this->emitCheckNonNullArg(ArgT, Arg))
2440template <
class Emitter>
2445template <
class Emitter>
2451template <
class Emitter>
2457template <
class Emitter>
2475template <
class Emitter>
2477 auto It = E->
begin();
2478 return this->
visit(*It);
2483 bool AlignOfReturnsPreferred =
2490 T = Ref->getPointeeType();
2492 if (T.getQualifiers().hasUnaligned())
2498 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2504template <
class Emitter>
2511 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2517 ArgType = Ref->getPointeeType();
2523 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2524 return this->emitInvalid(E);
2526 if (Kind == UETT_SizeOf)
2535 return this->emitConst(Size.getQuantity(), E);
2538 if (Kind == UETT_CountOf) {
2544 if (
const auto *CAT =
2548 return this->emitConst(CAT->getSize(), E);
2558 if (VAT->getElementType()->isArrayType()) {
2559 std::optional<APSInt> Res =
2561 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2566 return this->emitConst(*Res, E);
2571 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2591 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2594 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2604 return this->emitConst(Size.getQuantity(), E);
2607 if (Kind == UETT_VectorElements) {
2612 return this->emitConst(VT->getNumElements(), E);
2614 return this->emitSizelessVectorElementSize(E);
2617 if (Kind == UETT_VecStep) {
2619 unsigned N = VT->getNumElements();
2626 return this->emitConst(N, E);
2628 return this->emitConst(1, E);
2631 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2640 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2642 return this->emitInvalid(E);
2644 return this->emitConst(
2645 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2653template <
class Emitter>
2662 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2665 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2666 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2668 if (
Member->getType()->isReferenceType())
2669 return this->emitLoadPopPtr(E);
2678 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2679 MD && !MD->isStatic()) {
2683 if (!this->
discard(Base) && !this->emitSideEffect(E))
2698 const Record::Field *F = R->getField(FD);
2702 const auto maybeLoadValue = [&]() ->
bool {
2706 return this->emitLoadPop(*T, E);
2711 if (F->Decl->getType()->isReferenceType())
2712 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2713 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2716template <
class Emitter>
2726template <
class Emitter>
2740 if (!this->
visit(Common))
2742 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2756 for (
size_t I = 0; I != Size; ++I) {
2768template <
class Emitter>
2783 return this->emitGetLocal(SubExprT, It->second, E);
2786 if (!this->
visit(SourceExpr))
2793 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2802 return this->emitGetLocal(SubExprT, LocalIndex, E);
2806template <
class Emitter>
2819 bool IsBcpCall =
false;
2820 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2821 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2825 LabelTy LabelEnd = this->getLabel();
2826 LabelTy LabelFalse = this->getLabel();
2829 if (!this->emitPushIgnoreDiags(E))
2837 if (this->checkingForUndefinedBehavior()) {
2840 if (!this->
discard(FalseExpr))
2857 if (!this->jumpFalse(LabelFalse, E))
2862 if (!this->jump(LabelEnd, E))
2864 this->emitLabel(LabelFalse);
2868 this->fallthrough(LabelEnd);
2869 this->emitLabel(LabelEnd);
2872 return this->emitPopIgnoreDiags(E);
2876template <
class Emitter>
2882 unsigned StringIndex =
P.createGlobalString(E);
2883 return this->emitGetPtrGlobal(StringIndex, E);
2888 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2889 assert(CAT &&
"a string literal that's not a constant array?");
2894 unsigned N = std::min(ArraySize, E->
getLength());
2897 for (
unsigned I = 0; I != N; ++I) {
2900 if (CharWidth == 1) {
2901 this->emitConstSint8(CodeUnit, E);
2902 this->emitInitElemSint8(I, E);
2903 }
else if (CharWidth == 2) {
2904 this->emitConstUint16(CodeUnit, E);
2905 this->emitInitElemUint16(I, E);
2906 }
else if (CharWidth == 4) {
2907 this->emitConstUint32(CodeUnit, E);
2908 this->emitInitElemUint32(I, E);
2910 llvm_unreachable(
"unsupported character width");
2915 for (
unsigned I = N; I != ArraySize; ++I) {
2916 if (CharWidth == 1) {
2917 this->emitConstSint8(0, E);
2918 this->emitInitElemSint8(I, E);
2919 }
else if (CharWidth == 2) {
2920 this->emitConstUint16(0, E);
2921 this->emitInitElemUint16(I, E);
2922 }
else if (CharWidth == 4) {
2923 this->emitConstUint32(0, E);
2924 this->emitInitElemUint32(I, E);
2926 llvm_unreachable(
"unsupported character width");
2933template <
class Emitter>
2937 return this->emitDummyPtr(E, E);
2940template <
class Emitter>
2942 auto &A =
Ctx.getASTContext();
2951template <
class Emitter>
2959 auto &A =
Ctx.getASTContext();
2963 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2964 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2971 unsigned StringIndex =
P.createGlobalString(SL);
2972 return this->emitGetPtrGlobal(StringIndex, E);
2975template <
class Emitter>
2979 return this->emitConst(E->
getValue(), E);
2982template <
class Emitter>
3008 if (!this->emitSetLocal(*RT, TempOffset, E))
3014 if (!this->emitLoad(LHST, E))
3018 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3019 LHSComputationType, E))
3023 if (!this->emitGetLocal(*RT, TempOffset, E))
3028 if (!this->emitAddf(getFPOptions(E), E))
3032 if (!this->emitSubf(getFPOptions(E), E))
3036 if (!this->emitMulf(getFPOptions(E), E))
3040 if (!this->emitDivf(getFPOptions(E), E))
3051 return this->emitStorePop(LHST, E);
3052 return this->emitStore(LHST, E);
3055template <
class Emitter>
3064 if (Op != BO_AddAssign && Op != BO_SubAssign)
3073 if (!this->emitLoad(*
LT, LHS))
3079 if (Op == BO_AddAssign) {
3080 if (!this->emitAddOffset(*RT, E))
3083 if (!this->emitSubOffset(*RT, E))
3088 return this->emitStorePopPtr(E);
3089 return this->emitStorePtr(E);
3092template <
class Emitter>
3105 if (!
Ctx.getLangOpts().CPlusPlus14)
3106 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3108 if (!
LT || !RT || !ResultT || !LHSComputationT)
3133 if (!this->emitSetLocal(*RT, TempOffset, E))
3140 if (!this->emitLoad(*
LT, E))
3142 if (
LT != LHSComputationT &&
3148 if (!this->emitGetLocal(*RT, TempOffset, E))
3154 if (!this->emitAdd(*LHSComputationT, E))
3158 if (!this->emitSub(*LHSComputationT, E))
3162 if (!this->emitMul(*LHSComputationT, E))
3166 if (!this->emitDiv(*LHSComputationT, E))
3170 if (!this->emitRem(*LHSComputationT, E))
3174 if (!this->emitShl(*LHSComputationT, *RT, E))
3178 if (!this->emitShr(*LHSComputationT, *RT, E))
3182 if (!this->emitBitAnd(*LHSComputationT, E))
3186 if (!this->emitBitXor(*LHSComputationT, E))
3190 if (!this->emitBitOr(*LHSComputationT, E))
3194 llvm_unreachable(
"Unimplemented compound assign operator");
3198 if (ResultT != LHSComputationT &&
3199 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3205 return this->emitStoreBitFieldPop(*ResultT, E);
3206 return this->emitStorePop(*ResultT, E);
3209 return this->emitStoreBitField(*ResultT, E);
3210 return this->emitStore(*ResultT, E);
3213template <
class Emitter>
3221template <
class Emitter>
3236 if (!
Ctx.getLangOpts().CPlusPlus11)
3243 for (
const Expr *LHS : CommaLHSs) {
3265 if (!this->
visit(Inner))
3270 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3273 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3276 return this->emitGetPtrGlobal(*GlobalIndex, E);
3279 if (!this->checkLiteralType(Inner))
3282 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3288 return this->emitInitGlobalTempComp(TempDecl, E);
3301 unsigned LocalIndex =
3303 if (!this->VarScope->LocalsAlwaysEnabled &&
3304 !this->emitEnableLocal(LocalIndex, E))
3307 if (!this->
visit(Inner))
3309 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3312 return this->emitGetPtrLocal(LocalIndex, E);
3315 if (!this->checkLiteralType(Inner))
3322 if (!this->VarScope->LocalsAlwaysEnabled &&
3323 !this->emitEnableLocal(*LocalIndex, E))
3326 if (!this->emitGetPtrLocal(*LocalIndex, E))
3333template <
class Emitter>
3344 if (!this->
visit(SubExpr))
3348 return this->emitPopPtr(E);
3352template <
class Emitter>
3373 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3378 if (
P.isGlobalInitialized(*GlobalIndex))
3384 return this->emitInitGlobal(*T, *GlobalIndex, E);
3396 unsigned LocalIndex;
3400 LocalIndex = *MaybeIndex;
3404 if (!this->emitGetPtrLocal(LocalIndex, E))
3408 return this->
visit(
Init) && this->emitInit(*T, E);
3412template <
class Emitter>
3425template <
class Emitter>
3429 return this->emitConst(E->
getValue(), E);
3432template <
class Emitter>
3445 for (
const Record::Field &F : R->fields()) {
3447 if (!
Init ||
Init->containsErrors())
3455 if (!this->emitInitField(*T, F.Offset, E))
3458 if (!this->emitGetPtrField(F.Offset, E))
3469template <
class Emitter>
3476 return this->emitGetPtrGlobal(StringIndex, E);
3482template <
class Emitter>
3487 return this->emitInvalid(E);
3490template <
class Emitter>
3516 if (PointeeToT && PointeeFromT) {
3535 bool Fatal = (ToT != FromT);
3542template <
class Emitter>
3544 if (!
Ctx.getLangOpts().CPlusPlus20) {
3565 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3570 return this->emitPopPtr(E);
3574template <
class Emitter>
3580 return this->emitConstBool(E->
getValue(), E);
3583template <
class Emitter>
3588 if (T->isRecordType()) {
3602 if (!this->emitGetPtrLocal(*LocalIndex, E))
3610 T->getAsCXXRecordDecl()))
3620 if (!this->visitZeroRecordInitializer(R, E))
3632 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3634 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3635 if (!this->emitCheckFunctionDecl(Ctor, E))
3646 assert(
Func->hasThisPointer());
3647 assert(!
Func->hasRVO());
3651 if (!this->emitDupPtr(E))
3655 for (
const auto *Arg : E->
arguments()) {
3656 if (!this->
visit(Arg))
3660 if (
Func->isVariadic()) {
3661 uint32_t VarArgSize = 0;
3662 unsigned NumParams =
Func->getNumWrittenParams();
3663 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3667 if (!this->emitCallVar(
Func, VarArgSize, E))
3670 if (!this->emitCall(
Func, 0, E)) {
3675 (void)this->emitPopPtr(E);
3681 return this->emitPopPtr(E);
3685 if (T->isArrayType()) {
3690 if (!this->emitDupPtr(E))
3694 initArrayDimension = [&](
QualType T) ->
bool {
3695 if (!T->isArrayType()) {
3697 for (
const auto *Arg : E->
arguments()) {
3698 if (!this->
visit(Arg))
3702 return this->emitCall(
Func, 0, E);
3706 Ctx.getASTContext().getAsConstantArrayType(T);
3711 for (
size_t I = 0; I != NumElems; ++I) {
3712 if (!this->emitConstUint64(I, E))
3714 if (!this->emitArrayElemPtrUint64(E))
3716 if (!initArrayDimension(ElemTy))
3719 return this->emitPopPtr(E);
3722 return initArrayDimension(E->
getType());
3728template <
class Emitter>
3738 assert(Val.
isInt());
3740 return this->emitConst(I, E);
3747 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3748 return this->
visit(LValueExpr);
3763 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3767 const APValue &
V = UGCD->getValue();
3768 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3769 const Record::Field *F = R->getField(I);
3770 const APValue &FieldValue =
V.getStructField(I);
3776 if (!this->emitInitField(FieldT, F->Offset, E))
3784template <
class Emitter>
3790 for (
unsigned I = 0; I != N; ++I) {
3797 if (!this->
discard(ArrayIndexExpr))
3802 if (!this->
visit(ArrayIndexExpr))
3806 if (!this->emitCast(IndexT,
PT_Sint64, E))
3816 return this->emitOffsetOf(T, E, E);
3819template <
class Emitter>
3828 return this->visitZeroInitializer(*T, Ty, E);
3835 if (!this->emitGetPtrLocal(*LocalIndex, E))
3843 ElemQT = CT->getElementType();
3846 NumElems = VT->getNumElements();
3847 ElemQT = VT->getElementType();
3853 for (
unsigned I = 0, N = NumElems; I != N; ++I) {
3854 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3856 if (!this->emitInitElem(ElemT, I, E))
3865template <
class Emitter>
3870template <
class Emitter>
3876template <
class Emitter>
3881template <
class Emitter>
3886 return this->emitConst(E->
getValue(), E);
3889template <
class Emitter>
3894 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3908 unsigned ParamIndex = 0;
3912 if (!this->emitGetParam(PT, ParamIndex, E))
3917 return this->emitCall(F, 0, E);
3922template <
class Emitter>
3930 const Expr *PlacementDest =
nullptr;
3931 bool IsNoThrow =
false;
3936 if (PlacementArgs != 0) {
3945 if (PlacementArgs == 1) {
3953 if (!this->emitInvalidNewDeleteExpr(E, E))
3958 if (OperatorNew->isReservedGlobalPlacementOperator())
3959 PlacementDest = Arg1;
3963 return this->emitInvalid(E);
3965 }
else if (!OperatorNew
3966 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3967 return this->emitInvalidNewDeleteExpr(E, E);
3970 if (!PlacementDest) {
3975 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3978 Desc =
P.createDescriptor(
3981 false,
false,
false,
3987 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3991 const Expr *Stripped = *ArraySizeExpr;
3992 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3993 Stripped = ICE->getSubExpr())
3994 if (ICE->getCastKind() != CK_NoOp &&
3995 ICE->getCastKind() != CK_IntegralCast)
4003 if (!this->
visit(Stripped))
4005 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4008 if (PlacementDest) {
4009 if (!this->
visit(PlacementDest))
4011 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4013 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4016 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4021 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4025 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4032 size_t StaticInitElems = 0;
4033 const Expr *DynamicInit =
nullptr;
4037 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4038 StaticInitElems = CAT->getZExtSize();
4043 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4044 if (ILE->hasArrayFiller())
4045 DynamicInit = ILE->getArrayFiller();
4064 const Function *CtorFunc =
nullptr;
4065 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4069 }
else if (!DynamicInit && !ElemT)
4072 LabelTy EndLabel = this->getLabel();
4073 LabelTy StartLabel = this->getLabel();
4078 if (!this->emitDupPtr(E))
4080 if (!this->emitNullPtr(0,
nullptr, E))
4082 if (!this->emitEQPtr(E))
4084 if (!this->jumpTrue(EndLabel, E))
4091 if (!this->emitConst(StaticInitElems,
SizeT, E))
4093 if (!this->emitSetLocal(
SizeT, Iter, E))
4096 this->fallthrough(StartLabel);
4097 this->emitLabel(StartLabel);
4099 if (!this->emitGetLocal(
SizeT, Iter, E))
4101 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4103 if (!this->emitLT(
SizeT, E))
4105 if (!this->jumpFalse(EndLabel, E))
4109 if (!this->emitGetLocal(
SizeT, Iter, E))
4111 if (!this->emitArrayElemPtr(
SizeT, E))
4114 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4119 if (!this->visitZeroInitializer(InitT, ElemType, E))
4121 if (!this->emitStorePop(InitT, E))
4123 }
else if (DynamicInit) {
4125 if (!this->
visit(DynamicInit))
4127 if (!this->emitStorePop(*InitT, E))
4134 if (!this->visitZeroInitializer(
4138 if (!this->emitStorePop(*ElemT, E))
4142 if (!this->emitCall(CtorFunc, 0, E))
4147 if (!this->emitGetPtrLocal(Iter, E))
4149 if (!this->emitIncPop(
SizeT,
false, E))
4152 if (!this->jump(StartLabel, E))
4155 this->fallthrough(EndLabel);
4156 this->emitLabel(EndLabel);
4160 if (PlacementDest) {
4161 if (!this->
visit(PlacementDest))
4163 if (!this->emitCheckNewTypeMismatch(E, E))
4168 if (!this->emitAlloc(Desc, E))
4177 if (!this->emitInit(*ElemT, E))
4188 return this->emitPopPtr(E);
4193template <
class Emitter>
4199 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4200 return this->emitInvalidNewDeleteExpr(E, E);
4209template <
class Emitter>
4215 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4220 return this->emitGetFnPtr(
Func, E);
4223template <
class Emitter>
4227 auto canonType = [](
const Type *T) {
4228 return T->getCanonicalTypeUnqualified().getTypePtr();
4236 return this->emitGetTypeid(
4240 return this->emitGetTypeid(
4249 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4255 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4258 return this->emitPopPtr(E);
4262template <
class Emitter>
4266 return this->emitDummyPtr(E, E);
4267 return this->emitError(E);
4270template <
class Emitter>
4273 return this->emitDummyPtr(E, E);
4274 return this->emitError(E);
4277template <
class Emitter>
4279 assert(
Ctx.getLangOpts().CPlusPlus);
4280 return this->emitConstBool(E->
getValue(), E);
4283template <
class Emitter>
4295 return this->emitDummyPtr(GuidDecl, E);
4300 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4309 assert(
V.isStruct());
4310 assert(
V.getStructNumBases() == 0);
4314 return this->emitFinishInit(E);
4317template <
class Emitter>
4327template <
class Emitter>
4336template <
class Emitter>
4342template <
class Emitter>
4346 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4350 if (OVE->isUnique())
4366template <
class Emitter>
4371template <
class Emitter>
4373 return this->emitError(E);
4376template <
class Emitter>
4382 return this->emitDummyPtr(E, E);
4385template <
class Emitter>
4386bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4391 QualType ElemType = VT->getElementType();
4392 PrimType ElemT = classifyPrim(ElemType);
4394 PrimType SrcElemT = classifyVectorElementType(SrcType);
4400 if (!this->emitGetPtrLocal(*LocalIndex, E))
4404 unsigned SrcOffset =
4405 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4406 if (!this->visit(Src))
4408 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4411 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4412 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4414 if (!this->emitArrayElemPop(SrcElemT, I, E))
4418 if (SrcElemT != ElemT) {
4419 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4421 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4422 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4426 if (!this->emitInitElem(ElemT, I, E))
4432template <
class Emitter>
4434 return emitVectorConversion(E->
getSrcExpr(), E);
4437template <
class Emitter>
4441 return this->emitInvalid(E);
4450 assert(NumOutputElems > 0);
4456 if (!this->emitGetPtrLocal(*LocalIndex, E))
4461 unsigned VectorOffsets[2];
4462 for (
unsigned I = 0; I != 2; ++I) {
4465 if (!this->
visit(Vecs[I]))
4467 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4470 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4472 assert(ShuffleIndex >= -1);
4473 if (ShuffleIndex == -1)
4474 return this->emitInvalidShuffleVectorIndex(I, E);
4476 assert(ShuffleIndex < (NumInputElems * 2));
4477 if (!this->emitGetLocal(
PT_Ptr,
4478 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4480 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4481 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4484 if (!this->emitInitElem(ElemT, I, E))
4489 return this->emitPopPtr(E);
4494template <
class Emitter>
4499 Base->getType()->isVectorType() ||
4505 if (Indices.size() == 1) {
4510 if (!this->emitConstUint32(Indices[0], E))
4512 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4522 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4530 if (!this->emitGetPtrLocal(*ResultIndex, E))
4538 uint32_t DstIndex = 0;
4539 for (uint32_t I : Indices) {
4540 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4542 if (!this->emitArrayElemPop(ElemT, I, E))
4544 if (!this->emitInitElem(ElemT, DstIndex, E))
4554template <
class Emitter>
4558 return this->
discard(SubExpr) && this->emitInvalid(E);
4564 return this->emitDummyPtr(E, E);
4567template <
class Emitter>
4572 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4577 if (!this->
visit(SubExpr))
4579 if (!this->emitConstUint8(0, E))
4581 if (!this->emitArrayElemPtrPopUint8(E))
4583 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4588 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4590 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4592 assert(SecondFieldT ==
PT_Ptr);
4594 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4596 if (!this->emitExpandPtr(E))
4600 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4602 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4605template <
class Emitter>
4620 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4622 return this->emitUnsupported(E);
4631 return this->
Visit(E);
4638 return this->
Visit(E);
4642 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4645 if (
const auto *CE = dyn_cast<CastExpr>(E);
4647 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4654 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4657 if (
const auto *CE = dyn_cast<CastExpr>(E);
4658 CE && (CE->getCastKind() == CK_DerivedToBase ||
4659 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4660 CE->getCastKind() == CK_NoOp))
4680 if (!this->emitGetPtrLocal(*LocalIndex, E))
4690 return this->
Visit(E);
4693template <
class Emitter>
4699 return this->
Visit(E) && this->emitFinishInit(E);
4702template <
class Emitter>
4708 return this->
Visit(E) && this->emitFinishInitPop(E);
4714 return this->
Visit(E);
4725 if (!this->
visit(E))
4727 return this->emitComplexBoolCast(E);
4732 if (!this->
visit(E))
4740 return this->emitIsNonNullPtr(E);
4744 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4747 return this->emitCast(*T,
PT_Bool, E);
4750template <
class Emitter>
4754 QT = AT->getValueType();
4758 return this->emitZeroBool(E);
4760 return this->emitZeroSint8(E);
4762 return this->emitZeroUint8(E);
4764 return this->emitZeroSint16(E);
4766 return this->emitZeroUint16(E);
4768 return this->emitZeroSint32(E);
4770 return this->emitZeroUint32(E);
4772 return this->emitZeroSint64(E);
4774 return this->emitZeroUint64(E);
4776 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4778 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4780 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4783 return this->emitNullMemberPtr(0,
nullptr, E);
4785 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4786 return this->emitFloat(F, E);
4789 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
4793 llvm_unreachable(
"unknown primitive type");
4796template <
class Emitter>
4797bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4802 for (
const Record::Field &Field :
R->fields()) {
4803 if (Field.isUnnamedBitField())
4810 if (!this->visitZeroInitializer(T, QT, E))
4813 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4817 if (!this->emitInitField(T, Field.Offset, E))
4822 if (!this->emitGetPtrField(Field.Offset, E))
4829 if (!this->visitZeroInitializer(T, ET, E))
4831 if (!this->emitInitElem(T, I, E))
4836 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4839 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4847 if (!this->emitFinishInitActivatePop(E))
4851 if (!this->emitFinishInitPop(E))
4855 for (
const Record::Base &B :
R->bases()) {
4856 if (!this->emitGetPtrBase(B.Offset, E))
4858 if (!this->visitZeroRecordInitializer(B.R, E))
4860 if (!this->emitFinishInitPop(E))
4869template <
class Emitter>
4870bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4871 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4877 for (
size_t I = 0; I != NumElems; ++I) {
4878 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4880 if (!this->emitInitElem(*ElemT, I, E))
4886 const Record *
R = getRecord(ElemType);
4890 for (
size_t I = 0; I != NumElems; ++I) {
4891 if (!this->emitConstUint32(I, E))
4893 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4895 if (!this->visitZeroRecordInitializer(R, E))
4897 if (!this->emitPopPtr(E))
4903 for (
size_t I = 0; I != NumElems; ++I) {
4904 if (!this->emitConstUint32(I, E))
4906 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4908 if (!this->visitZeroArrayInitializer(ElemType, E))
4910 if (!this->emitPopPtr(E))
4919template <
class Emitter>
4920bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4922 if (!canClassify(E->
getType()))
4925 if (!this->visit(RHS))
4927 if (!this->visit(LHS))
4934 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4938 bool Activates = refersToUnion(LHS);
4941 if (!this->emitFlip(
PT_Ptr, RHT, E))
4944 if (DiscardResult) {
4945 if (BitField && Activates)
4946 return this->emitStoreBitFieldActivatePop(RHT, E);
4948 return this->emitStoreBitFieldPop(RHT, E);
4950 return this->emitStoreActivatePop(RHT, E);
4952 return this->emitStorePop(RHT, E);
4955 auto maybeLoad = [&](
bool Result) ->
bool {
4961 return this->emitLoadPop(RHT, E);
4965 if (BitField && Activates)
4966 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4968 return maybeLoad(this->emitStoreBitField(RHT, E));
4970 return maybeLoad(this->emitStoreActivate(RHT, E));
4972 return maybeLoad(this->emitStore(RHT, E));
4975template <
class Emitter>
4976template <
typename T>
4980 return this->emitConstSint8(
Value, E);
4982 return this->emitConstUint8(
Value, E);
4984 return this->emitConstSint16(
Value, E);
4986 return this->emitConstUint16(
Value, E);
4988 return this->emitConstSint32(
Value, E);
4990 return this->emitConstUint32(
Value, E);
4992 return this->emitConstSint64(
Value, E);
4994 return this->emitConstUint64(
Value, E);
4996 return this->emitConstBool(
Value, E);
5003 llvm_unreachable(
"Invalid integral type");
5006 llvm_unreachable(
"unknown primitive type");
5009template <
class Emitter>
5010template <
typename T>
5011bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
5012 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5015template <
class Emitter>
5019 return this->emitConstIntAPS(
Value, E);
5021 return this->emitConstIntAP(
Value, E);
5023 if (
Value.isSigned())
5024 return this->emitConst(
Value.getSExtValue(), Ty, E);
5025 return this->emitConst(
Value.getZExtValue(), Ty, E);
5028template <
class Emitter>
5032 return this->emitConstIntAPS(
Value, E);
5034 return this->emitConstIntAP(
Value, E);
5037 return this->emitConst(
Value.getSExtValue(), Ty, E);
5038 return this->emitConst(
Value.getZExtValue(), Ty, E);
5041template <
class Emitter>
5042bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5043 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5046template <
class Emitter>
5059 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5060 Locals.insert({VD, Local});
5061 VarScope->addForScopeKind(Local, SC);
5062 return Local.Offset;
5065template <
class Emitter>
5070 bool IsTemporary =
false;
5071 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5074 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5075 Init = VarD->getInit();
5077 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5088 return std::nullopt;
5093 Locals.insert({Key, Local});
5094 VarScope->addForScopeKind(Local, SC);
5095 return Local.Offset;
5098template <
class Emitter>
5108 return std::nullopt;
5118 return Local.Offset;
5121template <
class Emitter>
5123 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5124 return PT->getPointeeType()->getAsCanonical<RecordType>();
5130 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5134template <
class Emitter>
5136 return P.getOrCreateRecord(RD);
5139template <
class Emitter>
5141 return Ctx.getOrCreateFunction(FD);
5144template <
class Emitter>
5148 auto maybeDestroyLocals = [&]() ->
bool {
5149 if (DestroyToplevelScope)
5150 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5151 return this->emitCheckAllocations(E);
5158 return this->emitRetVoid(E) && maybeDestroyLocals();
5166 return this->emitRet(*T, E) && maybeDestroyLocals();
5174 if (!this->emitGetPtrLocal(*LocalOffset, E))
5182 return this->emitRetValue(E) && maybeDestroyLocals();
5185 return maybeDestroyLocals() &&
false;
5188template <
class Emitter>
5190 bool DestroyToplevelScope) {
5194 return this->
visitExpr(E, DestroyToplevelScope);
5197template <
class Emitter>
5209 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5210 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5224template <
class Emitter>
5226 bool ConstantContext) {
5229 if (!ConstantContext) {
5243 auto GlobalIndex =
P.getGlobal(VD);
5244 assert(GlobalIndex);
5246 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5249 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5253 auto Local =
Locals.find(VD);
5254 assert(Local !=
Locals.end());
5256 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5259 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5269 auto GlobalIndex =
P.getGlobal(VD);
5270 assert(GlobalIndex);
5271 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5280 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5283template <
class Emitter>
5294 if (!this->isActive())
5299 if (
Init &&
Init->isValueDependent())
5303 auto checkDecl = [&]() ->
bool {
5305 return !NeedsOp || this->emitCheckDecl(VD, VD);
5312 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5315 if (
P.isGlobalInitialized(*GlobalIndex))
5319 }
else if ((GlobalIndex =
5334 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5337 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5340 if (!this->emitStartInit(
Init))
5346 if (!this->emitEndInit(
Init))
5349 return this->emitFinishInitGlobal(
Init);
5359 if (!
Init ||
Init->getType()->isVoidType())
5368 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5380 if (!this->emitCheckRefInit(
Init))
5384 return this->emitSetLocal(*VarT, Offset, VD);
5392 if (!this->emitGetPtrLocal(*Offset,
Init))
5400template <
class Emitter>
5420 Locals.insert({VD, Local});
5423 if (!this->emitGetPtrLocal(Local.Offset, VD))
5427 return this->emitDestructionPop(D, VD);
5430template <
class Emitter>
5435 return this->emitConst(Val.
getInt(), ValType, E);
5438 return this->emitFloat(F, E);
5443 if (!this->emitGetMemberPtr(MemberDecl, E))
5449 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, E))
5455 return this->emitNullMemberPtr(0,
nullptr, E);
5460 return this->emitNull(ValType, 0,
nullptr, E);
5465 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5466 return this->
visit(BaseExpr);
5471 QualType EntryType = VD->getType();
5472 for (
auto &Entry : Path) {
5474 uint64_t Index = Entry.getAsArrayIndex();
5477 if (!this->emitConst(Index,
PT_Uint64, E))
5479 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5481 EntryType = ElemType;
5491 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5492 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5494 if (!this->emitGetPtrFieldPop(EntryOffset, E))
5496 EntryType = FD->getType();
5500 if (!this->emitGetPtrBasePop(BaseOffset,
false, E))
5502 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5514template <
class Emitter>
5522 const Record::Field *RF = R->getField(I);
5523 QualType FieldType = RF->Decl->getType();
5529 if (!this->emitInitField(*PT, RF->Offset, E))
5532 if (!this->emitGetPtrField(RF->Offset, E))
5536 if (!this->emitFinishInitPop(E))
5544 const Record::Base *RB = R->getBase(I);
5545 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5547 if (!this->emitGetPtrBase(RB->Offset, E))
5551 if (!this->emitFinishInitPop(E))
5564 const Record::Field *RF = R->getField(UnionField);
5565 QualType FieldType = RF->Decl->getType();
5570 if (RF->isBitField())
5571 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5573 return this->emitInitFieldActivate(*PT, RF->Offset, E);
5576 if (!this->emitGetPtrField(RF->Offset, E))
5578 if (!this->emitActivate(E))
5582 return this->emitPopPtr(E);
5586 const auto *ArrType = T->getAsArrayTypeUnsafe();
5587 QualType ElemType = ArrType->getElementType();
5590 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5591 const APValue &Elem = A >= InitializedElems
5598 if (!this->emitInitElem(*ElemT, A, E))
5601 if (!this->emitConstUint32(A, E))
5603 if (!this->emitArrayElemPtrUint32(E))
5607 if (!this->emitPopPtr(E))
5618template <
class Emitter>
5620 unsigned BuiltinID) {
5621 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5626 return this->emitConst(0, E);
5629 if (!this->emitStartSpeculation(E))
5631 LabelTy EndLabel = this->getLabel();
5632 if (!this->speculate(E, EndLabel))
5634 if (!this->emitEndSpeculation(E))
5636 this->fallthrough(EndLabel);
5644 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5645 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5646 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5647 BuiltinID == Builtin::BI__builtin_function_start) {
5650 return this->emitDummyPtr(E, E);
5661 if (!this->emitGetPtrLocal(*LocalIndex, E))
5666 switch (BuiltinID) {
5667 case Builtin::BI__builtin_object_size:
5668 case Builtin::BI__builtin_dynamic_object_size: {
5672 if (!this->
visit(Arg0))
5683 case Builtin::BI__assume:
5684 case Builtin::BI__builtin_assume:
5687 case Builtin::BI__atomic_is_lock_free:
5688 case Builtin::BI__atomic_always_lock_free: {
5699 for (
const auto *Arg : E->
arguments()) {
5700 if (!this->
visit(Arg))
5706 if (!this->emitCallBI(E, BuiltinID, E))
5715template <
class Emitter>
5736 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5737 DD && DD->isTrivial()) {
5739 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5741 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5742 this->emitPopPtr(E);
5750 bool HasRVO = !
ReturnType->isVoidType() && !T;
5758 if (!this->emitGetPtrLocal(*LocalIndex, E))
5766 if (!this->emitGetPtrLocal(*LocalIndex, E))
5770 if (!this->emitDupPtr(E))
5777 bool IsAssignmentOperatorCall =
false;
5778 bool ActivateLHS =
false;
5779 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5780 OCE && OCE->isAssignmentOp()) {
5784 assert(Args.size() == 2);
5785 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
5787 IsAssignmentOperatorCall =
true;
5788 std::reverse(Args.begin(), Args.end());
5794 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5795 MD && MD->isStatic()) {
5799 Args.erase(Args.begin());
5803 bool Devirtualized =
false;
5806 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5814 if (!this->
visit(Callee))
5816 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5818 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5820 if (!this->emitGetMemberPtrBase(E))
5823 const auto *InstancePtr = MC->getImplicitObjectArgument();
5830 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5831 Devirtualized =
true;
5832 if (!this->
visit(Stripped))
5835 if (!this->
visit(InstancePtr))
5839 if (!this->
visit(InstancePtr))
5843 }
else if (
const auto *PD =
5844 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5845 if (!this->emitCheckPseudoDtor(E))
5853 return this->emitEndLifetimePop(E);
5854 }
else if (!FuncDecl) {
5858 if (!this->
visit(Callee))
5860 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5869 if (IsAssignmentOperatorCall) {
5870 assert(Args.size() == 2);
5873 if (!this->emitFlip(Arg2T, Arg1T, E))
5887 assert(HasRVO ==
Func->hasRVO());
5889 bool HasQualifier =
false;
5890 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5891 HasQualifier = ME->hasQualifier();
5893 bool IsVirtual =
false;
5894 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5895 IsVirtual = !Devirtualized && MD->isVirtual();
5900 if (IsVirtual && !HasQualifier) {
5901 uint32_t VarArgSize = 0;
5902 unsigned NumParams =
5903 Func->getNumWrittenParams() +
5905 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5908 if (!this->emitCallVirt(
Func, VarArgSize, E))
5910 }
else if (
Func->isVariadic()) {
5911 uint32_t VarArgSize = 0;
5912 unsigned NumParams =
5913 Func->getNumWrittenParams() +
5915 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5917 if (!this->emitCallVar(
Func, VarArgSize, E))
5920 if (!this->emitCall(
Func, 0, E))
5929 uint32_t ArgSize = 0;
5930 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5936 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5938 if (!this->emitGetMemberPtrDecl(E))
5941 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5944 if (!this->emitCallPtr(ArgSize, E, E))
5955template <
class Emitter>
5962template <
class Emitter>
5969template <
class Emitter>
5974 return this->emitConstBool(E->
getValue(), E);
5977template <
class Emitter>
5983 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5984 return this->emitNullPtr(Val,
nullptr, E);
5987template <
class Emitter>
5995 return this->emitZero(T, E);
5998template <
class Emitter>
6003 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6004 if (this->LambdaThisCapture.Offset > 0) {
6005 if (this->LambdaThisCapture.IsPtr)
6006 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6007 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6016 return this->emitThis(E);
6031 unsigned StartIndex = 0;
6032 unsigned EndIndex = 0;
6034 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6036 EndIndex = StartIndex;
6043 for (; StartIndex > 0; --StartIndex) {
6053 if (StartIndex == 0 && EndIndex == 0)
6056 assert(StartIndex < EndIndex);
6059 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6071 case Stmt::CompoundStmtClass:
6073 case Stmt::DeclStmtClass:
6075 case Stmt::ReturnStmtClass:
6077 case Stmt::IfStmtClass:
6079 case Stmt::WhileStmtClass:
6081 case Stmt::DoStmtClass:
6083 case Stmt::ForStmtClass:
6085 case Stmt::CXXForRangeStmtClass:
6087 case Stmt::BreakStmtClass:
6089 case Stmt::ContinueStmtClass:
6091 case Stmt::SwitchStmtClass:
6093 case Stmt::CaseStmtClass:
6095 case Stmt::DefaultStmtClass:
6097 case Stmt::AttributedStmtClass:
6099 case Stmt::CXXTryStmtClass:
6101 case Stmt::NullStmtClass:
6104 case Stmt::GCCAsmStmtClass:
6105 case Stmt::MSAsmStmtClass:
6106 case Stmt::GotoStmtClass:
6107 return this->emitInvalid(S);
6108 case Stmt::LabelStmtClass:
6111 if (
const auto *E = dyn_cast<Expr>(S))
6118template <
class Emitter>
6121 for (
const auto *InnerStmt : S->
body())
6124 return Scope.destroyLocals();
6127template <
class Emitter>
6128bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6129 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6130 for (
auto *BD : DD->flat_bindings())
6131 if (
auto *KD = BD->getHoldingVar();
6132 KD && !this->visitVarDecl(KD, KD->getInit()))
6146template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6148 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6149 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6156 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6161 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6162 ICE && (ICE->getCastKind() == CK_NoOp ||
6163 ICE->getCastKind() == CK_DerivedToBase ||
6164 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6165 E = ICE->getSubExpr();
6169 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6170 const auto *ThisRecord =
6171 This->getType()->getPointeeType()->getAsRecordDecl();
6172 if (!ThisRecord->isUnion())
6175 if (
const auto *Ctor =
6176 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6177 return Ctor->getParent() == ThisRecord;
6186template <
class Emitter>
6188 bool EvaluateConditionDecl) {
6189 for (
const auto *D : DS->
decls()) {
6194 const auto *VD = dyn_cast<VarDecl>(D);
6201 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6208template <
class Emitter>
6211 return this->emitUnsupported(RS);
6217 if (!this->
visit(RE))
6223 if (RE->getType()->isVoidType()) {
6224 if (!this->
visit(RE))
6227 if (RE->containsErrors())
6232 if (!this->emitRVOPtr(RE))
6238 return this->emitRetVoid(RS);
6244 return this->emitRetVoid(RS);
6250 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6257 if (
auto *CondInit = IS->
getInit()) {
6273 return visitChildStmt(IS->
getThen());
6275 return visitChildStmt(Else);
6281 if (!this->emitIsConstantContext(IS))
6284 if (!this->emitIsConstantContext(IS))
6286 if (!this->emitInv(IS))
6300 LabelTy LabelElse = this->getLabel();
6301 LabelTy LabelEnd = this->getLabel();
6302 if (!this->jumpFalse(LabelElse, IS))
6304 if (!visitChildStmt(IS->
getThen()))
6306 if (!this->jump(LabelEnd, IS))
6308 this->emitLabel(LabelElse);
6309 if (!visitChildStmt(Else))
6311 this->emitLabel(LabelEnd);
6313 LabelTy LabelEnd = this->getLabel();
6314 if (!this->jumpFalse(LabelEnd, IS))
6316 if (!visitChildStmt(IS->
getThen()))
6318 this->emitLabel(LabelEnd);
6327template <
class Emitter>
6332 LabelTy CondLabel = this->getLabel();
6333 LabelTy EndLabel = this->getLabel();
6337 this->fallthrough(CondLabel);
6338 this->emitLabel(CondLabel);
6354 if (!this->jumpFalse(EndLabel, S))
6364 if (!this->jump(CondLabel, S))
6366 this->fallthrough(EndLabel);
6367 this->emitLabel(EndLabel);
6376 LabelTy StartLabel = this->getLabel();
6377 LabelTy EndLabel = this->getLabel();
6378 LabelTy CondLabel = this->getLabel();
6382 this->fallthrough(StartLabel);
6383 this->emitLabel(StartLabel);
6389 this->fallthrough(CondLabel);
6390 this->emitLabel(CondLabel);
6397 if (!this->jumpTrue(StartLabel, S))
6400 this->fallthrough(EndLabel);
6401 this->emitLabel(EndLabel);
6405template <
class Emitter>
6413 LabelTy EndLabel = this->getLabel();
6414 LabelTy CondLabel = this->getLabel();
6415 LabelTy IncLabel = this->getLabel();
6422 this->fallthrough(CondLabel);
6423 this->emitLabel(CondLabel);
6435 if (!this->jumpFalse(EndLabel, S))
6444 this->fallthrough(IncLabel);
6445 this->emitLabel(IncLabel);
6451 if (!this->jump(CondLabel, S))
6455 this->emitLabel(EndLabel);
6461template <
class Emitter>
6471 LabelTy EndLabel = this->getLabel();
6472 LabelTy CondLabel = this->getLabel();
6473 LabelTy IncLabel = this->getLabel();
6488 this->fallthrough(CondLabel);
6489 this->emitLabel(CondLabel);
6492 if (!this->jumpFalse(EndLabel, S))
6503 this->fallthrough(IncLabel);
6504 this->emitLabel(IncLabel);
6509 if (!this->jump(CondLabel, S))
6512 this->fallthrough(EndLabel);
6513 this->emitLabel(EndLabel);
6517template <
class Emitter>
6528 if (LI.BreakLabel) {
6529 TargetLabel = *LI.BreakLabel;
6530 BreakScope = LI.BreakOrContinueScope;
6536 if (LI.Name == TargetLoop) {
6537 TargetLabel = *LI.BreakLabel;
6538 BreakScope = LI.BreakOrContinueScope;
6549 C =
C->getParent()) {
6550 if (!
C->destroyLocals())
6554 return this->jump(*TargetLabel, S);
6557template <
class Emitter>
6568 if (LI.ContinueLabel) {
6569 TargetLabel = *LI.ContinueLabel;
6570 ContinueScope = LI.BreakOrContinueScope;
6576 if (LI.Name == TargetLoop) {
6577 TargetLabel = *LI.ContinueLabel;
6578 ContinueScope = LI.BreakOrContinueScope;
6583 assert(TargetLabel);
6586 C =
C->getParent()) {
6587 if (!
C->destroyLocals())
6591 return this->jump(*TargetLabel, S);
6594template <
class Emitter>
6597 if (
Cond->containsErrors())
6603 LabelTy EndLabel = this->getLabel();
6608 if (
const auto *CondInit = S->
getInit())
6619 if (!this->emitSetLocal(CondT, CondVar, S))
6629 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6632 if (CS->caseStmtIsGNURange()) {
6633 LabelTy EndOfRangeCheck = this->getLabel();
6634 const Expr *Low = CS->getLHS();
6635 const Expr *High = CS->getRHS();
6639 if (!this->emitGetLocal(CondT, CondVar, CS))
6641 if (!this->
visit(Low))
6644 if (!this->emitGE(
LT, S))
6646 if (!this->jumpFalse(EndOfRangeCheck, S))
6649 if (!this->emitGetLocal(CondT, CondVar, CS))
6651 if (!this->
visit(High))
6654 if (!this->emitLE(HT, S))
6658 this->emitLabel(EndOfRangeCheck);
6663 if (
Value->isValueDependent())
6668 if (!this->emitGetLocal(CondT, CondVar, CS))
6674 if (!this->emitEQ(ValueT, S))
6679 assert(!DefaultLabel);
6680 DefaultLabel = this->getLabel();
6687 if (!this->jump(*DefaultLabel, S))
6690 if (!this->jump(EndLabel, S))
6698 this->fallthrough(EndLabel);
6699 this->emitLabel(EndLabel);
6704template <
class Emitter>
6711template <
class Emitter>
6718 if (LI.DefaultLabel) {
6719 DefaultLabel = *LI.DefaultLabel;
6724 this->emitLabel(DefaultLabel);
6728template <
class Emitter>
6735 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6738 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6739 !this->Ctx.getLangOpts().MSVCCompat) {
6741 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6747 const Expr *Assumption = AA->getAssumption();
6758 if (!this->emitAssume(Assumption))
6767 if (IsMSVCConstexprAttr)
6768 return this->emitPopMSVCCE(S);
6772template <
class Emitter>
6778template <
class Emitter>
6779bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6786 assert(ClosureClass->
captures().empty());
6790 "A generic lambda's static-invoker function must be a "
6791 "template specialization");
6795 void *InsertPos =
nullptr;
6796 const FunctionDecl *CorrespondingCallOpSpecialization =
6798 assert(CorrespondingCallOpSpecialization);
6799 LambdaCallOp = CorrespondingCallOpSpecialization;
6803 assert(ClosureClass->
captures().empty());
6804 const Function *
Func = this->getFunction(LambdaCallOp);
6807 assert(
Func->hasThisPointer());
6810 if (
Func->hasRVO()) {
6811 if (!this->emitRVOPtr(MD))
6819 if (!this->emitNullPtr(0,
nullptr, MD))
6824 auto It = this->Params.find(PVD);
6825 assert(It != this->Params.end());
6829 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6830 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6834 if (!this->emitCall(
Func, 0, LambdaCallOp))
6839 return this->emitRet(*ReturnType, MD);
6842 return this->emitRetVoid(MD);
6845template <
class Emitter>
6846bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6847 if (Ctx.getLangOpts().CPlusPlus23)
6857 const Expr *InitExpr =
Init->getInit();
6859 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6863 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6873template <
class Emitter>
6875 assert(!ReturnType);
6878 if (!this->emitStartThisLifetime1(Ctor))
6881 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6882 const Expr *InitExpr,
6885 if (InitExpr->getType().isNull())
6889 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6892 if (!this->visit(InitExpr))
6895 if (F->isBitField())
6896 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
6898 return this->emitInitThisField(*T, FieldOffset, InitExpr);
6903 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6906 if (
Activate && !this->emitActivate(InitExpr))
6909 return this->visitInitializerPop(InitExpr);
6913 const Record *
R = this->getRecord(RD);
6916 bool IsUnion =
R->isUnion();
6926 if (!this->emitThis(Ctor))
6929 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
6932 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6933 this->emitRetVoid(Ctor);
6936 unsigned FieldInits = 0;
6938 for (
const auto *
Init : Ctor->
inits()) {
6942 const Expr *InitExpr =
Init->getInit();
6944 const Record::Field *F =
R->getField(
Member);
6948 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6952 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6955 if (
Init->isBaseVirtual()) {
6956 assert(
R->getVirtualBase(BaseDecl));
6957 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6963 const Record::Base *B =
R->getBase(BaseDecl);
6965 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6969 if (IsUnion && !this->emitActivate(InitExpr))
6972 if (!this->visitInitializerPop(InitExpr))
6977 unsigned ChainSize = IFD->getChainingSize();
6978 assert(ChainSize >= 2);
6980 unsigned NestedFieldOffset = 0;
6981 const Record::Field *NestedField =
nullptr;
6982 for (
unsigned I = 0; I != ChainSize; ++I) {
6984 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6985 assert(FieldRecord);
6987 NestedField = FieldRecord->
getField(FD);
6988 assert(NestedField);
6989 IsUnion = IsUnion || FieldRecord->
isUnion();
6991 NestedFieldOffset += NestedField->Offset;
6994 if (I != ChainSize - 1)
6997 assert(NestedField);
7000 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7005 unsigned InitFieldOffset = 0;
7006 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7008 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7009 assert(FieldRecord);
7010 NestedField = FieldRecord->
getField(FD);
7011 InitFieldOffset += NestedField->Offset;
7012 assert(NestedField);
7013 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7015 if (!this->emitFinishInitPop(InitExpr))
7019 InitStack.pop_back_n(ChainSize - 1);
7022 assert(
Init->isDelegatingInitializer());
7023 if (!this->emitThis(InitExpr))
7025 if (!this->visitInitializerPop(
Init->getInit()))
7029 if (!
Scope.destroyLocals())
7033 if (FieldInits !=
R->getNumFields()) {
7034 assert(FieldInits < R->getNumFields());
7036 if (!this->emitStartThisLifetime(Ctor))
7043 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7044 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7051 if (!visitStmt(Body))
7058template <
class Emitter>
7061 const Record *
R = this->getRecord(RD);
7066 if (!this->visitStmt(Dtor->
getBody()))
7070 if (!this->emitThis(Dtor))
7073 if (!this->emitCheckDestruction(Dtor))
7077 if (!
R->isUnion()) {
7081 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7085 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7087 if (!this->emitDestructionPop(D,
SourceInfo{}))
7092 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7093 if (
Base.R->hasTrivialDtor())
7097 if (!this->emitRecordDestructionPop(
Base.R, {}))
7101 if (!this->emitMarkDestroyed(Dtor))
7105 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
7108template <
class Emitter>
7109bool Compiler<Emitter>::compileUnionAssignmentOperator(
7111 if (!this->emitThis(MD))
7114 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7117 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7120template <
class Emitter>
7130 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7131 return this->compileConstructor(Ctor);
7132 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
7133 return this->compileDestructor(Dtor);
7136 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7141 return this->compileUnionAssignmentOperator(MD);
7144 return this->emitLambdaStaticInvokerBody(MD);
7148 if (
const auto *Body = F->
getBody())
7162 return FD->getBitWidthValue();
7165template <
class Emitter>
7181 if (!
Ctx.getLangOpts().CPlusPlus14)
7182 return this->emitInvalid(E);
7184 return this->emitError(E);
7186 if (!this->
visit(SubExpr))
7190 if (!this->emitIncPtr(E))
7197 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7198 : this->emitIncf(getFPOptions(E), E);
7210 if (!
Ctx.getLangOpts().CPlusPlus14)
7211 return this->emitInvalid(E);
7213 return this->emitError(E);
7215 if (!this->
visit(SubExpr))
7219 if (!this->emitDecPtr(E))
7226 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7227 : this->emitDecf(getFPOptions(E), E);
7240 if (!
Ctx.getLangOpts().CPlusPlus14)
7241 return this->emitInvalid(E);
7243 return this->emitError(E);
7245 if (!this->
visit(SubExpr))
7249 if (!this->emitLoadPtr(E))
7251 if (!this->emitConstUint8(1, E))
7253 if (!this->emitAddOffsetUint8(E))
7255 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7261 return this->emitIncfPop(getFPOptions(E), E);
7271 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7272 if (!this->emitLoadFloat(E))
7274 APFloat F(TargetSemantics, 1);
7275 if (!this->emitFloat(F, E))
7278 if (!this->emitAddf(getFPOptions(E), E))
7280 if (!this->emitStoreFloat(E))
7292 return E->
isGLValue() || this->emitLoadPop(*T, E);
7295 if (!
Ctx.getLangOpts().CPlusPlus14)
7296 return this->emitInvalid(E);
7298 return this->emitError(E);
7300 if (!this->
visit(SubExpr))
7304 if (!this->emitLoadPtr(E))
7306 if (!this->emitConstUint8(1, E))
7308 if (!this->emitSubOffsetUint8(E))
7310 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7316 return this->emitDecfPop(getFPOptions(E), E);
7326 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7327 if (!this->emitLoadFloat(E))
7329 APFloat F(TargetSemantics, 1);
7330 if (!this->emitFloat(F, E))
7333 if (!this->emitSubf(getFPOptions(E), E))
7335 if (!this->emitStoreFloat(E))
7347 return E->
isGLValue() || this->emitLoadPop(*T, E);
7351 return this->emitError(E);
7354 return this->
discard(SubExpr);
7359 if (!this->emitInv(E))
7363 return this->emitCast(
PT_Bool, ET, E);
7367 return this->emitError(E);
7369 if (!this->
visit(SubExpr))
7371 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7374 return this->emitError(E);
7376 if (!this->
visit(SubExpr))
7392 if (!
Ctx.getLangOpts().CPlusPlus) {
7394 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7395 Deref && Deref->getOpcode() == UO_Deref)
7396 return this->
delegate(Deref->getSubExpr());
7402 return this->
discard(SubExpr);
7404 if (!this->
visit(SubExpr))
7411 return this->emitNarrowPtr(E);
7416 return this->emitError(E);
7418 if (!this->
visit(SubExpr))
7420 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7432 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7437 assert(
false &&
"Unhandled opcode");
7443template <
class Emitter>
7449 return this->
discard(SubExpr);
7452 auto prepareResult = [=]() ->
bool {
7457 return this->emitGetPtrLocal(*LocalIndex, E);
7464 unsigned SubExprOffset = ~0u;
7465 auto createTemp = [=, &SubExprOffset]() ->
bool {
7468 if (!this->
visit(SubExpr))
7470 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7474 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7475 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7477 return this->emitArrayElemPop(ElemT, Index, E);
7482 if (!prepareResult())
7486 for (
unsigned I = 0; I != 2; ++I) {
7487 if (!getElem(SubExprOffset, I))
7489 if (!this->emitNeg(ElemT, E))
7491 if (!this->emitInitElem(ElemT, I, E))
7502 if (!this->
visit(SubExpr))
7504 if (!this->emitComplexBoolCast(SubExpr))
7506 if (!this->emitInv(E))
7509 return this->emitCast(
PT_Bool, ET, E);
7513 return this->emitComplexReal(SubExpr);
7516 if (!this->
visit(SubExpr))
7520 if (!this->emitConstUint8(1, E))
7522 return this->emitArrayElemPtrPopUint8(E);
7533 if (!this->emitArrayElem(ElemT, 1, E))
7535 if (!this->emitNeg(ElemT, E))
7537 if (!this->emitInitElem(ElemT, 1, E))
7545 return this->emitInvalid(E);
7551template <
class Emitter>
7557 return this->
discard(SubExpr);
7560 if (UnaryOp == UO_Extension)
7563 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7564 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7565 return this->emitInvalid(E);
7568 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7575 if (!this->emitGetPtrLocal(*LocalIndex, E))
7580 unsigned SubExprOffset =
7582 if (!this->
visit(SubExpr))
7584 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7589 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7590 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7592 return this->emitArrayElemPop(ElemT, Index, E);
7597 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7598 if (!getElem(SubExprOffset, I))
7600 if (!this->emitNeg(ElemT, E))
7602 if (!this->emitInitElem(ElemT, I, E))
7617 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7618 if (!getElem(SubExprOffset, I))
7621 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7623 if (!this->emitInv(E))
7625 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7627 if (!this->emitNeg(ElemT, E))
7629 if (ElemT != ResultVecElemT &&
7630 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7632 if (!this->emitInitElem(ResultVecElemT, I, E))
7638 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7639 if (!getElem(SubExprOffset, I))
7642 if (!this->emitInv(E))
7645 if (!this->emitComp(ElemT, E))
7648 if (!this->emitInitElem(ElemT, I, E))
7653 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7658template <
class Emitter>
7663 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7664 return this->emitConst(ECD->getInitVal(), E);
7665 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7667 return F && this->emitGetFnPtr(F, E);
7669 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7674 return this->emitInitGlobal(*T, *Index, E);
7677 if (!this->emitGetPtrGlobal(*Index, E))
7681 return this->emitFinishInit(E);
7696 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7697 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7702 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7703 if (IsReference || !It->second.IsPtr)
7704 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7706 return this->emitGetPtrParam(It->second.Index, E);
7709 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7715 const unsigned Offset = It->second.Offset;
7718 return this->emitGetRefLocal(Offset, E);
7720 return this->emitGetPtrLocal(Offset, E);
7723 if (
auto GlobalIndex =
P.getGlobal(D)) {
7725 if (!
Ctx.getLangOpts().CPlusPlus11)
7726 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7727 if (!
Ctx.getLangOpts().CPlusPlus23)
7728 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7729 return this->emitGetRefGlobal(*GlobalIndex, E);
7732 return this->emitGetPtrGlobal(*GlobalIndex, E);
7736 auto revisit = [&](
const VarDecl *VD,
7737 bool IsConstexprUnknown =
true) ->
bool {
7739 IsConstexprUnknown);
7744 if (!this->emitPopCC(E))
7747 if (VarState.notCreated())
7755 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7757 if (
auto It = this->LambdaCaptures.find(D);
7758 It != this->LambdaCaptures.end()) {
7759 auto [Offset, IsPtr] = It->second;
7762 return this->emitGetThisFieldPtr(Offset, E);
7763 return this->emitGetPtrThisField(Offset, E);
7767 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7768 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7769 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7773 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7774 return this->
visit(BD->getBinding());
7778 return this->emitDummyPtr(D, E);
7782 const auto *VD = dyn_cast<VarDecl>(D);
7784 return this->emitError(E);
7787 if (!
Ctx.getLangOpts().CPlusPlus) {
7791 return revisit(VD,
false);
7792 return this->emitDummyPtr(D, E);
7796 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7797 if (T.isConstant(
Ctx.getASTContext()))
7799 return T->isReferenceType();
7803 typeShouldBeVisited(DeclType)) {
7805 Init && !
Init->isValueDependent()) {
7811 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7825 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7830 return revisit(VD, IsConstexprUnknown);
7831 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7832 return revisit(VD,
true);
7839 return this->emitDummyPtr(
7843template <
class Emitter>
7849template <
class Emitter>
7859 if (!
C->destroyLocals())
7865template <
class Emitter>
7866unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7869 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7871 return Ty->getAsCXXRecordDecl();
7873 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7874 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7876 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7880template <
class Emitter>
7887 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7892 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7893 getFPOptions(E), E);
7895 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7896 getFPOptions(E), E);
7900 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7905 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7907 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7911 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7915 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7916 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7923template <
class Emitter>
7926 assert(FromT != ToT);
7929 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7931 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7933 return this->emitCast(FromT, ToT, E);
7937template <
class Emitter>
7938bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7942 return this->
discard(SubExpr);
7944 if (!this->visit(SubExpr))
7947 if (!this->emitConstUint8(0, SubExpr))
7949 return this->emitArrayElemPtrPopUint8(SubExpr);
7953 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7957template <
class Emitter>
7958bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7959 assert(!DiscardResult);
7963 if (!this->emitArrayElem(ElemT, 0, E))
7966 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7969 if (!this->emitCast(ElemT,
PT_Bool, E))
7974 LabelTy LabelTrue = this->getLabel();
7975 if (!this->jumpTrue(LabelTrue, E))
7978 if (!this->emitArrayElemPop(ElemT, 1, E))
7981 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7984 if (!this->emitCast(ElemT,
PT_Bool, E))
7988 LabelTy EndLabel = this->getLabel();
7989 this->jump(EndLabel, E);
7991 this->emitLabel(LabelTrue);
7992 if (!this->emitPopPtr(E))
7994 if (!this->emitConstBool(
true, E))
7997 this->fallthrough(EndLabel);
7998 this->emitLabel(EndLabel);
8003template <
class Emitter>
8004bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8015 LHSIsComplex =
true;
8016 ElemT = classifyComplexElementType(LHS->
getType());
8017 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8018 if (!this->visit(LHS))
8020 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8023 LHSIsComplex =
false;
8025 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8026 if (!this->visit(LHS))
8028 if (!this->emitSetLocal(LHST, LHSOffset, E))
8035 RHSIsComplex =
true;
8036 ElemT = classifyComplexElementType(RHS->
getType());
8037 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8038 if (!this->visit(RHS))
8040 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8043 RHSIsComplex =
false;
8045 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8046 if (!this->visit(RHS))
8048 if (!this->emitSetLocal(RHST, RHSOffset, E))
8052 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8053 bool IsComplex) ->
bool {
8055 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8057 return this->emitArrayElemPop(ElemT, Index, E);
8059 return this->emitGetLocal(ElemT, LocalOffset, E);
8062 for (
unsigned I = 0; I != 2; ++I) {
8064 if (!getElem(LHSOffset, I, LHSIsComplex))
8066 if (!getElem(RHSOffset, I, RHSIsComplex))
8069 if (!this->emitEQ(ElemT, E))
8072 if (!this->emitCastBoolUint8(E))
8077 if (!this->emitAddUint8(E))
8079 if (!this->emitConstUint8(2, E))
8083 if (!this->emitEQUint8(E))
8086 if (!this->emitNEUint8(E))
8093 return this->emitCast(
PT_Bool, ResT, E);
8100template <
class Emitter>
8101bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8104 assert(!
R->hasTrivialDtor());
8107 const Function *DtorFunc = getFunction(Dtor);
8110 assert(DtorFunc->hasThisPointer());
8111 assert(DtorFunc->getNumParams() == 1);
8112 return this->emitCall(DtorFunc, 0, Loc);
8117template <
class Emitter>
8118bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8130 return this->emitPopPtr(Loc);
8132 for (ssize_t I = N - 1; I >= 1; --I) {
8133 if (!this->emitConstUint64(I, Loc))
8135 if (!this->emitArrayElemPtrUint64(Loc))
8137 if (!this->emitDestructionPop(ElemDesc, Loc))
8141 if (!this->emitConstUint64(0, Loc))
8143 if (!this->emitArrayElemPtrPopUint64(Loc))
8145 return this->emitDestructionPop(ElemDesc, Loc);
8150 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8155template <
class Emitter>
8156bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E,
bool CU) {
8157 assert(!DiscardResult &&
"Should've been checked before");
8158 unsigned DummyID = P.getOrCreateDummy(D, CU);
8160 if (!this->emitGetPtrGlobal(DummyID, E))
8168 return this->emitDecayPtr(
PT_Ptr, PT, E);
8174template <
class Emitter>
8175bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
8177 return this->emitConstFloat(
Floating(F), E);
8179 APInt I = F.bitcastToAPInt();
8180 return this->emitConstFloat(
8181 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8182 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8193template <
class Emitter>
8194bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8207 if (!this->emitGetPtrLocal(*LocalIndex, E))
8217 if (!this->visit(SubExpr))
8219 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8220 unsigned TempOffset =
8221 allocateLocalPrimitive(SubExpr, *FromT,
true);
8222 if (!this->visit(SubExpr))
8224 if (!this->emitSetLocal(*FromT, TempOffset, E))
8226 if (!this->emitGetPtrLocal(TempOffset, E))
8233 if (!this->emitBitCast(E))
8235 return DiscardResult ? this->emitPopPtr(E) :
true;
8239 const llvm::fltSemantics *TargetSemantics =
nullptr;
8241 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8247 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8249 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8250 ResultBitWidth, TargetSemantics,
8255 return this->emitPop(*ToT, E);
8264template <
class Emitter>
8265bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8270 unsigned NumElems = 0;
8273 NumElems = VT->getNumElements();
8274 ElemType = VT->getElementType();
8276 NumElems = MT->getNumElementsFlattened();
8277 ElemType = MT->getElementType();
8280 PrimType ElemT = classifyPrim(ElemType);
8281 for (
unsigned I = 0; I != NumElems; ++I) {
8282 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8284 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8286 if (!this->emitInitElem(ElemT, I, E))
8296 QualType ArrElemType = CAT->getElementType();
8297 unsigned ArrSize = CAT->getZExtSize();
8300 for (
unsigned I = 0; I != ArrSize; ++I) {
8301 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8303 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8305 if (!this->emitInitElem(*ElemT, I, E))
8309 for (
unsigned I = 0; I != ArrSize; ++I) {
8310 if (!this->emitConstUint32(I, E))
8312 if (!this->emitArrayElemPtrUint32(E))
8314 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8316 if (!this->emitFinishInitPop(E))
8326 const Record *
R = getRecord(DestType);
8330 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8332 const Record::Base *B =
R->getBase(BS.getType());
8334 if (!this->emitGetPtrBase(B->Offset, E))
8336 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8338 if (!this->emitFinishInitPop(E))
8343 for (
const Record::Field &F :
R->fields()) {
8344 if (F.isUnnamedBitField())
8347 QualType FieldType = F.Decl->getType();
8349 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8351 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8353 if (F.isBitField()) {
8354 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8357 if (!this->emitInitField(*FieldT, F.Offset, E))
8361 if (!this->emitGetPtrField(F.Offset, E))
8363 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8365 if (!this->emitPopPtr(E))
8378template <
class Emitter>
8379unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8382 return VT->getNumElements();
8384 return MT->getNumElementsFlattened();
8388 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8392 const Record *
R = getRecord(Ty);
8396 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8398 Count += countHLSLFlatElements(BS.getType());
8400 for (
const Record::Field &F :
R->fields()) {
8401 if (F.isUnnamedBitField())
8403 Count += countHLSLFlatElements(F.Decl->getType());
8408 if (canClassify(Ty))
8417template <
class Emitter>
8418bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8419 QualType SrcType,
unsigned SrcOffset,
8424 auto saveToLocal = [&](
PrimType T) ->
bool {
8425 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8426 if (!this->emitSetLocal(T, Offset, E))
8428 Elements.push_back({Offset, T});
8434 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8435 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8436 return std::nullopt;
8441 unsigned NumElems = 0;
8444 NumElems = VT->getNumElements();
8445 ElemType = VT->getElementType();
8447 NumElems = MT->getNumElementsFlattened();
8448 ElemType = MT->getElementType();
8451 PrimType ElemT = classifyPrim(ElemType);
8452 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8453 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8455 if (!this->emitArrayElemPop(ElemT, I, E))
8457 if (!saveToLocal(ElemT))
8467 QualType ArrElemType = CAT->getElementType();
8468 unsigned ArrSize = CAT->getZExtSize();
8471 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8472 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8474 if (!this->emitArrayElemPop(*ElemT, I, E))
8476 if (!saveToLocal(*ElemT))
8480 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8481 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8483 if (!this->emitConstUint32(I, E))
8485 if (!this->emitArrayElemPtrPopUint32(E))
8490 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8501 const Record *
R = getRecord(SrcType);
8505 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8507 if (Elements.size() >= MaxElements)
8509 const Record::Base *B =
R->getBase(BS.getType());
8511 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8513 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8518 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8524 for (
const Record::Field &F :
R->fields()) {
8525 if (Elements.size() >= MaxElements)
8527 if (F.isUnnamedBitField())
8530 QualType FieldType = F.Decl->getType();
8531 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8533 if (!this->emitGetPtrFieldPop(F.Offset, E))
8537 if (!this->emitLoadPop(*FieldT, E))
8539 if (!saveToLocal(*FieldT))
8543 if (!FieldPtrOffset)
8545 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8561template <
class Emitter>
8562bool Compiler<Emitter>::emitHLSLConstructAggregate(
8568 const auto &Src = Elements[ElemIdx++];
8569 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8571 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8575 unsigned NumElems = 0;
8578 NumElems = VT->getNumElements();
8579 ElemType = VT->getElementType();
8581 NumElems = MT->getNumElementsFlattened();
8582 ElemType = MT->getElementType();
8585 PrimType DestElemT = classifyPrim(ElemType);
8586 for (
unsigned I = 0; I != NumElems; ++I) {
8587 if (!loadAndCast(DestElemT, ElemType))
8589 if (!this->emitInitElem(DestElemT, I, E))
8599 QualType ArrElemType = CAT->getElementType();
8600 unsigned ArrSize = CAT->getZExtSize();
8603 for (
unsigned I = 0; I != ArrSize; ++I) {
8604 if (!loadAndCast(*ElemT, ArrElemType))
8606 if (!this->emitInitElem(*ElemT, I, E))
8610 for (
unsigned I = 0; I != ArrSize; ++I) {
8611 if (!this->emitConstUint32(I, E))
8613 if (!this->emitArrayElemPtrUint32(E))
8615 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8617 if (!this->emitFinishInitPop(E))
8627 const Record *
R = getRecord(DestType);
8631 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8633 const Record::Base *B =
R->getBase(BS.getType());
8635 if (!this->emitGetPtrBase(B->Offset, E))
8637 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
8639 if (!this->emitFinishInitPop(E))
8644 for (
const Record::Field &F :
R->fields()) {
8645 if (F.isUnnamedBitField())
8648 QualType FieldType = F.Decl->getType();
8650 if (!loadAndCast(*FieldT, FieldType))
8652 if (F.isBitField()) {
8653 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8656 if (!this->emitInitField(*FieldT, F.Offset, E))
8660 if (!this->emitGetPtrField(F.Offset, E))
8662 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
8664 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 getArrayInitializedElts() const
unsigned getStructNumBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
APValue & getArrayFiller()
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.
bool isCompatibleWith(ClangABI Version) const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
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 isConstexpr() const
Whether this variable is (C++11) constexpr.
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.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
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
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
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()