29 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
30 CE && CE->hasAPValueResult() &&
32 return CE->getResultAsAPSInt().getBoolValue();
43 OldInitializingDecl(
Ctx->InitializingDecl) {
44 Ctx->InitializingDecl = VD;
49 this->
Ctx->InitializingDecl = OldInitializingDecl;
50 this->
Ctx->InitStack.pop_back();
63 bool NewInitializing,
bool NewToLValue)
64 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
65 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
66 Ctx->DiscardResult = NewDiscardResult;
67 Ctx->Initializing = NewInitializing;
68 Ctx->ToLValue = NewToLValue;
72 Ctx->DiscardResult = OldDiscardResult;
73 Ctx->Initializing = OldInitializing;
74 Ctx->ToLValue = OldToLValue;
81 bool OldDiscardResult;
86template <
class Emitter>
90 return Ctx->emitThis(E);
93 return Ctx->emitGetPtrFieldPop(
Offset, E);
95 return Ctx->emitGetPtrLocal(
Offset, E);
99 if (!Ctx->emitConstUint32(
Offset, E))
101 return Ctx->emitArrayElemPtrPopUint32(E);
103 return Ctx->emitRVOPtr(E);
107 llvm_unreachable(
"Unhandled InitLink kind");
123 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
124 assert(LI.Name != Name);
127 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
148 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
150 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
151 assert(LI.Name != Name);
154 this->Ctx->CaseLabels = std::move(CaseLabels);
155 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
157 DefaultLabel, Ctx->VarScope);
161 this->Ctx->CaseLabels = std::move(OldCaseLabels);
162 this->Ctx->LabelInfoStack.pop_back();
167 CaseMap OldCaseLabels;
173 Ctx->InStmtExpr =
true;
191 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
194 Ctx->LocOverride = NewValue;
199 Ctx->LocOverride = OldFlag;
204 std::optional<SourceInfo> OldFlag;
211template <
class Emitter>
212bool Compiler<Emitter>::isValidBitCast(
const CastExpr *E) {
216 if (classify(FromTy) == classify(ToTy))
224template <
class Emitter>
232 case CK_LValueToRValue: {
243 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
249 if (
auto GlobalIndex =
P.getGlobal(D))
250 return this->emitGetGlobal(*SubExprT, *GlobalIndex, CE);
251 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
252 return this->emitGetLocal(*SubExprT, It->second.Offset, CE);
253 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
254 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
255 return this->emitGetParam(*SubExprT, It->second.Offset, CE);
267 if (!this->emitGetPtrLocal(*LocalIndex, CE))
271 if (!this->
visit(SubExpr))
275 return this->emitLoadPop(*SubExprT, CE);
280 return this->emitMemcpy(CE);
283 case CK_DerivedToBaseMemberPointer: {
289 unsigned DerivedOffset =
291 FromMP->getMostRecentCXXRecordDecl());
296 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
299 case CK_BaseToDerivedMemberPointer: {
305 unsigned DerivedOffset =
306 Ctx.collectBaseOffset(FromMP->getMostRecentCXXRecordDecl(),
311 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
314 case CK_UncheckedDerivedToBase:
315 case CK_DerivedToBase: {
320 if (
const auto *PT = dyn_cast<PointerType>(Ty))
321 return PT->getPointeeType()->getAsCXXRecordDecl();
322 return Ty->getAsCXXRecordDecl();
329 if (B->isVirtual()) {
330 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), CE))
332 CurType = B->getType();
334 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
335 if (!this->emitGetPtrBasePop(
338 CurType = B->getType();
345 case CK_BaseToDerived: {
348 unsigned DerivedOffset =
354 return this->emitGetPtrDerivedPop(DerivedOffset,
359 case CK_FloatingCast: {
364 if (!this->
visit(SubExpr))
366 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
370 case CK_IntegralToFloating: {
373 if (!this->
visit(SubExpr))
375 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
376 return this->emitCastIntegralFloating(
377 classifyPrim(SubExpr), TargetSemantics, getFPOptions(CE), CE);
380 case CK_FloatingToBoolean: {
384 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
385 return this->emitConstBool(FL->getValue().isNonZero(), CE);
386 if (!this->
visit(SubExpr))
388 return this->emitCastFloatingIntegralBool(getFPOptions(CE), CE);
391 case CK_FloatingToIntegral: {
394 if (!this->
visit(SubExpr))
398 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(CE->
getType()),
399 getFPOptions(CE), CE);
401 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
402 getFPOptions(CE), CE);
404 return this->emitCastFloatingIntegral(ToT, getFPOptions(CE), CE);
407 case CK_NullToPointer:
408 case CK_NullToMemberPointer: {
413 if (!PointeeType.
isNull()) {
415 Desc =
P.createDescriptor(SubExpr, *
T);
417 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
421 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(CE->
getType());
425 case CK_PointerToIntegral: {
426 if (!this->
visit(SubExpr))
432 if (!this->emitDecayPtr(FromT,
PT_Ptr, CE))
438 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(CE->
getType()),
441 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
443 return this->emitCastPointerIntegral(
T, CE);
446 case CK_ArrayToPointerDecay: {
447 if (!this->
visit(SubExpr))
449 return this->emitArrayDecay(CE);
452 case CK_IntegralToPointer: {
454 assert(IntType->isIntegralOrEnumerationType());
455 if (!this->
visit(SubExpr))
463 Desc =
P.createDescriptor(SubExpr, *
T);
470 if (!this->emitGetIntPtr(
T, Desc, CE))
478 return this->emitDecayPtr(
PT_Ptr, DestPtrT, CE);
481 case CK_AtomicToNonAtomic:
482 case CK_ConstructorConversion:
483 case CK_FunctionToPointerDecay:
484 case CK_NonAtomicToAtomic:
486 case CK_UserDefinedConversion:
487 case CK_AddressSpaceConversion:
488 case CK_CPointerToObjCPointerCast:
503 return this->emitBuiltinBitCast(CE);
509 if (!this->isValidBitCast(CE) &&
521 if (!this->
visit(SubExpr))
525 return this->emitFnPtrCast(CE);
532 if (!this->
visit(SubExpr))
534 return this->emitDecayPtr(*FromT, *ToT, CE);
536 case CK_IntegralToBoolean:
537 case CK_FixedPointToBoolean: {
543 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
544 return this->emitConst(IL->getValue(), CE);
545 if (!this->
visit(SubExpr))
550 case CK_BooleanToSignedIntegral:
551 case CK_IntegralCast: {
558 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
563 if (!this->emitConst(IL->getValue(), SubExpr))
566 if (!this->
visit(SubExpr))
574 if (!ED->isFixed()) {
575 if (!this->emitCheckEnumValue(*FromT, ED, CE))
581 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
584 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
589 if (!this->emitCast(*FromT, *ToT, CE))
592 if (CE->
getCastKind() == CK_BooleanToSignedIntegral)
593 return this->emitNeg(*ToT, CE);
597 case CK_PointerToBoolean:
598 case CK_MemberPointerToBoolean: {
601 if (!this->
visit(SubExpr))
603 return this->emitIsNonNull(PtrT, CE);
606 case CK_IntegralComplexToBoolean:
607 case CK_FloatingComplexToBoolean: {
608 if (!this->
visit(SubExpr))
610 return this->emitComplexBoolCast(SubExpr);
613 case CK_IntegralComplexToReal:
614 case CK_FloatingComplexToReal:
615 return this->emitComplexReal(SubExpr);
617 case CK_IntegralRealToComplex:
618 case CK_FloatingRealToComplex: {
625 if (!this->emitGetPtrLocal(*LocalIndex, CE))
634 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
636 return this->emitInitElem(
T, 1, SubExpr);
639 case CK_IntegralComplexCast:
640 case CK_FloatingComplexCast:
641 case CK_IntegralComplexToFloatingComplex:
642 case CK_FloatingComplexToIntegralComplex: {
649 if (!this->emitGetPtrLocal(*LocalIndex, CE))
656 unsigned SubExprOffset =
658 if (!this->
visit(SubExpr))
660 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, CE))
668 for (
unsigned I = 0; I != 2; ++I) {
669 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, CE))
671 if (!this->emitArrayElemPop(SourceElemT, I, CE))
675 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, CE))
679 if (!this->emitInitElem(DestElemT, I, CE))
685 case CK_VectorSplat: {
694 if (!this->emitGetPtrLocal(*LocalIndex, CE))
700 unsigned ElemOffset =
704 if (!this->
visit(SubExpr))
709 if (!this->emitSetLocal(ElemT, ElemOffset, CE))
712 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
713 if (!this->emitGetLocal(ElemT, ElemOffset, CE))
715 if (!this->emitInitElem(ElemT, I, CE))
722 case CK_HLSLVectorTruncation: {
727 if (!this->
visit(SubExpr))
729 return this->emitArrayElemPop(*ResultT, 0, CE);
738 if (!this->emitGetPtrLocal(*LocalIndex, CE))
743 if (!this->
visit(SubExpr))
745 return this->emitCopyArray(classifyVectorElementType(CE->
getType()), 0, 0,
749 case CK_IntegralToFixedPoint: {
750 if (!this->
visit(SubExpr))
754 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
758 case CK_FloatingToFixedPoint: {
759 if (!this->
visit(SubExpr))
763 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
764 return this->emitCastFloatingFixedPoint(Sem, CE);
766 case CK_FixedPointToFloating: {
767 if (!this->
visit(SubExpr))
769 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
770 return this->emitCastFixedPointFloating(TargetSemantics, CE);
772 case CK_FixedPointToIntegral: {
773 if (!this->
visit(SubExpr))
777 case CK_FixedPointCast: {
778 if (!this->
visit(SubExpr))
781 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
782 return this->emitCastFixedPoint(Sem, CE);
789 return this->emitInvalid(CE);
791 llvm_unreachable(
"Unhandled clang::CastKind enum");
794template <
class Emitter>
796 return this->emitBuiltinBitCast(E);
799template <
class Emitter>
804 return this->emitConst(
LE->getValue(),
LE);
807template <
class Emitter>
813 return this->emitFloat(F, E);
816template <
class Emitter>
826 if (!this->emitGetPtrLocal(*LocalIndex, E))
833 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
835 if (!this->emitInitElem(SubExprT, 0, SubExpr))
840template <
class Emitter>
848 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
853template <
class Emitter>
858template <
class Emitter>
885 return this->emitComplexComparison(LHS, RHS, BO);
890 if (!this->
visit(LHS))
893 if (!this->
visit(RHS))
896 if (!this->emitToMemberPtr(BO))
902 if (!this->emitCastMemberPtrPtr(BO))
919 Ctx.getASTContext().CompCategories.lookupInfoForType(BO->
getType());
925 if (!this->emitGetPtrLocal(*ResultIndex, BO))
932 return this->emitCMP3(*
LT, CmpInfo, BO);
935 if (!
LT || !RT || !
T)
945 return this->visitAssignment(LHS, RHS, BO);
952 auto MaybeCastToBool = [
this,
T, BO](
bool Result) {
956 return this->emitPopBool(BO);
958 return this->emitCast(
PT_Bool, *
T, BO);
962 auto Discard = [
this,
T, BO](
bool Result) {
970 return MaybeCastToBool(this->emitEQ(*
LT, BO));
972 return MaybeCastToBool(this->emitNE(*
LT, BO));
974 return MaybeCastToBool(this->emitLT(*
LT, BO));
976 return MaybeCastToBool(this->emitLE(*
LT, BO));
978 return MaybeCastToBool(this->emitGT(*
LT, BO));
980 return MaybeCastToBool(this->emitGE(*
LT, BO));
983 return Discard(this->emitSubf(getFPOptions(BO), BO));
984 return Discard(this->emitSub(*
T, BO));
987 return Discard(this->emitAddf(getFPOptions(BO), BO));
988 return Discard(this->emitAdd(*
T, BO));
991 return Discard(this->emitMulf(getFPOptions(BO), BO));
992 return Discard(this->emitMul(*
T, BO));
994 return Discard(this->emitRem(*
T, BO));
997 return Discard(this->emitDivf(getFPOptions(BO), BO));
998 return Discard(this->emitDiv(*
T, BO));
1000 return Discard(this->emitBitAnd(*
T, BO));
1002 return Discard(this->emitBitOr(*
T, BO));
1004 return Discard(this->emitShl(*
LT, *RT, BO));
1006 return Discard(this->emitShr(*
LT, *RT, BO));
1008 return Discard(this->emitBitXor(*
T, BO));
1011 llvm_unreachable(
"Already handled earlier");
1016 llvm_unreachable(
"Unhandled binary op");
1021template <
class Emitter>
1027 if ((Op != BO_Add && Op != BO_Sub) ||
1038 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1039 if (!this->
visit(E))
1042 return this->emitDecayPtr(
T,
PT_Ptr, E);
1051 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1055 if (!this->emitSubPtr(IntT, E))
1062 if (!visitAsPointer(RHS, *RT))
1064 if (!this->
visit(LHS))
1068 if (!visitAsPointer(LHS, *
LT))
1070 if (!this->
visit(RHS))
1080 if (!this->emitAddOffset(OffsetType, E))
1088 if (!this->emitSubOffset(OffsetType, E))
1099template <
class Emitter>
1109 LabelTy LabelTrue = this->getLabel();
1110 LabelTy LabelEnd = this->getLabel();
1114 if (!this->jumpTrue(LabelTrue))
1119 if (!this->jump(LabelEnd))
1122 this->emitLabel(LabelTrue);
1123 this->emitConstBool(
true, E);
1124 this->fallthrough(LabelEnd);
1125 this->emitLabel(LabelEnd);
1128 assert(Op == BO_LAnd);
1131 LabelTy LabelFalse = this->getLabel();
1132 LabelTy LabelEnd = this->getLabel();
1136 if (!this->jumpFalse(LabelFalse))
1141 if (!this->jump(LabelEnd))
1144 this->emitLabel(LabelFalse);
1145 this->emitConstBool(
false, E);
1146 this->fallthrough(LabelEnd);
1147 this->emitLabel(LabelEnd);
1151 return this->emitPopBool(E);
1156 return this->emitCast(
PT_Bool, *
T, E);
1160template <
class Emitter>
1167 if (!this->emitGetPtrLocal(*LocalIndex, E))
1176 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1177 unsigned ResultOffset = ~0u;
1183 if (!this->emitDupPtr(E))
1185 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1190 LHSType = AT->getValueType();
1193 RHSType = AT->getValueType();
1202 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1207 if (!this->
visit(LHS))
1209 if (!this->
visit(RHS))
1211 return this->emitMulc(ElemT, E);
1214 if (Op == BO_Div && RHSIsComplex) {
1221 if (!LHSIsComplex) {
1226 LHSOffset = *LocalIndex;
1228 if (!this->emitGetPtrLocal(LHSOffset, E))
1231 if (!this->
visit(LHS))
1234 if (!this->emitInitElem(ElemT, 0, E))
1237 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1239 if (!this->emitInitElem(ElemT, 1, E))
1242 if (!this->
visit(LHS))
1246 if (!this->
visit(RHS))
1248 return this->emitDivc(ElemT, E);
1254 if (!this->
visit(LHS))
1256 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1261 if (!this->
visit(LHS))
1263 if (!this->emitSetLocal(LHST, LHSOffset, E))
1271 if (!this->
visit(RHS))
1273 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1278 if (!this->
visit(RHS))
1280 if (!this->emitSetLocal(RHST, RHSOffset, E))
1287 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1288 unsigned ElemIndex,
unsigned Offset,
1289 const Expr *E) ->
bool {
1291 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1293 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1296 if (ElemIndex == 0 || !LoadZero)
1303 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1306 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1313 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1316 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1319 if (!this->emitAddf(getFPOptions(E), E))
1322 if (!this->emitAdd(ResultElemT, E))
1327 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1330 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1333 if (!this->emitSubf(getFPOptions(E), E))
1336 if (!this->emitSub(ResultElemT, E))
1341 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1344 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1348 if (!this->emitMulf(getFPOptions(E), E))
1351 if (!this->emitMul(ResultElemT, E))
1356 assert(!RHSIsComplex);
1357 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1360 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1364 if (!this->emitDivf(getFPOptions(E), E))
1367 if (!this->emitDiv(ResultElemT, E))
1378 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1381 if (!this->emitPop(ResultElemT, E))
1388template <
class Emitter>
1393 "Comma op should be handled in VisitBinaryOperator");
1407 if (!this->emitGetPtrLocal(*LocalIndex, E))
1421 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1424 if (!this->
visit(LHS))
1426 if (!this->
visit(RHS))
1428 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1431 return this->emitPopPtr(E);
1436 unsigned LHSOffset =
1438 if (!this->
visit(LHS))
1440 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1444 unsigned RHSOffset =
1446 if (!this->
visit(RHS))
1448 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1460 if (NeedIntPromot) {
1462 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1467 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1468 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1470 if (!this->emitArrayElemPop(ElemT, Index, E))
1473 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1475 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1477 }
else if (NeedIntPromot) {
1478 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1484#define EMIT_ARITH_OP(OP) \
1486 if (ElemT == PT_Float) { \
1487 if (!this->emit##OP##f(getFPOptions(E), E)) \
1490 if (!this->emit##OP(ElemT, E)) \
1496 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1497 if (!getElem(LHSOffset, ElemT, I))
1499 if (!getElem(RHSOffset, RHSElemT, I))
1511 if (!this->emitRem(ElemT, E))
1515 if (!this->emitBitAnd(OpT, E))
1519 if (!this->emitBitOr(OpT, E))
1523 if (!this->emitBitXor(OpT, E))
1527 if (!this->emitShl(OpT, RHSElemT, E))
1531 if (!this->emitShr(OpT, RHSElemT, E))
1535 if (!this->emitEQ(ElemT, E))
1539 if (!this->emitNE(ElemT, E))
1543 if (!this->emitLE(ElemT, E))
1547 if (!this->emitLT(ElemT, E))
1551 if (!this->emitGE(ElemT, E))
1555 if (!this->emitGT(ElemT, E))
1560 if (!this->emitBitAnd(ResultElemT, E))
1565 if (!this->emitBitOr(ResultElemT, E))
1569 return this->emitInvalid(E);
1578 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1580 if (!this->emitNeg(ResultElemT, E))
1586 if (NeedIntPromot &&
1587 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1591 if (!this->emitInitElem(ResultElemT, I, E))
1600template <
class Emitter>
1610 auto LHSSemaInt = LHSSema.toOpaqueInt();
1612 auto RHSSemaInt = RHSSema.toOpaqueInt();
1614 if (!this->
visit(LHS))
1622 if (!this->
visit(RHS))
1631 auto ConvertResult = [&](
bool R) ->
bool {
1635 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1636 if (ResultSema != CommonSema)
1637 return this->emitCastFixedPoint(ResultSema, E);
1641 auto MaybeCastToBool = [&](
bool Result) {
1646 return this->emitPop(
T, E);
1648 return this->emitCast(
PT_Bool,
T, E);
1654 return MaybeCastToBool(this->emitEQFixedPoint(E));
1656 return MaybeCastToBool(this->emitNEFixedPoint(E));
1658 return MaybeCastToBool(this->emitLTFixedPoint(E));
1660 return MaybeCastToBool(this->emitLEFixedPoint(E));
1662 return MaybeCastToBool(this->emitGTFixedPoint(E));
1664 return MaybeCastToBool(this->emitGEFixedPoint(E));
1666 return ConvertResult(this->emitAddFixedPoint(E));
1668 return ConvertResult(this->emitSubFixedPoint(E));
1670 return ConvertResult(this->emitMulFixedPoint(E));
1672 return ConvertResult(this->emitDivFixedPoint(E));
1674 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1676 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1679 return this->emitInvalid(E);
1682 llvm_unreachable(
"unhandled binop opcode");
1685template <
class Emitter>
1694 if (!this->
visit(SubExpr))
1696 return this->emitNegFixedPoint(E);
1701 llvm_unreachable(
"Unhandled unary opcode");
1704template <
class Emitter>
1710 return this->visitZeroInitializer(*
T, QT, E);
1718 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1719 CXXRD && CXXRD->getNumVBases() > 0) {
1729 return this->visitZeroRecordInitializer(R, E);
1736 return this->visitZeroArrayInitializer(QT, E);
1740 QualType ElemQT = ComplexTy->getElementType();
1742 for (
unsigned I = 0; I < 2; ++I) {
1743 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1745 if (!this->emitInitElem(ElemT, I, E))
1752 unsigned NumVecElements = VecT->getNumElements();
1753 QualType ElemQT = VecT->getElementType();
1756 for (
unsigned I = 0; I < NumVecElements; ++I) {
1757 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1759 if (!this->emitInitElem(ElemT, I, E))
1768template <
class Emitter>
1778 for (
const Expr *SubExpr : {LHS, RHS}) {
1779 if (!this->
visit(SubExpr)) {
1786 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
1787 if (!this->emitExpandPtr(E))
1798 return this->emitError(E);
1801 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
1805 if (!this->emitArrayElemPtrPop(*IndexT, E))
1808 return this->emitPopPtr(E);
1814 return this->emitLoadPop(*
T, E);
1817template <
class Emitter>
1819 const Expr *ArrayFiller,
const Expr *E) {
1824 QT = AT->getValueType();
1827 if (Inits.size() == 0)
1829 return this->emitInvalid(E);
1844 if (Inits.size() == 0)
1845 return this->visitZeroInitializer(*
T, QT, E);
1846 assert(Inits.size() == 1);
1853 if (Inits.size() == 1 && E->
getType() == Inits[0]->getType())
1859 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
1866 bool BitField = FieldToInit->isBitField();
1868 return this->emitInitBitFieldActivate(
T, FieldToInit, E);
1870 return this->emitInitBitField(
T, FieldToInit, E);
1872 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
1873 return this->emitInitField(
T, FieldToInit->Offset, E);
1876 auto initCompositeField = [=](
const Record::Field *FieldToInit,
1884 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
1887 if (
Activate && !this->emitActivate(E))
1892 return this->emitPopPtr(E);
1896 if (Inits.size() == 0) {
1897 if (!this->visitZeroRecordInitializer(R, E))
1902 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
1903 FToInit = ILE->getInitializedFieldInUnion();
1907 const Record::Field *FieldToInit = R->
getField(FToInit);
1909 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
1912 if (!initCompositeField(FieldToInit,
Init,
true))
1916 return this->emitFinishInit(E);
1920 unsigned InitIndex = 0;
1923 while (InitIndex < R->getNumFields() &&
1928 const Record::Field *FieldToInit = R->
getField(InitIndex);
1929 if (!initPrimitiveField(FieldToInit,
Init, *
T))
1934 if (
const Record::Base *B = R->
getBase(
Init->getType())) {
1935 if (!this->emitGetPtrBase(B->Offset,
Init))
1941 if (!this->emitFinishInitPop(E))
1946 const Record::Field *FieldToInit = R->
getField(InitIndex);
1947 if (!initCompositeField(FieldToInit,
Init))
1953 return this->emitFinishInit(E);
1957 if (Inits.size() == 1 && QT == Inits[0]->getType())
1961 Ctx.getASTContext().getAsConstantArrayType(QT);
1964 if (!this->emitCheckArraySize(NumElems, E))
1968 unsigned ElementIndex = 0;
1970 if (
const auto *EmbedS =
1971 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
1979 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
1980 getFPOptions(E), E))
1986 return this->emitInitElem(TargetT, ElemIndex, IL);
1988 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2000 for (; ElementIndex != NumElems; ++ElementIndex) {
2006 return this->emitFinishInit(E);
2010 unsigned NumInits = Inits.size();
2015 QualType ElemQT = ComplexTy->getElementType();
2017 if (NumInits == 0) {
2019 for (
unsigned I = 0; I < 2; ++I) {
2020 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2022 if (!this->emitInitElem(ElemT, I, E))
2025 }
else if (NumInits == 2) {
2026 unsigned InitIndex = 0;
2031 if (!this->emitInitElem(ElemT, InitIndex, E))
2040 unsigned NumVecElements = VecT->getNumElements();
2041 assert(NumVecElements >= Inits.size());
2043 QualType ElemQT = VecT->getElementType();
2047 unsigned InitIndex = 0;
2054 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2055 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2056 InitVecT->getNumElements(), E))
2058 InitIndex += InitVecT->getNumElements();
2060 if (!this->emitInitElem(ElemT, InitIndex, E))
2066 assert(InitIndex <= NumVecElements);
2069 for (; InitIndex != NumVecElements; ++InitIndex) {
2070 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2072 if (!this->emitInitElem(ElemT, InitIndex, E))
2083template <
class Emitter>
2090 return this->emitInitElem(*InitT, ElemIndex,
Init);
2096 if (!this->emitConstUint32(ElemIndex,
Init))
2098 if (!this->emitArrayElemPtrUint32(
Init))
2102 return this->emitFinishInitPop(
Init);
2105template <
class Emitter>
2108 bool Activate,
bool IsOperatorCall) {
2110 llvm::BitVector NonNullArgs;
2111 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2114 bool ExplicitMemberFn =
false;
2115 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2116 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2118 unsigned ArgIndex = 0;
2119 for (
const Expr *Arg : Args) {
2121 if (!this->
visit(Arg))
2129 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2130 if (DeclIndex < FuncDecl->getNumParams())
2131 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2141 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2149 if (!this->emitActivate(Arg))
2153 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2156 if (!this->emitCheckNonNullArg(ArgT, Arg))
2167template <
class Emitter>
2172template <
class Emitter>
2178template <
class Emitter>
2184template <
class Emitter>
2200template <
class Emitter>
2202 auto It = E->
begin();
2203 return this->
visit(*It);
2208 bool AlignOfReturnsPreferred =
2209 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2215 T = Ref->getPointeeType();
2217 if (
T.getQualifiers().hasUnaligned())
2223 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2229template <
class Emitter>
2235 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2241 ArgType = Ref->getPointeeType();
2247 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2248 return this->emitInvalid(E);
2250 if (Kind == UETT_SizeOf)
2259 return this->emitConst(Size.getQuantity(), E);
2262 if (Kind == UETT_CountOf) {
2268 if (
const auto *CAT =
2272 return this->emitConst(CAT->getSize(), E);
2282 if (VAT->getElementType()->isArrayType()) {
2283 std::optional<APSInt> Res =
2285 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2290 return this->emitConst(*Res, E);
2295 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2312 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2315 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2325 return this->emitConst(Size.getQuantity(), E);
2328 if (Kind == UETT_VectorElements) {
2330 return this->emitConst(VT->getNumElements(), E);
2332 return this->emitSizelessVectorElementSize(E);
2335 if (Kind == UETT_VecStep) {
2337 unsigned N = VT->getNumElements();
2344 return this->emitConst(N, E);
2346 return this->emitConst(1, E);
2349 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2356 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2358 return this->emitInvalid(E);
2360 return this->emitConst(
2361 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2369template <
class Emitter>
2380 const auto maybeLoadValue = [&]() ->
bool {
2384 return this->emitLoadPop(*
T, E);
2388 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2392 if (
auto GlobalIndex =
P.getGlobal(VD))
2393 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2398 if (!this->
discard(Base) && !this->emitSideEffect(E))
2413 const Record::Field *F = R->
getField(FD);
2415 if (F->Decl->getType()->isReferenceType())
2416 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2417 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2420template <
class Emitter>
2429template <
class Emitter>
2448 for (
size_t I = 0; I != Size; ++I) {
2460template <
class Emitter>
2471 return this->emitGetLocal(SubExprT, It->second, E);
2473 if (!this->
visit(SourceExpr))
2480 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2486 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2496template <
class Emitter>
2503 auto visitChildExpr = [&](
const Expr *E) ->
bool {
2512 return visitChildExpr(TrueExpr);
2513 return visitChildExpr(FalseExpr);
2516 bool IsBcpCall =
false;
2517 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2518 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2522 LabelTy LabelEnd = this->getLabel();
2523 LabelTy LabelFalse = this->getLabel();
2526 if (!this->emitStartSpeculation(E))
2534 if (this->checkingForUndefinedBehavior()) {
2537 if (!this->
discard(FalseExpr))
2543 if (!this->jumpFalse(LabelFalse))
2545 if (!visitChildExpr(TrueExpr))
2547 if (!this->jump(LabelEnd))
2549 this->emitLabel(LabelFalse);
2550 if (!visitChildExpr(FalseExpr))
2552 this->fallthrough(LabelEnd);
2553 this->emitLabel(LabelEnd);
2556 return this->emitEndSpeculation(E);
2560template <
class Emitter>
2566 unsigned StringIndex =
P.createGlobalString(E);
2567 return this->emitGetPtrGlobal(StringIndex, E);
2572 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2573 assert(CAT &&
"a string literal that's not a constant array?");
2578 unsigned N = std::min(ArraySize, E->
getLength());
2581 for (
unsigned I = 0; I != N; ++I) {
2584 if (CharWidth == 1) {
2585 this->emitConstSint8(CodeUnit, E);
2586 this->emitInitElemSint8(I, E);
2587 }
else if (CharWidth == 2) {
2588 this->emitConstUint16(CodeUnit, E);
2589 this->emitInitElemUint16(I, E);
2590 }
else if (CharWidth == 4) {
2591 this->emitConstUint32(CodeUnit, E);
2592 this->emitInitElemUint32(I, E);
2594 llvm_unreachable(
"unsupported character width");
2599 for (
unsigned I = N; I != ArraySize; ++I) {
2600 if (CharWidth == 1) {
2601 this->emitConstSint8(0, E);
2602 this->emitInitElemSint8(I, E);
2603 }
else if (CharWidth == 2) {
2604 this->emitConstUint16(0, E);
2605 this->emitInitElemUint16(I, E);
2606 }
else if (CharWidth == 4) {
2607 this->emitConstUint32(0, E);
2608 this->emitInitElemUint32(I, E);
2610 llvm_unreachable(
"unsupported character width");
2617template <
class Emitter>
2621 return this->emitDummyPtr(E, E);
2624template <
class Emitter>
2626 auto &A =
Ctx.getASTContext();
2635template <
class Emitter>
2643 auto &A =
Ctx.getASTContext();
2647 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2648 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2655 unsigned StringIndex =
P.createGlobalString(SL);
2656 return this->emitGetPtrGlobal(StringIndex, E);
2659template <
class Emitter>
2663 return this->emitConst(E->
getValue(), E);
2666template <
class Emitter>
2692 if (!this->emitSetLocal(*RT, TempOffset, E))
2698 if (!this->emitLoad(LHST, E))
2702 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2703 LHSComputationType, E))
2707 if (!this->emitGetLocal(*RT, TempOffset, E))
2712 if (!this->emitAddf(getFPOptions(E), E))
2716 if (!this->emitSubf(getFPOptions(E), E))
2720 if (!this->emitMulf(getFPOptions(E), E))
2724 if (!this->emitDivf(getFPOptions(E), E))
2735 return this->emitStorePop(LHST, E);
2736 return this->emitStore(LHST, E);
2739template <
class Emitter>
2748 if (Op != BO_AddAssign && Op != BO_SubAssign)
2757 if (!this->emitLoad(*
LT, LHS))
2763 if (Op == BO_AddAssign) {
2764 if (!this->emitAddOffset(*RT, E))
2767 if (!this->emitSubOffset(*RT, E))
2772 return this->emitStorePopPtr(E);
2773 return this->emitStorePtr(E);
2776template <
class Emitter>
2789 if (!
Ctx.getLangOpts().CPlusPlus14)
2790 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2792 if (!
LT || !RT || !ResultT || !LHSComputationT)
2817 if (!this->emitSetLocal(*RT, TempOffset, E))
2824 if (!this->emitLoad(*
LT, E))
2826 if (
LT != LHSComputationT) {
2827 if (!this->emitCast(*
LT, *LHSComputationT, E))
2832 if (!this->emitGetLocal(*RT, TempOffset, E))
2838 if (!this->emitAdd(*LHSComputationT, E))
2842 if (!this->emitSub(*LHSComputationT, E))
2846 if (!this->emitMul(*LHSComputationT, E))
2850 if (!this->emitDiv(*LHSComputationT, E))
2854 if (!this->emitRem(*LHSComputationT, E))
2858 if (!this->emitShl(*LHSComputationT, *RT, E))
2862 if (!this->emitShr(*LHSComputationT, *RT, E))
2866 if (!this->emitBitAnd(*LHSComputationT, E))
2870 if (!this->emitBitXor(*LHSComputationT, E))
2874 if (!this->emitBitOr(*LHSComputationT, E))
2878 llvm_unreachable(
"Unimplemented compound assign operator");
2882 if (ResultT != LHSComputationT) {
2883 if (!this->emitCast(*LHSComputationT, *ResultT, E))
2890 return this->emitStoreBitFieldPop(*ResultT, E);
2891 return this->emitStorePop(*ResultT, E);
2894 return this->emitStoreBitField(*ResultT, E);
2895 return this->emitStore(*ResultT, E);
2898template <
class Emitter>
2906template <
class Emitter>
2918 return this->
discard(SubExpr);
2935 if (!this->
visit(SubExpr))
2937 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2939 return this->emitGetPtrGlobal(*GlobalIndex, E);
2942 if (!this->checkLiteralType(SubExpr))
2945 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2949 return this->emitInitGlobalTempComp(TempDecl, E);
2958 if (!this->
visit(SubExpr))
2960 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2962 return this->emitGetPtrLocal(LocalIndex, E);
2965 if (!this->checkLiteralType(SubExpr))
2971 if (!this->emitGetPtrLocal(*LocalIndex, E))
2978template <
class Emitter>
2989 if (!this->
visit(SubExpr))
2993 return this->emitPopPtr(E);
2997template <
class Emitter>
3018 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3023 if (
P.isGlobalInitialized(*GlobalIndex))
3029 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3041 unsigned LocalIndex;
3045 LocalIndex = *MaybeIndex;
3049 if (!this->emitGetPtrLocal(LocalIndex, E))
3053 return this->
visit(
Init) && this->emitInit(*
T, E);
3057template <
class Emitter>
3070template <
class Emitter>
3074 return this->emitConst(E->
getValue(), E);
3077template <
class Emitter>
3090 for (
const Record::Field &F : R->
fields()) {
3092 if (!
Init ||
Init->containsErrors())
3100 if (!this->emitInitField(*
T, F.Offset, E))
3103 if (!this->emitGetPtrField(F.Offset, E))
3109 if (!this->emitPopPtr(E))
3117template <
class Emitter>
3124 return this->emitGetPtrGlobal(StringIndex, E);
3130template <
class Emitter>
3135 return this->emitInvalid(E);
3138template <
class Emitter>
3164 if (PointeeToT && PointeeFromT) {
3180 bool Fatal = (ToT != FromT);
3187template <
class Emitter>
3190 if (!
Ctx.getLangOpts().CPlusPlus20) {
3198template <
class Emitter>
3204 return this->emitConstBool(E->
getValue(), E);
3207template <
class Emitter>
3212 if (
T->isRecordType()) {
3226 if (!this->emitGetPtrLocal(*LocalIndex, E))
3234 T->getAsCXXRecordDecl()))
3241 if (!this->visitZeroRecordInitializer(R, E))
3254 assert(
Func->hasThisPointer());
3255 assert(!
Func->hasRVO());
3259 if (!this->emitDupPtr(E))
3263 for (
const auto *Arg : E->
arguments()) {
3264 if (!this->
visit(Arg))
3268 if (
Func->isVariadic()) {
3269 uint32_t VarArgSize = 0;
3270 unsigned NumParams =
Func->getNumWrittenParams();
3271 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3275 if (!this->emitCallVar(
Func, VarArgSize, E))
3278 if (!this->emitCall(
Func, 0, E)) {
3283 (void)this->emitPopPtr(E);
3289 return this->emitPopPtr(E);
3290 return this->emitFinishInit(E);
3293 if (
T->isArrayType()) {
3298 if (!this->emitDupPtr(E))
3302 initArrayDimension = [&](
QualType T) ->
bool {
3303 if (!
T->isArrayType()) {
3305 for (
const auto *Arg : E->
arguments()) {
3306 if (!this->
visit(Arg))
3310 return this->emitCall(
Func, 0, E);
3314 Ctx.getASTContext().getAsConstantArrayType(
T);
3319 for (
size_t I = 0; I != NumElems; ++I) {
3320 if (!this->emitConstUint64(I, E))
3322 if (!this->emitArrayElemPtrUint64(E))
3324 if (!initArrayDimension(ElemTy))
3327 return this->emitPopPtr(E);
3330 return initArrayDimension(E->
getType());
3336template <
class Emitter>
3346 assert(Val.
isInt());
3348 return this->emitConst(I, E);
3355 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3356 return this->
visit(LValueExpr);
3371 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3375 const APValue &
V = UGCD->getValue();
3376 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3377 const Record::Field *F = R->
getField(I);
3378 const APValue &FieldValue =
V.getStructField(I);
3384 if (!this->emitInitField(FieldT, F->Offset, E))
3392template <
class Emitter>
3398 for (
unsigned I = 0; I != N; ++I) {
3405 if (!this->
discard(ArrayIndexExpr))
3410 if (!this->
visit(ArrayIndexExpr))
3414 if (!this->emitCast(IndexT,
PT_Sint64, E))
3424 return this->emitOffsetOf(
T, E, E);
3427template <
class Emitter>
3436 return this->visitZeroInitializer(*
T, Ty, E);
3443 if (!this->emitGetPtrLocal(*LocalIndex, E))
3448 QualType ElemQT = CT->getElementType();
3451 for (
unsigned I = 0; I != 2; ++I) {
3452 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3454 if (!this->emitInitElem(ElemT, I, E))
3466 if (!this->emitGetPtrLocal(*LocalIndex, E))
3471 QualType ElemQT = VT->getElementType();
3474 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3475 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3477 if (!this->emitInitElem(ElemT, I, E))
3486template <
class Emitter>
3491template <
class Emitter>
3497template <
class Emitter>
3502template <
class Emitter>
3507 return this->emitConst(E->
getValue(), E);
3510template <
class Emitter>
3515 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3533 if (!this->emitGetParam(PT, Offset, E))
3538 return this->emitCall(F, 0, E);
3543template <
class Emitter>
3551 const Expr *PlacementDest =
nullptr;
3552 bool IsNoThrow =
false;
3554 if (PlacementArgs != 0) {
3563 if (PlacementArgs == 1) {
3571 if (!this->emitInvalidNewDeleteExpr(E, E))
3576 if (OperatorNew->isReservedGlobalPlacementOperator())
3577 PlacementDest = Arg1;
3581 return this->emitInvalid(E);
3583 }
else if (!OperatorNew
3584 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3585 return this->emitInvalidNewDeleteExpr(E, E);
3588 if (!PlacementDest) {
3593 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3596 Desc =
P.createDescriptor(
3599 false,
false,
false,
3605 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3609 const Expr *Stripped = *ArraySizeExpr;
3610 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3611 Stripped = ICE->getSubExpr())
3612 if (ICE->getCastKind() != CK_NoOp &&
3613 ICE->getCastKind() != CK_IntegralCast)
3621 if (!this->
visit(Stripped))
3623 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3626 if (PlacementDest) {
3627 if (!this->
visit(PlacementDest))
3629 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3631 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3634 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3639 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3643 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3650 size_t StaticInitElems = 0;
3651 const Expr *DynamicInit =
nullptr;
3653 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3654 StaticInitElems = CAT->getZExtSize();
3658 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init);
3659 ILE && ILE->hasArrayFiller())
3660 DynamicInit = ILE->getArrayFiller();
3674 const Function *CtorFunc =
nullptr;
3675 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3679 }
else if (!DynamicInit)
3682 LabelTy EndLabel = this->getLabel();
3683 LabelTy StartLabel = this->getLabel();
3688 if (!this->emitDupPtr(E))
3690 if (!this->emitNullPtr(0,
nullptr, E))
3692 if (!this->emitEQPtr(E))
3694 if (!this->jumpTrue(EndLabel))
3701 if (!this->emitConst(StaticInitElems,
SizeT, E))
3703 if (!this->emitSetLocal(
SizeT, Iter, E))
3706 this->fallthrough(StartLabel);
3707 this->emitLabel(StartLabel);
3709 if (!this->emitGetLocal(
SizeT, Iter, E))
3711 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3713 if (!this->emitLT(
SizeT, E))
3715 if (!this->jumpFalse(EndLabel))
3719 if (!this->emitGetLocal(
SizeT, Iter, E))
3721 if (!this->emitArrayElemPtr(
SizeT, E))
3724 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3729 if (!this->visitZeroInitializer(InitT, ElemType, E))
3731 if (!this->emitStorePop(InitT, E))
3733 }
else if (DynamicInit) {
3735 if (!this->
visit(DynamicInit))
3737 if (!this->emitStorePop(*InitT, E))
3742 if (!this->emitPopPtr(E))
3747 if (!this->emitCall(CtorFunc, 0, E))
3752 if (!this->emitGetPtrLocal(Iter, E))
3754 if (!this->emitIncPop(
SizeT,
false, E))
3757 if (!this->jump(StartLabel))
3760 this->fallthrough(EndLabel);
3761 this->emitLabel(EndLabel);
3765 if (PlacementDest) {
3766 if (!this->
visit(PlacementDest))
3768 if (!this->emitCheckNewTypeMismatch(E, E))
3773 if (!this->emitAlloc(Desc, E))
3782 if (!this->emitInit(*ElemT, E))
3793 return this->emitPopPtr(E);
3798template <
class Emitter>
3804 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3805 return this->emitInvalidNewDeleteExpr(E, E);
3808 if (!this->
visit(Arg))
3814template <
class Emitter>
3820 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3825 return this->emitGetFnPtr(
Func, E);
3828template <
class Emitter>
3832 auto canonType = [](
const Type *
T) {
3833 return T->getCanonicalTypeUnqualified().getTypePtr();
3841 return this->emitGetTypeid(
3845 return this->emitGetTypeid(
3854 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3860 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3863 return this->emitPopPtr(E);
3867template <
class Emitter>
3869 assert(
Ctx.getLangOpts().CPlusPlus);
3870 return this->emitConstBool(E->
getValue(), E);
3873template <
class Emitter>
3885 return this->emitDummyPtr(GuidDecl, E);
3890 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3899 assert(
V.isStruct());
3900 assert(
V.getStructNumBases() == 0);
3904 return this->emitFinishInit(E);
3907template <
class Emitter>
3917template <
class Emitter>
3926template <
class Emitter>
3932template <
class Emitter>
3936 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
3940 if (OVE->isUnique())
3956template <
class Emitter>
3961template <
class Emitter>
3963 return this->emitError(E);
3966template <
class Emitter>
3972 return this->emitDummyPtr(E, E);
3975template <
class Emitter>
3979 QualType ElemType = VT->getElementType();
3983 PrimType SrcElemT = classifyVectorElementType(SrcType);
3985 unsigned SrcOffset =
3987 if (!this->
visit(Src))
3989 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
3992 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
3993 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
3995 if (!this->emitArrayElemPop(SrcElemT, I, E))
3999 if (SrcElemT != ElemT) {
4000 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4002 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4003 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4007 if (!this->emitInitElem(ElemT, I, E))
4014template <
class Emitter>
4018 return this->emitInvalid(E);
4028 assert(NumOutputElems > 0);
4031 unsigned VectorOffsets[2];
4032 for (
unsigned I = 0; I != 2; ++I) {
4035 if (!this->
visit(Vecs[I]))
4037 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4040 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4042 assert(ShuffleIndex >= -1);
4043 if (ShuffleIndex == -1)
4044 return this->emitInvalidShuffleVectorIndex(I, E);
4046 assert(ShuffleIndex < (NumInputElems * 2));
4047 if (!this->emitGetLocal(
PT_Ptr,
4048 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4050 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4051 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4054 if (!this->emitInitElem(ElemT, I, E))
4061template <
class Emitter>
4066 Base->getType()->isVectorType() ||
4072 if (Indices.size() == 1) {
4077 if (!this->emitConstUint32(Indices[0], E))
4079 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4089 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4097 if (!this->emitGetPtrLocal(*ResultIndex, E))
4105 uint32_t DstIndex = 0;
4106 for (uint32_t I : Indices) {
4107 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4109 if (!this->emitArrayElemPop(ElemT, I, E))
4111 if (!this->emitInitElem(ElemT, DstIndex, E))
4121template <
class Emitter>
4125 return this->
discard(SubExpr) && this->emitInvalid(E);
4131 return this->emitDummyPtr(E, E);
4134template <
class Emitter>
4139 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4144 if (!this->
visit(SubExpr))
4146 if (!this->emitConstUint8(0, E))
4148 if (!this->emitArrayElemPtrPopUint8(E))
4155 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4157 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4159 assert(SecondFieldT ==
PT_Ptr);
4163 if (!this->emitExpandPtr(E))
4167 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4172template <
class Emitter>
4187 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4189 return this->emitUnsupported(E);
4198 return this->
Visit(E);
4205 return this->
Visit(E);
4209 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4212 if (
const auto *CE = dyn_cast<CastExpr>(E);
4214 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4221 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4224 if (
const auto *CE = dyn_cast<CastExpr>(E);
4225 CE && (CE->getCastKind() == CK_DerivedToBase ||
4226 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4227 CE->getCastKind() == CK_NoOp))
4246 if (!this->emitGetPtrLocal(*LocalIndex, E))
4256 return this->
Visit(E);
4259template <
class Emitter>
4265 return this->
Visit(E);
4271 return this->
Visit(E);
4279 if (!this->
visit(E))
4281 return this->emitComplexBoolCast(E);
4286 if (!this->
visit(E))
4294 return this->emitIsNonNullPtr(E);
4298 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4301 return this->emitCast(*
T,
PT_Bool, E);
4304template <
class Emitter>
4308 QT = AT->getValueType();
4312 return this->emitZeroBool(E);
4314 return this->emitZeroSint8(E);
4316 return this->emitZeroUint8(E);
4318 return this->emitZeroSint16(E);
4320 return this->emitZeroUint16(E);
4322 return this->emitZeroSint32(E);
4324 return this->emitZeroUint32(E);
4326 return this->emitZeroSint64(E);
4328 return this->emitZeroUint64(E);
4330 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4332 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4334 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4337 return this->emitNullMemberPtr(0,
nullptr, E);
4339 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4340 return this->emitFloat(F, E);
4343 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4347 llvm_unreachable(
"unknown primitive type");
4350template <
class Emitter>
4351bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4356 for (
const Record::Field &Field : R->
fields()) {
4357 if (Field.isUnnamedBitField())
4364 if (!this->visitZeroInitializer(
T, QT, E))
4367 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4371 if (!this->emitInitField(
T, Field.Offset, E))
4376 if (!this->emitGetPtrField(Field.Offset, E))
4382 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4383 if (!this->visitZeroInitializer(
T, ET, E))
4385 if (!this->emitInitElem(
T, I, E))
4390 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4393 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4401 if (!this->emitFinishInitActivatePop(E))
4405 if (!this->emitFinishInitPop(E))
4409 for (
const Record::Base &B : R->
bases()) {
4410 if (!this->emitGetPtrBase(B.Offset, E))
4412 if (!this->visitZeroRecordInitializer(B.R, E))
4414 if (!this->emitFinishInitPop(E))
4423template <
class Emitter>
4424bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4425 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4426 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4431 for (
size_t I = 0; I != NumElems; ++I) {
4432 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4434 if (!this->emitInitElem(*ElemT, I, E))
4440 const Record *R = getRecord(ElemType);
4442 for (
size_t I = 0; I != NumElems; ++I) {
4443 if (!this->emitConstUint32(I, E))
4445 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4447 if (!this->visitZeroRecordInitializer(R, E))
4449 if (!this->emitPopPtr(E))
4455 for (
size_t I = 0; I != NumElems; ++I) {
4456 if (!this->emitConstUint32(I, E))
4458 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4460 if (!this->visitZeroArrayInitializer(ElemType, E))
4462 if (!this->emitPopPtr(E))
4471template <
class Emitter>
4472bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4474 if (!canClassify(E->
getType()))
4477 if (!this->visit(RHS))
4479 if (!this->visit(LHS))
4486 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4490 bool Activates = refersToUnion(LHS);
4493 if (!this->emitFlip(
PT_Ptr, RHT, E))
4496 if (DiscardResult) {
4497 if (BitField && Activates)
4498 return this->emitStoreBitFieldActivatePop(RHT, E);
4500 return this->emitStoreBitFieldPop(RHT, E);
4502 return this->emitStoreActivatePop(RHT, E);
4504 return this->emitStorePop(RHT, E);
4507 auto maybeLoad = [&](
bool Result) ->
bool {
4513 return this->emitLoadPop(RHT, E);
4517 if (BitField && Activates)
4518 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4520 return maybeLoad(this->emitStoreBitField(RHT, E));
4522 return maybeLoad(this->emitStoreActivate(RHT, E));
4524 return maybeLoad(this->emitStore(RHT, E));
4527template <
class Emitter>
4528template <
typename T>
4532 return this->emitConstSint8(
Value, E);
4534 return this->emitConstUint8(
Value, E);
4536 return this->emitConstSint16(
Value, E);
4538 return this->emitConstUint16(
Value, E);
4540 return this->emitConstSint32(
Value, E);
4542 return this->emitConstUint32(
Value, E);
4544 return this->emitConstSint64(
Value, E);
4546 return this->emitConstUint64(
Value, E);
4548 return this->emitConstBool(
Value, E);
4555 llvm_unreachable(
"Invalid integral type");
4558 llvm_unreachable(
"unknown primitive type");
4561template <
class Emitter>
4562template <
typename T>
4563bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4564 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4567template <
class Emitter>
4571 return this->emitConstIntAPS(
Value, E);
4573 return this->emitConstIntAP(
Value, E);
4575 if (
Value.isSigned())
4576 return this->emitConst(
Value.getSExtValue(), Ty, E);
4577 return this->emitConst(
Value.getZExtValue(), Ty, E);
4580template <
class Emitter>
4584 return this->emitConstIntAPS(
Value, E);
4586 return this->emitConstIntAP(
Value, E);
4589 return this->emitConst(
Value.getSExtValue(), Ty, E);
4590 return this->emitConst(
Value.getZExtValue(), Ty, E);
4593template <
class Emitter>
4594bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4595 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4598template <
class Emitter>
4610 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4611 Locals.insert({VD, Local});
4613 VarScope->addExtended(Local, ExtendingDecl);
4615 VarScope->addForScopeKind(Local, SC);
4616 return Local.Offset;
4619template <
class Emitter>
4623 bool IsConstexprUnknown) {
4626 bool IsTemporary =
false;
4627 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4630 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4631 Init = VarD->getInit();
4633 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4641 IsTemporary,
false,
false,
Init);
4643 return std::nullopt;
4648 Locals.insert({Key, Local});
4650 VarScope->addExtended(Local, ExtendingDecl);
4652 VarScope->addForScopeKind(Local, SC);
4653 return Local.Offset;
4656template <
class Emitter>
4666 return std::nullopt;
4676 return Local.Offset;
4679template <
class Emitter>
4681 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
4682 return PT->getPointeeType()->getAsCanonical<RecordType>();
4688 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
4692template <
class Emitter>
4694 return P.getOrCreateRecord(RD);
4697template <
class Emitter>
4699 return Ctx.getOrCreateFunction(FD);
4702template <
class Emitter>
4707 if (!DestroyToplevelScope) {
4708 if (!this->emitCheckAllocations(E))
4712 auto maybeDestroyLocals = [&]() ->
bool {
4713 if (DestroyToplevelScope)
4714 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
4715 return this->emitCheckAllocations(E);
4722 return this->emitRetVoid(E) && maybeDestroyLocals();
4730 return this->emitRet(*
T, E) && maybeDestroyLocals();
4738 if (!this->emitGetPtrLocal(*LocalOffset, E))
4744 if (!this->emitFinishInit(E))
4749 return this->emitRetValue(E) && maybeDestroyLocals();
4752 return maybeDestroyLocals() && this->emitCheckAllocations(E) &&
false;
4755template <
class Emitter>
4757 bool IsConstexprUnknown) {
4760 IsConstexprUnknown);
4769 if (
auto GlobalIndex =
P.getGlobal(VD)) {
4770 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4785template <
class Emitter>
4787 bool ConstantContext) {
4790 if (!ConstantContext) {
4804 auto GlobalIndex =
P.getGlobal(VD);
4805 assert(GlobalIndex);
4807 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
4810 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
4814 auto Local =
Locals.find(VD);
4815 assert(Local !=
Locals.end());
4817 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
4820 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
4830 auto GlobalIndex =
P.getGlobal(VD);
4831 assert(GlobalIndex);
4832 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4842 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
4845template <
class Emitter>
4848 bool Toplevel,
bool IsConstexprUnknown) {
4855 if (!this->isActive())
4860 if (
Init &&
Init->isValueDependent())
4864 auto checkDecl = [&]() ->
bool {
4866 return !NeedsOp || this->emitCheckDecl(VD, VD);
4874 if (
P.getPtrGlobal(*GlobalIndex).isInitialized())
4878 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
4892 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
4895 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
4901 return this->emitFinishInitGlobal(
Init);
4910 IsConstexprUnknown);
4921 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
4925 return this->emitSetLocal(*VarT, Offset, VD);
4933 if (!this->emitGetPtrLocal(*Offset,
Init))
4939 return this->emitFinishInitPop(
Init);
4944template <
class Emitter>
4949 return this->emitConst(Val.
getInt(), ValType, E);
4952 return this->emitFloat(F, E);
4957 return this->emitNull(ValType, 0,
nullptr, E);
4959 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
4960 return this->
visit(BaseExpr);
4965 return this->emitGetMemberPtr(MemberDecl, E);
4966 return this->emitNullMemberPtr(0,
nullptr, E);
4972template <
class Emitter>
4980 const Record::Field *RF = R->
getField(I);
4981 QualType FieldType = RF->Decl->getType();
4986 if (!this->emitInitField(*PT, RF->Offset, E))
4989 if (!this->emitGetPtrField(RF->Offset, E))
4993 if (!this->emitPopPtr(E))
5004 const Record::Field *RF = R->
getField(UnionField);
5008 return this->emitInitField(
T, RF->Offset, E);
5011 const auto *ArrType =
T->getAsArrayTypeUnsafe();
5012 QualType ElemType = ArrType->getElementType();
5013 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5018 if (!this->emitInitElem(*ElemT, A, E))
5021 if (!this->emitConstUint32(A, E))
5023 if (!this->emitArrayElemPtrUint32(E))
5027 if (!this->emitPopPtr(E))
5038template <
class Emitter>
5040 unsigned BuiltinID) {
5041 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5046 return this->emitConst(0, E);
5049 if (!this->emitStartSpeculation(E))
5051 LabelTy EndLabel = this->getLabel();
5052 if (!this->speculate(E, EndLabel))
5054 this->fallthrough(EndLabel);
5055 if (!this->emitEndSpeculation(E))
5064 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5065 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5066 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5067 BuiltinID == Builtin::BI__builtin_function_start) {
5070 return this->emitDummyPtr(E, E);
5081 if (!this->emitGetPtrLocal(*LocalIndex, E))
5086 switch (BuiltinID) {
5087 case Builtin::BI__builtin_object_size:
5088 case Builtin::BI__builtin_dynamic_object_size: {
5092 if (!this->
visit(Arg0))
5106 for (
const auto *Arg : E->
arguments()) {
5107 if (!this->
visit(Arg))
5113 if (!this->emitCallBI(E, BuiltinID, E))
5118 return this->emitPop(*ReturnT, E);
5124template <
class Emitter>
5141 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5142 DD && DD->isTrivial()) {
5144 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5146 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5147 this->emitPopPtr(E);
5163 if (!this->emitGetPtrLocal(*LocalIndex, E))
5171 if (!this->emitGetPtrLocal(*LocalIndex, E))
5175 if (!this->emitDupPtr(E))
5182 bool IsAssignmentOperatorCall =
false;
5183 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5184 OCE && OCE->isAssignmentOp()) {
5188 assert(Args.size() == 2);
5189 IsAssignmentOperatorCall =
true;
5190 std::reverse(Args.begin(), Args.end());
5196 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5197 MD && MD->isStatic()) {
5201 Args.erase(Args.begin());
5205 bool Devirtualized =
false;
5208 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5216 if (!this->
visit(Callee))
5218 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5220 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5222 if (!this->emitGetMemberPtrBase(E))
5225 const auto *InstancePtr = MC->getImplicitObjectArgument();
5232 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5233 Devirtualized =
true;
5234 if (!this->
visit(Stripped))
5237 if (!this->
visit(InstancePtr))
5241 if (!this->
visit(InstancePtr))
5245 }
else if (
const auto *PD =
5246 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5247 if (!this->emitCheckPseudoDtor(E))
5255 return this->emitEndLifetimePop(E);
5256 }
else if (!FuncDecl) {
5260 if (!this->
visit(Callee))
5262 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5266 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5271 if (IsAssignmentOperatorCall) {
5272 assert(Args.size() == 2);
5275 if (!this->emitFlip(Arg2T, Arg1T, E))
5289 assert(HasRVO ==
Func->hasRVO());
5291 bool HasQualifier =
false;
5292 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5293 HasQualifier = ME->hasQualifier();
5295 bool IsVirtual =
false;
5296 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5297 IsVirtual = !Devirtualized && MD->isVirtual();
5302 if (IsVirtual && !HasQualifier) {
5303 uint32_t VarArgSize = 0;
5304 unsigned NumParams =
5306 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5309 if (!this->emitCallVirt(
Func, VarArgSize, E))
5311 }
else if (
Func->isVariadic()) {
5312 uint32_t VarArgSize = 0;
5313 unsigned NumParams =
5315 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5317 if (!this->emitCallVar(
Func, VarArgSize, E))
5320 if (!this->emitCall(
Func, 0, E))
5329 uint32_t ArgSize = 0;
5330 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5336 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5338 if (!this->emitGetMemberPtrDecl(E))
5341 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5344 if (!this->emitCallPtr(ArgSize, E, E))
5355template <
class Emitter>
5362template <
class Emitter>
5369template <
class Emitter>
5374 return this->emitConstBool(E->
getValue(), E);
5377template <
class Emitter>
5383 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5384 return this->emitNullPtr(Val,
nullptr, E);
5387template <
class Emitter>
5395 return this->emitZero(
T, E);
5398template <
class Emitter>
5403 if (this->LambdaThisCapture.Offset > 0) {
5404 if (this->LambdaThisCapture.IsPtr)
5405 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5406 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5414 return this->emitThis(E);
5429 unsigned StartIndex = 0;
5430 unsigned EndIndex = 0;
5432 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5435 EndIndex = StartIndex;
5442 for (; StartIndex > 0; --StartIndex) {
5451 if (StartIndex == 0 && EndIndex == 0)
5454 assert(StartIndex < EndIndex);
5457 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5468 case Stmt::CompoundStmtClass:
5470 case Stmt::DeclStmtClass:
5472 case Stmt::ReturnStmtClass:
5474 case Stmt::IfStmtClass:
5476 case Stmt::WhileStmtClass:
5478 case Stmt::DoStmtClass:
5480 case Stmt::ForStmtClass:
5482 case Stmt::CXXForRangeStmtClass:
5484 case Stmt::BreakStmtClass:
5486 case Stmt::ContinueStmtClass:
5488 case Stmt::SwitchStmtClass:
5490 case Stmt::CaseStmtClass:
5492 case Stmt::DefaultStmtClass:
5494 case Stmt::AttributedStmtClass:
5496 case Stmt::CXXTryStmtClass:
5498 case Stmt::NullStmtClass:
5501 case Stmt::GCCAsmStmtClass:
5502 case Stmt::MSAsmStmtClass:
5503 case Stmt::GotoStmtClass:
5504 return this->emitInvalid(S);
5505 case Stmt::LabelStmtClass:
5508 if (
const auto *E = dyn_cast<Expr>(S))
5515template <
class Emitter>
5518 for (
const auto *InnerStmt : S->
body())
5521 return Scope.destroyLocals();
5524template <
class Emitter>
5525bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5526 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5527 for (
auto *BD : DD->flat_bindings())
5528 if (
auto *KD = BD->getHoldingVar();
5529 KD && !this->visitVarDecl(KD, KD->getInit()))
5538 const auto *CXXRD = dyn_cast<CXXRecordDecl>(FD->
getParent());
5539 return !CXXRD || CXXRD->hasTrivialDefaultConstructor();
5542template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5544 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5545 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5552 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5557 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5558 ICE && (ICE->getCastKind() == CK_NoOp ||
5559 ICE->getCastKind() == CK_DerivedToBase ||
5560 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5561 E = ICE->getSubExpr();
5565 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5566 const auto *ThisRecord =
5567 This->getType()->getPointeeType()->getAsRecordDecl();
5568 if (!ThisRecord->isUnion())
5571 if (
const auto *Ctor =
5572 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5573 return Ctor->getParent() == ThisRecord;
5582template <
class Emitter>
5584 bool EvaluateConditionDecl) {
5585 for (
const auto *D : DS->
decls()) {
5590 const auto *VD = dyn_cast<VarDecl>(D);
5597 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5604template <
class Emitter>
5607 return this->emitUnsupported(RS);
5613 if (!this->
visit(RE))
5619 if (RE->getType()->isVoidType()) {
5620 if (!this->
visit(RE))
5625 if (!this->emitRVOPtr(RE))
5629 if (!this->emitPopPtr(RE))
5633 return this->emitRetVoid(RS);
5639 return this->emitRetVoid(RS);
5643 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5649 if (
auto *CondInit = IS->
getInit())
5663 return visitChildStmt(IS->
getThen());
5665 return visitChildStmt(Else);
5671 if (!this->emitIsConstantContext(IS))
5674 if (!this->emitIsConstantContext(IS))
5676 if (!this->emitInv(IS))
5687 LabelTy LabelElse = this->getLabel();
5688 LabelTy LabelEnd = this->getLabel();
5689 if (!this->jumpFalse(LabelElse))
5691 if (!visitChildStmt(IS->
getThen()))
5693 if (!this->jump(LabelEnd))
5695 this->emitLabel(LabelElse);
5696 if (!visitChildStmt(Else))
5698 this->emitLabel(LabelEnd);
5700 LabelTy LabelEnd = this->getLabel();
5701 if (!this->jumpFalse(LabelEnd))
5703 if (!visitChildStmt(IS->
getThen()))
5705 this->emitLabel(LabelEnd);
5711template <
class Emitter>
5716 LabelTy CondLabel = this->getLabel();
5717 LabelTy EndLabel = this->getLabel();
5721 this->fallthrough(CondLabel);
5722 this->emitLabel(CondLabel);
5736 if (!this->jumpFalse(EndLabel))
5745 if (!this->jump(CondLabel))
5747 this->fallthrough(EndLabel);
5748 this->emitLabel(EndLabel);
5756 LabelTy StartLabel = this->getLabel();
5757 LabelTy EndLabel = this->getLabel();
5758 LabelTy CondLabel = this->getLabel();
5762 this->fallthrough(StartLabel);
5763 this->emitLabel(StartLabel);
5769 this->fallthrough(CondLabel);
5770 this->emitLabel(CondLabel);
5777 if (!this->jumpTrue(StartLabel))
5780 this->fallthrough(EndLabel);
5781 this->emitLabel(EndLabel);
5785template <
class Emitter>
5793 LabelTy EndLabel = this->getLabel();
5794 LabelTy CondLabel = this->getLabel();
5795 LabelTy IncLabel = this->getLabel();
5802 this->fallthrough(CondLabel);
5803 this->emitLabel(CondLabel);
5815 if (!this->jumpFalse(EndLabel))
5824 this->fallthrough(IncLabel);
5825 this->emitLabel(IncLabel);
5831 if (!this->jump(CondLabel))
5835 this->emitLabel(EndLabel);
5841template <
class Emitter>
5851 LabelTy EndLabel = this->getLabel();
5852 LabelTy CondLabel = this->getLabel();
5853 LabelTy IncLabel = this->getLabel();
5868 this->fallthrough(CondLabel);
5869 this->emitLabel(CondLabel);
5872 if (!this->jumpFalse(EndLabel))
5883 this->fallthrough(IncLabel);
5884 this->emitLabel(IncLabel);
5889 if (!this->jump(CondLabel))
5892 this->fallthrough(EndLabel);
5893 this->emitLabel(EndLabel);
5897template <
class Emitter>
5908 if (LI.BreakLabel) {
5909 TargetLabel = *LI.BreakLabel;
5910 BreakScope = LI.BreakOrContinueScope;
5916 if (LI.Name == TargetLoop) {
5917 TargetLabel = *LI.BreakLabel;
5918 BreakScope = LI.BreakOrContinueScope;
5924 assert(TargetLabel);
5928 C->emitDestruction();
5930 return this->jump(*TargetLabel);
5933template <
class Emitter>
5944 if (LI.ContinueLabel) {
5945 TargetLabel = *LI.ContinueLabel;
5946 ContinueScope = LI.BreakOrContinueScope;
5952 if (LI.Name == TargetLoop) {
5953 TargetLabel = *LI.ContinueLabel;
5954 ContinueScope = LI.BreakOrContinueScope;
5959 assert(TargetLabel);
5963 C->emitDestruction();
5965 return this->jump(*TargetLabel);
5968template <
class Emitter>
5971 if (
Cond->containsErrors())
5977 LabelTy EndLabel = this->getLabel();
5982 if (
const auto *CondInit = S->
getInit())
5993 if (!this->emitSetLocal(CondT, CondVar, S))
6003 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6005 if (CS->caseStmtIsGNURange())
6010 if (
Value->isValueDependent())
6015 if (!this->emitGetLocal(CondT, CondVar, CS))
6021 if (!this->emitEQ(ValueT, S))
6026 assert(!DefaultLabel);
6027 DefaultLabel = this->getLabel();
6034 if (!this->jump(*DefaultLabel))
6037 if (!this->jump(EndLabel))
6045 this->emitLabel(EndLabel);
6050template <
class Emitter>
6056template <
class Emitter>
6063 if (LI.DefaultLabel) {
6064 DefaultLabel = *LI.DefaultLabel;
6069 this->emitLabel(DefaultLabel);
6073template <
class Emitter>
6075 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6076 !this->Ctx.getLangOpts().MSVCCompat) {
6078 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6084 const Expr *Assumption = AA->getAssumption();
6095 if (!this->emitAssume(Assumption))
6104template <
class Emitter>
6110template <
class Emitter>
6111bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6118 assert(ClosureClass->
captures().empty());
6122 "A generic lambda's static-invoker function must be a "
6123 "template specialization");
6127 void *InsertPos =
nullptr;
6128 const FunctionDecl *CorrespondingCallOpSpecialization =
6130 assert(CorrespondingCallOpSpecialization);
6131 LambdaCallOp = CorrespondingCallOpSpecialization;
6135 assert(ClosureClass->
captures().empty());
6136 const Function *
Func = this->getFunction(LambdaCallOp);
6139 assert(
Func->hasThisPointer());
6142 if (
Func->hasRVO()) {
6143 if (!this->emitRVOPtr(MD))
6151 if (!this->emitNullPtr(0,
nullptr, MD))
6156 auto It = this->Params.find(PVD);
6157 assert(It != this->Params.end());
6161 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6162 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6166 if (!this->emitCall(
Func, 0, LambdaCallOp))
6171 return this->emitRet(*ReturnType, MD);
6174 return this->emitRetVoid(MD);
6177template <
class Emitter>
6178bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6179 if (Ctx.getLangOpts().CPlusPlus23)
6189 const Expr *InitExpr =
Init->getInit();
6191 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6195 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6205template <
class Emitter>
6207 assert(!ReturnType);
6209 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6210 const Expr *InitExpr,
6213 if (InitExpr->getType().isNull())
6217 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6220 if (!this->visit(InitExpr))
6223 bool BitField = F->isBitField();
6225 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6226 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6231 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6234 if (
Activate && !this->emitActivate(InitExpr))
6237 if (!this->visitInitializer(InitExpr))
6240 return this->emitFinishInitPop(InitExpr);
6244 const Record *R = this->getRecord(RD);
6253 return this->emitRetVoid(Ctor);
6256 if (!this->emitThis(Ctor))
6265 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6266 this->emitRetVoid(Ctor);
6270 for (
const auto *
Init : Ctor->
inits()) {
6272 LocalScope<Emitter>
Scope(
this);
6274 const Expr *InitExpr =
Init->getInit();
6280 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6283 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6286 if (
Init->isBaseVirtual()) {
6288 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6294 const Record::Base *B = R->
getBase(BaseDecl);
6296 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6300 if (IsUnion && !this->emitActivate(InitExpr))
6303 if (!this->visitInitializer(InitExpr))
6305 if (!this->emitFinishInitPop(InitExpr))
6310 assert(IFD->getChainingSize() >= 2);
6312 unsigned NestedFieldOffset = 0;
6313 const Record::Field *NestedField =
nullptr;
6314 for (
const NamedDecl *ND : IFD->chain()) {
6316 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6317 assert(FieldRecord);
6319 NestedField = FieldRecord->
getField(FD);
6320 assert(NestedField);
6321 IsUnion = IsUnion || FieldRecord->
isUnion();
6323 NestedFieldOffset += NestedField->Offset;
6325 assert(NestedField);
6327 unsigned FirstLinkOffset =
6331 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6336 unsigned InitFieldOffset = 0;
6337 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6339 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6340 assert(FieldRecord);
6341 NestedField = FieldRecord->
getField(FD);
6342 InitFieldOffset += NestedField->Offset;
6343 assert(NestedField);
6344 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6346 if (!this->emitFinishInitPop(InitExpr))
6351 assert(
Init->isDelegatingInitializer());
6352 if (!this->emitThis(InitExpr))
6354 if (!this->visitInitializer(
Init->getInit()))
6356 if (!this->emitPopPtr(InitExpr))
6360 if (!
Scope.destroyLocals())
6364 if (
const auto *Body = Ctor->
getBody())
6365 if (!visitStmt(Body))
6371template <
class Emitter>
6374 const Record *R = this->getRecord(RD);
6379 if (!this->visitStmt(Dtor->
getBody()))
6383 if (!this->emitThis(Dtor))
6386 if (!this->emitCheckDestruction(Dtor))
6394 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6398 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6400 if (!this->emitDestructionPop(D,
SourceInfo{}))
6405 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6406 if (
Base.R->hasTrivialDtor())
6410 if (!this->emitRecordDestructionPop(
Base.R, {}))
6415 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6418template <
class Emitter>
6419bool Compiler<Emitter>::compileUnionAssignmentOperator(
6421 if (!this->emitThis(MD))
6430 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6433template <
class Emitter>
6440 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6441 return this->compileConstructor(Ctor);
6442 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6443 return this->compileDestructor(Dtor);
6446 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6451 return this->compileUnionAssignmentOperator(MD);
6454 return this->emitLambdaStaticInvokerBody(MD);
6458 if (
const auto *Body = F->
getBody())
6472 return FD->getBitWidthValue();
6475template <
class Emitter>
6488 if (!
Ctx.getLangOpts().CPlusPlus14)
6489 return this->emitInvalid(E);
6491 return this->emitError(E);
6493 if (!this->
visit(SubExpr))
6497 if (!this->emitIncPtr(E))
6504 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6505 : this->emitIncf(getFPOptions(E), E);
6517 if (!
Ctx.getLangOpts().CPlusPlus14)
6518 return this->emitInvalid(E);
6520 return this->emitError(E);
6522 if (!this->
visit(SubExpr))
6526 if (!this->emitDecPtr(E))
6533 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6534 : this->emitDecf(getFPOptions(E), E);
6547 if (!
Ctx.getLangOpts().CPlusPlus14)
6548 return this->emitInvalid(E);
6550 return this->emitError(E);
6552 if (!this->
visit(SubExpr))
6556 if (!this->emitLoadPtr(E))
6558 if (!this->emitConstUint8(1, E))
6560 if (!this->emitAddOffsetUint8(E))
6562 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6568 return this->emitIncfPop(getFPOptions(E), E);
6578 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6579 if (!this->emitLoadFloat(E))
6581 APFloat F(TargetSemantics, 1);
6582 if (!this->emitFloat(F, E))
6585 if (!this->emitAddf(getFPOptions(E), E))
6587 if (!this->emitStoreFloat(E))
6599 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6602 if (!
Ctx.getLangOpts().CPlusPlus14)
6603 return this->emitInvalid(E);
6605 return this->emitError(E);
6607 if (!this->
visit(SubExpr))
6611 if (!this->emitLoadPtr(E))
6613 if (!this->emitConstUint8(1, E))
6615 if (!this->emitSubOffsetUint8(E))
6617 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6623 return this->emitDecfPop(getFPOptions(E), E);
6633 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6634 if (!this->emitLoadFloat(E))
6636 APFloat F(TargetSemantics, 1);
6637 if (!this->emitFloat(F, E))
6640 if (!this->emitSubf(getFPOptions(E), E))
6642 if (!this->emitStoreFloat(E))
6654 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6658 return this->emitError(E);
6661 return this->
discard(SubExpr);
6666 if (!this->emitInv(E))
6670 return this->emitCast(
PT_Bool, ET, E);
6674 return this->emitError(E);
6676 if (!this->
visit(SubExpr))
6681 return this->emitError(E);
6683 if (!this->
visit(SubExpr))
6696 return this->
discard(SubExpr);
6698 if (!this->
visit(SubExpr))
6705 return this->emitNarrowPtr(E);
6710 return this->emitError(E);
6712 if (!this->
visit(SubExpr))
6722 return this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6727 assert(
false &&
"Unhandled opcode");
6733template <
class Emitter>
6739 return this->
discard(SubExpr);
6742 auto prepareResult = [=]() ->
bool {
6747 return this->emitGetPtrLocal(*LocalIndex, E);
6754 unsigned SubExprOffset = ~0u;
6755 auto createTemp = [=, &SubExprOffset]() ->
bool {
6758 if (!this->
visit(SubExpr))
6760 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6764 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6765 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6767 return this->emitArrayElemPop(ElemT, Index, E);
6772 if (!prepareResult())
6776 for (
unsigned I = 0; I != 2; ++I) {
6777 if (!getElem(SubExprOffset, I))
6779 if (!this->emitNeg(ElemT, E))
6781 if (!this->emitInitElem(ElemT, I, E))
6792 if (!this->
visit(SubExpr))
6794 if (!this->emitComplexBoolCast(SubExpr))
6796 if (!this->emitInv(E))
6799 return this->emitCast(
PT_Bool, ET, E);
6803 return this->emitComplexReal(SubExpr);
6806 if (!this->
visit(SubExpr))
6810 if (!this->emitConstUint8(1, E))
6812 return this->emitArrayElemPtrPopUint8(E);
6820 if (!this->
visit(SubExpr))
6823 if (!this->emitArrayElem(ElemT, 1, E))
6825 if (!this->emitNeg(ElemT, E))
6827 if (!this->emitInitElem(ElemT, 1, E))
6835 return this->emitInvalid(E);
6841template <
class Emitter>
6847 return this->
discard(SubExpr);
6850 if (UnaryOp == UO_Extension)
6853 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6854 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6855 return this->emitInvalid(E);
6858 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
6865 if (!this->emitGetPtrLocal(*LocalIndex, E))
6870 unsigned SubExprOffset =
6872 if (!this->
visit(SubExpr))
6874 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
6879 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6880 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6882 return this->emitArrayElemPop(ElemT, Index, E);
6887 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6888 if (!getElem(SubExprOffset, I))
6890 if (!this->emitNeg(ElemT, E))
6892 if (!this->emitInitElem(ElemT, I, E))
6907 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6908 if (!getElem(SubExprOffset, I))
6911 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
6913 if (!this->emitInv(E))
6915 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
6917 if (!this->emitNeg(ElemT, E))
6919 if (ElemT != ResultVecElemT &&
6920 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
6922 if (!this->emitInitElem(ResultVecElemT, I, E))
6928 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6929 if (!getElem(SubExprOffset, I))
6932 if (!this->emitInv(E))
6935 if (!this->emitComp(ElemT, E))
6938 if (!this->emitInitElem(ElemT, I, E))
6943 llvm_unreachable(
"Unsupported unary operators should be handled up front");
6948template <
class Emitter>
6953 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
6954 return this->emitConst(ECD->getInitVal(), E);
6955 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
6957 return F && this->emitGetFnPtr(F, E);
6959 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6961 if (!this->emitGetPtrGlobal(*Index, E))
6966 return this->emitInitGlobal(*
T, *Index, E);
6983 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
6984 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
6989 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
6990 if (IsReference || !It->second.IsPtr)
6991 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
6993 return this->emitGetPtrParam(It->second.Offset, E);
6998 const unsigned Offset = It->second.Offset;
7001 return this->emitGetPtrLocal(Offset, E);
7004 if (
auto GlobalIndex =
P.getGlobal(D)) {
7006 if (!
Ctx.getLangOpts().CPlusPlus11)
7007 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7008 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7011 return this->emitGetPtrGlobal(*GlobalIndex, E);
7015 auto revisit = [&](
const VarDecl *VD) ->
bool {
7018 auto VarState = this->
visitDecl(VD,
true);
7020 if (!this->emitPopCC(E))
7023 if (VarState.notCreated())
7032 if (
auto It = this->LambdaCaptures.find(D);
7033 It != this->LambdaCaptures.end()) {
7034 auto [Offset, IsPtr] = It->second;
7037 return this->emitGetThisFieldPtr(Offset, E);
7038 return this->emitGetPtrThisField(Offset, E);
7041 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7042 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7043 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7047 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7048 return this->
visit(BD->getBinding());
7052 return this->emitDummyPtr(D, E);
7057 if (!
Ctx.getLangOpts().CPlusPlus) {
7058 if (
const auto *VD = dyn_cast<VarDecl>(D);
7062 return this->emitDummyPtr(D, E);
7066 const auto *VD = dyn_cast<VarDecl>(D);
7068 return this->emitDummyPtr(D, E);
7070 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7071 if (
T.isConstant(
Ctx.getASTContext()))
7073 return T->isReferenceType();
7077 typeShouldBeVisited(VD->
getType())) {
7079 Init && !
Init->isValueDependent()) {
7085 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7103 return this->emitDummyPtr(D, E);
7109 return this->emitDummyPtr(D, E);
7112template <
class Emitter>
7120 C->emitDestruction();
7123template <
class Emitter>
7124unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7127 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7129 return Ty->getAsCXXRecordDecl();
7131 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7132 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7134 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7138template <
class Emitter>
7145 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7150 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7151 getFPOptions(E), E);
7153 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7154 getFPOptions(E), E);
7158 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7163 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7165 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7169 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7173 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7174 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7182template <
class Emitter>
7183bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7187 return this->
discard(SubExpr);
7189 if (!this->visit(SubExpr))
7192 if (!this->emitConstUint8(0, SubExpr))
7194 return this->emitArrayElemPtrPopUint8(SubExpr);
7198 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7202template <
class Emitter>
7203bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7204 assert(!DiscardResult);
7208 if (!this->emitArrayElem(ElemT, 0, E))
7211 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7214 if (!this->emitCast(ElemT,
PT_Bool, E))
7219 LabelTy LabelTrue = this->getLabel();
7220 if (!this->jumpTrue(LabelTrue))
7223 if (!this->emitArrayElemPop(ElemT, 1, E))
7226 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7229 if (!this->emitCast(ElemT,
PT_Bool, E))
7233 LabelTy EndLabel = this->getLabel();
7234 this->jump(EndLabel);
7236 this->emitLabel(LabelTrue);
7237 if (!this->emitPopPtr(E))
7239 if (!this->emitConstBool(
true, E))
7242 this->fallthrough(EndLabel);
7243 this->emitLabel(EndLabel);
7248template <
class Emitter>
7249bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7253 assert(!DiscardResult);
7259 LHSIsComplex =
true;
7260 ElemT = classifyComplexElementType(LHS->
getType());
7261 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7262 if (!this->visit(LHS))
7264 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7267 LHSIsComplex =
false;
7269 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7270 if (!this->visit(LHS))
7272 if (!this->emitSetLocal(LHST, LHSOffset, E))
7279 RHSIsComplex =
true;
7280 ElemT = classifyComplexElementType(RHS->
getType());
7281 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7282 if (!this->visit(RHS))
7284 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7287 RHSIsComplex =
false;
7289 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7290 if (!this->visit(RHS))
7292 if (!this->emitSetLocal(RHST, RHSOffset, E))
7296 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7297 bool IsComplex) ->
bool {
7299 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7301 return this->emitArrayElemPop(ElemT, Index, E);
7303 return this->emitGetLocal(ElemT, LocalOffset, E);
7306 for (
unsigned I = 0; I != 2; ++I) {
7308 if (!getElem(LHSOffset, I, LHSIsComplex))
7310 if (!getElem(RHSOffset, I, RHSIsComplex))
7313 if (!this->emitEQ(ElemT, E))
7316 if (!this->emitCastBoolUint8(E))
7321 if (!this->emitAddUint8(E))
7323 if (!this->emitConstUint8(2, E))
7327 if (!this->emitEQUint8(E))
7330 if (!this->emitNEUint8(E))
7337 return this->emitCast(
PT_Bool, ResT, E);
7344template <
class Emitter>
7345bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7351 const Function *DtorFunc = getFunction(Dtor);
7354 assert(DtorFunc->hasThisPointer());
7355 assert(DtorFunc->getNumParams() == 1);
7356 return this->emitCall(DtorFunc, 0, Loc);
7361template <
class Emitter>
7362bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7374 return this->emitPopPtr(Loc);
7376 for (ssize_t I = N - 1; I >= 1; --I) {
7377 if (!this->emitConstUint64(I, Loc))
7379 if (!this->emitArrayElemPtrUint64(Loc))
7381 if (!this->emitDestructionPop(ElemDesc, Loc))
7385 if (!this->emitConstUint64(0, Loc))
7387 if (!this->emitArrayElemPtrPopUint64(Loc))
7389 return this->emitDestructionPop(ElemDesc, Loc);
7394 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7399template <
class Emitter>
7400bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7401 assert(!DiscardResult &&
"Should've been checked before");
7403 unsigned DummyID = P.getOrCreateDummy(D);
7405 if (!this->emitGetPtrGlobal(DummyID, E))
7413 return this->emitDecayPtr(
PT_Ptr, PT, E);
7419template <
class Emitter>
7420bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7421 assert(!DiscardResult &&
"Should've been checked before");
7424 return this->emitConstFloat(
Floating(F), E);
7426 APInt I = F.bitcastToAPInt();
7427 return this->emitConstFloat(
7428 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7429 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7440template <
class Emitter>
7441bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7454 if (!this->emitGetPtrLocal(*LocalIndex, E))
7464 if (!this->visit(SubExpr))
7466 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7467 unsigned TempOffset =
7468 allocateLocalPrimitive(SubExpr, *FromT,
true);
7469 if (!this->visit(SubExpr))
7471 if (!this->emitSetLocal(*FromT, TempOffset, E))
7473 if (!this->emitGetPtrLocal(TempOffset, E))
7480 if (!this->emitBitCast(E))
7482 return DiscardResult ? this->emitPopPtr(E) :
true;
7486 const llvm::fltSemantics *TargetSemantics =
nullptr;
7488 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7494 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7496 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7497 ResultBitWidth, TargetSemantics,
7502 return this->emitPop(*ToT, E);
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, EHScopeStack::Cleanup *cleanup)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
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.
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 }.
Stmt * getStmtExprResult()
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
DoStmt - This represents a 'do/while' stmt.
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
const Expr * getBase() const
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits()
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
bool isExpressibleAsConstantInitializer() const
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
uint32_t getCodeUnit(size_t i) const
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool 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.
void emitCleanup()
Emits scope cleanup instructions.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E)
Visit an APValue.
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
const ValueDecl * InitializingDecl
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
typename Emitter::LabelTy LabelTy
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false, bool IsConstexprUnknown=false)
Creates and initializes a variable from the given decl.
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, const ValueDecl *ExtendingDecl=nullptr, ScopeKind SC=ScopeKind::Block, bool IsConstexprUnknown=false)
Creates a local primitive value.
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), const ValueDecl *ExtendingDecl=nullptr, ScopeKind=ScopeKind::Block, bool IsConstexprUnknown=false)
Allocates a space storing a local given its type.
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const ValueDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
const Field * getField(const FieldDecl *FD) const
Returns a field.
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
llvm::iterator_range< const_base_iter > bases() const
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
unsigned getNumFields() const
llvm::iterator_range< const_field_iter > fields() const
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
Describes the statement/declaration an opcode was generated from.
StmtExprScope(Compiler< Emitter > *Ctx)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
Compiler< Emitter > * Ctx
Compiler instance.
virtual void addLocal(const Scope::Local &Local)
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
static bool Activate(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool InitScope(InterpState &S, CodePtr OpPC, uint32_t I)
static void discard(InterpStack &Stk, PrimType T)
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
bool Init(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
constexpr bool isIntegralType(PrimType T)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Success
Annotation was successful.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ SD_Static
Static storage duration.
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
static constexpr MetadataSize InlineDescMD
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink Decl(const ValueDecl *D)
static InitLink Temp(unsigned Offset)
bool isUnnamedBitField() const
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()