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 +
2144 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2152 if (!this->emitActivate(Arg))
2156 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2159 if (!this->emitCheckNonNullArg(ArgT, Arg))
2170template <
class Emitter>
2175template <
class Emitter>
2181template <
class Emitter>
2187template <
class Emitter>
2203template <
class Emitter>
2205 auto It = E->
begin();
2206 return this->
visit(*It);
2211 bool AlignOfReturnsPreferred =
2212 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2218 T = Ref->getPointeeType();
2220 if (
T.getQualifiers().hasUnaligned())
2226 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2232template <
class Emitter>
2238 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2244 ArgType = Ref->getPointeeType();
2250 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2251 return this->emitInvalid(E);
2253 if (Kind == UETT_SizeOf)
2262 return this->emitConst(Size.getQuantity(), E);
2265 if (Kind == UETT_CountOf) {
2271 if (
const auto *CAT =
2275 return this->emitConst(CAT->getSize(), E);
2285 if (VAT->getElementType()->isArrayType()) {
2286 std::optional<APSInt> Res =
2288 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2293 return this->emitConst(*Res, E);
2298 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2315 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2318 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2328 return this->emitConst(Size.getQuantity(), E);
2331 if (Kind == UETT_VectorElements) {
2333 return this->emitConst(VT->getNumElements(), E);
2335 return this->emitSizelessVectorElementSize(E);
2338 if (Kind == UETT_VecStep) {
2340 unsigned N = VT->getNumElements();
2347 return this->emitConst(N, E);
2349 return this->emitConst(1, E);
2352 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2359 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2361 return this->emitInvalid(E);
2363 return this->emitConst(
2364 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2372template <
class Emitter>
2383 const auto maybeLoadValue = [&]() ->
bool {
2387 return this->emitLoadPop(*
T, E);
2391 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2395 if (
auto GlobalIndex =
P.getGlobal(VD))
2396 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2401 if (!this->
discard(Base) && !this->emitSideEffect(E))
2416 const Record::Field *F = R->
getField(FD);
2418 if (F->Decl->getType()->isReferenceType())
2419 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2420 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2423template <
class Emitter>
2432template <
class Emitter>
2451 for (
size_t I = 0; I != Size; ++I) {
2463template <
class Emitter>
2474 return this->emitGetLocal(SubExprT, It->second, E);
2476 if (!this->
visit(SourceExpr))
2483 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2489 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2499template <
class Emitter>
2522 bool IsBcpCall =
false;
2523 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2524 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2528 LabelTy LabelEnd = this->getLabel();
2529 LabelTy LabelFalse = this->getLabel();
2532 if (!this->emitStartSpeculation(E))
2540 if (this->checkingForUndefinedBehavior()) {
2543 if (!this->
discard(FalseExpr))
2549 if (!this->jumpFalse(LabelFalse))
2554 if (!this->jump(LabelEnd))
2556 this->emitLabel(LabelFalse);
2560 this->fallthrough(LabelEnd);
2561 this->emitLabel(LabelEnd);
2564 return this->emitEndSpeculation(E);
2568template <
class Emitter>
2574 unsigned StringIndex =
P.createGlobalString(E);
2575 return this->emitGetPtrGlobal(StringIndex, E);
2580 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2581 assert(CAT &&
"a string literal that's not a constant array?");
2586 unsigned N = std::min(ArraySize, E->
getLength());
2589 for (
unsigned I = 0; I != N; ++I) {
2592 if (CharWidth == 1) {
2593 this->emitConstSint8(CodeUnit, E);
2594 this->emitInitElemSint8(I, E);
2595 }
else if (CharWidth == 2) {
2596 this->emitConstUint16(CodeUnit, E);
2597 this->emitInitElemUint16(I, E);
2598 }
else if (CharWidth == 4) {
2599 this->emitConstUint32(CodeUnit, E);
2600 this->emitInitElemUint32(I, E);
2602 llvm_unreachable(
"unsupported character width");
2607 for (
unsigned I = N; I != ArraySize; ++I) {
2608 if (CharWidth == 1) {
2609 this->emitConstSint8(0, E);
2610 this->emitInitElemSint8(I, E);
2611 }
else if (CharWidth == 2) {
2612 this->emitConstUint16(0, E);
2613 this->emitInitElemUint16(I, E);
2614 }
else if (CharWidth == 4) {
2615 this->emitConstUint32(0, E);
2616 this->emitInitElemUint32(I, E);
2618 llvm_unreachable(
"unsupported character width");
2625template <
class Emitter>
2629 return this->emitDummyPtr(E, E);
2632template <
class Emitter>
2634 auto &A =
Ctx.getASTContext();
2643template <
class Emitter>
2651 auto &A =
Ctx.getASTContext();
2655 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2656 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2663 unsigned StringIndex =
P.createGlobalString(SL);
2664 return this->emitGetPtrGlobal(StringIndex, E);
2667template <
class Emitter>
2671 return this->emitConst(E->
getValue(), E);
2674template <
class Emitter>
2700 if (!this->emitSetLocal(*RT, TempOffset, E))
2706 if (!this->emitLoad(LHST, E))
2710 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2711 LHSComputationType, E))
2715 if (!this->emitGetLocal(*RT, TempOffset, E))
2720 if (!this->emitAddf(getFPOptions(E), E))
2724 if (!this->emitSubf(getFPOptions(E), E))
2728 if (!this->emitMulf(getFPOptions(E), E))
2732 if (!this->emitDivf(getFPOptions(E), E))
2743 return this->emitStorePop(LHST, E);
2744 return this->emitStore(LHST, E);
2747template <
class Emitter>
2756 if (Op != BO_AddAssign && Op != BO_SubAssign)
2765 if (!this->emitLoad(*
LT, LHS))
2771 if (Op == BO_AddAssign) {
2772 if (!this->emitAddOffset(*RT, E))
2775 if (!this->emitSubOffset(*RT, E))
2780 return this->emitStorePopPtr(E);
2781 return this->emitStorePtr(E);
2784template <
class Emitter>
2797 if (!
Ctx.getLangOpts().CPlusPlus14)
2798 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2800 if (!
LT || !RT || !ResultT || !LHSComputationT)
2825 if (!this->emitSetLocal(*RT, TempOffset, E))
2832 if (!this->emitLoad(*
LT, E))
2834 if (
LT != LHSComputationT &&
2840 if (!this->emitGetLocal(*RT, TempOffset, E))
2846 if (!this->emitAdd(*LHSComputationT, E))
2850 if (!this->emitSub(*LHSComputationT, E))
2854 if (!this->emitMul(*LHSComputationT, E))
2858 if (!this->emitDiv(*LHSComputationT, E))
2862 if (!this->emitRem(*LHSComputationT, E))
2866 if (!this->emitShl(*LHSComputationT, *RT, E))
2870 if (!this->emitShr(*LHSComputationT, *RT, E))
2874 if (!this->emitBitAnd(*LHSComputationT, E))
2878 if (!this->emitBitXor(*LHSComputationT, E))
2882 if (!this->emitBitOr(*LHSComputationT, E))
2886 llvm_unreachable(
"Unimplemented compound assign operator");
2890 if (ResultT != LHSComputationT &&
2891 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
2897 return this->emitStoreBitFieldPop(*ResultT, E);
2898 return this->emitStorePop(*ResultT, E);
2901 return this->emitStoreBitField(*ResultT, E);
2902 return this->emitStore(*ResultT, E);
2905template <
class Emitter>
2913template <
class Emitter>
2925 return this->
discard(SubExpr);
2940 if (!this->
visit(SubExpr))
2942 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2944 return this->emitGetPtrGlobal(*GlobalIndex, E);
2947 if (!this->checkLiteralType(SubExpr))
2950 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2954 return this->emitInitGlobalTempComp(TempDecl, E);
2965 unsigned LocalIndex =
2967 if (!this->VarScope->LocalsAlwaysEnabled &&
2968 !this->emitEnableLocal(LocalIndex, E))
2971 if (!this->
visit(SubExpr))
2973 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2976 return this->emitGetPtrLocal(LocalIndex, E);
2979 if (!this->checkLiteralType(SubExpr))
2987 if (!this->VarScope->LocalsAlwaysEnabled &&
2988 !this->emitEnableLocal(*LocalIndex, E))
2991 if (!this->emitGetPtrLocal(*LocalIndex, E))
2998template <
class Emitter>
3009 if (!this->
visit(SubExpr))
3013 return this->emitPopPtr(E);
3017template <
class Emitter>
3038 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3043 if (
P.isGlobalInitialized(*GlobalIndex))
3049 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3061 unsigned LocalIndex;
3065 LocalIndex = *MaybeIndex;
3069 if (!this->emitGetPtrLocal(LocalIndex, E))
3073 return this->
visit(
Init) && this->emitInit(*
T, E);
3077template <
class Emitter>
3090template <
class Emitter>
3094 return this->emitConst(E->
getValue(), E);
3097template <
class Emitter>
3110 for (
const Record::Field &F : R->
fields()) {
3112 if (!
Init ||
Init->containsErrors())
3120 if (!this->emitInitField(*
T, F.Offset, E))
3123 if (!this->emitGetPtrField(F.Offset, E))
3129 if (!this->emitPopPtr(E))
3137template <
class Emitter>
3144 return this->emitGetPtrGlobal(StringIndex, E);
3150template <
class Emitter>
3155 return this->emitInvalid(E);
3158template <
class Emitter>
3184 if (PointeeToT && PointeeFromT) {
3200 bool Fatal = (ToT != FromT);
3207template <
class Emitter>
3210 if (!
Ctx.getLangOpts().CPlusPlus20) {
3218template <
class Emitter>
3224 return this->emitConstBool(E->
getValue(), E);
3227template <
class Emitter>
3232 if (
T->isRecordType()) {
3246 if (!this->emitGetPtrLocal(*LocalIndex, E))
3254 T->getAsCXXRecordDecl()))
3262 if (!this->visitZeroRecordInitializer(R, E))
3274 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3276 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3277 if (!this->emitCheckFunctionDecl(Ctor, E))
3288 assert(
Func->hasThisPointer());
3289 assert(!
Func->hasRVO());
3293 if (!this->emitDupPtr(E))
3297 for (
const auto *Arg : E->
arguments()) {
3298 if (!this->
visit(Arg))
3302 if (
Func->isVariadic()) {
3303 uint32_t VarArgSize = 0;
3304 unsigned NumParams =
Func->getNumWrittenParams();
3305 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3309 if (!this->emitCallVar(
Func, VarArgSize, E))
3312 if (!this->emitCall(
Func, 0, E)) {
3317 (void)this->emitPopPtr(E);
3323 return this->emitPopPtr(E);
3324 return this->emitFinishInit(E);
3327 if (
T->isArrayType()) {
3332 if (!this->emitDupPtr(E))
3336 initArrayDimension = [&](
QualType T) ->
bool {
3337 if (!
T->isArrayType()) {
3339 for (
const auto *Arg : E->
arguments()) {
3340 if (!this->
visit(Arg))
3344 return this->emitCall(
Func, 0, E);
3348 Ctx.getASTContext().getAsConstantArrayType(
T);
3353 for (
size_t I = 0; I != NumElems; ++I) {
3354 if (!this->emitConstUint64(I, E))
3356 if (!this->emitArrayElemPtrUint64(E))
3358 if (!initArrayDimension(ElemTy))
3361 return this->emitPopPtr(E);
3364 return initArrayDimension(E->
getType());
3370template <
class Emitter>
3380 assert(Val.
isInt());
3382 return this->emitConst(I, E);
3389 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3390 return this->
visit(LValueExpr);
3405 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3409 const APValue &
V = UGCD->getValue();
3410 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3411 const Record::Field *F = R->
getField(I);
3412 const APValue &FieldValue =
V.getStructField(I);
3418 if (!this->emitInitField(FieldT, F->Offset, E))
3426template <
class Emitter>
3432 for (
unsigned I = 0; I != N; ++I) {
3439 if (!this->
discard(ArrayIndexExpr))
3444 if (!this->
visit(ArrayIndexExpr))
3448 if (!this->emitCast(IndexT,
PT_Sint64, E))
3458 return this->emitOffsetOf(
T, E, E);
3461template <
class Emitter>
3470 return this->visitZeroInitializer(*
T, Ty, E);
3477 if (!this->emitGetPtrLocal(*LocalIndex, E))
3482 QualType ElemQT = CT->getElementType();
3485 for (
unsigned I = 0; I != 2; ++I) {
3486 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3488 if (!this->emitInitElem(ElemT, I, E))
3500 if (!this->emitGetPtrLocal(*LocalIndex, E))
3505 QualType ElemQT = VT->getElementType();
3508 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3509 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3511 if (!this->emitInitElem(ElemT, I, E))
3520template <
class Emitter>
3525template <
class Emitter>
3531template <
class Emitter>
3536template <
class Emitter>
3541 return this->emitConst(E->
getValue(), E);
3544template <
class Emitter>
3549 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3567 if (!this->emitGetParam(PT, Offset, E))
3572 return this->emitCall(F, 0, E);
3577template <
class Emitter>
3585 const Expr *PlacementDest =
nullptr;
3586 bool IsNoThrow =
false;
3588 if (PlacementArgs != 0) {
3597 if (PlacementArgs == 1) {
3605 if (!this->emitInvalidNewDeleteExpr(E, E))
3610 if (OperatorNew->isReservedGlobalPlacementOperator())
3611 PlacementDest = Arg1;
3615 return this->emitInvalid(E);
3617 }
else if (!OperatorNew
3618 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3619 return this->emitInvalidNewDeleteExpr(E, E);
3622 if (!PlacementDest) {
3627 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3630 Desc =
P.createDescriptor(
3633 false,
false,
false,
3639 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3643 const Expr *Stripped = *ArraySizeExpr;
3644 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3645 Stripped = ICE->getSubExpr())
3646 if (ICE->getCastKind() != CK_NoOp &&
3647 ICE->getCastKind() != CK_IntegralCast)
3655 if (!this->
visit(Stripped))
3657 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3660 if (PlacementDest) {
3661 if (!this->
visit(PlacementDest))
3663 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3665 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3668 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3673 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3677 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3684 size_t StaticInitElems = 0;
3685 const Expr *DynamicInit =
nullptr;
3687 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3688 StaticInitElems = CAT->getZExtSize();
3692 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init);
3693 ILE && ILE->hasArrayFiller())
3694 DynamicInit = ILE->getArrayFiller();
3708 const Function *CtorFunc =
nullptr;
3709 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3713 }
else if (!DynamicInit)
3716 LabelTy EndLabel = this->getLabel();
3717 LabelTy StartLabel = this->getLabel();
3722 if (!this->emitDupPtr(E))
3724 if (!this->emitNullPtr(0,
nullptr, E))
3726 if (!this->emitEQPtr(E))
3728 if (!this->jumpTrue(EndLabel))
3735 if (!this->emitConst(StaticInitElems,
SizeT, E))
3737 if (!this->emitSetLocal(
SizeT, Iter, E))
3740 this->fallthrough(StartLabel);
3741 this->emitLabel(StartLabel);
3743 if (!this->emitGetLocal(
SizeT, Iter, E))
3745 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3747 if (!this->emitLT(
SizeT, E))
3749 if (!this->jumpFalse(EndLabel))
3753 if (!this->emitGetLocal(
SizeT, Iter, E))
3755 if (!this->emitArrayElemPtr(
SizeT, E))
3758 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3763 if (!this->visitZeroInitializer(InitT, ElemType, E))
3765 if (!this->emitStorePop(InitT, E))
3767 }
else if (DynamicInit) {
3769 if (!this->
visit(DynamicInit))
3771 if (!this->emitStorePop(*InitT, E))
3776 if (!this->emitPopPtr(E))
3781 if (!this->emitCall(CtorFunc, 0, E))
3786 if (!this->emitGetPtrLocal(Iter, E))
3788 if (!this->emitIncPop(
SizeT,
false, E))
3791 if (!this->jump(StartLabel))
3794 this->fallthrough(EndLabel);
3795 this->emitLabel(EndLabel);
3799 if (PlacementDest) {
3800 if (!this->
visit(PlacementDest))
3802 if (!this->emitCheckNewTypeMismatch(E, E))
3807 if (!this->emitAlloc(Desc, E))
3816 if (!this->emitInit(*ElemT, E))
3827 return this->emitPopPtr(E);
3832template <
class Emitter>
3838 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3839 return this->emitInvalidNewDeleteExpr(E, E);
3842 if (!this->
visit(Arg))
3848template <
class Emitter>
3854 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3859 return this->emitGetFnPtr(
Func, E);
3862template <
class Emitter>
3866 auto canonType = [](
const Type *
T) {
3867 return T->getCanonicalTypeUnqualified().getTypePtr();
3875 return this->emitGetTypeid(
3879 return this->emitGetTypeid(
3888 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3894 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3897 return this->emitPopPtr(E);
3901template <
class Emitter>
3903 assert(
Ctx.getLangOpts().CPlusPlus);
3904 return this->emitConstBool(E->
getValue(), E);
3907template <
class Emitter>
3919 return this->emitDummyPtr(GuidDecl, E);
3924 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3933 assert(
V.isStruct());
3934 assert(
V.getStructNumBases() == 0);
3938 return this->emitFinishInit(E);
3941template <
class Emitter>
3951template <
class Emitter>
3960template <
class Emitter>
3966template <
class Emitter>
3970 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
3974 if (OVE->isUnique())
3990template <
class Emitter>
3995template <
class Emitter>
3997 return this->emitError(E);
4000template <
class Emitter>
4006 return this->emitDummyPtr(E, E);
4009template <
class Emitter>
4013 QualType ElemType = VT->getElementType();
4017 PrimType SrcElemT = classifyVectorElementType(SrcType);
4019 unsigned SrcOffset =
4021 if (!this->
visit(Src))
4023 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4026 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4027 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4029 if (!this->emitArrayElemPop(SrcElemT, I, E))
4033 if (SrcElemT != ElemT) {
4034 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4036 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4037 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4041 if (!this->emitInitElem(ElemT, I, E))
4048template <
class Emitter>
4052 return this->emitInvalid(E);
4062 assert(NumOutputElems > 0);
4065 unsigned VectorOffsets[2];
4066 for (
unsigned I = 0; I != 2; ++I) {
4069 if (!this->
visit(Vecs[I]))
4071 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4074 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4076 assert(ShuffleIndex >= -1);
4077 if (ShuffleIndex == -1)
4078 return this->emitInvalidShuffleVectorIndex(I, E);
4080 assert(ShuffleIndex < (NumInputElems * 2));
4081 if (!this->emitGetLocal(
PT_Ptr,
4082 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4084 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4085 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4088 if (!this->emitInitElem(ElemT, I, E))
4095template <
class Emitter>
4100 Base->getType()->isVectorType() ||
4106 if (Indices.size() == 1) {
4111 if (!this->emitConstUint32(Indices[0], E))
4113 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4123 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4131 if (!this->emitGetPtrLocal(*ResultIndex, E))
4139 uint32_t DstIndex = 0;
4140 for (uint32_t I : Indices) {
4141 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4143 if (!this->emitArrayElemPop(ElemT, I, E))
4145 if (!this->emitInitElem(ElemT, DstIndex, E))
4155template <
class Emitter>
4159 return this->
discard(SubExpr) && this->emitInvalid(E);
4165 return this->emitDummyPtr(E, E);
4168template <
class Emitter>
4173 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4178 if (!this->
visit(SubExpr))
4180 if (!this->emitConstUint8(0, E))
4182 if (!this->emitArrayElemPtrPopUint8(E))
4189 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4191 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4193 assert(SecondFieldT ==
PT_Ptr);
4197 if (!this->emitExpandPtr(E))
4201 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4206template <
class Emitter>
4221 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4223 return this->emitUnsupported(E);
4232 return this->
Visit(E);
4239 return this->
Visit(E);
4243 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4246 if (
const auto *CE = dyn_cast<CastExpr>(E);
4248 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4255 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4258 if (
const auto *CE = dyn_cast<CastExpr>(E);
4259 CE && (CE->getCastKind() == CK_DerivedToBase ||
4260 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4261 CE->getCastKind() == CK_NoOp))
4281 if (!this->emitGetPtrLocal(*LocalIndex, E))
4291 return this->
Visit(E);
4294template <
class Emitter>
4300 return this->
Visit(E);
4306 return this->
Visit(E);
4314 if (!this->
visit(E))
4316 return this->emitComplexBoolCast(E);
4321 if (!this->
visit(E))
4329 return this->emitIsNonNullPtr(E);
4333 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4336 return this->emitCast(*
T,
PT_Bool, E);
4339template <
class Emitter>
4343 QT = AT->getValueType();
4347 return this->emitZeroBool(E);
4349 return this->emitZeroSint8(E);
4351 return this->emitZeroUint8(E);
4353 return this->emitZeroSint16(E);
4355 return this->emitZeroUint16(E);
4357 return this->emitZeroSint32(E);
4359 return this->emitZeroUint32(E);
4361 return this->emitZeroSint64(E);
4363 return this->emitZeroUint64(E);
4365 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4367 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4369 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4372 return this->emitNullMemberPtr(0,
nullptr, E);
4374 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4375 return this->emitFloat(F, E);
4378 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4382 llvm_unreachable(
"unknown primitive type");
4385template <
class Emitter>
4386bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4391 for (
const Record::Field &Field : R->
fields()) {
4392 if (Field.isUnnamedBitField())
4399 if (!this->visitZeroInitializer(
T, QT, E))
4402 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4406 if (!this->emitInitField(
T, Field.Offset, E))
4411 if (!this->emitGetPtrField(Field.Offset, E))
4417 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4418 if (!this->visitZeroInitializer(
T, ET, E))
4420 if (!this->emitInitElem(
T, I, E))
4425 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4428 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4436 if (!this->emitFinishInitActivatePop(E))
4440 if (!this->emitFinishInitPop(E))
4444 for (
const Record::Base &B : R->
bases()) {
4445 if (!this->emitGetPtrBase(B.Offset, E))
4447 if (!this->visitZeroRecordInitializer(B.R, E))
4449 if (!this->emitFinishInitPop(E))
4458template <
class Emitter>
4459bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4460 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4461 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4466 for (
size_t I = 0; I != NumElems; ++I) {
4467 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4469 if (!this->emitInitElem(*ElemT, I, E))
4475 const Record *R = getRecord(ElemType);
4477 for (
size_t I = 0; I != NumElems; ++I) {
4478 if (!this->emitConstUint32(I, E))
4480 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4482 if (!this->visitZeroRecordInitializer(R, E))
4484 if (!this->emitPopPtr(E))
4490 for (
size_t I = 0; I != NumElems; ++I) {
4491 if (!this->emitConstUint32(I, E))
4493 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4495 if (!this->visitZeroArrayInitializer(ElemType, E))
4497 if (!this->emitPopPtr(E))
4506template <
class Emitter>
4507bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4509 if (!canClassify(E->
getType()))
4512 if (!this->visit(RHS))
4514 if (!this->visit(LHS))
4521 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4525 bool Activates = refersToUnion(LHS);
4528 if (!this->emitFlip(
PT_Ptr, RHT, E))
4531 if (DiscardResult) {
4532 if (BitField && Activates)
4533 return this->emitStoreBitFieldActivatePop(RHT, E);
4535 return this->emitStoreBitFieldPop(RHT, E);
4537 return this->emitStoreActivatePop(RHT, E);
4539 return this->emitStorePop(RHT, E);
4542 auto maybeLoad = [&](
bool Result) ->
bool {
4548 return this->emitLoadPop(RHT, E);
4552 if (BitField && Activates)
4553 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4555 return maybeLoad(this->emitStoreBitField(RHT, E));
4557 return maybeLoad(this->emitStoreActivate(RHT, E));
4559 return maybeLoad(this->emitStore(RHT, E));
4562template <
class Emitter>
4563template <
typename T>
4567 return this->emitConstSint8(
Value, E);
4569 return this->emitConstUint8(
Value, E);
4571 return this->emitConstSint16(
Value, E);
4573 return this->emitConstUint16(
Value, E);
4575 return this->emitConstSint32(
Value, E);
4577 return this->emitConstUint32(
Value, E);
4579 return this->emitConstSint64(
Value, E);
4581 return this->emitConstUint64(
Value, E);
4583 return this->emitConstBool(
Value, E);
4590 llvm_unreachable(
"Invalid integral type");
4593 llvm_unreachable(
"unknown primitive type");
4596template <
class Emitter>
4597template <
typename T>
4598bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4599 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4602template <
class Emitter>
4606 return this->emitConstIntAPS(
Value, E);
4608 return this->emitConstIntAP(
Value, E);
4610 if (
Value.isSigned())
4611 return this->emitConst(
Value.getSExtValue(), Ty, E);
4612 return this->emitConst(
Value.getZExtValue(), Ty, E);
4615template <
class Emitter>
4619 return this->emitConstIntAPS(
Value, E);
4621 return this->emitConstIntAP(
Value, E);
4624 return this->emitConst(
Value.getSExtValue(), Ty, E);
4625 return this->emitConst(
Value.getZExtValue(), Ty, E);
4628template <
class Emitter>
4629bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4630 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4633template <
class Emitter>
4638 bool IsConstexprUnknown) {
4647 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4648 Locals.insert({VD, Local});
4649 VarScope->addForScopeKind(Local, SC);
4650 return Local.Offset;
4653template <
class Emitter>
4656 bool IsConstexprUnknown) {
4659 bool IsTemporary =
false;
4660 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4663 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4664 Init = VarD->getInit();
4666 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4674 IsTemporary,
false,
false,
Init);
4676 return std::nullopt;
4681 Locals.insert({Key, Local});
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);
5676 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5683 if (
auto *CondInit = IS->
getInit()) {
5699 return visitChildStmt(IS->
getThen());
5701 return visitChildStmt(Else);
5707 if (!this->emitIsConstantContext(IS))
5710 if (!this->emitIsConstantContext(IS))
5712 if (!this->emitInv(IS))
5726 LabelTy LabelElse = this->getLabel();
5727 LabelTy LabelEnd = this->getLabel();
5728 if (!this->jumpFalse(LabelElse))
5730 if (!visitChildStmt(IS->
getThen()))
5732 if (!this->jump(LabelEnd))
5734 this->emitLabel(LabelElse);
5735 if (!visitChildStmt(Else))
5737 this->emitLabel(LabelEnd);
5739 LabelTy LabelEnd = this->getLabel();
5740 if (!this->jumpFalse(LabelEnd))
5742 if (!visitChildStmt(IS->
getThen()))
5744 this->emitLabel(LabelEnd);
5753template <
class Emitter>
5758 LabelTy CondLabel = this->getLabel();
5759 LabelTy EndLabel = this->getLabel();
5763 this->fallthrough(CondLabel);
5764 this->emitLabel(CondLabel);
5778 if (!this->jumpFalse(EndLabel))
5787 if (!this->jump(CondLabel))
5789 this->fallthrough(EndLabel);
5790 this->emitLabel(EndLabel);
5798 LabelTy StartLabel = this->getLabel();
5799 LabelTy EndLabel = this->getLabel();
5800 LabelTy CondLabel = this->getLabel();
5804 this->fallthrough(StartLabel);
5805 this->emitLabel(StartLabel);
5811 this->fallthrough(CondLabel);
5812 this->emitLabel(CondLabel);
5819 if (!this->jumpTrue(StartLabel))
5822 this->fallthrough(EndLabel);
5823 this->emitLabel(EndLabel);
5827template <
class Emitter>
5835 LabelTy EndLabel = this->getLabel();
5836 LabelTy CondLabel = this->getLabel();
5837 LabelTy IncLabel = this->getLabel();
5844 this->fallthrough(CondLabel);
5845 this->emitLabel(CondLabel);
5857 if (!this->jumpFalse(EndLabel))
5866 this->fallthrough(IncLabel);
5867 this->emitLabel(IncLabel);
5873 if (!this->jump(CondLabel))
5877 this->emitLabel(EndLabel);
5883template <
class Emitter>
5893 LabelTy EndLabel = this->getLabel();
5894 LabelTy CondLabel = this->getLabel();
5895 LabelTy IncLabel = this->getLabel();
5910 this->fallthrough(CondLabel);
5911 this->emitLabel(CondLabel);
5914 if (!this->jumpFalse(EndLabel))
5925 this->fallthrough(IncLabel);
5926 this->emitLabel(IncLabel);
5931 if (!this->jump(CondLabel))
5934 this->fallthrough(EndLabel);
5935 this->emitLabel(EndLabel);
5939template <
class Emitter>
5950 if (LI.BreakLabel) {
5951 TargetLabel = *LI.BreakLabel;
5952 BreakScope = LI.BreakOrContinueScope;
5958 if (LI.Name == TargetLoop) {
5959 TargetLabel = *LI.BreakLabel;
5960 BreakScope = LI.BreakOrContinueScope;
5966 assert(TargetLabel);
5969 C =
C->getParent()) {
5970 if (!
C->destroyLocals())
5974 return this->jump(*TargetLabel);
5977template <
class Emitter>
5988 if (LI.ContinueLabel) {
5989 TargetLabel = *LI.ContinueLabel;
5990 ContinueScope = LI.BreakOrContinueScope;
5996 if (LI.Name == TargetLoop) {
5997 TargetLabel = *LI.ContinueLabel;
5998 ContinueScope = LI.BreakOrContinueScope;
6003 assert(TargetLabel);
6006 C =
C->getParent()) {
6007 if (!
C->destroyLocals())
6011 return this->jump(*TargetLabel);
6014template <
class Emitter>
6017 if (
Cond->containsErrors())
6023 LabelTy EndLabel = this->getLabel();
6028 if (
const auto *CondInit = S->
getInit())
6039 if (!this->emitSetLocal(CondT, CondVar, S))
6049 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6052 if (CS->caseStmtIsGNURange()) {
6053 LabelTy EndOfRangeCheck = this->getLabel();
6054 const Expr *Low = CS->getLHS();
6055 const Expr *High = CS->getRHS();
6059 if (!this->emitGetLocal(CondT, CondVar, CS))
6061 if (!this->
visit(Low))
6064 if (!this->emitGE(
LT, S))
6066 if (!this->jumpFalse(EndOfRangeCheck))
6069 if (!this->emitGetLocal(CondT, CondVar, CS))
6071 if (!this->
visit(High))
6074 if (!this->emitLE(HT, S))
6078 this->emitLabel(EndOfRangeCheck);
6083 if (
Value->isValueDependent())
6088 if (!this->emitGetLocal(CondT, CondVar, CS))
6094 if (!this->emitEQ(ValueT, S))
6099 assert(!DefaultLabel);
6100 DefaultLabel = this->getLabel();
6107 if (!this->jump(*DefaultLabel))
6110 if (!this->jump(EndLabel))
6118 this->fallthrough(EndLabel);
6119 this->emitLabel(EndLabel);
6124template <
class Emitter>
6131template <
class Emitter>
6138 if (LI.DefaultLabel) {
6139 DefaultLabel = *LI.DefaultLabel;
6144 this->emitLabel(DefaultLabel);
6148template <
class Emitter>
6150 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6151 !this->Ctx.getLangOpts().MSVCCompat) {
6153 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6159 const Expr *Assumption = AA->getAssumption();
6170 if (!this->emitAssume(Assumption))
6179template <
class Emitter>
6185template <
class Emitter>
6186bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6193 assert(ClosureClass->
captures().empty());
6197 "A generic lambda's static-invoker function must be a "
6198 "template specialization");
6202 void *InsertPos =
nullptr;
6203 const FunctionDecl *CorrespondingCallOpSpecialization =
6205 assert(CorrespondingCallOpSpecialization);
6206 LambdaCallOp = CorrespondingCallOpSpecialization;
6210 assert(ClosureClass->
captures().empty());
6211 const Function *
Func = this->getFunction(LambdaCallOp);
6214 assert(
Func->hasThisPointer());
6217 if (
Func->hasRVO()) {
6218 if (!this->emitRVOPtr(MD))
6226 if (!this->emitNullPtr(0,
nullptr, MD))
6231 auto It = this->Params.find(PVD);
6232 assert(It != this->Params.end());
6236 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6237 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6241 if (!this->emitCall(
Func, 0, LambdaCallOp))
6246 return this->emitRet(*ReturnType, MD);
6249 return this->emitRetVoid(MD);
6252template <
class Emitter>
6253bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6254 if (Ctx.getLangOpts().CPlusPlus23)
6264 const Expr *InitExpr =
Init->getInit();
6266 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6270 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6280template <
class Emitter>
6282 assert(!ReturnType);
6284 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6285 const Expr *InitExpr,
6288 if (InitExpr->getType().isNull())
6292 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6295 if (!this->visit(InitExpr))
6298 bool BitField = F->isBitField();
6300 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6301 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6306 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6309 if (
Activate && !this->emitActivate(InitExpr))
6312 if (!this->visitInitializer(InitExpr))
6315 return this->emitFinishInitPop(InitExpr);
6319 const Record *R = this->getRecord(RD);
6328 return this->emitRetVoid(Ctor);
6331 if (!this->emitThis(Ctor))
6340 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6341 this->emitRetVoid(Ctor);
6345 for (
const auto *
Init : Ctor->
inits()) {
6349 const Expr *InitExpr =
Init->getInit();
6355 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6358 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6361 if (
Init->isBaseVirtual()) {
6363 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6369 const Record::Base *B = R->
getBase(BaseDecl);
6371 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6375 if (IsUnion && !this->emitActivate(InitExpr))
6378 if (!this->visitInitializer(InitExpr))
6380 if (!this->emitFinishInitPop(InitExpr))
6385 assert(IFD->getChainingSize() >= 2);
6387 unsigned NestedFieldOffset = 0;
6388 const Record::Field *NestedField =
nullptr;
6389 for (
const NamedDecl *ND : IFD->chain()) {
6391 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6392 assert(FieldRecord);
6394 NestedField = FieldRecord->
getField(FD);
6395 assert(NestedField);
6396 IsUnion = IsUnion || FieldRecord->
isUnion();
6398 NestedFieldOffset += NestedField->Offset;
6400 assert(NestedField);
6402 unsigned FirstLinkOffset =
6406 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6411 unsigned InitFieldOffset = 0;
6412 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6414 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6415 assert(FieldRecord);
6416 NestedField = FieldRecord->
getField(FD);
6417 InitFieldOffset += NestedField->Offset;
6418 assert(NestedField);
6419 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6421 if (!this->emitFinishInitPop(InitExpr))
6426 assert(
Init->isDelegatingInitializer());
6427 if (!this->emitThis(InitExpr))
6429 if (!this->visitInitializer(
Init->getInit()))
6431 if (!this->emitPopPtr(InitExpr))
6435 if (!
Scope.destroyLocals())
6439 if (
const auto *Body = Ctor->
getBody())
6440 if (!visitStmt(Body))
6446template <
class Emitter>
6449 const Record *R = this->getRecord(RD);
6454 if (!this->visitStmt(Dtor->
getBody()))
6458 if (!this->emitThis(Dtor))
6461 if (!this->emitCheckDestruction(Dtor))
6469 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6473 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6475 if (!this->emitDestructionPop(D,
SourceInfo{}))
6480 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6481 if (
Base.R->hasTrivialDtor())
6485 if (!this->emitRecordDestructionPop(
Base.R, {}))
6490 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6493template <
class Emitter>
6494bool Compiler<Emitter>::compileUnionAssignmentOperator(
6496 if (!this->emitThis(MD))
6505 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6508template <
class Emitter>
6515 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6516 return this->compileConstructor(Ctor);
6517 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6518 return this->compileDestructor(Dtor);
6521 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6526 return this->compileUnionAssignmentOperator(MD);
6529 return this->emitLambdaStaticInvokerBody(MD);
6533 if (
const auto *Body = F->
getBody())
6547 return FD->getBitWidthValue();
6550template <
class Emitter>
6563 if (!
Ctx.getLangOpts().CPlusPlus14)
6564 return this->emitInvalid(E);
6566 return this->emitError(E);
6568 if (!this->
visit(SubExpr))
6572 if (!this->emitIncPtr(E))
6579 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6580 : this->emitIncf(getFPOptions(E), E);
6592 if (!
Ctx.getLangOpts().CPlusPlus14)
6593 return this->emitInvalid(E);
6595 return this->emitError(E);
6597 if (!this->
visit(SubExpr))
6601 if (!this->emitDecPtr(E))
6608 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6609 : this->emitDecf(getFPOptions(E), E);
6622 if (!
Ctx.getLangOpts().CPlusPlus14)
6623 return this->emitInvalid(E);
6625 return this->emitError(E);
6627 if (!this->
visit(SubExpr))
6631 if (!this->emitLoadPtr(E))
6633 if (!this->emitConstUint8(1, E))
6635 if (!this->emitAddOffsetUint8(E))
6637 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6643 return this->emitIncfPop(getFPOptions(E), E);
6653 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6654 if (!this->emitLoadFloat(E))
6656 APFloat F(TargetSemantics, 1);
6657 if (!this->emitFloat(F, E))
6660 if (!this->emitAddf(getFPOptions(E), E))
6662 if (!this->emitStoreFloat(E))
6674 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6677 if (!
Ctx.getLangOpts().CPlusPlus14)
6678 return this->emitInvalid(E);
6680 return this->emitError(E);
6682 if (!this->
visit(SubExpr))
6686 if (!this->emitLoadPtr(E))
6688 if (!this->emitConstUint8(1, E))
6690 if (!this->emitSubOffsetUint8(E))
6692 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6698 return this->emitDecfPop(getFPOptions(E), E);
6708 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6709 if (!this->emitLoadFloat(E))
6711 APFloat F(TargetSemantics, 1);
6712 if (!this->emitFloat(F, E))
6715 if (!this->emitSubf(getFPOptions(E), E))
6717 if (!this->emitStoreFloat(E))
6729 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6733 return this->emitError(E);
6736 return this->
discard(SubExpr);
6741 if (!this->emitInv(E))
6745 return this->emitCast(
PT_Bool, ET, E);
6749 return this->emitError(E);
6751 if (!this->
visit(SubExpr))
6756 return this->emitError(E);
6758 if (!this->
visit(SubExpr))
6771 return this->
discard(SubExpr);
6773 if (!this->
visit(SubExpr))
6780 return this->emitNarrowPtr(E);
6785 return this->emitError(E);
6787 if (!this->
visit(SubExpr))
6797 return this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6802 assert(
false &&
"Unhandled opcode");
6808template <
class Emitter>
6814 return this->
discard(SubExpr);
6817 auto prepareResult = [=]() ->
bool {
6822 return this->emitGetPtrLocal(*LocalIndex, E);
6829 unsigned SubExprOffset = ~0u;
6830 auto createTemp = [=, &SubExprOffset]() ->
bool {
6833 if (!this->
visit(SubExpr))
6835 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6839 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6840 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6842 return this->emitArrayElemPop(ElemT, Index, E);
6847 if (!prepareResult())
6851 for (
unsigned I = 0; I != 2; ++I) {
6852 if (!getElem(SubExprOffset, I))
6854 if (!this->emitNeg(ElemT, E))
6856 if (!this->emitInitElem(ElemT, I, E))
6867 if (!this->
visit(SubExpr))
6869 if (!this->emitComplexBoolCast(SubExpr))
6871 if (!this->emitInv(E))
6874 return this->emitCast(
PT_Bool, ET, E);
6878 return this->emitComplexReal(SubExpr);
6881 if (!this->
visit(SubExpr))
6885 if (!this->emitConstUint8(1, E))
6887 return this->emitArrayElemPtrPopUint8(E);
6895 if (!this->
visit(SubExpr))
6898 if (!this->emitArrayElem(ElemT, 1, E))
6900 if (!this->emitNeg(ElemT, E))
6902 if (!this->emitInitElem(ElemT, 1, E))
6910 return this->emitInvalid(E);
6916template <
class Emitter>
6922 return this->
discard(SubExpr);
6925 if (UnaryOp == UO_Extension)
6928 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6929 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6930 return this->emitInvalid(E);
6933 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
6940 if (!this->emitGetPtrLocal(*LocalIndex, E))
6945 unsigned SubExprOffset =
6947 if (!this->
visit(SubExpr))
6949 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
6954 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6955 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6957 return this->emitArrayElemPop(ElemT, Index, E);
6962 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6963 if (!getElem(SubExprOffset, I))
6965 if (!this->emitNeg(ElemT, E))
6967 if (!this->emitInitElem(ElemT, I, E))
6982 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6983 if (!getElem(SubExprOffset, I))
6986 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
6988 if (!this->emitInv(E))
6990 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
6992 if (!this->emitNeg(ElemT, E))
6994 if (ElemT != ResultVecElemT &&
6995 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
6997 if (!this->emitInitElem(ResultVecElemT, I, E))
7003 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7004 if (!getElem(SubExprOffset, I))
7007 if (!this->emitInv(E))
7010 if (!this->emitComp(ElemT, E))
7013 if (!this->emitInitElem(ElemT, I, E))
7018 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7023template <
class Emitter>
7028 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7029 return this->emitConst(ECD->getInitVal(), E);
7030 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7032 return F && this->emitGetFnPtr(F, E);
7034 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7036 if (!this->emitGetPtrGlobal(*Index, E))
7041 return this->emitInitGlobal(*
T, *Index, E);
7058 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7059 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7064 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7065 if (IsReference || !It->second.IsPtr)
7066 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
7068 return this->emitGetPtrParam(It->second.Offset, E);
7073 const unsigned Offset = It->second.Offset;
7076 return this->emitGetPtrLocal(Offset, E);
7079 if (
auto GlobalIndex =
P.getGlobal(D)) {
7081 if (!
Ctx.getLangOpts().CPlusPlus11)
7082 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7083 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7086 return this->emitGetPtrGlobal(*GlobalIndex, E);
7090 auto revisit = [&](
const VarDecl *VD) ->
bool {
7093 auto VarState = this->
visitDecl(VD,
true);
7095 if (!this->emitPopCC(E))
7098 if (VarState.notCreated())
7107 if (
auto It = this->LambdaCaptures.find(D);
7108 It != this->LambdaCaptures.end()) {
7109 auto [Offset, IsPtr] = It->second;
7112 return this->emitGetThisFieldPtr(Offset, E);
7113 return this->emitGetPtrThisField(Offset, E);
7116 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7117 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7118 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7122 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7123 return this->
visit(BD->getBinding());
7127 return this->emitDummyPtr(D, E);
7132 if (!
Ctx.getLangOpts().CPlusPlus) {
7133 if (
const auto *VD = dyn_cast<VarDecl>(D);
7137 return this->emitDummyPtr(D, E);
7141 const auto *VD = dyn_cast<VarDecl>(D);
7143 return this->emitDummyPtr(D, E);
7145 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7146 if (
T.isConstant(
Ctx.getASTContext()))
7148 return T->isReferenceType();
7152 typeShouldBeVisited(VD->
getType())) {
7154 Init && !
Init->isValueDependent()) {
7160 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7178 return this->emitDummyPtr(D, E);
7184 return this->emitDummyPtr(D, E);
7187template <
class Emitter>
7195 if (!
C->destroyLocals())
7201template <
class Emitter>
7202unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7205 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7207 return Ty->getAsCXXRecordDecl();
7209 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7210 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7212 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7216template <
class Emitter>
7223 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7228 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7229 getFPOptions(E), E);
7231 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7232 getFPOptions(E), E);
7236 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7241 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7243 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7247 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7251 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7252 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7259template <
class Emitter>
7262 assert(FromT != ToT);
7265 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7267 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7269 return this->emitCast(FromT, ToT, E);
7273template <
class Emitter>
7274bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7278 return this->
discard(SubExpr);
7280 if (!this->visit(SubExpr))
7283 if (!this->emitConstUint8(0, SubExpr))
7285 return this->emitArrayElemPtrPopUint8(SubExpr);
7289 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7293template <
class Emitter>
7294bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7295 assert(!DiscardResult);
7299 if (!this->emitArrayElem(ElemT, 0, E))
7302 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7305 if (!this->emitCast(ElemT,
PT_Bool, E))
7310 LabelTy LabelTrue = this->getLabel();
7311 if (!this->jumpTrue(LabelTrue))
7314 if (!this->emitArrayElemPop(ElemT, 1, E))
7317 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7320 if (!this->emitCast(ElemT,
PT_Bool, E))
7324 LabelTy EndLabel = this->getLabel();
7325 this->jump(EndLabel);
7327 this->emitLabel(LabelTrue);
7328 if (!this->emitPopPtr(E))
7330 if (!this->emitConstBool(
true, E))
7333 this->fallthrough(EndLabel);
7334 this->emitLabel(EndLabel);
7339template <
class Emitter>
7340bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7344 assert(!DiscardResult);
7350 LHSIsComplex =
true;
7351 ElemT = classifyComplexElementType(LHS->
getType());
7352 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7353 if (!this->visit(LHS))
7355 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7358 LHSIsComplex =
false;
7360 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7361 if (!this->visit(LHS))
7363 if (!this->emitSetLocal(LHST, LHSOffset, E))
7370 RHSIsComplex =
true;
7371 ElemT = classifyComplexElementType(RHS->
getType());
7372 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7373 if (!this->visit(RHS))
7375 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7378 RHSIsComplex =
false;
7380 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7381 if (!this->visit(RHS))
7383 if (!this->emitSetLocal(RHST, RHSOffset, E))
7387 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7388 bool IsComplex) ->
bool {
7390 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7392 return this->emitArrayElemPop(ElemT, Index, E);
7394 return this->emitGetLocal(ElemT, LocalOffset, E);
7397 for (
unsigned I = 0; I != 2; ++I) {
7399 if (!getElem(LHSOffset, I, LHSIsComplex))
7401 if (!getElem(RHSOffset, I, RHSIsComplex))
7404 if (!this->emitEQ(ElemT, E))
7407 if (!this->emitCastBoolUint8(E))
7412 if (!this->emitAddUint8(E))
7414 if (!this->emitConstUint8(2, E))
7418 if (!this->emitEQUint8(E))
7421 if (!this->emitNEUint8(E))
7428 return this->emitCast(
PT_Bool, ResT, E);
7435template <
class Emitter>
7436bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7442 const Function *DtorFunc = getFunction(Dtor);
7445 assert(DtorFunc->hasThisPointer());
7446 assert(DtorFunc->getNumParams() == 1);
7447 return this->emitCall(DtorFunc, 0, Loc);
7452template <
class Emitter>
7453bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7465 return this->emitPopPtr(Loc);
7467 for (ssize_t I = N - 1; I >= 1; --I) {
7468 if (!this->emitConstUint64(I, Loc))
7470 if (!this->emitArrayElemPtrUint64(Loc))
7472 if (!this->emitDestructionPop(ElemDesc, Loc))
7476 if (!this->emitConstUint64(0, Loc))
7478 if (!this->emitArrayElemPtrPopUint64(Loc))
7480 return this->emitDestructionPop(ElemDesc, Loc);
7485 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7490template <
class Emitter>
7491bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7492 assert(!DiscardResult &&
"Should've been checked before");
7494 unsigned DummyID = P.getOrCreateDummy(D);
7496 if (!this->emitGetPtrGlobal(DummyID, E))
7504 return this->emitDecayPtr(
PT_Ptr, PT, E);
7510template <
class Emitter>
7511bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7512 assert(!DiscardResult &&
"Should've been checked before");
7515 return this->emitConstFloat(
Floating(F), E);
7517 APInt I = F.bitcastToAPInt();
7518 return this->emitConstFloat(
7519 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7520 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7531template <
class Emitter>
7532bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7545 if (!this->emitGetPtrLocal(*LocalIndex, E))
7555 if (!this->visit(SubExpr))
7557 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7558 unsigned TempOffset =
7559 allocateLocalPrimitive(SubExpr, *FromT,
true);
7560 if (!this->visit(SubExpr))
7562 if (!this->emitSetLocal(*FromT, TempOffset, E))
7564 if (!this->emitGetPtrLocal(TempOffset, E))
7571 if (!this->emitBitCast(E))
7573 return DiscardResult ? this->emitPopPtr(E) :
true;
7577 const llvm::fltSemantics *TargetSemantics =
nullptr;
7579 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7585 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7587 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7588 ResultBitWidth, TargetSemantics,
7593 return this->emitPop(*ToT, E);
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool 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.
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.
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block, bool IsConstexprUnknown=false)
Creates a local primitive value.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
typename Emitter::LabelTy LabelTy
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false, bool IsConstexprUnknown=false)
Creates and initializes a variable from the given decl.
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VisitGNUNullExpr(const GNUNullExpr *E)
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block, bool IsConstexprUnknown=false)
Allocates a space storing a local given its type.
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const ValueDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const 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.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
static constexpr MetadataSize InlineDescMD
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink Decl(const ValueDecl *D)
static InitLink Temp(unsigned Offset)
bool isUnnamedBitField() const
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()