20#include "llvm/Support/SaveAndRestore.h"
31 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
32 CE && CE->hasAPValueResult() &&
34 return CE->getResultAsAPSInt().getBoolValue();
53 llvm_unreachable(
"Shouldn't be called");
119 this->
Ctx->emitDestroy(*
Idx, E);
125 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
126 this->
Ctx->Descriptors.emplace_back();
127 this->
Ctx->emitInitScope(*
Idx, {});
131 this->
Ctx->Descriptors[*
Idx].emplace_back(Local);
141 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
142 this->
Ctx->Descriptors.emplace_back();
143 this->
Ctx->emitInitScope(*
Idx, {});
154 if (Local.Desc->hasTrivialDtor())
157 if (!Local.EnabledByDefault) {
158 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
159 if (!this->
Ctx->emitGetLocalEnabled(Local.Offset, E))
161 if (!this->
Ctx->jumpFalse(EndLabel, E))
164 if (!this->
Ctx->emitGetPtrLocal(Local.Offset, E))
167 if (!this->
Ctx->emitDestructionPop(Local.Desc, Local.Desc->getLoc()))
170 this->
Ctx->fallthrough(EndLabel);
171 this->
Ctx->emitLabel(EndLabel);
173 if (!this->
Ctx->emitGetPtrLocal(Local.Offset, E))
175 if (!this->
Ctx->emitDestructionPop(Local.Desc, Local.Desc->getLoc()))
194 if (
const auto *OVE =
195 llvm::dyn_cast_if_present<OpaqueValueExpr>(Local.Desc->asExpr())) {
196 if (
auto It = this->
Ctx->OpaqueExprs.find(OVE);
197 It != this->Ctx->OpaqueExprs.end())
198 this->
Ctx->OpaqueExprs.erase(It);
209 OldArrayIndex = Ctx->ArrayIndex;
210 Ctx->ArrayIndex = Index;
217 std::optional<uint64_t> OldArrayIndex;
225 if (!Ctx->SourceLocDefaultExpr) {
227 Ctx->SourceLocDefaultExpr = DefaultExpr;
233 Ctx->SourceLocDefaultExpr =
nullptr;
238 bool Enabled =
false;
244 Ctx->InitStack.push_back(std::move(
Link));
256 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
257 Ctx->InitStackActive = Active;
263 this->Ctx->InitStackActive = OldValue;
265 Ctx->InitStack.pop_back();
279 OldInitializingDecl(
Ctx->InitializingDecl) {
280 Ctx->InitializingDecl = VD;
285 this->
Ctx->InitializingDecl = OldInitializingDecl;
286 this->
Ctx->InitStack.pop_back();
299 bool NewInitializing,
bool NewToLValue)
300 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
301 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
302 Ctx->DiscardResult = NewDiscardResult;
303 Ctx->Initializing = NewInitializing;
304 Ctx->ToLValue = NewToLValue;
308 Ctx->DiscardResult = OldDiscardResult;
309 Ctx->Initializing = OldInitializing;
310 Ctx->ToLValue = OldToLValue;
317 bool OldDiscardResult;
318 bool OldInitializing;
322template <
class Emitter>
326 return Ctx->emitThis(E);
329 return Ctx->emitGetPtrFieldPop(
Offset, E);
331 return Ctx->emitGetPtrLocal(
Offset, E);
335 if (!Ctx->emitConstUint32(
Offset, E))
337 return Ctx->emitArrayElemPtrPopUint32(E);
339 return Ctx->emitRVOPtr(E);
343 llvm_unreachable(
"Unhandled InitLink kind");
359 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
360 assert(LI.Name != Name);
363 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
384 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
386 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
387 assert(LI.Name != Name);
390 this->Ctx->CaseLabels = std::move(CaseLabels);
391 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
393 DefaultLabel, Ctx->VarScope);
397 this->Ctx->CaseLabels = std::move(OldCaseLabels);
398 this->Ctx->LabelInfoStack.pop_back();
403 CaseMap OldCaseLabels;
414 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
417 Ctx->LocOverride = NewValue;
422 Ctx->LocOverride = OldFlag;
427 std::optional<SourceInfo> OldFlag;
434template <
class Emitter>
442 case CK_LValueToRValue: {
453 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
459 if (
auto GlobalIndex =
P.getGlobal(D))
460 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
461 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
462 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
463 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
464 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
465 return this->emitGetParam(*SubExprT, It->second.Index, E);
477 if (!this->emitGetPtrLocal(*LocalIndex, E))
481 if (!this->
visit(SubExpr))
485 return this->emitLoadPop(*SubExprT, E);
490 return this->emitMemcpy(E);
493 case CK_DerivedToBaseMemberPointer: {
504 ->getMostRecentCXXRecordDecl();
506 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
507 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
509 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
517 case CK_BaseToDerivedMemberPointer: {
528 ->getMostRecentCXXRecordDecl();
532 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
534 PathI != PathE; ++PathI) {
535 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
536 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
538 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
545 assert(ToDecl != CurDecl);
546 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
548 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
554 case CK_UncheckedDerivedToBase:
555 case CK_DerivedToBase: {
560 if (
const auto *PT = dyn_cast<PointerType>(Ty))
561 return PT->getPointeeType()->getAsCXXRecordDecl();
562 return Ty->getAsCXXRecordDecl();
569 if (B->isVirtual()) {
570 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
572 CurType = B->getType();
574 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
575 if (!this->emitGetPtrBasePop(
578 CurType = B->getType();
585 case CK_BaseToDerived: {
588 unsigned DerivedOffset =
594 return this->emitGetPtrDerivedPop(DerivedOffset,
599 case CK_FloatingCast: {
602 return this->emitVectorConversion(E->
getSubExpr(), E);
606 if (!this->
visit(SubExpr))
608 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
612 case CK_IntegralToFloating: {
614 return this->emitVectorConversion(E->
getSubExpr(), E);
617 if (!this->
visit(SubExpr))
619 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
620 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
621 TargetSemantics, getFPOptions(E), E);
624 case CK_FloatingToBoolean: {
626 return this->emitVectorConversion(E->
getSubExpr(), E);
630 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
631 return this->emitConstBool(FL->getValue().isNonZero(), E);
632 if (!this->
visit(SubExpr))
634 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
637 case CK_FloatingToIntegral: {
639 return this->emitVectorConversion(E->
getSubExpr(), E);
642 if (!this->
visit(SubExpr))
646 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
649 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
652 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
655 case CK_NullToPointer:
656 case CK_NullToMemberPointer: {
659 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
664 case CK_PointerToIntegral: {
665 if (!this->
visit(SubExpr))
671 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
677 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
679 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
680 return this->emitCastPointerIntegral(T, E);
683 case CK_ArrayToPointerDecay: {
684 if (!this->
visit(SubExpr))
686 return this->emitArrayDecay(E);
689 case CK_IntegralToPointer: {
691 assert(IntType->isIntegralOrEnumerationType());
692 if (!this->
visit(SubExpr))
706 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
709 case CK_AtomicToNonAtomic:
710 case CK_ConstructorConversion:
711 case CK_FunctionToPointerDecay:
712 case CK_NonAtomicToAtomic:
714 case CK_UserDefinedConversion:
715 case CK_AddressSpaceConversion:
716 case CK_CPointerToObjCPointerCast:
733 return this->emitBuiltinBitCast(E);
748 if (!this->
visit(SubExpr))
756 return this->emitFnPtrCast(E);
763 if (!this->
visit(SubExpr))
765 return this->emitDecayPtr(*FromT, *ToT, E);
767 case CK_IntegralToBoolean:
768 case CK_FixedPointToBoolean: {
770 return this->emitVectorConversion(E->
getSubExpr(), E);
776 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
777 return this->emitConst(IL->getValue(), E);
778 if (!this->
visit(SubExpr))
783 case CK_IntegralCast:
785 return this->emitVectorConversion(E->
getSubExpr(), E);
787 case CK_BooleanToSignedIntegral: {
794 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
799 if (!this->emitConst(IL->getValue(), SubExpr))
802 if (!this->
visit(SubExpr))
810 if (!ED->isFixed()) {
811 if (!this->emitCheckEnumValue(*FromT, ED, E))
817 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
820 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
825 if (!this->emitCast(*FromT, *ToT, E))
828 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
829 return this->emitNeg(*ToT, E);
833 case CK_PointerToBoolean:
834 case CK_MemberPointerToBoolean: {
837 if (!this->
visit(SubExpr))
839 return this->emitIsNonNull(PtrT, E);
842 case CK_IntegralComplexToBoolean:
843 case CK_FloatingComplexToBoolean: {
844 if (!this->
visit(SubExpr))
846 return this->emitComplexBoolCast(SubExpr);
849 case CK_IntegralComplexToReal:
850 case CK_FloatingComplexToReal:
851 return this->emitComplexReal(SubExpr);
853 case CK_IntegralRealToComplex:
854 case CK_FloatingRealToComplex: {
861 if (!this->emitGetPtrLocal(*LocalIndex, E))
870 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
872 return this->emitInitElem(T, 1, SubExpr);
875 case CK_IntegralComplexCast:
876 case CK_FloatingComplexCast:
877 case CK_IntegralComplexToFloatingComplex:
878 case CK_FloatingComplexToIntegralComplex: {
885 if (!this->emitGetPtrLocal(*LocalIndex, E))
892 unsigned SubExprOffset =
894 if (!this->
visit(SubExpr))
896 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
904 for (
unsigned I = 0; I != 2; ++I) {
905 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
907 if (!this->emitArrayElemPop(SourceElemT, I, E))
911 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
915 if (!this->emitInitElem(DestElemT, I, E))
921 case CK_VectorSplat: {
932 if (!this->emitGetPtrLocal(*LocalIndex, E))
938 unsigned ElemOffset =
942 if (!this->
visit(SubExpr))
947 if (!this->emitSetLocal(ElemT, ElemOffset, E))
950 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
951 if (!this->emitGetLocal(ElemT, ElemOffset, E))
953 if (!this->emitInitElem(ElemT, I, E))
960 case CK_HLSLVectorTruncation: {
965 if (!this->
visit(SubExpr))
967 return this->emitArrayElemPop(*ResultT, 0, E);
976 if (!this->emitGetPtrLocal(*LocalIndex, E))
981 if (!this->
visit(SubExpr))
983 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
987 case CK_IntegralToFixedPoint: {
988 if (!this->
visit(SubExpr))
992 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
997 return this->emitPopFixedPoint(E);
1000 case CK_FloatingToFixedPoint: {
1001 if (!this->
visit(SubExpr))
1005 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1006 if (!this->emitCastFloatingFixedPoint(Sem, E))
1009 return this->emitPopFixedPoint(E);
1012 case CK_FixedPointToFloating: {
1013 if (!this->
visit(SubExpr))
1015 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1016 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1019 return this->emitPopFloat(E);
1022 case CK_FixedPointToIntegral: {
1023 if (!this->
visit(SubExpr))
1026 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1029 return this->emitPop(IntegralT, E);
1032 case CK_FixedPointCast: {
1033 if (!this->
visit(SubExpr))
1036 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1037 if (!this->emitCastFixedPoint(Sem, E))
1040 return this->emitPopFixedPoint(E);
1048 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1050 case CK_LValueBitCast:
1055 case CK_HLSLArrayRValue: {
1062 if (!this->emitGetPtrLocal(*LocalIndex, E))
1065 if (!this->
visit(SubExpr))
1067 return this->emitMemcpy(E);
1070 case CK_HLSLMatrixTruncation: {
1075 if (!this->
visit(SubExpr))
1077 return this->emitArrayElemPop(*ResultT, 0, E);
1086 if (!this->emitGetPtrLocal(*LocalIndex, E))
1091 if (!this->
visit(SubExpr))
1093 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1097 case CK_HLSLAggregateSplatCast: {
1107 if (!this->emitGetPtrLocal(*LocalIndex, E))
1114 unsigned SrcOffset =
1117 if (!this->
visit(SubExpr))
1119 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1123 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1126 case CK_HLSLElementwiseCast: {
1137 unsigned SrcPtrOffset =
1139 if (!this->
visit(SubExpr))
1141 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1145 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1147 if (Elements.empty())
1150 const HLSLFlatElement &Src = Elements[0];
1151 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1153 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1160 if (!this->emitGetPtrLocal(*LocalIndex, E))
1164 unsigned SrcOffset =
1166 if (!this->
visit(SubExpr))
1168 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1172 unsigned ElemCount = countHLSLFlatElements(DestType);
1175 Elements.reserve(ElemCount);
1176 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1181 assert(Elements.size() == ElemCount &&
1182 "Source type has fewer scalar elements than the destination type");
1184 return emitHLSLConstructAggregate(DestType, Elements, E);
1191 const Record::Field *RF = R->getField(UnionField);
1192 QualType FieldType = RF->Decl->getType();
1195 if (!this->
visit(SubExpr))
1197 if (RF->isBitField())
1198 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1200 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1203 if (!this->emitGetPtrField(RF->Offset, E))
1205 if (!this->emitActivate(E))
1211 return this->emitInvalid(E);
1213 llvm_unreachable(
"Unhandled clang::CastKind enum");
1216template <
class Emitter>
1218 return this->emitBuiltinBitCast(E);
1221template <
class Emitter>
1226 return this->emitConst(
LE->getValue(),
LE);
1229template <
class Emitter>
1235 return this->emitFloat(F, E);
1238template <
class Emitter>
1248 if (!this->emitGetPtrLocal(*LocalIndex, E))
1255 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1257 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1262template <
class Emitter>
1270 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1275template <
class Emitter>
1280template <
class Emitter>
1307 return this->emitComplexComparison(LHS, RHS, E);
1315 if (!this->
visit(LHS))
1318 if (!this->
visit(RHS))
1321 if (!this->emitToMemberPtr(E))
1327 if (!this->emitCastMemberPtrPtr(E))
1344 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1350 if (!this->emitGetPtrLocal(*ResultIndex, E))
1357 return this->emitCMP3(*
LT, CmpInfo, E);
1360 if (!
LT || !RT || !T)
1370 return this->visitAssignment(LHS, RHS, E);
1377 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1381 return this->emitPopBool(E);
1383 return this->emitCast(
PT_Bool, *T, E);
1387 auto Discard = [
this, T, E](
bool Result) {
1395 return MaybeCastToBool(this->emitEQ(*
LT, E));
1397 return MaybeCastToBool(this->emitNE(*
LT, E));
1399 return MaybeCastToBool(this->emitLT(*
LT, E));
1401 return MaybeCastToBool(this->emitLE(*
LT, E));
1403 return MaybeCastToBool(this->emitGT(*
LT, E));
1405 return MaybeCastToBool(this->emitGE(*
LT, E));
1408 return Discard(this->emitSubf(getFPOptions(E), E));
1409 return Discard(this->emitSub(*T, E));
1412 return Discard(this->emitAddf(getFPOptions(E), E));
1413 return Discard(this->emitAdd(*T, E));
1416 return Discard(this->emitMulf(getFPOptions(E), E));
1417 return Discard(this->emitMul(*T, E));
1419 return Discard(this->emitRem(*T, E));
1422 return Discard(this->emitDivf(getFPOptions(E), E));
1423 return Discard(this->emitDiv(*T, E));
1425 return Discard(this->emitBitAnd(*T, E));
1427 return Discard(this->emitBitOr(*T, E));
1429 return Discard(this->emitShl(*
LT, *RT, E));
1431 return Discard(this->emitShr(*
LT, *RT, E));
1433 return Discard(this->emitBitXor(*T, E));
1436 llvm_unreachable(
"Already handled earlier");
1441 llvm_unreachable(
"Unhandled binary op");
1446template <
class Emitter>
1452 if ((Op != BO_Add && Op != BO_Sub) ||
1463 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1464 if (!this->
visit(E))
1467 return this->emitDecayPtr(T,
PT_Ptr, E);
1476 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1484 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1487 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1494 if (!visitAsPointer(RHS, *RT))
1496 if (!this->
visit(LHS))
1500 if (!visitAsPointer(LHS, *
LT))
1502 if (!this->
visit(RHS))
1513 if (!this->emitAddOffset(OffsetType, E))
1517 if (!this->emitSubOffset(OffsetType, E))
1534template <
class Emitter>
1544 LabelTy LabelTrue = this->getLabel();
1545 LabelTy LabelEnd = this->getLabel();
1549 if (!this->jumpTrue(LabelTrue, E))
1554 if (!this->jump(LabelEnd, E))
1557 this->emitLabel(LabelTrue);
1558 this->emitConstBool(
true, E);
1559 this->fallthrough(LabelEnd);
1560 this->emitLabel(LabelEnd);
1563 assert(Op == BO_LAnd);
1566 LabelTy LabelFalse = this->getLabel();
1567 LabelTy LabelEnd = this->getLabel();
1571 if (!this->jumpFalse(LabelFalse, E))
1576 if (!this->jump(LabelEnd, E))
1579 this->emitLabel(LabelFalse);
1580 this->emitConstBool(
false, E);
1581 this->fallthrough(LabelEnd);
1582 this->emitLabel(LabelEnd);
1586 return this->emitPopBool(E);
1591 return this->emitCast(
PT_Bool, *T, E);
1595template <
class Emitter>
1602 if (!this->emitGetPtrLocal(*LocalIndex, E))
1611 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1612 unsigned ResultOffset = ~0u;
1618 if (!this->emitDupPtr(E))
1620 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1625 LHSType = AT->getValueType();
1628 RHSType = AT->getValueType();
1637 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1642 if (!this->
visit(LHS))
1644 if (!this->
visit(RHS))
1646 if (!this->emitMulc(ElemT, E))
1649 return this->emitPopPtr(E);
1653 if (Op == BO_Div && RHSIsComplex) {
1660 if (!LHSIsComplex) {
1665 LHSOffset = *LocalIndex;
1667 if (!this->emitGetPtrLocal(LHSOffset, E))
1670 if (!this->
visit(LHS))
1673 if (!this->emitInitElem(ElemT, 0, E))
1676 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1678 if (!this->emitInitElem(ElemT, 1, E))
1681 if (!this->
visit(LHS))
1685 if (!this->
visit(RHS))
1687 if (!this->emitDivc(ElemT, E))
1690 return this->emitPopPtr(E);
1697 if (!this->
visit(LHS))
1699 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1704 if (!this->
visit(LHS))
1706 if (!this->emitSetLocal(LHST, LHSOffset, E))
1714 if (!this->
visit(RHS))
1716 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1721 if (!this->
visit(RHS))
1723 if (!this->emitSetLocal(RHST, RHSOffset, E))
1730 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1731 unsigned ElemIndex,
unsigned Offset,
1732 const Expr *E) ->
bool {
1734 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1736 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1739 if (ElemIndex == 0 || !LoadZero)
1746 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1749 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1756 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1759 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1762 if (!this->emitAddf(getFPOptions(E), E))
1765 if (!this->emitAdd(ResultElemT, E))
1770 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1773 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1776 if (!this->emitSubf(getFPOptions(E), E))
1779 if (!this->emitSub(ResultElemT, E))
1784 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1787 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1791 if (!this->emitMulf(getFPOptions(E), E))
1794 if (!this->emitMul(ResultElemT, E))
1799 assert(!RHSIsComplex);
1800 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1803 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1807 if (!this->emitDivf(getFPOptions(E), E))
1810 if (!this->emitDiv(ResultElemT, E))
1821 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1824 if (!this->emitPop(ResultElemT, E))
1829 return this->emitPopPtr(E);
1835template <
class Emitter>
1840 "Comma op should be handled in VisitBinaryOperator");
1854 if (!this->emitGetPtrLocal(*LocalIndex, E))
1868 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1871 if (!this->
visit(LHS))
1873 if (!this->
visit(RHS))
1875 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1878 return this->emitPopPtr(E);
1883 unsigned LHSOffset =
1885 if (!this->
visit(LHS))
1887 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1891 unsigned RHSOffset =
1893 if (!this->
visit(RHS))
1895 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1907 if (NeedIntPromot) {
1909 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1914 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1915 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1917 if (!this->emitArrayElemPop(ElemT, Index, E))
1920 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1922 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1924 }
else if (NeedIntPromot) {
1925 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1931#define EMIT_ARITH_OP(OP) \
1933 if (ElemT == PT_Float) { \
1934 if (!this->emit##OP##f(getFPOptions(E), E)) \
1937 if (!this->emit##OP(ElemT, E)) \
1943 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1944 if (!getElem(LHSOffset, ElemT, I))
1946 if (!getElem(RHSOffset, RHSElemT, I))
1958 if (!this->emitRem(ElemT, E))
1962 if (!this->emitBitAnd(OpT, E))
1966 if (!this->emitBitOr(OpT, E))
1970 if (!this->emitBitXor(OpT, E))
1974 if (!this->emitShl(OpT, RHSElemT, E))
1978 if (!this->emitShr(OpT, RHSElemT, E))
1982 if (!this->emitEQ(ElemT, E))
1986 if (!this->emitNE(ElemT, E))
1990 if (!this->emitLE(ElemT, E))
1994 if (!this->emitLT(ElemT, E))
1998 if (!this->emitGE(ElemT, E))
2002 if (!this->emitGT(ElemT, E))
2007 if (!this->emitBitAnd(ResultElemT, E))
2012 if (!this->emitBitOr(ResultElemT, E))
2016 return this->emitInvalid(E);
2025 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2027 if (!this->emitNeg(ResultElemT, E))
2033 if (NeedIntPromot &&
2034 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2038 if (!this->emitInitElem(ResultElemT, I, E))
2047template <
class Emitter>
2057 auto LHSSemaInt = LHSSema.toOpaqueInt();
2059 auto RHSSemaInt = RHSSema.toOpaqueInt();
2061 if (!this->
visit(LHS))
2069 if (!this->
visit(RHS))
2078 auto ConvertResult = [&](
bool R) ->
bool {
2082 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2083 if (ResultSema != CommonSema)
2084 return this->emitCastFixedPoint(ResultSema, E);
2088 auto MaybeCastToBool = [&](
bool Result) {
2093 return this->emitPop(T, E);
2095 return this->emitCast(
PT_Bool, T, E);
2101 return MaybeCastToBool(this->emitEQFixedPoint(E));
2103 return MaybeCastToBool(this->emitNEFixedPoint(E));
2105 return MaybeCastToBool(this->emitLTFixedPoint(E));
2107 return MaybeCastToBool(this->emitLEFixedPoint(E));
2109 return MaybeCastToBool(this->emitGTFixedPoint(E));
2111 return MaybeCastToBool(this->emitGEFixedPoint(E));
2113 return ConvertResult(this->emitAddFixedPoint(E));
2115 return ConvertResult(this->emitSubFixedPoint(E));
2117 return ConvertResult(this->emitMulFixedPoint(E));
2119 return ConvertResult(this->emitDivFixedPoint(E));
2121 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2123 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2126 return this->emitInvalid(E);
2129 llvm_unreachable(
"unhandled binop opcode");
2132template <
class Emitter>
2141 if (!this->
visit(SubExpr))
2143 if (!this->emitNegFixedPoint(E))
2146 return this->emitPopFixedPoint(E);
2152 llvm_unreachable(
"Unhandled unary opcode");
2155template <
class Emitter>
2164 return this->visitZeroInitializer(*T, QT, E);
2172 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
2173 CXXRD && CXXRD->getNumVBases() > 0) {
2183 return this->visitZeroRecordInitializer(R, E);
2190 return this->visitZeroArrayInitializer(QT, E);
2194 QualType ElemQT = ComplexTy->getElementType();
2196 for (
unsigned I = 0; I < 2; ++I) {
2197 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2199 if (!this->emitInitElem(ElemT, I, E))
2206 unsigned NumVecElements = VecT->getNumElements();
2207 QualType ElemQT = VecT->getElementType();
2210 for (
unsigned I = 0; I < NumVecElements; ++I) {
2211 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2213 if (!this->emitInitElem(ElemT, I, E))
2220 unsigned NumElems = MT->getNumElementsFlattened();
2221 QualType ElemQT = MT->getElementType();
2224 for (
unsigned I = 0; I != NumElems; ++I) {
2225 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2227 if (!this->emitInitElem(ElemT, I, E))
2236template <
class Emitter>
2249 for (
const Expr *SubExpr : {LHS, RHS}) {
2250 if (!this->
visit(SubExpr)) {
2257 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2258 if (!this->emitExpandPtr(E))
2269 return this->emitError(E);
2272 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2276 if (!this->emitArrayElemPtrPop(*IndexT, E))
2279 return this->emitPopPtr(E);
2285 return this->emitLoadPop(*T, E);
2288template <
class Emitter>
2290 const Expr *ArrayFiller,
const Expr *E) {
2295 QT = AT->getValueType();
2298 if (
Inits.size() == 0)
2300 return this->emitInvalid(E);
2315 if (
Inits.size() == 0)
2316 return this->visitZeroInitializer(*T, QT, E);
2317 assert(
Inits.size() == 1);
2330 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2337 bool BitField = FieldToInit->isBitField();
2339 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2340 FieldToInit->bitWidth(), E);
2342 return this->emitInitBitField(T, FieldToInit->Offset,
2343 FieldToInit->bitWidth(), E);
2345 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2346 return this->emitInitField(T, FieldToInit->Offset, E);
2349 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2357 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2360 if (
Activate && !this->emitActivate(E))
2367 if (
Inits.size() == 0) {
2368 if (!this->visitZeroRecordInitializer(R, E))
2373 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2374 FToInit = ILE->getInitializedFieldInUnion();
2378 const Record::Field *FieldToInit = R->getField(FToInit);
2380 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2383 if (!initCompositeField(FieldToInit,
Init,
true))
2387 return this->emitFinishInit(E);
2390 assert(!R->isUnion());
2391 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2393 const Record::Base *B = R->getBase(BI);
2394 if (!this->emitGetPtrBase(B->Offset,
Init))
2400 unsigned FieldIndex = 0;
2401 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2402 const Record::Field *FieldToInit = R->getField(FieldIndex);
2403 if (FieldToInit->isUnnamedBitField()) {
2418 if (!initPrimitiveField(FieldToInit,
Init, *T))
2420 }
else if (!initCompositeField(FieldToInit,
Init)) {
2428 assert(R->getNumVirtualBases() == 0);
2430 return this->emitFinishInit(E);
2435 Ctx.getASTContext().getAsConstantArrayType(QT);
2438 if (
Initializing && !this->emitCheckArrayDestSize(NumElems, E))
2441 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2445 unsigned ElementIndex = 0;
2447 if (
const auto *EmbedS =
2448 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2456 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2457 getFPOptions(E), E))
2463 return this->emitInitElem(TargetT, ElemIndex, IL);
2465 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2481 for (; ElementIndex != NumElems; ++ElementIndex) {
2487 return this->emitFinishInit(E);
2491 unsigned NumInits =
Inits.size();
2496 QualType ElemQT = ComplexTy->getElementType();
2498 if (NumInits == 0) {
2500 for (
unsigned I = 0; I < 2; ++I) {
2501 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2503 if (!this->emitInitElem(ElemT, I, E))
2506 }
else if (NumInits == 2) {
2507 unsigned InitIndex = 0;
2512 if (!this->emitInitElem(ElemT, InitIndex, E))
2521 unsigned NumVecElements = VecT->getNumElements();
2522 assert(NumVecElements >=
Inits.size());
2524 QualType ElemQT = VecT->getElementType();
2528 unsigned InitIndex = 0;
2535 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2536 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2537 InitVecT->getNumElements(), E))
2539 InitIndex += InitVecT->getNumElements();
2541 if (!this->emitInitElem(ElemT, InitIndex, E))
2547 assert(InitIndex <= NumVecElements);
2550 for (; InitIndex != NumVecElements; ++InitIndex) {
2551 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2553 if (!this->emitInitElem(ElemT, InitIndex, E))
2560 unsigned NumElems = MT->getNumElementsFlattened();
2561 assert(
Inits.size() == NumElems);
2563 QualType ElemQT = MT->getElementType();
2569 for (
unsigned I = 0; I != NumElems; ++I) {
2572 if (!this->emitInitElem(ElemT, I, E))
2583template <
class Emitter>
2590 return this->emitInitElem(*InitT, ElemIndex,
Init);
2596 if (!this->emitConstUint32(ElemIndex,
Init))
2598 if (!this->emitArrayElemPtrUint32(
Init))
2603template <
class Emitter>
2606 bool Activate,
bool IsOperatorCall) {
2608 llvm::BitVector NonNullArgs;
2609 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2612 bool ExplicitMemberFn =
false;
2613 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2614 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2616 unsigned ArgIndex = 0;
2617 for (
const Expr *Arg : Args) {
2619 if (!this->
visit(Arg))
2627 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2628 if (DeclIndex < FuncDecl->getNumParams())
2629 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2638 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2646 if (!this->emitActivate(Arg))
2650 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2653 if (!this->emitCheckNonNullArg(ArgT, Arg))
2664template <
class Emitter>
2669template <
class Emitter>
2675template <
class Emitter>
2681template <
class Emitter>
2699template <
class Emitter>
2701 auto It = E->
begin();
2702 return this->
visit(*It);
2707 bool AlignOfReturnsPreferred =
2714 T = Ref->getPointeeType();
2716 if (T.getQualifiers().hasUnaligned())
2722 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2728template <
class Emitter>
2735 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2741 ArgType = Ref->getPointeeType();
2747 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2748 return this->emitInvalid(E);
2750 if (Kind == UETT_SizeOf)
2759 return this->emitConst(Size.getQuantity(), E);
2762 if (Kind == UETT_CountOf) {
2768 if (
const auto *CAT =
2772 return this->emitConst(CAT->getSize(), E);
2782 if (VAT->getElementType()->isArrayType()) {
2783 std::optional<APSInt> Res =
2785 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2790 return this->emitConst(*Res, E);
2795 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2815 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2818 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2828 return this->emitConst(Size.getQuantity(), E);
2831 if (Kind == UETT_VectorElements) {
2836 return this->emitConst(VT->getNumElements(), E);
2838 return this->emitSizelessVectorElementSize(E);
2841 if (Kind == UETT_VecStep) {
2843 unsigned N = VT->getNumElements();
2850 return this->emitConst(N, E);
2852 return this->emitConst(1, E);
2855 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2864 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2866 return this->emitInvalid(E);
2868 return this->emitConst(
2869 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2877template <
class Emitter>
2886 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2889 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2890 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2892 if (
Member->getType()->isReferenceType())
2893 return this->emitLoadPopPtr(E);
2902 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2903 MD && !MD->isStatic()) {
2907 if (!this->
discard(Base) && !this->emitSideEffect(E))
2922 const Record::Field *F = R->getField(FD);
2926 const auto maybeLoadValue = [&]() ->
bool {
2930 return this->emitLoadPop(*T, E);
2935 if (F->Decl->getType()->isReferenceType())
2936 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2937 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2940template <
class Emitter>
2950template <
class Emitter>
2964 if (!this->
visit(Common))
2966 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2980 for (
size_t I = 0; I != Size; ++I) {
2992template <
class Emitter>
3007 return this->emitGetLocal(SubExprT, It->second, E);
3010 if (!this->
visit(SourceExpr))
3017 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3026 return this->emitGetLocal(SubExprT, LocalIndex, E);
3030template <
class Emitter>
3043 bool IsBcpCall =
false;
3044 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3045 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3049 LabelTy LabelEnd = this->getLabel();
3050 LabelTy LabelFalse = this->getLabel();
3053 if (!this->emitPushIgnoreDiags(E))
3061 if (this->checkingForUndefinedBehavior()) {
3064 if (!this->
discard(FalseExpr))
3081 if (!this->jumpFalse(LabelFalse, E))
3086 if (!this->jump(LabelEnd, E))
3088 this->emitLabel(LabelFalse);
3092 this->fallthrough(LabelEnd);
3093 this->emitLabel(LabelEnd);
3096 return this->emitPopIgnoreDiags(E);
3100template <
class Emitter>
3106 unsigned StringIndex =
P.createGlobalString(E);
3107 return this->emitGetPtrGlobal(StringIndex, E);
3112 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3113 assert(CAT &&
"a string literal that's not a constant array?");
3118 unsigned N = std::min(ArraySize, E->
getLength());
3121 for (
unsigned I = 0; I != N; ++I) {
3124 if (CharWidth == 1) {
3125 this->emitConstSint8(CodeUnit, E);
3126 this->emitInitElemSint8(I, E);
3127 }
else if (CharWidth == 2) {
3128 this->emitConstUint16(CodeUnit, E);
3129 this->emitInitElemUint16(I, E);
3130 }
else if (CharWidth == 4) {
3131 this->emitConstUint32(CodeUnit, E);
3132 this->emitInitElemUint32(I, E);
3134 llvm_unreachable(
"unsupported character width");
3139 for (
unsigned I = N; I != ArraySize; ++I) {
3140 if (CharWidth == 1) {
3141 this->emitConstSint8(0, E);
3142 this->emitInitElemSint8(I, E);
3143 }
else if (CharWidth == 2) {
3144 this->emitConstUint16(0, E);
3145 this->emitInitElemUint16(I, E);
3146 }
else if (CharWidth == 4) {
3147 this->emitConstUint32(0, E);
3148 this->emitInitElemUint32(I, E);
3150 llvm_unreachable(
"unsupported character width");
3157template <
class Emitter>
3161 return this->emitDummyPtr(E, E);
3164template <
class Emitter>
3166 auto &A =
Ctx.getASTContext();
3175template <
class Emitter>
3183 auto &A =
Ctx.getASTContext();
3187 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3188 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3195 unsigned StringIndex =
P.createGlobalString(SL);
3196 return this->emitGetPtrGlobal(StringIndex, E);
3199template <
class Emitter>
3203 return this->emitConst(E->
getValue(), E);
3206template <
class Emitter>
3232 if (!this->emitSetLocal(*RT, TempOffset, E))
3238 if (!this->emitLoad(LHST, E))
3242 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3243 LHSComputationType, E))
3247 if (!this->emitGetLocal(*RT, TempOffset, E))
3252 if (!this->emitAddf(getFPOptions(E), E))
3256 if (!this->emitSubf(getFPOptions(E), E))
3260 if (!this->emitMulf(getFPOptions(E), E))
3264 if (!this->emitDivf(getFPOptions(E), E))
3275 return this->emitStorePop(LHST, E);
3276 return this->emitStore(LHST, E);
3279template <
class Emitter>
3288 if (Op != BO_AddAssign && Op != BO_SubAssign)
3297 if (!this->emitLoad(*
LT, LHS))
3303 if (Op == BO_AddAssign) {
3304 if (!this->emitAddOffset(*RT, E))
3307 if (!this->emitSubOffset(*RT, E))
3312 return this->emitStorePopPtr(E);
3313 return this->emitStorePtr(E);
3316template <
class Emitter>
3329 if (!
Ctx.getLangOpts().CPlusPlus14)
3330 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3332 if (!
LT || !RT || !ResultT || !LHSComputationT)
3357 if (!this->emitSetLocal(*RT, TempOffset, E))
3364 if (!this->emitLoad(*
LT, E))
3366 if (
LT != LHSComputationT &&
3372 if (!this->emitGetLocal(*RT, TempOffset, E))
3378 if (!this->emitAdd(*LHSComputationT, E))
3382 if (!this->emitSub(*LHSComputationT, E))
3386 if (!this->emitMul(*LHSComputationT, E))
3390 if (!this->emitDiv(*LHSComputationT, E))
3394 if (!this->emitRem(*LHSComputationT, E))
3398 if (!this->emitShl(*LHSComputationT, *RT, E))
3402 if (!this->emitShr(*LHSComputationT, *RT, E))
3406 if (!this->emitBitAnd(*LHSComputationT, E))
3410 if (!this->emitBitXor(*LHSComputationT, E))
3414 if (!this->emitBitOr(*LHSComputationT, E))
3418 llvm_unreachable(
"Unimplemented compound assign operator");
3422 if (ResultT != LHSComputationT &&
3423 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3429 return this->emitStoreBitFieldPop(*ResultT, E);
3430 return this->emitStorePop(*ResultT, E);
3433 return this->emitStoreBitField(*ResultT, E);
3434 return this->emitStore(*ResultT, E);
3437template <
class Emitter>
3445template <
class Emitter>
3460 if (!
Ctx.getLangOpts().CPlusPlus11)
3467 for (
const Expr *LHS : CommaLHSs) {
3489 if (!this->
visit(Inner))
3494 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3497 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3500 return this->emitGetPtrGlobal(*GlobalIndex, E);
3503 if (!this->checkLiteralType(Inner))
3506 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3512 return this->emitInitGlobalTempComp(TempDecl, E);
3525 unsigned LocalIndex =
3527 if (!this->VarScope->LocalsAlwaysEnabled &&
3528 !this->emitEnableLocal(LocalIndex, E))
3531 if (!this->
visit(Inner))
3533 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3536 return this->emitGetPtrLocal(LocalIndex, E);
3539 if (!this->checkLiteralType(Inner))
3546 if (!this->VarScope->LocalsAlwaysEnabled &&
3547 !this->emitEnableLocal(*LocalIndex, E))
3550 if (!this->emitGetPtrLocal(*LocalIndex, E))
3557template <
class Emitter>
3568 if (!this->
visit(SubExpr))
3572 return this->emitPopPtr(E);
3576template <
class Emitter>
3597 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3602 if (
P.isGlobalInitialized(*GlobalIndex))
3608 return this->emitInitGlobal(*T, *GlobalIndex, E);
3620 unsigned LocalIndex;
3624 LocalIndex = *MaybeIndex;
3628 if (!this->emitGetPtrLocal(LocalIndex, E))
3632 return this->
visit(
Init) && this->emitInit(*T, E);
3636template <
class Emitter>
3649template <
class Emitter>
3653 return this->emitConst(E->
getValue(), E);
3656template <
class Emitter>
3669 for (
const Record::Field &F : R->fields()) {
3671 if (!
Init ||
Init->containsErrors())
3679 if (!this->emitInitField(*T, F.Offset, E))
3682 if (!this->emitGetPtrField(F.Offset, E))
3693template <
class Emitter>
3700 return this->emitGetPtrGlobal(StringIndex, E);
3706template <
class Emitter>
3711 return this->emitInvalid(E);
3714template <
class Emitter>
3734 bool Fatal = (ToT != FromT);
3741template <
class Emitter>
3743 if (!
Ctx.getLangOpts().CPlusPlus20) {
3764 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3769 return this->emitPopPtr(E);
3773template <
class Emitter>
3779 return this->emitConstBool(E->
getValue(), E);
3782template <
class Emitter>
3787 if (T->isRecordType()) {
3801 if (!this->emitGetPtrLocal(*LocalIndex, E))
3809 T->getAsCXXRecordDecl()))
3819 if (!this->visitZeroRecordInitializer(R, E))
3831 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3833 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3834 if (!this->emitCheckFunctionDecl(Ctor, E))
3845 assert(
Func->hasThisPointer());
3846 assert(!
Func->hasRVO());
3850 if (!this->emitDupPtr(E))
3854 for (
const auto *Arg : E->
arguments()) {
3855 if (!this->
visit(Arg))
3859 if (
Func->isVariadic()) {
3860 uint32_t VarArgSize = 0;
3861 unsigned NumParams =
Func->getNumWrittenParams();
3862 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3866 if (!this->emitCallVar(
Func, VarArgSize, E))
3869 if (!this->emitCall(
Func, 0, E)) {
3874 (void)this->emitPopPtr(E);
3880 return this->emitPopPtr(E);
3884 if (T->isArrayType()) {
3889 if (!this->emitDupPtr(E))
3893 initArrayDimension = [&](
QualType T) ->
bool {
3894 if (!T->isArrayType()) {
3896 for (
const auto *Arg : E->
arguments()) {
3897 if (!this->
visit(Arg))
3901 return this->emitCall(
Func, 0, E);
3905 Ctx.getASTContext().getAsConstantArrayType(T);
3910 for (
size_t I = 0; I != NumElems; ++I) {
3911 if (!this->emitConstUint64(I, E))
3913 if (!this->emitArrayElemPtrUint64(E))
3915 if (!initArrayDimension(ElemTy))
3918 return this->emitPopPtr(E);
3921 return initArrayDimension(E->
getType());
3927template <
class Emitter>
3937 assert(Val.
isInt());
3939 return this->emitConst(I, E);
3946 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3947 return this->
visit(LValueExpr);
3962 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3966 const APValue &
V = UGCD->getValue();
3967 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3968 const Record::Field *F = R->getField(I);
3969 const APValue &FieldValue =
V.getStructField(I);
3975 if (!this->emitInitField(FieldT, F->Offset, E))
3983template <
class Emitter>
3989 for (
unsigned I = 0; I != N; ++I) {
3996 if (!this->
discard(ArrayIndexExpr))
4002 if (!this->
visit(ArrayIndexExpr))
4004 if (!this->emitCastNoOverflow(IndexT, E))
4008 if (!this->
visit(ArrayIndexExpr))
4012 if (!this->emitCast(IndexT,
PT_Sint64, E))
4022 return this->emitOffsetOf(T, E, E);
4025template <
class Emitter>
4034 return this->visitZeroInitializer(*T, Ty, E);
4041 if (!this->emitGetPtrLocal(*LocalIndex, E))
4049 ElemQT = CT->getElementType();
4052 NumElems = VT->getNumElements();
4053 ElemQT = VT->getElementType();
4059 for (
unsigned I = 0; I != NumElems; ++I) {
4060 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4062 if (!this->emitInitElem(ElemT, I, E))
4071template <
class Emitter>
4076template <
class Emitter>
4082template <
class Emitter>
4087template <
class Emitter>
4092 return this->emitConst(E->
getValue(), E);
4095template <
class Emitter>
4100 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4114 unsigned ParamIndex = 0;
4118 if (!this->emitGetParam(PT, ParamIndex, E))
4123 return this->emitCall(F, 0, E);
4128template <
class Emitter>
4136 const Expr *PlacementDest =
nullptr;
4137 bool IsNoThrow =
false;
4142 if (PlacementArgs != 0) {
4151 if (PlacementArgs == 1) {
4159 if (!this->emitInvalidNewDeleteExpr(E, E))
4164 if (OperatorNew->isReservedGlobalPlacementOperator())
4165 PlacementDest = Arg1;
4169 return this->emitInvalid(E);
4171 }
else if (!OperatorNew
4172 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4173 return this->emitInvalidNewDeleteExpr(E, E);
4176 if (!PlacementDest) {
4181 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
4184 Desc =
P.createDescriptor(
4187 false,
false,
false,
4193 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4197 const Expr *Stripped = *ArraySizeExpr;
4198 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4199 Stripped = ICE->getSubExpr())
4200 if (ICE->getCastKind() != CK_NoOp &&
4201 ICE->getCastKind() != CK_IntegralCast)
4209 if (!this->
visit(Stripped))
4211 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4214 if (PlacementDest) {
4215 if (!this->
visit(PlacementDest))
4217 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4219 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4222 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4227 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4231 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4238 size_t StaticInitElems = 0;
4239 const Expr *DynamicInit =
nullptr;
4243 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4244 StaticInitElems = CAT->getZExtSize();
4249 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4250 if (ILE->hasArrayFiller())
4251 DynamicInit = ILE->getArrayFiller();
4270 const Function *CtorFunc =
nullptr;
4271 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4275 }
else if (!DynamicInit && !ElemT)
4278 LabelTy EndLabel = this->getLabel();
4279 LabelTy StartLabel = this->getLabel();
4284 if (!this->emitDupPtr(E))
4286 if (!this->emitNullPtr(0,
nullptr, E))
4288 if (!this->emitEQPtr(E))
4290 if (!this->jumpTrue(EndLabel, E))
4297 if (!this->emitConst(StaticInitElems,
SizeT, E))
4299 if (!this->emitSetLocal(
SizeT, Iter, E))
4302 this->fallthrough(StartLabel);
4303 this->emitLabel(StartLabel);
4305 if (!this->emitGetLocal(
SizeT, Iter, E))
4307 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4309 if (!this->emitLT(
SizeT, E))
4311 if (!this->jumpFalse(EndLabel, E))
4315 if (!this->emitGetLocal(
SizeT, Iter, E))
4317 if (!this->emitArrayElemPtr(
SizeT, E))
4320 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4325 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4327 if (!this->emitStorePop(*InitT, E))
4331 if (!this->visitZeroArrayInitializer(ElemType, E))
4334 }
else if (DynamicInit) {
4336 if (!this->
visit(DynamicInit))
4338 if (!this->emitStorePop(*InitT, E))
4345 if (!this->visitZeroInitializer(
4349 if (!this->emitStorePop(*ElemT, E))
4353 if (!this->emitCall(CtorFunc, 0, E))
4358 if (!this->emitGetPtrLocal(Iter, E))
4360 if (!this->emitIncPop(
SizeT,
false, E))
4363 if (!this->jump(StartLabel, E))
4366 this->fallthrough(EndLabel);
4367 this->emitLabel(EndLabel);
4371 if (PlacementDest) {
4372 if (!this->
visit(PlacementDest))
4374 if (!this->emitCheckNewTypeMismatch(E, E))
4379 if (!this->emitAlloc(Desc, E))
4388 if (!this->emitInit(*ElemT, E))
4399 return this->emitPopPtr(E);
4404template <
class Emitter>
4410 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4411 return this->emitInvalidNewDeleteExpr(E, E);
4420template <
class Emitter>
4426 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4431 return this->emitGetFnPtr(
Func, E);
4434template <
class Emitter>
4438 auto canonType = [](
const Type *T) {
4439 return T->getCanonicalTypeUnqualified().getTypePtr();
4447 return this->emitGetTypeid(
4451 return this->emitGetTypeid(
4460 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4466 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4469 return this->emitPopPtr(E);
4473template <
class Emitter>
4477 return this->emitDummyPtr(E, E);
4478 return this->emitError(E);
4481template <
class Emitter>
4484 return this->emitDummyPtr(E, E);
4485 return this->emitError(E);
4488template <
class Emitter>
4490 assert(
Ctx.getLangOpts().CPlusPlus);
4491 return this->emitConstBool(E->
getValue(), E);
4494template <
class Emitter>
4506 return this->emitDummyPtr(GuidDecl, E);
4511 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4520 assert(
V.isStruct());
4521 assert(
V.getStructNumBases() == 0);
4525 return this->emitFinishInit(E);
4528template <
class Emitter>
4538template <
class Emitter>
4547template <
class Emitter>
4553template <
class Emitter>
4557 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4561 if (OVE->isUnique())
4577template <
class Emitter>
4582template <
class Emitter>
4584 return this->emitError(E);
4587template <
class Emitter>
4593 return this->emitDummyPtr(E, E);
4596template <
class Emitter>
4597bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4602 QualType ElemType = VT->getElementType();
4603 PrimType ElemT = classifyPrim(ElemType);
4605 PrimType SrcElemT = classifyVectorElementType(SrcType);
4611 if (!this->emitGetPtrLocal(*LocalIndex, E))
4615 unsigned SrcOffset =
4616 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4617 if (!this->visit(Src))
4619 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4622 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4623 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4625 if (!this->emitArrayElemPop(SrcElemT, I, E))
4629 if (SrcElemT != ElemT) {
4630 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4632 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4633 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4637 if (!this->emitInitElem(ElemT, I, E))
4643template <
class Emitter>
4645 return emitVectorConversion(E->
getSrcExpr(), E);
4648template <
class Emitter>
4652 return this->emitInvalid(E);
4661 assert(NumOutputElems > 0);
4667 if (!this->emitGetPtrLocal(*LocalIndex, E))
4672 unsigned VectorOffsets[2];
4673 for (
unsigned I = 0; I != 2; ++I) {
4676 if (!this->
visit(Vecs[I]))
4678 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4681 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4683 assert(ShuffleIndex >= -1);
4684 if (ShuffleIndex == -1)
4685 return this->emitInvalidShuffleVectorIndex(I, E);
4687 assert(ShuffleIndex < (NumInputElems * 2));
4688 if (!this->emitGetLocal(
PT_Ptr,
4689 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4691 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4692 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4695 if (!this->emitInitElem(ElemT, I, E))
4700 return this->emitPopPtr(E);
4705template <
class Emitter>
4710 Base->getType()->isVectorType() ||
4716 if (Indices.size() == 1) {
4721 if (!this->emitConstUint32(Indices[0], E))
4723 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4733 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4741 if (!this->emitGetPtrLocal(*ResultIndex, E))
4749 uint32_t DstIndex = 0;
4750 for (uint32_t I : Indices) {
4751 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4753 if (!this->emitArrayElemPop(ElemT, I, E))
4755 if (!this->emitInitElem(ElemT, DstIndex, E))
4765template <
class Emitter>
4769 return this->
discard(SubExpr) && this->emitInvalid(E);
4775 return this->emitDummyPtr(E, E);
4778template <
class Emitter>
4783 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4788 if (!this->
visit(SubExpr))
4790 if (!this->emitConstUint8(0, E))
4792 if (!this->emitArrayElemPtrPopUint8(E))
4794 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4799 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4801 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4803 assert(SecondFieldT ==
PT_Ptr);
4805 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4807 if (!this->emitExpandPtr(E))
4811 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4813 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4816template <
class Emitter>
4831 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4835 return this->emitUnsupported(E);
4844 return this->
Visit(E);
4851 return this->
Visit(E);
4855 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4858 if (
const auto *CE = dyn_cast<CastExpr>(E);
4860 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4867 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4870 if (
const auto *CE = dyn_cast<CastExpr>(E);
4871 CE && (CE->getCastKind() == CK_DerivedToBase ||
4872 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4873 CE->getCastKind() == CK_NoOp))
4893 if (!this->emitGetPtrLocal(*LocalIndex, E))
4903 return this->
Visit(E);
4906template <
class Emitter>
4912 return this->
Visit(E) && this->emitFinishInit(E);
4915template <
class Emitter>
4921 return this->
Visit(E) && this->emitFinishInitPop(E);
4927 return this->
Visit(E);
4938 if (!this->
visit(E))
4940 return this->emitComplexBoolCast(E);
4945 if (!this->
visit(E))
4953 return this->emitIsNonNullPtr(E);
4957 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4960 return this->emitCast(*T,
PT_Bool, E);
4963template <
class Emitter>
4967 QT = AT->getValueType();
4971 return this->emitZeroBool(E);
4973 return this->emitZeroSint8(E);
4975 return this->emitZeroUint8(E);
4977 return this->emitZeroSint16(E);
4979 return this->emitZeroUint16(E);
4981 return this->emitZeroSint32(E);
4983 return this->emitZeroUint32(E);
4985 return this->emitZeroSint64(E);
4987 return this->emitZeroUint64(E);
4989 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4991 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4993 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4996 return this->emitNullMemberPtr(0,
nullptr, E);
4998 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4999 return this->emitFloat(F, E);
5002 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5006 llvm_unreachable(
"unknown primitive type");
5009template <
class Emitter>
5010bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5015 for (
const Record::Field &Field :
R->fields()) {
5016 if (Field.isUnnamedBitField())
5023 if (!this->visitZeroInitializer(T, QT, E))
5026 if (!this->emitInitFieldActivate(T, Field.Offset, E))
5030 if (!this->emitInitField(T, Field.Offset, E))
5035 if (!this->emitGetPtrField(Field.Offset, E))
5042 if (!this->visitZeroInitializer(T, ET, E))
5044 if (!this->emitInitElem(T, I, E))
5049 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5052 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5060 if (!this->emitFinishInitActivatePop(E))
5064 if (!this->emitFinishInitPop(E))
5068 for (
const Record::Base &B :
R->bases()) {
5069 if (!this->emitGetPtrBase(B.Offset, E))
5071 if (!this->visitZeroRecordInitializer(B.R, E))
5073 if (!this->emitFinishInitPop(E))
5082template <
class Emitter>
5083bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5084 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
5090 for (
size_t I = 0; I != NumElems; ++I) {
5091 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5093 if (!this->emitInitElem(*ElemT, I, E))
5099 const Record *
R = getRecord(ElemType);
5103 for (
size_t I = 0; I != NumElems; ++I) {
5104 if (!this->emitConstUint32(I, E))
5106 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5108 if (!this->visitZeroRecordInitializer(R, E))
5110 if (!this->emitPopPtr(E))
5116 for (
size_t I = 0; I != NumElems; ++I) {
5117 if (!this->emitConstUint32(I, E))
5119 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5121 if (!this->visitZeroArrayInitializer(ElemType, E))
5123 if (!this->emitPopPtr(E))
5132template <
class Emitter>
5133bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5135 if (!canClassify(E->
getType()))
5138 if (!this->visit(RHS))
5140 if (!this->visit(LHS))
5147 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5151 bool Activates = refersToUnion(LHS);
5154 if (!this->emitFlip(
PT_Ptr, RHT, E))
5157 if (DiscardResult) {
5158 if (BitField && Activates)
5159 return this->emitStoreBitFieldActivatePop(RHT, E);
5161 return this->emitStoreBitFieldPop(RHT, E);
5163 return this->emitStoreActivatePop(RHT, E);
5165 return this->emitStorePop(RHT, E);
5168 auto maybeLoad = [&](
bool Result) ->
bool {
5174 return this->emitLoadPop(RHT, E);
5178 if (BitField && Activates)
5179 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5181 return maybeLoad(this->emitStoreBitField(RHT, E));
5183 return maybeLoad(this->emitStoreActivate(RHT, E));
5185 return maybeLoad(this->emitStore(RHT, E));
5188template <
class Emitter>
5189template <
typename T>
5193 return this->emitConstSint8(
Value, Info);
5195 return this->emitConstUint8(
Value, Info);
5197 return this->emitConstSint16(
Value, Info);
5199 return this->emitConstUint16(
Value, Info);
5201 return this->emitConstSint32(
Value, Info);
5203 return this->emitConstUint32(
Value, Info);
5205 return this->emitConstSint64(
Value, Info);
5207 return this->emitConstUint64(
Value, Info);
5209 return this->emitConstBool(
Value, Info);
5216 llvm_unreachable(
"Invalid integral type");
5219 llvm_unreachable(
"unknown primitive type");
5222template <
class Emitter>
5223template <
typename T>
5224bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
5225 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5228template <
class Emitter>
5232 return this->emitConstIntAPS(
Value, Info);
5234 return this->emitConstIntAP(
Value, Info);
5236 if (
Value.isSigned())
5237 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5238 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5241template <
class Emitter>
5245 return this->emitConstIntAPS(
Value, Info);
5247 return this->emitConstIntAP(
Value, Info);
5250 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5251 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5254template <
class Emitter>
5255bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5256 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5259template <
class Emitter>
5272 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5273 Locals.insert({VD, Local});
5274 VarScope->addForScopeKind(Local, SC);
5275 return Local.Offset;
5278template <
class Emitter>
5283 bool IsTemporary =
false;
5284 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5287 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5288 Init = VarD->getInit();
5290 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5301 return std::nullopt;
5306 Locals.insert({Key, Local});
5307 VarScope->addForScopeKind(Local, SC);
5308 return Local.Offset;
5311template <
class Emitter>
5321 return std::nullopt;
5331 return Local.Offset;
5334template <
class Emitter>
5336 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5337 return PT->getPointeeType()->getAsCanonical<RecordType>();
5343 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5347template <
class Emitter>
5349 return P.getOrCreateRecord(RD);
5352template <
class Emitter>
5354 return Ctx.getOrCreateFunction(FD);
5357template <
class Emitter>
5361 auto maybeDestroyLocals = [&]() ->
bool {
5362 if (DestroyToplevelScope)
5363 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5364 return this->emitCheckAllocations(E);
5371 return this->emitRetVoid(E) && maybeDestroyLocals();
5379 return this->emitRet(*T, E) && maybeDestroyLocals();
5387 if (!this->emitGetPtrLocal(*LocalOffset, E))
5395 return this->emitRetValue(E) && maybeDestroyLocals();
5398 return maybeDestroyLocals() &&
false;
5401template <
class Emitter>
5403 bool DestroyToplevelScope) {
5407 return this->
visitExpr(E, DestroyToplevelScope);
5410template <
class Emitter>
5422 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5423 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5437template <
class Emitter>
5439 bool ConstantContext) {
5442 if (!ConstantContext) {
5456 auto GlobalIndex =
P.getGlobal(VD);
5457 assert(GlobalIndex);
5459 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5462 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5466 auto Local =
Locals.find(VD);
5467 assert(Local !=
Locals.end());
5469 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5472 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5482 auto GlobalIndex =
P.getGlobal(VD);
5483 assert(GlobalIndex);
5484 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5493 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5496template <
class Emitter>
5507 if (!this->isActive())
5512 if (
Init &&
Init->isValueDependent())
5516 auto checkDecl = [&]() ->
bool {
5518 return !NeedsOp || this->emitCheckDecl(VD, VD);
5525 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5528 if (
P.isGlobalInitialized(*GlobalIndex))
5532 }
else if ((GlobalIndex =
5547 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5550 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5553 if (!this->emitStartInit(
Init))
5559 if (!this->emitEndInit(
Init))
5562 return this->emitFinishInitGlobal(
Init);
5572 if (!
Init ||
Init->getType()->isVoidType())
5581 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5593 if (!this->emitCheckRefInit(
Init))
5597 return this->emitSetLocal(*VarT, Offset, VD);
5605 if (!this->emitGetPtrLocal(*Offset,
Init))
5613template <
class Emitter>
5634 Locals.insert({VD, Local});
5637 if (!this->emitGetPtrLocal(Local.Offset, VD))
5643 return this->emitDestructionPop(D, VD);
5652 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5676template <
class Emitter>
5691 unsigned ParamIndex = 0;
5698 const Expr *Arg = Args[ParamIndex];
5699 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5701 unsigned ArgOffset =
5703 if (!this->
visit(Arg))
5705 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5711 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5723 if (
This->getType()->isPointerType()) {
5726 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5733 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5755template <
class Emitter>
5761 return this->emitConst(Val.
getInt(), ValType, Info);
5764 return this->emitFloat(F, Info);
5769 if (!this->emitGetMemberPtr(MemberDecl, Info))
5775 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5781 return this->emitNullMemberPtr(0,
nullptr, Info);
5786 return this->emitNull(ValType, 0,
nullptr, Info);
5791 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5792 return this->
visit(BaseExpr);
5797 QualType EntryType = VD->getType();
5798 for (
auto &Entry : Path) {
5800 uint64_t Index = Entry.getAsArrayIndex();
5803 if (!this->emitConst(Index,
PT_Uint64, Info))
5805 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5807 EntryType = ElemType;
5817 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5818 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5820 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5822 EntryType = FD->getType();
5826 if (!this->emitGetPtrBasePop(BaseOffset,
false, Info))
5828 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5840template <
class Emitter>
5850 const Record::Field *RF = R->getField(I);
5851 QualType FieldType = RF->Decl->getType();
5857 if (!this->emitInitField(*PT, RF->Offset, Info))
5860 if (!this->emitGetPtrField(RF->Offset, Info))
5864 if (!this->emitFinishInitPop(Info))
5874 if (I >= R->getNumBases())
5879 const Record::Base *RB = R->getBase(I);
5880 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5882 if (!this->emitGetPtrBase(RB->Offset, Info))
5886 if (!this->emitFinishInitPop(Info))
5901 const Record::Field *RF = R->getField(UnionField);
5902 QualType FieldType = RF->Decl->getType();
5907 if (RF->isBitField())
5908 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5910 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
5913 if (!this->emitGetPtrField(RF->Offset, Info))
5915 if (!this->emitActivate(Info))
5919 return this->emitPopPtr(Info);
5923 const auto *ArrType = T->getAsArrayTypeUnsafe();
5924 QualType ElemType = ArrType->getElementType();
5927 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5928 const APValue &Elem = A >= InitializedElems
5937 if (!this->emitInitElem(*ElemT, A, Info))
5940 if (!this->emitConstUint32(A, Info))
5942 if (!this->emitArrayElemPtrUint32(Info))
5946 if (!this->emitPopPtr(Info))
5957template <
class Emitter>
5959 unsigned BuiltinID) {
5960 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5965 return this->emitConst(0, E);
5968 if (!this->emitStartSpeculation(E))
5970 LabelTy EndLabel = this->getLabel();
5971 if (!this->speculate(E, EndLabel))
5973 if (!this->emitEndSpeculation(E))
5975 this->fallthrough(EndLabel);
5983 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5984 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5985 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5986 BuiltinID == Builtin::BI__builtin_function_start) {
5989 return this->emitDummyPtr(E, E);
6000 if (!this->emitGetPtrLocal(*LocalIndex, E))
6005 switch (BuiltinID) {
6006 case Builtin::BI__builtin_object_size:
6007 case Builtin::BI__builtin_dynamic_object_size: {
6011 if (!this->
visit(Arg0))
6022 case Builtin::BI__assume:
6023 case Builtin::BI__builtin_assume:
6026 case Builtin::BI__atomic_is_lock_free:
6027 case Builtin::BI__atomic_always_lock_free: {
6038 for (
const auto *Arg : E->
arguments()) {
6039 if (!this->
visit(Arg))
6045 if (!this->emitCallBI(E, BuiltinID, E))
6054template <
class Emitter>
6075 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6076 DD && DD->isTrivial()) {
6078 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6080 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6081 this->emitPopPtr(E);
6089 bool HasRVO = !
ReturnType->isVoidType() && !T;
6097 if (!this->emitGetPtrLocal(*LocalIndex, E))
6105 if (!this->emitGetPtrLocal(*LocalIndex, E))
6109 if (!this->emitDupPtr(E))
6116 bool IsAssignmentOperatorCall =
false;
6117 bool ActivateLHS =
false;
6118 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6119 OCE && OCE->isAssignmentOp()) {
6123 assert(Args.size() == 2);
6124 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6126 IsAssignmentOperatorCall =
true;
6127 std::reverse(Args.begin(), Args.end());
6133 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6134 MD && MD->isStatic()) {
6138 Args.erase(Args.begin());
6142 bool Devirtualized =
false;
6145 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6153 if (!this->
visit(Callee))
6155 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6157 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6159 if (!this->emitGetMemberPtrBase(E))
6162 const auto *InstancePtr = MC->getImplicitObjectArgument();
6169 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6170 Devirtualized =
true;
6171 if (!this->
visit(Stripped))
6174 if (!this->
visit(InstancePtr))
6178 if (!this->
visit(InstancePtr))
6182 }
else if (
const auto *PD =
6183 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6184 if (!this->emitCheckPseudoDtor(E))
6192 return this->emitEndLifetimePop(E);
6193 }
else if (!FuncDecl) {
6197 if (!this->
visit(Callee))
6199 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6208 if (IsAssignmentOperatorCall) {
6209 assert(Args.size() == 2);
6212 if (!this->emitFlip(Arg2T, Arg1T, E))
6226 assert(HasRVO ==
Func->hasRVO());
6228 bool HasQualifier =
false;
6229 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6230 HasQualifier = ME->hasQualifier();
6232 bool IsVirtual =
false;
6233 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6234 IsVirtual = !Devirtualized && MD->isVirtual();
6239 if (IsVirtual && !HasQualifier) {
6240 uint32_t VarArgSize = 0;
6241 unsigned NumParams =
6242 Func->getNumWrittenParams() +
6244 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6247 if (!this->emitCallVirt(
Func, VarArgSize, E))
6249 }
else if (
Func->isVariadic()) {
6250 uint32_t VarArgSize = 0;
6251 unsigned NumParams =
6252 Func->getNumWrittenParams() +
6254 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6256 if (!this->emitCallVar(
Func, VarArgSize, E))
6259 if (!this->emitCall(
Func, 0, E))
6268 uint32_t ArgSize = 0;
6269 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6275 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6277 if (!this->emitGetMemberPtrDecl(E))
6280 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6283 if (!this->emitCallPtr(ArgSize, E, E))
6294template <
class Emitter>
6301template <
class Emitter>
6308template <
class Emitter>
6313 return this->emitConstBool(E->
getValue(), E);
6316template <
class Emitter>
6322 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6323 return this->emitNullPtr(Val,
nullptr, E);
6326template <
class Emitter>
6334 return this->emitZero(T, E);
6337template <
class Emitter>
6342 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6343 if (this->LambdaThisCapture.Offset > 0) {
6344 if (this->LambdaThisCapture.IsPtr)
6345 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6346 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6355 return this->emitThis(E);
6370 unsigned StartIndex = 0;
6371 unsigned EndIndex = 0;
6373 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6375 EndIndex = StartIndex;
6382 for (; StartIndex > 0; --StartIndex) {
6392 if (StartIndex == 0 && EndIndex == 0)
6398 assert(StartIndex <= EndIndex);
6401 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6413 case Stmt::CompoundStmtClass:
6415 case Stmt::DeclStmtClass:
6417 case Stmt::ReturnStmtClass:
6419 case Stmt::IfStmtClass:
6421 case Stmt::WhileStmtClass:
6423 case Stmt::DoStmtClass:
6425 case Stmt::ForStmtClass:
6427 case Stmt::CXXForRangeStmtClass:
6429 case Stmt::BreakStmtClass:
6431 case Stmt::ContinueStmtClass:
6433 case Stmt::SwitchStmtClass:
6435 case Stmt::CaseStmtClass:
6437 case Stmt::DefaultStmtClass:
6439 case Stmt::AttributedStmtClass:
6441 case Stmt::CXXTryStmtClass:
6443 case Stmt::NullStmtClass:
6446 case Stmt::GCCAsmStmtClass:
6447 case Stmt::MSAsmStmtClass:
6448 case Stmt::GotoStmtClass:
6449 return this->emitInvalid(S);
6450 case Stmt::LabelStmtClass:
6453 if (
const auto *E = dyn_cast<Expr>(S))
6460template <
class Emitter>
6463 for (
const auto *InnerStmt : S->
body())
6466 return Scope.destroyLocals();
6469template <
class Emitter>
6470bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6471 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6472 for (
auto *BD : DD->flat_bindings())
6473 if (
auto *KD = BD->getHoldingVar();
6474 KD && !this->visitVarDecl(KD, KD->getInit()))
6488template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6490 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6491 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6498 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6503 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6504 ICE && (ICE->getCastKind() == CK_NoOp ||
6505 ICE->getCastKind() == CK_DerivedToBase ||
6506 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6507 E = ICE->getSubExpr();
6511 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6512 const auto *ThisRecord =
6513 This->getType()->getPointeeType()->getAsRecordDecl();
6514 if (!ThisRecord->isUnion())
6517 if (
const auto *Ctor =
6518 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6519 return Ctor->getParent() == ThisRecord;
6528template <
class Emitter>
6530 bool EvaluateConditionDecl) {
6531 for (
const auto *D : DS->
decls()) {
6536 const auto *VD = dyn_cast<VarDecl>(D);
6543 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6550template <
class Emitter>
6553 return this->emitUnsupported(RS);
6559 if (!this->
visit(RE))
6565 if (RE->getType()->isVoidType()) {
6566 if (!this->
visit(RE))
6569 if (RE->containsErrors())
6574 if (!this->emitRVOPtr(RE))
6580 return this->emitRetVoid(RS);
6586 return this->emitRetVoid(RS);
6592 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6599 if (
auto *CondInit = IS->
getInit()) {
6615 return visitChildStmt(IS->
getThen());
6617 return visitChildStmt(Else);
6623 if (!this->emitIsConstantContext(IS))
6626 if (!this->emitIsConstantContext(IS))
6628 if (!this->emitInv(IS))
6642 LabelTy LabelElse = this->getLabel();
6643 LabelTy LabelEnd = this->getLabel();
6644 if (!this->jumpFalse(LabelElse, IS))
6646 if (!visitChildStmt(IS->
getThen()))
6648 if (!this->jump(LabelEnd, IS))
6650 this->emitLabel(LabelElse);
6651 if (!visitChildStmt(Else))
6653 this->emitLabel(LabelEnd);
6655 LabelTy LabelEnd = this->getLabel();
6656 if (!this->jumpFalse(LabelEnd, IS))
6658 if (!visitChildStmt(IS->
getThen()))
6660 this->emitLabel(LabelEnd);
6669template <
class Emitter>
6674 LabelTy CondLabel = this->getLabel();
6675 LabelTy EndLabel = this->getLabel();
6679 this->fallthrough(CondLabel);
6680 this->emitLabel(CondLabel);
6696 if (!this->jumpFalse(EndLabel, S))
6706 if (!this->jump(CondLabel, S))
6708 this->fallthrough(EndLabel);
6709 this->emitLabel(EndLabel);
6718 LabelTy StartLabel = this->getLabel();
6719 LabelTy EndLabel = this->getLabel();
6720 LabelTy CondLabel = this->getLabel();
6724 this->fallthrough(StartLabel);
6725 this->emitLabel(StartLabel);
6731 this->fallthrough(CondLabel);
6732 this->emitLabel(CondLabel);
6739 if (!this->jumpTrue(StartLabel, S))
6742 this->fallthrough(EndLabel);
6743 this->emitLabel(EndLabel);
6747template <
class Emitter>
6755 LabelTy EndLabel = this->getLabel();
6756 LabelTy CondLabel = this->getLabel();
6757 LabelTy IncLabel = this->getLabel();
6764 this->fallthrough(CondLabel);
6765 this->emitLabel(CondLabel);
6777 if (!this->jumpFalse(EndLabel, S))
6786 this->fallthrough(IncLabel);
6787 this->emitLabel(IncLabel);
6793 if (!this->jump(CondLabel, S))
6797 this->emitLabel(EndLabel);
6803template <
class Emitter>
6813 LabelTy EndLabel = this->getLabel();
6814 LabelTy CondLabel = this->getLabel();
6815 LabelTy IncLabel = this->getLabel();
6830 this->fallthrough(CondLabel);
6831 this->emitLabel(CondLabel);
6834 if (!this->jumpFalse(EndLabel, S))
6845 this->fallthrough(IncLabel);
6846 this->emitLabel(IncLabel);
6851 if (!this->jump(CondLabel, S))
6854 this->fallthrough(EndLabel);
6855 this->emitLabel(EndLabel);
6859template <
class Emitter>
6870 if (LI.BreakLabel) {
6871 TargetLabel = *LI.BreakLabel;
6872 BreakScope = LI.BreakOrContinueScope;
6878 if (LI.Name == TargetLoop) {
6879 TargetLabel = *LI.BreakLabel;
6880 BreakScope = LI.BreakOrContinueScope;
6891 C =
C->getParent()) {
6892 if (!
C->destroyLocals())
6896 return this->jump(*TargetLabel, S);
6899template <
class Emitter>
6910 if (LI.ContinueLabel) {
6911 TargetLabel = *LI.ContinueLabel;
6912 ContinueScope = LI.BreakOrContinueScope;
6918 if (LI.Name == TargetLoop) {
6919 TargetLabel = *LI.ContinueLabel;
6920 ContinueScope = LI.BreakOrContinueScope;
6925 assert(TargetLabel);
6928 C =
C->getParent()) {
6929 if (!
C->destroyLocals())
6933 return this->jump(*TargetLabel, S);
6936template <
class Emitter>
6939 if (
Cond->containsErrors())
6946 LabelTy EndLabel = this->getLabel();
6951 if (
const auto *CondInit = S->
getInit())
6962 if (!this->emitSetLocal(CondT, CondVar, S))
6972 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6975 if (CS->caseStmtIsGNURange()) {
6976 LabelTy EndOfRangeCheck = this->getLabel();
6977 const Expr *Low = CS->getLHS();
6978 const Expr *High = CS->getRHS();
6982 if (!this->emitGetLocal(CondT, CondVar, CS))
6984 if (!this->
visit(Low))
6987 if (!this->emitGE(
LT, S))
6989 if (!this->jumpFalse(EndOfRangeCheck, S))
6992 if (!this->emitGetLocal(CondT, CondVar, CS))
6994 if (!this->
visit(High))
6997 if (!this->emitLE(HT, S))
7001 this->emitLabel(EndOfRangeCheck);
7006 if (
Value->isValueDependent())
7011 if (!this->emitGetLocal(CondT, CondVar, CS))
7017 if (!this->emitEQ(ValueT, S))
7022 assert(!DefaultLabel);
7023 DefaultLabel = this->getLabel();
7030 if (!this->jump(*DefaultLabel, S))
7033 if (!this->jump(EndLabel, S))
7041 this->fallthrough(EndLabel);
7042 this->emitLabel(EndLabel);
7047template <
class Emitter>
7055 return this->emitUnsupported(S);
7060template <
class Emitter>
7067 if (LI.DefaultLabel) {
7068 DefaultLabel = *LI.DefaultLabel;
7073 this->emitLabel(DefaultLabel);
7077template <
class Emitter>
7084 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7087 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7088 !this->Ctx.getLangOpts().MSVCCompat) {
7090 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7096 const Expr *Assumption = AA->getAssumption();
7107 if (!this->emitAssume(Assumption))
7116 if (IsMSVCConstexprAttr)
7117 return this->emitPopMSVCCE(S);
7121template <
class Emitter>
7127template <
class Emitter>
7128bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7135 assert(ClosureClass->
captures().empty());
7139 "A generic lambda's static-invoker function must be a "
7140 "template specialization");
7144 void *InsertPos =
nullptr;
7145 const FunctionDecl *CorrespondingCallOpSpecialization =
7147 assert(CorrespondingCallOpSpecialization);
7148 LambdaCallOp = CorrespondingCallOpSpecialization;
7152 assert(ClosureClass->
captures().empty());
7153 const Function *
Func = this->getFunction(LambdaCallOp);
7156 assert(
Func->hasThisPointer());
7159 if (
Func->hasRVO()) {
7160 if (!this->emitRVOPtr(MD))
7168 if (!this->emitNullPtr(0,
nullptr, MD))
7173 auto It = this->Params.find(PVD);
7174 assert(It != this->Params.end());
7178 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7179 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7183 if (!this->emitCall(
Func, 0, LambdaCallOp))
7188 return this->emitRet(*ReturnType, MD);
7191 return this->emitRetVoid(MD);
7194template <
class Emitter>
7195bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7196 if (Ctx.getLangOpts().CPlusPlus23)
7206 const Expr *InitExpr =
Init->getInit();
7208 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7212 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7222template <
class Emitter>
7224 assert(!ReturnType);
7227 if (!this->emitStartThisLifetime1(Ctor))
7230 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7231 const Expr *InitExpr,
7234 if (InitExpr->getType().isNull())
7238 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7241 if (!this->visit(InitExpr))
7244 if (F->isBitField())
7245 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
7247 return this->emitInitThisField(*T, FieldOffset, InitExpr);
7252 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7255 if (
Activate && !this->emitActivate(InitExpr))
7258 return this->visitInitializerPop(InitExpr);
7262 const Record *
R = this->getRecord(RD);
7265 bool IsUnion =
R->isUnion();
7275 if (!this->emitThis(Ctor))
7278 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7281 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7282 this->emitRetVoid(Ctor);
7285 unsigned FieldInits = 0;
7287 for (
const auto *
Init : Ctor->
inits()) {
7291 const Expr *InitExpr =
Init->getInit();
7293 const Record::Field *F =
R->getField(
Member);
7297 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7301 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7304 if (
Init->isBaseVirtual()) {
7305 assert(
R->getVirtualBase(BaseDecl));
7306 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
7312 const Record::Base *B =
R->getBase(BaseDecl);
7314 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7318 if (!this->visitInitializerPop(InitExpr))
7323 unsigned ChainSize = IFD->getChainingSize();
7324 assert(ChainSize >= 2);
7326 unsigned NestedFieldOffset = 0;
7327 const Record::Field *NestedField =
nullptr;
7328 for (
unsigned I = 0; I != ChainSize; ++I) {
7330 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7331 assert(FieldRecord);
7333 NestedField = FieldRecord->
getField(FD);
7334 assert(NestedField);
7335 IsUnion = IsUnion || FieldRecord->
isUnion();
7337 NestedFieldOffset += NestedField->Offset;
7340 if (I != ChainSize - 1)
7343 assert(NestedField);
7346 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7351 unsigned InitFieldOffset = 0;
7352 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7354 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7355 assert(FieldRecord);
7356 NestedField = FieldRecord->
getField(FD);
7357 InitFieldOffset += NestedField->Offset;
7358 assert(NestedField);
7359 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7361 if (!this->emitFinishInitPop(InitExpr))
7365 InitStack.pop_back_n(ChainSize - 1);
7368 assert(
Init->isDelegatingInitializer());
7369 if (!this->emitThis(InitExpr))
7371 if (!this->visitInitializerPop(
Init->getInit()))
7375 if (!
Scope.destroyLocals())
7379 if (FieldInits !=
R->getNumFields()) {
7380 assert(FieldInits < R->getNumFields());
7382 if (!this->emitStartThisLifetime(Ctor))
7389 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7390 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7397 if (!visitStmt(Body))
7404template <
class Emitter>
7407 const Record *
R = this->getRecord(RD);
7411 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7412 if (!this->visitStmt(
Dtor->getBody()))
7416 if (!this->emitThis(
Dtor))
7419 if (!this->emitCheckDestruction(
Dtor))
7423 if (!
R->isUnion()) {
7427 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7431 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7433 if (!this->emitDestructionPop(D,
SourceInfo{}))
7438 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7439 if (
Base.R->hasTrivialDtor())
7443 if (!this->emitRecordDestructionPop(
Base.R, {}))
7447 if (!this->emitMarkDestroyed(
Dtor))
7451 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7454template <
class Emitter>
7455bool Compiler<Emitter>::compileUnionAssignmentOperator(
7457 if (!this->emitThis(MD))
7460 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7463 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7466template <
class Emitter>
7476 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7477 return this->compileConstructor(Ctor);
7478 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7479 return this->compileDestructor(
Dtor);
7482 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7487 return this->compileUnionAssignmentOperator(MD);
7490 return this->emitLambdaStaticInvokerBody(MD);
7494 if (
const auto *Body = F->
getBody())
7508 return FD->getBitWidthValue();
7511template <
class Emitter>
7527 if (!
Ctx.getLangOpts().CPlusPlus14)
7528 return this->emitInvalid(E);
7530 return this->emitError(E);
7532 if (!this->
visit(SubExpr))
7536 if (!this->emitIncPtr(E))
7543 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7544 : this->emitIncf(getFPOptions(E), E);
7556 if (!
Ctx.getLangOpts().CPlusPlus14)
7557 return this->emitInvalid(E);
7559 return this->emitError(E);
7561 if (!this->
visit(SubExpr))
7565 if (!this->emitDecPtr(E))
7572 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7573 : this->emitDecf(getFPOptions(E), E);
7586 if (!
Ctx.getLangOpts().CPlusPlus14)
7587 return this->emitInvalid(E);
7589 return this->emitError(E);
7591 if (!this->
visit(SubExpr))
7595 if (!this->emitLoadPtr(E))
7597 if (!this->emitConstUint8(1, E))
7599 if (!this->emitAddOffsetUint8(E))
7601 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7607 return this->emitIncfPop(getFPOptions(E), E);
7617 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7618 if (!this->emitLoadFloat(E))
7620 APFloat F(TargetSemantics, 1);
7621 if (!this->emitFloat(F, E))
7624 if (!this->emitAddf(getFPOptions(E), E))
7626 if (!this->emitStoreFloat(E))
7638 return E->
isGLValue() || this->emitLoadPop(*T, E);
7641 if (!
Ctx.getLangOpts().CPlusPlus14)
7642 return this->emitInvalid(E);
7644 return this->emitError(E);
7646 if (!this->
visit(SubExpr))
7650 if (!this->emitLoadPtr(E))
7652 if (!this->emitConstUint8(1, E))
7654 if (!this->emitSubOffsetUint8(E))
7656 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7662 return this->emitDecfPop(getFPOptions(E), E);
7672 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7673 if (!this->emitLoadFloat(E))
7675 APFloat F(TargetSemantics, 1);
7676 if (!this->emitFloat(F, E))
7679 if (!this->emitSubf(getFPOptions(E), E))
7681 if (!this->emitStoreFloat(E))
7693 return E->
isGLValue() || this->emitLoadPop(*T, E);
7697 return this->emitError(E);
7700 return this->
discard(SubExpr);
7705 if (!this->emitInv(E))
7709 return this->emitCast(
PT_Bool, ET, E);
7713 return this->emitError(E);
7715 if (!this->
visit(SubExpr))
7717 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7720 return this->emitError(E);
7722 if (!this->
visit(SubExpr))
7738 if (!
Ctx.getLangOpts().CPlusPlus) {
7740 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7741 Deref && Deref->getOpcode() == UO_Deref)
7742 return this->
delegate(Deref->getSubExpr());
7748 return this->
discard(SubExpr);
7750 if (!this->
visit(SubExpr))
7757 return this->emitNarrowPtr(E);
7762 return this->emitError(E);
7764 if (!this->
visit(SubExpr))
7766 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7778 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7783 assert(
false &&
"Unhandled opcode");
7789template <
class Emitter>
7795 return this->
discard(SubExpr);
7798 auto prepareResult = [=]() ->
bool {
7803 return this->emitGetPtrLocal(*LocalIndex, E);
7810 unsigned SubExprOffset = ~0u;
7811 auto createTemp = [=, &SubExprOffset]() ->
bool {
7814 if (!this->
visit(SubExpr))
7816 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7820 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7821 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7823 return this->emitArrayElemPop(ElemT, Index, E);
7828 if (!prepareResult())
7832 for (
unsigned I = 0; I != 2; ++I) {
7833 if (!getElem(SubExprOffset, I))
7835 if (!this->emitNeg(ElemT, E))
7837 if (!this->emitInitElem(ElemT, I, E))
7848 if (!this->
visit(SubExpr))
7850 if (!this->emitComplexBoolCast(SubExpr))
7852 if (!this->emitInv(E))
7855 return this->emitCast(
PT_Bool, ET, E);
7859 return this->emitComplexReal(SubExpr);
7862 if (!this->
visit(SubExpr))
7866 if (!this->emitConstUint8(1, E))
7868 return this->emitArrayElemPtrPopUint8(E);
7879 if (!this->emitArrayElem(ElemT, 1, E))
7881 if (!this->emitNeg(ElemT, E))
7883 if (!this->emitInitElem(ElemT, 1, E))
7891 return this->emitInvalid(E);
7897template <
class Emitter>
7903 return this->
discard(SubExpr);
7906 if (UnaryOp == UO_Extension)
7909 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7910 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7911 return this->emitInvalid(E);
7914 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7921 if (!this->emitGetPtrLocal(*LocalIndex, E))
7926 unsigned SubExprOffset =
7928 if (!this->
visit(SubExpr))
7930 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7935 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7936 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7938 return this->emitArrayElemPop(ElemT, Index, E);
7943 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7944 if (!getElem(SubExprOffset, I))
7946 if (!this->emitNeg(ElemT, E))
7948 if (!this->emitInitElem(ElemT, I, E))
7963 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7964 if (!getElem(SubExprOffset, I))
7967 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7969 if (!this->emitInv(E))
7971 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7973 if (!this->emitNeg(ElemT, E))
7975 if (ElemT != ResultVecElemT &&
7976 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7978 if (!this->emitInitElem(ResultVecElemT, I, E))
7984 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7985 if (!getElem(SubExprOffset, I))
7988 if (!this->emitInv(E))
7991 if (!this->emitComp(ElemT, E))
7994 if (!this->emitInitElem(ElemT, I, E))
7999 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8004template <
class Emitter>
8006 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8009 return this->emitConst(ECD->getInitVal(), E);
8011 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8015 return F && this->emitGetFnPtr(F, E);
8017 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8025 return this->emitInitGlobal(*T, *Index, E);
8028 if (!this->emitGetPtrGlobal(*Index, E))
8032 return this->emitFinishInit(E);
8044 auto maybePopPtr = [&]() ->
bool {
8046 return this->emitPopPtr(E);
8053 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8057 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8062 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8063 if (IsReference || !It->second.IsPtr)
8064 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8066 return this->emitGetPtrParam(It->second.Index, E);
8069 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8076 const unsigned Offset = It->second.Offset;
8079 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8081 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8084 if (
auto GlobalIndex =
P.getGlobal(D)) {
8086 if (!
Ctx.getLangOpts().CPlusPlus11)
8087 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8088 if (!
Ctx.getLangOpts().CPlusPlus23)
8089 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8091 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8094 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8098 auto revisit = [&](
const VarDecl *VD,
8099 bool IsConstexprUnknown =
true) ->
bool {
8101 IsConstexprUnknown);
8106 if (!this->emitPopCC(E))
8109 if (VarState.notCreated())
8117 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8119 if (
auto It = this->LambdaCaptures.find(D);
8120 It != this->LambdaCaptures.end()) {
8121 auto [Offset, IsPtr] = It->second;
8124 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8125 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8129 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8130 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8131 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8135 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8136 return this->
delegate(BD->getBinding());
8142 return this->emitDummyPtr(D, E);
8147 const auto *VD = dyn_cast<VarDecl>(D);
8149 return this->emitError(E);
8152 if (!
Ctx.getLangOpts().CPlusPlus) {
8156 return revisit(VD,
false);
8160 return this->emitDummyPtr(D, E);
8164 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8165 if (T.isConstant(
Ctx.getASTContext()))
8167 return T->isReferenceType();
8171 typeShouldBeVisited(DeclType)) {
8173 Init && !
Init->isValueDependent()) {
8178 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8191 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8196 return revisit(VD, IsConstexprUnknown);
8197 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8198 return revisit(VD,
true);
8207 return this->emitDummyPtr(
8211template <
class Emitter>
8217template <
class Emitter>
8227 if (!
C->destroyLocals())
8233template <
class Emitter>
8234unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8237 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8239 return Ty->getAsCXXRecordDecl();
8241 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8242 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8244 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8248template <
class Emitter>
8255 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8260 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8261 getFPOptions(E), E);
8263 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8264 getFPOptions(E), E);
8268 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8273 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8275 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8279 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8283 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8284 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8291template <
class Emitter>
8294 assert(FromT != ToT);
8297 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8299 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8301 return this->emitCast(FromT, ToT, E);
8305template <
class Emitter>
8306bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8310 return this->
discard(SubExpr);
8312 if (!this->visit(SubExpr))
8315 if (!this->emitConstUint8(0, SubExpr))
8317 return this->emitArrayElemPtrPopUint8(SubExpr);
8321 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8325template <
class Emitter>
8326bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8327 assert(!DiscardResult);
8331 if (!this->emitArrayElem(ElemT, 0, E))
8334 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8337 if (!this->emitCast(ElemT,
PT_Bool, E))
8342 LabelTy LabelTrue = this->getLabel();
8343 if (!this->jumpTrue(LabelTrue, E))
8346 if (!this->emitArrayElemPop(ElemT, 1, E))
8349 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8352 if (!this->emitCast(ElemT,
PT_Bool, E))
8356 LabelTy EndLabel = this->getLabel();
8357 this->jump(EndLabel, E);
8359 this->emitLabel(LabelTrue);
8360 if (!this->emitPopPtr(E))
8362 if (!this->emitConstBool(
true, E))
8365 this->fallthrough(EndLabel);
8366 this->emitLabel(EndLabel);
8371template <
class Emitter>
8372bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8383 LHSIsComplex =
true;
8384 ElemT = classifyComplexElementType(LHS->
getType());
8385 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8386 if (!this->visit(LHS))
8388 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8391 LHSIsComplex =
false;
8393 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8394 if (!this->visit(LHS))
8396 if (!this->emitSetLocal(LHST, LHSOffset, E))
8403 RHSIsComplex =
true;
8404 ElemT = classifyComplexElementType(RHS->
getType());
8405 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8406 if (!this->visit(RHS))
8408 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8411 RHSIsComplex =
false;
8413 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8414 if (!this->visit(RHS))
8416 if (!this->emitSetLocal(RHST, RHSOffset, E))
8420 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8421 bool IsComplex) ->
bool {
8423 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8425 return this->emitArrayElemPop(ElemT, Index, E);
8427 return this->emitGetLocal(ElemT, LocalOffset, E);
8430 for (
unsigned I = 0; I != 2; ++I) {
8432 if (!getElem(LHSOffset, I, LHSIsComplex))
8434 if (!getElem(RHSOffset, I, RHSIsComplex))
8437 if (!this->emitEQ(ElemT, E))
8440 if (!this->emitCastBoolUint8(E))
8445 if (!this->emitAddUint8(E))
8447 if (!this->emitConstUint8(2, E))
8451 if (!this->emitEQUint8(E))
8454 if (!this->emitNEUint8(E))
8461 return this->emitCast(
PT_Bool, ResT, E);
8468template <
class Emitter>
8469bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8472 assert(!
R->hasTrivialDtor());
8475 const Function *DtorFunc = getFunction(
Dtor);
8478 assert(DtorFunc->hasThisPointer());
8479 assert(DtorFunc->getNumParams() == 1);
8480 return this->emitCall(DtorFunc, 0, Loc);
8485template <
class Emitter>
8486bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8498 return this->emitPopPtr(Loc);
8500 for (ssize_t I = N - 1; I >= 1; --I) {
8501 if (!this->emitConstUint64(I, Loc))
8503 if (!this->emitArrayElemPtrUint64(Loc))
8505 if (!this->emitDestructionPop(ElemDesc, Loc))
8509 if (!this->emitConstUint64(0, Loc))
8511 if (!this->emitArrayElemPtrPopUint64(Loc))
8513 return this->emitDestructionPop(ElemDesc, Loc);
8518 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8523template <
class Emitter>
8524bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E,
bool CU) {
8525 assert(!DiscardResult &&
"Should've been checked before");
8526 unsigned DummyID = P.getOrCreateDummy(D, CU);
8528 if (!this->emitGetPtrGlobal(DummyID, E))
8536 return this->emitDecayPtr(
PT_Ptr, PT, E);
8542template <
class Emitter>
8545 return this->emitConstFloat(
Floating(F), Info);
8547 APInt I = F.bitcastToAPInt();
8548 return this->emitConstFloat(
8549 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8550 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8561template <
class Emitter>
8562bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8575 if (!this->emitGetPtrLocal(*LocalIndex, E))
8585 if (!this->visit(SubExpr))
8587 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8588 unsigned TempOffset =
8589 allocateLocalPrimitive(SubExpr, *FromT,
true);
8590 if (!this->visit(SubExpr))
8592 if (!this->emitSetLocal(*FromT, TempOffset, E))
8594 if (!this->emitGetPtrLocal(TempOffset, E))
8601 if (!this->emitBitCast(E))
8603 return DiscardResult ? this->emitPopPtr(E) :
true;
8607 const llvm::fltSemantics *TargetSemantics =
nullptr;
8609 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8615 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8617 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8618 ResultBitWidth, TargetSemantics,
8623 return this->emitPop(*ToT, E);
8632template <
class Emitter>
8633bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8638 unsigned NumElems = 0;
8641 NumElems = VT->getNumElements();
8642 ElemType = VT->getElementType();
8644 NumElems = MT->getNumElementsFlattened();
8645 ElemType = MT->getElementType();
8648 PrimType ElemT = classifyPrim(ElemType);
8649 for (
unsigned I = 0; I != NumElems; ++I) {
8650 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8652 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8654 if (!this->emitInitElem(ElemT, I, E))
8664 QualType ArrElemType = CAT->getElementType();
8665 unsigned ArrSize = CAT->getZExtSize();
8668 for (
unsigned I = 0; I != ArrSize; ++I) {
8669 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8671 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8673 if (!this->emitInitElem(*ElemT, I, E))
8677 for (
unsigned I = 0; I != ArrSize; ++I) {
8678 if (!this->emitConstUint32(I, E))
8680 if (!this->emitArrayElemPtrUint32(E))
8682 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8684 if (!this->emitFinishInitPop(E))
8694 const Record *
R = getRecord(DestType);
8698 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8700 const Record::Base *B =
R->getBase(BS.getType());
8702 if (!this->emitGetPtrBase(B->Offset, E))
8704 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8706 if (!this->emitFinishInitPop(E))
8711 for (
const Record::Field &F :
R->fields()) {
8712 if (F.isUnnamedBitField())
8715 QualType FieldType = F.Decl->getType();
8717 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8719 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8721 if (F.isBitField()) {
8722 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8725 if (!this->emitInitField(*FieldT, F.Offset, E))
8729 if (!this->emitGetPtrField(F.Offset, E))
8731 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8733 if (!this->emitPopPtr(E))
8746template <
class Emitter>
8747unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8750 return VT->getNumElements();
8752 return MT->getNumElementsFlattened();
8756 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8760 const Record *
R = getRecord(Ty);
8764 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8766 Count += countHLSLFlatElements(BS.getType());
8768 for (
const Record::Field &F :
R->fields()) {
8769 if (F.isUnnamedBitField())
8771 Count += countHLSLFlatElements(F.Decl->getType());
8776 if (canClassify(Ty))
8785template <
class Emitter>
8786bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8787 QualType SrcType,
unsigned SrcOffset,
8792 auto saveToLocal = [&](
PrimType T) ->
bool {
8793 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8794 if (!this->emitSetLocal(T, Offset, E))
8796 Elements.push_back({Offset, T});
8802 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8803 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8804 return std::nullopt;
8809 unsigned NumElems = 0;
8812 NumElems = VT->getNumElements();
8813 ElemType = VT->getElementType();
8815 NumElems = MT->getNumElementsFlattened();
8816 ElemType = MT->getElementType();
8819 PrimType ElemT = classifyPrim(ElemType);
8820 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8821 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8823 if (!this->emitArrayElemPop(ElemT, I, E))
8825 if (!saveToLocal(ElemT))
8835 QualType ArrElemType = CAT->getElementType();
8836 unsigned ArrSize = CAT->getZExtSize();
8839 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8840 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8842 if (!this->emitArrayElemPop(*ElemT, I, E))
8844 if (!saveToLocal(*ElemT))
8848 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8849 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8851 if (!this->emitConstUint32(I, E))
8853 if (!this->emitArrayElemPtrPopUint32(E))
8858 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8869 const Record *
R = getRecord(SrcType);
8873 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8875 if (Elements.size() >= MaxElements)
8877 const Record::Base *B =
R->getBase(BS.getType());
8879 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8881 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8886 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8892 for (
const Record::Field &F :
R->fields()) {
8893 if (Elements.size() >= MaxElements)
8895 if (F.isUnnamedBitField())
8898 QualType FieldType = F.Decl->getType();
8899 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8901 if (!this->emitGetPtrFieldPop(F.Offset, E))
8905 if (!this->emitLoadPop(*FieldT, E))
8907 if (!saveToLocal(*FieldT))
8911 if (!FieldPtrOffset)
8913 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8929template <
class Emitter>
8930bool Compiler<Emitter>::emitHLSLConstructAggregate(
8936 const auto &Src = Elements[ElemIdx++];
8937 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8939 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8943 unsigned NumElems = 0;
8946 NumElems = VT->getNumElements();
8947 ElemType = VT->getElementType();
8949 NumElems = MT->getNumElementsFlattened();
8950 ElemType = MT->getElementType();
8953 PrimType DestElemT = classifyPrim(ElemType);
8954 for (
unsigned I = 0; I != NumElems; ++I) {
8955 if (!loadAndCast(DestElemT, ElemType))
8957 if (!this->emitInitElem(DestElemT, I, E))
8967 QualType ArrElemType = CAT->getElementType();
8968 unsigned ArrSize = CAT->getZExtSize();
8971 for (
unsigned I = 0; I != ArrSize; ++I) {
8972 if (!loadAndCast(*ElemT, ArrElemType))
8974 if (!this->emitInitElem(*ElemT, I, E))
8978 for (
unsigned I = 0; I != ArrSize; ++I) {
8979 if (!this->emitConstUint32(I, E))
8981 if (!this->emitArrayElemPtrUint32(E))
8983 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8985 if (!this->emitFinishInitPop(E))
8995 const Record *
R = getRecord(DestType);
8999 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9001 const Record::Base *B =
R->getBase(BS.getType());
9003 if (!this->emitGetPtrBase(B->Offset, E))
9005 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9007 if (!this->emitFinishInitPop(E))
9012 for (
const Record::Field &F :
R->fields()) {
9013 if (F.isUnnamedBitField())
9016 QualType FieldType = F.Decl->getType();
9018 if (!loadAndCast(*FieldT, FieldType))
9020 if (F.isBitField()) {
9021 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9024 if (!this->emitInitField(*FieldT, F.Offset, E))
9028 if (!this->emitGetPtrField(F.Offset, E))
9030 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9032 if (!this->emitPopPtr(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, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
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)
Result
Implement __builtin_bit_cast and related operations.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
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
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
APValue & getArrayFiller()
bool isIndeterminate() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
A rewritten comparison expression that was originally written using operator syntax.
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Represents the this expression in C++.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
CXXTryStmt - A C++ try block, including all handlers.
CompoundStmt * getTryBlock()
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
const FieldDecl * getTargetUnionField() const
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 }.
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
Represents a concrete matrix type with constant number of rows and columns.
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
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
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() const
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.
bool isCompatibleWith(ClangABI Version) const
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.
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.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
uint32_t getCodeUnit(size_t i) const
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
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
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
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.
ArrayIndexScope(Compiler< Emitter > *Ctx, uint64_t Index)
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
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)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
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 visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
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 visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
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.
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T)
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
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)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
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)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
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.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBase(unsigned I) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
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.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
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.
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool This(InterpState &S, CodePtr OpPC)
constexpr bool isIntegerOrBoolType(PrimType T)
bool InitScope(InterpState &S, 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)
static bool Activate(InterpState &S)
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)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
U cast(CodeGen::Address addr)
int const char * function
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
EvalResult is a struct with detailed info about an evaluated expression.
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.
PrimType getPrimType() const
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)
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()