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, CE);
239 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
240 return this->emitGetLocal(*SubExprT, It->second.Offset, CE);
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.Offset, CE);
255 if (!this->emitGetPtrLocal(*LocalIndex, CE))
259 if (!this->
visit(SubExpr))
263 return this->emitLoadPop(*SubExprT, CE);
268 return this->emitMemcpy(CE);
271 case CK_DerivedToBaseMemberPointer: {
277 unsigned DerivedOffset =
279 FromMP->getMostRecentCXXRecordDecl());
284 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
287 case CK_BaseToDerivedMemberPointer: {
293 unsigned DerivedOffset =
294 Ctx.collectBaseOffset(FromMP->getMostRecentCXXRecordDecl(),
299 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
302 case CK_UncheckedDerivedToBase:
303 case CK_DerivedToBase: {
308 if (
const auto *PT = dyn_cast<PointerType>(Ty))
309 return PT->getPointeeType()->getAsCXXRecordDecl();
310 return Ty->getAsCXXRecordDecl();
317 if (B->isVirtual()) {
318 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), CE))
320 CurType = B->getType();
322 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
323 if (!this->emitGetPtrBasePop(
326 CurType = B->getType();
333 case CK_BaseToDerived: {
336 unsigned DerivedOffset =
342 return this->emitGetPtrDerivedPop(DerivedOffset,
347 case CK_FloatingCast: {
352 if (!this->
visit(SubExpr))
354 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
358 case CK_IntegralToFloating: {
361 if (!this->
visit(SubExpr))
363 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
364 return this->emitCastIntegralFloating(
365 classifyPrim(SubExpr), TargetSemantics, getFPOptions(CE), CE);
368 case CK_FloatingToBoolean: {
372 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
373 return this->emitConstBool(FL->getValue().isNonZero(), CE);
374 if (!this->
visit(SubExpr))
376 return this->emitCastFloatingIntegralBool(getFPOptions(CE), CE);
379 case CK_FloatingToIntegral: {
382 if (!this->
visit(SubExpr))
386 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(CE->
getType()),
387 getFPOptions(CE), CE);
389 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
390 getFPOptions(CE), CE);
392 return this->emitCastFloatingIntegral(ToT, getFPOptions(CE), CE);
395 case CK_NullToPointer:
396 case CK_NullToMemberPointer: {
401 if (!PointeeType.
isNull()) {
403 Desc =
P.createDescriptor(SubExpr, *
T);
405 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
409 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(CE->
getType());
413 case CK_PointerToIntegral: {
414 if (!this->
visit(SubExpr))
420 if (!this->emitDecayPtr(FromT,
PT_Ptr, CE))
426 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(CE->
getType()),
429 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
431 return this->emitCastPointerIntegral(
T, CE);
434 case CK_ArrayToPointerDecay: {
435 if (!this->
visit(SubExpr))
437 return this->emitArrayDecay(CE);
440 case CK_IntegralToPointer: {
442 assert(IntType->isIntegralOrEnumerationType());
443 if (!this->
visit(SubExpr))
451 Desc =
P.createDescriptor(SubExpr, *
T);
458 if (!this->emitGetIntPtr(
T, Desc, CE))
466 return this->emitDecayPtr(
PT_Ptr, DestPtrT, CE);
469 case CK_AtomicToNonAtomic:
470 case CK_ConstructorConversion:
471 case CK_FunctionToPointerDecay:
472 case CK_NonAtomicToAtomic:
474 case CK_UserDefinedConversion:
475 case CK_AddressSpaceConversion:
476 case CK_CPointerToObjCPointerCast:
493 return this->emitBuiltinBitCast(CE);
508 if (!this->
visit(SubExpr))
516 return this->emitFnPtrCast(CE);
523 if (!this->
visit(SubExpr))
525 return this->emitDecayPtr(*FromT, *ToT, CE);
527 case CK_IntegralToBoolean:
528 case CK_FixedPointToBoolean: {
534 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
535 return this->emitConst(IL->getValue(), CE);
536 if (!this->
visit(SubExpr))
541 case CK_BooleanToSignedIntegral:
542 case CK_IntegralCast: {
549 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
554 if (!this->emitConst(IL->getValue(), SubExpr))
557 if (!this->
visit(SubExpr))
565 if (!ED->isFixed()) {
566 if (!this->emitCheckEnumValue(*FromT, ED, CE))
572 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
575 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
580 if (!this->emitCast(*FromT, *ToT, CE))
583 if (CE->
getCastKind() == CK_BooleanToSignedIntegral)
584 return this->emitNeg(*ToT, CE);
588 case CK_PointerToBoolean:
589 case CK_MemberPointerToBoolean: {
592 if (!this->
visit(SubExpr))
594 return this->emitIsNonNull(PtrT, CE);
597 case CK_IntegralComplexToBoolean:
598 case CK_FloatingComplexToBoolean: {
599 if (!this->
visit(SubExpr))
601 return this->emitComplexBoolCast(SubExpr);
604 case CK_IntegralComplexToReal:
605 case CK_FloatingComplexToReal:
606 return this->emitComplexReal(SubExpr);
608 case CK_IntegralRealToComplex:
609 case CK_FloatingRealToComplex: {
616 if (!this->emitGetPtrLocal(*LocalIndex, CE))
625 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
627 return this->emitInitElem(
T, 1, SubExpr);
630 case CK_IntegralComplexCast:
631 case CK_FloatingComplexCast:
632 case CK_IntegralComplexToFloatingComplex:
633 case CK_FloatingComplexToIntegralComplex: {
640 if (!this->emitGetPtrLocal(*LocalIndex, CE))
647 unsigned SubExprOffset =
649 if (!this->
visit(SubExpr))
651 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, CE))
659 for (
unsigned I = 0; I != 2; ++I) {
660 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, CE))
662 if (!this->emitArrayElemPop(SourceElemT, I, CE))
666 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, CE))
670 if (!this->emitInitElem(DestElemT, I, CE))
676 case CK_VectorSplat: {
685 if (!this->emitGetPtrLocal(*LocalIndex, CE))
691 unsigned ElemOffset =
695 if (!this->
visit(SubExpr))
700 if (!this->emitSetLocal(ElemT, ElemOffset, CE))
703 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
704 if (!this->emitGetLocal(ElemT, ElemOffset, CE))
706 if (!this->emitInitElem(ElemT, I, CE))
713 case CK_HLSLVectorTruncation: {
718 if (!this->
visit(SubExpr))
720 return this->emitArrayElemPop(*ResultT, 0, CE);
729 if (!this->emitGetPtrLocal(*LocalIndex, CE))
734 if (!this->
visit(SubExpr))
736 return this->emitCopyArray(classifyVectorElementType(CE->
getType()), 0, 0,
740 case CK_IntegralToFixedPoint: {
741 if (!this->
visit(SubExpr))
745 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
749 case CK_FloatingToFixedPoint: {
750 if (!this->
visit(SubExpr))
754 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
755 return this->emitCastFloatingFixedPoint(Sem, CE);
757 case CK_FixedPointToFloating: {
758 if (!this->
visit(SubExpr))
760 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
761 return this->emitCastFixedPointFloating(TargetSemantics, CE);
763 case CK_FixedPointToIntegral: {
764 if (!this->
visit(SubExpr))
768 case CK_FixedPointCast: {
769 if (!this->
visit(SubExpr))
772 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
773 return this->emitCastFixedPoint(Sem, CE);
784 case CK_LValueBitCast:
788 return this->emitInvalid(CE);
790 llvm_unreachable(
"Unhandled clang::CastKind enum");
793template <
class Emitter>
795 return this->emitBuiltinBitCast(E);
798template <
class Emitter>
803 return this->emitConst(
LE->getValue(),
LE);
806template <
class Emitter>
812 return this->emitFloat(F, E);
815template <
class Emitter>
825 if (!this->emitGetPtrLocal(*LocalIndex, E))
832 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
834 if (!this->emitInitElem(SubExprT, 0, SubExpr))
839template <
class Emitter>
847 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
852template <
class Emitter>
857template <
class Emitter>
884 return this->emitComplexComparison(LHS, RHS, BO);
889 if (!this->
visit(LHS))
892 if (!this->
visit(RHS))
895 if (!this->emitToMemberPtr(BO))
901 if (!this->emitCastMemberPtrPtr(BO))
918 Ctx.getASTContext().CompCategories.lookupInfoForType(BO->
getType());
924 if (!this->emitGetPtrLocal(*ResultIndex, BO))
931 return this->emitCMP3(*
LT, CmpInfo, BO);
934 if (!
LT || !RT || !
T)
944 return this->visitAssignment(LHS, RHS, BO);
951 auto MaybeCastToBool = [
this,
T, BO](
bool Result) {
955 return this->emitPopBool(BO);
957 return this->emitCast(
PT_Bool, *
T, BO);
961 auto Discard = [
this,
T, BO](
bool Result) {
969 return MaybeCastToBool(this->emitEQ(*
LT, BO));
971 return MaybeCastToBool(this->emitNE(*
LT, BO));
973 return MaybeCastToBool(this->emitLT(*
LT, BO));
975 return MaybeCastToBool(this->emitLE(*
LT, BO));
977 return MaybeCastToBool(this->emitGT(*
LT, BO));
979 return MaybeCastToBool(this->emitGE(*
LT, BO));
982 return Discard(this->emitSubf(getFPOptions(BO), BO));
983 return Discard(this->emitSub(*
T, BO));
986 return Discard(this->emitAddf(getFPOptions(BO), BO));
987 return Discard(this->emitAdd(*
T, BO));
990 return Discard(this->emitMulf(getFPOptions(BO), BO));
991 return Discard(this->emitMul(*
T, BO));
993 return Discard(this->emitRem(*
T, BO));
996 return Discard(this->emitDivf(getFPOptions(BO), BO));
997 return Discard(this->emitDiv(*
T, BO));
999 return Discard(this->emitBitAnd(*
T, BO));
1001 return Discard(this->emitBitOr(*
T, BO));
1003 return Discard(this->emitShl(*
LT, *RT, BO));
1005 return Discard(this->emitShr(*
LT, *RT, BO));
1007 return Discard(this->emitBitXor(*
T, BO));
1010 llvm_unreachable(
"Already handled earlier");
1015 llvm_unreachable(
"Unhandled binary op");
1020template <
class Emitter>
1026 if ((Op != BO_Add && Op != BO_Sub) ||
1037 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1038 if (!this->
visit(E))
1041 return this->emitDecayPtr(
T,
PT_Ptr, E);
1050 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1058 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1061 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1068 if (!visitAsPointer(RHS, *RT))
1070 if (!this->
visit(LHS))
1074 if (!visitAsPointer(LHS, *
LT))
1076 if (!this->
visit(RHS))
1086 if (!this->emitAddOffset(OffsetType, E))
1094 if (!this->emitSubOffset(OffsetType, E))
1105template <
class Emitter>
1115 LabelTy LabelTrue = this->getLabel();
1116 LabelTy LabelEnd = this->getLabel();
1120 if (!this->jumpTrue(LabelTrue))
1125 if (!this->jump(LabelEnd))
1128 this->emitLabel(LabelTrue);
1129 this->emitConstBool(
true, E);
1130 this->fallthrough(LabelEnd);
1131 this->emitLabel(LabelEnd);
1134 assert(Op == BO_LAnd);
1137 LabelTy LabelFalse = this->getLabel();
1138 LabelTy LabelEnd = this->getLabel();
1142 if (!this->jumpFalse(LabelFalse))
1147 if (!this->jump(LabelEnd))
1150 this->emitLabel(LabelFalse);
1151 this->emitConstBool(
false, E);
1152 this->fallthrough(LabelEnd);
1153 this->emitLabel(LabelEnd);
1157 return this->emitPopBool(E);
1162 return this->emitCast(
PT_Bool, *
T, E);
1166template <
class Emitter>
1173 if (!this->emitGetPtrLocal(*LocalIndex, E))
1182 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1183 unsigned ResultOffset = ~0u;
1189 if (!this->emitDupPtr(E))
1191 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1196 LHSType = AT->getValueType();
1199 RHSType = AT->getValueType();
1208 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1213 if (!this->
visit(LHS))
1215 if (!this->
visit(RHS))
1217 return this->emitMulc(ElemT, E);
1220 if (Op == BO_Div && RHSIsComplex) {
1227 if (!LHSIsComplex) {
1232 LHSOffset = *LocalIndex;
1234 if (!this->emitGetPtrLocal(LHSOffset, E))
1237 if (!this->
visit(LHS))
1240 if (!this->emitInitElem(ElemT, 0, E))
1243 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1245 if (!this->emitInitElem(ElemT, 1, E))
1248 if (!this->
visit(LHS))
1252 if (!this->
visit(RHS))
1254 return this->emitDivc(ElemT, E);
1260 if (!this->
visit(LHS))
1262 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1267 if (!this->
visit(LHS))
1269 if (!this->emitSetLocal(LHST, LHSOffset, E))
1277 if (!this->
visit(RHS))
1279 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1284 if (!this->
visit(RHS))
1286 if (!this->emitSetLocal(RHST, RHSOffset, E))
1293 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1294 unsigned ElemIndex,
unsigned Offset,
1295 const Expr *E) ->
bool {
1297 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1299 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1302 if (ElemIndex == 0 || !LoadZero)
1309 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1312 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1319 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1322 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1325 if (!this->emitAddf(getFPOptions(E), E))
1328 if (!this->emitAdd(ResultElemT, E))
1333 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1336 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1339 if (!this->emitSubf(getFPOptions(E), E))
1342 if (!this->emitSub(ResultElemT, E))
1347 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1350 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1354 if (!this->emitMulf(getFPOptions(E), E))
1357 if (!this->emitMul(ResultElemT, E))
1362 assert(!RHSIsComplex);
1363 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1366 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1370 if (!this->emitDivf(getFPOptions(E), E))
1373 if (!this->emitDiv(ResultElemT, E))
1384 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1387 if (!this->emitPop(ResultElemT, E))
1392 return this->emitPopPtr(E);
1398template <
class Emitter>
1403 "Comma op should be handled in VisitBinaryOperator");
1417 if (!this->emitGetPtrLocal(*LocalIndex, E))
1431 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1434 if (!this->
visit(LHS))
1436 if (!this->
visit(RHS))
1438 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1441 return this->emitPopPtr(E);
1446 unsigned LHSOffset =
1448 if (!this->
visit(LHS))
1450 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1454 unsigned RHSOffset =
1456 if (!this->
visit(RHS))
1458 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1470 if (NeedIntPromot) {
1472 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1477 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1478 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1480 if (!this->emitArrayElemPop(ElemT, Index, E))
1483 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1485 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1487 }
else if (NeedIntPromot) {
1488 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1494#define EMIT_ARITH_OP(OP) \
1496 if (ElemT == PT_Float) { \
1497 if (!this->emit##OP##f(getFPOptions(E), E)) \
1500 if (!this->emit##OP(ElemT, E)) \
1506 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1507 if (!getElem(LHSOffset, ElemT, I))
1509 if (!getElem(RHSOffset, RHSElemT, I))
1521 if (!this->emitRem(ElemT, E))
1525 if (!this->emitBitAnd(OpT, E))
1529 if (!this->emitBitOr(OpT, E))
1533 if (!this->emitBitXor(OpT, E))
1537 if (!this->emitShl(OpT, RHSElemT, E))
1541 if (!this->emitShr(OpT, RHSElemT, E))
1545 if (!this->emitEQ(ElemT, E))
1549 if (!this->emitNE(ElemT, E))
1553 if (!this->emitLE(ElemT, E))
1557 if (!this->emitLT(ElemT, E))
1561 if (!this->emitGE(ElemT, E))
1565 if (!this->emitGT(ElemT, E))
1570 if (!this->emitBitAnd(ResultElemT, E))
1575 if (!this->emitBitOr(ResultElemT, E))
1579 return this->emitInvalid(E);
1588 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1590 if (!this->emitNeg(ResultElemT, E))
1596 if (NeedIntPromot &&
1597 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1601 if (!this->emitInitElem(ResultElemT, I, E))
1610template <
class Emitter>
1620 auto LHSSemaInt = LHSSema.toOpaqueInt();
1622 auto RHSSemaInt = RHSSema.toOpaqueInt();
1624 if (!this->
visit(LHS))
1632 if (!this->
visit(RHS))
1641 auto ConvertResult = [&](
bool R) ->
bool {
1645 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1646 if (ResultSema != CommonSema)
1647 return this->emitCastFixedPoint(ResultSema, E);
1651 auto MaybeCastToBool = [&](
bool Result) {
1656 return this->emitPop(
T, E);
1658 return this->emitCast(
PT_Bool,
T, E);
1664 return MaybeCastToBool(this->emitEQFixedPoint(E));
1666 return MaybeCastToBool(this->emitNEFixedPoint(E));
1668 return MaybeCastToBool(this->emitLTFixedPoint(E));
1670 return MaybeCastToBool(this->emitLEFixedPoint(E));
1672 return MaybeCastToBool(this->emitGTFixedPoint(E));
1674 return MaybeCastToBool(this->emitGEFixedPoint(E));
1676 return ConvertResult(this->emitAddFixedPoint(E));
1678 return ConvertResult(this->emitSubFixedPoint(E));
1680 return ConvertResult(this->emitMulFixedPoint(E));
1682 return ConvertResult(this->emitDivFixedPoint(E));
1684 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1686 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1689 return this->emitInvalid(E);
1692 llvm_unreachable(
"unhandled binop opcode");
1695template <
class Emitter>
1704 if (!this->
visit(SubExpr))
1706 return this->emitNegFixedPoint(E);
1711 llvm_unreachable(
"Unhandled unary opcode");
1714template <
class Emitter>
1723 return this->visitZeroInitializer(*
T, QT, E);
1731 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1732 CXXRD && CXXRD->getNumVBases() > 0) {
1742 return this->visitZeroRecordInitializer(R, E);
1749 return this->visitZeroArrayInitializer(QT, E);
1753 QualType ElemQT = ComplexTy->getElementType();
1755 for (
unsigned I = 0; I < 2; ++I) {
1756 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1758 if (!this->emitInitElem(ElemT, I, E))
1765 unsigned NumVecElements = VecT->getNumElements();
1766 QualType ElemQT = VecT->getElementType();
1769 for (
unsigned I = 0; I < NumVecElements; ++I) {
1770 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1772 if (!this->emitInitElem(ElemT, I, E))
1781template <
class Emitter>
1791 for (
const Expr *SubExpr : {LHS, RHS}) {
1792 if (!this->
visit(SubExpr)) {
1799 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
1800 if (!this->emitExpandPtr(E))
1811 return this->emitError(E);
1814 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
1818 if (!this->emitArrayElemPtrPop(*IndexT, E))
1821 return this->emitPopPtr(E);
1827 return this->emitLoadPop(*
T, E);
1830template <
class Emitter>
1832 const Expr *ArrayFiller,
const Expr *E) {
1837 QT = AT->getValueType();
1840 if (
Inits.size() == 0)
1842 return this->emitInvalid(E);
1857 if (
Inits.size() == 0)
1858 return this->visitZeroInitializer(*
T, QT, E);
1859 assert(
Inits.size() == 1);
1872 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
1879 bool BitField = FieldToInit->isBitField();
1881 return this->emitInitBitFieldActivate(
T, FieldToInit, E);
1883 return this->emitInitBitField(
T, FieldToInit, E);
1885 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
1886 return this->emitInitField(
T, FieldToInit->Offset, E);
1889 auto initCompositeField = [=](
const Record::Field *FieldToInit,
1897 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
1900 if (
Activate && !this->emitActivate(E))
1905 return this->emitPopPtr(E);
1909 if (
Inits.size() == 0) {
1910 if (!this->visitZeroRecordInitializer(R, E))
1915 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
1916 FToInit = ILE->getInitializedFieldInUnion();
1920 const Record::Field *FieldToInit = R->
getField(FToInit);
1922 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
1925 if (!initCompositeField(FieldToInit,
Init,
true))
1929 return this->emitFinishInit(E);
1933 unsigned InitIndex = 0;
1936 while (InitIndex < R->getNumFields() &&
1941 const Record::Field *FieldToInit = R->
getField(InitIndex);
1942 if (!initPrimitiveField(FieldToInit,
Init, *
T))
1947 if (
const Record::Base *B = R->
getBase(
Init->getType())) {
1948 if (!this->emitGetPtrBase(B->Offset,
Init))
1954 if (!this->emitFinishInitPop(E))
1959 const Record::Field *FieldToInit = R->
getField(InitIndex);
1960 if (!initCompositeField(FieldToInit,
Init))
1966 return this->emitFinishInit(E);
1970 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
1974 Ctx.getASTContext().getAsConstantArrayType(QT);
1977 if (!this->emitCheckArraySize(NumElems, E))
1981 unsigned ElementIndex = 0;
1983 if (
const auto *EmbedS =
1984 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
1992 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
1993 getFPOptions(E), E))
1999 return this->emitInitElem(TargetT, ElemIndex, IL);
2001 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2013 for (; ElementIndex != NumElems; ++ElementIndex) {
2019 return this->emitFinishInit(E);
2023 unsigned NumInits =
Inits.size();
2028 QualType ElemQT = ComplexTy->getElementType();
2030 if (NumInits == 0) {
2032 for (
unsigned I = 0; I < 2; ++I) {
2033 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2035 if (!this->emitInitElem(ElemT, I, E))
2038 }
else if (NumInits == 2) {
2039 unsigned InitIndex = 0;
2044 if (!this->emitInitElem(ElemT, InitIndex, E))
2053 unsigned NumVecElements = VecT->getNumElements();
2054 assert(NumVecElements >=
Inits.size());
2056 QualType ElemQT = VecT->getElementType();
2060 unsigned InitIndex = 0;
2067 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2068 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2069 InitVecT->getNumElements(), E))
2071 InitIndex += InitVecT->getNumElements();
2073 if (!this->emitInitElem(ElemT, InitIndex, E))
2079 assert(InitIndex <= NumVecElements);
2082 for (; InitIndex != NumVecElements; ++InitIndex) {
2083 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2085 if (!this->emitInitElem(ElemT, InitIndex, E))
2096template <
class Emitter>
2103 return this->emitInitElem(*InitT, ElemIndex,
Init);
2109 if (!this->emitConstUint32(ElemIndex,
Init))
2111 if (!this->emitArrayElemPtrUint32(
Init))
2115 return this->emitFinishInitPop(
Init);
2118template <
class Emitter>
2121 bool Activate,
bool IsOperatorCall) {
2123 llvm::BitVector NonNullArgs;
2124 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2127 bool ExplicitMemberFn =
false;
2128 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2129 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2131 unsigned ArgIndex = 0;
2132 for (
const Expr *Arg : Args) {
2134 if (!this->
visit(Arg))
2142 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2143 if (DeclIndex < FuncDecl->getNumParams())
2144 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2153 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2161 if (!this->emitActivate(Arg))
2165 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2168 if (!this->emitCheckNonNullArg(ArgT, Arg))
2179template <
class Emitter>
2184template <
class Emitter>
2190template <
class Emitter>
2196template <
class Emitter>
2212template <
class Emitter>
2214 auto It = E->
begin();
2215 return this->
visit(*It);
2220 bool AlignOfReturnsPreferred =
2221 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2227 T = Ref->getPointeeType();
2229 if (
T.getQualifiers().hasUnaligned())
2235 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2241template <
class Emitter>
2247 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2253 ArgType = Ref->getPointeeType();
2259 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2260 return this->emitInvalid(E);
2262 if (Kind == UETT_SizeOf)
2271 return this->emitConst(Size.getQuantity(), E);
2274 if (Kind == UETT_CountOf) {
2280 if (
const auto *CAT =
2284 return this->emitConst(CAT->getSize(), E);
2294 if (VAT->getElementType()->isArrayType()) {
2295 std::optional<APSInt> Res =
2297 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2302 return this->emitConst(*Res, E);
2307 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2324 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2327 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2337 return this->emitConst(Size.getQuantity(), E);
2340 if (Kind == UETT_VectorElements) {
2342 return this->emitConst(VT->getNumElements(), E);
2344 return this->emitSizelessVectorElementSize(E);
2347 if (Kind == UETT_VecStep) {
2349 unsigned N = VT->getNumElements();
2356 return this->emitConst(N, E);
2358 return this->emitConst(1, E);
2361 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2368 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2370 return this->emitInvalid(E);
2372 return this->emitConst(
2373 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2381template <
class Emitter>
2392 const auto maybeLoadValue = [&]() ->
bool {
2396 return this->emitLoadPop(*
T, E);
2400 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2404 if (
auto GlobalIndex =
P.getGlobal(VD))
2405 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2410 if (!this->
discard(Base) && !this->emitSideEffect(E))
2425 const Record::Field *F = R->
getField(FD);
2427 if (F->Decl->getType()->isReferenceType())
2428 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2429 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2432template <
class Emitter>
2441template <
class Emitter>
2460 for (
size_t I = 0; I != Size; ++I) {
2472template <
class Emitter>
2483 return this->emitGetLocal(SubExprT, It->second, E);
2485 if (!this->
visit(SourceExpr))
2492 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2498 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2508template <
class Emitter>
2531 bool IsBcpCall =
false;
2532 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2533 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2537 LabelTy LabelEnd = this->getLabel();
2538 LabelTy LabelFalse = this->getLabel();
2541 if (!this->emitStartSpeculation(E))
2549 if (this->checkingForUndefinedBehavior()) {
2552 if (!this->
discard(FalseExpr))
2558 if (!this->jumpFalse(LabelFalse))
2563 if (!this->jump(LabelEnd))
2565 this->emitLabel(LabelFalse);
2569 this->fallthrough(LabelEnd);
2570 this->emitLabel(LabelEnd);
2573 return this->emitEndSpeculation(E);
2577template <
class Emitter>
2583 unsigned StringIndex =
P.createGlobalString(E);
2584 return this->emitGetPtrGlobal(StringIndex, E);
2589 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2590 assert(CAT &&
"a string literal that's not a constant array?");
2595 unsigned N = std::min(ArraySize, E->
getLength());
2598 for (
unsigned I = 0; I != N; ++I) {
2601 if (CharWidth == 1) {
2602 this->emitConstSint8(CodeUnit, E);
2603 this->emitInitElemSint8(I, E);
2604 }
else if (CharWidth == 2) {
2605 this->emitConstUint16(CodeUnit, E);
2606 this->emitInitElemUint16(I, E);
2607 }
else if (CharWidth == 4) {
2608 this->emitConstUint32(CodeUnit, E);
2609 this->emitInitElemUint32(I, E);
2611 llvm_unreachable(
"unsupported character width");
2616 for (
unsigned I = N; I != ArraySize; ++I) {
2617 if (CharWidth == 1) {
2618 this->emitConstSint8(0, E);
2619 this->emitInitElemSint8(I, E);
2620 }
else if (CharWidth == 2) {
2621 this->emitConstUint16(0, E);
2622 this->emitInitElemUint16(I, E);
2623 }
else if (CharWidth == 4) {
2624 this->emitConstUint32(0, E);
2625 this->emitInitElemUint32(I, E);
2627 llvm_unreachable(
"unsupported character width");
2634template <
class Emitter>
2638 return this->emitDummyPtr(E, E);
2641template <
class Emitter>
2643 auto &A =
Ctx.getASTContext();
2652template <
class Emitter>
2660 auto &A =
Ctx.getASTContext();
2664 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2665 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2672 unsigned StringIndex =
P.createGlobalString(SL);
2673 return this->emitGetPtrGlobal(StringIndex, E);
2676template <
class Emitter>
2680 return this->emitConst(E->
getValue(), E);
2683template <
class Emitter>
2709 if (!this->emitSetLocal(*RT, TempOffset, E))
2715 if (!this->emitLoad(LHST, E))
2719 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2720 LHSComputationType, E))
2724 if (!this->emitGetLocal(*RT, TempOffset, E))
2729 if (!this->emitAddf(getFPOptions(E), E))
2733 if (!this->emitSubf(getFPOptions(E), E))
2737 if (!this->emitMulf(getFPOptions(E), E))
2741 if (!this->emitDivf(getFPOptions(E), E))
2752 return this->emitStorePop(LHST, E);
2753 return this->emitStore(LHST, E);
2756template <
class Emitter>
2765 if (Op != BO_AddAssign && Op != BO_SubAssign)
2774 if (!this->emitLoad(*
LT, LHS))
2780 if (Op == BO_AddAssign) {
2781 if (!this->emitAddOffset(*RT, E))
2784 if (!this->emitSubOffset(*RT, E))
2789 return this->emitStorePopPtr(E);
2790 return this->emitStorePtr(E);
2793template <
class Emitter>
2806 if (!
Ctx.getLangOpts().CPlusPlus14)
2807 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2809 if (!
LT || !RT || !ResultT || !LHSComputationT)
2834 if (!this->emitSetLocal(*RT, TempOffset, E))
2841 if (!this->emitLoad(*
LT, E))
2843 if (
LT != LHSComputationT &&
2849 if (!this->emitGetLocal(*RT, TempOffset, E))
2855 if (!this->emitAdd(*LHSComputationT, E))
2859 if (!this->emitSub(*LHSComputationT, E))
2863 if (!this->emitMul(*LHSComputationT, E))
2867 if (!this->emitDiv(*LHSComputationT, E))
2871 if (!this->emitRem(*LHSComputationT, E))
2875 if (!this->emitShl(*LHSComputationT, *RT, E))
2879 if (!this->emitShr(*LHSComputationT, *RT, E))
2883 if (!this->emitBitAnd(*LHSComputationT, E))
2887 if (!this->emitBitXor(*LHSComputationT, E))
2891 if (!this->emitBitOr(*LHSComputationT, E))
2895 llvm_unreachable(
"Unimplemented compound assign operator");
2899 if (ResultT != LHSComputationT &&
2900 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
2906 return this->emitStoreBitFieldPop(*ResultT, E);
2907 return this->emitStorePop(*ResultT, E);
2910 return this->emitStoreBitField(*ResultT, E);
2911 return this->emitStore(*ResultT, E);
2914template <
class Emitter>
2922template <
class Emitter>
2934 return this->
discard(SubExpr);
2949 if (!this->
visit(SubExpr))
2951 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2953 return this->emitGetPtrGlobal(*GlobalIndex, E);
2956 if (!this->checkLiteralType(SubExpr))
2959 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2963 return this->emitInitGlobalTempComp(TempDecl, E);
2974 unsigned LocalIndex =
2976 if (!this->VarScope->LocalsAlwaysEnabled &&
2977 !this->emitEnableLocal(LocalIndex, E))
2980 if (!this->
visit(SubExpr))
2982 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2985 return this->emitGetPtrLocal(LocalIndex, E);
2988 if (!this->checkLiteralType(SubExpr))
2996 if (!this->VarScope->LocalsAlwaysEnabled &&
2997 !this->emitEnableLocal(*LocalIndex, E))
3000 if (!this->emitGetPtrLocal(*LocalIndex, E))
3007template <
class Emitter>
3018 if (!this->
visit(SubExpr))
3022 return this->emitPopPtr(E);
3026template <
class Emitter>
3047 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3052 if (
P.isGlobalInitialized(*GlobalIndex))
3058 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3070 unsigned LocalIndex;
3074 LocalIndex = *MaybeIndex;
3078 if (!this->emitGetPtrLocal(LocalIndex, E))
3082 return this->
visit(
Init) && this->emitInit(*
T, E);
3086template <
class Emitter>
3099template <
class Emitter>
3103 return this->emitConst(E->
getValue(), E);
3106template <
class Emitter>
3119 for (
const Record::Field &F : R->
fields()) {
3121 if (!
Init ||
Init->containsErrors())
3129 if (!this->emitInitField(*
T, F.Offset, E))
3132 if (!this->emitGetPtrField(F.Offset, E))
3138 if (!this->emitPopPtr(E))
3146template <
class Emitter>
3153 return this->emitGetPtrGlobal(StringIndex, E);
3159template <
class Emitter>
3164 return this->emitInvalid(E);
3167template <
class Emitter>
3193 if (PointeeToT && PointeeFromT) {
3211 bool Fatal = (ToT != FromT);
3218template <
class Emitter>
3221 if (!
Ctx.getLangOpts().CPlusPlus20) {
3229template <
class Emitter>
3235 return this->emitConstBool(E->
getValue(), E);
3238template <
class Emitter>
3243 if (
T->isRecordType()) {
3257 if (!this->emitGetPtrLocal(*LocalIndex, E))
3265 T->getAsCXXRecordDecl()))
3275 if (!this->visitZeroRecordInitializer(R, E))
3287 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3289 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3290 if (!this->emitCheckFunctionDecl(Ctor, E))
3301 assert(
Func->hasThisPointer());
3302 assert(!
Func->hasRVO());
3306 if (!this->emitDupPtr(E))
3310 for (
const auto *Arg : E->
arguments()) {
3311 if (!this->
visit(Arg))
3315 if (
Func->isVariadic()) {
3316 uint32_t VarArgSize = 0;
3317 unsigned NumParams =
Func->getNumWrittenParams();
3318 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3322 if (!this->emitCallVar(
Func, VarArgSize, E))
3325 if (!this->emitCall(
Func, 0, E)) {
3330 (void)this->emitPopPtr(E);
3336 return this->emitPopPtr(E);
3337 return this->emitFinishInit(E);
3340 if (
T->isArrayType()) {
3345 if (!this->emitDupPtr(E))
3349 initArrayDimension = [&](
QualType T) ->
bool {
3350 if (!
T->isArrayType()) {
3352 for (
const auto *Arg : E->
arguments()) {
3353 if (!this->
visit(Arg))
3357 return this->emitCall(
Func, 0, E);
3361 Ctx.getASTContext().getAsConstantArrayType(
T);
3366 for (
size_t I = 0; I != NumElems; ++I) {
3367 if (!this->emitConstUint64(I, E))
3369 if (!this->emitArrayElemPtrUint64(E))
3371 if (!initArrayDimension(ElemTy))
3374 return this->emitPopPtr(E);
3377 return initArrayDimension(E->
getType());
3383template <
class Emitter>
3393 assert(Val.
isInt());
3395 return this->emitConst(I, E);
3402 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3403 return this->
visit(LValueExpr);
3418 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3422 const APValue &
V = UGCD->getValue();
3423 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3424 const Record::Field *F = R->
getField(I);
3425 const APValue &FieldValue =
V.getStructField(I);
3431 if (!this->emitInitField(FieldT, F->Offset, E))
3439template <
class Emitter>
3445 for (
unsigned I = 0; I != N; ++I) {
3452 if (!this->
discard(ArrayIndexExpr))
3457 if (!this->
visit(ArrayIndexExpr))
3461 if (!this->emitCast(IndexT,
PT_Sint64, E))
3471 return this->emitOffsetOf(
T, E, E);
3474template <
class Emitter>
3483 return this->visitZeroInitializer(*
T, Ty, E);
3490 if (!this->emitGetPtrLocal(*LocalIndex, E))
3495 QualType ElemQT = CT->getElementType();
3498 for (
unsigned I = 0; I != 2; ++I) {
3499 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3501 if (!this->emitInitElem(ElemT, I, E))
3513 if (!this->emitGetPtrLocal(*LocalIndex, E))
3518 QualType ElemQT = VT->getElementType();
3521 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3522 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3524 if (!this->emitInitElem(ElemT, I, E))
3533template <
class Emitter>
3538template <
class Emitter>
3544template <
class Emitter>
3549template <
class Emitter>
3554 return this->emitConst(E->
getValue(), E);
3557template <
class Emitter>
3562 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3580 if (!this->emitGetParam(PT, Offset, E))
3585 return this->emitCall(F, 0, E);
3590template <
class Emitter>
3598 const Expr *PlacementDest =
nullptr;
3599 bool IsNoThrow =
false;
3601 if (PlacementArgs != 0) {
3610 if (PlacementArgs == 1) {
3618 if (!this->emitInvalidNewDeleteExpr(E, E))
3623 if (OperatorNew->isReservedGlobalPlacementOperator())
3624 PlacementDest = Arg1;
3628 return this->emitInvalid(E);
3630 }
else if (!OperatorNew
3631 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3632 return this->emitInvalidNewDeleteExpr(E, E);
3635 if (!PlacementDest) {
3640 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3643 Desc =
P.createDescriptor(
3646 false,
false,
false,
3652 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3656 const Expr *Stripped = *ArraySizeExpr;
3657 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3658 Stripped = ICE->getSubExpr())
3659 if (ICE->getCastKind() != CK_NoOp &&
3660 ICE->getCastKind() != CK_IntegralCast)
3668 if (!this->
visit(Stripped))
3670 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3673 if (PlacementDest) {
3674 if (!this->
visit(PlacementDest))
3676 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3678 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3681 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3686 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3690 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3697 size_t StaticInitElems = 0;
3698 const Expr *DynamicInit =
nullptr;
3702 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3703 StaticInitElems = CAT->getZExtSize();
3708 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
3709 if (ILE->hasArrayFiller())
3710 DynamicInit = ILE->getArrayFiller();
3729 const Function *CtorFunc =
nullptr;
3730 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3734 }
else if (!DynamicInit && !ElemT)
3737 LabelTy EndLabel = this->getLabel();
3738 LabelTy StartLabel = this->getLabel();
3743 if (!this->emitDupPtr(E))
3745 if (!this->emitNullPtr(0,
nullptr, E))
3747 if (!this->emitEQPtr(E))
3749 if (!this->jumpTrue(EndLabel))
3756 if (!this->emitConst(StaticInitElems,
SizeT, E))
3758 if (!this->emitSetLocal(
SizeT, Iter, E))
3761 this->fallthrough(StartLabel);
3762 this->emitLabel(StartLabel);
3764 if (!this->emitGetLocal(
SizeT, Iter, E))
3766 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3768 if (!this->emitLT(
SizeT, E))
3770 if (!this->jumpFalse(EndLabel))
3774 if (!this->emitGetLocal(
SizeT, Iter, E))
3776 if (!this->emitArrayElemPtr(
SizeT, E))
3779 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3784 if (!this->visitZeroInitializer(InitT, ElemType, E))
3786 if (!this->emitStorePop(InitT, E))
3788 }
else if (DynamicInit) {
3790 if (!this->
visit(DynamicInit))
3792 if (!this->emitStorePop(*InitT, E))
3797 if (!this->emitPopPtr(E))
3801 if (!this->visitZeroInitializer(
3805 if (!this->emitStorePop(*ElemT, E))
3809 if (!this->emitCall(CtorFunc, 0, E))
3814 if (!this->emitGetPtrLocal(Iter, E))
3816 if (!this->emitIncPop(
SizeT,
false, E))
3819 if (!this->jump(StartLabel))
3822 this->fallthrough(EndLabel);
3823 this->emitLabel(EndLabel);
3827 if (PlacementDest) {
3828 if (!this->
visit(PlacementDest))
3830 if (!this->emitCheckNewTypeMismatch(E, E))
3835 if (!this->emitAlloc(Desc, E))
3844 if (!this->emitInit(*ElemT, E))
3855 return this->emitPopPtr(E);
3860template <
class Emitter>
3866 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3867 return this->emitInvalidNewDeleteExpr(E, E);
3870 if (!this->
visit(Arg))
3876template <
class Emitter>
3882 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3887 return this->emitGetFnPtr(
Func, E);
3890template <
class Emitter>
3894 auto canonType = [](
const Type *
T) {
3895 return T->getCanonicalTypeUnqualified().getTypePtr();
3903 return this->emitGetTypeid(
3907 return this->emitGetTypeid(
3916 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3922 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3925 return this->emitPopPtr(E);
3929template <
class Emitter>
3931 assert(
Ctx.getLangOpts().CPlusPlus);
3932 return this->emitConstBool(E->
getValue(), E);
3935template <
class Emitter>
3947 return this->emitDummyPtr(GuidDecl, E);
3952 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3961 assert(
V.isStruct());
3962 assert(
V.getStructNumBases() == 0);
3966 return this->emitFinishInit(E);
3969template <
class Emitter>
3979template <
class Emitter>
3988template <
class Emitter>
3994template <
class Emitter>
3998 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4002 if (OVE->isUnique())
4018template <
class Emitter>
4023template <
class Emitter>
4025 return this->emitError(E);
4028template <
class Emitter>
4034 return this->emitDummyPtr(E, E);
4037template <
class Emitter>
4041 QualType ElemType = VT->getElementType();
4045 PrimType SrcElemT = classifyVectorElementType(SrcType);
4047 unsigned SrcOffset =
4049 if (!this->
visit(Src))
4051 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4054 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4055 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4057 if (!this->emitArrayElemPop(SrcElemT, I, E))
4061 if (SrcElemT != ElemT) {
4062 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4064 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4065 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4069 if (!this->emitInitElem(ElemT, I, E))
4076template <
class Emitter>
4080 return this->emitInvalid(E);
4090 assert(NumOutputElems > 0);
4093 unsigned VectorOffsets[2];
4094 for (
unsigned I = 0; I != 2; ++I) {
4097 if (!this->
visit(Vecs[I]))
4099 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4102 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4104 assert(ShuffleIndex >= -1);
4105 if (ShuffleIndex == -1)
4106 return this->emitInvalidShuffleVectorIndex(I, E);
4108 assert(ShuffleIndex < (NumInputElems * 2));
4109 if (!this->emitGetLocal(
PT_Ptr,
4110 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4112 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4113 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4116 if (!this->emitInitElem(ElemT, I, E))
4123template <
class Emitter>
4128 Base->getType()->isVectorType() ||
4134 if (Indices.size() == 1) {
4139 if (!this->emitConstUint32(Indices[0], E))
4141 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4151 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4159 if (!this->emitGetPtrLocal(*ResultIndex, E))
4167 uint32_t DstIndex = 0;
4168 for (uint32_t I : Indices) {
4169 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4171 if (!this->emitArrayElemPop(ElemT, I, E))
4173 if (!this->emitInitElem(ElemT, DstIndex, E))
4183template <
class Emitter>
4187 return this->
discard(SubExpr) && this->emitInvalid(E);
4193 return this->emitDummyPtr(E, E);
4196template <
class Emitter>
4201 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4206 if (!this->
visit(SubExpr))
4208 if (!this->emitConstUint8(0, E))
4210 if (!this->emitArrayElemPtrPopUint8(E))
4217 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4219 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4221 assert(SecondFieldT ==
PT_Ptr);
4225 if (!this->emitExpandPtr(E))
4229 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4234template <
class Emitter>
4249 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4251 return this->emitUnsupported(E);
4260 return this->
Visit(E);
4267 return this->
Visit(E);
4271 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4274 if (
const auto *CE = dyn_cast<CastExpr>(E);
4276 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4283 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4286 if (
const auto *CE = dyn_cast<CastExpr>(E);
4287 CE && (CE->getCastKind() == CK_DerivedToBase ||
4288 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4289 CE->getCastKind() == CK_NoOp))
4309 if (!this->emitGetPtrLocal(*LocalIndex, E))
4319 return this->
Visit(E);
4322template <
class Emitter>
4328 return this->
Visit(E);
4334 return this->
Visit(E);
4342 if (!this->
visit(E))
4344 return this->emitComplexBoolCast(E);
4349 if (!this->
visit(E))
4357 return this->emitIsNonNullPtr(E);
4361 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4364 return this->emitCast(*
T,
PT_Bool, E);
4367template <
class Emitter>
4371 QT = AT->getValueType();
4375 return this->emitZeroBool(E);
4377 return this->emitZeroSint8(E);
4379 return this->emitZeroUint8(E);
4381 return this->emitZeroSint16(E);
4383 return this->emitZeroUint16(E);
4385 return this->emitZeroSint32(E);
4387 return this->emitZeroUint32(E);
4389 return this->emitZeroSint64(E);
4391 return this->emitZeroUint64(E);
4393 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4395 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4397 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4400 return this->emitNullMemberPtr(0,
nullptr, E);
4402 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4403 return this->emitFloat(F, E);
4406 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4410 llvm_unreachable(
"unknown primitive type");
4413template <
class Emitter>
4414bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4419 for (
const Record::Field &Field : R->
fields()) {
4420 if (Field.isUnnamedBitField())
4427 if (!this->visitZeroInitializer(
T, QT, E))
4430 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4434 if (!this->emitInitField(
T, Field.Offset, E))
4439 if (!this->emitGetPtrField(Field.Offset, E))
4445 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4446 if (!this->visitZeroInitializer(
T, ET, E))
4448 if (!this->emitInitElem(
T, I, E))
4453 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4456 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4464 if (!this->emitFinishInitActivatePop(E))
4468 if (!this->emitFinishInitPop(E))
4472 for (
const Record::Base &B : R->
bases()) {
4473 if (!this->emitGetPtrBase(B.Offset, E))
4475 if (!this->visitZeroRecordInitializer(B.R, E))
4477 if (!this->emitFinishInitPop(E))
4486template <
class Emitter>
4487bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4488 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4489 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4494 for (
size_t I = 0; I != NumElems; ++I) {
4495 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4497 if (!this->emitInitElem(*ElemT, I, E))
4503 const Record *R = getRecord(ElemType);
4505 for (
size_t I = 0; I != NumElems; ++I) {
4506 if (!this->emitConstUint32(I, E))
4508 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4510 if (!this->visitZeroRecordInitializer(R, E))
4512 if (!this->emitPopPtr(E))
4518 for (
size_t I = 0; I != NumElems; ++I) {
4519 if (!this->emitConstUint32(I, E))
4521 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4523 if (!this->visitZeroArrayInitializer(ElemType, E))
4525 if (!this->emitPopPtr(E))
4534template <
class Emitter>
4535bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4537 if (!canClassify(E->
getType()))
4540 if (!this->visit(RHS))
4542 if (!this->visit(LHS))
4549 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4553 bool Activates = refersToUnion(LHS);
4556 if (!this->emitFlip(
PT_Ptr, RHT, E))
4559 if (DiscardResult) {
4560 if (BitField && Activates)
4561 return this->emitStoreBitFieldActivatePop(RHT, E);
4563 return this->emitStoreBitFieldPop(RHT, E);
4565 return this->emitStoreActivatePop(RHT, E);
4567 return this->emitStorePop(RHT, E);
4570 auto maybeLoad = [&](
bool Result) ->
bool {
4576 return this->emitLoadPop(RHT, E);
4580 if (BitField && Activates)
4581 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4583 return maybeLoad(this->emitStoreBitField(RHT, E));
4585 return maybeLoad(this->emitStoreActivate(RHT, E));
4587 return maybeLoad(this->emitStore(RHT, E));
4590template <
class Emitter>
4591template <
typename T>
4595 return this->emitConstSint8(
Value, E);
4597 return this->emitConstUint8(
Value, E);
4599 return this->emitConstSint16(
Value, E);
4601 return this->emitConstUint16(
Value, E);
4603 return this->emitConstSint32(
Value, E);
4605 return this->emitConstUint32(
Value, E);
4607 return this->emitConstSint64(
Value, E);
4609 return this->emitConstUint64(
Value, E);
4611 return this->emitConstBool(
Value, E);
4618 llvm_unreachable(
"Invalid integral type");
4621 llvm_unreachable(
"unknown primitive type");
4624template <
class Emitter>
4625template <
typename T>
4626bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4627 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4630template <
class Emitter>
4634 return this->emitConstIntAPS(
Value, E);
4636 return this->emitConstIntAP(
Value, E);
4638 if (
Value.isSigned())
4639 return this->emitConst(
Value.getSExtValue(), Ty, E);
4640 return this->emitConst(
Value.getZExtValue(), Ty, E);
4643template <
class Emitter>
4647 return this->emitConstIntAPS(
Value, E);
4649 return this->emitConstIntAP(
Value, E);
4652 return this->emitConst(
Value.getSExtValue(), Ty, E);
4653 return this->emitConst(
Value.getZExtValue(), Ty, E);
4656template <
class Emitter>
4657bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4658 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4661template <
class Emitter>
4666 bool IsConstexprUnknown) {
4675 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4676 Locals.insert({VD, Local});
4677 VarScope->addForScopeKind(Local, SC);
4678 return Local.Offset;
4681template <
class Emitter>
4684 bool IsConstexprUnknown) {
4687 bool IsTemporary =
false;
4688 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4691 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4692 Init = VarD->getInit();
4694 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4705 return std::nullopt;
4710 Locals.insert({Key, Local});
4711 VarScope->addForScopeKind(Local, SC);
4712 return Local.Offset;
4715template <
class Emitter>
4725 return std::nullopt;
4735 return Local.Offset;
4738template <
class Emitter>
4740 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
4741 return PT->getPointeeType()->getAsCanonical<RecordType>();
4747 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
4751template <
class Emitter>
4753 return P.getOrCreateRecord(RD);
4756template <
class Emitter>
4758 return Ctx.getOrCreateFunction(FD);
4761template <
class Emitter>
4766 if (!DestroyToplevelScope) {
4767 if (!this->emitCheckAllocations(E))
4771 auto maybeDestroyLocals = [&]() ->
bool {
4772 if (DestroyToplevelScope)
4773 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
4774 return this->emitCheckAllocations(E);
4781 return this->emitRetVoid(E) && maybeDestroyLocals();
4789 return this->emitRet(*
T, E) && maybeDestroyLocals();
4797 if (!this->emitGetPtrLocal(*LocalOffset, E))
4803 if (!this->emitFinishInit(E))
4808 return this->emitRetValue(E) && maybeDestroyLocals();
4811 return maybeDestroyLocals() && this->emitCheckAllocations(E) &&
false;
4814template <
class Emitter>
4816 bool IsConstexprUnknown) {
4819 IsConstexprUnknown);
4828 if (
auto GlobalIndex =
P.getGlobal(VD)) {
4829 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4843template <
class Emitter>
4845 bool ConstantContext) {
4848 if (!ConstantContext) {
4862 auto GlobalIndex =
P.getGlobal(VD);
4863 assert(GlobalIndex);
4865 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
4868 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
4872 auto Local =
Locals.find(VD);
4873 assert(Local !=
Locals.end());
4875 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
4878 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
4888 auto GlobalIndex =
P.getGlobal(VD);
4889 assert(GlobalIndex);
4890 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4899 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
4902template <
class Emitter>
4905 bool Toplevel,
bool IsConstexprUnknown) {
4912 if (!this->isActive())
4917 if (
Init &&
Init->isValueDependent())
4921 auto checkDecl = [&]() ->
bool {
4923 return !NeedsOp || this->emitCheckDecl(VD, VD);
4931 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
4934 if (
P.isGlobalInitialized(*GlobalIndex))
4938 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
4952 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
4955 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
4961 return this->emitFinishInitGlobal(
Init);
4970 IsConstexprUnknown);
4981 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
4985 return this->emitSetLocal(*VarT, Offset, VD);
4993 if (!this->emitGetPtrLocal(*Offset,
Init))
4999 return this->emitFinishInitPop(
Init);
5004template <
class Emitter>
5009 return this->emitConst(Val.
getInt(), ValType, E);
5012 return this->emitFloat(F, E);
5017 return this->emitNull(ValType, 0,
nullptr, E);
5019 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5020 return this->
visit(BaseExpr);
5025 return this->emitGetMemberPtr(MemberDecl, E);
5026 return this->emitNullMemberPtr(0,
nullptr, E);
5032template <
class Emitter>
5040 const Record::Field *RF = R->
getField(I);
5041 QualType FieldType = RF->Decl->getType();
5046 if (!this->emitInitField(*PT, RF->Offset, E))
5049 if (!this->emitGetPtrField(RF->Offset, E))
5053 if (!this->emitPopPtr(E))
5064 const Record::Field *RF = R->
getField(UnionField);
5068 return this->emitInitField(
T, RF->Offset, E);
5071 const auto *ArrType =
T->getAsArrayTypeUnsafe();
5072 QualType ElemType = ArrType->getElementType();
5073 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5078 if (!this->emitInitElem(*ElemT, A, E))
5081 if (!this->emitConstUint32(A, E))
5083 if (!this->emitArrayElemPtrUint32(E))
5087 if (!this->emitPopPtr(E))
5098template <
class Emitter>
5100 unsigned BuiltinID) {
5101 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5106 return this->emitConst(0, E);
5109 if (!this->emitStartSpeculation(E))
5111 LabelTy EndLabel = this->getLabel();
5112 if (!this->speculate(E, EndLabel))
5114 this->fallthrough(EndLabel);
5115 if (!this->emitEndSpeculation(E))
5124 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5125 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5126 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5127 BuiltinID == Builtin::BI__builtin_function_start) {
5130 return this->emitDummyPtr(E, E);
5141 if (!this->emitGetPtrLocal(*LocalIndex, E))
5146 switch (BuiltinID) {
5147 case Builtin::BI__builtin_object_size:
5148 case Builtin::BI__builtin_dynamic_object_size: {
5152 if (!this->
visit(Arg0))
5163 case Builtin::BI__assume:
5164 case Builtin::BI__builtin_assume:
5170 for (
const auto *Arg : E->
arguments()) {
5171 if (!this->
visit(Arg))
5177 if (!this->emitCallBI(E, BuiltinID, E))
5182 return this->emitPop(*ReturnT, E);
5188template <
class Emitter>
5205 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5206 DD && DD->isTrivial()) {
5208 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5210 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5211 this->emitPopPtr(E);
5227 if (!this->emitGetPtrLocal(*LocalIndex, E))
5235 if (!this->emitGetPtrLocal(*LocalIndex, E))
5239 if (!this->emitDupPtr(E))
5246 bool IsAssignmentOperatorCall =
false;
5247 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5248 OCE && OCE->isAssignmentOp()) {
5252 assert(Args.size() == 2);
5253 IsAssignmentOperatorCall =
true;
5254 std::reverse(Args.begin(), Args.end());
5260 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5261 MD && MD->isStatic()) {
5265 Args.erase(Args.begin());
5269 bool Devirtualized =
false;
5272 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5280 if (!this->
visit(Callee))
5282 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5284 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5286 if (!this->emitGetMemberPtrBase(E))
5289 const auto *InstancePtr = MC->getImplicitObjectArgument();
5296 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5297 Devirtualized =
true;
5298 if (!this->
visit(Stripped))
5301 if (!this->
visit(InstancePtr))
5305 if (!this->
visit(InstancePtr))
5309 }
else if (
const auto *PD =
5310 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5311 if (!this->emitCheckPseudoDtor(E))
5319 return this->emitEndLifetimePop(E);
5320 }
else if (!FuncDecl) {
5324 if (!this->
visit(Callee))
5326 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5330 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5335 if (IsAssignmentOperatorCall) {
5336 assert(Args.size() == 2);
5339 if (!this->emitFlip(Arg2T, Arg1T, E))
5353 assert(HasRVO ==
Func->hasRVO());
5355 bool HasQualifier =
false;
5356 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5357 HasQualifier = ME->hasQualifier();
5359 bool IsVirtual =
false;
5360 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5361 IsVirtual = !Devirtualized && MD->isVirtual();
5366 if (IsVirtual && !HasQualifier) {
5367 uint32_t VarArgSize = 0;
5368 unsigned NumParams =
5370 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5373 if (!this->emitCallVirt(
Func, VarArgSize, E))
5375 }
else if (
Func->isVariadic()) {
5376 uint32_t VarArgSize = 0;
5377 unsigned NumParams =
5379 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5381 if (!this->emitCallVar(
Func, VarArgSize, E))
5384 if (!this->emitCall(
Func, 0, E))
5393 uint32_t ArgSize = 0;
5394 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5400 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5402 if (!this->emitGetMemberPtrDecl(E))
5405 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5408 if (!this->emitCallPtr(ArgSize, E, E))
5419template <
class Emitter>
5426template <
class Emitter>
5433template <
class Emitter>
5438 return this->emitConstBool(E->
getValue(), E);
5441template <
class Emitter>
5447 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5448 return this->emitNullPtr(Val,
nullptr, E);
5451template <
class Emitter>
5459 return this->emitZero(
T, E);
5462template <
class Emitter>
5467 if (this->LambdaThisCapture.Offset > 0) {
5468 if (this->LambdaThisCapture.IsPtr)
5469 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5470 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5478 return this->emitThis(E);
5493 unsigned StartIndex = 0;
5494 unsigned EndIndex = 0;
5496 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5498 EndIndex = StartIndex;
5505 for (; StartIndex > 0; --StartIndex) {
5515 if (StartIndex == 0 && EndIndex == 0)
5518 assert(StartIndex < EndIndex);
5521 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5533 case Stmt::CompoundStmtClass:
5535 case Stmt::DeclStmtClass:
5537 case Stmt::ReturnStmtClass:
5539 case Stmt::IfStmtClass:
5541 case Stmt::WhileStmtClass:
5543 case Stmt::DoStmtClass:
5545 case Stmt::ForStmtClass:
5547 case Stmt::CXXForRangeStmtClass:
5549 case Stmt::BreakStmtClass:
5551 case Stmt::ContinueStmtClass:
5553 case Stmt::SwitchStmtClass:
5555 case Stmt::CaseStmtClass:
5557 case Stmt::DefaultStmtClass:
5559 case Stmt::AttributedStmtClass:
5561 case Stmt::CXXTryStmtClass:
5563 case Stmt::NullStmtClass:
5566 case Stmt::GCCAsmStmtClass:
5567 case Stmt::MSAsmStmtClass:
5568 case Stmt::GotoStmtClass:
5569 return this->emitInvalid(S);
5570 case Stmt::LabelStmtClass:
5573 if (
const auto *E = dyn_cast<Expr>(S))
5580template <
class Emitter>
5583 for (
const auto *InnerStmt : S->
body())
5586 return Scope.destroyLocals();
5589template <
class Emitter>
5590bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5591 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5592 for (
auto *BD : DD->flat_bindings())
5593 if (
auto *KD = BD->getHoldingVar();
5594 KD && !this->visitVarDecl(KD, KD->getInit()))
5608template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5610 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5611 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5618 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5623 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5624 ICE && (ICE->getCastKind() == CK_NoOp ||
5625 ICE->getCastKind() == CK_DerivedToBase ||
5626 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5627 E = ICE->getSubExpr();
5631 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5632 const auto *ThisRecord =
5633 This->getType()->getPointeeType()->getAsRecordDecl();
5634 if (!ThisRecord->isUnion())
5637 if (
const auto *Ctor =
5638 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5639 return Ctor->getParent() == ThisRecord;
5648template <
class Emitter>
5650 bool EvaluateConditionDecl) {
5651 for (
const auto *D : DS->
decls()) {
5656 const auto *VD = dyn_cast<VarDecl>(D);
5663 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5670template <
class Emitter>
5673 return this->emitUnsupported(RS);
5679 if (!this->
visit(RE))
5685 if (RE->getType()->isVoidType()) {
5686 if (!this->
visit(RE))
5689 if (RE->containsErrors())
5694 if (!this->emitRVOPtr(RE))
5698 if (!this->emitPopPtr(RE))
5702 return this->emitRetVoid(RS);
5708 return this->emitRetVoid(RS);
5714 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5721 if (
auto *CondInit = IS->
getInit()) {
5737 return visitChildStmt(IS->
getThen());
5739 return visitChildStmt(Else);
5745 if (!this->emitIsConstantContext(IS))
5748 if (!this->emitIsConstantContext(IS))
5750 if (!this->emitInv(IS))
5764 LabelTy LabelElse = this->getLabel();
5765 LabelTy LabelEnd = this->getLabel();
5766 if (!this->jumpFalse(LabelElse))
5768 if (!visitChildStmt(IS->
getThen()))
5770 if (!this->jump(LabelEnd))
5772 this->emitLabel(LabelElse);
5773 if (!visitChildStmt(Else))
5775 this->emitLabel(LabelEnd);
5777 LabelTy LabelEnd = this->getLabel();
5778 if (!this->jumpFalse(LabelEnd))
5780 if (!visitChildStmt(IS->
getThen()))
5782 this->emitLabel(LabelEnd);
5791template <
class Emitter>
5796 LabelTy CondLabel = this->getLabel();
5797 LabelTy EndLabel = this->getLabel();
5801 this->fallthrough(CondLabel);
5802 this->emitLabel(CondLabel);
5816 if (!this->jumpFalse(EndLabel))
5825 if (!this->jump(CondLabel))
5827 this->fallthrough(EndLabel);
5828 this->emitLabel(EndLabel);
5836 LabelTy StartLabel = this->getLabel();
5837 LabelTy EndLabel = this->getLabel();
5838 LabelTy CondLabel = this->getLabel();
5842 this->fallthrough(StartLabel);
5843 this->emitLabel(StartLabel);
5849 this->fallthrough(CondLabel);
5850 this->emitLabel(CondLabel);
5857 if (!this->jumpTrue(StartLabel))
5860 this->fallthrough(EndLabel);
5861 this->emitLabel(EndLabel);
5865template <
class Emitter>
5873 LabelTy EndLabel = this->getLabel();
5874 LabelTy CondLabel = this->getLabel();
5875 LabelTy IncLabel = this->getLabel();
5882 this->fallthrough(CondLabel);
5883 this->emitLabel(CondLabel);
5895 if (!this->jumpFalse(EndLabel))
5904 this->fallthrough(IncLabel);
5905 this->emitLabel(IncLabel);
5911 if (!this->jump(CondLabel))
5915 this->emitLabel(EndLabel);
5921template <
class Emitter>
5931 LabelTy EndLabel = this->getLabel();
5932 LabelTy CondLabel = this->getLabel();
5933 LabelTy IncLabel = this->getLabel();
5948 this->fallthrough(CondLabel);
5949 this->emitLabel(CondLabel);
5952 if (!this->jumpFalse(EndLabel))
5963 this->fallthrough(IncLabel);
5964 this->emitLabel(IncLabel);
5969 if (!this->jump(CondLabel))
5972 this->fallthrough(EndLabel);
5973 this->emitLabel(EndLabel);
5977template <
class Emitter>
5988 if (LI.BreakLabel) {
5989 TargetLabel = *LI.BreakLabel;
5990 BreakScope = LI.BreakOrContinueScope;
5996 if (LI.Name == TargetLoop) {
5997 TargetLabel = *LI.BreakLabel;
5998 BreakScope = LI.BreakOrContinueScope;
6004 assert(TargetLabel);
6007 C =
C->getParent()) {
6008 if (!
C->destroyLocals())
6012 return this->jump(*TargetLabel);
6015template <
class Emitter>
6026 if (LI.ContinueLabel) {
6027 TargetLabel = *LI.ContinueLabel;
6028 ContinueScope = LI.BreakOrContinueScope;
6034 if (LI.Name == TargetLoop) {
6035 TargetLabel = *LI.ContinueLabel;
6036 ContinueScope = LI.BreakOrContinueScope;
6041 assert(TargetLabel);
6044 C =
C->getParent()) {
6045 if (!
C->destroyLocals())
6049 return this->jump(*TargetLabel);
6052template <
class Emitter>
6055 if (
Cond->containsErrors())
6061 LabelTy EndLabel = this->getLabel();
6066 if (
const auto *CondInit = S->
getInit())
6077 if (!this->emitSetLocal(CondT, CondVar, S))
6087 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6090 if (CS->caseStmtIsGNURange()) {
6091 LabelTy EndOfRangeCheck = this->getLabel();
6092 const Expr *Low = CS->getLHS();
6093 const Expr *High = CS->getRHS();
6097 if (!this->emitGetLocal(CondT, CondVar, CS))
6099 if (!this->
visit(Low))
6102 if (!this->emitGE(
LT, S))
6104 if (!this->jumpFalse(EndOfRangeCheck))
6107 if (!this->emitGetLocal(CondT, CondVar, CS))
6109 if (!this->
visit(High))
6112 if (!this->emitLE(HT, S))
6116 this->emitLabel(EndOfRangeCheck);
6121 if (
Value->isValueDependent())
6126 if (!this->emitGetLocal(CondT, CondVar, CS))
6132 if (!this->emitEQ(ValueT, S))
6137 assert(!DefaultLabel);
6138 DefaultLabel = this->getLabel();
6145 if (!this->jump(*DefaultLabel))
6148 if (!this->jump(EndLabel))
6156 this->fallthrough(EndLabel);
6157 this->emitLabel(EndLabel);
6162template <
class Emitter>
6169template <
class Emitter>
6176 if (LI.DefaultLabel) {
6177 DefaultLabel = *LI.DefaultLabel;
6182 this->emitLabel(DefaultLabel);
6186template <
class Emitter>
6193 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6196 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6197 !this->Ctx.getLangOpts().MSVCCompat) {
6199 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6205 const Expr *Assumption = AA->getAssumption();
6216 if (!this->emitAssume(Assumption))
6225 if (IsMSVCConstexprAttr)
6226 return this->emitPopMSVCCE(S);
6230template <
class Emitter>
6236template <
class Emitter>
6237bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6244 assert(ClosureClass->
captures().empty());
6248 "A generic lambda's static-invoker function must be a "
6249 "template specialization");
6253 void *InsertPos =
nullptr;
6254 const FunctionDecl *CorrespondingCallOpSpecialization =
6256 assert(CorrespondingCallOpSpecialization);
6257 LambdaCallOp = CorrespondingCallOpSpecialization;
6261 assert(ClosureClass->
captures().empty());
6262 const Function *
Func = this->getFunction(LambdaCallOp);
6265 assert(
Func->hasThisPointer());
6268 if (
Func->hasRVO()) {
6269 if (!this->emitRVOPtr(MD))
6277 if (!this->emitNullPtr(0,
nullptr, MD))
6282 auto It = this->Params.find(PVD);
6283 assert(It != this->Params.end());
6287 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6288 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6292 if (!this->emitCall(
Func, 0, LambdaCallOp))
6297 return this->emitRet(*ReturnType, MD);
6300 return this->emitRetVoid(MD);
6303template <
class Emitter>
6304bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6305 if (Ctx.getLangOpts().CPlusPlus23)
6315 const Expr *InitExpr =
Init->getInit();
6317 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6321 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6331template <
class Emitter>
6333 assert(!ReturnType);
6335 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6336 const Expr *InitExpr,
6339 if (InitExpr->getType().isNull())
6343 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6346 if (!this->visit(InitExpr))
6349 bool BitField = F->isBitField();
6351 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6352 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6357 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6360 if (
Activate && !this->emitActivate(InitExpr))
6363 if (!this->visitInitializer(InitExpr))
6366 return this->emitFinishInitPop(InitExpr);
6370 const Record *R = this->getRecord(RD);
6379 return this->emitRetVoid(Ctor);
6382 if (!this->emitThis(Ctor))
6391 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6392 this->emitRetVoid(Ctor);
6396 for (
const auto *
Init : Ctor->
inits()) {
6400 const Expr *InitExpr =
Init->getInit();
6406 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6409 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6412 if (
Init->isBaseVirtual()) {
6414 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6420 const Record::Base *B = R->
getBase(BaseDecl);
6422 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6426 if (IsUnion && !this->emitActivate(InitExpr))
6429 if (!this->visitInitializer(InitExpr))
6431 if (!this->emitFinishInitPop(InitExpr))
6436 assert(IFD->getChainingSize() >= 2);
6438 unsigned NestedFieldOffset = 0;
6439 const Record::Field *NestedField =
nullptr;
6440 for (
const NamedDecl *ND : IFD->chain()) {
6442 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6443 assert(FieldRecord);
6445 NestedField = FieldRecord->
getField(FD);
6446 assert(NestedField);
6447 IsUnion = IsUnion || FieldRecord->
isUnion();
6449 NestedFieldOffset += NestedField->Offset;
6451 assert(NestedField);
6453 unsigned FirstLinkOffset =
6457 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6462 unsigned InitFieldOffset = 0;
6463 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6465 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6466 assert(FieldRecord);
6467 NestedField = FieldRecord->
getField(FD);
6468 InitFieldOffset += NestedField->Offset;
6469 assert(NestedField);
6470 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6472 if (!this->emitFinishInitPop(InitExpr))
6477 assert(
Init->isDelegatingInitializer());
6478 if (!this->emitThis(InitExpr))
6480 if (!this->visitInitializer(
Init->getInit()))
6482 if (!this->emitPopPtr(InitExpr))
6486 if (!
Scope.destroyLocals())
6493 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
6494 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
6501 if (!visitStmt(Body))
6508template <
class Emitter>
6511 const Record *R = this->getRecord(RD);
6516 if (!this->visitStmt(Dtor->
getBody()))
6520 if (!this->emitThis(Dtor))
6523 if (!this->emitCheckDestruction(Dtor))
6531 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6535 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6537 if (!this->emitDestructionPop(D,
SourceInfo{}))
6542 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6543 if (
Base.R->hasTrivialDtor())
6547 if (!this->emitRecordDestructionPop(
Base.R, {}))
6552 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6555template <
class Emitter>
6556bool Compiler<Emitter>::compileUnionAssignmentOperator(
6558 if (!this->emitThis(MD))
6567 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6570template <
class Emitter>
6577 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6578 return this->compileConstructor(Ctor);
6579 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6580 return this->compileDestructor(Dtor);
6583 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6588 return this->compileUnionAssignmentOperator(MD);
6591 return this->emitLambdaStaticInvokerBody(MD);
6595 if (
const auto *Body = F->
getBody())
6609 return FD->getBitWidthValue();
6612template <
class Emitter>
6625 if (!
Ctx.getLangOpts().CPlusPlus14)
6626 return this->emitInvalid(E);
6628 return this->emitError(E);
6630 if (!this->
visit(SubExpr))
6634 if (!this->emitIncPtr(E))
6641 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6642 : this->emitIncf(getFPOptions(E), E);
6654 if (!
Ctx.getLangOpts().CPlusPlus14)
6655 return this->emitInvalid(E);
6657 return this->emitError(E);
6659 if (!this->
visit(SubExpr))
6663 if (!this->emitDecPtr(E))
6670 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6671 : this->emitDecf(getFPOptions(E), E);
6684 if (!
Ctx.getLangOpts().CPlusPlus14)
6685 return this->emitInvalid(E);
6687 return this->emitError(E);
6689 if (!this->
visit(SubExpr))
6693 if (!this->emitLoadPtr(E))
6695 if (!this->emitConstUint8(1, E))
6697 if (!this->emitAddOffsetUint8(E))
6699 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6705 return this->emitIncfPop(getFPOptions(E), E);
6715 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6716 if (!this->emitLoadFloat(E))
6718 APFloat F(TargetSemantics, 1);
6719 if (!this->emitFloat(F, E))
6722 if (!this->emitAddf(getFPOptions(E), E))
6724 if (!this->emitStoreFloat(E))
6736 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6739 if (!
Ctx.getLangOpts().CPlusPlus14)
6740 return this->emitInvalid(E);
6742 return this->emitError(E);
6744 if (!this->
visit(SubExpr))
6748 if (!this->emitLoadPtr(E))
6750 if (!this->emitConstUint8(1, E))
6752 if (!this->emitSubOffsetUint8(E))
6754 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6760 return this->emitDecfPop(getFPOptions(E), E);
6770 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6771 if (!this->emitLoadFloat(E))
6773 APFloat F(TargetSemantics, 1);
6774 if (!this->emitFloat(F, E))
6777 if (!this->emitSubf(getFPOptions(E), E))
6779 if (!this->emitStoreFloat(E))
6791 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6795 return this->emitError(E);
6798 return this->
discard(SubExpr);
6803 if (!this->emitInv(E))
6807 return this->emitCast(
PT_Bool, ET, E);
6811 return this->emitError(E);
6813 if (!this->
visit(SubExpr))
6818 return this->emitError(E);
6820 if (!this->
visit(SubExpr))
6833 return this->
discard(SubExpr);
6835 if (!this->
visit(SubExpr))
6842 return this->emitNarrowPtr(E);
6847 return this->emitError(E);
6849 if (!this->
visit(SubExpr))
6863 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6868 assert(
false &&
"Unhandled opcode");
6874template <
class Emitter>
6880 return this->
discard(SubExpr);
6883 auto prepareResult = [=]() ->
bool {
6888 return this->emitGetPtrLocal(*LocalIndex, E);
6895 unsigned SubExprOffset = ~0u;
6896 auto createTemp = [=, &SubExprOffset]() ->
bool {
6899 if (!this->
visit(SubExpr))
6901 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6905 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6906 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6908 return this->emitArrayElemPop(ElemT, Index, E);
6913 if (!prepareResult())
6917 for (
unsigned I = 0; I != 2; ++I) {
6918 if (!getElem(SubExprOffset, I))
6920 if (!this->emitNeg(ElemT, E))
6922 if (!this->emitInitElem(ElemT, I, E))
6933 if (!this->
visit(SubExpr))
6935 if (!this->emitComplexBoolCast(SubExpr))
6937 if (!this->emitInv(E))
6940 return this->emitCast(
PT_Bool, ET, E);
6944 return this->emitComplexReal(SubExpr);
6947 if (!this->
visit(SubExpr))
6951 if (!this->emitConstUint8(1, E))
6953 return this->emitArrayElemPtrPopUint8(E);
6961 if (!this->
visit(SubExpr))
6964 if (!this->emitArrayElem(ElemT, 1, E))
6966 if (!this->emitNeg(ElemT, E))
6968 if (!this->emitInitElem(ElemT, 1, E))
6976 return this->emitInvalid(E);
6982template <
class Emitter>
6988 return this->
discard(SubExpr);
6991 if (UnaryOp == UO_Extension)
6994 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6995 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6996 return this->emitInvalid(E);
6999 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7006 if (!this->emitGetPtrLocal(*LocalIndex, E))
7011 unsigned SubExprOffset =
7013 if (!this->
visit(SubExpr))
7015 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7020 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7021 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7023 return this->emitArrayElemPop(ElemT, Index, E);
7028 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7029 if (!getElem(SubExprOffset, I))
7031 if (!this->emitNeg(ElemT, E))
7033 if (!this->emitInitElem(ElemT, I, E))
7048 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7049 if (!getElem(SubExprOffset, I))
7052 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7054 if (!this->emitInv(E))
7056 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7058 if (!this->emitNeg(ElemT, E))
7060 if (ElemT != ResultVecElemT &&
7061 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7063 if (!this->emitInitElem(ResultVecElemT, I, E))
7069 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7070 if (!getElem(SubExprOffset, I))
7073 if (!this->emitInv(E))
7076 if (!this->emitComp(ElemT, E))
7079 if (!this->emitInitElem(ElemT, I, E))
7084 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7089template <
class Emitter>
7094 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7095 return this->emitConst(ECD->getInitVal(), E);
7096 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7098 return F && this->emitGetFnPtr(F, E);
7100 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7102 if (!this->emitGetPtrGlobal(*Index, E))
7107 return this->emitInitGlobal(*
T, *Index, E);
7124 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7125 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7130 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7131 if (IsReference || !It->second.IsPtr)
7132 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
7134 return this->emitGetPtrParam(It->second.Offset, E);
7137 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7143 const unsigned Offset = It->second.Offset;
7146 return this->emitGetPtrLocal(Offset, E);
7149 if (
auto GlobalIndex =
P.getGlobal(D)) {
7151 if (!
Ctx.getLangOpts().CPlusPlus11)
7152 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7153 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7156 return this->emitGetPtrGlobal(*GlobalIndex, E);
7160 auto revisit = [&](
const VarDecl *VD) ->
bool {
7163 auto VarState = this->
visitDecl(VD,
true);
7165 if (!this->emitPopCC(E))
7168 if (VarState.notCreated())
7177 if (
auto It = this->LambdaCaptures.find(D);
7178 It != this->LambdaCaptures.end()) {
7179 auto [Offset, IsPtr] = It->second;
7182 return this->emitGetThisFieldPtr(Offset, E);
7183 return this->emitGetPtrThisField(Offset, E);
7186 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7187 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7188 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7192 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7193 return this->
visit(BD->getBinding());
7197 return this->emitDummyPtr(D, E);
7202 if (!
Ctx.getLangOpts().CPlusPlus) {
7203 if (
const auto *VD = dyn_cast<VarDecl>(D);
7207 return this->emitDummyPtr(D, E);
7211 const auto *VD = dyn_cast<VarDecl>(D);
7213 return this->emitDummyPtr(D, E);
7215 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7216 if (
T.isConstant(
Ctx.getASTContext()))
7218 return T->isReferenceType();
7222 typeShouldBeVisited(VD->
getType())) {
7224 Init && !
Init->isValueDependent()) {
7230 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7248 return this->emitDummyPtr(D, E);
7254 return this->emitDummyPtr(D, E);
7257template <
class Emitter>
7265 if (!
C->destroyLocals())
7271template <
class Emitter>
7272unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7275 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7277 return Ty->getAsCXXRecordDecl();
7279 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7280 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7282 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7286template <
class Emitter>
7293 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7298 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7299 getFPOptions(E), E);
7301 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7302 getFPOptions(E), E);
7306 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7311 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7313 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7317 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7321 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7322 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7329template <
class Emitter>
7332 assert(FromT != ToT);
7335 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7337 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7339 return this->emitCast(FromT, ToT, E);
7343template <
class Emitter>
7344bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7348 return this->
discard(SubExpr);
7350 if (!this->visit(SubExpr))
7353 if (!this->emitConstUint8(0, SubExpr))
7355 return this->emitArrayElemPtrPopUint8(SubExpr);
7359 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7363template <
class Emitter>
7364bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7365 assert(!DiscardResult);
7369 if (!this->emitArrayElem(ElemT, 0, E))
7372 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7375 if (!this->emitCast(ElemT,
PT_Bool, E))
7380 LabelTy LabelTrue = this->getLabel();
7381 if (!this->jumpTrue(LabelTrue))
7384 if (!this->emitArrayElemPop(ElemT, 1, E))
7387 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7390 if (!this->emitCast(ElemT,
PT_Bool, E))
7394 LabelTy EndLabel = this->getLabel();
7395 this->jump(EndLabel);
7397 this->emitLabel(LabelTrue);
7398 if (!this->emitPopPtr(E))
7400 if (!this->emitConstBool(
true, E))
7403 this->fallthrough(EndLabel);
7404 this->emitLabel(EndLabel);
7409template <
class Emitter>
7410bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7421 LHSIsComplex =
true;
7422 ElemT = classifyComplexElementType(LHS->
getType());
7423 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7424 if (!this->visit(LHS))
7426 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7429 LHSIsComplex =
false;
7431 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7432 if (!this->visit(LHS))
7434 if (!this->emitSetLocal(LHST, LHSOffset, E))
7441 RHSIsComplex =
true;
7442 ElemT = classifyComplexElementType(RHS->
getType());
7443 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7444 if (!this->visit(RHS))
7446 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7449 RHSIsComplex =
false;
7451 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7452 if (!this->visit(RHS))
7454 if (!this->emitSetLocal(RHST, RHSOffset, E))
7458 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7459 bool IsComplex) ->
bool {
7461 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7463 return this->emitArrayElemPop(ElemT, Index, E);
7465 return this->emitGetLocal(ElemT, LocalOffset, E);
7468 for (
unsigned I = 0; I != 2; ++I) {
7470 if (!getElem(LHSOffset, I, LHSIsComplex))
7472 if (!getElem(RHSOffset, I, RHSIsComplex))
7475 if (!this->emitEQ(ElemT, E))
7478 if (!this->emitCastBoolUint8(E))
7483 if (!this->emitAddUint8(E))
7485 if (!this->emitConstUint8(2, E))
7489 if (!this->emitEQUint8(E))
7492 if (!this->emitNEUint8(E))
7499 return this->emitCast(
PT_Bool, ResT, E);
7506template <
class Emitter>
7507bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7513 const Function *DtorFunc = getFunction(Dtor);
7516 assert(DtorFunc->hasThisPointer());
7517 assert(DtorFunc->getNumParams() == 1);
7518 return this->emitCall(DtorFunc, 0, Loc);
7523template <
class Emitter>
7524bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7536 return this->emitPopPtr(Loc);
7538 for (ssize_t I = N - 1; I >= 1; --I) {
7539 if (!this->emitConstUint64(I, Loc))
7541 if (!this->emitArrayElemPtrUint64(Loc))
7543 if (!this->emitDestructionPop(ElemDesc, Loc))
7547 if (!this->emitConstUint64(0, Loc))
7549 if (!this->emitArrayElemPtrPopUint64(Loc))
7551 return this->emitDestructionPop(ElemDesc, Loc);
7556 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7561template <
class Emitter>
7562bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7563 assert(!DiscardResult &&
"Should've been checked before");
7565 unsigned DummyID = P.getOrCreateDummy(D);
7567 if (!this->emitGetPtrGlobal(DummyID, E))
7575 return this->emitDecayPtr(
PT_Ptr, PT, E);
7581template <
class Emitter>
7582bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7583 assert(!DiscardResult &&
"Should've been checked before");
7586 return this->emitConstFloat(
Floating(F), E);
7588 APInt I = F.bitcastToAPInt();
7589 return this->emitConstFloat(
7590 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7591 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7602template <
class Emitter>
7603bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7616 if (!this->emitGetPtrLocal(*LocalIndex, E))
7626 if (!this->visit(SubExpr))
7628 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7629 unsigned TempOffset =
7630 allocateLocalPrimitive(SubExpr, *FromT,
true);
7631 if (!this->visit(SubExpr))
7633 if (!this->emitSetLocal(*FromT, TempOffset, E))
7635 if (!this->emitGetPtrLocal(TempOffset, E))
7642 if (!this->emitBitCast(E))
7644 return DiscardResult ? this->emitPopPtr(E) :
true;
7648 const llvm::fltSemantics *TargetSemantics =
nullptr;
7650 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7656 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7658 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7659 ResultBitWidth, TargetSemantics,
7664 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, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags)
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...
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
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.
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...
const Expr * getBase() const
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.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
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.
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
bool isExpressibleAsConstantInitializer() const
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() 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 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.
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)
VarCreationState visitDecl(const VarDecl *VD, bool IsConstexprUnknown=false)
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)
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)
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.
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block, bool IsConstexprUnknown=false)
Creates a local primitive value.
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.
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)
typename Emitter::LabelTy LabelTy
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)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false, bool IsConstexprUnknown=false)
Creates and initializes a variable from the given decl.
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 VisitGNUNullExpr(const GNUNullExpr *E)
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block, bool IsConstexprUnknown=false)
Allocates a space storing a local given its type.
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const ValueDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
const Base * getBase(unsigned I) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * getVirtualBase(unsigned I) const
llvm::iterator_range< const_base_iter > bases() const
unsigned getNumFields() const
llvm::iterator_range< const_field_iter > fields() const
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)
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)
constexpr bool isIntegralType(PrimType T)
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.
const FunctionProtoType * T
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)
bool isUnnamedBitField() const
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()