19#include "llvm/Support/SaveAndRestore.h"
30 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
31 CE && CE->hasAPValueResult() &&
33 return CE->getResultAsAPSInt().getBoolValue();
44 OldInitializingDecl(
Ctx->InitializingDecl) {
45 Ctx->InitializingDecl = VD;
50 this->
Ctx->InitializingDecl = OldInitializingDecl;
51 this->
Ctx->InitStack.pop_back();
64 bool NewInitializing,
bool NewToLValue)
65 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
66 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
67 Ctx->DiscardResult = NewDiscardResult;
68 Ctx->Initializing = NewInitializing;
69 Ctx->ToLValue = NewToLValue;
73 Ctx->DiscardResult = OldDiscardResult;
74 Ctx->Initializing = OldInitializing;
75 Ctx->ToLValue = OldToLValue;
82 bool OldDiscardResult;
87template <
class Emitter>
91 return Ctx->emitThis(E);
94 return Ctx->emitGetPtrFieldPop(
Offset, E);
96 return Ctx->emitGetPtrLocal(
Offset, E);
100 if (!Ctx->emitConstUint32(
Offset, E))
102 return Ctx->emitArrayElemPtrPopUint32(E);
104 return Ctx->emitRVOPtr(E);
108 llvm_unreachable(
"Unhandled InitLink kind");
124 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
125 assert(LI.Name != Name);
128 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
149 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
151 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
152 assert(LI.Name != Name);
155 this->Ctx->CaseLabels = std::move(CaseLabels);
156 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
158 DefaultLabel, Ctx->VarScope);
162 this->Ctx->CaseLabels = std::move(OldCaseLabels);
163 this->Ctx->LabelInfoStack.pop_back();
168 CaseMap OldCaseLabels;
174 Ctx->InStmtExpr =
true;
192 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
195 Ctx->LocOverride = NewValue;
200 Ctx->LocOverride = OldFlag;
205 std::optional<SourceInfo> OldFlag;
212template <
class Emitter>
220 case CK_LValueToRValue: {
231 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
237 if (
auto GlobalIndex =
P.getGlobal(D))
238 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
239 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
240 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
241 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
242 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
243 return this->emitGetParam(*SubExprT, It->second.Index, E);
255 if (!this->emitGetPtrLocal(*LocalIndex, E))
259 if (!this->
visit(SubExpr))
263 return this->emitLoadPop(*SubExprT, E);
268 return this->emitMemcpy(E);
271 case CK_DerivedToBaseMemberPointer: {
282 ->getMostRecentCXXRecordDecl();
284 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
285 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
287 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
295 case CK_BaseToDerivedMemberPointer: {
306 ->getMostRecentCXXRecordDecl();
310 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
312 PathI != PathE; ++PathI) {
313 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
314 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
316 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
323 assert(ToDecl != CurDecl);
324 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
326 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
332 case CK_UncheckedDerivedToBase:
333 case CK_DerivedToBase: {
338 if (
const auto *PT = dyn_cast<PointerType>(Ty))
339 return PT->getPointeeType()->getAsCXXRecordDecl();
340 return Ty->getAsCXXRecordDecl();
347 if (B->isVirtual()) {
348 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
350 CurType = B->getType();
352 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
353 if (!this->emitGetPtrBasePop(
356 CurType = B->getType();
363 case CK_BaseToDerived: {
366 unsigned DerivedOffset =
372 return this->emitGetPtrDerivedPop(DerivedOffset,
377 case CK_FloatingCast: {
382 if (!this->
visit(SubExpr))
384 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
388 case CK_IntegralToFloating: {
391 if (!this->
visit(SubExpr))
393 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
394 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
395 TargetSemantics, getFPOptions(E), E);
398 case CK_FloatingToBoolean: {
402 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
403 return this->emitConstBool(FL->getValue().isNonZero(), E);
404 if (!this->
visit(SubExpr))
406 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
409 case CK_FloatingToIntegral: {
412 if (!this->
visit(SubExpr))
416 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
419 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
422 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
425 case CK_NullToPointer:
426 case CK_NullToMemberPointer: {
431 if (!PointeeType.
isNull()) {
433 Desc =
P.createDescriptor(SubExpr, *T);
435 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
439 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
443 case CK_PointerToIntegral: {
444 if (!this->
visit(SubExpr))
450 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
456 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
458 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
459 return this->emitCastPointerIntegral(T, E);
462 case CK_ArrayToPointerDecay: {
463 if (!this->
visit(SubExpr))
465 return this->emitArrayDecay(E);
468 case CK_IntegralToPointer: {
470 assert(IntType->isIntegralOrEnumerationType());
471 if (!this->
visit(SubExpr))
479 Desc =
P.createDescriptor(SubExpr, *T);
486 if (!this->emitGetIntPtr(T, Desc, E))
494 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
497 case CK_AtomicToNonAtomic:
498 case CK_ConstructorConversion:
499 case CK_FunctionToPointerDecay:
500 case CK_NonAtomicToAtomic:
502 case CK_UserDefinedConversion:
503 case CK_AddressSpaceConversion:
504 case CK_CPointerToObjCPointerCast:
521 return this->emitBuiltinBitCast(E);
536 if (!this->
visit(SubExpr))
544 return this->emitFnPtrCast(E);
551 if (!this->
visit(SubExpr))
553 return this->emitDecayPtr(*FromT, *ToT, E);
555 case CK_IntegralToBoolean:
556 case CK_FixedPointToBoolean: {
562 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
563 return this->emitConst(IL->getValue(), E);
564 if (!this->
visit(SubExpr))
569 case CK_BooleanToSignedIntegral:
570 case CK_IntegralCast: {
577 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
582 if (!this->emitConst(IL->getValue(), SubExpr))
585 if (!this->
visit(SubExpr))
593 if (!ED->isFixed()) {
594 if (!this->emitCheckEnumValue(*FromT, ED, E))
600 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
603 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
608 if (!this->emitCast(*FromT, *ToT, E))
611 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
612 return this->emitNeg(*ToT, E);
616 case CK_PointerToBoolean:
617 case CK_MemberPointerToBoolean: {
620 if (!this->
visit(SubExpr))
622 return this->emitIsNonNull(PtrT, E);
625 case CK_IntegralComplexToBoolean:
626 case CK_FloatingComplexToBoolean: {
627 if (!this->
visit(SubExpr))
629 return this->emitComplexBoolCast(SubExpr);
632 case CK_IntegralComplexToReal:
633 case CK_FloatingComplexToReal:
634 return this->emitComplexReal(SubExpr);
636 case CK_IntegralRealToComplex:
637 case CK_FloatingRealToComplex: {
644 if (!this->emitGetPtrLocal(*LocalIndex, E))
653 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
655 return this->emitInitElem(T, 1, SubExpr);
658 case CK_IntegralComplexCast:
659 case CK_FloatingComplexCast:
660 case CK_IntegralComplexToFloatingComplex:
661 case CK_FloatingComplexToIntegralComplex: {
668 if (!this->emitGetPtrLocal(*LocalIndex, E))
675 unsigned SubExprOffset =
677 if (!this->
visit(SubExpr))
679 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
687 for (
unsigned I = 0; I != 2; ++I) {
688 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
690 if (!this->emitArrayElemPop(SourceElemT, I, E))
694 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
698 if (!this->emitInitElem(DestElemT, I, E))
704 case CK_VectorSplat: {
715 if (!this->emitGetPtrLocal(*LocalIndex, E))
721 unsigned ElemOffset =
725 if (!this->
visit(SubExpr))
730 if (!this->emitSetLocal(ElemT, ElemOffset, E))
733 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
734 if (!this->emitGetLocal(ElemT, ElemOffset, E))
736 if (!this->emitInitElem(ElemT, I, E))
743 case CK_HLSLVectorTruncation: {
748 if (!this->
visit(SubExpr))
750 return this->emitArrayElemPop(*ResultT, 0, E);
759 if (!this->emitGetPtrLocal(*LocalIndex, E))
764 if (!this->
visit(SubExpr))
766 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
770 case CK_IntegralToFixedPoint: {
771 if (!this->
visit(SubExpr))
775 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
779 case CK_FloatingToFixedPoint: {
780 if (!this->
visit(SubExpr))
784 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
785 return this->emitCastFloatingFixedPoint(Sem, E);
787 case CK_FixedPointToFloating: {
788 if (!this->
visit(SubExpr))
790 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
791 return this->emitCastFixedPointFloating(TargetSemantics, E);
793 case CK_FixedPointToIntegral: {
794 if (!this->
visit(SubExpr))
798 case CK_FixedPointCast: {
799 if (!this->
visit(SubExpr))
802 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
803 return this->emitCastFixedPoint(Sem, E);
814 case CK_LValueBitCast:
817 case CK_HLSLArrayRValue: {
824 if (!this->emitGetPtrLocal(*LocalIndex, E))
827 if (!this->
visit(SubExpr))
829 return this->emitMemcpy(E);
832 case CK_HLSLMatrixTruncation: {
837 if (!this->
visit(SubExpr))
839 return this->emitArrayElemPop(*ResultT, 0, E);
848 if (!this->emitGetPtrLocal(*LocalIndex, E))
853 if (!this->
visit(SubExpr))
855 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
859 case CK_HLSLAggregateSplatCast: {
870 NumElems = VT->getNumElements();
871 DestElemType = VT->getElementType();
873 NumElems = MT->getNumElementsFlattened();
874 DestElemType = MT->getElementType();
884 if (!this->emitGetPtrLocal(*LocalIndex, E))
892 if (!this->
visit(SubExpr))
894 if (SrcElemT != DestElemT) {
895 if (!this->emitPrimCast(SrcElemT, DestElemT, DestElemType, E))
898 if (!this->emitSetLocal(DestElemT, SrcOffset, E))
901 for (
unsigned I = 0; I != NumElems; ++I) {
902 if (!this->emitGetLocal(DestElemT, SrcOffset, E))
904 if (!this->emitInitElem(DestElemT, I, E))
910 case CK_HLSLElementwiseCast: {
923 const auto *SrcCAT = SrcAT ? dyn_cast<ConstantArrayType>(SrcAT) :
nullptr;
929 const auto *DestCAT =
930 DestAT ? dyn_cast<ConstantArrayType>(DestAT) :
nullptr;
933 if (!SrcVT && !SrcMT && !SrcCAT)
935 if (!DestVT && !DestMT && !DestCAT && !DestPT)
938 unsigned SrcNumElems;
941 SrcNumElems = SrcVT->getNumElements();
944 SrcNumElems = SrcMT->getNumElementsFlattened();
947 SrcNumElems = SrcCAT->getZExtSize();
953 if (!this->
visit(SubExpr))
955 if (!this->emitArrayElemPop(SrcElemT, 0, E))
957 if (SrcElemT != *DestPT) {
958 if (!this->emitPrimCast(SrcElemT, *DestPT, DestType, E))
964 unsigned DestNumElems;
968 DestNumElems = DestVT->getNumElements();
969 DestElemType = DestVT->getElementType();
971 DestNumElems = DestMT->getNumElementsFlattened();
973 }
else if (DestCAT) {
974 DestNumElems = DestCAT->getZExtSize();
975 DestElemType = DestCAT->getElementType();
983 if (!this->emitGetPtrLocal(*LocalIndex, E))
989 if (!this->
visit(SubExpr))
991 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
994 unsigned NumElems = std::min(SrcNumElems, DestNumElems);
995 for (
unsigned I = 0; I != NumElems; ++I) {
996 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
998 if (!this->emitArrayElemPop(SrcElemT, I, E))
1000 if (SrcElemT != DestElemT) {
1001 if (!this->emitPrimCast(SrcElemT, DestElemT, DestElemType, E))
1004 if (!this->emitInitElem(DestElemT, I, E))
1011 return this->emitInvalid(E);
1013 llvm_unreachable(
"Unhandled clang::CastKind enum");
1016template <
class Emitter>
1018 return this->emitBuiltinBitCast(E);
1021template <
class Emitter>
1026 return this->emitConst(
LE->getValue(),
LE);
1029template <
class Emitter>
1035 return this->emitFloat(F, E);
1038template <
class Emitter>
1048 if (!this->emitGetPtrLocal(*LocalIndex, E))
1055 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1057 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1062template <
class Emitter>
1070 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1075template <
class Emitter>
1080template <
class Emitter>
1107 return this->emitComplexComparison(LHS, RHS, E);
1115 if (!this->
visit(LHS))
1118 if (!this->
visit(RHS))
1121 if (!this->emitToMemberPtr(E))
1127 if (!this->emitCastMemberPtrPtr(E))
1144 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1150 if (!this->emitGetPtrLocal(*ResultIndex, E))
1157 return this->emitCMP3(*
LT, CmpInfo, E);
1160 if (!
LT || !RT || !T)
1170 return this->visitAssignment(LHS, RHS, E);
1177 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1181 return this->emitPopBool(E);
1183 return this->emitCast(
PT_Bool, *T, E);
1187 auto Discard = [
this, T, E](
bool Result) {
1195 return MaybeCastToBool(this->emitEQ(*
LT, E));
1197 return MaybeCastToBool(this->emitNE(*
LT, E));
1199 return MaybeCastToBool(this->emitLT(*
LT, E));
1201 return MaybeCastToBool(this->emitLE(*
LT, E));
1203 return MaybeCastToBool(this->emitGT(*
LT, E));
1205 return MaybeCastToBool(this->emitGE(*
LT, E));
1208 return Discard(this->emitSubf(getFPOptions(E), E));
1209 return Discard(this->emitSub(*T, E));
1212 return Discard(this->emitAddf(getFPOptions(E), E));
1213 return Discard(this->emitAdd(*T, E));
1216 return Discard(this->emitMulf(getFPOptions(E), E));
1217 return Discard(this->emitMul(*T, E));
1219 return Discard(this->emitRem(*T, E));
1222 return Discard(this->emitDivf(getFPOptions(E), E));
1223 return Discard(this->emitDiv(*T, E));
1225 return Discard(this->emitBitAnd(*T, E));
1227 return Discard(this->emitBitOr(*T, E));
1229 return Discard(this->emitShl(*
LT, *RT, E));
1231 return Discard(this->emitShr(*
LT, *RT, E));
1233 return Discard(this->emitBitXor(*T, E));
1236 llvm_unreachable(
"Already handled earlier");
1241 llvm_unreachable(
"Unhandled binary op");
1246template <
class Emitter>
1252 if ((Op != BO_Add && Op != BO_Sub) ||
1263 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1264 if (!this->
visit(E))
1267 return this->emitDecayPtr(T,
PT_Ptr, E);
1276 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1284 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1287 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1294 if (!visitAsPointer(RHS, *RT))
1296 if (!this->
visit(LHS))
1300 if (!visitAsPointer(LHS, *
LT))
1302 if (!this->
visit(RHS))
1313 if (!this->emitAddOffset(OffsetType, E))
1317 if (!this->emitSubOffset(OffsetType, E))
1334template <
class Emitter>
1344 LabelTy LabelTrue = this->getLabel();
1345 LabelTy LabelEnd = this->getLabel();
1349 if (!this->jumpTrue(LabelTrue, E))
1354 if (!this->jump(LabelEnd, E))
1357 this->emitLabel(LabelTrue);
1358 this->emitConstBool(
true, E);
1359 this->fallthrough(LabelEnd);
1360 this->emitLabel(LabelEnd);
1363 assert(Op == BO_LAnd);
1366 LabelTy LabelFalse = this->getLabel();
1367 LabelTy LabelEnd = this->getLabel();
1371 if (!this->jumpFalse(LabelFalse, E))
1376 if (!this->jump(LabelEnd, E))
1379 this->emitLabel(LabelFalse);
1380 this->emitConstBool(
false, E);
1381 this->fallthrough(LabelEnd);
1382 this->emitLabel(LabelEnd);
1386 return this->emitPopBool(E);
1391 return this->emitCast(
PT_Bool, *T, E);
1395template <
class Emitter>
1402 if (!this->emitGetPtrLocal(*LocalIndex, E))
1411 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1412 unsigned ResultOffset = ~0u;
1418 if (!this->emitDupPtr(E))
1420 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1425 LHSType = AT->getValueType();
1428 RHSType = AT->getValueType();
1437 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1442 if (!this->
visit(LHS))
1444 if (!this->
visit(RHS))
1446 if (!this->emitMulc(ElemT, E))
1449 return this->emitPopPtr(E);
1453 if (Op == BO_Div && RHSIsComplex) {
1460 if (!LHSIsComplex) {
1465 LHSOffset = *LocalIndex;
1467 if (!this->emitGetPtrLocal(LHSOffset, E))
1470 if (!this->
visit(LHS))
1473 if (!this->emitInitElem(ElemT, 0, E))
1476 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1478 if (!this->emitInitElem(ElemT, 1, E))
1481 if (!this->
visit(LHS))
1485 if (!this->
visit(RHS))
1487 if (!this->emitDivc(ElemT, E))
1490 return this->emitPopPtr(E);
1497 if (!this->
visit(LHS))
1499 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1504 if (!this->
visit(LHS))
1506 if (!this->emitSetLocal(LHST, LHSOffset, E))
1514 if (!this->
visit(RHS))
1516 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1521 if (!this->
visit(RHS))
1523 if (!this->emitSetLocal(RHST, RHSOffset, E))
1530 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1531 unsigned ElemIndex,
unsigned Offset,
1532 const Expr *E) ->
bool {
1534 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1536 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1539 if (ElemIndex == 0 || !LoadZero)
1546 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1549 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1556 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1559 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1562 if (!this->emitAddf(getFPOptions(E), E))
1565 if (!this->emitAdd(ResultElemT, E))
1570 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1573 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1576 if (!this->emitSubf(getFPOptions(E), E))
1579 if (!this->emitSub(ResultElemT, E))
1584 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1587 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1591 if (!this->emitMulf(getFPOptions(E), E))
1594 if (!this->emitMul(ResultElemT, E))
1599 assert(!RHSIsComplex);
1600 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1603 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1607 if (!this->emitDivf(getFPOptions(E), E))
1610 if (!this->emitDiv(ResultElemT, E))
1621 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1624 if (!this->emitPop(ResultElemT, E))
1629 return this->emitPopPtr(E);
1635template <
class Emitter>
1640 "Comma op should be handled in VisitBinaryOperator");
1654 if (!this->emitGetPtrLocal(*LocalIndex, E))
1668 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1671 if (!this->
visit(LHS))
1673 if (!this->
visit(RHS))
1675 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1678 return this->emitPopPtr(E);
1683 unsigned LHSOffset =
1685 if (!this->
visit(LHS))
1687 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1691 unsigned RHSOffset =
1693 if (!this->
visit(RHS))
1695 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1707 if (NeedIntPromot) {
1709 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1714 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1715 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1717 if (!this->emitArrayElemPop(ElemT, Index, E))
1720 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1722 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1724 }
else if (NeedIntPromot) {
1725 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1731#define EMIT_ARITH_OP(OP) \
1733 if (ElemT == PT_Float) { \
1734 if (!this->emit##OP##f(getFPOptions(E), E)) \
1737 if (!this->emit##OP(ElemT, E)) \
1743 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1744 if (!getElem(LHSOffset, ElemT, I))
1746 if (!getElem(RHSOffset, RHSElemT, I))
1758 if (!this->emitRem(ElemT, E))
1762 if (!this->emitBitAnd(OpT, E))
1766 if (!this->emitBitOr(OpT, E))
1770 if (!this->emitBitXor(OpT, E))
1774 if (!this->emitShl(OpT, RHSElemT, E))
1778 if (!this->emitShr(OpT, RHSElemT, E))
1782 if (!this->emitEQ(ElemT, E))
1786 if (!this->emitNE(ElemT, E))
1790 if (!this->emitLE(ElemT, E))
1794 if (!this->emitLT(ElemT, E))
1798 if (!this->emitGE(ElemT, E))
1802 if (!this->emitGT(ElemT, E))
1807 if (!this->emitBitAnd(ResultElemT, E))
1812 if (!this->emitBitOr(ResultElemT, E))
1816 return this->emitInvalid(E);
1825 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1827 if (!this->emitNeg(ResultElemT, E))
1833 if (NeedIntPromot &&
1834 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1838 if (!this->emitInitElem(ResultElemT, I, E))
1847template <
class Emitter>
1857 auto LHSSemaInt = LHSSema.toOpaqueInt();
1859 auto RHSSemaInt = RHSSema.toOpaqueInt();
1861 if (!this->
visit(LHS))
1869 if (!this->
visit(RHS))
1878 auto ConvertResult = [&](
bool R) ->
bool {
1882 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1883 if (ResultSema != CommonSema)
1884 return this->emitCastFixedPoint(ResultSema, E);
1888 auto MaybeCastToBool = [&](
bool Result) {
1893 return this->emitPop(T, E);
1895 return this->emitCast(
PT_Bool, T, E);
1901 return MaybeCastToBool(this->emitEQFixedPoint(E));
1903 return MaybeCastToBool(this->emitNEFixedPoint(E));
1905 return MaybeCastToBool(this->emitLTFixedPoint(E));
1907 return MaybeCastToBool(this->emitLEFixedPoint(E));
1909 return MaybeCastToBool(this->emitGTFixedPoint(E));
1911 return MaybeCastToBool(this->emitGEFixedPoint(E));
1913 return ConvertResult(this->emitAddFixedPoint(E));
1915 return ConvertResult(this->emitSubFixedPoint(E));
1917 return ConvertResult(this->emitMulFixedPoint(E));
1919 return ConvertResult(this->emitDivFixedPoint(E));
1921 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1923 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1926 return this->emitInvalid(E);
1929 llvm_unreachable(
"unhandled binop opcode");
1932template <
class Emitter>
1941 if (!this->
visit(SubExpr))
1943 return this->emitNegFixedPoint(E);
1948 llvm_unreachable(
"Unhandled unary opcode");
1951template <
class Emitter>
1960 return this->visitZeroInitializer(*T, QT, E);
1968 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1969 CXXRD && CXXRD->getNumVBases() > 0) {
1979 return this->visitZeroRecordInitializer(R, E);
1986 return this->visitZeroArrayInitializer(QT, E);
1990 QualType ElemQT = ComplexTy->getElementType();
1992 for (
unsigned I = 0; I < 2; ++I) {
1993 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1995 if (!this->emitInitElem(ElemT, I, E))
2002 unsigned NumVecElements = VecT->getNumElements();
2003 QualType ElemQT = VecT->getElementType();
2006 for (
unsigned I = 0; I < NumVecElements; ++I) {
2007 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2009 if (!this->emitInitElem(ElemT, I, E))
2016 unsigned NumElems = MT->getNumElementsFlattened();
2017 QualType ElemQT = MT->getElementType();
2020 for (
unsigned I = 0; I != NumElems; ++I) {
2021 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2023 if (!this->emitInitElem(ElemT, I, E))
2032template <
class Emitter>
2045 for (
const Expr *SubExpr : {LHS, RHS}) {
2046 if (!this->
visit(SubExpr)) {
2053 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2054 if (!this->emitExpandPtr(E))
2065 return this->emitError(E);
2068 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2072 if (!this->emitArrayElemPtrPop(*IndexT, E))
2075 return this->emitPopPtr(E);
2081 return this->emitLoadPop(*T, E);
2084template <
class Emitter>
2086 const Expr *ArrayFiller,
const Expr *E) {
2091 QT = AT->getValueType();
2094 if (
Inits.size() == 0)
2096 return this->emitInvalid(E);
2111 if (
Inits.size() == 0)
2112 return this->visitZeroInitializer(*T, QT, E);
2113 assert(
Inits.size() == 1);
2126 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2133 bool BitField = FieldToInit->isBitField();
2135 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2136 FieldToInit->bitWidth(), E);
2138 return this->emitInitBitField(T, FieldToInit->Offset,
2139 FieldToInit->bitWidth(), E);
2141 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2142 return this->emitInitField(T, FieldToInit->Offset, E);
2145 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2153 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2156 if (
Activate && !this->emitActivate(E))
2161 return this->emitPopPtr(E);
2165 if (
Inits.size() == 0) {
2166 if (!this->visitZeroRecordInitializer(R, E))
2171 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2172 FToInit = ILE->getInitializedFieldInUnion();
2176 const Record::Field *FieldToInit = R->getField(FToInit);
2178 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2181 if (!initCompositeField(FieldToInit,
Init,
true))
2185 return this->emitFinishInit(E);
2188 assert(!R->isUnion());
2189 unsigned InitIndex = 0;
2192 while (InitIndex < R->getNumFields() &&
2193 R->getField(InitIndex)->isUnnamedBitField())
2197 const Record::Field *FieldToInit = R->getField(InitIndex);
2198 if (!initPrimitiveField(FieldToInit,
Init, *T))
2203 if (
const Record::Base *B = R->getBase(
Init->getType())) {
2204 if (!this->emitGetPtrBase(B->Offset,
Init))
2210 if (!this->emitFinishInitPop(E))
2215 const Record::Field *FieldToInit = R->getField(InitIndex);
2216 if (!initCompositeField(FieldToInit,
Init))
2222 return this->emitFinishInit(E);
2226 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2230 Ctx.getASTContext().getAsConstantArrayType(QT);
2233 if (!this->emitCheckArraySize(NumElems, E))
2237 unsigned ElementIndex = 0;
2239 if (
const auto *EmbedS =
2240 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2248 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2249 getFPOptions(E), E))
2255 return this->emitInitElem(TargetT, ElemIndex, IL);
2257 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2269 for (; ElementIndex != NumElems; ++ElementIndex) {
2275 return this->emitFinishInit(E);
2279 unsigned NumInits =
Inits.size();
2284 QualType ElemQT = ComplexTy->getElementType();
2286 if (NumInits == 0) {
2288 for (
unsigned I = 0; I < 2; ++I) {
2289 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2291 if (!this->emitInitElem(ElemT, I, E))
2294 }
else if (NumInits == 2) {
2295 unsigned InitIndex = 0;
2300 if (!this->emitInitElem(ElemT, InitIndex, E))
2309 unsigned NumVecElements = VecT->getNumElements();
2310 assert(NumVecElements >=
Inits.size());
2312 QualType ElemQT = VecT->getElementType();
2316 unsigned InitIndex = 0;
2323 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2324 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2325 InitVecT->getNumElements(), E))
2327 InitIndex += InitVecT->getNumElements();
2329 if (!this->emitInitElem(ElemT, InitIndex, E))
2335 assert(InitIndex <= NumVecElements);
2338 for (; InitIndex != NumVecElements; ++InitIndex) {
2339 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2341 if (!this->emitInitElem(ElemT, InitIndex, E))
2348 unsigned NumElems = MT->getNumElementsFlattened();
2349 assert(
Inits.size() == NumElems);
2351 QualType ElemQT = MT->getElementType();
2357 for (
unsigned I = 0; I != NumElems; ++I) {
2360 if (!this->emitInitElem(ElemT, I, E))
2371template <
class Emitter>
2378 return this->emitInitElem(*InitT, ElemIndex,
Init);
2384 if (!this->emitConstUint32(ElemIndex,
Init))
2386 if (!this->emitArrayElemPtrUint32(
Init))
2390 return this->emitFinishInitPop(
Init);
2393template <
class Emitter>
2396 bool Activate,
bool IsOperatorCall) {
2398 llvm::BitVector NonNullArgs;
2399 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2402 bool ExplicitMemberFn =
false;
2403 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2404 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2406 unsigned ArgIndex = 0;
2407 for (
const Expr *Arg : Args) {
2409 if (!this->
visit(Arg))
2417 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2418 if (DeclIndex < FuncDecl->getNumParams())
2419 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2428 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2436 if (!this->emitActivate(Arg))
2440 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2443 if (!this->emitCheckNonNullArg(ArgT, Arg))
2454template <
class Emitter>
2459template <
class Emitter>
2465template <
class Emitter>
2471template <
class Emitter>
2487template <
class Emitter>
2489 auto It = E->
begin();
2490 return this->
visit(*It);
2495 bool AlignOfReturnsPreferred =
2496 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2502 T = Ref->getPointeeType();
2504 if (T.getQualifiers().hasUnaligned())
2510 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2516template <
class Emitter>
2523 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2529 ArgType = Ref->getPointeeType();
2535 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2536 return this->emitInvalid(E);
2538 if (Kind == UETT_SizeOf)
2547 return this->emitConst(Size.getQuantity(), E);
2550 if (Kind == UETT_CountOf) {
2556 if (
const auto *CAT =
2560 return this->emitConst(CAT->getSize(), E);
2570 if (VAT->getElementType()->isArrayType()) {
2571 std::optional<APSInt> Res =
2573 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2578 return this->emitConst(*Res, E);
2583 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2603 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2606 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2616 return this->emitConst(Size.getQuantity(), E);
2619 if (Kind == UETT_VectorElements) {
2624 return this->emitConst(VT->getNumElements(), E);
2626 return this->emitSizelessVectorElementSize(E);
2629 if (Kind == UETT_VecStep) {
2631 unsigned N = VT->getNumElements();
2638 return this->emitConst(N, E);
2640 return this->emitConst(1, E);
2643 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2650 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2652 return this->emitInvalid(E);
2654 return this->emitConst(
2655 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2663template <
class Emitter>
2674 const auto maybeLoadValue = [&]() ->
bool {
2678 return this->emitLoadPop(*T, E);
2682 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2686 if (
auto GlobalIndex =
P.getGlobal(VD))
2687 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2692 if (!this->
discard(Base) && !this->emitSideEffect(E))
2707 const Record::Field *F = R->getField(FD);
2709 if (F->Decl->getType()->isReferenceType())
2710 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2711 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2714template <
class Emitter>
2724template <
class Emitter>
2738 if (!this->
visit(Common))
2740 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2754 for (
size_t I = 0; I != Size; ++I) {
2766template <
class Emitter>
2781 return this->emitGetLocal(SubExprT, It->second, E);
2784 if (!this->
visit(SourceExpr))
2791 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2800 return this->emitGetLocal(SubExprT, LocalIndex, E);
2804template <
class Emitter>
2827 bool IsBcpCall =
false;
2828 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2829 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2833 LabelTy LabelEnd = this->getLabel();
2834 LabelTy LabelFalse = this->getLabel();
2837 if (!this->emitPushIgnoreDiags(E))
2845 if (this->checkingForUndefinedBehavior()) {
2848 if (!this->
discard(FalseExpr))
2854 if (!this->jumpFalse(LabelFalse, E))
2859 if (!this->jump(LabelEnd, E))
2861 this->emitLabel(LabelFalse);
2865 this->fallthrough(LabelEnd);
2866 this->emitLabel(LabelEnd);
2869 return this->emitPopIgnoreDiags(E);
2873template <
class Emitter>
2879 unsigned StringIndex =
P.createGlobalString(E);
2880 return this->emitGetPtrGlobal(StringIndex, E);
2885 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2886 assert(CAT &&
"a string literal that's not a constant array?");
2891 unsigned N = std::min(ArraySize, E->
getLength());
2894 for (
unsigned I = 0; I != N; ++I) {
2897 if (CharWidth == 1) {
2898 this->emitConstSint8(CodeUnit, E);
2899 this->emitInitElemSint8(I, E);
2900 }
else if (CharWidth == 2) {
2901 this->emitConstUint16(CodeUnit, E);
2902 this->emitInitElemUint16(I, E);
2903 }
else if (CharWidth == 4) {
2904 this->emitConstUint32(CodeUnit, E);
2905 this->emitInitElemUint32(I, E);
2907 llvm_unreachable(
"unsupported character width");
2912 for (
unsigned I = N; I != ArraySize; ++I) {
2913 if (CharWidth == 1) {
2914 this->emitConstSint8(0, E);
2915 this->emitInitElemSint8(I, E);
2916 }
else if (CharWidth == 2) {
2917 this->emitConstUint16(0, E);
2918 this->emitInitElemUint16(I, E);
2919 }
else if (CharWidth == 4) {
2920 this->emitConstUint32(0, E);
2921 this->emitInitElemUint32(I, E);
2923 llvm_unreachable(
"unsupported character width");
2930template <
class Emitter>
2934 return this->emitDummyPtr(E, E);
2937template <
class Emitter>
2939 auto &A =
Ctx.getASTContext();
2948template <
class Emitter>
2956 auto &A =
Ctx.getASTContext();
2960 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2961 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2968 unsigned StringIndex =
P.createGlobalString(SL);
2969 return this->emitGetPtrGlobal(StringIndex, E);
2972template <
class Emitter>
2976 return this->emitConst(E->
getValue(), E);
2979template <
class Emitter>
3005 if (!this->emitSetLocal(*RT, TempOffset, E))
3011 if (!this->emitLoad(LHST, E))
3015 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3016 LHSComputationType, E))
3020 if (!this->emitGetLocal(*RT, TempOffset, E))
3025 if (!this->emitAddf(getFPOptions(E), E))
3029 if (!this->emitSubf(getFPOptions(E), E))
3033 if (!this->emitMulf(getFPOptions(E), E))
3037 if (!this->emitDivf(getFPOptions(E), E))
3048 return this->emitStorePop(LHST, E);
3049 return this->emitStore(LHST, E);
3052template <
class Emitter>
3061 if (Op != BO_AddAssign && Op != BO_SubAssign)
3070 if (!this->emitLoad(*
LT, LHS))
3076 if (Op == BO_AddAssign) {
3077 if (!this->emitAddOffset(*RT, E))
3080 if (!this->emitSubOffset(*RT, E))
3085 return this->emitStorePopPtr(E);
3086 return this->emitStorePtr(E);
3089template <
class Emitter>
3102 if (!
Ctx.getLangOpts().CPlusPlus14)
3103 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3105 if (!
LT || !RT || !ResultT || !LHSComputationT)
3130 if (!this->emitSetLocal(*RT, TempOffset, E))
3137 if (!this->emitLoad(*
LT, E))
3139 if (
LT != LHSComputationT &&
3145 if (!this->emitGetLocal(*RT, TempOffset, E))
3151 if (!this->emitAdd(*LHSComputationT, E))
3155 if (!this->emitSub(*LHSComputationT, E))
3159 if (!this->emitMul(*LHSComputationT, E))
3163 if (!this->emitDiv(*LHSComputationT, E))
3167 if (!this->emitRem(*LHSComputationT, E))
3171 if (!this->emitShl(*LHSComputationT, *RT, E))
3175 if (!this->emitShr(*LHSComputationT, *RT, E))
3179 if (!this->emitBitAnd(*LHSComputationT, E))
3183 if (!this->emitBitXor(*LHSComputationT, E))
3187 if (!this->emitBitOr(*LHSComputationT, E))
3191 llvm_unreachable(
"Unimplemented compound assign operator");
3195 if (ResultT != LHSComputationT &&
3196 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3202 return this->emitStoreBitFieldPop(*ResultT, E);
3203 return this->emitStorePop(*ResultT, E);
3206 return this->emitStoreBitField(*ResultT, E);
3207 return this->emitStore(*ResultT, E);
3210template <
class Emitter>
3218template <
class Emitter>
3233 if (!
Ctx.getLangOpts().CPlusPlus11)
3240 for (
const Expr *LHS : CommaLHSs) {
3260 if (!this->
visit(Inner))
3262 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3264 return this->emitGetPtrGlobal(*GlobalIndex, E);
3267 if (!this->checkLiteralType(Inner))
3270 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3274 return this->emitInitGlobalTempComp(TempDecl, E);
3285 unsigned LocalIndex =
3287 if (!this->VarScope->LocalsAlwaysEnabled &&
3288 !this->emitEnableLocal(LocalIndex, E))
3291 if (!this->
visit(Inner))
3293 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3296 return this->emitGetPtrLocal(LocalIndex, E);
3299 if (!this->checkLiteralType(Inner))
3306 if (!this->VarScope->LocalsAlwaysEnabled &&
3307 !this->emitEnableLocal(*LocalIndex, E))
3310 if (!this->emitGetPtrLocal(*LocalIndex, E))
3317template <
class Emitter>
3328 if (!this->
visit(SubExpr))
3332 return this->emitPopPtr(E);
3336template <
class Emitter>
3357 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3362 if (
P.isGlobalInitialized(*GlobalIndex))
3368 return this->emitInitGlobal(*T, *GlobalIndex, E);
3380 unsigned LocalIndex;
3384 LocalIndex = *MaybeIndex;
3388 if (!this->emitGetPtrLocal(LocalIndex, E))
3392 return this->
visit(
Init) && this->emitInit(*T, E);
3396template <
class Emitter>
3409template <
class Emitter>
3413 return this->emitConst(E->
getValue(), E);
3416template <
class Emitter>
3429 for (
const Record::Field &F : R->fields()) {
3431 if (!
Init ||
Init->containsErrors())
3439 if (!this->emitInitField(*T, F.Offset, E))
3442 if (!this->emitGetPtrField(F.Offset, E))
3448 if (!this->emitPopPtr(E))
3456template <
class Emitter>
3463 return this->emitGetPtrGlobal(StringIndex, E);
3469template <
class Emitter>
3474 return this->emitInvalid(E);
3477template <
class Emitter>
3503 if (PointeeToT && PointeeFromT) {
3522 bool Fatal = (ToT != FromT);
3529template <
class Emitter>
3532 if (!
Ctx.getLangOpts().CPlusPlus20) {
3540template <
class Emitter>
3546 return this->emitConstBool(E->
getValue(), E);
3549template <
class Emitter>
3554 if (T->isRecordType()) {
3568 if (!this->emitGetPtrLocal(*LocalIndex, E))
3576 T->getAsCXXRecordDecl()))
3586 if (!this->visitZeroRecordInitializer(R, E))
3598 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3600 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3601 if (!this->emitCheckFunctionDecl(Ctor, E))
3612 assert(
Func->hasThisPointer());
3613 assert(!
Func->hasRVO());
3617 if (!this->emitDupPtr(E))
3621 for (
const auto *Arg : E->
arguments()) {
3622 if (!this->
visit(Arg))
3626 if (
Func->isVariadic()) {
3627 uint32_t VarArgSize = 0;
3628 unsigned NumParams =
Func->getNumWrittenParams();
3629 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3633 if (!this->emitCallVar(
Func, VarArgSize, E))
3636 if (!this->emitCall(
Func, 0, E)) {
3641 (void)this->emitPopPtr(E);
3647 return this->emitPopPtr(E);
3648 return this->emitFinishInit(E);
3651 if (T->isArrayType()) {
3656 if (!this->emitDupPtr(E))
3660 initArrayDimension = [&](
QualType T) ->
bool {
3661 if (!T->isArrayType()) {
3663 for (
const auto *Arg : E->
arguments()) {
3664 if (!this->
visit(Arg))
3668 return this->emitCall(
Func, 0, E);
3672 Ctx.getASTContext().getAsConstantArrayType(T);
3677 for (
size_t I = 0; I != NumElems; ++I) {
3678 if (!this->emitConstUint64(I, E))
3680 if (!this->emitArrayElemPtrUint64(E))
3682 if (!initArrayDimension(ElemTy))
3685 return this->emitPopPtr(E);
3688 return initArrayDimension(E->
getType());
3694template <
class Emitter>
3704 assert(Val.
isInt());
3706 return this->emitConst(I, E);
3713 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3714 return this->
visit(LValueExpr);
3729 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3733 const APValue &
V = UGCD->getValue();
3734 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3735 const Record::Field *F = R->getField(I);
3736 const APValue &FieldValue =
V.getStructField(I);
3742 if (!this->emitInitField(FieldT, F->Offset, E))
3750template <
class Emitter>
3756 for (
unsigned I = 0; I != N; ++I) {
3763 if (!this->
discard(ArrayIndexExpr))
3768 if (!this->
visit(ArrayIndexExpr))
3772 if (!this->emitCast(IndexT,
PT_Sint64, E))
3782 return this->emitOffsetOf(T, E, E);
3785template <
class Emitter>
3794 return this->visitZeroInitializer(*T, Ty, E);
3801 if (!this->emitGetPtrLocal(*LocalIndex, E))
3806 QualType ElemQT = CT->getElementType();
3809 for (
unsigned I = 0; I != 2; ++I) {
3810 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3812 if (!this->emitInitElem(ElemT, I, E))
3824 if (!this->emitGetPtrLocal(*LocalIndex, E))
3829 QualType ElemQT = VT->getElementType();
3832 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3833 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3835 if (!this->emitInitElem(ElemT, I, E))
3844template <
class Emitter>
3849template <
class Emitter>
3855template <
class Emitter>
3860template <
class Emitter>
3865 return this->emitConst(E->
getValue(), E);
3868template <
class Emitter>
3873 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3887 unsigned ParamIndex = 0;
3891 if (!this->emitGetParam(PT, ParamIndex, E))
3896 return this->emitCall(F, 0, E);
3901template <
class Emitter>
3909 const Expr *PlacementDest =
nullptr;
3910 bool IsNoThrow =
false;
3915 if (PlacementArgs != 0) {
3924 if (PlacementArgs == 1) {
3932 if (!this->emitInvalidNewDeleteExpr(E, E))
3937 if (OperatorNew->isReservedGlobalPlacementOperator())
3938 PlacementDest = Arg1;
3942 return this->emitInvalid(E);
3944 }
else if (!OperatorNew
3945 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3946 return this->emitInvalidNewDeleteExpr(E, E);
3949 if (!PlacementDest) {
3954 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3957 Desc =
P.createDescriptor(
3960 false,
false,
false,
3966 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3970 const Expr *Stripped = *ArraySizeExpr;
3971 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3972 Stripped = ICE->getSubExpr())
3973 if (ICE->getCastKind() != CK_NoOp &&
3974 ICE->getCastKind() != CK_IntegralCast)
3982 if (!this->
visit(Stripped))
3984 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3987 if (PlacementDest) {
3988 if (!this->
visit(PlacementDest))
3990 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3992 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3995 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4000 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4004 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4011 size_t StaticInitElems = 0;
4012 const Expr *DynamicInit =
nullptr;
4016 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4017 StaticInitElems = CAT->getZExtSize();
4022 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4023 if (ILE->hasArrayFiller())
4024 DynamicInit = ILE->getArrayFiller();
4043 const Function *CtorFunc =
nullptr;
4044 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4048 }
else if (!DynamicInit && !ElemT)
4051 LabelTy EndLabel = this->getLabel();
4052 LabelTy StartLabel = this->getLabel();
4057 if (!this->emitDupPtr(E))
4059 if (!this->emitNullPtr(0,
nullptr, E))
4061 if (!this->emitEQPtr(E))
4063 if (!this->jumpTrue(EndLabel, E))
4070 if (!this->emitConst(StaticInitElems,
SizeT, E))
4072 if (!this->emitSetLocal(
SizeT, Iter, E))
4075 this->fallthrough(StartLabel);
4076 this->emitLabel(StartLabel);
4078 if (!this->emitGetLocal(
SizeT, Iter, E))
4080 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4082 if (!this->emitLT(
SizeT, E))
4084 if (!this->jumpFalse(EndLabel, E))
4088 if (!this->emitGetLocal(
SizeT, Iter, E))
4090 if (!this->emitArrayElemPtr(
SizeT, E))
4093 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4098 if (!this->visitZeroInitializer(InitT, ElemType, E))
4100 if (!this->emitStorePop(InitT, E))
4102 }
else if (DynamicInit) {
4104 if (!this->
visit(DynamicInit))
4106 if (!this->emitStorePop(*InitT, E))
4111 if (!this->emitPopPtr(E))
4115 if (!this->visitZeroInitializer(
4119 if (!this->emitStorePop(*ElemT, E))
4123 if (!this->emitCall(CtorFunc, 0, E))
4128 if (!this->emitGetPtrLocal(Iter, E))
4130 if (!this->emitIncPop(
SizeT,
false, E))
4133 if (!this->jump(StartLabel, E))
4136 this->fallthrough(EndLabel);
4137 this->emitLabel(EndLabel);
4141 if (PlacementDest) {
4142 if (!this->
visit(PlacementDest))
4144 if (!this->emitCheckNewTypeMismatch(E, E))
4149 if (!this->emitAlloc(Desc, E))
4158 if (!this->emitInit(*ElemT, E))
4169 return this->emitPopPtr(E);
4174template <
class Emitter>
4180 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4181 return this->emitInvalidNewDeleteExpr(E, E);
4190template <
class Emitter>
4196 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4201 return this->emitGetFnPtr(
Func, E);
4204template <
class Emitter>
4208 auto canonType = [](
const Type *T) {
4209 return T->getCanonicalTypeUnqualified().getTypePtr();
4217 return this->emitGetTypeid(
4221 return this->emitGetTypeid(
4230 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4236 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4239 return this->emitPopPtr(E);
4243template <
class Emitter>
4247 return this->emitDummyPtr(E, E);
4248 return this->emitError(E);
4251template <
class Emitter>
4254 return this->emitDummyPtr(E, E);
4255 return this->emitError(E);
4258template <
class Emitter>
4260 assert(
Ctx.getLangOpts().CPlusPlus);
4261 return this->emitConstBool(E->
getValue(), E);
4264template <
class Emitter>
4276 return this->emitDummyPtr(GuidDecl, E);
4281 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4290 assert(
V.isStruct());
4291 assert(
V.getStructNumBases() == 0);
4295 return this->emitFinishInit(E);
4298template <
class Emitter>
4308template <
class Emitter>
4317template <
class Emitter>
4323template <
class Emitter>
4327 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4331 if (OVE->isUnique())
4347template <
class Emitter>
4352template <
class Emitter>
4354 return this->emitError(E);
4357template <
class Emitter>
4363 return this->emitDummyPtr(E, E);
4366template <
class Emitter>
4370 QualType ElemType = VT->getElementType();
4374 PrimType SrcElemT = classifyVectorElementType(SrcType);
4376 unsigned SrcOffset =
4378 if (!this->
visit(Src))
4380 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4383 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4384 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4386 if (!this->emitArrayElemPop(SrcElemT, I, E))
4390 if (SrcElemT != ElemT) {
4391 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4393 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4394 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4398 if (!this->emitInitElem(ElemT, I, E))
4405template <
class Emitter>
4409 return this->emitInvalid(E);
4418 assert(NumOutputElems > 0);
4424 if (!this->emitGetPtrLocal(*LocalIndex, E))
4429 unsigned VectorOffsets[2];
4430 for (
unsigned I = 0; I != 2; ++I) {
4433 if (!this->
visit(Vecs[I]))
4435 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4438 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4440 assert(ShuffleIndex >= -1);
4441 if (ShuffleIndex == -1)
4442 return this->emitInvalidShuffleVectorIndex(I, E);
4444 assert(ShuffleIndex < (NumInputElems * 2));
4445 if (!this->emitGetLocal(
PT_Ptr,
4446 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4448 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4449 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4452 if (!this->emitInitElem(ElemT, I, E))
4457 return this->emitPopPtr(E);
4462template <
class Emitter>
4467 Base->getType()->isVectorType() ||
4473 if (Indices.size() == 1) {
4478 if (!this->emitConstUint32(Indices[0], E))
4480 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4490 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4498 if (!this->emitGetPtrLocal(*ResultIndex, E))
4506 uint32_t DstIndex = 0;
4507 for (uint32_t I : Indices) {
4508 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4510 if (!this->emitArrayElemPop(ElemT, I, E))
4512 if (!this->emitInitElem(ElemT, DstIndex, E))
4522template <
class Emitter>
4526 return this->
discard(SubExpr) && this->emitInvalid(E);
4532 return this->emitDummyPtr(E, E);
4535template <
class Emitter>
4540 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4545 if (!this->
visit(SubExpr))
4547 if (!this->emitConstUint8(0, E))
4549 if (!this->emitArrayElemPtrPopUint8(E))
4551 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4556 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4558 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4560 assert(SecondFieldT ==
PT_Ptr);
4562 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4564 if (!this->emitExpandPtr(E))
4568 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4570 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4573template <
class Emitter>
4588 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4590 return this->emitUnsupported(E);
4599 return this->
Visit(E);
4606 return this->
Visit(E);
4610 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4613 if (
const auto *CE = dyn_cast<CastExpr>(E);
4615 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4622 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4625 if (
const auto *CE = dyn_cast<CastExpr>(E);
4626 CE && (CE->getCastKind() == CK_DerivedToBase ||
4627 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4628 CE->getCastKind() == CK_NoOp))
4648 if (!this->emitGetPtrLocal(*LocalIndex, E))
4658 return this->
Visit(E);
4661template <
class Emitter>
4667 return this->
Visit(E);
4673 return this->
Visit(E);
4684 if (!this->
visit(E))
4686 return this->emitComplexBoolCast(E);
4691 if (!this->
visit(E))
4699 return this->emitIsNonNullPtr(E);
4703 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4706 return this->emitCast(*T,
PT_Bool, E);
4709template <
class Emitter>
4713 QT = AT->getValueType();
4717 return this->emitZeroBool(E);
4719 return this->emitZeroSint8(E);
4721 return this->emitZeroUint8(E);
4723 return this->emitZeroSint16(E);
4725 return this->emitZeroUint16(E);
4727 return this->emitZeroSint32(E);
4729 return this->emitZeroUint32(E);
4731 return this->emitZeroSint64(E);
4733 return this->emitZeroUint64(E);
4735 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4737 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4739 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4742 return this->emitNullMemberPtr(0,
nullptr, E);
4744 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4745 return this->emitFloat(F, E);
4748 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4752 llvm_unreachable(
"unknown primitive type");
4755template <
class Emitter>
4756bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4761 for (
const Record::Field &Field :
R->fields()) {
4762 if (Field.isUnnamedBitField())
4769 if (!this->visitZeroInitializer(T, QT, E))
4772 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4776 if (!this->emitInitField(T, Field.Offset, E))
4781 if (!this->emitGetPtrField(Field.Offset, E))
4787 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4788 if (!this->visitZeroInitializer(T, ET, E))
4790 if (!this->emitInitElem(T, I, E))
4795 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4798 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4806 if (!this->emitFinishInitActivatePop(E))
4810 if (!this->emitFinishInitPop(E))
4814 for (
const Record::Base &B :
R->bases()) {
4815 if (!this->emitGetPtrBase(B.Offset, E))
4817 if (!this->visitZeroRecordInitializer(B.R, E))
4819 if (!this->emitFinishInitPop(E))
4828template <
class Emitter>
4829bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4830 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4836 for (
size_t I = 0; I != NumElems; ++I) {
4837 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4839 if (!this->emitInitElem(*ElemT, I, E))
4845 const Record *
R = getRecord(ElemType);
4849 for (
size_t I = 0; I != NumElems; ++I) {
4850 if (!this->emitConstUint32(I, E))
4852 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4854 if (!this->visitZeroRecordInitializer(R, E))
4856 if (!this->emitPopPtr(E))
4862 for (
size_t I = 0; I != NumElems; ++I) {
4863 if (!this->emitConstUint32(I, E))
4865 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4867 if (!this->visitZeroArrayInitializer(ElemType, E))
4869 if (!this->emitPopPtr(E))
4878template <
class Emitter>
4879bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4881 if (!canClassify(E->
getType()))
4884 if (!this->visit(RHS))
4886 if (!this->visit(LHS))
4893 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4897 bool Activates = refersToUnion(LHS);
4900 if (!this->emitFlip(
PT_Ptr, RHT, E))
4903 if (DiscardResult) {
4904 if (BitField && Activates)
4905 return this->emitStoreBitFieldActivatePop(RHT, E);
4907 return this->emitStoreBitFieldPop(RHT, E);
4909 return this->emitStoreActivatePop(RHT, E);
4911 return this->emitStorePop(RHT, E);
4914 auto maybeLoad = [&](
bool Result) ->
bool {
4920 return this->emitLoadPop(RHT, E);
4924 if (BitField && Activates)
4925 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4927 return maybeLoad(this->emitStoreBitField(RHT, E));
4929 return maybeLoad(this->emitStoreActivate(RHT, E));
4931 return maybeLoad(this->emitStore(RHT, E));
4934template <
class Emitter>
4935template <
typename T>
4939 return this->emitConstSint8(
Value, E);
4941 return this->emitConstUint8(
Value, E);
4943 return this->emitConstSint16(
Value, E);
4945 return this->emitConstUint16(
Value, E);
4947 return this->emitConstSint32(
Value, E);
4949 return this->emitConstUint32(
Value, E);
4951 return this->emitConstSint64(
Value, E);
4953 return this->emitConstUint64(
Value, E);
4955 return this->emitConstBool(
Value, E);
4962 llvm_unreachable(
"Invalid integral type");
4965 llvm_unreachable(
"unknown primitive type");
4968template <
class Emitter>
4969template <
typename T>
4970bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
4971 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4974template <
class Emitter>
4978 return this->emitConstIntAPS(
Value, E);
4980 return this->emitConstIntAP(
Value, E);
4982 if (
Value.isSigned())
4983 return this->emitConst(
Value.getSExtValue(), Ty, E);
4984 return this->emitConst(
Value.getZExtValue(), Ty, E);
4987template <
class Emitter>
4991 return this->emitConstIntAPS(
Value, E);
4993 return this->emitConstIntAP(
Value, E);
4996 return this->emitConst(
Value.getSExtValue(), Ty, E);
4997 return this->emitConst(
Value.getZExtValue(), Ty, E);
5000template <
class Emitter>
5001bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5002 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5005template <
class Emitter>
5018 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5019 Locals.insert({VD, Local});
5020 VarScope->addForScopeKind(Local, SC);
5021 return Local.Offset;
5024template <
class Emitter>
5029 bool IsTemporary =
false;
5030 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5033 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5034 Init = VarD->getInit();
5036 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5047 return std::nullopt;
5052 Locals.insert({Key, Local});
5053 VarScope->addForScopeKind(Local, SC);
5054 return Local.Offset;
5057template <
class Emitter>
5067 return std::nullopt;
5077 return Local.Offset;
5080template <
class Emitter>
5082 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5083 return PT->getPointeeType()->getAsCanonical<RecordType>();
5089 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5093template <
class Emitter>
5095 return P.getOrCreateRecord(RD);
5098template <
class Emitter>
5100 return Ctx.getOrCreateFunction(FD);
5103template <
class Emitter>
5107 auto maybeDestroyLocals = [&]() ->
bool {
5108 if (DestroyToplevelScope)
5109 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5110 return this->emitCheckAllocations(E);
5117 return this->emitRetVoid(E) && maybeDestroyLocals();
5125 return this->emitRet(*T, E) && maybeDestroyLocals();
5133 if (!this->emitGetPtrLocal(*LocalOffset, E))
5139 if (!this->emitFinishInit(E))
5144 return this->emitRetValue(E) && maybeDestroyLocals();
5147 return maybeDestroyLocals() &&
false;
5150template <
class Emitter>
5162 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5163 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5177template <
class Emitter>
5179 bool ConstantContext) {
5182 if (!ConstantContext) {
5196 auto GlobalIndex =
P.getGlobal(VD);
5197 assert(GlobalIndex);
5199 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5202 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5206 auto Local =
Locals.find(VD);
5207 assert(Local !=
Locals.end());
5209 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5212 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5222 auto GlobalIndex =
P.getGlobal(VD);
5223 assert(GlobalIndex);
5224 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5233 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5236template <
class Emitter>
5246 if (!this->isActive())
5251 if (
Init &&
Init->isValueDependent())
5255 auto checkDecl = [&]() ->
bool {
5257 return !NeedsOp || this->emitCheckDecl(VD, VD);
5264 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5267 if (
P.isGlobalInitialized(*GlobalIndex))
5271 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
5285 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5288 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5294 return this->emitFinishInitGlobal(
Init);
5304 if (!
Init ||
Init->getType()->isVoidType())
5313 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5317 return this->emitSetLocal(*VarT, Offset, VD);
5325 if (!this->emitGetPtrLocal(*Offset,
Init))
5331 return this->emitFinishInitPop(
Init);
5336template <
class Emitter>
5341 return this->emitConst(Val.
getInt(), ValType, E);
5344 return this->emitFloat(F, E);
5349 return this->emitNull(ValType, 0,
nullptr, E);
5351 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5352 return this->
visit(BaseExpr);
5357 return this->emitGetMemberPtr(MemberDecl, E);
5358 return this->emitNullMemberPtr(0,
nullptr, E);
5364template <
class Emitter>
5372 const Record::Field *RF = R->getField(I);
5373 QualType FieldType = RF->Decl->getType();
5378 if (!this->emitInitField(*PT, RF->Offset, E))
5381 if (!this->emitGetPtrField(RF->Offset, E))
5385 if (!this->emitPopPtr(E))
5398 const Record::Field *RF = R->getField(UnionField);
5399 QualType FieldType = RF->Decl->getType();
5404 if (RF->isBitField())
5405 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5407 return this->emitInitFieldActivate(*PT, RF->Offset, E);
5410 if (!this->emitGetPtrField(RF->Offset, E))
5412 if (!this->emitActivate(E))
5416 return this->emitPopPtr(E);
5419 const auto *ArrType = T->getAsArrayTypeUnsafe();
5420 QualType ElemType = ArrType->getElementType();
5421 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5426 if (!this->emitInitElem(*ElemT, A, E))
5429 if (!this->emitConstUint32(A, E))
5431 if (!this->emitArrayElemPtrUint32(E))
5435 if (!this->emitPopPtr(E))
5446template <
class Emitter>
5448 unsigned BuiltinID) {
5449 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5454 return this->emitConst(0, E);
5457 if (!this->emitStartSpeculation(E))
5459 LabelTy EndLabel = this->getLabel();
5460 if (!this->speculate(E, EndLabel))
5462 if (!this->emitEndSpeculation(E))
5464 this->fallthrough(EndLabel);
5472 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5473 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5474 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5475 BuiltinID == Builtin::BI__builtin_function_start) {
5478 return this->emitDummyPtr(E, E);
5489 if (!this->emitGetPtrLocal(*LocalIndex, E))
5494 switch (BuiltinID) {
5495 case Builtin::BI__builtin_object_size:
5496 case Builtin::BI__builtin_dynamic_object_size: {
5500 if (!this->
visit(Arg0))
5511 case Builtin::BI__assume:
5512 case Builtin::BI__builtin_assume:
5515 case Builtin::BI__atomic_is_lock_free:
5516 case Builtin::BI__atomic_always_lock_free: {
5527 for (
const auto *Arg : E->
arguments()) {
5528 if (!this->
visit(Arg))
5534 if (!this->emitCallBI(E, BuiltinID, E))
5543template <
class Emitter>
5562 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5563 DD && DD->isTrivial()) {
5565 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5567 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5568 this->emitPopPtr(E);
5576 bool HasRVO = !
ReturnType->isVoidType() && !T;
5584 if (!this->emitGetPtrLocal(*LocalIndex, E))
5592 if (!this->emitGetPtrLocal(*LocalIndex, E))
5596 if (!this->emitDupPtr(E))
5603 bool IsAssignmentOperatorCall =
false;
5604 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5605 OCE && OCE->isAssignmentOp()) {
5609 assert(Args.size() == 2);
5610 IsAssignmentOperatorCall =
true;
5611 std::reverse(Args.begin(), Args.end());
5617 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5618 MD && MD->isStatic()) {
5622 Args.erase(Args.begin());
5626 bool Devirtualized =
false;
5629 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5637 if (!this->
visit(Callee))
5639 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5641 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5643 if (!this->emitGetMemberPtrBase(E))
5646 const auto *InstancePtr = MC->getImplicitObjectArgument();
5653 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5654 Devirtualized =
true;
5655 if (!this->
visit(Stripped))
5658 if (!this->
visit(InstancePtr))
5662 if (!this->
visit(InstancePtr))
5666 }
else if (
const auto *PD =
5667 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5668 if (!this->emitCheckPseudoDtor(E))
5676 return this->emitEndLifetimePop(E);
5677 }
else if (!FuncDecl) {
5681 if (!this->
visit(Callee))
5683 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5687 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5692 if (IsAssignmentOperatorCall) {
5693 assert(Args.size() == 2);
5696 if (!this->emitFlip(Arg2T, Arg1T, E))
5710 assert(HasRVO ==
Func->hasRVO());
5712 bool HasQualifier =
false;
5713 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5714 HasQualifier = ME->hasQualifier();
5716 bool IsVirtual =
false;
5717 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5718 IsVirtual = !Devirtualized && MD->isVirtual();
5723 if (IsVirtual && !HasQualifier) {
5724 uint32_t VarArgSize = 0;
5725 unsigned NumParams =
5727 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5730 if (!this->emitCallVirt(
Func, VarArgSize, E))
5732 }
else if (
Func->isVariadic()) {
5733 uint32_t VarArgSize = 0;
5734 unsigned NumParams =
5736 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5738 if (!this->emitCallVar(
Func, VarArgSize, E))
5741 if (!this->emitCall(
Func, 0, E))
5750 uint32_t ArgSize = 0;
5751 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5757 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5759 if (!this->emitGetMemberPtrDecl(E))
5762 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5765 if (!this->emitCallPtr(ArgSize, E, E))
5776template <
class Emitter>
5783template <
class Emitter>
5790template <
class Emitter>
5795 return this->emitConstBool(E->
getValue(), E);
5798template <
class Emitter>
5804 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5805 return this->emitNullPtr(Val,
nullptr, E);
5808template <
class Emitter>
5816 return this->emitZero(T, E);
5819template <
class Emitter>
5824 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
5825 if (this->LambdaThisCapture.Offset > 0) {
5826 if (this->LambdaThisCapture.IsPtr)
5827 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5828 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5837 return this->emitThis(E);
5852 unsigned StartIndex = 0;
5853 unsigned EndIndex = 0;
5855 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5857 EndIndex = StartIndex;
5864 for (; StartIndex > 0; --StartIndex) {
5874 if (StartIndex == 0 && EndIndex == 0)
5877 assert(StartIndex < EndIndex);
5880 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5892 case Stmt::CompoundStmtClass:
5894 case Stmt::DeclStmtClass:
5896 case Stmt::ReturnStmtClass:
5898 case Stmt::IfStmtClass:
5900 case Stmt::WhileStmtClass:
5902 case Stmt::DoStmtClass:
5904 case Stmt::ForStmtClass:
5906 case Stmt::CXXForRangeStmtClass:
5908 case Stmt::BreakStmtClass:
5910 case Stmt::ContinueStmtClass:
5912 case Stmt::SwitchStmtClass:
5914 case Stmt::CaseStmtClass:
5916 case Stmt::DefaultStmtClass:
5918 case Stmt::AttributedStmtClass:
5920 case Stmt::CXXTryStmtClass:
5922 case Stmt::NullStmtClass:
5925 case Stmt::GCCAsmStmtClass:
5926 case Stmt::MSAsmStmtClass:
5927 case Stmt::GotoStmtClass:
5928 return this->emitInvalid(S);
5929 case Stmt::LabelStmtClass:
5932 if (
const auto *E = dyn_cast<Expr>(S))
5939template <
class Emitter>
5942 for (
const auto *InnerStmt : S->
body())
5945 return Scope.destroyLocals();
5948template <
class Emitter>
5949bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5950 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5951 for (
auto *BD : DD->flat_bindings())
5952 if (
auto *KD = BD->getHoldingVar();
5953 KD && !this->visitVarDecl(KD, KD->getInit()))
5967template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5969 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5970 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5977 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5982 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5983 ICE && (ICE->getCastKind() == CK_NoOp ||
5984 ICE->getCastKind() == CK_DerivedToBase ||
5985 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5986 E = ICE->getSubExpr();
5990 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5991 const auto *ThisRecord =
5992 This->getType()->getPointeeType()->getAsRecordDecl();
5993 if (!ThisRecord->isUnion())
5996 if (
const auto *Ctor =
5997 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5998 return Ctor->getParent() == ThisRecord;
6007template <
class Emitter>
6009 bool EvaluateConditionDecl) {
6010 for (
const auto *D : DS->
decls()) {
6015 const auto *VD = dyn_cast<VarDecl>(D);
6022 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6029template <
class Emitter>
6032 return this->emitUnsupported(RS);
6038 if (!this->
visit(RE))
6044 if (RE->getType()->isVoidType()) {
6045 if (!this->
visit(RE))
6048 if (RE->containsErrors())
6053 if (!this->emitRVOPtr(RE))
6057 if (!this->emitPopPtr(RE))
6061 return this->emitRetVoid(RS);
6067 return this->emitRetVoid(RS);
6073 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6080 if (
auto *CondInit = IS->
getInit()) {
6096 return visitChildStmt(IS->
getThen());
6098 return visitChildStmt(Else);
6104 if (!this->emitIsConstantContext(IS))
6107 if (!this->emitIsConstantContext(IS))
6109 if (!this->emitInv(IS))
6123 LabelTy LabelElse = this->getLabel();
6124 LabelTy LabelEnd = this->getLabel();
6125 if (!this->jumpFalse(LabelElse, IS))
6127 if (!visitChildStmt(IS->
getThen()))
6129 if (!this->jump(LabelEnd, IS))
6131 this->emitLabel(LabelElse);
6132 if (!visitChildStmt(Else))
6134 this->emitLabel(LabelEnd);
6136 LabelTy LabelEnd = this->getLabel();
6137 if (!this->jumpFalse(LabelEnd, IS))
6139 if (!visitChildStmt(IS->
getThen()))
6141 this->emitLabel(LabelEnd);
6150template <
class Emitter>
6155 LabelTy CondLabel = this->getLabel();
6156 LabelTy EndLabel = this->getLabel();
6160 this->fallthrough(CondLabel);
6161 this->emitLabel(CondLabel);
6177 if (!this->jumpFalse(EndLabel, S))
6187 if (!this->jump(CondLabel, S))
6189 this->fallthrough(EndLabel);
6190 this->emitLabel(EndLabel);
6199 LabelTy StartLabel = this->getLabel();
6200 LabelTy EndLabel = this->getLabel();
6201 LabelTy CondLabel = this->getLabel();
6205 this->fallthrough(StartLabel);
6206 this->emitLabel(StartLabel);
6212 this->fallthrough(CondLabel);
6213 this->emitLabel(CondLabel);
6220 if (!this->jumpTrue(StartLabel, S))
6223 this->fallthrough(EndLabel);
6224 this->emitLabel(EndLabel);
6228template <
class Emitter>
6236 LabelTy EndLabel = this->getLabel();
6237 LabelTy CondLabel = this->getLabel();
6238 LabelTy IncLabel = this->getLabel();
6245 this->fallthrough(CondLabel);
6246 this->emitLabel(CondLabel);
6258 if (!this->jumpFalse(EndLabel, S))
6267 this->fallthrough(IncLabel);
6268 this->emitLabel(IncLabel);
6274 if (!this->jump(CondLabel, S))
6278 this->emitLabel(EndLabel);
6284template <
class Emitter>
6294 LabelTy EndLabel = this->getLabel();
6295 LabelTy CondLabel = this->getLabel();
6296 LabelTy IncLabel = this->getLabel();
6311 this->fallthrough(CondLabel);
6312 this->emitLabel(CondLabel);
6315 if (!this->jumpFalse(EndLabel, S))
6326 this->fallthrough(IncLabel);
6327 this->emitLabel(IncLabel);
6332 if (!this->jump(CondLabel, S))
6335 this->fallthrough(EndLabel);
6336 this->emitLabel(EndLabel);
6340template <
class Emitter>
6351 if (LI.BreakLabel) {
6352 TargetLabel = *LI.BreakLabel;
6353 BreakScope = LI.BreakOrContinueScope;
6359 if (LI.Name == TargetLoop) {
6360 TargetLabel = *LI.BreakLabel;
6361 BreakScope = LI.BreakOrContinueScope;
6372 C =
C->getParent()) {
6373 if (!
C->destroyLocals())
6377 return this->jump(*TargetLabel, S);
6380template <
class Emitter>
6391 if (LI.ContinueLabel) {
6392 TargetLabel = *LI.ContinueLabel;
6393 ContinueScope = LI.BreakOrContinueScope;
6399 if (LI.Name == TargetLoop) {
6400 TargetLabel = *LI.ContinueLabel;
6401 ContinueScope = LI.BreakOrContinueScope;
6406 assert(TargetLabel);
6409 C =
C->getParent()) {
6410 if (!
C->destroyLocals())
6414 return this->jump(*TargetLabel, S);
6417template <
class Emitter>
6420 if (
Cond->containsErrors())
6426 LabelTy EndLabel = this->getLabel();
6431 if (
const auto *CondInit = S->
getInit())
6442 if (!this->emitSetLocal(CondT, CondVar, S))
6452 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6455 if (CS->caseStmtIsGNURange()) {
6456 LabelTy EndOfRangeCheck = this->getLabel();
6457 const Expr *Low = CS->getLHS();
6458 const Expr *High = CS->getRHS();
6462 if (!this->emitGetLocal(CondT, CondVar, CS))
6464 if (!this->
visit(Low))
6467 if (!this->emitGE(
LT, S))
6469 if (!this->jumpFalse(EndOfRangeCheck, S))
6472 if (!this->emitGetLocal(CondT, CondVar, CS))
6474 if (!this->
visit(High))
6477 if (!this->emitLE(HT, S))
6481 this->emitLabel(EndOfRangeCheck);
6486 if (
Value->isValueDependent())
6491 if (!this->emitGetLocal(CondT, CondVar, CS))
6497 if (!this->emitEQ(ValueT, S))
6502 assert(!DefaultLabel);
6503 DefaultLabel = this->getLabel();
6510 if (!this->jump(*DefaultLabel, S))
6513 if (!this->jump(EndLabel, S))
6521 this->fallthrough(EndLabel);
6522 this->emitLabel(EndLabel);
6527template <
class Emitter>
6534template <
class Emitter>
6541 if (LI.DefaultLabel) {
6542 DefaultLabel = *LI.DefaultLabel;
6547 this->emitLabel(DefaultLabel);
6551template <
class Emitter>
6558 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6561 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6562 !this->Ctx.getLangOpts().MSVCCompat) {
6564 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6570 const Expr *Assumption = AA->getAssumption();
6581 if (!this->emitAssume(Assumption))
6590 if (IsMSVCConstexprAttr)
6591 return this->emitPopMSVCCE(S);
6595template <
class Emitter>
6601template <
class Emitter>
6602bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6609 assert(ClosureClass->
captures().empty());
6613 "A generic lambda's static-invoker function must be a "
6614 "template specialization");
6618 void *InsertPos =
nullptr;
6619 const FunctionDecl *CorrespondingCallOpSpecialization =
6621 assert(CorrespondingCallOpSpecialization);
6622 LambdaCallOp = CorrespondingCallOpSpecialization;
6626 assert(ClosureClass->
captures().empty());
6627 const Function *
Func = this->getFunction(LambdaCallOp);
6630 assert(
Func->hasThisPointer());
6633 if (
Func->hasRVO()) {
6634 if (!this->emitRVOPtr(MD))
6642 if (!this->emitNullPtr(0,
nullptr, MD))
6647 auto It = this->Params.find(PVD);
6648 assert(It != this->Params.end());
6652 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6653 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6657 if (!this->emitCall(
Func, 0, LambdaCallOp))
6662 return this->emitRet(*ReturnType, MD);
6665 return this->emitRetVoid(MD);
6668template <
class Emitter>
6669bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6670 if (Ctx.getLangOpts().CPlusPlus23)
6680 const Expr *InitExpr =
Init->getInit();
6682 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6686 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6696template <
class Emitter>
6698 assert(!ReturnType);
6700 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6701 const Expr *InitExpr,
6704 if (InitExpr->getType().isNull())
6708 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6711 if (!this->visit(InitExpr))
6714 if (F->isBitField())
6715 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
6717 return this->emitInitThisField(*T, FieldOffset, InitExpr);
6722 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6725 if (
Activate && !this->emitActivate(InitExpr))
6728 if (!this->visitInitializer(InitExpr))
6731 return this->emitFinishInitPop(InitExpr);
6735 const Record *
R = this->getRecord(RD);
6738 bool IsUnion =
R->isUnion();
6743 if (
R->getNumFields() == 0)
6744 return this->emitRetVoid(Ctor);
6747 if (!this->emitThis(Ctor))
6750 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
6753 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6754 this->emitRetVoid(Ctor);
6758 for (
const auto *
Init : Ctor->
inits()) {
6762 const Expr *InitExpr =
Init->getInit();
6764 const Record::Field *F =
R->getField(
Member);
6768 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6771 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6774 if (
Init->isBaseVirtual()) {
6775 assert(
R->getVirtualBase(BaseDecl));
6776 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6782 const Record::Base *B =
R->getBase(BaseDecl);
6784 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6788 if (IsUnion && !this->emitActivate(InitExpr))
6791 if (!this->visitInitializer(InitExpr))
6793 if (!this->emitFinishInitPop(InitExpr))
6798 assert(IFD->getChainingSize() >= 2);
6800 unsigned NestedFieldOffset = 0;
6801 const Record::Field *NestedField =
nullptr;
6802 for (
const NamedDecl *ND : IFD->chain()) {
6804 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6805 assert(FieldRecord);
6807 NestedField = FieldRecord->
getField(FD);
6808 assert(NestedField);
6809 IsUnion = IsUnion || FieldRecord->
isUnion();
6811 NestedFieldOffset += NestedField->Offset;
6813 assert(NestedField);
6815 unsigned FirstLinkOffset =
6819 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6824 unsigned InitFieldOffset = 0;
6825 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6827 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6828 assert(FieldRecord);
6829 NestedField = FieldRecord->
getField(FD);
6830 InitFieldOffset += NestedField->Offset;
6831 assert(NestedField);
6832 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6834 if (!this->emitFinishInitPop(InitExpr))
6839 assert(
Init->isDelegatingInitializer());
6840 if (!this->emitThis(InitExpr))
6842 if (!this->visitInitializer(
Init->getInit()))
6844 if (!this->emitPopPtr(InitExpr))
6848 if (!
Scope.destroyLocals())
6855 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
6856 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
6863 if (!visitStmt(Body))
6870template <
class Emitter>
6873 const Record *
R = this->getRecord(RD);
6878 if (!this->visitStmt(Dtor->
getBody()))
6882 if (!this->emitThis(Dtor))
6885 if (!this->emitCheckDestruction(Dtor))
6889 if (!
R->isUnion()) {
6893 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
6897 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6899 if (!this->emitDestructionPop(D,
SourceInfo{}))
6904 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
6905 if (
Base.R->hasTrivialDtor())
6909 if (!this->emitRecordDestructionPop(
Base.R, {}))
6914 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6917template <
class Emitter>
6918bool Compiler<Emitter>::compileUnionAssignmentOperator(
6920 if (!this->emitThis(MD))
6923 if (!this->emitGetParam(
PT_Ptr, 0, MD))
6926 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6929template <
class Emitter>
6936 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6937 return this->compileConstructor(Ctor);
6938 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6939 return this->compileDestructor(Dtor);
6942 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6947 return this->compileUnionAssignmentOperator(MD);
6950 return this->emitLambdaStaticInvokerBody(MD);
6954 if (
const auto *Body = F->
getBody())
6968 return FD->getBitWidthValue();
6971template <
class Emitter>
6984 if (!
Ctx.getLangOpts().CPlusPlus14)
6985 return this->emitInvalid(E);
6987 return this->emitError(E);
6989 if (!this->
visit(SubExpr))
6993 if (!this->emitIncPtr(E))
7000 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7001 : this->emitIncf(getFPOptions(E), E);
7013 if (!
Ctx.getLangOpts().CPlusPlus14)
7014 return this->emitInvalid(E);
7016 return this->emitError(E);
7018 if (!this->
visit(SubExpr))
7022 if (!this->emitDecPtr(E))
7029 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7030 : this->emitDecf(getFPOptions(E), E);
7043 if (!
Ctx.getLangOpts().CPlusPlus14)
7044 return this->emitInvalid(E);
7046 return this->emitError(E);
7048 if (!this->
visit(SubExpr))
7052 if (!this->emitLoadPtr(E))
7054 if (!this->emitConstUint8(1, E))
7056 if (!this->emitAddOffsetUint8(E))
7058 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7064 return this->emitIncfPop(getFPOptions(E), E);
7074 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7075 if (!this->emitLoadFloat(E))
7077 APFloat F(TargetSemantics, 1);
7078 if (!this->emitFloat(F, E))
7081 if (!this->emitAddf(getFPOptions(E), E))
7083 if (!this->emitStoreFloat(E))
7095 return E->
isGLValue() || this->emitLoadPop(*T, E);
7098 if (!
Ctx.getLangOpts().CPlusPlus14)
7099 return this->emitInvalid(E);
7101 return this->emitError(E);
7103 if (!this->
visit(SubExpr))
7107 if (!this->emitLoadPtr(E))
7109 if (!this->emitConstUint8(1, E))
7111 if (!this->emitSubOffsetUint8(E))
7113 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7119 return this->emitDecfPop(getFPOptions(E), E);
7129 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7130 if (!this->emitLoadFloat(E))
7132 APFloat F(TargetSemantics, 1);
7133 if (!this->emitFloat(F, E))
7136 if (!this->emitSubf(getFPOptions(E), E))
7138 if (!this->emitStoreFloat(E))
7150 return E->
isGLValue() || this->emitLoadPop(*T, E);
7154 return this->emitError(E);
7157 return this->
discard(SubExpr);
7162 if (!this->emitInv(E))
7166 return this->emitCast(
PT_Bool, ET, E);
7170 return this->emitError(E);
7172 if (!this->
visit(SubExpr))
7174 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7177 return this->emitError(E);
7179 if (!this->
visit(SubExpr))
7194 return this->
discard(SubExpr);
7196 if (!this->
visit(SubExpr))
7203 return this->emitNarrowPtr(E);
7208 return this->emitError(E);
7210 if (!this->
visit(SubExpr))
7212 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7224 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7229 assert(
false &&
"Unhandled opcode");
7235template <
class Emitter>
7241 return this->
discard(SubExpr);
7244 auto prepareResult = [=]() ->
bool {
7249 return this->emitGetPtrLocal(*LocalIndex, E);
7256 unsigned SubExprOffset = ~0u;
7257 auto createTemp = [=, &SubExprOffset]() ->
bool {
7260 if (!this->
visit(SubExpr))
7262 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7266 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7267 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7269 return this->emitArrayElemPop(ElemT, Index, E);
7274 if (!prepareResult())
7278 for (
unsigned I = 0; I != 2; ++I) {
7279 if (!getElem(SubExprOffset, I))
7281 if (!this->emitNeg(ElemT, E))
7283 if (!this->emitInitElem(ElemT, I, E))
7294 if (!this->
visit(SubExpr))
7296 if (!this->emitComplexBoolCast(SubExpr))
7298 if (!this->emitInv(E))
7301 return this->emitCast(
PT_Bool, ET, E);
7305 return this->emitComplexReal(SubExpr);
7308 if (!this->
visit(SubExpr))
7312 if (!this->emitConstUint8(1, E))
7314 return this->emitArrayElemPtrPopUint8(E);
7325 if (!this->emitArrayElem(ElemT, 1, E))
7327 if (!this->emitNeg(ElemT, E))
7329 if (!this->emitInitElem(ElemT, 1, E))
7337 return this->emitInvalid(E);
7343template <
class Emitter>
7349 return this->
discard(SubExpr);
7352 if (UnaryOp == UO_Extension)
7355 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7356 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7357 return this->emitInvalid(E);
7360 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7367 if (!this->emitGetPtrLocal(*LocalIndex, E))
7372 unsigned SubExprOffset =
7374 if (!this->
visit(SubExpr))
7376 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7381 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7382 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7384 return this->emitArrayElemPop(ElemT, Index, E);
7389 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7390 if (!getElem(SubExprOffset, I))
7392 if (!this->emitNeg(ElemT, E))
7394 if (!this->emitInitElem(ElemT, I, E))
7409 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7410 if (!getElem(SubExprOffset, I))
7413 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7415 if (!this->emitInv(E))
7417 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7419 if (!this->emitNeg(ElemT, E))
7421 if (ElemT != ResultVecElemT &&
7422 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7424 if (!this->emitInitElem(ResultVecElemT, I, E))
7430 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7431 if (!getElem(SubExprOffset, I))
7434 if (!this->emitInv(E))
7437 if (!this->emitComp(ElemT, E))
7440 if (!this->emitInitElem(ElemT, I, E))
7445 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7450template <
class Emitter>
7455 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7456 return this->emitConst(ECD->getInitVal(), E);
7457 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7459 return F && this->emitGetFnPtr(F, E);
7461 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7463 if (!this->emitGetPtrGlobal(*Index, E))
7468 return this->emitInitGlobal(*T, *Index, E);
7472 return this->emitFinishInit(E);
7487 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7488 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7493 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7494 if (IsReference || !It->second.IsPtr)
7495 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7497 return this->emitGetPtrParam(It->second.Index, E);
7500 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7506 const unsigned Offset = It->second.Offset;
7509 return this->emitGetRefLocal(Offset, E);
7511 return this->emitGetPtrLocal(Offset, E);
7514 if (
auto GlobalIndex =
P.getGlobal(D)) {
7516 if (!
Ctx.getLangOpts().CPlusPlus11)
7517 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7518 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7521 return this->emitGetPtrGlobal(*GlobalIndex, E);
7525 auto revisit = [&](
const VarDecl *VD,
7526 bool IsConstexprUnknown =
true) ->
bool {
7528 IsConstexprUnknown);
7533 if (!this->emitPopCC(E))
7536 if (VarState.notCreated())
7544 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7546 if (
auto It = this->LambdaCaptures.find(D);
7547 It != this->LambdaCaptures.end()) {
7548 auto [Offset, IsPtr] = It->second;
7551 return this->emitGetThisFieldPtr(Offset, E);
7552 return this->emitGetPtrThisField(Offset, E);
7556 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7557 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7558 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7562 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7563 return this->
visit(BD->getBinding());
7567 return this->emitDummyPtr(D, E);
7571 const auto *VD = dyn_cast<VarDecl>(D);
7573 return this->emitError(E);
7576 if (!
Ctx.getLangOpts().CPlusPlus) {
7579 return revisit(VD,
false);
7580 return this->emitDummyPtr(D, E);
7584 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7585 if (T.isConstant(
Ctx.getASTContext()))
7587 return T->isReferenceType();
7591 typeShouldBeVisited(DeclType)) {
7593 Init && !
Init->isValueDependent()) {
7599 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7613 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7618 return revisit(VD, IsConstexprUnknown);
7619 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7620 return revisit(VD,
true);
7627 return this->emitDummyPtr(D, E);
7630template <
class Emitter>
7638 if (!
C->destroyLocals())
7644template <
class Emitter>
7645unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7648 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7650 return Ty->getAsCXXRecordDecl();
7652 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7653 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7655 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7659template <
class Emitter>
7666 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7671 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7672 getFPOptions(E), E);
7674 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7675 getFPOptions(E), E);
7679 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7684 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7686 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7690 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7694 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7695 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7702template <
class Emitter>
7705 assert(FromT != ToT);
7708 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7710 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7712 return this->emitCast(FromT, ToT, E);
7716template <
class Emitter>
7717bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7721 return this->
discard(SubExpr);
7723 if (!this->visit(SubExpr))
7726 if (!this->emitConstUint8(0, SubExpr))
7728 return this->emitArrayElemPtrPopUint8(SubExpr);
7732 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7736template <
class Emitter>
7737bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7738 assert(!DiscardResult);
7742 if (!this->emitArrayElem(ElemT, 0, E))
7745 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7748 if (!this->emitCast(ElemT,
PT_Bool, E))
7753 LabelTy LabelTrue = this->getLabel();
7754 if (!this->jumpTrue(LabelTrue, E))
7757 if (!this->emitArrayElemPop(ElemT, 1, E))
7760 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7763 if (!this->emitCast(ElemT,
PT_Bool, E))
7767 LabelTy EndLabel = this->getLabel();
7768 this->jump(EndLabel, E);
7770 this->emitLabel(LabelTrue);
7771 if (!this->emitPopPtr(E))
7773 if (!this->emitConstBool(
true, E))
7776 this->fallthrough(EndLabel);
7777 this->emitLabel(EndLabel);
7782template <
class Emitter>
7783bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7794 LHSIsComplex =
true;
7795 ElemT = classifyComplexElementType(LHS->
getType());
7796 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7797 if (!this->visit(LHS))
7799 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7802 LHSIsComplex =
false;
7804 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7805 if (!this->visit(LHS))
7807 if (!this->emitSetLocal(LHST, LHSOffset, E))
7814 RHSIsComplex =
true;
7815 ElemT = classifyComplexElementType(RHS->
getType());
7816 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7817 if (!this->visit(RHS))
7819 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7822 RHSIsComplex =
false;
7824 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7825 if (!this->visit(RHS))
7827 if (!this->emitSetLocal(RHST, RHSOffset, E))
7831 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7832 bool IsComplex) ->
bool {
7834 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7836 return this->emitArrayElemPop(ElemT, Index, E);
7838 return this->emitGetLocal(ElemT, LocalOffset, E);
7841 for (
unsigned I = 0; I != 2; ++I) {
7843 if (!getElem(LHSOffset, I, LHSIsComplex))
7845 if (!getElem(RHSOffset, I, RHSIsComplex))
7848 if (!this->emitEQ(ElemT, E))
7851 if (!this->emitCastBoolUint8(E))
7856 if (!this->emitAddUint8(E))
7858 if (!this->emitConstUint8(2, E))
7862 if (!this->emitEQUint8(E))
7865 if (!this->emitNEUint8(E))
7872 return this->emitCast(
PT_Bool, ResT, E);
7879template <
class Emitter>
7880bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7883 assert(!
R->hasTrivialDtor());
7886 const Function *DtorFunc = getFunction(Dtor);
7889 assert(DtorFunc->hasThisPointer());
7890 assert(DtorFunc->getNumParams() == 1);
7891 return this->emitCall(DtorFunc, 0, Loc);
7896template <
class Emitter>
7897bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7909 return this->emitPopPtr(Loc);
7911 for (ssize_t I = N - 1; I >= 1; --I) {
7912 if (!this->emitConstUint64(I, Loc))
7914 if (!this->emitArrayElemPtrUint64(Loc))
7916 if (!this->emitDestructionPop(ElemDesc, Loc))
7920 if (!this->emitConstUint64(0, Loc))
7922 if (!this->emitArrayElemPtrPopUint64(Loc))
7924 return this->emitDestructionPop(ElemDesc, Loc);
7929 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7934template <
class Emitter>
7935bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7936 assert(!DiscardResult &&
"Should've been checked before");
7937 unsigned DummyID = P.getOrCreateDummy(D);
7939 if (!this->emitGetPtrGlobal(DummyID, E))
7947 return this->emitDecayPtr(
PT_Ptr, PT, E);
7953template <
class Emitter>
7954bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7956 return this->emitConstFloat(
Floating(F), E);
7958 APInt I = F.bitcastToAPInt();
7959 return this->emitConstFloat(
7960 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7961 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7972template <
class Emitter>
7973bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7986 if (!this->emitGetPtrLocal(*LocalIndex, E))
7996 if (!this->visit(SubExpr))
7998 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7999 unsigned TempOffset =
8000 allocateLocalPrimitive(SubExpr, *FromT,
true);
8001 if (!this->visit(SubExpr))
8003 if (!this->emitSetLocal(*FromT, TempOffset, E))
8005 if (!this->emitGetPtrLocal(TempOffset, E))
8012 if (!this->emitBitCast(E))
8014 return DiscardResult ? this->emitPopPtr(E) :
true;
8018 const llvm::fltSemantics *TargetSemantics =
nullptr;
8020 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8026 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8028 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8029 ResultBitWidth, TargetSemantics,
8034 return this->emitPop(*ToT, E);
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
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 ...
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
DoStmt - This represents a 'do/while' stmt.
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits()
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
uint32_t getCodeUnit(size_t i) const
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool visitAPValueInitializer(const APValue &Val, const Expr *E, QualType T)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E)
Visit an APValue.
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
const ValueDecl * InitializingDecl
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const ValueDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
Describes the statement/declaration an opcode was generated from.
StmtExprScope(Compiler< Emitter > *Ctx)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
Compiler< Emitter > * Ctx
Compiler instance.
virtual void addLocal(Scope::Local Local)
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
static bool Activate(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool InitScope(InterpState &S, CodePtr OpPC, uint32_t I)
constexpr bool isIntegerOrBoolType(PrimType T)
static void discard(InterpStack &Stk, PrimType T)
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
bool Init(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
U cast(CodeGen::Address addr)
int const char * function
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
static constexpr MetadataSize InlineDescMD
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
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()