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:
491 return this->emitBuiltinBitCast(CE);
506 if (!this->
visit(SubExpr))
514 return this->emitFnPtrCast(CE);
521 if (!this->
visit(SubExpr))
523 return this->emitDecayPtr(*FromT, *ToT, CE);
525 case CK_IntegralToBoolean:
526 case CK_FixedPointToBoolean: {
532 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
533 return this->emitConst(IL->getValue(), CE);
534 if (!this->
visit(SubExpr))
539 case CK_BooleanToSignedIntegral:
540 case CK_IntegralCast: {
547 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
552 if (!this->emitConst(IL->getValue(), SubExpr))
555 if (!this->
visit(SubExpr))
563 if (!ED->isFixed()) {
564 if (!this->emitCheckEnumValue(*FromT, ED, CE))
570 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
573 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
578 if (!this->emitCast(*FromT, *ToT, CE))
581 if (CE->
getCastKind() == CK_BooleanToSignedIntegral)
582 return this->emitNeg(*ToT, CE);
586 case CK_PointerToBoolean:
587 case CK_MemberPointerToBoolean: {
590 if (!this->
visit(SubExpr))
592 return this->emitIsNonNull(PtrT, CE);
595 case CK_IntegralComplexToBoolean:
596 case CK_FloatingComplexToBoolean: {
597 if (!this->
visit(SubExpr))
599 return this->emitComplexBoolCast(SubExpr);
602 case CK_IntegralComplexToReal:
603 case CK_FloatingComplexToReal:
604 return this->emitComplexReal(SubExpr);
606 case CK_IntegralRealToComplex:
607 case CK_FloatingRealToComplex: {
614 if (!this->emitGetPtrLocal(*LocalIndex, CE))
623 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
625 return this->emitInitElem(
T, 1, SubExpr);
628 case CK_IntegralComplexCast:
629 case CK_FloatingComplexCast:
630 case CK_IntegralComplexToFloatingComplex:
631 case CK_FloatingComplexToIntegralComplex: {
638 if (!this->emitGetPtrLocal(*LocalIndex, CE))
645 unsigned SubExprOffset =
647 if (!this->
visit(SubExpr))
649 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, CE))
657 for (
unsigned I = 0; I != 2; ++I) {
658 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, CE))
660 if (!this->emitArrayElemPop(SourceElemT, I, CE))
664 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, CE))
668 if (!this->emitInitElem(DestElemT, I, CE))
674 case CK_VectorSplat: {
683 if (!this->emitGetPtrLocal(*LocalIndex, CE))
689 unsigned ElemOffset =
693 if (!this->
visit(SubExpr))
698 if (!this->emitSetLocal(ElemT, ElemOffset, CE))
701 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
702 if (!this->emitGetLocal(ElemT, ElemOffset, CE))
704 if (!this->emitInitElem(ElemT, I, CE))
711 case CK_HLSLVectorTruncation: {
716 if (!this->
visit(SubExpr))
718 return this->emitArrayElemPop(*ResultT, 0, CE);
727 if (!this->emitGetPtrLocal(*LocalIndex, CE))
732 if (!this->
visit(SubExpr))
734 return this->emitCopyArray(classifyVectorElementType(CE->
getType()), 0, 0,
738 case CK_IntegralToFixedPoint: {
739 if (!this->
visit(SubExpr))
743 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
747 case CK_FloatingToFixedPoint: {
748 if (!this->
visit(SubExpr))
752 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
753 return this->emitCastFloatingFixedPoint(Sem, CE);
755 case CK_FixedPointToFloating: {
756 if (!this->
visit(SubExpr))
758 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
759 return this->emitCastFixedPointFloating(TargetSemantics, CE);
761 case CK_FixedPointToIntegral: {
762 if (!this->
visit(SubExpr))
766 case CK_FixedPointCast: {
767 if (!this->
visit(SubExpr))
770 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
771 return this->emitCastFixedPoint(Sem, CE);
783 return this->emitInvalid(CE);
785 llvm_unreachable(
"Unhandled clang::CastKind enum");
788template <
class Emitter>
790 return this->emitBuiltinBitCast(E);
793template <
class Emitter>
798 return this->emitConst(
LE->getValue(),
LE);
801template <
class Emitter>
807 return this->emitFloat(F, E);
810template <
class Emitter>
820 if (!this->emitGetPtrLocal(*LocalIndex, E))
827 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
829 if (!this->emitInitElem(SubExprT, 0, SubExpr))
834template <
class Emitter>
842 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
847template <
class Emitter>
852template <
class Emitter>
879 return this->emitComplexComparison(LHS, RHS, BO);
884 if (!this->
visit(LHS))
887 if (!this->
visit(RHS))
890 if (!this->emitToMemberPtr(BO))
896 if (!this->emitCastMemberPtrPtr(BO))
913 Ctx.getASTContext().CompCategories.lookupInfoForType(BO->
getType());
919 if (!this->emitGetPtrLocal(*ResultIndex, BO))
926 return this->emitCMP3(*
LT, CmpInfo, BO);
929 if (!
LT || !RT || !
T)
939 return this->visitAssignment(LHS, RHS, BO);
946 auto MaybeCastToBool = [
this,
T, BO](
bool Result) {
950 return this->emitPopBool(BO);
952 return this->emitCast(
PT_Bool, *
T, BO);
956 auto Discard = [
this,
T, BO](
bool Result) {
964 return MaybeCastToBool(this->emitEQ(*
LT, BO));
966 return MaybeCastToBool(this->emitNE(*
LT, BO));
968 return MaybeCastToBool(this->emitLT(*
LT, BO));
970 return MaybeCastToBool(this->emitLE(*
LT, BO));
972 return MaybeCastToBool(this->emitGT(*
LT, BO));
974 return MaybeCastToBool(this->emitGE(*
LT, BO));
977 return Discard(this->emitSubf(getFPOptions(BO), BO));
978 return Discard(this->emitSub(*
T, BO));
981 return Discard(this->emitAddf(getFPOptions(BO), BO));
982 return Discard(this->emitAdd(*
T, BO));
985 return Discard(this->emitMulf(getFPOptions(BO), BO));
986 return Discard(this->emitMul(*
T, BO));
988 return Discard(this->emitRem(*
T, BO));
991 return Discard(this->emitDivf(getFPOptions(BO), BO));
992 return Discard(this->emitDiv(*
T, BO));
994 return Discard(this->emitBitAnd(*
T, BO));
996 return Discard(this->emitBitOr(*
T, BO));
998 return Discard(this->emitShl(*
LT, *RT, BO));
1000 return Discard(this->emitShr(*
LT, *RT, BO));
1002 return Discard(this->emitBitXor(*
T, BO));
1005 llvm_unreachable(
"Already handled earlier");
1010 llvm_unreachable(
"Unhandled binary op");
1015template <
class Emitter>
1021 if ((Op != BO_Add && Op != BO_Sub) ||
1032 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1033 if (!this->
visit(E))
1036 return this->emitDecayPtr(
T,
PT_Ptr, E);
1045 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1053 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1056 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1063 if (!visitAsPointer(RHS, *RT))
1065 if (!this->
visit(LHS))
1069 if (!visitAsPointer(LHS, *
LT))
1071 if (!this->
visit(RHS))
1081 if (!this->emitAddOffset(OffsetType, E))
1089 if (!this->emitSubOffset(OffsetType, E))
1100template <
class Emitter>
1110 LabelTy LabelTrue = this->getLabel();
1111 LabelTy LabelEnd = this->getLabel();
1115 if (!this->jumpTrue(LabelTrue))
1120 if (!this->jump(LabelEnd))
1123 this->emitLabel(LabelTrue);
1124 this->emitConstBool(
true, E);
1125 this->fallthrough(LabelEnd);
1126 this->emitLabel(LabelEnd);
1129 assert(Op == BO_LAnd);
1132 LabelTy LabelFalse = this->getLabel();
1133 LabelTy LabelEnd = this->getLabel();
1137 if (!this->jumpFalse(LabelFalse))
1142 if (!this->jump(LabelEnd))
1145 this->emitLabel(LabelFalse);
1146 this->emitConstBool(
false, E);
1147 this->fallthrough(LabelEnd);
1148 this->emitLabel(LabelEnd);
1152 return this->emitPopBool(E);
1157 return this->emitCast(
PT_Bool, *
T, E);
1161template <
class Emitter>
1168 if (!this->emitGetPtrLocal(*LocalIndex, E))
1177 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1178 unsigned ResultOffset = ~0u;
1184 if (!this->emitDupPtr(E))
1186 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1191 LHSType = AT->getValueType();
1194 RHSType = AT->getValueType();
1203 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1208 if (!this->
visit(LHS))
1210 if (!this->
visit(RHS))
1212 return this->emitMulc(ElemT, E);
1215 if (Op == BO_Div && RHSIsComplex) {
1222 if (!LHSIsComplex) {
1227 LHSOffset = *LocalIndex;
1229 if (!this->emitGetPtrLocal(LHSOffset, E))
1232 if (!this->
visit(LHS))
1235 if (!this->emitInitElem(ElemT, 0, E))
1238 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1240 if (!this->emitInitElem(ElemT, 1, E))
1243 if (!this->
visit(LHS))
1247 if (!this->
visit(RHS))
1249 return this->emitDivc(ElemT, E);
1255 if (!this->
visit(LHS))
1257 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1262 if (!this->
visit(LHS))
1264 if (!this->emitSetLocal(LHST, LHSOffset, E))
1272 if (!this->
visit(RHS))
1274 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1279 if (!this->
visit(RHS))
1281 if (!this->emitSetLocal(RHST, RHSOffset, E))
1288 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1289 unsigned ElemIndex,
unsigned Offset,
1290 const Expr *E) ->
bool {
1292 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1294 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1297 if (ElemIndex == 0 || !LoadZero)
1304 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1307 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1314 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1317 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1320 if (!this->emitAddf(getFPOptions(E), E))
1323 if (!this->emitAdd(ResultElemT, E))
1328 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1331 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1334 if (!this->emitSubf(getFPOptions(E), E))
1337 if (!this->emitSub(ResultElemT, E))
1342 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1345 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1349 if (!this->emitMulf(getFPOptions(E), E))
1352 if (!this->emitMul(ResultElemT, E))
1357 assert(!RHSIsComplex);
1358 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1361 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1365 if (!this->emitDivf(getFPOptions(E), E))
1368 if (!this->emitDiv(ResultElemT, E))
1379 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1382 if (!this->emitPop(ResultElemT, E))
1389template <
class Emitter>
1394 "Comma op should be handled in VisitBinaryOperator");
1408 if (!this->emitGetPtrLocal(*LocalIndex, E))
1422 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1425 if (!this->
visit(LHS))
1427 if (!this->
visit(RHS))
1429 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1432 return this->emitPopPtr(E);
1437 unsigned LHSOffset =
1439 if (!this->
visit(LHS))
1441 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1445 unsigned RHSOffset =
1447 if (!this->
visit(RHS))
1449 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1461 if (NeedIntPromot) {
1463 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1468 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1469 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1471 if (!this->emitArrayElemPop(ElemT, Index, E))
1474 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1476 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1478 }
else if (NeedIntPromot) {
1479 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1485#define EMIT_ARITH_OP(OP) \
1487 if (ElemT == PT_Float) { \
1488 if (!this->emit##OP##f(getFPOptions(E), E)) \
1491 if (!this->emit##OP(ElemT, E)) \
1497 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1498 if (!getElem(LHSOffset, ElemT, I))
1500 if (!getElem(RHSOffset, RHSElemT, I))
1512 if (!this->emitRem(ElemT, E))
1516 if (!this->emitBitAnd(OpT, E))
1520 if (!this->emitBitOr(OpT, E))
1524 if (!this->emitBitXor(OpT, E))
1528 if (!this->emitShl(OpT, RHSElemT, E))
1532 if (!this->emitShr(OpT, RHSElemT, E))
1536 if (!this->emitEQ(ElemT, E))
1540 if (!this->emitNE(ElemT, E))
1544 if (!this->emitLE(ElemT, E))
1548 if (!this->emitLT(ElemT, E))
1552 if (!this->emitGE(ElemT, E))
1556 if (!this->emitGT(ElemT, E))
1561 if (!this->emitBitAnd(ResultElemT, E))
1566 if (!this->emitBitOr(ResultElemT, E))
1570 return this->emitInvalid(E);
1579 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1581 if (!this->emitNeg(ResultElemT, E))
1587 if (NeedIntPromot &&
1588 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1592 if (!this->emitInitElem(ResultElemT, I, E))
1601template <
class Emitter>
1611 auto LHSSemaInt = LHSSema.toOpaqueInt();
1613 auto RHSSemaInt = RHSSema.toOpaqueInt();
1615 if (!this->
visit(LHS))
1623 if (!this->
visit(RHS))
1632 auto ConvertResult = [&](
bool R) ->
bool {
1636 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1637 if (ResultSema != CommonSema)
1638 return this->emitCastFixedPoint(ResultSema, E);
1642 auto MaybeCastToBool = [&](
bool Result) {
1647 return this->emitPop(
T, E);
1649 return this->emitCast(
PT_Bool,
T, E);
1655 return MaybeCastToBool(this->emitEQFixedPoint(E));
1657 return MaybeCastToBool(this->emitNEFixedPoint(E));
1659 return MaybeCastToBool(this->emitLTFixedPoint(E));
1661 return MaybeCastToBool(this->emitLEFixedPoint(E));
1663 return MaybeCastToBool(this->emitGTFixedPoint(E));
1665 return MaybeCastToBool(this->emitGEFixedPoint(E));
1667 return ConvertResult(this->emitAddFixedPoint(E));
1669 return ConvertResult(this->emitSubFixedPoint(E));
1671 return ConvertResult(this->emitMulFixedPoint(E));
1673 return ConvertResult(this->emitDivFixedPoint(E));
1675 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1677 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1680 return this->emitInvalid(E);
1683 llvm_unreachable(
"unhandled binop opcode");
1686template <
class Emitter>
1695 if (!this->
visit(SubExpr))
1697 return this->emitNegFixedPoint(E);
1702 llvm_unreachable(
"Unhandled unary opcode");
1705template <
class Emitter>
1711 return this->visitZeroInitializer(*
T, QT, E);
1719 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1720 CXXRD && CXXRD->getNumVBases() > 0) {
1730 return this->visitZeroRecordInitializer(R, E);
1737 return this->visitZeroArrayInitializer(QT, E);
1741 QualType ElemQT = ComplexTy->getElementType();
1743 for (
unsigned I = 0; I < 2; ++I) {
1744 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1746 if (!this->emitInitElem(ElemT, I, E))
1753 unsigned NumVecElements = VecT->getNumElements();
1754 QualType ElemQT = VecT->getElementType();
1757 for (
unsigned I = 0; I < NumVecElements; ++I) {
1758 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1760 if (!this->emitInitElem(ElemT, I, E))
1769template <
class Emitter>
1779 for (
const Expr *SubExpr : {LHS, RHS}) {
1780 if (!this->
visit(SubExpr)) {
1787 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
1788 if (!this->emitExpandPtr(E))
1799 return this->emitError(E);
1802 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
1806 if (!this->emitArrayElemPtrPop(*IndexT, E))
1809 return this->emitPopPtr(E);
1815 return this->emitLoadPop(*
T, E);
1818template <
class Emitter>
1820 const Expr *ArrayFiller,
const Expr *E) {
1825 QT = AT->getValueType();
1828 if (Inits.size() == 0)
1830 return this->emitInvalid(E);
1845 if (Inits.size() == 0)
1846 return this->visitZeroInitializer(*
T, QT, E);
1847 assert(Inits.size() == 1);
1854 if (Inits.size() == 1 && E->
getType() == Inits[0]->getType())
1860 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
1867 bool BitField = FieldToInit->isBitField();
1869 return this->emitInitBitFieldActivate(
T, FieldToInit, E);
1871 return this->emitInitBitField(
T, FieldToInit, E);
1873 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
1874 return this->emitInitField(
T, FieldToInit->Offset, E);
1877 auto initCompositeField = [=](
const Record::Field *FieldToInit,
1885 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
1888 if (
Activate && !this->emitActivate(E))
1893 return this->emitPopPtr(E);
1897 if (Inits.size() == 0) {
1898 if (!this->visitZeroRecordInitializer(R, E))
1903 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
1904 FToInit = ILE->getInitializedFieldInUnion();
1908 const Record::Field *FieldToInit = R->
getField(FToInit);
1910 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
1913 if (!initCompositeField(FieldToInit,
Init,
true))
1917 return this->emitFinishInit(E);
1921 unsigned InitIndex = 0;
1924 while (InitIndex < R->getNumFields() &&
1929 const Record::Field *FieldToInit = R->
getField(InitIndex);
1930 if (!initPrimitiveField(FieldToInit,
Init, *
T))
1935 if (
const Record::Base *B = R->
getBase(
Init->getType())) {
1936 if (!this->emitGetPtrBase(B->Offset,
Init))
1942 if (!this->emitFinishInitPop(E))
1947 const Record::Field *FieldToInit = R->
getField(InitIndex);
1948 if (!initCompositeField(FieldToInit,
Init))
1954 return this->emitFinishInit(E);
1958 if (Inits.size() == 1 && QT == Inits[0]->getType())
1962 Ctx.getASTContext().getAsConstantArrayType(QT);
1965 if (!this->emitCheckArraySize(NumElems, E))
1969 unsigned ElementIndex = 0;
1971 if (
const auto *EmbedS =
1972 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
1980 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
1981 getFPOptions(E), E))
1987 return this->emitInitElem(TargetT, ElemIndex, IL);
1989 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2001 for (; ElementIndex != NumElems; ++ElementIndex) {
2007 return this->emitFinishInit(E);
2011 unsigned NumInits = Inits.size();
2016 QualType ElemQT = ComplexTy->getElementType();
2018 if (NumInits == 0) {
2020 for (
unsigned I = 0; I < 2; ++I) {
2021 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2023 if (!this->emitInitElem(ElemT, I, E))
2026 }
else if (NumInits == 2) {
2027 unsigned InitIndex = 0;
2032 if (!this->emitInitElem(ElemT, InitIndex, E))
2041 unsigned NumVecElements = VecT->getNumElements();
2042 assert(NumVecElements >= Inits.size());
2044 QualType ElemQT = VecT->getElementType();
2048 unsigned InitIndex = 0;
2055 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2056 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2057 InitVecT->getNumElements(), E))
2059 InitIndex += InitVecT->getNumElements();
2061 if (!this->emitInitElem(ElemT, InitIndex, E))
2067 assert(InitIndex <= NumVecElements);
2070 for (; InitIndex != NumVecElements; ++InitIndex) {
2071 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2073 if (!this->emitInitElem(ElemT, InitIndex, E))
2084template <
class Emitter>
2091 return this->emitInitElem(*InitT, ElemIndex,
Init);
2097 if (!this->emitConstUint32(ElemIndex,
Init))
2099 if (!this->emitArrayElemPtrUint32(
Init))
2103 return this->emitFinishInitPop(
Init);
2106template <
class Emitter>
2109 bool Activate,
bool IsOperatorCall) {
2111 llvm::BitVector NonNullArgs;
2112 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2115 bool ExplicitMemberFn =
false;
2116 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2117 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2119 unsigned ArgIndex = 0;
2120 for (
const Expr *Arg : Args) {
2122 if (!this->
visit(Arg))
2130 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2131 if (DeclIndex < FuncDecl->getNumParams())
2132 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2142 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2150 if (!this->emitActivate(Arg))
2154 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2157 if (!this->emitCheckNonNullArg(ArgT, Arg))
2168template <
class Emitter>
2173template <
class Emitter>
2179template <
class Emitter>
2185template <
class Emitter>
2201template <
class Emitter>
2203 auto It = E->
begin();
2204 return this->
visit(*It);
2209 bool AlignOfReturnsPreferred =
2210 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2216 T = Ref->getPointeeType();
2218 if (
T.getQualifiers().hasUnaligned())
2224 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2230template <
class Emitter>
2236 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2242 ArgType = Ref->getPointeeType();
2248 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2249 return this->emitInvalid(E);
2251 if (Kind == UETT_SizeOf)
2260 return this->emitConst(Size.getQuantity(), E);
2263 if (Kind == UETT_CountOf) {
2269 if (
const auto *CAT =
2273 return this->emitConst(CAT->getSize(), E);
2283 if (VAT->getElementType()->isArrayType()) {
2284 std::optional<APSInt> Res =
2286 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2291 return this->emitConst(*Res, E);
2296 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2313 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2316 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2326 return this->emitConst(Size.getQuantity(), E);
2329 if (Kind == UETT_VectorElements) {
2331 return this->emitConst(VT->getNumElements(), E);
2333 return this->emitSizelessVectorElementSize(E);
2336 if (Kind == UETT_VecStep) {
2338 unsigned N = VT->getNumElements();
2345 return this->emitConst(N, E);
2347 return this->emitConst(1, E);
2350 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2357 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2359 return this->emitInvalid(E);
2361 return this->emitConst(
2362 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2370template <
class Emitter>
2381 const auto maybeLoadValue = [&]() ->
bool {
2385 return this->emitLoadPop(*
T, E);
2389 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2393 if (
auto GlobalIndex =
P.getGlobal(VD))
2394 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2399 if (!this->
discard(Base) && !this->emitSideEffect(E))
2414 const Record::Field *F = R->
getField(FD);
2416 if (F->Decl->getType()->isReferenceType())
2417 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2418 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2421template <
class Emitter>
2430template <
class Emitter>
2449 for (
size_t I = 0; I != Size; ++I) {
2461template <
class Emitter>
2472 return this->emitGetLocal(SubExprT, It->second, E);
2474 if (!this->
visit(SourceExpr))
2481 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2487 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2497template <
class Emitter>
2518 bool IsBcpCall =
false;
2519 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2520 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2524 LabelTy LabelEnd = this->getLabel();
2525 LabelTy LabelFalse = this->getLabel();
2528 if (!this->emitStartSpeculation(E))
2536 if (this->checkingForUndefinedBehavior()) {
2539 if (!this->
discard(FalseExpr))
2545 if (!this->jumpFalse(LabelFalse))
2550 if (!this->jump(LabelEnd))
2552 this->emitLabel(LabelFalse);
2556 this->fallthrough(LabelEnd);
2557 this->emitLabel(LabelEnd);
2560 return this->emitEndSpeculation(E);
2564template <
class Emitter>
2570 unsigned StringIndex =
P.createGlobalString(E);
2571 return this->emitGetPtrGlobal(StringIndex, E);
2576 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2577 assert(CAT &&
"a string literal that's not a constant array?");
2582 unsigned N = std::min(ArraySize, E->
getLength());
2585 for (
unsigned I = 0; I != N; ++I) {
2588 if (CharWidth == 1) {
2589 this->emitConstSint8(CodeUnit, E);
2590 this->emitInitElemSint8(I, E);
2591 }
else if (CharWidth == 2) {
2592 this->emitConstUint16(CodeUnit, E);
2593 this->emitInitElemUint16(I, E);
2594 }
else if (CharWidth == 4) {
2595 this->emitConstUint32(CodeUnit, E);
2596 this->emitInitElemUint32(I, E);
2598 llvm_unreachable(
"unsupported character width");
2603 for (
unsigned I = N; I != ArraySize; ++I) {
2604 if (CharWidth == 1) {
2605 this->emitConstSint8(0, E);
2606 this->emitInitElemSint8(I, E);
2607 }
else if (CharWidth == 2) {
2608 this->emitConstUint16(0, E);
2609 this->emitInitElemUint16(I, E);
2610 }
else if (CharWidth == 4) {
2611 this->emitConstUint32(0, E);
2612 this->emitInitElemUint32(I, E);
2614 llvm_unreachable(
"unsupported character width");
2621template <
class Emitter>
2625 return this->emitDummyPtr(E, E);
2628template <
class Emitter>
2630 auto &A =
Ctx.getASTContext();
2639template <
class Emitter>
2647 auto &A =
Ctx.getASTContext();
2651 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2652 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2659 unsigned StringIndex =
P.createGlobalString(SL);
2660 return this->emitGetPtrGlobal(StringIndex, E);
2663template <
class Emitter>
2667 return this->emitConst(E->
getValue(), E);
2670template <
class Emitter>
2696 if (!this->emitSetLocal(*RT, TempOffset, E))
2702 if (!this->emitLoad(LHST, E))
2706 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2707 LHSComputationType, E))
2711 if (!this->emitGetLocal(*RT, TempOffset, E))
2716 if (!this->emitAddf(getFPOptions(E), E))
2720 if (!this->emitSubf(getFPOptions(E), E))
2724 if (!this->emitMulf(getFPOptions(E), E))
2728 if (!this->emitDivf(getFPOptions(E), E))
2739 return this->emitStorePop(LHST, E);
2740 return this->emitStore(LHST, E);
2743template <
class Emitter>
2752 if (Op != BO_AddAssign && Op != BO_SubAssign)
2761 if (!this->emitLoad(*
LT, LHS))
2767 if (Op == BO_AddAssign) {
2768 if (!this->emitAddOffset(*RT, E))
2771 if (!this->emitSubOffset(*RT, E))
2776 return this->emitStorePopPtr(E);
2777 return this->emitStorePtr(E);
2780template <
class Emitter>
2793 if (!
Ctx.getLangOpts().CPlusPlus14)
2794 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2796 if (!
LT || !RT || !ResultT || !LHSComputationT)
2821 if (!this->emitSetLocal(*RT, TempOffset, E))
2828 if (!this->emitLoad(*
LT, E))
2830 if (
LT != LHSComputationT &&
2836 if (!this->emitGetLocal(*RT, TempOffset, E))
2842 if (!this->emitAdd(*LHSComputationT, E))
2846 if (!this->emitSub(*LHSComputationT, E))
2850 if (!this->emitMul(*LHSComputationT, E))
2854 if (!this->emitDiv(*LHSComputationT, E))
2858 if (!this->emitRem(*LHSComputationT, E))
2862 if (!this->emitShl(*LHSComputationT, *RT, E))
2866 if (!this->emitShr(*LHSComputationT, *RT, E))
2870 if (!this->emitBitAnd(*LHSComputationT, E))
2874 if (!this->emitBitXor(*LHSComputationT, E))
2878 if (!this->emitBitOr(*LHSComputationT, E))
2882 llvm_unreachable(
"Unimplemented compound assign operator");
2886 if (ResultT != LHSComputationT &&
2887 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
2893 return this->emitStoreBitFieldPop(*ResultT, E);
2894 return this->emitStorePop(*ResultT, E);
2897 return this->emitStoreBitField(*ResultT, E);
2898 return this->emitStore(*ResultT, E);
2901template <
class Emitter>
2909template <
class Emitter>
2921 return this->
discard(SubExpr);
2938 if (!this->
visit(SubExpr))
2940 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2942 return this->emitGetPtrGlobal(*GlobalIndex, E);
2945 if (!this->checkLiteralType(SubExpr))
2948 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2952 return this->emitInitGlobalTempComp(TempDecl, E);
2961 if (!this->
VarScope->LocalsAlwaysEnabled &&
2962 !this->emitEnableLocal(LocalIndex, E))
2965 if (!this->
visit(SubExpr))
2967 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2970 return this->emitGetPtrLocal(LocalIndex, E);
2973 if (!this->checkLiteralType(SubExpr))
2980 if (!this->
VarScope->LocalsAlwaysEnabled &&
2981 !this->emitEnableLocal(*LocalIndex, E))
2984 if (!this->emitGetPtrLocal(*LocalIndex, E))
2991template <
class Emitter>
3002 if (!this->
visit(SubExpr))
3006 return this->emitPopPtr(E);
3010template <
class Emitter>
3031 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3036 if (
P.isGlobalInitialized(*GlobalIndex))
3042 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3054 unsigned LocalIndex;
3058 LocalIndex = *MaybeIndex;
3062 if (!this->emitGetPtrLocal(LocalIndex, E))
3066 return this->
visit(
Init) && this->emitInit(*
T, E);
3070template <
class Emitter>
3083template <
class Emitter>
3087 return this->emitConst(E->
getValue(), E);
3090template <
class Emitter>
3103 for (
const Record::Field &F : R->
fields()) {
3105 if (!
Init ||
Init->containsErrors())
3113 if (!this->emitInitField(*
T, F.Offset, E))
3116 if (!this->emitGetPtrField(F.Offset, E))
3122 if (!this->emitPopPtr(E))
3130template <
class Emitter>
3137 return this->emitGetPtrGlobal(StringIndex, E);
3143template <
class Emitter>
3148 return this->emitInvalid(E);
3151template <
class Emitter>
3177 if (PointeeToT && PointeeFromT) {
3193 bool Fatal = (ToT != FromT);
3200template <
class Emitter>
3203 if (!
Ctx.getLangOpts().CPlusPlus20) {
3211template <
class Emitter>
3217 return this->emitConstBool(E->
getValue(), E);
3220template <
class Emitter>
3225 if (
T->isRecordType()) {
3239 if (!this->emitGetPtrLocal(*LocalIndex, E))
3247 T->getAsCXXRecordDecl()))
3255 if (!this->visitZeroRecordInitializer(R, E))
3267 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3269 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3270 if (!this->emitCheckFunctionDecl(Ctor, E))
3281 assert(
Func->hasThisPointer());
3282 assert(!
Func->hasRVO());
3286 if (!this->emitDupPtr(E))
3290 for (
const auto *Arg : E->
arguments()) {
3291 if (!this->
visit(Arg))
3295 if (
Func->isVariadic()) {
3296 uint32_t VarArgSize = 0;
3297 unsigned NumParams =
Func->getNumWrittenParams();
3298 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3302 if (!this->emitCallVar(
Func, VarArgSize, E))
3305 if (!this->emitCall(
Func, 0, E)) {
3310 (void)this->emitPopPtr(E);
3316 return this->emitPopPtr(E);
3317 return this->emitFinishInit(E);
3320 if (
T->isArrayType()) {
3325 if (!this->emitDupPtr(E))
3329 initArrayDimension = [&](
QualType T) ->
bool {
3330 if (!
T->isArrayType()) {
3332 for (
const auto *Arg : E->
arguments()) {
3333 if (!this->
visit(Arg))
3337 return this->emitCall(
Func, 0, E);
3341 Ctx.getASTContext().getAsConstantArrayType(
T);
3346 for (
size_t I = 0; I != NumElems; ++I) {
3347 if (!this->emitConstUint64(I, E))
3349 if (!this->emitArrayElemPtrUint64(E))
3351 if (!initArrayDimension(ElemTy))
3354 return this->emitPopPtr(E);
3357 return initArrayDimension(E->
getType());
3363template <
class Emitter>
3373 assert(Val.
isInt());
3375 return this->emitConst(I, E);
3382 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3383 return this->
visit(LValueExpr);
3398 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3402 const APValue &
V = UGCD->getValue();
3403 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3404 const Record::Field *F = R->
getField(I);
3405 const APValue &FieldValue =
V.getStructField(I);
3411 if (!this->emitInitField(FieldT, F->Offset, E))
3419template <
class Emitter>
3425 for (
unsigned I = 0; I != N; ++I) {
3432 if (!this->
discard(ArrayIndexExpr))
3437 if (!this->
visit(ArrayIndexExpr))
3441 if (!this->emitCast(IndexT,
PT_Sint64, E))
3451 return this->emitOffsetOf(
T, E, E);
3454template <
class Emitter>
3463 return this->visitZeroInitializer(*
T, Ty, E);
3470 if (!this->emitGetPtrLocal(*LocalIndex, E))
3475 QualType ElemQT = CT->getElementType();
3478 for (
unsigned I = 0; I != 2; ++I) {
3479 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3481 if (!this->emitInitElem(ElemT, I, E))
3493 if (!this->emitGetPtrLocal(*LocalIndex, E))
3498 QualType ElemQT = VT->getElementType();
3501 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3502 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3504 if (!this->emitInitElem(ElemT, I, E))
3513template <
class Emitter>
3518template <
class Emitter>
3524template <
class Emitter>
3529template <
class Emitter>
3534 return this->emitConst(E->
getValue(), E);
3537template <
class Emitter>
3542 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3560 if (!this->emitGetParam(PT, Offset, E))
3565 return this->emitCall(F, 0, E);
3570template <
class Emitter>
3578 const Expr *PlacementDest =
nullptr;
3579 bool IsNoThrow =
false;
3581 if (PlacementArgs != 0) {
3590 if (PlacementArgs == 1) {
3598 if (!this->emitInvalidNewDeleteExpr(E, E))
3603 if (OperatorNew->isReservedGlobalPlacementOperator())
3604 PlacementDest = Arg1;
3608 return this->emitInvalid(E);
3610 }
else if (!OperatorNew
3611 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3612 return this->emitInvalidNewDeleteExpr(E, E);
3615 if (!PlacementDest) {
3620 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3623 Desc =
P.createDescriptor(
3626 false,
false,
false,
3632 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3636 const Expr *Stripped = *ArraySizeExpr;
3637 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3638 Stripped = ICE->getSubExpr())
3639 if (ICE->getCastKind() != CK_NoOp &&
3640 ICE->getCastKind() != CK_IntegralCast)
3648 if (!this->
visit(Stripped))
3650 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3653 if (PlacementDest) {
3654 if (!this->
visit(PlacementDest))
3656 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3658 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3661 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3666 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3670 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3677 size_t StaticInitElems = 0;
3678 const Expr *DynamicInit =
nullptr;
3680 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3681 StaticInitElems = CAT->getZExtSize();
3685 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init);
3686 ILE && ILE->hasArrayFiller())
3687 DynamicInit = ILE->getArrayFiller();
3701 const Function *CtorFunc =
nullptr;
3702 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3706 }
else if (!DynamicInit)
3709 LabelTy EndLabel = this->getLabel();
3710 LabelTy StartLabel = this->getLabel();
3715 if (!this->emitDupPtr(E))
3717 if (!this->emitNullPtr(0,
nullptr, E))
3719 if (!this->emitEQPtr(E))
3721 if (!this->jumpTrue(EndLabel))
3728 if (!this->emitConst(StaticInitElems,
SizeT, E))
3730 if (!this->emitSetLocal(
SizeT, Iter, E))
3733 this->fallthrough(StartLabel);
3734 this->emitLabel(StartLabel);
3736 if (!this->emitGetLocal(
SizeT, Iter, E))
3738 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3740 if (!this->emitLT(
SizeT, E))
3742 if (!this->jumpFalse(EndLabel))
3746 if (!this->emitGetLocal(
SizeT, Iter, E))
3748 if (!this->emitArrayElemPtr(
SizeT, E))
3751 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3756 if (!this->visitZeroInitializer(InitT, ElemType, E))
3758 if (!this->emitStorePop(InitT, E))
3760 }
else if (DynamicInit) {
3762 if (!this->
visit(DynamicInit))
3764 if (!this->emitStorePop(*InitT, E))
3769 if (!this->emitPopPtr(E))
3774 if (!this->emitCall(CtorFunc, 0, E))
3779 if (!this->emitGetPtrLocal(Iter, E))
3781 if (!this->emitIncPop(
SizeT,
false, E))
3784 if (!this->jump(StartLabel))
3787 this->fallthrough(EndLabel);
3788 this->emitLabel(EndLabel);
3792 if (PlacementDest) {
3793 if (!this->
visit(PlacementDest))
3795 if (!this->emitCheckNewTypeMismatch(E, E))
3800 if (!this->emitAlloc(Desc, E))
3809 if (!this->emitInit(*ElemT, E))
3820 return this->emitPopPtr(E);
3825template <
class Emitter>
3831 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3832 return this->emitInvalidNewDeleteExpr(E, E);
3835 if (!this->
visit(Arg))
3841template <
class Emitter>
3847 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3852 return this->emitGetFnPtr(
Func, E);
3855template <
class Emitter>
3859 auto canonType = [](
const Type *
T) {
3860 return T->getCanonicalTypeUnqualified().getTypePtr();
3868 return this->emitGetTypeid(
3872 return this->emitGetTypeid(
3881 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3887 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3890 return this->emitPopPtr(E);
3894template <
class Emitter>
3896 assert(
Ctx.getLangOpts().CPlusPlus);
3897 return this->emitConstBool(E->
getValue(), E);
3900template <
class Emitter>
3912 return this->emitDummyPtr(GuidDecl, E);
3917 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3926 assert(
V.isStruct());
3927 assert(
V.getStructNumBases() == 0);
3931 return this->emitFinishInit(E);
3934template <
class Emitter>
3944template <
class Emitter>
3953template <
class Emitter>
3959template <
class Emitter>
3963 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
3967 if (OVE->isUnique())
3983template <
class Emitter>
3988template <
class Emitter>
3990 return this->emitError(E);
3993template <
class Emitter>
3999 return this->emitDummyPtr(E, E);
4002template <
class Emitter>
4006 QualType ElemType = VT->getElementType();
4010 PrimType SrcElemT = classifyVectorElementType(SrcType);
4012 unsigned SrcOffset =
4014 if (!this->
visit(Src))
4016 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4019 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4020 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4022 if (!this->emitArrayElemPop(SrcElemT, I, E))
4026 if (SrcElemT != ElemT) {
4027 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4029 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4030 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4034 if (!this->emitInitElem(ElemT, I, E))
4041template <
class Emitter>
4045 return this->emitInvalid(E);
4055 assert(NumOutputElems > 0);
4058 unsigned VectorOffsets[2];
4059 for (
unsigned I = 0; I != 2; ++I) {
4062 if (!this->
visit(Vecs[I]))
4064 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4067 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4069 assert(ShuffleIndex >= -1);
4070 if (ShuffleIndex == -1)
4071 return this->emitInvalidShuffleVectorIndex(I, E);
4073 assert(ShuffleIndex < (NumInputElems * 2));
4074 if (!this->emitGetLocal(
PT_Ptr,
4075 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4077 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4078 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4081 if (!this->emitInitElem(ElemT, I, E))
4088template <
class Emitter>
4093 Base->getType()->isVectorType() ||
4099 if (Indices.size() == 1) {
4104 if (!this->emitConstUint32(Indices[0], E))
4106 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4116 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4124 if (!this->emitGetPtrLocal(*ResultIndex, E))
4132 uint32_t DstIndex = 0;
4133 for (uint32_t I : Indices) {
4134 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4136 if (!this->emitArrayElemPop(ElemT, I, E))
4138 if (!this->emitInitElem(ElemT, DstIndex, E))
4148template <
class Emitter>
4152 return this->
discard(SubExpr) && this->emitInvalid(E);
4158 return this->emitDummyPtr(E, E);
4161template <
class Emitter>
4166 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4171 if (!this->
visit(SubExpr))
4173 if (!this->emitConstUint8(0, E))
4175 if (!this->emitArrayElemPtrPopUint8(E))
4182 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4184 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4186 assert(SecondFieldT ==
PT_Ptr);
4190 if (!this->emitExpandPtr(E))
4194 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4199template <
class Emitter>
4214 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4216 return this->emitUnsupported(E);
4225 return this->
Visit(E);
4232 return this->
Visit(E);
4236 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4239 if (
const auto *CE = dyn_cast<CastExpr>(E);
4241 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4248 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4251 if (
const auto *CE = dyn_cast<CastExpr>(E);
4252 CE && (CE->getCastKind() == CK_DerivedToBase ||
4253 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4254 CE->getCastKind() == CK_NoOp))
4273 if (!this->emitGetPtrLocal(*LocalIndex, E))
4283 return this->
Visit(E);
4286template <
class Emitter>
4292 return this->
Visit(E);
4298 return this->
Visit(E);
4306 if (!this->
visit(E))
4308 return this->emitComplexBoolCast(E);
4313 if (!this->
visit(E))
4321 return this->emitIsNonNullPtr(E);
4325 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4328 return this->emitCast(*
T,
PT_Bool, E);
4331template <
class Emitter>
4335 QT = AT->getValueType();
4339 return this->emitZeroBool(E);
4341 return this->emitZeroSint8(E);
4343 return this->emitZeroUint8(E);
4345 return this->emitZeroSint16(E);
4347 return this->emitZeroUint16(E);
4349 return this->emitZeroSint32(E);
4351 return this->emitZeroUint32(E);
4353 return this->emitZeroSint64(E);
4355 return this->emitZeroUint64(E);
4357 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4359 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4361 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4364 return this->emitNullMemberPtr(0,
nullptr, E);
4366 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4367 return this->emitFloat(F, E);
4370 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4374 llvm_unreachable(
"unknown primitive type");
4377template <
class Emitter>
4378bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4383 for (
const Record::Field &Field : R->
fields()) {
4384 if (Field.isUnnamedBitField())
4391 if (!this->visitZeroInitializer(
T, QT, E))
4394 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4398 if (!this->emitInitField(
T, Field.Offset, E))
4403 if (!this->emitGetPtrField(Field.Offset, E))
4409 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4410 if (!this->visitZeroInitializer(
T, ET, E))
4412 if (!this->emitInitElem(
T, I, E))
4417 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4420 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4428 if (!this->emitFinishInitActivatePop(E))
4432 if (!this->emitFinishInitPop(E))
4436 for (
const Record::Base &B : R->
bases()) {
4437 if (!this->emitGetPtrBase(B.Offset, E))
4439 if (!this->visitZeroRecordInitializer(B.R, E))
4441 if (!this->emitFinishInitPop(E))
4450template <
class Emitter>
4451bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4452 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4453 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4458 for (
size_t I = 0; I != NumElems; ++I) {
4459 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4461 if (!this->emitInitElem(*ElemT, I, E))
4467 const Record *R = getRecord(ElemType);
4469 for (
size_t I = 0; I != NumElems; ++I) {
4470 if (!this->emitConstUint32(I, E))
4472 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4474 if (!this->visitZeroRecordInitializer(R, E))
4476 if (!this->emitPopPtr(E))
4482 for (
size_t I = 0; I != NumElems; ++I) {
4483 if (!this->emitConstUint32(I, E))
4485 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4487 if (!this->visitZeroArrayInitializer(ElemType, E))
4489 if (!this->emitPopPtr(E))
4498template <
class Emitter>
4499bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4501 if (!canClassify(E->
getType()))
4504 if (!this->visit(RHS))
4506 if (!this->visit(LHS))
4513 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4517 bool Activates = refersToUnion(LHS);
4520 if (!this->emitFlip(
PT_Ptr, RHT, E))
4523 if (DiscardResult) {
4524 if (BitField && Activates)
4525 return this->emitStoreBitFieldActivatePop(RHT, E);
4527 return this->emitStoreBitFieldPop(RHT, E);
4529 return this->emitStoreActivatePop(RHT, E);
4531 return this->emitStorePop(RHT, E);
4534 auto maybeLoad = [&](
bool Result) ->
bool {
4540 return this->emitLoadPop(RHT, E);
4544 if (BitField && Activates)
4545 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4547 return maybeLoad(this->emitStoreBitField(RHT, E));
4549 return maybeLoad(this->emitStoreActivate(RHT, E));
4551 return maybeLoad(this->emitStore(RHT, E));
4554template <
class Emitter>
4555template <
typename T>
4559 return this->emitConstSint8(
Value, E);
4561 return this->emitConstUint8(
Value, E);
4563 return this->emitConstSint16(
Value, E);
4565 return this->emitConstUint16(
Value, E);
4567 return this->emitConstSint32(
Value, E);
4569 return this->emitConstUint32(
Value, E);
4571 return this->emitConstSint64(
Value, E);
4573 return this->emitConstUint64(
Value, E);
4575 return this->emitConstBool(
Value, E);
4582 llvm_unreachable(
"Invalid integral type");
4585 llvm_unreachable(
"unknown primitive type");
4588template <
class Emitter>
4589template <
typename T>
4590bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4591 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4594template <
class Emitter>
4598 return this->emitConstIntAPS(
Value, E);
4600 return this->emitConstIntAP(
Value, E);
4602 if (
Value.isSigned())
4603 return this->emitConst(
Value.getSExtValue(), Ty, E);
4604 return this->emitConst(
Value.getZExtValue(), Ty, E);
4607template <
class Emitter>
4611 return this->emitConstIntAPS(
Value, E);
4613 return this->emitConstIntAP(
Value, E);
4616 return this->emitConst(
Value.getSExtValue(), Ty, E);
4617 return this->emitConst(
Value.getZExtValue(), Ty, E);
4620template <
class Emitter>
4621bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4622 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4625template <
class Emitter>
4637 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4638 Locals.insert({VD, Local});
4640 VarScope->addExtended(Local, ExtendingDecl);
4642 VarScope->addForScopeKind(Local, SC);
4643 return Local.Offset;
4646template <
class Emitter>
4650 bool IsConstexprUnknown) {
4653 bool IsTemporary =
false;
4654 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4657 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4658 Init = VarD->getInit();
4660 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4668 IsTemporary,
false,
false,
Init);
4670 return std::nullopt;
4675 Locals.insert({Key, Local});
4677 VarScope->addExtended(Local, ExtendingDecl);
4679 VarScope->addForScopeKind(Local, SC);
4680 return Local.Offset;
4683template <
class Emitter>
4693 return std::nullopt;
4703 return Local.Offset;
4706template <
class Emitter>
4708 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
4709 return PT->getPointeeType()->getAsCanonical<RecordType>();
4715 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
4719template <
class Emitter>
4721 return P.getOrCreateRecord(RD);
4724template <
class Emitter>
4726 return Ctx.getOrCreateFunction(FD);
4729template <
class Emitter>
4734 if (!DestroyToplevelScope) {
4735 if (!this->emitCheckAllocations(E))
4739 auto maybeDestroyLocals = [&]() ->
bool {
4740 if (DestroyToplevelScope)
4741 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
4742 return this->emitCheckAllocations(E);
4749 return this->emitRetVoid(E) && maybeDestroyLocals();
4757 return this->emitRet(*
T, E) && maybeDestroyLocals();
4765 if (!this->emitGetPtrLocal(*LocalOffset, E))
4771 if (!this->emitFinishInit(E))
4776 return this->emitRetValue(E) && maybeDestroyLocals();
4779 return maybeDestroyLocals() && this->emitCheckAllocations(E) &&
false;
4782template <
class Emitter>
4784 bool IsConstexprUnknown) {
4787 IsConstexprUnknown);
4796 if (
auto GlobalIndex =
P.getGlobal(VD)) {
4797 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4812template <
class Emitter>
4814 bool ConstantContext) {
4817 if (!ConstantContext) {
4831 auto GlobalIndex =
P.getGlobal(VD);
4832 assert(GlobalIndex);
4834 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
4837 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
4841 auto Local =
Locals.find(VD);
4842 assert(Local !=
Locals.end());
4844 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
4847 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
4857 auto GlobalIndex =
P.getGlobal(VD);
4858 assert(GlobalIndex);
4859 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4869 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
4872template <
class Emitter>
4875 bool Toplevel,
bool IsConstexprUnknown) {
4882 if (!this->isActive())
4887 if (
Init &&
Init->isValueDependent())
4891 auto checkDecl = [&]() ->
bool {
4893 return !NeedsOp || this->emitCheckDecl(VD, VD);
4901 if (
P.getPtrGlobal(*GlobalIndex).isInitialized())
4905 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
4919 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
4922 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
4928 return this->emitFinishInitGlobal(
Init);
4937 IsConstexprUnknown);
4948 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
4952 return this->emitSetLocal(*VarT, Offset, VD);
4960 if (!this->emitGetPtrLocal(*Offset,
Init))
4966 return this->emitFinishInitPop(
Init);
4971template <
class Emitter>
4976 return this->emitConst(Val.
getInt(), ValType, E);
4979 return this->emitFloat(F, E);
4984 return this->emitNull(ValType, 0,
nullptr, E);
4986 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
4987 return this->
visit(BaseExpr);
4992 return this->emitGetMemberPtr(MemberDecl, E);
4993 return this->emitNullMemberPtr(0,
nullptr, E);
4999template <
class Emitter>
5007 const Record::Field *RF = R->
getField(I);
5008 QualType FieldType = RF->Decl->getType();
5013 if (!this->emitInitField(*PT, RF->Offset, E))
5016 if (!this->emitGetPtrField(RF->Offset, E))
5020 if (!this->emitPopPtr(E))
5031 const Record::Field *RF = R->
getField(UnionField);
5035 return this->emitInitField(
T, RF->Offset, E);
5038 const auto *ArrType =
T->getAsArrayTypeUnsafe();
5039 QualType ElemType = ArrType->getElementType();
5040 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5045 if (!this->emitInitElem(*ElemT, A, E))
5048 if (!this->emitConstUint32(A, E))
5050 if (!this->emitArrayElemPtrUint32(E))
5054 if (!this->emitPopPtr(E))
5065template <
class Emitter>
5067 unsigned BuiltinID) {
5068 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5073 return this->emitConst(0, E);
5076 if (!this->emitStartSpeculation(E))
5078 LabelTy EndLabel = this->getLabel();
5079 if (!this->speculate(E, EndLabel))
5081 this->fallthrough(EndLabel);
5082 if (!this->emitEndSpeculation(E))
5091 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5092 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5093 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5094 BuiltinID == Builtin::BI__builtin_function_start) {
5097 return this->emitDummyPtr(E, E);
5108 if (!this->emitGetPtrLocal(*LocalIndex, E))
5113 switch (BuiltinID) {
5114 case Builtin::BI__builtin_object_size:
5115 case Builtin::BI__builtin_dynamic_object_size: {
5119 if (!this->
visit(Arg0))
5133 for (
const auto *Arg : E->
arguments()) {
5134 if (!this->
visit(Arg))
5140 if (!this->emitCallBI(E, BuiltinID, E))
5145 return this->emitPop(*ReturnT, E);
5151template <
class Emitter>
5168 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5169 DD && DD->isTrivial()) {
5171 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5173 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5174 this->emitPopPtr(E);
5190 if (!this->emitGetPtrLocal(*LocalIndex, E))
5198 if (!this->emitGetPtrLocal(*LocalIndex, E))
5202 if (!this->emitDupPtr(E))
5209 bool IsAssignmentOperatorCall =
false;
5210 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5211 OCE && OCE->isAssignmentOp()) {
5215 assert(Args.size() == 2);
5216 IsAssignmentOperatorCall =
true;
5217 std::reverse(Args.begin(), Args.end());
5223 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5224 MD && MD->isStatic()) {
5228 Args.erase(Args.begin());
5232 bool Devirtualized =
false;
5235 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5243 if (!this->
visit(Callee))
5245 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5247 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5249 if (!this->emitGetMemberPtrBase(E))
5252 const auto *InstancePtr = MC->getImplicitObjectArgument();
5259 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5260 Devirtualized =
true;
5261 if (!this->
visit(Stripped))
5264 if (!this->
visit(InstancePtr))
5268 if (!this->
visit(InstancePtr))
5272 }
else if (
const auto *PD =
5273 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5274 if (!this->emitCheckPseudoDtor(E))
5282 return this->emitEndLifetimePop(E);
5283 }
else if (!FuncDecl) {
5287 if (!this->
visit(Callee))
5289 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5293 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5298 if (IsAssignmentOperatorCall) {
5299 assert(Args.size() == 2);
5302 if (!this->emitFlip(Arg2T, Arg1T, E))
5316 assert(HasRVO ==
Func->hasRVO());
5318 bool HasQualifier =
false;
5319 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5320 HasQualifier = ME->hasQualifier();
5322 bool IsVirtual =
false;
5323 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5324 IsVirtual = !Devirtualized && MD->isVirtual();
5329 if (IsVirtual && !HasQualifier) {
5330 uint32_t VarArgSize = 0;
5331 unsigned NumParams =
5333 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5336 if (!this->emitCallVirt(
Func, VarArgSize, E))
5338 }
else if (
Func->isVariadic()) {
5339 uint32_t VarArgSize = 0;
5340 unsigned NumParams =
5342 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5344 if (!this->emitCallVar(
Func, VarArgSize, E))
5347 if (!this->emitCall(
Func, 0, E))
5356 uint32_t ArgSize = 0;
5357 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5363 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5365 if (!this->emitGetMemberPtrDecl(E))
5368 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5371 if (!this->emitCallPtr(ArgSize, E, E))
5382template <
class Emitter>
5389template <
class Emitter>
5396template <
class Emitter>
5401 return this->emitConstBool(E->
getValue(), E);
5404template <
class Emitter>
5410 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5411 return this->emitNullPtr(Val,
nullptr, E);
5414template <
class Emitter>
5422 return this->emitZero(
T, E);
5425template <
class Emitter>
5430 if (this->LambdaThisCapture.Offset > 0) {
5431 if (this->LambdaThisCapture.IsPtr)
5432 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5433 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5441 return this->emitThis(E);
5456 unsigned StartIndex = 0;
5457 unsigned EndIndex = 0;
5459 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5461 EndIndex = StartIndex;
5468 for (; StartIndex > 0; --StartIndex) {
5478 if (StartIndex == 0 && EndIndex == 0)
5481 assert(StartIndex < EndIndex);
5484 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5496 case Stmt::CompoundStmtClass:
5498 case Stmt::DeclStmtClass:
5500 case Stmt::ReturnStmtClass:
5502 case Stmt::IfStmtClass:
5504 case Stmt::WhileStmtClass:
5506 case Stmt::DoStmtClass:
5508 case Stmt::ForStmtClass:
5510 case Stmt::CXXForRangeStmtClass:
5512 case Stmt::BreakStmtClass:
5514 case Stmt::ContinueStmtClass:
5516 case Stmt::SwitchStmtClass:
5518 case Stmt::CaseStmtClass:
5520 case Stmt::DefaultStmtClass:
5522 case Stmt::AttributedStmtClass:
5524 case Stmt::CXXTryStmtClass:
5526 case Stmt::NullStmtClass:
5529 case Stmt::GCCAsmStmtClass:
5530 case Stmt::MSAsmStmtClass:
5531 case Stmt::GotoStmtClass:
5532 return this->emitInvalid(S);
5533 case Stmt::LabelStmtClass:
5536 if (
const auto *E = dyn_cast<Expr>(S))
5543template <
class Emitter>
5546 for (
const auto *InnerStmt : S->
body())
5549 return Scope.destroyLocals();
5552template <
class Emitter>
5553bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5554 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5555 for (
auto *BD : DD->flat_bindings())
5556 if (
auto *KD = BD->getHoldingVar();
5557 KD && !this->visitVarDecl(KD, KD->getInit()))
5566 const auto *CXXRD = dyn_cast<CXXRecordDecl>(FD->
getParent());
5567 return !CXXRD || CXXRD->hasTrivialDefaultConstructor();
5570template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5572 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5573 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5580 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5585 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5586 ICE && (ICE->getCastKind() == CK_NoOp ||
5587 ICE->getCastKind() == CK_DerivedToBase ||
5588 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5589 E = ICE->getSubExpr();
5593 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5594 const auto *ThisRecord =
5595 This->getType()->getPointeeType()->getAsRecordDecl();
5596 if (!ThisRecord->isUnion())
5599 if (
const auto *Ctor =
5600 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5601 return Ctor->getParent() == ThisRecord;
5610template <
class Emitter>
5612 bool EvaluateConditionDecl) {
5613 for (
const auto *D : DS->
decls()) {
5618 const auto *VD = dyn_cast<VarDecl>(D);
5625 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5632template <
class Emitter>
5635 return this->emitUnsupported(RS);
5641 if (!this->
visit(RE))
5647 if (RE->getType()->isVoidType()) {
5648 if (!this->
visit(RE))
5653 if (!this->emitRVOPtr(RE))
5657 if (!this->emitPopPtr(RE))
5661 return this->emitRetVoid(RS);
5667 return this->emitRetVoid(RS);
5671 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5677 if (
auto *CondInit = IS->
getInit())
5691 return visitChildStmt(IS->
getThen());
5693 return visitChildStmt(Else);
5699 if (!this->emitIsConstantContext(IS))
5702 if (!this->emitIsConstantContext(IS))
5704 if (!this->emitInv(IS))
5715 LabelTy LabelElse = this->getLabel();
5716 LabelTy LabelEnd = this->getLabel();
5717 if (!this->jumpFalse(LabelElse))
5719 if (!visitChildStmt(IS->
getThen()))
5721 if (!this->jump(LabelEnd))
5723 this->emitLabel(LabelElse);
5724 if (!visitChildStmt(Else))
5726 this->emitLabel(LabelEnd);
5728 LabelTy LabelEnd = this->getLabel();
5729 if (!this->jumpFalse(LabelEnd))
5731 if (!visitChildStmt(IS->
getThen()))
5733 this->emitLabel(LabelEnd);
5739template <
class Emitter>
5744 LabelTy CondLabel = this->getLabel();
5745 LabelTy EndLabel = this->getLabel();
5749 this->fallthrough(CondLabel);
5750 this->emitLabel(CondLabel);
5764 if (!this->jumpFalse(EndLabel))
5773 if (!this->jump(CondLabel))
5775 this->fallthrough(EndLabel);
5776 this->emitLabel(EndLabel);
5784 LabelTy StartLabel = this->getLabel();
5785 LabelTy EndLabel = this->getLabel();
5786 LabelTy CondLabel = this->getLabel();
5790 this->fallthrough(StartLabel);
5791 this->emitLabel(StartLabel);
5797 this->fallthrough(CondLabel);
5798 this->emitLabel(CondLabel);
5805 if (!this->jumpTrue(StartLabel))
5808 this->fallthrough(EndLabel);
5809 this->emitLabel(EndLabel);
5813template <
class Emitter>
5821 LabelTy EndLabel = this->getLabel();
5822 LabelTy CondLabel = this->getLabel();
5823 LabelTy IncLabel = this->getLabel();
5830 this->fallthrough(CondLabel);
5831 this->emitLabel(CondLabel);
5843 if (!this->jumpFalse(EndLabel))
5852 this->fallthrough(IncLabel);
5853 this->emitLabel(IncLabel);
5859 if (!this->jump(CondLabel))
5863 this->emitLabel(EndLabel);
5869template <
class Emitter>
5879 LabelTy EndLabel = this->getLabel();
5880 LabelTy CondLabel = this->getLabel();
5881 LabelTy IncLabel = this->getLabel();
5896 this->fallthrough(CondLabel);
5897 this->emitLabel(CondLabel);
5900 if (!this->jumpFalse(EndLabel))
5911 this->fallthrough(IncLabel);
5912 this->emitLabel(IncLabel);
5917 if (!this->jump(CondLabel))
5920 this->fallthrough(EndLabel);
5921 this->emitLabel(EndLabel);
5925template <
class Emitter>
5936 if (LI.BreakLabel) {
5937 TargetLabel = *LI.BreakLabel;
5938 BreakScope = LI.BreakOrContinueScope;
5944 if (LI.Name == TargetLoop) {
5945 TargetLabel = *LI.BreakLabel;
5946 BreakScope = LI.BreakOrContinueScope;
5952 assert(TargetLabel);
5955 C =
C->getParent()) {
5956 if (!
C->destroyLocals())
5960 return this->jump(*TargetLabel);
5963template <
class Emitter>
5974 if (LI.ContinueLabel) {
5975 TargetLabel = *LI.ContinueLabel;
5976 ContinueScope = LI.BreakOrContinueScope;
5982 if (LI.Name == TargetLoop) {
5983 TargetLabel = *LI.ContinueLabel;
5984 ContinueScope = LI.BreakOrContinueScope;
5989 assert(TargetLabel);
5992 C =
C->getParent()) {
5993 if (!
C->destroyLocals())
5997 return this->jump(*TargetLabel);
6000template <
class Emitter>
6003 if (
Cond->containsErrors())
6009 LabelTy EndLabel = this->getLabel();
6014 if (
const auto *CondInit = S->
getInit())
6025 if (!this->emitSetLocal(CondT, CondVar, S))
6035 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6038 if (CS->caseStmtIsGNURange()) {
6039 LabelTy EndOfRangeCheck = this->getLabel();
6040 const Expr *Low = CS->getLHS();
6041 const Expr *High = CS->getRHS();
6045 if (!this->emitGetLocal(CondT, CondVar, CS))
6047 if (!this->
visit(Low))
6050 if (!this->emitGE(
LT, S))
6052 if (!this->jumpFalse(EndOfRangeCheck))
6055 if (!this->emitGetLocal(CondT, CondVar, CS))
6057 if (!this->
visit(High))
6060 if (!this->emitLE(HT, S))
6064 this->emitLabel(EndOfRangeCheck);
6069 if (
Value->isValueDependent())
6074 if (!this->emitGetLocal(CondT, CondVar, CS))
6080 if (!this->emitEQ(ValueT, S))
6085 assert(!DefaultLabel);
6086 DefaultLabel = this->getLabel();
6093 if (!this->jump(*DefaultLabel))
6096 if (!this->jump(EndLabel))
6104 this->fallthrough(EndLabel);
6105 this->emitLabel(EndLabel);
6110template <
class Emitter>
6117template <
class Emitter>
6124 if (LI.DefaultLabel) {
6125 DefaultLabel = *LI.DefaultLabel;
6130 this->emitLabel(DefaultLabel);
6134template <
class Emitter>
6136 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6137 !this->Ctx.getLangOpts().MSVCCompat) {
6139 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6145 const Expr *Assumption = AA->getAssumption();
6156 if (!this->emitAssume(Assumption))
6165template <
class Emitter>
6171template <
class Emitter>
6172bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6179 assert(ClosureClass->
captures().empty());
6183 "A generic lambda's static-invoker function must be a "
6184 "template specialization");
6188 void *InsertPos =
nullptr;
6189 const FunctionDecl *CorrespondingCallOpSpecialization =
6191 assert(CorrespondingCallOpSpecialization);
6192 LambdaCallOp = CorrespondingCallOpSpecialization;
6196 assert(ClosureClass->
captures().empty());
6197 const Function *
Func = this->getFunction(LambdaCallOp);
6200 assert(
Func->hasThisPointer());
6203 if (
Func->hasRVO()) {
6204 if (!this->emitRVOPtr(MD))
6212 if (!this->emitNullPtr(0,
nullptr, MD))
6217 auto It = this->Params.find(PVD);
6218 assert(It != this->Params.end());
6222 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6223 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6227 if (!this->emitCall(
Func, 0, LambdaCallOp))
6232 return this->emitRet(*ReturnType, MD);
6235 return this->emitRetVoid(MD);
6238template <
class Emitter>
6239bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6240 if (Ctx.getLangOpts().CPlusPlus23)
6250 const Expr *InitExpr =
Init->getInit();
6252 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6256 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6266template <
class Emitter>
6268 assert(!ReturnType);
6270 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6271 const Expr *InitExpr,
6274 if (InitExpr->getType().isNull())
6278 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6281 if (!this->visit(InitExpr))
6284 bool BitField = F->isBitField();
6286 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6287 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6292 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6295 if (
Activate && !this->emitActivate(InitExpr))
6298 if (!this->visitInitializer(InitExpr))
6301 return this->emitFinishInitPop(InitExpr);
6305 const Record *R = this->getRecord(RD);
6314 return this->emitRetVoid(Ctor);
6317 if (!this->emitThis(Ctor))
6326 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6327 this->emitRetVoid(Ctor);
6331 for (
const auto *
Init : Ctor->
inits()) {
6333 LocalScope<Emitter>
Scope(
this);
6335 const Expr *InitExpr =
Init->getInit();
6341 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6344 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6347 if (
Init->isBaseVirtual()) {
6349 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6355 const Record::Base *B = R->
getBase(BaseDecl);
6357 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6361 if (IsUnion && !this->emitActivate(InitExpr))
6364 if (!this->visitInitializer(InitExpr))
6366 if (!this->emitFinishInitPop(InitExpr))
6371 assert(IFD->getChainingSize() >= 2);
6373 unsigned NestedFieldOffset = 0;
6374 const Record::Field *NestedField =
nullptr;
6375 for (
const NamedDecl *ND : IFD->chain()) {
6377 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6378 assert(FieldRecord);
6380 NestedField = FieldRecord->
getField(FD);
6381 assert(NestedField);
6382 IsUnion = IsUnion || FieldRecord->
isUnion();
6384 NestedFieldOffset += NestedField->Offset;
6386 assert(NestedField);
6388 unsigned FirstLinkOffset =
6392 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6397 unsigned InitFieldOffset = 0;
6398 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6400 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6401 assert(FieldRecord);
6402 NestedField = FieldRecord->
getField(FD);
6403 InitFieldOffset += NestedField->Offset;
6404 assert(NestedField);
6405 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6407 if (!this->emitFinishInitPop(InitExpr))
6412 assert(
Init->isDelegatingInitializer());
6413 if (!this->emitThis(InitExpr))
6415 if (!this->visitInitializer(
Init->getInit()))
6417 if (!this->emitPopPtr(InitExpr))
6421 if (!
Scope.destroyLocals())
6425 if (
const auto *Body = Ctor->
getBody())
6426 if (!visitStmt(Body))
6432template <
class Emitter>
6435 const Record *R = this->getRecord(RD);
6440 if (!this->visitStmt(Dtor->
getBody()))
6444 if (!this->emitThis(Dtor))
6447 if (!this->emitCheckDestruction(Dtor))
6455 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6459 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6461 if (!this->emitDestructionPop(D,
SourceInfo{}))
6466 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6467 if (
Base.R->hasTrivialDtor())
6471 if (!this->emitRecordDestructionPop(
Base.R, {}))
6476 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6479template <
class Emitter>
6480bool Compiler<Emitter>::compileUnionAssignmentOperator(
6482 if (!this->emitThis(MD))
6491 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6494template <
class Emitter>
6501 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6502 return this->compileConstructor(Ctor);
6503 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6504 return this->compileDestructor(Dtor);
6507 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6512 return this->compileUnionAssignmentOperator(MD);
6515 return this->emitLambdaStaticInvokerBody(MD);
6519 if (
const auto *Body = F->
getBody())
6533 return FD->getBitWidthValue();
6536template <
class Emitter>
6549 if (!
Ctx.getLangOpts().CPlusPlus14)
6550 return this->emitInvalid(E);
6552 return this->emitError(E);
6554 if (!this->
visit(SubExpr))
6558 if (!this->emitIncPtr(E))
6565 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6566 : this->emitIncf(getFPOptions(E), E);
6578 if (!
Ctx.getLangOpts().CPlusPlus14)
6579 return this->emitInvalid(E);
6581 return this->emitError(E);
6583 if (!this->
visit(SubExpr))
6587 if (!this->emitDecPtr(E))
6594 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6595 : this->emitDecf(getFPOptions(E), E);
6608 if (!
Ctx.getLangOpts().CPlusPlus14)
6609 return this->emitInvalid(E);
6611 return this->emitError(E);
6613 if (!this->
visit(SubExpr))
6617 if (!this->emitLoadPtr(E))
6619 if (!this->emitConstUint8(1, E))
6621 if (!this->emitAddOffsetUint8(E))
6623 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6629 return this->emitIncfPop(getFPOptions(E), E);
6639 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6640 if (!this->emitLoadFloat(E))
6642 APFloat F(TargetSemantics, 1);
6643 if (!this->emitFloat(F, E))
6646 if (!this->emitAddf(getFPOptions(E), E))
6648 if (!this->emitStoreFloat(E))
6660 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6663 if (!
Ctx.getLangOpts().CPlusPlus14)
6664 return this->emitInvalid(E);
6666 return this->emitError(E);
6668 if (!this->
visit(SubExpr))
6672 if (!this->emitLoadPtr(E))
6674 if (!this->emitConstUint8(1, E))
6676 if (!this->emitSubOffsetUint8(E))
6678 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6684 return this->emitDecfPop(getFPOptions(E), E);
6694 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6695 if (!this->emitLoadFloat(E))
6697 APFloat F(TargetSemantics, 1);
6698 if (!this->emitFloat(F, E))
6701 if (!this->emitSubf(getFPOptions(E), E))
6703 if (!this->emitStoreFloat(E))
6715 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6719 return this->emitError(E);
6722 return this->
discard(SubExpr);
6727 if (!this->emitInv(E))
6731 return this->emitCast(
PT_Bool, ET, E);
6735 return this->emitError(E);
6737 if (!this->
visit(SubExpr))
6742 return this->emitError(E);
6744 if (!this->
visit(SubExpr))
6757 return this->
discard(SubExpr);
6759 if (!this->
visit(SubExpr))
6766 return this->emitNarrowPtr(E);
6771 return this->emitError(E);
6773 if (!this->
visit(SubExpr))
6783 return this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6788 assert(
false &&
"Unhandled opcode");
6794template <
class Emitter>
6800 return this->
discard(SubExpr);
6803 auto prepareResult = [=]() ->
bool {
6808 return this->emitGetPtrLocal(*LocalIndex, E);
6815 unsigned SubExprOffset = ~0u;
6816 auto createTemp = [=, &SubExprOffset]() ->
bool {
6819 if (!this->
visit(SubExpr))
6821 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6825 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6826 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6828 return this->emitArrayElemPop(ElemT, Index, E);
6833 if (!prepareResult())
6837 for (
unsigned I = 0; I != 2; ++I) {
6838 if (!getElem(SubExprOffset, I))
6840 if (!this->emitNeg(ElemT, E))
6842 if (!this->emitInitElem(ElemT, I, E))
6853 if (!this->
visit(SubExpr))
6855 if (!this->emitComplexBoolCast(SubExpr))
6857 if (!this->emitInv(E))
6860 return this->emitCast(
PT_Bool, ET, E);
6864 return this->emitComplexReal(SubExpr);
6867 if (!this->
visit(SubExpr))
6871 if (!this->emitConstUint8(1, E))
6873 return this->emitArrayElemPtrPopUint8(E);
6881 if (!this->
visit(SubExpr))
6884 if (!this->emitArrayElem(ElemT, 1, E))
6886 if (!this->emitNeg(ElemT, E))
6888 if (!this->emitInitElem(ElemT, 1, E))
6896 return this->emitInvalid(E);
6902template <
class Emitter>
6908 return this->
discard(SubExpr);
6911 if (UnaryOp == UO_Extension)
6914 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6915 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6916 return this->emitInvalid(E);
6919 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
6926 if (!this->emitGetPtrLocal(*LocalIndex, E))
6931 unsigned SubExprOffset =
6933 if (!this->
visit(SubExpr))
6935 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
6940 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6941 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6943 return this->emitArrayElemPop(ElemT, Index, E);
6948 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6949 if (!getElem(SubExprOffset, I))
6951 if (!this->emitNeg(ElemT, E))
6953 if (!this->emitInitElem(ElemT, I, E))
6968 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6969 if (!getElem(SubExprOffset, I))
6972 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
6974 if (!this->emitInv(E))
6976 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
6978 if (!this->emitNeg(ElemT, E))
6980 if (ElemT != ResultVecElemT &&
6981 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
6983 if (!this->emitInitElem(ResultVecElemT, I, E))
6989 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6990 if (!getElem(SubExprOffset, I))
6993 if (!this->emitInv(E))
6996 if (!this->emitComp(ElemT, E))
6999 if (!this->emitInitElem(ElemT, I, E))
7004 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7009template <
class Emitter>
7014 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7015 return this->emitConst(ECD->getInitVal(), E);
7016 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7018 return F && this->emitGetFnPtr(F, E);
7020 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7022 if (!this->emitGetPtrGlobal(*Index, E))
7027 return this->emitInitGlobal(*
T, *Index, E);
7044 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7045 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7050 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7051 if (IsReference || !It->second.IsPtr)
7052 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
7054 return this->emitGetPtrParam(It->second.Offset, E);
7059 const unsigned Offset = It->second.Offset;
7062 return this->emitGetPtrLocal(Offset, E);
7065 if (
auto GlobalIndex =
P.getGlobal(D)) {
7067 if (!
Ctx.getLangOpts().CPlusPlus11)
7068 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7069 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7072 return this->emitGetPtrGlobal(*GlobalIndex, E);
7076 auto revisit = [&](
const VarDecl *VD) ->
bool {
7079 auto VarState = this->
visitDecl(VD,
true);
7081 if (!this->emitPopCC(E))
7084 if (VarState.notCreated())
7093 if (
auto It = this->LambdaCaptures.find(D);
7094 It != this->LambdaCaptures.end()) {
7095 auto [Offset, IsPtr] = It->second;
7098 return this->emitGetThisFieldPtr(Offset, E);
7099 return this->emitGetPtrThisField(Offset, E);
7102 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7103 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7104 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7108 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7109 return this->
visit(BD->getBinding());
7113 return this->emitDummyPtr(D, E);
7118 if (!
Ctx.getLangOpts().CPlusPlus) {
7119 if (
const auto *VD = dyn_cast<VarDecl>(D);
7123 return this->emitDummyPtr(D, E);
7127 const auto *VD = dyn_cast<VarDecl>(D);
7129 return this->emitDummyPtr(D, E);
7131 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7132 if (
T.isConstant(
Ctx.getASTContext()))
7134 return T->isReferenceType();
7138 typeShouldBeVisited(VD->
getType())) {
7140 Init && !
Init->isValueDependent()) {
7146 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7164 return this->emitDummyPtr(D, E);
7170 return this->emitDummyPtr(D, E);
7173template <
class Emitter>
7181 if (!
C->destroyLocals())
7187template <
class Emitter>
7188unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7191 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7193 return Ty->getAsCXXRecordDecl();
7195 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7196 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7198 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7202template <
class Emitter>
7209 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7214 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7215 getFPOptions(E), E);
7217 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7218 getFPOptions(E), E);
7222 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7227 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7229 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7233 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7237 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7238 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7245template <
class Emitter>
7248 assert(FromT != ToT);
7251 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7253 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7255 return this->emitCast(FromT, ToT, E);
7259template <
class Emitter>
7260bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7264 return this->
discard(SubExpr);
7266 if (!this->visit(SubExpr))
7269 if (!this->emitConstUint8(0, SubExpr))
7271 return this->emitArrayElemPtrPopUint8(SubExpr);
7275 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7279template <
class Emitter>
7280bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7281 assert(!DiscardResult);
7285 if (!this->emitArrayElem(ElemT, 0, E))
7288 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7291 if (!this->emitCast(ElemT,
PT_Bool, E))
7296 LabelTy LabelTrue = this->getLabel();
7297 if (!this->jumpTrue(LabelTrue))
7300 if (!this->emitArrayElemPop(ElemT, 1, E))
7303 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7306 if (!this->emitCast(ElemT,
PT_Bool, E))
7310 LabelTy EndLabel = this->getLabel();
7311 this->jump(EndLabel);
7313 this->emitLabel(LabelTrue);
7314 if (!this->emitPopPtr(E))
7316 if (!this->emitConstBool(
true, E))
7319 this->fallthrough(EndLabel);
7320 this->emitLabel(EndLabel);
7325template <
class Emitter>
7326bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7330 assert(!DiscardResult);
7336 LHSIsComplex =
true;
7337 ElemT = classifyComplexElementType(LHS->
getType());
7338 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7339 if (!this->visit(LHS))
7341 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7344 LHSIsComplex =
false;
7346 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7347 if (!this->visit(LHS))
7349 if (!this->emitSetLocal(LHST, LHSOffset, E))
7356 RHSIsComplex =
true;
7357 ElemT = classifyComplexElementType(RHS->
getType());
7358 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7359 if (!this->visit(RHS))
7361 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7364 RHSIsComplex =
false;
7366 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7367 if (!this->visit(RHS))
7369 if (!this->emitSetLocal(RHST, RHSOffset, E))
7373 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7374 bool IsComplex) ->
bool {
7376 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7378 return this->emitArrayElemPop(ElemT, Index, E);
7380 return this->emitGetLocal(ElemT, LocalOffset, E);
7383 for (
unsigned I = 0; I != 2; ++I) {
7385 if (!getElem(LHSOffset, I, LHSIsComplex))
7387 if (!getElem(RHSOffset, I, RHSIsComplex))
7390 if (!this->emitEQ(ElemT, E))
7393 if (!this->emitCastBoolUint8(E))
7398 if (!this->emitAddUint8(E))
7400 if (!this->emitConstUint8(2, E))
7404 if (!this->emitEQUint8(E))
7407 if (!this->emitNEUint8(E))
7414 return this->emitCast(
PT_Bool, ResT, E);
7421template <
class Emitter>
7422bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7428 const Function *DtorFunc = getFunction(Dtor);
7431 assert(DtorFunc->hasThisPointer());
7432 assert(DtorFunc->getNumParams() == 1);
7433 return this->emitCall(DtorFunc, 0, Loc);
7438template <
class Emitter>
7439bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7451 return this->emitPopPtr(Loc);
7453 for (ssize_t I = N - 1; I >= 1; --I) {
7454 if (!this->emitConstUint64(I, Loc))
7456 if (!this->emitArrayElemPtrUint64(Loc))
7458 if (!this->emitDestructionPop(ElemDesc, Loc))
7462 if (!this->emitConstUint64(0, Loc))
7464 if (!this->emitArrayElemPtrPopUint64(Loc))
7466 return this->emitDestructionPop(ElemDesc, Loc);
7471 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7476template <
class Emitter>
7477bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7478 assert(!DiscardResult &&
"Should've been checked before");
7480 unsigned DummyID = P.getOrCreateDummy(D);
7482 if (!this->emitGetPtrGlobal(DummyID, E))
7490 return this->emitDecayPtr(
PT_Ptr, PT, E);
7496template <
class Emitter>
7497bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7498 assert(!DiscardResult &&
"Should've been checked before");
7501 return this->emitConstFloat(
Floating(F), E);
7503 APInt I = F.bitcastToAPInt();
7504 return this->emitConstFloat(
7505 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7506 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7517template <
class Emitter>
7518bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7531 if (!this->emitGetPtrLocal(*LocalIndex, E))
7541 if (!this->visit(SubExpr))
7543 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7544 unsigned TempOffset =
7545 allocateLocalPrimitive(SubExpr, *FromT,
true);
7546 if (!this->visit(SubExpr))
7548 if (!this->emitSetLocal(*FromT, TempOffset, E))
7550 if (!this->emitGetPtrLocal(TempOffset, E))
7557 if (!this->emitBitCast(E))
7559 return DiscardResult ? this->emitPopPtr(E) :
true;
7563 const llvm::fltSemantics *TargetSemantics =
nullptr;
7565 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7571 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7573 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7574 ResultBitWidth, TargetSemantics,
7579 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)
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 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.
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.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
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
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.
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.
std::byte * rawData()
Returns a pointer to the raw data, including metadata.
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.
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)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, const ValueDecl *ExtendingDecl=nullptr, ScopeKind SC=ScopeKind::Block, bool IsConstexprUnknown=false)
Creates a local primitive value.
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)
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), const ValueDecl *ExtendingDecl=nullptr, ScopeKind=ScopeKind::Block, bool IsConstexprUnknown=false)
Allocates a space storing a local given its type.
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)
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 CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
const Field * getField(const FieldDecl *FD) const
Returns a field.
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
llvm::iterator_range< const_base_iter > bases() const
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
unsigned getNumFields() const
llvm::iterator_range< const_field_iter > fields() const
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
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)
@ Success
Annotation was successful.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ SD_Static
Static storage duration.
@ 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()