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>
1714 return this->visitZeroInitializer(*
T, QT, E);
1722 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1723 CXXRD && CXXRD->getNumVBases() > 0) {
1733 return this->visitZeroRecordInitializer(R, E);
1740 return this->visitZeroArrayInitializer(QT, E);
1744 QualType ElemQT = ComplexTy->getElementType();
1746 for (
unsigned I = 0; I < 2; ++I) {
1747 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1749 if (!this->emitInitElem(ElemT, I, E))
1756 unsigned NumVecElements = VecT->getNumElements();
1757 QualType ElemQT = VecT->getElementType();
1760 for (
unsigned I = 0; I < NumVecElements; ++I) {
1761 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1763 if (!this->emitInitElem(ElemT, I, E))
1772template <
class Emitter>
1782 for (
const Expr *SubExpr : {LHS, RHS}) {
1783 if (!this->
visit(SubExpr)) {
1790 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
1791 if (!this->emitExpandPtr(E))
1802 return this->emitError(E);
1805 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
1809 if (!this->emitArrayElemPtrPop(*IndexT, E))
1812 return this->emitPopPtr(E);
1818 return this->emitLoadPop(*
T, E);
1821template <
class Emitter>
1823 const Expr *ArrayFiller,
const Expr *E) {
1828 QT = AT->getValueType();
1831 if (Inits.size() == 0)
1833 return this->emitInvalid(E);
1848 if (Inits.size() == 0)
1849 return this->visitZeroInitializer(*
T, QT, E);
1850 assert(Inits.size() == 1);
1857 if (Inits.size() == 1 && E->
getType() == Inits[0]->getType())
1863 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
1870 bool BitField = FieldToInit->isBitField();
1872 return this->emitInitBitFieldActivate(
T, FieldToInit, E);
1874 return this->emitInitBitField(
T, FieldToInit, E);
1876 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
1877 return this->emitInitField(
T, FieldToInit->Offset, E);
1880 auto initCompositeField = [=](
const Record::Field *FieldToInit,
1888 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
1891 if (
Activate && !this->emitActivate(E))
1896 return this->emitPopPtr(E);
1900 if (Inits.size() == 0) {
1901 if (!this->visitZeroRecordInitializer(R, E))
1906 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
1907 FToInit = ILE->getInitializedFieldInUnion();
1911 const Record::Field *FieldToInit = R->
getField(FToInit);
1913 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
1916 if (!initCompositeField(FieldToInit,
Init,
true))
1920 return this->emitFinishInit(E);
1924 unsigned InitIndex = 0;
1927 while (InitIndex < R->getNumFields() &&
1932 const Record::Field *FieldToInit = R->
getField(InitIndex);
1933 if (!initPrimitiveField(FieldToInit,
Init, *
T))
1938 if (
const Record::Base *B = R->
getBase(
Init->getType())) {
1939 if (!this->emitGetPtrBase(B->Offset,
Init))
1945 if (!this->emitFinishInitPop(E))
1950 const Record::Field *FieldToInit = R->
getField(InitIndex);
1951 if (!initCompositeField(FieldToInit,
Init))
1957 return this->emitFinishInit(E);
1961 if (Inits.size() == 1 && QT == Inits[0]->getType())
1965 Ctx.getASTContext().getAsConstantArrayType(QT);
1968 if (!this->emitCheckArraySize(NumElems, E))
1972 unsigned ElementIndex = 0;
1974 if (
const auto *EmbedS =
1975 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
1983 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
1984 getFPOptions(E), E))
1990 return this->emitInitElem(TargetT, ElemIndex, IL);
1992 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2004 for (; ElementIndex != NumElems; ++ElementIndex) {
2010 return this->emitFinishInit(E);
2014 unsigned NumInits = Inits.size();
2019 QualType ElemQT = ComplexTy->getElementType();
2021 if (NumInits == 0) {
2023 for (
unsigned I = 0; I < 2; ++I) {
2024 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2026 if (!this->emitInitElem(ElemT, I, E))
2029 }
else if (NumInits == 2) {
2030 unsigned InitIndex = 0;
2035 if (!this->emitInitElem(ElemT, InitIndex, E))
2044 unsigned NumVecElements = VecT->getNumElements();
2045 assert(NumVecElements >= Inits.size());
2047 QualType ElemQT = VecT->getElementType();
2051 unsigned InitIndex = 0;
2058 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2059 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2060 InitVecT->getNumElements(), E))
2062 InitIndex += InitVecT->getNumElements();
2064 if (!this->emitInitElem(ElemT, InitIndex, E))
2070 assert(InitIndex <= NumVecElements);
2073 for (; InitIndex != NumVecElements; ++InitIndex) {
2074 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2076 if (!this->emitInitElem(ElemT, InitIndex, E))
2087template <
class Emitter>
2094 return this->emitInitElem(*InitT, ElemIndex,
Init);
2100 if (!this->emitConstUint32(ElemIndex,
Init))
2102 if (!this->emitArrayElemPtrUint32(
Init))
2106 return this->emitFinishInitPop(
Init);
2109template <
class Emitter>
2112 bool Activate,
bool IsOperatorCall) {
2114 llvm::BitVector NonNullArgs;
2115 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2118 bool ExplicitMemberFn =
false;
2119 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2120 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2122 unsigned ArgIndex = 0;
2123 for (
const Expr *Arg : Args) {
2125 if (!this->
visit(Arg))
2133 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2134 if (DeclIndex < FuncDecl->getNumParams())
2135 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2145 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2153 if (!this->emitActivate(Arg))
2157 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2160 if (!this->emitCheckNonNullArg(ArgT, Arg))
2171template <
class Emitter>
2176template <
class Emitter>
2182template <
class Emitter>
2188template <
class Emitter>
2204template <
class Emitter>
2206 auto It = E->
begin();
2207 return this->
visit(*It);
2212 bool AlignOfReturnsPreferred =
2213 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2219 T = Ref->getPointeeType();
2221 if (
T.getQualifiers().hasUnaligned())
2227 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2233template <
class Emitter>
2239 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2245 ArgType = Ref->getPointeeType();
2251 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2252 return this->emitInvalid(E);
2254 if (Kind == UETT_SizeOf)
2263 return this->emitConst(Size.getQuantity(), E);
2266 if (Kind == UETT_CountOf) {
2272 if (
const auto *CAT =
2276 return this->emitConst(CAT->getSize(), E);
2286 if (VAT->getElementType()->isArrayType()) {
2287 std::optional<APSInt> Res =
2289 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2294 return this->emitConst(*Res, E);
2299 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2316 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2319 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2329 return this->emitConst(Size.getQuantity(), E);
2332 if (Kind == UETT_VectorElements) {
2334 return this->emitConst(VT->getNumElements(), E);
2336 return this->emitSizelessVectorElementSize(E);
2339 if (Kind == UETT_VecStep) {
2341 unsigned N = VT->getNumElements();
2348 return this->emitConst(N, E);
2350 return this->emitConst(1, E);
2353 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2360 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2362 return this->emitInvalid(E);
2364 return this->emitConst(
2365 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2373template <
class Emitter>
2384 const auto maybeLoadValue = [&]() ->
bool {
2388 return this->emitLoadPop(*
T, E);
2392 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2396 if (
auto GlobalIndex =
P.getGlobal(VD))
2397 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2402 if (!this->
discard(Base) && !this->emitSideEffect(E))
2417 const Record::Field *F = R->
getField(FD);
2419 if (F->Decl->getType()->isReferenceType())
2420 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2421 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2424template <
class Emitter>
2433template <
class Emitter>
2452 for (
size_t I = 0; I != Size; ++I) {
2464template <
class Emitter>
2475 return this->emitGetLocal(SubExprT, It->second, E);
2477 if (!this->
visit(SourceExpr))
2484 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2490 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2500template <
class Emitter>
2521 bool IsBcpCall =
false;
2522 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2523 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2527 LabelTy LabelEnd = this->getLabel();
2528 LabelTy LabelFalse = this->getLabel();
2531 if (!this->emitStartSpeculation(E))
2539 if (this->checkingForUndefinedBehavior()) {
2542 if (!this->
discard(FalseExpr))
2548 if (!this->jumpFalse(LabelFalse))
2553 if (!this->jump(LabelEnd))
2555 this->emitLabel(LabelFalse);
2559 this->fallthrough(LabelEnd);
2560 this->emitLabel(LabelEnd);
2563 return this->emitEndSpeculation(E);
2567template <
class Emitter>
2573 unsigned StringIndex =
P.createGlobalString(E);
2574 return this->emitGetPtrGlobal(StringIndex, E);
2579 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2580 assert(CAT &&
"a string literal that's not a constant array?");
2585 unsigned N = std::min(ArraySize, E->
getLength());
2588 for (
unsigned I = 0; I != N; ++I) {
2591 if (CharWidth == 1) {
2592 this->emitConstSint8(CodeUnit, E);
2593 this->emitInitElemSint8(I, E);
2594 }
else if (CharWidth == 2) {
2595 this->emitConstUint16(CodeUnit, E);
2596 this->emitInitElemUint16(I, E);
2597 }
else if (CharWidth == 4) {
2598 this->emitConstUint32(CodeUnit, E);
2599 this->emitInitElemUint32(I, E);
2601 llvm_unreachable(
"unsupported character width");
2606 for (
unsigned I = N; I != ArraySize; ++I) {
2607 if (CharWidth == 1) {
2608 this->emitConstSint8(0, E);
2609 this->emitInitElemSint8(I, E);
2610 }
else if (CharWidth == 2) {
2611 this->emitConstUint16(0, E);
2612 this->emitInitElemUint16(I, E);
2613 }
else if (CharWidth == 4) {
2614 this->emitConstUint32(0, E);
2615 this->emitInitElemUint32(I, E);
2617 llvm_unreachable(
"unsupported character width");
2624template <
class Emitter>
2628 return this->emitDummyPtr(E, E);
2631template <
class Emitter>
2633 auto &A =
Ctx.getASTContext();
2642template <
class Emitter>
2650 auto &A =
Ctx.getASTContext();
2654 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2655 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2662 unsigned StringIndex =
P.createGlobalString(SL);
2663 return this->emitGetPtrGlobal(StringIndex, E);
2666template <
class Emitter>
2670 return this->emitConst(E->
getValue(), E);
2673template <
class Emitter>
2699 if (!this->emitSetLocal(*RT, TempOffset, E))
2705 if (!this->emitLoad(LHST, E))
2709 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2710 LHSComputationType, E))
2714 if (!this->emitGetLocal(*RT, TempOffset, E))
2719 if (!this->emitAddf(getFPOptions(E), E))
2723 if (!this->emitSubf(getFPOptions(E), E))
2727 if (!this->emitMulf(getFPOptions(E), E))
2731 if (!this->emitDivf(getFPOptions(E), E))
2742 return this->emitStorePop(LHST, E);
2743 return this->emitStore(LHST, E);
2746template <
class Emitter>
2755 if (Op != BO_AddAssign && Op != BO_SubAssign)
2764 if (!this->emitLoad(*
LT, LHS))
2770 if (Op == BO_AddAssign) {
2771 if (!this->emitAddOffset(*RT, E))
2774 if (!this->emitSubOffset(*RT, E))
2779 return this->emitStorePopPtr(E);
2780 return this->emitStorePtr(E);
2783template <
class Emitter>
2796 if (!
Ctx.getLangOpts().CPlusPlus14)
2797 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2799 if (!
LT || !RT || !ResultT || !LHSComputationT)
2824 if (!this->emitSetLocal(*RT, TempOffset, E))
2831 if (!this->emitLoad(*
LT, E))
2833 if (
LT != LHSComputationT &&
2839 if (!this->emitGetLocal(*RT, TempOffset, E))
2845 if (!this->emitAdd(*LHSComputationT, E))
2849 if (!this->emitSub(*LHSComputationT, E))
2853 if (!this->emitMul(*LHSComputationT, E))
2857 if (!this->emitDiv(*LHSComputationT, E))
2861 if (!this->emitRem(*LHSComputationT, E))
2865 if (!this->emitShl(*LHSComputationT, *RT, E))
2869 if (!this->emitShr(*LHSComputationT, *RT, E))
2873 if (!this->emitBitAnd(*LHSComputationT, E))
2877 if (!this->emitBitXor(*LHSComputationT, E))
2881 if (!this->emitBitOr(*LHSComputationT, E))
2885 llvm_unreachable(
"Unimplemented compound assign operator");
2889 if (ResultT != LHSComputationT &&
2890 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
2896 return this->emitStoreBitFieldPop(*ResultT, E);
2897 return this->emitStorePop(*ResultT, E);
2900 return this->emitStoreBitField(*ResultT, E);
2901 return this->emitStore(*ResultT, E);
2904template <
class Emitter>
2912template <
class Emitter>
2924 return this->
discard(SubExpr);
2941 if (!this->
visit(SubExpr))
2943 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2945 return this->emitGetPtrGlobal(*GlobalIndex, E);
2948 if (!this->checkLiteralType(SubExpr))
2951 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2955 return this->emitInitGlobalTempComp(TempDecl, E);
2964 if (!this->
VarScope->LocalsAlwaysEnabled &&
2965 !this->emitEnableLocal(LocalIndex, E))
2968 if (!this->
visit(SubExpr))
2970 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2973 return this->emitGetPtrLocal(LocalIndex, E);
2976 if (!this->checkLiteralType(SubExpr))
2983 if (!this->
VarScope->LocalsAlwaysEnabled &&
2984 !this->emitEnableLocal(*LocalIndex, E))
2987 if (!this->emitGetPtrLocal(*LocalIndex, E))
2994template <
class Emitter>
3005 if (!this->
visit(SubExpr))
3009 return this->emitPopPtr(E);
3013template <
class Emitter>
3034 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3039 if (
P.isGlobalInitialized(*GlobalIndex))
3045 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3057 unsigned LocalIndex;
3061 LocalIndex = *MaybeIndex;
3065 if (!this->emitGetPtrLocal(LocalIndex, E))
3069 return this->
visit(
Init) && this->emitInit(*
T, E);
3073template <
class Emitter>
3086template <
class Emitter>
3090 return this->emitConst(E->
getValue(), E);
3093template <
class Emitter>
3106 for (
const Record::Field &F : R->
fields()) {
3108 if (!
Init ||
Init->containsErrors())
3116 if (!this->emitInitField(*
T, F.Offset, E))
3119 if (!this->emitGetPtrField(F.Offset, E))
3125 if (!this->emitPopPtr(E))
3133template <
class Emitter>
3140 return this->emitGetPtrGlobal(StringIndex, E);
3146template <
class Emitter>
3151 return this->emitInvalid(E);
3154template <
class Emitter>
3180 if (PointeeToT && PointeeFromT) {
3196 bool Fatal = (ToT != FromT);
3203template <
class Emitter>
3206 if (!
Ctx.getLangOpts().CPlusPlus20) {
3214template <
class Emitter>
3220 return this->emitConstBool(E->
getValue(), E);
3223template <
class Emitter>
3228 if (
T->isRecordType()) {
3242 if (!this->emitGetPtrLocal(*LocalIndex, E))
3250 T->getAsCXXRecordDecl()))
3258 if (!this->visitZeroRecordInitializer(R, E))
3270 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3272 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3273 if (!this->emitCheckFunctionDecl(Ctor, E))
3284 assert(
Func->hasThisPointer());
3285 assert(!
Func->hasRVO());
3289 if (!this->emitDupPtr(E))
3293 for (
const auto *Arg : E->
arguments()) {
3294 if (!this->
visit(Arg))
3298 if (
Func->isVariadic()) {
3299 uint32_t VarArgSize = 0;
3300 unsigned NumParams =
Func->getNumWrittenParams();
3301 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3305 if (!this->emitCallVar(
Func, VarArgSize, E))
3308 if (!this->emitCall(
Func, 0, E)) {
3313 (void)this->emitPopPtr(E);
3319 return this->emitPopPtr(E);
3320 return this->emitFinishInit(E);
3323 if (
T->isArrayType()) {
3328 if (!this->emitDupPtr(E))
3332 initArrayDimension = [&](
QualType T) ->
bool {
3333 if (!
T->isArrayType()) {
3335 for (
const auto *Arg : E->
arguments()) {
3336 if (!this->
visit(Arg))
3340 return this->emitCall(
Func, 0, E);
3344 Ctx.getASTContext().getAsConstantArrayType(
T);
3349 for (
size_t I = 0; I != NumElems; ++I) {
3350 if (!this->emitConstUint64(I, E))
3352 if (!this->emitArrayElemPtrUint64(E))
3354 if (!initArrayDimension(ElemTy))
3357 return this->emitPopPtr(E);
3360 return initArrayDimension(E->
getType());
3366template <
class Emitter>
3376 assert(Val.
isInt());
3378 return this->emitConst(I, E);
3385 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3386 return this->
visit(LValueExpr);
3401 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3405 const APValue &
V = UGCD->getValue();
3406 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3407 const Record::Field *F = R->
getField(I);
3408 const APValue &FieldValue =
V.getStructField(I);
3414 if (!this->emitInitField(FieldT, F->Offset, E))
3422template <
class Emitter>
3428 for (
unsigned I = 0; I != N; ++I) {
3435 if (!this->
discard(ArrayIndexExpr))
3440 if (!this->
visit(ArrayIndexExpr))
3444 if (!this->emitCast(IndexT,
PT_Sint64, E))
3454 return this->emitOffsetOf(
T, E, E);
3457template <
class Emitter>
3466 return this->visitZeroInitializer(*
T, Ty, E);
3473 if (!this->emitGetPtrLocal(*LocalIndex, E))
3478 QualType ElemQT = CT->getElementType();
3481 for (
unsigned I = 0; I != 2; ++I) {
3482 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3484 if (!this->emitInitElem(ElemT, I, E))
3496 if (!this->emitGetPtrLocal(*LocalIndex, E))
3501 QualType ElemQT = VT->getElementType();
3504 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3505 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3507 if (!this->emitInitElem(ElemT, I, E))
3516template <
class Emitter>
3521template <
class Emitter>
3527template <
class Emitter>
3532template <
class Emitter>
3537 return this->emitConst(E->
getValue(), E);
3540template <
class Emitter>
3545 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3563 if (!this->emitGetParam(PT, Offset, E))
3568 return this->emitCall(F, 0, E);
3573template <
class Emitter>
3581 const Expr *PlacementDest =
nullptr;
3582 bool IsNoThrow =
false;
3584 if (PlacementArgs != 0) {
3593 if (PlacementArgs == 1) {
3601 if (!this->emitInvalidNewDeleteExpr(E, E))
3606 if (OperatorNew->isReservedGlobalPlacementOperator())
3607 PlacementDest = Arg1;
3611 return this->emitInvalid(E);
3613 }
else if (!OperatorNew
3614 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3615 return this->emitInvalidNewDeleteExpr(E, E);
3618 if (!PlacementDest) {
3623 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3626 Desc =
P.createDescriptor(
3629 false,
false,
false,
3635 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3639 const Expr *Stripped = *ArraySizeExpr;
3640 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3641 Stripped = ICE->getSubExpr())
3642 if (ICE->getCastKind() != CK_NoOp &&
3643 ICE->getCastKind() != CK_IntegralCast)
3651 if (!this->
visit(Stripped))
3653 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3656 if (PlacementDest) {
3657 if (!this->
visit(PlacementDest))
3659 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3661 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3664 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3669 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3673 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3680 size_t StaticInitElems = 0;
3681 const Expr *DynamicInit =
nullptr;
3683 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3684 StaticInitElems = CAT->getZExtSize();
3688 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init);
3689 ILE && ILE->hasArrayFiller())
3690 DynamicInit = ILE->getArrayFiller();
3704 const Function *CtorFunc =
nullptr;
3705 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3709 }
else if (!DynamicInit)
3712 LabelTy EndLabel = this->getLabel();
3713 LabelTy StartLabel = this->getLabel();
3718 if (!this->emitDupPtr(E))
3720 if (!this->emitNullPtr(0,
nullptr, E))
3722 if (!this->emitEQPtr(E))
3724 if (!this->jumpTrue(EndLabel))
3731 if (!this->emitConst(StaticInitElems,
SizeT, E))
3733 if (!this->emitSetLocal(
SizeT, Iter, E))
3736 this->fallthrough(StartLabel);
3737 this->emitLabel(StartLabel);
3739 if (!this->emitGetLocal(
SizeT, Iter, E))
3741 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3743 if (!this->emitLT(
SizeT, E))
3745 if (!this->jumpFalse(EndLabel))
3749 if (!this->emitGetLocal(
SizeT, Iter, E))
3751 if (!this->emitArrayElemPtr(
SizeT, E))
3754 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3759 if (!this->visitZeroInitializer(InitT, ElemType, E))
3761 if (!this->emitStorePop(InitT, E))
3763 }
else if (DynamicInit) {
3765 if (!this->
visit(DynamicInit))
3767 if (!this->emitStorePop(*InitT, E))
3772 if (!this->emitPopPtr(E))
3777 if (!this->emitCall(CtorFunc, 0, E))
3782 if (!this->emitGetPtrLocal(Iter, E))
3784 if (!this->emitIncPop(
SizeT,
false, E))
3787 if (!this->jump(StartLabel))
3790 this->fallthrough(EndLabel);
3791 this->emitLabel(EndLabel);
3795 if (PlacementDest) {
3796 if (!this->
visit(PlacementDest))
3798 if (!this->emitCheckNewTypeMismatch(E, E))
3803 if (!this->emitAlloc(Desc, E))
3812 if (!this->emitInit(*ElemT, E))
3823 return this->emitPopPtr(E);
3828template <
class Emitter>
3834 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3835 return this->emitInvalidNewDeleteExpr(E, E);
3838 if (!this->
visit(Arg))
3844template <
class Emitter>
3850 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3855 return this->emitGetFnPtr(
Func, E);
3858template <
class Emitter>
3862 auto canonType = [](
const Type *
T) {
3863 return T->getCanonicalTypeUnqualified().getTypePtr();
3871 return this->emitGetTypeid(
3875 return this->emitGetTypeid(
3884 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3890 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3893 return this->emitPopPtr(E);
3897template <
class Emitter>
3899 assert(
Ctx.getLangOpts().CPlusPlus);
3900 return this->emitConstBool(E->
getValue(), E);
3903template <
class Emitter>
3915 return this->emitDummyPtr(GuidDecl, E);
3920 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3929 assert(
V.isStruct());
3930 assert(
V.getStructNumBases() == 0);
3934 return this->emitFinishInit(E);
3937template <
class Emitter>
3947template <
class Emitter>
3956template <
class Emitter>
3962template <
class Emitter>
3966 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
3970 if (OVE->isUnique())
3986template <
class Emitter>
3991template <
class Emitter>
3993 return this->emitError(E);
3996template <
class Emitter>
4002 return this->emitDummyPtr(E, E);
4005template <
class Emitter>
4009 QualType ElemType = VT->getElementType();
4013 PrimType SrcElemT = classifyVectorElementType(SrcType);
4015 unsigned SrcOffset =
4017 if (!this->
visit(Src))
4019 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4022 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4023 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4025 if (!this->emitArrayElemPop(SrcElemT, I, E))
4029 if (SrcElemT != ElemT) {
4030 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4032 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4033 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4037 if (!this->emitInitElem(ElemT, I, E))
4044template <
class Emitter>
4048 return this->emitInvalid(E);
4058 assert(NumOutputElems > 0);
4061 unsigned VectorOffsets[2];
4062 for (
unsigned I = 0; I != 2; ++I) {
4065 if (!this->
visit(Vecs[I]))
4067 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4070 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4072 assert(ShuffleIndex >= -1);
4073 if (ShuffleIndex == -1)
4074 return this->emitInvalidShuffleVectorIndex(I, E);
4076 assert(ShuffleIndex < (NumInputElems * 2));
4077 if (!this->emitGetLocal(
PT_Ptr,
4078 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4080 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4081 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4084 if (!this->emitInitElem(ElemT, I, E))
4091template <
class Emitter>
4096 Base->getType()->isVectorType() ||
4102 if (Indices.size() == 1) {
4107 if (!this->emitConstUint32(Indices[0], E))
4109 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4119 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4127 if (!this->emitGetPtrLocal(*ResultIndex, E))
4135 uint32_t DstIndex = 0;
4136 for (uint32_t I : Indices) {
4137 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4139 if (!this->emitArrayElemPop(ElemT, I, E))
4141 if (!this->emitInitElem(ElemT, DstIndex, E))
4151template <
class Emitter>
4155 return this->
discard(SubExpr) && this->emitInvalid(E);
4161 return this->emitDummyPtr(E, E);
4164template <
class Emitter>
4169 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4174 if (!this->
visit(SubExpr))
4176 if (!this->emitConstUint8(0, E))
4178 if (!this->emitArrayElemPtrPopUint8(E))
4185 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4187 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4189 assert(SecondFieldT ==
PT_Ptr);
4193 if (!this->emitExpandPtr(E))
4197 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4202template <
class Emitter>
4217 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4219 return this->emitUnsupported(E);
4228 return this->
Visit(E);
4235 return this->
Visit(E);
4239 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4242 if (
const auto *CE = dyn_cast<CastExpr>(E);
4244 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4251 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4254 if (
const auto *CE = dyn_cast<CastExpr>(E);
4255 CE && (CE->getCastKind() == CK_DerivedToBase ||
4256 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4257 CE->getCastKind() == CK_NoOp))
4276 if (!this->emitGetPtrLocal(*LocalIndex, E))
4286 return this->
Visit(E);
4289template <
class Emitter>
4295 return this->
Visit(E);
4301 return this->
Visit(E);
4309 if (!this->
visit(E))
4311 return this->emitComplexBoolCast(E);
4316 if (!this->
visit(E))
4324 return this->emitIsNonNullPtr(E);
4328 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4331 return this->emitCast(*
T,
PT_Bool, E);
4334template <
class Emitter>
4338 QT = AT->getValueType();
4342 return this->emitZeroBool(E);
4344 return this->emitZeroSint8(E);
4346 return this->emitZeroUint8(E);
4348 return this->emitZeroSint16(E);
4350 return this->emitZeroUint16(E);
4352 return this->emitZeroSint32(E);
4354 return this->emitZeroUint32(E);
4356 return this->emitZeroSint64(E);
4358 return this->emitZeroUint64(E);
4360 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4362 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4364 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4367 return this->emitNullMemberPtr(0,
nullptr, E);
4369 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4370 return this->emitFloat(F, E);
4373 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4377 llvm_unreachable(
"unknown primitive type");
4380template <
class Emitter>
4381bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4386 for (
const Record::Field &Field : R->
fields()) {
4387 if (Field.isUnnamedBitField())
4394 if (!this->visitZeroInitializer(
T, QT, E))
4397 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4401 if (!this->emitInitField(
T, Field.Offset, E))
4406 if (!this->emitGetPtrField(Field.Offset, E))
4412 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4413 if (!this->visitZeroInitializer(
T, ET, E))
4415 if (!this->emitInitElem(
T, I, E))
4420 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4423 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4431 if (!this->emitFinishInitActivatePop(E))
4435 if (!this->emitFinishInitPop(E))
4439 for (
const Record::Base &B : R->
bases()) {
4440 if (!this->emitGetPtrBase(B.Offset, E))
4442 if (!this->visitZeroRecordInitializer(B.R, E))
4444 if (!this->emitFinishInitPop(E))
4453template <
class Emitter>
4454bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4455 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4456 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4461 for (
size_t I = 0; I != NumElems; ++I) {
4462 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4464 if (!this->emitInitElem(*ElemT, I, E))
4470 const Record *R = getRecord(ElemType);
4472 for (
size_t I = 0; I != NumElems; ++I) {
4473 if (!this->emitConstUint32(I, E))
4475 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4477 if (!this->visitZeroRecordInitializer(R, E))
4479 if (!this->emitPopPtr(E))
4485 for (
size_t I = 0; I != NumElems; ++I) {
4486 if (!this->emitConstUint32(I, E))
4488 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4490 if (!this->visitZeroArrayInitializer(ElemType, E))
4492 if (!this->emitPopPtr(E))
4501template <
class Emitter>
4502bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4504 if (!canClassify(E->
getType()))
4507 if (!this->visit(RHS))
4509 if (!this->visit(LHS))
4516 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4520 bool Activates = refersToUnion(LHS);
4523 if (!this->emitFlip(
PT_Ptr, RHT, E))
4526 if (DiscardResult) {
4527 if (BitField && Activates)
4528 return this->emitStoreBitFieldActivatePop(RHT, E);
4530 return this->emitStoreBitFieldPop(RHT, E);
4532 return this->emitStoreActivatePop(RHT, E);
4534 return this->emitStorePop(RHT, E);
4537 auto maybeLoad = [&](
bool Result) ->
bool {
4543 return this->emitLoadPop(RHT, E);
4547 if (BitField && Activates)
4548 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4550 return maybeLoad(this->emitStoreBitField(RHT, E));
4552 return maybeLoad(this->emitStoreActivate(RHT, E));
4554 return maybeLoad(this->emitStore(RHT, E));
4557template <
class Emitter>
4558template <
typename T>
4562 return this->emitConstSint8(
Value, E);
4564 return this->emitConstUint8(
Value, E);
4566 return this->emitConstSint16(
Value, E);
4568 return this->emitConstUint16(
Value, E);
4570 return this->emitConstSint32(
Value, E);
4572 return this->emitConstUint32(
Value, E);
4574 return this->emitConstSint64(
Value, E);
4576 return this->emitConstUint64(
Value, E);
4578 return this->emitConstBool(
Value, E);
4585 llvm_unreachable(
"Invalid integral type");
4588 llvm_unreachable(
"unknown primitive type");
4591template <
class Emitter>
4592template <
typename T>
4593bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4594 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4597template <
class Emitter>
4601 return this->emitConstIntAPS(
Value, E);
4603 return this->emitConstIntAP(
Value, E);
4605 if (
Value.isSigned())
4606 return this->emitConst(
Value.getSExtValue(), Ty, E);
4607 return this->emitConst(
Value.getZExtValue(), Ty, E);
4610template <
class Emitter>
4614 return this->emitConstIntAPS(
Value, E);
4616 return this->emitConstIntAP(
Value, E);
4619 return this->emitConst(
Value.getSExtValue(), Ty, E);
4620 return this->emitConst(
Value.getZExtValue(), Ty, E);
4623template <
class Emitter>
4624bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4625 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4628template <
class Emitter>
4640 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4641 Locals.insert({VD, Local});
4643 VarScope->addExtended(Local, ExtendingDecl);
4645 VarScope->addForScopeKind(Local, SC);
4646 return Local.Offset;
4649template <
class Emitter>
4653 bool IsConstexprUnknown) {
4656 bool IsTemporary =
false;
4657 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4660 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4661 Init = VarD->getInit();
4663 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4671 IsTemporary,
false,
false,
Init);
4673 return std::nullopt;
4678 Locals.insert({Key, Local});
4680 VarScope->addExtended(Local, ExtendingDecl);
4682 VarScope->addForScopeKind(Local, SC);
4683 return Local.Offset;
4686template <
class Emitter>
4696 return std::nullopt;
4706 return Local.Offset;
4709template <
class Emitter>
4711 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
4712 return PT->getPointeeType()->getAsCanonical<RecordType>();
4718 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
4722template <
class Emitter>
4724 return P.getOrCreateRecord(RD);
4727template <
class Emitter>
4729 return Ctx.getOrCreateFunction(FD);
4732template <
class Emitter>
4737 if (!DestroyToplevelScope) {
4738 if (!this->emitCheckAllocations(E))
4742 auto maybeDestroyLocals = [&]() ->
bool {
4743 if (DestroyToplevelScope)
4744 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
4745 return this->emitCheckAllocations(E);
4752 return this->emitRetVoid(E) && maybeDestroyLocals();
4760 return this->emitRet(*
T, E) && maybeDestroyLocals();
4768 if (!this->emitGetPtrLocal(*LocalOffset, E))
4774 if (!this->emitFinishInit(E))
4779 return this->emitRetValue(E) && maybeDestroyLocals();
4782 return maybeDestroyLocals() && this->emitCheckAllocations(E) &&
false;
4785template <
class Emitter>
4787 bool IsConstexprUnknown) {
4790 IsConstexprUnknown);
4799 if (
auto GlobalIndex =
P.getGlobal(VD)) {
4800 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4815template <
class Emitter>
4817 bool ConstantContext) {
4820 if (!ConstantContext) {
4834 auto GlobalIndex =
P.getGlobal(VD);
4835 assert(GlobalIndex);
4837 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
4840 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
4844 auto Local =
Locals.find(VD);
4845 assert(Local !=
Locals.end());
4847 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
4850 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
4860 auto GlobalIndex =
P.getGlobal(VD);
4861 assert(GlobalIndex);
4862 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4872 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
4875template <
class Emitter>
4878 bool Toplevel,
bool IsConstexprUnknown) {
4885 if (!this->isActive())
4890 if (
Init &&
Init->isValueDependent())
4894 auto checkDecl = [&]() ->
bool {
4896 return !NeedsOp || this->emitCheckDecl(VD, VD);
4904 if (
P.getPtrGlobal(*GlobalIndex).isInitialized())
4908 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
4922 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
4925 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
4931 return this->emitFinishInitGlobal(
Init);
4940 IsConstexprUnknown);
4951 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
4955 return this->emitSetLocal(*VarT, Offset, VD);
4963 if (!this->emitGetPtrLocal(*Offset,
Init))
4969 return this->emitFinishInitPop(
Init);
4974template <
class Emitter>
4979 return this->emitConst(Val.
getInt(), ValType, E);
4982 return this->emitFloat(F, E);
4987 return this->emitNull(ValType, 0,
nullptr, E);
4989 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
4990 return this->
visit(BaseExpr);
4995 return this->emitGetMemberPtr(MemberDecl, E);
4996 return this->emitNullMemberPtr(0,
nullptr, E);
5002template <
class Emitter>
5010 const Record::Field *RF = R->
getField(I);
5011 QualType FieldType = RF->Decl->getType();
5016 if (!this->emitInitField(*PT, RF->Offset, E))
5019 if (!this->emitGetPtrField(RF->Offset, E))
5023 if (!this->emitPopPtr(E))
5034 const Record::Field *RF = R->
getField(UnionField);
5038 return this->emitInitField(
T, RF->Offset, E);
5041 const auto *ArrType =
T->getAsArrayTypeUnsafe();
5042 QualType ElemType = ArrType->getElementType();
5043 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5048 if (!this->emitInitElem(*ElemT, A, E))
5051 if (!this->emitConstUint32(A, E))
5053 if (!this->emitArrayElemPtrUint32(E))
5057 if (!this->emitPopPtr(E))
5068template <
class Emitter>
5070 unsigned BuiltinID) {
5071 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5076 return this->emitConst(0, E);
5079 if (!this->emitStartSpeculation(E))
5081 LabelTy EndLabel = this->getLabel();
5082 if (!this->speculate(E, EndLabel))
5084 this->fallthrough(EndLabel);
5085 if (!this->emitEndSpeculation(E))
5094 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5095 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5096 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5097 BuiltinID == Builtin::BI__builtin_function_start) {
5100 return this->emitDummyPtr(E, E);
5111 if (!this->emitGetPtrLocal(*LocalIndex, E))
5116 switch (BuiltinID) {
5117 case Builtin::BI__builtin_object_size:
5118 case Builtin::BI__builtin_dynamic_object_size: {
5122 if (!this->
visit(Arg0))
5136 for (
const auto *Arg : E->
arguments()) {
5137 if (!this->
visit(Arg))
5143 if (!this->emitCallBI(E, BuiltinID, E))
5148 return this->emitPop(*ReturnT, E);
5154template <
class Emitter>
5171 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5172 DD && DD->isTrivial()) {
5174 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5176 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5177 this->emitPopPtr(E);
5193 if (!this->emitGetPtrLocal(*LocalIndex, E))
5201 if (!this->emitGetPtrLocal(*LocalIndex, E))
5205 if (!this->emitDupPtr(E))
5212 bool IsAssignmentOperatorCall =
false;
5213 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5214 OCE && OCE->isAssignmentOp()) {
5218 assert(Args.size() == 2);
5219 IsAssignmentOperatorCall =
true;
5220 std::reverse(Args.begin(), Args.end());
5226 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5227 MD && MD->isStatic()) {
5231 Args.erase(Args.begin());
5235 bool Devirtualized =
false;
5238 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5246 if (!this->
visit(Callee))
5248 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5250 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5252 if (!this->emitGetMemberPtrBase(E))
5255 const auto *InstancePtr = MC->getImplicitObjectArgument();
5262 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5263 Devirtualized =
true;
5264 if (!this->
visit(Stripped))
5267 if (!this->
visit(InstancePtr))
5271 if (!this->
visit(InstancePtr))
5275 }
else if (
const auto *PD =
5276 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5277 if (!this->emitCheckPseudoDtor(E))
5285 return this->emitEndLifetimePop(E);
5286 }
else if (!FuncDecl) {
5290 if (!this->
visit(Callee))
5292 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5296 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5301 if (IsAssignmentOperatorCall) {
5302 assert(Args.size() == 2);
5305 if (!this->emitFlip(Arg2T, Arg1T, E))
5319 assert(HasRVO ==
Func->hasRVO());
5321 bool HasQualifier =
false;
5322 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5323 HasQualifier = ME->hasQualifier();
5325 bool IsVirtual =
false;
5326 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5327 IsVirtual = !Devirtualized && MD->isVirtual();
5332 if (IsVirtual && !HasQualifier) {
5333 uint32_t VarArgSize = 0;
5334 unsigned NumParams =
5336 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5339 if (!this->emitCallVirt(
Func, VarArgSize, E))
5341 }
else if (
Func->isVariadic()) {
5342 uint32_t VarArgSize = 0;
5343 unsigned NumParams =
5345 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5347 if (!this->emitCallVar(
Func, VarArgSize, E))
5350 if (!this->emitCall(
Func, 0, E))
5359 uint32_t ArgSize = 0;
5360 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5366 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5368 if (!this->emitGetMemberPtrDecl(E))
5371 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5374 if (!this->emitCallPtr(ArgSize, E, E))
5385template <
class Emitter>
5392template <
class Emitter>
5399template <
class Emitter>
5404 return this->emitConstBool(E->
getValue(), E);
5407template <
class Emitter>
5413 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5414 return this->emitNullPtr(Val,
nullptr, E);
5417template <
class Emitter>
5425 return this->emitZero(
T, E);
5428template <
class Emitter>
5433 if (this->LambdaThisCapture.Offset > 0) {
5434 if (this->LambdaThisCapture.IsPtr)
5435 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5436 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5444 return this->emitThis(E);
5459 unsigned StartIndex = 0;
5460 unsigned EndIndex = 0;
5462 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5464 EndIndex = StartIndex;
5471 for (; StartIndex > 0; --StartIndex) {
5481 if (StartIndex == 0 && EndIndex == 0)
5484 assert(StartIndex < EndIndex);
5487 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5499 case Stmt::CompoundStmtClass:
5501 case Stmt::DeclStmtClass:
5503 case Stmt::ReturnStmtClass:
5505 case Stmt::IfStmtClass:
5507 case Stmt::WhileStmtClass:
5509 case Stmt::DoStmtClass:
5511 case Stmt::ForStmtClass:
5513 case Stmt::CXXForRangeStmtClass:
5515 case Stmt::BreakStmtClass:
5517 case Stmt::ContinueStmtClass:
5519 case Stmt::SwitchStmtClass:
5521 case Stmt::CaseStmtClass:
5523 case Stmt::DefaultStmtClass:
5525 case Stmt::AttributedStmtClass:
5527 case Stmt::CXXTryStmtClass:
5529 case Stmt::NullStmtClass:
5532 case Stmt::GCCAsmStmtClass:
5533 case Stmt::MSAsmStmtClass:
5534 case Stmt::GotoStmtClass:
5535 return this->emitInvalid(S);
5536 case Stmt::LabelStmtClass:
5539 if (
const auto *E = dyn_cast<Expr>(S))
5546template <
class Emitter>
5549 for (
const auto *InnerStmt : S->
body())
5552 return Scope.destroyLocals();
5555template <
class Emitter>
5556bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5557 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5558 for (
auto *BD : DD->flat_bindings())
5559 if (
auto *KD = BD->getHoldingVar();
5560 KD && !this->visitVarDecl(KD, KD->getInit()))
5569 const auto *CXXRD = dyn_cast<CXXRecordDecl>(FD->
getParent());
5570 return !CXXRD || CXXRD->hasTrivialDefaultConstructor();
5573template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5575 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5576 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5583 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5588 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5589 ICE && (ICE->getCastKind() == CK_NoOp ||
5590 ICE->getCastKind() == CK_DerivedToBase ||
5591 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5592 E = ICE->getSubExpr();
5596 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5597 const auto *ThisRecord =
5598 This->getType()->getPointeeType()->getAsRecordDecl();
5599 if (!ThisRecord->isUnion())
5602 if (
const auto *Ctor =
5603 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5604 return Ctor->getParent() == ThisRecord;
5613template <
class Emitter>
5615 bool EvaluateConditionDecl) {
5616 for (
const auto *D : DS->
decls()) {
5621 const auto *VD = dyn_cast<VarDecl>(D);
5628 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5635template <
class Emitter>
5638 return this->emitUnsupported(RS);
5644 if (!this->
visit(RE))
5650 if (RE->getType()->isVoidType()) {
5651 if (!this->
visit(RE))
5656 if (!this->emitRVOPtr(RE))
5660 if (!this->emitPopPtr(RE))
5664 return this->emitRetVoid(RS);
5670 return this->emitRetVoid(RS);
5674 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5680 if (
auto *CondInit = IS->
getInit())
5694 return visitChildStmt(IS->
getThen());
5696 return visitChildStmt(Else);
5702 if (!this->emitIsConstantContext(IS))
5705 if (!this->emitIsConstantContext(IS))
5707 if (!this->emitInv(IS))
5718 LabelTy LabelElse = this->getLabel();
5719 LabelTy LabelEnd = this->getLabel();
5720 if (!this->jumpFalse(LabelElse))
5722 if (!visitChildStmt(IS->
getThen()))
5724 if (!this->jump(LabelEnd))
5726 this->emitLabel(LabelElse);
5727 if (!visitChildStmt(Else))
5729 this->emitLabel(LabelEnd);
5731 LabelTy LabelEnd = this->getLabel();
5732 if (!this->jumpFalse(LabelEnd))
5734 if (!visitChildStmt(IS->
getThen()))
5736 this->emitLabel(LabelEnd);
5742template <
class Emitter>
5747 LabelTy CondLabel = this->getLabel();
5748 LabelTy EndLabel = this->getLabel();
5752 this->fallthrough(CondLabel);
5753 this->emitLabel(CondLabel);
5767 if (!this->jumpFalse(EndLabel))
5776 if (!this->jump(CondLabel))
5778 this->fallthrough(EndLabel);
5779 this->emitLabel(EndLabel);
5787 LabelTy StartLabel = this->getLabel();
5788 LabelTy EndLabel = this->getLabel();
5789 LabelTy CondLabel = this->getLabel();
5793 this->fallthrough(StartLabel);
5794 this->emitLabel(StartLabel);
5800 this->fallthrough(CondLabel);
5801 this->emitLabel(CondLabel);
5808 if (!this->jumpTrue(StartLabel))
5811 this->fallthrough(EndLabel);
5812 this->emitLabel(EndLabel);
5816template <
class Emitter>
5824 LabelTy EndLabel = this->getLabel();
5825 LabelTy CondLabel = this->getLabel();
5826 LabelTy IncLabel = this->getLabel();
5833 this->fallthrough(CondLabel);
5834 this->emitLabel(CondLabel);
5846 if (!this->jumpFalse(EndLabel))
5855 this->fallthrough(IncLabel);
5856 this->emitLabel(IncLabel);
5862 if (!this->jump(CondLabel))
5866 this->emitLabel(EndLabel);
5872template <
class Emitter>
5882 LabelTy EndLabel = this->getLabel();
5883 LabelTy CondLabel = this->getLabel();
5884 LabelTy IncLabel = this->getLabel();
5899 this->fallthrough(CondLabel);
5900 this->emitLabel(CondLabel);
5903 if (!this->jumpFalse(EndLabel))
5914 this->fallthrough(IncLabel);
5915 this->emitLabel(IncLabel);
5920 if (!this->jump(CondLabel))
5923 this->fallthrough(EndLabel);
5924 this->emitLabel(EndLabel);
5928template <
class Emitter>
5939 if (LI.BreakLabel) {
5940 TargetLabel = *LI.BreakLabel;
5941 BreakScope = LI.BreakOrContinueScope;
5947 if (LI.Name == TargetLoop) {
5948 TargetLabel = *LI.BreakLabel;
5949 BreakScope = LI.BreakOrContinueScope;
5955 assert(TargetLabel);
5958 C =
C->getParent()) {
5959 if (!
C->destroyLocals())
5963 return this->jump(*TargetLabel);
5966template <
class Emitter>
5977 if (LI.ContinueLabel) {
5978 TargetLabel = *LI.ContinueLabel;
5979 ContinueScope = LI.BreakOrContinueScope;
5985 if (LI.Name == TargetLoop) {
5986 TargetLabel = *LI.ContinueLabel;
5987 ContinueScope = LI.BreakOrContinueScope;
5992 assert(TargetLabel);
5995 C =
C->getParent()) {
5996 if (!
C->destroyLocals())
6000 return this->jump(*TargetLabel);
6003template <
class Emitter>
6006 if (
Cond->containsErrors())
6012 LabelTy EndLabel = this->getLabel();
6017 if (
const auto *CondInit = S->
getInit())
6028 if (!this->emitSetLocal(CondT, CondVar, S))
6038 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6041 if (CS->caseStmtIsGNURange()) {
6042 LabelTy EndOfRangeCheck = this->getLabel();
6043 const Expr *Low = CS->getLHS();
6044 const Expr *High = CS->getRHS();
6048 if (!this->emitGetLocal(CondT, CondVar, CS))
6050 if (!this->
visit(Low))
6053 if (!this->emitGE(
LT, S))
6055 if (!this->jumpFalse(EndOfRangeCheck))
6058 if (!this->emitGetLocal(CondT, CondVar, CS))
6060 if (!this->
visit(High))
6063 if (!this->emitLE(HT, S))
6067 this->emitLabel(EndOfRangeCheck);
6072 if (
Value->isValueDependent())
6077 if (!this->emitGetLocal(CondT, CondVar, CS))
6083 if (!this->emitEQ(ValueT, S))
6088 assert(!DefaultLabel);
6089 DefaultLabel = this->getLabel();
6096 if (!this->jump(*DefaultLabel))
6099 if (!this->jump(EndLabel))
6107 this->fallthrough(EndLabel);
6108 this->emitLabel(EndLabel);
6113template <
class Emitter>
6120template <
class Emitter>
6127 if (LI.DefaultLabel) {
6128 DefaultLabel = *LI.DefaultLabel;
6133 this->emitLabel(DefaultLabel);
6137template <
class Emitter>
6139 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6140 !this->Ctx.getLangOpts().MSVCCompat) {
6142 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6148 const Expr *Assumption = AA->getAssumption();
6159 if (!this->emitAssume(Assumption))
6168template <
class Emitter>
6174template <
class Emitter>
6175bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6182 assert(ClosureClass->
captures().empty());
6186 "A generic lambda's static-invoker function must be a "
6187 "template specialization");
6191 void *InsertPos =
nullptr;
6192 const FunctionDecl *CorrespondingCallOpSpecialization =
6194 assert(CorrespondingCallOpSpecialization);
6195 LambdaCallOp = CorrespondingCallOpSpecialization;
6199 assert(ClosureClass->
captures().empty());
6200 const Function *
Func = this->getFunction(LambdaCallOp);
6203 assert(
Func->hasThisPointer());
6206 if (
Func->hasRVO()) {
6207 if (!this->emitRVOPtr(MD))
6215 if (!this->emitNullPtr(0,
nullptr, MD))
6220 auto It = this->Params.find(PVD);
6221 assert(It != this->Params.end());
6225 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6226 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6230 if (!this->emitCall(
Func, 0, LambdaCallOp))
6235 return this->emitRet(*ReturnType, MD);
6238 return this->emitRetVoid(MD);
6241template <
class Emitter>
6242bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6243 if (Ctx.getLangOpts().CPlusPlus23)
6253 const Expr *InitExpr =
Init->getInit();
6255 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6259 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6269template <
class Emitter>
6271 assert(!ReturnType);
6273 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6274 const Expr *InitExpr,
6277 if (InitExpr->getType().isNull())
6281 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6284 if (!this->visit(InitExpr))
6287 bool BitField = F->isBitField();
6289 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6290 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6295 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6298 if (
Activate && !this->emitActivate(InitExpr))
6301 if (!this->visitInitializer(InitExpr))
6304 return this->emitFinishInitPop(InitExpr);
6308 const Record *R = this->getRecord(RD);
6317 return this->emitRetVoid(Ctor);
6320 if (!this->emitThis(Ctor))
6329 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6330 this->emitRetVoid(Ctor);
6334 for (
const auto *
Init : Ctor->
inits()) {
6336 LocalScope<Emitter>
Scope(
this);
6338 const Expr *InitExpr =
Init->getInit();
6344 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6347 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6350 if (
Init->isBaseVirtual()) {
6352 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6358 const Record::Base *B = R->
getBase(BaseDecl);
6360 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6364 if (IsUnion && !this->emitActivate(InitExpr))
6367 if (!this->visitInitializer(InitExpr))
6369 if (!this->emitFinishInitPop(InitExpr))
6374 assert(IFD->getChainingSize() >= 2);
6376 unsigned NestedFieldOffset = 0;
6377 const Record::Field *NestedField =
nullptr;
6378 for (
const NamedDecl *ND : IFD->chain()) {
6380 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6381 assert(FieldRecord);
6383 NestedField = FieldRecord->
getField(FD);
6384 assert(NestedField);
6385 IsUnion = IsUnion || FieldRecord->
isUnion();
6387 NestedFieldOffset += NestedField->Offset;
6389 assert(NestedField);
6391 unsigned FirstLinkOffset =
6395 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6400 unsigned InitFieldOffset = 0;
6401 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6403 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6404 assert(FieldRecord);
6405 NestedField = FieldRecord->
getField(FD);
6406 InitFieldOffset += NestedField->Offset;
6407 assert(NestedField);
6408 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6410 if (!this->emitFinishInitPop(InitExpr))
6415 assert(
Init->isDelegatingInitializer());
6416 if (!this->emitThis(InitExpr))
6418 if (!this->visitInitializer(
Init->getInit()))
6420 if (!this->emitPopPtr(InitExpr))
6424 if (!
Scope.destroyLocals())
6428 if (
const auto *Body = Ctor->
getBody())
6429 if (!visitStmt(Body))
6435template <
class Emitter>
6438 const Record *R = this->getRecord(RD);
6443 if (!this->visitStmt(Dtor->
getBody()))
6447 if (!this->emitThis(Dtor))
6450 if (!this->emitCheckDestruction(Dtor))
6458 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6462 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6464 if (!this->emitDestructionPop(D,
SourceInfo{}))
6469 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6470 if (
Base.R->hasTrivialDtor())
6474 if (!this->emitRecordDestructionPop(
Base.R, {}))
6479 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6482template <
class Emitter>
6483bool Compiler<Emitter>::compileUnionAssignmentOperator(
6485 if (!this->emitThis(MD))
6494 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6497template <
class Emitter>
6504 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6505 return this->compileConstructor(Ctor);
6506 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6507 return this->compileDestructor(Dtor);
6510 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6515 return this->compileUnionAssignmentOperator(MD);
6518 return this->emitLambdaStaticInvokerBody(MD);
6522 if (
const auto *Body = F->
getBody())
6536 return FD->getBitWidthValue();
6539template <
class Emitter>
6552 if (!
Ctx.getLangOpts().CPlusPlus14)
6553 return this->emitInvalid(E);
6555 return this->emitError(E);
6557 if (!this->
visit(SubExpr))
6561 if (!this->emitIncPtr(E))
6568 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6569 : this->emitIncf(getFPOptions(E), E);
6581 if (!
Ctx.getLangOpts().CPlusPlus14)
6582 return this->emitInvalid(E);
6584 return this->emitError(E);
6586 if (!this->
visit(SubExpr))
6590 if (!this->emitDecPtr(E))
6597 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6598 : this->emitDecf(getFPOptions(E), E);
6611 if (!
Ctx.getLangOpts().CPlusPlus14)
6612 return this->emitInvalid(E);
6614 return this->emitError(E);
6616 if (!this->
visit(SubExpr))
6620 if (!this->emitLoadPtr(E))
6622 if (!this->emitConstUint8(1, E))
6624 if (!this->emitAddOffsetUint8(E))
6626 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6632 return this->emitIncfPop(getFPOptions(E), E);
6642 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6643 if (!this->emitLoadFloat(E))
6645 APFloat F(TargetSemantics, 1);
6646 if (!this->emitFloat(F, E))
6649 if (!this->emitAddf(getFPOptions(E), E))
6651 if (!this->emitStoreFloat(E))
6663 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6666 if (!
Ctx.getLangOpts().CPlusPlus14)
6667 return this->emitInvalid(E);
6669 return this->emitError(E);
6671 if (!this->
visit(SubExpr))
6675 if (!this->emitLoadPtr(E))
6677 if (!this->emitConstUint8(1, E))
6679 if (!this->emitSubOffsetUint8(E))
6681 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6687 return this->emitDecfPop(getFPOptions(E), E);
6697 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6698 if (!this->emitLoadFloat(E))
6700 APFloat F(TargetSemantics, 1);
6701 if (!this->emitFloat(F, E))
6704 if (!this->emitSubf(getFPOptions(E), E))
6706 if (!this->emitStoreFloat(E))
6718 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6722 return this->emitError(E);
6725 return this->
discard(SubExpr);
6730 if (!this->emitInv(E))
6734 return this->emitCast(
PT_Bool, ET, E);
6738 return this->emitError(E);
6740 if (!this->
visit(SubExpr))
6745 return this->emitError(E);
6747 if (!this->
visit(SubExpr))
6760 return this->
discard(SubExpr);
6762 if (!this->
visit(SubExpr))
6769 return this->emitNarrowPtr(E);
6774 return this->emitError(E);
6776 if (!this->
visit(SubExpr))
6786 return this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6791 assert(
false &&
"Unhandled opcode");
6797template <
class Emitter>
6803 return this->
discard(SubExpr);
6806 auto prepareResult = [=]() ->
bool {
6811 return this->emitGetPtrLocal(*LocalIndex, E);
6818 unsigned SubExprOffset = ~0u;
6819 auto createTemp = [=, &SubExprOffset]() ->
bool {
6822 if (!this->
visit(SubExpr))
6824 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6828 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6829 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6831 return this->emitArrayElemPop(ElemT, Index, E);
6836 if (!prepareResult())
6840 for (
unsigned I = 0; I != 2; ++I) {
6841 if (!getElem(SubExprOffset, I))
6843 if (!this->emitNeg(ElemT, E))
6845 if (!this->emitInitElem(ElemT, I, E))
6856 if (!this->
visit(SubExpr))
6858 if (!this->emitComplexBoolCast(SubExpr))
6860 if (!this->emitInv(E))
6863 return this->emitCast(
PT_Bool, ET, E);
6867 return this->emitComplexReal(SubExpr);
6870 if (!this->
visit(SubExpr))
6874 if (!this->emitConstUint8(1, E))
6876 return this->emitArrayElemPtrPopUint8(E);
6884 if (!this->
visit(SubExpr))
6887 if (!this->emitArrayElem(ElemT, 1, E))
6889 if (!this->emitNeg(ElemT, E))
6891 if (!this->emitInitElem(ElemT, 1, E))
6899 return this->emitInvalid(E);
6905template <
class Emitter>
6911 return this->
discard(SubExpr);
6914 if (UnaryOp == UO_Extension)
6917 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6918 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6919 return this->emitInvalid(E);
6922 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
6929 if (!this->emitGetPtrLocal(*LocalIndex, E))
6934 unsigned SubExprOffset =
6936 if (!this->
visit(SubExpr))
6938 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
6943 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6944 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6946 return this->emitArrayElemPop(ElemT, Index, E);
6951 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6952 if (!getElem(SubExprOffset, I))
6954 if (!this->emitNeg(ElemT, E))
6956 if (!this->emitInitElem(ElemT, I, E))
6971 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6972 if (!getElem(SubExprOffset, I))
6975 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
6977 if (!this->emitInv(E))
6979 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
6981 if (!this->emitNeg(ElemT, E))
6983 if (ElemT != ResultVecElemT &&
6984 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
6986 if (!this->emitInitElem(ResultVecElemT, I, E))
6992 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6993 if (!getElem(SubExprOffset, I))
6996 if (!this->emitInv(E))
6999 if (!this->emitComp(ElemT, E))
7002 if (!this->emitInitElem(ElemT, I, E))
7007 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7012template <
class Emitter>
7017 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7018 return this->emitConst(ECD->getInitVal(), E);
7019 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7021 return F && this->emitGetFnPtr(F, E);
7023 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7025 if (!this->emitGetPtrGlobal(*Index, E))
7030 return this->emitInitGlobal(*
T, *Index, E);
7047 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7048 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7053 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7054 if (IsReference || !It->second.IsPtr)
7055 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
7057 return this->emitGetPtrParam(It->second.Offset, E);
7062 const unsigned Offset = It->second.Offset;
7065 return this->emitGetPtrLocal(Offset, E);
7068 if (
auto GlobalIndex =
P.getGlobal(D)) {
7070 if (!
Ctx.getLangOpts().CPlusPlus11)
7071 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7072 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7075 return this->emitGetPtrGlobal(*GlobalIndex, E);
7079 auto revisit = [&](
const VarDecl *VD) ->
bool {
7082 auto VarState = this->
visitDecl(VD,
true);
7084 if (!this->emitPopCC(E))
7087 if (VarState.notCreated())
7096 if (
auto It = this->LambdaCaptures.find(D);
7097 It != this->LambdaCaptures.end()) {
7098 auto [Offset, IsPtr] = It->second;
7101 return this->emitGetThisFieldPtr(Offset, E);
7102 return this->emitGetPtrThisField(Offset, E);
7105 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7106 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7107 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7111 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7112 return this->
visit(BD->getBinding());
7116 return this->emitDummyPtr(D, E);
7121 if (!
Ctx.getLangOpts().CPlusPlus) {
7122 if (
const auto *VD = dyn_cast<VarDecl>(D);
7126 return this->emitDummyPtr(D, E);
7130 const auto *VD = dyn_cast<VarDecl>(D);
7132 return this->emitDummyPtr(D, E);
7134 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7135 if (
T.isConstant(
Ctx.getASTContext()))
7137 return T->isReferenceType();
7141 typeShouldBeVisited(VD->
getType())) {
7143 Init && !
Init->isValueDependent()) {
7149 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7167 return this->emitDummyPtr(D, E);
7173 return this->emitDummyPtr(D, E);
7176template <
class Emitter>
7184 if (!
C->destroyLocals())
7190template <
class Emitter>
7191unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7194 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7196 return Ty->getAsCXXRecordDecl();
7198 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7199 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7201 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7205template <
class Emitter>
7212 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7217 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7218 getFPOptions(E), E);
7220 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7221 getFPOptions(E), E);
7225 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7230 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7232 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7236 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7240 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7241 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7248template <
class Emitter>
7251 assert(FromT != ToT);
7254 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7256 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7258 return this->emitCast(FromT, ToT, E);
7262template <
class Emitter>
7263bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7267 return this->
discard(SubExpr);
7269 if (!this->visit(SubExpr))
7272 if (!this->emitConstUint8(0, SubExpr))
7274 return this->emitArrayElemPtrPopUint8(SubExpr);
7278 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7282template <
class Emitter>
7283bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7284 assert(!DiscardResult);
7288 if (!this->emitArrayElem(ElemT, 0, E))
7291 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7294 if (!this->emitCast(ElemT,
PT_Bool, E))
7299 LabelTy LabelTrue = this->getLabel();
7300 if (!this->jumpTrue(LabelTrue))
7303 if (!this->emitArrayElemPop(ElemT, 1, E))
7306 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7309 if (!this->emitCast(ElemT,
PT_Bool, E))
7313 LabelTy EndLabel = this->getLabel();
7314 this->jump(EndLabel);
7316 this->emitLabel(LabelTrue);
7317 if (!this->emitPopPtr(E))
7319 if (!this->emitConstBool(
true, E))
7322 this->fallthrough(EndLabel);
7323 this->emitLabel(EndLabel);
7328template <
class Emitter>
7329bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7333 assert(!DiscardResult);
7339 LHSIsComplex =
true;
7340 ElemT = classifyComplexElementType(LHS->
getType());
7341 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7342 if (!this->visit(LHS))
7344 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7347 LHSIsComplex =
false;
7349 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7350 if (!this->visit(LHS))
7352 if (!this->emitSetLocal(LHST, LHSOffset, E))
7359 RHSIsComplex =
true;
7360 ElemT = classifyComplexElementType(RHS->
getType());
7361 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7362 if (!this->visit(RHS))
7364 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7367 RHSIsComplex =
false;
7369 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7370 if (!this->visit(RHS))
7372 if (!this->emitSetLocal(RHST, RHSOffset, E))
7376 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7377 bool IsComplex) ->
bool {
7379 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7381 return this->emitArrayElemPop(ElemT, Index, E);
7383 return this->emitGetLocal(ElemT, LocalOffset, E);
7386 for (
unsigned I = 0; I != 2; ++I) {
7388 if (!getElem(LHSOffset, I, LHSIsComplex))
7390 if (!getElem(RHSOffset, I, RHSIsComplex))
7393 if (!this->emitEQ(ElemT, E))
7396 if (!this->emitCastBoolUint8(E))
7401 if (!this->emitAddUint8(E))
7403 if (!this->emitConstUint8(2, E))
7407 if (!this->emitEQUint8(E))
7410 if (!this->emitNEUint8(E))
7417 return this->emitCast(
PT_Bool, ResT, E);
7424template <
class Emitter>
7425bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7431 const Function *DtorFunc = getFunction(Dtor);
7434 assert(DtorFunc->hasThisPointer());
7435 assert(DtorFunc->getNumParams() == 1);
7436 return this->emitCall(DtorFunc, 0, Loc);
7441template <
class Emitter>
7442bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7454 return this->emitPopPtr(Loc);
7456 for (ssize_t I = N - 1; I >= 1; --I) {
7457 if (!this->emitConstUint64(I, Loc))
7459 if (!this->emitArrayElemPtrUint64(Loc))
7461 if (!this->emitDestructionPop(ElemDesc, Loc))
7465 if (!this->emitConstUint64(0, Loc))
7467 if (!this->emitArrayElemPtrPopUint64(Loc))
7469 return this->emitDestructionPop(ElemDesc, Loc);
7474 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7479template <
class Emitter>
7480bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7481 assert(!DiscardResult &&
"Should've been checked before");
7483 unsigned DummyID = P.getOrCreateDummy(D);
7485 if (!this->emitGetPtrGlobal(DummyID, E))
7493 return this->emitDecayPtr(
PT_Ptr, PT, E);
7499template <
class Emitter>
7500bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7501 assert(!DiscardResult &&
"Should've been checked before");
7504 return this->emitConstFloat(
Floating(F), E);
7506 APInt I = F.bitcastToAPInt();
7507 return this->emitConstFloat(
7508 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7509 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7520template <
class Emitter>
7521bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7534 if (!this->emitGetPtrLocal(*LocalIndex, E))
7544 if (!this->visit(SubExpr))
7546 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7547 unsigned TempOffset =
7548 allocateLocalPrimitive(SubExpr, *FromT,
true);
7549 if (!this->visit(SubExpr))
7551 if (!this->emitSetLocal(*FromT, TempOffset, E))
7553 if (!this->emitGetPtrLocal(TempOffset, E))
7560 if (!this->emitBitCast(E))
7562 return DiscardResult ? this->emitPopPtr(E) :
true;
7566 const llvm::fltSemantics *TargetSemantics =
nullptr;
7568 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7574 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7576 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7577 ResultBitWidth, TargetSemantics,
7582 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()