21#include "llvm/Support/SaveAndRestore.h"
32 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
33 CE && CE->hasAPValueResult() &&
35 return CE->getResultAsAPSInt().getBoolValue();
67 llvm_unreachable(
"Shouldn't be called");
133 this->
Ctx->emitDestroy(*
Idx, E);
140 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
141 this->
Ctx->Descriptors.emplace_back();
142 this->
Ctx->emitInitScope(*
Idx, {});
156 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
157 this->
Ctx->Descriptors.emplace_back();
158 this->
Ctx->emitInitScope(*
Idx, {});
169 if (
Local.Desc->hasTrivialDtor())
172 if (!
Local.EnabledByDefault) {
173 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
174 if (!this->
Ctx->emitGetLocalEnabled(
Local.Offset, E))
176 if (!this->
Ctx->jumpFalse(EndLabel, E))
179 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
182 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
185 this->
Ctx->fallthrough(EndLabel);
186 this->
Ctx->emitLabel(EndLabel);
188 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
190 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
209 if (
const auto *OVE =
210 llvm::dyn_cast_if_present<OpaqueValueExpr>(
Local.Desc->asExpr())) {
211 this->
Ctx->OpaqueExprs.erase(OVE);
223 OldArrayIndex = Ctx->ArrayIndex;
224 Ctx->ArrayIndex = Index;
231 std::optional<uint64_t> OldArrayIndex;
239 if (!Ctx->SourceLocDefaultExpr) {
241 Ctx->SourceLocDefaultExpr = DefaultExpr;
247 Ctx->SourceLocDefaultExpr =
nullptr;
252 bool Enabled =
false;
258 Ctx->InitStack.push_back(std::move(
Link));
270 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
273 Ctx->InitStackActive = OldValue || Active;
279 this->Ctx->InitStackActive = OldValue;
281 Ctx->InitStack.pop_back();
295 OldInitializingDecl(
Ctx->InitializingDecl) {
296 Ctx->InitializingDecl = VD;
301 this->
Ctx->InitializingDecl = OldInitializingDecl;
302 this->
Ctx->InitStack.pop_back();
307 const VarDecl *OldInitializingDecl;
315 bool NewInitializing,
bool NewToLValue)
316 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
317 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
318 Ctx->DiscardResult = NewDiscardResult;
319 Ctx->Initializing = NewInitializing;
320 Ctx->ToLValue = NewToLValue;
324 Ctx->DiscardResult = OldDiscardResult;
325 Ctx->Initializing = OldInitializing;
326 Ctx->ToLValue = OldToLValue;
333 bool OldDiscardResult;
334 bool OldInitializing;
338template <
class Emitter>
342 return Ctx->emitThis(E);
345 return Ctx->emitGetPtrFieldPop(
Offset, E);
347 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
349 return Ctx->emitGetPtrLocal(
Offset, E);
353 if (!Ctx->emitConstUint32(
Offset, E))
355 return Ctx->emitArrayElemPtrPopUint32(E);
357 return Ctx->emitRVOPtr(E);
361 llvm_unreachable(
"Unhandled InitLink kind");
377 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
378 assert(LI.Name != Name);
381 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
402 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
404 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
405 assert(LI.Name != Name);
408 this->Ctx->CaseLabels = std::move(CaseLabels);
409 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
411 DefaultLabel, Ctx->VarScope);
415 this->Ctx->CaseLabels = std::move(OldCaseLabels);
416 this->Ctx->LabelInfoStack.pop_back();
421 CaseMap OldCaseLabels;
432 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
435 Ctx->LocOverride = NewValue;
440 Ctx->LocOverride = OldFlag;
445 std::optional<SourceInfo> OldFlag;
452template <
class Emitter>
460 case CK_LValueToRValue: {
463 if (!this->
visit(SubExpr))
465 return this->emitLoadPopL(E);
475 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
481 if (
auto GlobalIndex =
P.getGlobal(D))
482 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
483 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
484 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
485 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
486 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
487 return this->emitGetParam(*SubExprT, It->second.Index, E);
499 if (!this->emitGetPtrLocal(*LocalIndex, E))
503 if (!this->
visit(SubExpr))
507 return this->emitLoadPop(*SubExprT, E);
512 return this->emitMemcpy(E);
515 case CK_DerivedToBaseMemberPointer: {
526 ->getMostRecentCXXRecordDecl();
528 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
529 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
531 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
539 case CK_BaseToDerivedMemberPointer: {
550 ->getMostRecentCXXRecordDecl();
554 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
556 PathI != PathE; ++PathI) {
557 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
558 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
560 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
567 assert(ToDecl != CurDecl);
568 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
570 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
576 case CK_UncheckedDerivedToBase:
577 case CK_DerivedToBase: {
582 if (
const auto *PT = dyn_cast<PointerType>(Ty))
583 return PT->getPointeeType()->getAsCXXRecordDecl();
584 return Ty->getAsCXXRecordDecl();
591 if (B->isVirtual()) {
592 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
594 CurType = B->getType();
596 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
597 if (!this->emitGetPtrBasePop(
600 CurType = B->getType();
607 case CK_BaseToDerived: {
610 unsigned DerivedOffset =
616 return this->emitGetPtrDerivedPop(DerivedOffset,
621 case CK_FloatingCast: {
624 return this->emitVectorConversion(E->
getSubExpr(), E);
628 if (!this->
visit(SubExpr))
630 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
634 case CK_IntegralToFloating: {
636 return this->emitVectorConversion(E->
getSubExpr(), E);
639 if (!this->
visit(SubExpr))
641 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
642 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
643 TargetSemantics, getFPOptions(E), E);
646 case CK_FloatingToBoolean: {
648 return this->emitVectorConversion(E->
getSubExpr(), E);
652 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
653 return this->emitConstBool(FL->getValue().isNonZero(), E);
654 if (!this->
visit(SubExpr))
656 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
659 case CK_FloatingToIntegral: {
661 return this->emitVectorConversion(E->
getSubExpr(), E);
664 if (!this->
visit(SubExpr))
668 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
671 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
674 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
677 case CK_NullToPointer:
678 case CK_NullToMemberPointer: {
681 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
686 case CK_PointerToIntegral: {
687 if (!this->
visit(SubExpr))
693 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
699 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
701 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
702 return this->emitCastPointerIntegral(
T, E);
705 case CK_ArrayToPointerDecay: {
706 if (!this->
visit(SubExpr))
708 return this->emitArrayDecay(E);
711 case CK_IntegralToPointer: {
713 assert(IntType->isIntegralOrEnumerationType());
714 if (!this->
visit(SubExpr))
728 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
731 case CK_AtomicToNonAtomic:
732 case CK_ConstructorConversion:
733 case CK_FunctionToPointerDecay:
734 case CK_NonAtomicToAtomic:
736 case CK_UserDefinedConversion:
737 case CK_AddressSpaceConversion:
738 case CK_CPointerToObjCPointerCast:
755 return this->emitBuiltinBitCast(E);
770 if (!this->
visit(SubExpr))
778 return this->emitFnPtrCast(E);
786 if (!this->
visit(SubExpr))
788 return this->emitDecayPtr(*FromT, *ToT, E);
790 case CK_IntegralToBoolean:
791 case CK_FixedPointToBoolean: {
793 return this->emitVectorConversion(E->
getSubExpr(), E);
799 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
800 return this->emitConst(IL->getValue(), E);
801 if (!this->
visit(SubExpr))
806 case CK_IntegralCast:
808 return this->emitVectorConversion(E->
getSubExpr(), E);
810 case CK_BooleanToSignedIntegral: {
817 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
822 if (!this->emitConst(IL->getValue(), SubExpr))
825 if (!this->
visit(SubExpr))
833 if (!ED->isFixed()) {
834 if (!this->emitCheckEnumValue(*FromT, ED, E))
840 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
843 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
848 if (!this->emitCast(*FromT, *ToT, E))
851 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
852 return this->emitNeg(*ToT, E);
856 case CK_PointerToBoolean:
857 if (!this->
visit(SubExpr))
859 return this->emitIsNonNullPtr(E);
861 case CK_MemberPointerToBoolean:
862 if (!this->
visit(SubExpr))
864 return this->emitIsNonNullMemberPtr(E);
866 case CK_IntegralComplexToBoolean:
867 case CK_FloatingComplexToBoolean: {
868 if (!this->
visit(SubExpr))
870 return this->emitComplexBoolCast(SubExpr);
873 case CK_IntegralComplexToReal:
874 case CK_FloatingComplexToReal:
875 return this->emitComplexReal(SubExpr);
877 case CK_IntegralRealToComplex:
878 case CK_FloatingRealToComplex: {
885 if (!this->emitGetPtrLocal(*LocalIndex, E))
894 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
896 return this->emitInitElem(
T, 1, SubExpr);
899 case CK_IntegralComplexCast:
900 case CK_FloatingComplexCast:
901 case CK_IntegralComplexToFloatingComplex:
902 case CK_FloatingComplexToIntegralComplex: {
909 if (!this->emitGetPtrLocal(*LocalIndex, E))
916 unsigned SubExprOffset =
918 if (!this->
visit(SubExpr))
920 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
928 for (
unsigned I = 0; I != 2; ++I) {
929 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
931 if (!this->emitArrayElemPop(SourceElemT, I, E))
935 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
939 if (!this->emitInitElem(DestElemT, I, E))
945 case CK_VectorSplat: {
956 if (!this->emitGetPtrLocal(*LocalIndex, E))
962 unsigned ElemOffset =
966 if (!this->
visit(SubExpr))
971 if (!this->emitSetLocal(ElemT, ElemOffset, E))
974 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
975 if (!this->emitGetLocal(ElemT, ElemOffset, E))
977 if (!this->emitInitElem(ElemT, I, E))
984 case CK_HLSLVectorTruncation: {
989 if (!this->
visit(SubExpr))
991 return this->emitArrayElemPop(*ResultT, 0, E);
1000 if (!this->emitGetPtrLocal(*LocalIndex, E))
1005 if (!this->
visit(SubExpr))
1007 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1011 case CK_IntegralToFixedPoint: {
1012 if (!this->
visit(SubExpr))
1016 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1021 return this->emitPopFixedPoint(E);
1024 case CK_FloatingToFixedPoint: {
1025 if (!this->
visit(SubExpr))
1029 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1030 if (!this->emitCastFloatingFixedPoint(Sem, E))
1033 return this->emitPopFixedPoint(E);
1036 case CK_FixedPointToFloating: {
1037 if (!this->
visit(SubExpr))
1039 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1040 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1043 return this->emitPopFloat(E);
1046 case CK_FixedPointToIntegral: {
1047 if (!this->
visit(SubExpr))
1050 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1053 return this->emitPop(IntegralT, E);
1056 case CK_FixedPointCast: {
1057 if (!this->
visit(SubExpr))
1060 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1061 if (!this->emitCastFixedPoint(Sem, E))
1064 return this->emitPopFixedPoint(E);
1072 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1074 case CK_LValueBitCast:
1079 case CK_HLSLArrayRValue: {
1086 if (!this->emitGetPtrLocal(*LocalIndex, E))
1089 if (!this->
visit(SubExpr))
1091 return this->emitMemcpy(E);
1094 case CK_HLSLMatrixTruncation: {
1099 if (!this->
visit(SubExpr))
1101 return this->emitArrayElemPop(*ResultT, 0, E);
1110 if (!this->emitGetPtrLocal(*LocalIndex, E))
1115 if (!this->
visit(SubExpr))
1117 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1121 case CK_HLSLAggregateSplatCast: {
1131 if (!this->emitGetPtrLocal(*LocalIndex, E))
1138 unsigned SrcOffset =
1141 if (!this->
visit(SubExpr))
1143 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1147 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1150 case CK_HLSLElementwiseCast: {
1161 unsigned SrcPtrOffset =
1163 if (!this->
visit(SubExpr))
1165 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1169 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1171 if (Elements.empty())
1174 const HLSLFlatElement &Src = Elements[0];
1175 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1177 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1184 if (!this->emitGetPtrLocal(*LocalIndex, E))
1188 unsigned SrcOffset =
1190 if (!this->
visit(SubExpr))
1192 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1196 unsigned ElemCount = countHLSLFlatElements(DestType);
1199 Elements.reserve(ElemCount);
1200 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1205 assert(Elements.size() == ElemCount &&
1206 "Source type has fewer scalar elements than the destination type");
1208 return emitHLSLConstructAggregate(DestType, Elements, E);
1215 const Record::Field *RF = R->getField(UnionField);
1218 if (!this->
visit(SubExpr))
1220 if (RF->isBitField())
1221 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1223 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1226 if (!this->emitGetPtrField(RF->Offset, E))
1228 if (!this->emitActivate(E))
1234 return this->emitInvalid(E);
1236 llvm_unreachable(
"Unhandled clang::CastKind enum");
1239template <
class Emitter>
1241 return this->emitBuiltinBitCast(E);
1244template <
class Emitter>
1249 return this->emitConst(
LE->getValue(),
LE);
1252template <
class Emitter>
1258 return this->emitFloat(F, E);
1261template <
class Emitter>
1271 if (!this->emitGetPtrLocal(*LocalIndex, E))
1278 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1280 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1285template <
class Emitter>
1293 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1298template <
class Emitter>
1303template <
class Emitter>
1330 return this->emitComplexComparison(LHS, RHS, E);
1338 if (!this->
visit(LHS))
1341 if (!this->
visit(RHS))
1344 if (!this->emitToMemberPtr(E))
1350 if (!this->emitCastMemberPtrPtr(E))
1367 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1373 if (!this->emitGetPtrLocal(*ResultIndex, E))
1380 return this->emitCMP3(*
LT, CmpInfo, E);
1383 if (!
LT || !RT || !
T)
1393 return this->visitAssignment(LHS, RHS, E);
1400 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1404 return this->emitPopBool(E);
1406 return this->emitCast(
PT_Bool, *
T, E);
1410 auto Discard = [
this,
T, E](
bool Result) {
1418 return MaybeCastToBool(this->emitEQ(*
LT, E));
1420 return MaybeCastToBool(this->emitNE(*
LT, E));
1422 return MaybeCastToBool(this->emitLT(*
LT, E));
1424 return MaybeCastToBool(this->emitLE(*
LT, E));
1426 return MaybeCastToBool(this->emitGT(*
LT, E));
1428 return MaybeCastToBool(this->emitGE(*
LT, E));
1431 return Discard(this->emitSubf(getFPOptions(E), E));
1432 return Discard(this->emitSub(*
T, E));
1435 return Discard(this->emitAddf(getFPOptions(E), E));
1436 return Discard(this->emitAdd(*
T, E));
1439 return Discard(this->emitMulf(getFPOptions(E), E));
1440 return Discard(this->emitMul(*
T, E));
1442 return Discard(this->emitRem(*
T, E));
1445 return Discard(this->emitDivf(getFPOptions(E), E));
1446 return Discard(this->emitDiv(*
T, E));
1448 return Discard(this->emitBitAnd(*
T, E));
1450 return Discard(this->emitBitOr(*
T, E));
1452 return Discard(this->emitShl(*
LT, *RT, E));
1454 return Discard(this->emitShr(*
LT, *RT, E));
1456 return Discard(this->emitBitXor(*
T, E));
1459 llvm_unreachable(
"Already handled earlier");
1464 llvm_unreachable(
"Unhandled binary op");
1469template <
class Emitter>
1475 if ((Op != BO_Add && Op != BO_Sub) ||
1486 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1487 if (!this->
visit(E))
1490 return this->emitDecayPtr(
T,
PT_Ptr, E);
1499 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1507 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1510 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1517 if (!visitAsPointer(RHS, *RT))
1519 if (!this->
visit(LHS))
1523 if (!visitAsPointer(LHS, *
LT))
1525 if (!this->
visit(RHS))
1536 if (!this->emitAddOffset(OffsetType, E))
1540 if (!this->emitSubOffset(OffsetType, E))
1549 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1554 return this->emitPop(ExprT, E);
1558template <
class Emitter>
1567 LabelTy LabelTrue = this->getLabel();
1568 LabelTy LabelEnd = this->getLabel();
1572 if (!this->jumpTrue(LabelTrue, E))
1577 if (!this->jump(LabelEnd, E))
1580 this->emitLabel(LabelTrue);
1581 this->emitConstBool(
true, E);
1582 this->fallthrough(LabelEnd);
1583 this->emitLabel(LabelEnd);
1586 assert(Op == BO_LAnd);
1589 LabelTy LabelFalse = this->getLabel();
1590 LabelTy LabelEnd = this->getLabel();
1594 if (!this->jumpFalse(LabelFalse, E))
1599 if (!this->jump(LabelEnd, E))
1602 this->emitLabel(LabelFalse);
1603 this->emitConstBool(
false, E);
1604 this->fallthrough(LabelEnd);
1605 this->emitLabel(LabelEnd);
1609 return this->emitPopBool(E);
1614 return this->emitCast(
PT_Bool,
T, E);
1619template <
class Emitter>
1626 if (!this->emitGetPtrLocal(*LocalIndex, E))
1635 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1636 unsigned ResultOffset = ~0u;
1642 if (!this->emitDupPtr(E))
1644 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1649 LHSType = AT->getValueType();
1652 RHSType = AT->getValueType();
1661 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1666 if (!this->
visit(LHS))
1668 if (!this->
visit(RHS))
1670 if (!this->emitMulc(ElemT, E))
1673 return this->emitPopPtr(E);
1677 if (Op == BO_Div && RHSIsComplex) {
1684 if (!LHSIsComplex) {
1689 LHSOffset = *LocalIndex;
1691 if (!this->emitGetPtrLocal(LHSOffset, E))
1694 if (!this->
visit(LHS))
1697 if (!this->emitInitElem(ElemT, 0, E))
1700 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1702 if (!this->emitInitElem(ElemT, 1, E))
1705 if (!this->
visit(LHS))
1709 if (!this->
visit(RHS))
1711 if (!this->emitDivc(ElemT, E))
1714 return this->emitPopPtr(E);
1721 if (!this->
visit(LHS))
1723 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1728 if (!this->
visit(LHS))
1730 if (!this->emitSetLocal(LHST, LHSOffset, E))
1738 if (!this->
visit(RHS))
1740 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1745 if (!this->
visit(RHS))
1747 if (!this->emitSetLocal(RHST, RHSOffset, E))
1754 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1755 unsigned ElemIndex,
unsigned Offset,
1756 const Expr *E) ->
bool {
1758 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1760 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1763 if (ElemIndex == 0 || !LoadZero)
1770 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1773 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1780 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1783 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1786 if (!this->emitAddf(getFPOptions(E), E))
1789 if (!this->emitAdd(ResultElemT, E))
1794 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1797 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1800 if (!this->emitSubf(getFPOptions(E), E))
1803 if (!this->emitSub(ResultElemT, E))
1808 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1811 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1815 if (!this->emitMulf(getFPOptions(E), E))
1818 if (!this->emitMul(ResultElemT, E))
1823 assert(!RHSIsComplex);
1824 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1827 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1831 if (!this->emitDivf(getFPOptions(E), E))
1834 if (!this->emitDiv(ResultElemT, E))
1845 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1848 if (!this->emitPop(ResultElemT, E))
1853 return this->emitPopPtr(E);
1859template <
class Emitter>
1864 "Comma op should be handled in VisitBinaryOperator");
1878 if (!this->emitGetPtrLocal(*LocalIndex, E))
1892 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1895 if (!this->
visit(LHS))
1897 if (!this->
visit(RHS))
1899 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1902 return this->emitPopPtr(E);
1907 unsigned LHSOffset =
1909 if (!this->
visit(LHS))
1911 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1915 unsigned RHSOffset =
1917 if (!this->
visit(RHS))
1919 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1931 if (NeedIntPromot) {
1933 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1938 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1939 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1941 if (!this->emitArrayElemPop(ElemT, Index, E))
1944 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1946 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1948 }
else if (NeedIntPromot) {
1949 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1955#define EMIT_ARITH_OP(OP) \
1957 if (ElemT == PT_Float) { \
1958 if (!this->emit##OP##f(getFPOptions(E), E)) \
1961 if (!this->emit##OP(ElemT, E)) \
1967 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1968 if (!getElem(LHSOffset, ElemT, I))
1970 if (!getElem(RHSOffset, RHSElemT, I))
1982 if (!this->emitRem(ElemT, E))
1986 if (!this->emitBitAnd(OpT, E))
1990 if (!this->emitBitOr(OpT, E))
1994 if (!this->emitBitXor(OpT, E))
1998 if (!this->emitShl(OpT, RHSElemT, E))
2002 if (!this->emitShr(OpT, RHSElemT, E))
2006 if (!this->emitEQ(ElemT, E))
2010 if (!this->emitNE(ElemT, E))
2014 if (!this->emitLE(ElemT, E))
2018 if (!this->emitLT(ElemT, E))
2022 if (!this->emitGE(ElemT, E))
2026 if (!this->emitGT(ElemT, E))
2031 if (!this->emitBitAnd(ResultElemT, E))
2036 if (!this->emitBitOr(ResultElemT, E))
2040 return this->emitInvalid(E);
2049 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2051 if (!this->emitNeg(ResultElemT, E))
2057 if (NeedIntPromot &&
2058 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2062 if (!this->emitInitElem(ResultElemT, I, E))
2071template <
class Emitter>
2081 auto LHSSemaInt = LHSSema.toOpaqueInt();
2083 auto RHSSemaInt = RHSSema.toOpaqueInt();
2085 if (!this->
visit(LHS))
2093 if (!this->
visit(RHS))
2102 auto ConvertResult = [&](
bool R) ->
bool {
2106 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2107 if (ResultSema != CommonSema)
2108 return this->emitCastFixedPoint(ResultSema, E);
2112 auto MaybeCastToBool = [&](
bool Result) {
2117 return this->emitPop(
T, E);
2119 return this->emitCast(
PT_Bool,
T, E);
2125 return MaybeCastToBool(this->emitEQFixedPoint(E));
2127 return MaybeCastToBool(this->emitNEFixedPoint(E));
2129 return MaybeCastToBool(this->emitLTFixedPoint(E));
2131 return MaybeCastToBool(this->emitLEFixedPoint(E));
2133 return MaybeCastToBool(this->emitGTFixedPoint(E));
2135 return MaybeCastToBool(this->emitGEFixedPoint(E));
2137 return ConvertResult(this->emitAddFixedPoint(E));
2139 return ConvertResult(this->emitSubFixedPoint(E));
2141 return ConvertResult(this->emitMulFixedPoint(E));
2143 return ConvertResult(this->emitDivFixedPoint(E));
2145 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2147 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2150 return this->emitInvalid(E);
2153 llvm_unreachable(
"unhandled binop opcode");
2156template <
class Emitter>
2165 if (!this->
visit(SubExpr))
2167 if (!this->emitNegFixedPoint(E))
2170 return this->emitPopFixedPoint(E);
2176 llvm_unreachable(
"Unhandled unary opcode");
2179template <
class Emitter>
2188 return this->visitZeroInitializer(*
T, QT, E);
2201 return this->visitZeroRecordInitializer(R, E);
2208 return this->visitZeroArrayInitializer(QT, E);
2212 QualType ElemQT = ComplexTy->getElementType();
2214 for (
unsigned I = 0; I < 2; ++I) {
2215 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2217 if (!this->emitInitElem(ElemT, I, E))
2224 unsigned NumVecElements = VecT->getNumElements();
2225 QualType ElemQT = VecT->getElementType();
2228 for (
unsigned I = 0; I < NumVecElements; ++I) {
2229 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2231 if (!this->emitInitElem(ElemT, I, E))
2238 unsigned NumElems = MT->getNumElementsFlattened();
2239 QualType ElemQT = MT->getElementType();
2242 for (
unsigned I = 0; I != NumElems; ++I) {
2243 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2245 if (!this->emitInitElem(ElemT, I, E))
2254template <
class Emitter>
2267 for (
const Expr *SubExpr : {LHS, RHS}) {
2268 if (!this->
visit(SubExpr)) {
2275 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2276 if (!this->emitExpandPtr(E))
2287 return this->emitError(E);
2290 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2294 if (!this->emitArrayElemPtrPop(*IndexT, E))
2297 return this->emitPopPtr(E);
2303 return this->emitLoadPop(*
T, E);
2306template <
class Emitter>
2308 const Expr *ArrayFiller,
const Expr *E) {
2313 QT = AT->getValueType();
2316 if (
Inits.size() == 0)
2318 return this->emitInvalid(E);
2331 if (
Inits.size() == 0)
2332 return this->visitZeroInitializer(*
T, QT, E);
2333 assert(
Inits.size() == 1);
2347 if (!this->emitGetPtrLocal(*LocalIndex, E))
2362 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2369 bool BitField = FieldToInit->isBitField();
2371 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2372 FieldToInit->bitWidth(), E);
2374 return this->emitInitBitField(
T, FieldToInit->Offset,
2375 FieldToInit->bitWidth(), E);
2377 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2378 return this->emitInitField(
T, FieldToInit->Offset, E);
2381 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2389 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2392 if (
Activate && !this->emitActivate(E))
2399 if (
Inits.size() == 0) {
2400 if (!this->visitZeroRecordInitializer(R, E))
2405 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2406 FToInit = ILE->getInitializedFieldInUnion();
2410 const Record::Field *FieldToInit = R->getField(FToInit);
2412 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2415 if (!initCompositeField(FieldToInit,
Init,
true))
2419 return this->emitFinishInit(E);
2422 assert(!R->isUnion());
2423 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2425 const Record::Base *B = R->getBase(BI);
2428 if (!this->emitGetPtrBase(B->Offset,
Init))
2434 unsigned FieldIndex = 0;
2435 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2436 const Record::Field *FieldToInit = R->getField(FieldIndex);
2437 if (FieldToInit->isUnnamedBitField()) {
2452 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2454 }
else if (!initCompositeField(FieldToInit,
Init)) {
2462 assert(R->getNumVirtualBases() == 0);
2464 return this->emitFinishInit(E);
2469 Ctx.getASTContext().getAsConstantArrayType(QT);
2474 !this->emitCheckArrayDestSize(NumElems, E))
2477 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2481 unsigned ElementIndex = 0;
2483 if (
const auto *EmbedS =
2484 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2492 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2493 getFPOptions(E), E))
2499 return this->emitInitElem(TargetT, ElemIndex, IL);
2501 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2517 for (; ElementIndex != NumElems; ++ElementIndex) {
2523 return this->emitFinishInit(E);
2527 unsigned NumInits =
Inits.size();
2532 QualType ElemQT = ComplexTy->getElementType();
2534 if (NumInits == 0) {
2536 for (
unsigned I = 0; I < 2; ++I) {
2537 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2539 if (!this->emitInitElem(ElemT, I, E))
2542 }
else if (NumInits == 2) {
2543 unsigned InitIndex = 0;
2548 if (!this->emitInitElem(ElemT, InitIndex, E))
2557 unsigned NumVecElements = VecT->getNumElements();
2558 assert(NumVecElements >=
Inits.size());
2560 QualType ElemQT = VecT->getElementType();
2564 unsigned InitIndex = 0;
2571 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2572 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2573 InitVecT->getNumElements(), E))
2575 InitIndex += InitVecT->getNumElements();
2577 if (!this->emitInitElem(ElemT, InitIndex, E))
2583 assert(InitIndex <= NumVecElements);
2586 for (; InitIndex != NumVecElements; ++InitIndex) {
2587 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2589 if (!this->emitInitElem(ElemT, InitIndex, E))
2596 unsigned NumElems = MT->getNumElementsFlattened();
2597 assert(
Inits.size() == NumElems);
2599 QualType ElemQT = MT->getElementType();
2605 for (
unsigned I = 0; I != NumElems; ++I) {
2608 if (!this->emitInitElem(ElemT, I, E))
2619template <
class Emitter>
2626 return this->emitInitElem(*InitT, ElemIndex,
Init);
2632 if (!this->emitConstUint32(ElemIndex,
Init))
2634 if (!this->emitArrayElemPtrUint32(
Init))
2639template <
class Emitter>
2642 bool Activate,
bool IsOperatorCall) {
2644 llvm::BitVector NonNullArgs;
2645 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2648 bool ExplicitMemberFn =
false;
2649 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2650 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2652 unsigned ArgIndex = 0;
2653 for (
const Expr *Arg : Args) {
2655 if (!this->
visit(Arg))
2663 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2664 if (DeclIndex < FuncDecl->getNumParams())
2665 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2674 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2682 if (!this->emitActivate(Arg))
2686 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2689 if (!this->emitCheckNonNullArg(ArgT, Arg))
2700template <
class Emitter>
2705template <
class Emitter>
2711template <
class Emitter>
2717template <
class Emitter>
2735template <
class Emitter>
2737 auto It = E->
begin();
2738 return this->
visit(*It);
2742 UnaryExprOrTypeTrait Kind) {
2743 bool AlignOfReturnsPreferred =
2750 T = Ref->getPointeeType();
2752 if (
T.getQualifiers().hasUnaligned())
2758 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2764template <
class Emitter>
2768 UnaryExprOrTypeTrait Kind = E->
getKind();
2771 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2777 ArgType = Ref->getPointeeType();
2783 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2784 return this->emitInvalid(E);
2786 if (Kind == UETT_SizeOf)
2795 return this->emitConst(Size.getQuantity(), E);
2798 if (Kind == UETT_CountOf) {
2804 if (
const auto *CAT =
2808 return this->emitConst(CAT->getSize(), E);
2818 if (VAT->getElementType()->isArrayType()) {
2819 std::optional<APSInt> Res =
2821 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2826 return this->emitConst(*Res, E);
2831 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2851 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2854 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2864 return this->emitConst(Size.getQuantity(), E);
2867 if (Kind == UETT_VectorElements) {
2872 return this->emitConst(VT->getNumElements(), E);
2874 return this->emitSizelessVectorElementSize(E);
2877 if (Kind == UETT_VecStep) {
2879 unsigned N = VT->getNumElements();
2886 return this->emitConst(N, E);
2888 return this->emitConst(1, E);
2891 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2900 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2902 return this->emitInvalid(E);
2904 return this->emitConst(
2905 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2913template <
class Emitter>
2922 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2927 if (VD->getInit() && !VD->getInit()->isValueDependent())
2928 VD->evaluateValue();
2929 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2930 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2932 if (
Member->getType()->isReferenceType())
2933 return this->emitLoadPopPtr(E);
2942 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2943 MD && !MD->isStatic()) {
2947 if (!this->
discard(Base) && !this->emitSideEffect(E))
2962 const Record::Field *F = R->getField(FD);
2966 const auto maybeLoadValue = [&]() ->
bool {
2970 return this->emitLoadPop(*
T, E);
2975 if (F->Decl->getType()->isReferenceType())
2976 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2977 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2980template <
class Emitter>
2990template <
class Emitter>
3004 if (!this->
visit(Common))
3006 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3020 for (
size_t I = 0; I != Size; ++I) {
3032template <
class Emitter>
3047 return this->emitGetLocal(SubExprT, It->second, E);
3050 if (!this->
visit(SourceExpr))
3057 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3066 return this->emitGetLocal(SubExprT, LocalIndex, E);
3070template <
class Emitter>
3083 bool IsBcpCall =
false;
3084 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3085 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3089 LabelTy LabelEnd = this->getLabel();
3090 LabelTy LabelFalse = this->getLabel();
3093 if (!this->emitPushIgnoreDiags(E))
3101 if (this->checkingForUndefinedBehavior()) {
3104 if (!this->
discard(FalseExpr))
3121 if (!this->jumpFalse(LabelFalse, E))
3126 if (!this->jump(LabelEnd, E))
3128 this->emitLabel(LabelFalse);
3132 this->fallthrough(LabelEnd);
3133 this->emitLabel(LabelEnd);
3136 return this->emitPopIgnoreDiags(E);
3140template <
class Emitter>
3146 return this->emitGetStringPtr(E, E);
3150 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3151 assert(CAT &&
"a string literal that's not a constant array?");
3156 unsigned N = std::min(ArraySize, E->
getLength());
3159 for (
unsigned I = 0; I != N; ++I) {
3162 if (CharWidth == 1) {
3163 this->emitConstSint8(CodeUnit, E);
3164 this->emitInitElemSint8(I, E);
3165 }
else if (CharWidth == 2) {
3166 this->emitConstUint16(CodeUnit, E);
3167 this->emitInitElemUint16(I, E);
3168 }
else if (CharWidth == 4) {
3169 this->emitConstUint32(CodeUnit, E);
3170 this->emitInitElemUint32(I, E);
3172 llvm_unreachable(
"unsupported character width");
3177 for (
unsigned I = N; I != ArraySize; ++I) {
3178 if (CharWidth == 1) {
3179 this->emitConstSint8(0, E);
3180 this->emitInitElemSint8(I, E);
3181 }
else if (CharWidth == 2) {
3182 this->emitConstUint16(0, E);
3183 this->emitInitElemUint16(I, E);
3184 }
else if (CharWidth == 4) {
3185 this->emitConstUint32(0, E);
3186 this->emitInitElemUint32(I, E);
3188 llvm_unreachable(
"unsupported character width");
3195template <
class Emitter>
3199 return this->emitDummyPtr(E, E);
3202template <
class Emitter>
3204 auto &A =
Ctx.getASTContext();
3213template <
class Emitter>
3221 auto &A =
Ctx.getASTContext();
3225 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3226 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3232 return this->emitGetStringPtr(SL, E);
3235template <
class Emitter>
3239 return this->emitConst(E->
getValue(), E);
3242template <
class Emitter>
3264 if (!this->emitLoad(LHST, E))
3267 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3268 LHSComputationType, E))
3280 unsigned TempOffset =
3282 if (!this->emitSetLocal(*RT, TempOffset, E))
3288 if (!this->emitLoad(LHST, E))
3292 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3293 LHSComputationType, E))
3297 if (!this->emitGetLocal(*RT, TempOffset, E))
3303 if (!this->emitAddf(getFPOptions(E), E))
3307 if (!this->emitSubf(getFPOptions(E), E))
3311 if (!this->emitMulf(getFPOptions(E), E))
3315 if (!this->emitDivf(getFPOptions(E), E))
3326 return this->emitStorePop(LHST, E);
3327 return this->emitStore(LHST, E);
3330template <
class Emitter>
3339 if (Op != BO_AddAssign && Op != BO_SubAssign)
3348 if (!this->emitLoad(*
LT, LHS))
3354 if (Op == BO_AddAssign) {
3355 if (!this->emitAddOffset(*RT, E))
3358 if (!this->emitSubOffset(*RT, E))
3363 return this->emitStorePopPtr(E);
3364 return this->emitStorePtr(E);
3367template <
class Emitter>
3380 if (!
Ctx.getLangOpts().CPlusPlus14)
3381 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3383 if (!
LT || !RT || !ResultT || !LHSComputationT)
3400 if (!this->emitLoad(*
LT, E))
3402 if (
LT != LHSComputationT &&
3403 !this->emitIntegralCast(*
LT, *LHSComputationT,
3417 unsigned TempOffset =
3420 if (!this->emitSetLocal(*RT, TempOffset, E))
3427 if (!this->emitLoad(*
LT, E))
3429 if (
LT != LHSComputationT &&
3430 !this->emitIntegralCast(*
LT, *LHSComputationT,
3435 if (!this->emitGetLocal(*RT, TempOffset, E))
3442 if (!this->emitAdd(*LHSComputationT, E))
3446 if (!this->emitSub(*LHSComputationT, E))
3450 if (!this->emitMul(*LHSComputationT, E))
3454 if (!this->emitDiv(*LHSComputationT, E))
3458 if (!this->emitRem(*LHSComputationT, E))
3462 if (!this->emitShl(*LHSComputationT, *RT, E))
3466 if (!this->emitShr(*LHSComputationT, *RT, E))
3470 if (!this->emitBitAnd(*LHSComputationT, E))
3474 if (!this->emitBitXor(*LHSComputationT, E))
3478 if (!this->emitBitOr(*LHSComputationT, E))
3482 llvm_unreachable(
"Unimplemented compound assign operator");
3486 if (ResultT != LHSComputationT &&
3487 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3493 return this->emitStoreBitFieldPop(*ResultT, E);
3494 return this->emitStorePop(*ResultT, E);
3497 return this->emitStoreBitField(*ResultT, E);
3498 return this->emitStore(*ResultT, E);
3501template <
class Emitter>
3509template <
class Emitter>
3524 if (!
Ctx.getLangOpts().CPlusPlus11)
3531 for (
const Expr *LHS : CommaLHSs) {
3553 if (!this->
visit(Inner))
3558 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3561 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3564 return this->emitGetPtrGlobal(*GlobalIndex, E);
3567 if (!this->checkLiteralType(Inner))
3570 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3576 return this->emitInitGlobalTempComp(TempDecl, E);
3589 unsigned LocalIndex =
3591 if (!this->VarScope->LocalsAlwaysEnabled &&
3592 !this->emitEnableLocal(LocalIndex, E))
3595 if (!this->
visit(Inner))
3597 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3600 return this->emitGetPtrLocal(LocalIndex, E);
3603 if (!this->checkLiteralType(Inner))
3610 if (!this->VarScope->LocalsAlwaysEnabled &&
3611 !this->emitEnableLocal(*LocalIndex, E))
3614 if (!this->emitGetPtrLocal(*LocalIndex, E))
3621template <
class Emitter>
3632 if (!this->
visit(SubExpr))
3636 return this->emitPopPtr(E);
3640template <
class Emitter>
3661 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3666 if (
P.isGlobalInitialized(*GlobalIndex))
3672 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3684 unsigned LocalIndex;
3688 LocalIndex = *MaybeIndex;
3692 if (!this->emitGetPtrLocal(LocalIndex, E))
3696 return this->
visit(
Init) && this->emitInit(*
T, E);
3700template <
class Emitter>
3711 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3715 if (!R || R->getNumFields() == 0)
3717 const Record::Field *Field = R->getField(0
U);
3722 return this->emitInitField(*Field->T, Field->Offset, E);
3729template <
class Emitter>
3733 return this->emitConst(E->
getValue(), E);
3736template <
class Emitter>
3749 for (
const Record::Field &F : R->fields()) {
3751 if (!
Init ||
Init->containsErrors())
3759 if (!this->emitInitField(*
T, F.Offset, E))
3762 if (!this->emitGetPtrField(F.Offset, E))
3773template <
class Emitter>
3779 return this->emitGetStringPtr(E, E);
3783template <
class Emitter>
3788 return this->emitInvalid(E);
3791template <
class Emitter>
3805 if (!this->emitInvalidCast(
CastKind,
false, E))
3813 bool Fatal = (ToT != FromT);
3820template <
class Emitter>
3822 if (!
Ctx.getLangOpts().CPlusPlus20) {
3843 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3848 return this->emitPopPtr(E);
3852template <
class Emitter>
3858 return this->emitConstBool(E->
getValue(), E);
3861template <
class Emitter>
3866 if (
T->isRecordType()) {
3880 if (!this->emitGetPtrLocal(*LocalIndex, E))
3888 T->getAsCXXRecordDecl()))
3898 if (!this->visitZeroRecordInitializer(R, E))
3910 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3912 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3913 if (!this->emitCheckFunctionDecl(Ctor, E))
3924 assert(
Func->hasThisPointer());
3925 assert(!
Func->hasRVO());
3929 if (!this->emitDupPtr(E))
3933 for (
const auto *Arg : E->
arguments()) {
3934 if (!this->
visit(Arg))
3938 if (
Func->isVariadic()) {
3939 uint32_t VarArgSize = 0;
3940 unsigned NumParams =
Func->getNumWrittenParams();
3941 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3945 if (!this->emitCallVar(
Func, VarArgSize, E))
3948 if (!this->emitCall(
Func, 0, E)) {
3953 (void)this->emitPopPtr(E);
3959 return this->emitPopPtr(E);
3963 if (
T->isArrayType()) {
3968 if (!this->emitDupPtr(E))
3972 initArrayDimension = [&](
QualType T) ->
bool {
3973 if (!
T->isArrayType()) {
3975 for (
const auto *Arg : E->
arguments()) {
3976 if (!this->
visit(Arg))
3980 return this->emitCall(
Func, 0, E);
3984 Ctx.getASTContext().getAsConstantArrayType(
T);
3989 for (
size_t I = 0; I != NumElems; ++I) {
3990 if (!this->emitConstUint64(I, E))
3992 if (!this->emitArrayElemPtrUint64(E))
3994 if (!initArrayDimension(ElemTy))
3997 return this->emitPopPtr(E);
4000 return initArrayDimension(E->
getType());
4006template <
class Emitter>
4016 assert(Val.
isInt());
4018 return this->emitConst(I, E);
4025 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4026 return this->
visit(LValueExpr);
4041 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4045 const APValue &
V = UGCD->getValue();
4046 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4047 const Record::Field *F = R->getField(I);
4048 const APValue &FieldValue =
V.getStructField(I);
4052 if (!this->emitInitField(*F->T, F->Offset, E))
4060template <
class Emitter>
4066 for (
unsigned I = 0; I != N; ++I) {
4073 if (!this->
discard(ArrayIndexExpr))
4079 if (!this->
visit(ArrayIndexExpr))
4081 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4085 if (!this->
visit(ArrayIndexExpr))
4089 if (!this->emitCast(IndexT,
PT_Sint64, E))
4099 return this->emitOffsetOf(
T, E, E);
4102template <
class Emitter>
4111 return this->visitZeroInitializer(*
T, Ty, E);
4118 if (!this->emitGetPtrLocal(*LocalIndex, E))
4126 ElemQT = CT->getElementType();
4129 NumElems = VT->getNumElements();
4130 ElemQT = VT->getElementType();
4136 for (
unsigned I = 0; I != NumElems; ++I) {
4137 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4139 if (!this->emitInitElem(ElemT, I, E))
4148template <
class Emitter>
4153template <
class Emitter>
4159template <
class Emitter>
4164template <
class Emitter>
4169 return this->emitConst(E->
getValue(), E);
4172template <
class Emitter>
4177 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4192 unsigned ParamIndex = 0;
4196 if (!this->emitGetParam(PT, ParamIndex, E))
4201 return this->emitCall(F, 0, E);
4206template <
class Emitter>
4214 const Expr *PlacementDest =
nullptr;
4215 bool IsNoThrow =
false;
4220 if (PlacementArgs != 0) {
4229 if (PlacementArgs == 1) {
4237 if (!this->emitInvalidNewDeleteExpr(E, E))
4242 if (OperatorNew->isReservedGlobalPlacementOperator())
4243 PlacementDest = Arg1;
4247 return this->emitInvalid(E);
4249 }
else if (!OperatorNew
4250 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4251 return this->emitInvalidNewDeleteExpr(E, E);
4254 if (!PlacementDest) {
4259 Desc =
P.createDescriptor(E, *ElemT);
4261 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4268 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4272 const Expr *Stripped = *ArraySizeExpr;
4273 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4274 Stripped = ICE->getSubExpr())
4275 if (ICE->getCastKind() != CK_NoOp &&
4276 ICE->getCastKind() != CK_IntegralCast)
4284 if (!this->
visit(Stripped))
4286 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4289 if (PlacementDest) {
4290 if (!this->
visit(PlacementDest))
4292 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4294 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4297 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4302 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4306 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4313 size_t StaticInitElems = 0;
4314 const Expr *DynamicInit =
nullptr;
4318 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4319 StaticInitElems = CAT->getZExtSize();
4324 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4325 if (ILE->hasArrayFiller())
4326 DynamicInit = ILE->getArrayFiller();
4345 const Function *CtorFunc =
nullptr;
4346 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4350 }
else if (!DynamicInit && !ElemT)
4353 LabelTy EndLabel = this->getLabel();
4354 LabelTy StartLabel = this->getLabel();
4359 if (!this->emitDupPtr(E))
4361 if (!this->emitIsNonNullPtr(E))
4363 if (!this->jumpFalse(EndLabel, E))
4370 if (!this->emitConst(StaticInitElems,
SizeT, E))
4372 if (!this->emitSetLocal(
SizeT, Iter, E))
4375 this->fallthrough(StartLabel);
4376 this->emitLabel(StartLabel);
4378 if (!this->emitGetLocal(
SizeT, Iter, E))
4380 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4382 if (!this->emitLT(
SizeT, E))
4384 if (!this->jumpFalse(EndLabel, E))
4388 if (!this->emitGetLocal(
SizeT, Iter, E))
4390 if (!this->emitArrayElemPtr(
SizeT, E))
4393 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4398 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4400 if (!this->emitStorePop(*InitT, E))
4404 if (!this->visitZeroArrayInitializer(ElemType, E))
4407 }
else if (DynamicInit) {
4409 if (!this->
visit(DynamicInit))
4411 if (!this->emitStorePop(*InitT, E))
4418 if (!this->visitZeroInitializer(
4422 if (!this->emitStorePop(*ElemT, E))
4426 if (!this->emitCall(CtorFunc, 0, E))
4431 if (!this->emitGetPtrLocal(Iter, E))
4433 if (!this->emitIncPop(
SizeT,
false, E))
4436 if (!this->jump(StartLabel, E))
4439 this->fallthrough(EndLabel);
4440 this->emitLabel(EndLabel);
4444 if (PlacementDest) {
4445 if (!this->
visit(PlacementDest))
4447 if (!this->emitCheckNewTypeMismatch(E, E))
4452 if (!this->emitAlloc(Desc, E))
4461 if (!this->emitInit(*ElemT, E))
4472 return this->emitPopPtr(E);
4477template <
class Emitter>
4483 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4484 return this->emitInvalidNewDeleteExpr(E, E);
4493template <
class Emitter>
4499 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4504 return this->emitGetFnPtr(
Func, E);
4507template <
class Emitter>
4511 auto canonType = [](
const Type *
T) {
4512 return T->getCanonicalTypeUnqualified().getTypePtr();
4520 return this->emitGetTypeid(
4524 return this->emitGetTypeid(
4533 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4539 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4542 return this->emitPopPtr(E);
4546template <
class Emitter>
4550 return this->emitDummyPtr(E, E);
4551 return this->emitError(E);
4554template <
class Emitter>
4557 return this->emitDummyPtr(E, E);
4558 return this->emitError(E);
4561template <
class Emitter>
4563 assert(
Ctx.getLangOpts().CPlusPlus);
4564 return this->emitConstBool(E->
getValue(), E);
4567template <
class Emitter>
4579 return this->emitDummyPtr(GuidDecl, E);
4584 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4593 assert(
V.isStruct());
4594 assert(
V.getStructNumBases() == 0);
4598 return this->emitFinishInit(E);
4601template <
class Emitter>
4611template <
class Emitter>
4620template <
class Emitter>
4626template <
class Emitter>
4630 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4634 if (OVE->isUnique())
4650template <
class Emitter>
4655template <
class Emitter>
4657 return this->emitError(E);
4660template <
class Emitter>
4666 return this->emitDummyPtr(E, E);
4669template <
class Emitter>
4670bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4675 QualType ElemType = VT->getElementType();
4676 PrimType ElemT = classifyPrim(ElemType);
4678 PrimType SrcElemT = classifyVectorElementType(SrcType);
4684 if (!this->emitGetPtrLocal(*LocalIndex, E))
4688 unsigned SrcOffset =
4689 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4690 if (!this->visit(Src))
4692 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4695 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4696 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4698 if (!this->emitArrayElemPop(SrcElemT, I, E))
4702 if (SrcElemT != ElemT) {
4703 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4705 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4706 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4710 if (!this->emitInitElem(ElemT, I, E))
4716template <
class Emitter>
4718 return emitVectorConversion(E->
getSrcExpr(), E);
4721template <
class Emitter>
4725 return this->emitInvalid(E);
4734 assert(NumOutputElems > 0);
4740 if (!this->emitGetPtrLocal(*LocalIndex, E))
4745 unsigned VectorOffsets[2];
4746 for (
unsigned I = 0; I != 2; ++I) {
4749 if (!this->
visit(Vecs[I]))
4751 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4754 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4756 assert(ShuffleIndex >= -1);
4757 if (ShuffleIndex == -1)
4758 return this->emitInvalidShuffleVectorIndex(I, E);
4760 assert(ShuffleIndex < (NumInputElems * 2));
4761 if (!this->emitGetLocal(
PT_Ptr,
4762 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4764 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4765 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4768 if (!this->emitInitElem(ElemT, I, E))
4773 return this->emitPopPtr(E);
4778template <
class Emitter>
4783 Base->getType()->isVectorType() ||
4789 if (Indices.size() == 1) {
4794 if (!this->emitConstUint32(Indices[0], E))
4796 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4806 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4814 if (!this->emitGetPtrLocal(*ResultIndex, E))
4822 uint32_t DstIndex = 0;
4823 for (uint32_t I : Indices) {
4824 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4826 if (!this->emitArrayElemPop(ElemT, I, E))
4828 if (!this->emitInitElem(ElemT, DstIndex, E))
4838template <
class Emitter>
4842 return this->
discard(SubExpr) && this->emitInvalid(E);
4848 return this->emitDummyPtr(E, E);
4851template <
class Emitter>
4856 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4861 if (!this->
visit(SubExpr))
4863 if (!this->emitConstUint8(0, E))
4865 if (!this->emitArrayElemPtrPopUint8(E))
4867 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4870 PrimType SecondFieldT = *R->getField(1u)->T;
4872 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4874 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4876 assert(SecondFieldT ==
PT_Ptr);
4878 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4880 if (!this->emitExpandPtr(E))
4884 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4886 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4889template <
class Emitter>
4904 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4908 return this->emitUnsupported(E);
4917 return this->
Visit(E);
4924 return this->
Visit(E);
4928 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4931 if (
const auto *CE = dyn_cast<CastExpr>(E);
4933 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4940 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4943 if (
const auto *CE = dyn_cast<CastExpr>(E);
4944 CE && (CE->getCastKind() == CK_DerivedToBase ||
4945 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4946 CE->getCastKind() == CK_NoOp))
4966 if (!this->emitGetPtrLocal(*LocalIndex, E))
4976 return this->
Visit(E);
4979template <
class Emitter>
4985 return this->
Visit(E) && this->emitFinishInit(E);
4988template <
class Emitter>
4994 return this->
Visit(E) && this->emitFinishInitPop(E);
5000 return this->
Visit(E);
5011 if (!this->
visit(E))
5013 return this->emitComplexBoolCast(E);
5018 if (!this->
visit(E))
5026 return this->emitIsNonNullPtr(E);
5030 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5033 return this->emitCast(*
T,
PT_Bool, E);
5036template <
class Emitter>
5040 QT = AT->getValueType();
5044 return this->emitZeroBool(E);
5046 return this->emitZeroSint8(E);
5048 return this->emitZeroUint8(E);
5050 return this->emitZeroSint16(E);
5052 return this->emitZeroUint16(E);
5054 return this->emitZeroSint32(E);
5056 return this->emitZeroUint32(E);
5058 return this->emitZeroSint64(E);
5060 return this->emitZeroUint64(E);
5062 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5064 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5066 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5069 return this->emitNullMemberPtr(0,
nullptr, E);
5071 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5072 return this->emitFloat(F, E);
5075 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5079 llvm_unreachable(
"unknown primitive type");
5082template <
class Emitter>
5083bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5085 bool IsCompleteClass) {
5089 for (
const Record::Field &Field :
R->fields()) {
5090 if (Field.isUnnamedBitField())
5097 if (!this->visitZeroInitializer(
T, QT, E))
5100 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5104 if (!this->emitInitField(
T, Field.Offset, E))
5109 if (!this->emitGetPtrField(Field.Offset, E))
5116 if (!this->visitZeroInitializer(
T, ET, E))
5118 if (!this->emitInitElem(
T, I, E))
5123 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5126 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5134 if (!this->emitFinishInitActivatePop(E))
5138 if (!this->emitFinishInitPop(E))
5142 for (
const Record::Base &B :
R->bases()) {
5143 if (!this->emitGetPtrBase(B.Offset, E))
5145 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5147 if (!this->emitFinishInitPop(E))
5151 if (IsCompleteClass) {
5152 for (
const Record::Base &B :
R->virtual_bases()) {
5155 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5157 if (!this->emitFinishInitPop(E))
5165template <
class Emitter>
5166bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5167 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5168 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5173 for (
size_t I = 0; I != NumElems; ++I) {
5174 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5176 if (!this->emitInitElem(*ElemT, I, E))
5182 const Record *
R = getRecord(ElemType);
5186 for (
size_t I = 0; I != NumElems; ++I) {
5187 if (!this->emitConstUint32(I, E))
5189 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5191 if (!this->visitZeroRecordInitializer(R, E))
5193 if (!this->emitPopPtr(E))
5199 for (
size_t I = 0; I != NumElems; ++I) {
5200 if (!this->emitConstUint32(I, E))
5202 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5204 if (!this->visitZeroArrayInitializer(ElemType, E))
5206 if (!this->emitPopPtr(E))
5215template <
class Emitter>
5216bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5218 if (!canClassify(E->
getType()))
5223 if (!this->visit(LHS))
5225 if (!this->visit(RHS))
5228 if (!this->visit(RHS))
5230 if (!this->visit(LHS))
5238 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5242 bool Activates = refersToUnion(LHS);
5245 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5248 if (DiscardResult) {
5249 if (BitField && Activates)
5250 return this->emitStoreBitFieldActivatePop(RHT, E);
5252 return this->emitStoreBitFieldPop(RHT, E);
5254 return this->emitStoreActivatePop(RHT, E);
5256 return this->emitStorePop(RHT, E);
5259 auto maybeLoad = [&](
bool Result) ->
bool {
5265 return this->emitLoadPop(RHT, E);
5269 if (BitField && Activates)
5270 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5272 return maybeLoad(this->emitStoreBitField(RHT, E));
5274 return maybeLoad(this->emitStoreActivate(RHT, E));
5276 return maybeLoad(this->emitStore(RHT, E));
5279template <
class Emitter>
5280template <
typename T>
5284 return this->emitConstSint8(
Value, Info);
5286 return this->emitConstUint8(
Value, Info);
5288 return this->emitConstSint16(
Value, Info);
5290 return this->emitConstUint16(
Value, Info);
5292 return this->emitConstSint32(
Value, Info);
5294 return this->emitConstUint32(
Value, Info);
5296 return this->emitConstSint64(
Value, Info);
5298 return this->emitConstUint64(
Value, Info);
5300 return this->emitConstBool(
Value, Info);
5307 llvm_unreachable(
"Invalid integral type");
5310 llvm_unreachable(
"unknown primitive type");
5313template <
class Emitter>
5314template <
typename T>
5315bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5316 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5319template <
class Emitter>
5323 return this->emitConstIntAPS(
Value, Info);
5325 return this->emitConstIntAP(
Value, Info);
5327 if (
Value.isSigned())
5328 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5329 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5332template <
class Emitter>
5336 return this->emitConstIntAPS(
Value, Info);
5338 return this->emitConstIntAP(
Value, Info);
5341 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5342 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5345template <
class Emitter>
5346bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5347 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5350template <
class Emitter>
5365 return Local.Offset;
5368template <
class Emitter>
5373 bool IsTemporary =
false;
5377 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5378 Init = VarD->getInit();
5380 if (
const auto *E = Src.
asExpr()) {
5390 return std::nullopt;
5397 return Local.Offset;
5400template <
class Emitter>
5409 return std::nullopt;
5419 return Local.Offset;
5422template <
class Emitter>
5424 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5425 return PT->getPointeeType()->getAsCanonical<RecordType>();
5431 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5435template <
class Emitter>
5437 return P.getOrCreateRecord(RD);
5440template <
class Emitter>
5442 return Ctx.getOrCreateFunction(FD);
5445template <
class Emitter>
5449 auto maybeDestroyLocals = [&]() ->
bool {
5450 if (DestroyToplevelScope)
5451 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5452 return this->emitCheckAllocations(E);
5459 return this->emitRetVoid(E) && maybeDestroyLocals();
5467 return this->emitRet(*
T, E) && maybeDestroyLocals();
5475 if (!this->emitGetPtrLocal(*LocalOffset, E))
5483 return this->emitRetValue(E) && maybeDestroyLocals();
5486 return maybeDestroyLocals() &&
false;
5489template <
class Emitter>
5491 bool DestroyToplevelScope) {
5495 return this->
visitExpr(E, DestroyToplevelScope);
5498template <
class Emitter>
5510 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5511 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5525template <
class Emitter>
5527 bool ConstantContext) {
5530 if (!ConstantContext) {
5545 auto GlobalIndex =
P.getGlobal(VD);
5546 assert(GlobalIndex);
5548 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5551 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5559 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5561 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5564 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5574 auto GlobalIndex =
P.getGlobal(VD);
5575 assert(GlobalIndex);
5576 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5585 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5588template <
class Emitter>
5599 if (!this->isActive())
5604 if (
Init &&
Init->isValueDependent())
5608 auto checkDecl = [&]() ->
bool {
5610 return !NeedsOp || this->emitCheckDecl(VD, VD);
5617 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5620 if (
P.isGlobalInitialized(*GlobalIndex))
5624 }
else if ((GlobalIndex =
5639 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5642 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5645 if (!this->emitStartInit(
Init))
5651 if (!this->emitEndInit(
Init))
5654 return this->emitFinishInitGlobal(
Init);
5664 if (!
Init ||
Init->getType()->isVoidType())
5673 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5685 if (!this->emitCheckRefInit(
Init))
5689 return this->emitSetLocal(*VarT, Offset, VD);
5697 if (!this->emitGetPtrLocal(*Offset,
Init))
5705template <
class Emitter>
5728 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5734 return this->emitDestructionPop(D, VD);
5743 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5767template <
class Emitter>
5782 unsigned ParamIndex = 0;
5789 const Expr *Arg = Args[ParamIndex];
5790 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5792 unsigned ArgOffset =
5794 if (!this->
visit(Arg))
5796 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5802 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5814 if (
This->getType()->isPointerType()) {
5817 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5824 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5846template <
class Emitter>
5852 return this->emitConst(Val.
getInt(), ValType, Info);
5854 return this->emitFloat(Val.
getFloat(), Info);
5858 if (!this->emitGetMemberPtr(MemberDecl, Info))
5864 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5870 return this->emitNullMemberPtr(0,
nullptr, Info);
5875 return this->emitNull(ValType, 0,
nullptr, Info);
5880 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5881 return this->
visit(BaseExpr);
5886 QualType EntryType = VD->getType();
5887 for (
auto &Entry : Path) {
5889 uint64_t Index = Entry.getAsArrayIndex();
5892 if (!this->emitConst(Index,
PT_Uint64, Info))
5894 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5896 EntryType = ElemType;
5903 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5904 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5906 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5908 EntryType = FD->getType();
5912 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
5917 if (!this->emitGetPtrVirtBasePop(
Base, Info))
5920 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5932template <
class Emitter>
5935 bool IsCompleteClass) {
5941 if (IsCompleteClass)
5948 const Record::Base *RB = R->getBase(I);
5949 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5951 if (!this->emitGetPtrBase(RB->Offset, Info))
5956 if (!this->emitFinishInitPop(Info))
5964 const Record::Field *RF = R->getField(I);
5965 QualType FieldType = RF->Decl->getType();
5970 if (!this->emitInitField(*PT, RF->Offset, Info))
5973 if (!this->emitGetPtrField(RF->Offset, Info))
5977 if (!this->emitFinishInitPop(Info))
5983 if (IsCompleteClass) {
5988 const Record::Base *RB = R->getVirtualBase(I);
5989 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5997 if (!this->emitFinishInitPop(Info))
6013 const Record::Field *RF = R->getField(UnionField);
6014 QualType FieldType = RF->Decl->getType();
6019 if (RF->isBitField())
6020 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6022 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6025 if (!this->emitGetPtrField(RF->Offset, Info))
6027 if (!this->emitActivate(Info))
6031 return this->emitPopPtr(Info);
6035 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6036 QualType ElemType = ArrType->getElementType();
6039 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6040 const APValue &Elem = A >= InitializedElems
6049 if (!this->emitInitElem(*ElemT, A, Info))
6052 if (!this->emitConstUint32(A, Info))
6054 if (!this->emitArrayElemPtrUint32(Info))
6058 if (!this->emitPopPtr(Info))
6069template <
class Emitter>
6071 unsigned BuiltinID) {
6072 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6077 return this->emitConst(0, E);
6080 if (!this->emitStartSpeculation(E))
6082 LabelTy EndLabel = this->getLabel();
6083 if (!this->speculate(E, EndLabel))
6085 if (!this->emitEndSpeculation(E))
6087 this->fallthrough(EndLabel);
6095 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6096 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6097 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6098 BuiltinID == Builtin::BI__builtin_function_start) {
6101 return this->emitDummyPtr(E, E);
6112 if (!this->emitGetPtrLocal(*LocalIndex, E))
6117 switch (BuiltinID) {
6118 case Builtin::BI__builtin_object_size:
6119 case Builtin::BI__builtin_dynamic_object_size: {
6123 if (!this->
visit(Arg0))
6134 case Builtin::BI__assume:
6135 case Builtin::BI__builtin_assume:
6138 case Builtin::BI__atomic_is_lock_free:
6139 case Builtin::BI__atomic_always_lock_free: {
6150 for (
const auto *Arg : E->
arguments()) {
6151 if (!this->
visit(Arg))
6157 if (!this->emitCallBI(E, BuiltinID, E))
6175template <
class Emitter>
6196 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6197 DD && DD->isTrivial()) {
6199 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6201 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6202 this->emitPopPtr(E);
6208 bool ActivateLHS =
false;
6216 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6217 OCE && OCE->isAssignmentOp()) {
6218 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6221 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6222 if (!this->
visit(MCE->getImplicitObjectArgument()))
6229 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6247 if (!this->emitGetPtrLocal(*LocalIndex, E))
6255 if (!this->emitGetPtrLocal(*LocalIndex, E))
6259 if (!this->emitDupPtr(E))
6264 const Expr *ReversedArgs[2];
6265 bool IsAssignmentOperatorCall =
false;
6266 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6267 OCE && OCE->isAssignmentOp()) {
6271 assert(Args.size() == 2);
6272 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6274 IsAssignmentOperatorCall =
true;
6275 ReversedArgs[0] = Args[1];
6276 ReversedArgs[1] = Args[0];
6277 Args = ReversedArgs;
6284 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6285 MD && MD->isStatic()) {
6289 Args = Args.drop_front();
6293 bool Devirtualized =
false;
6296 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6304 if (!this->
visit(Callee))
6306 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6308 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6310 if (!this->emitGetMemberPtrBase(E))
6313 const auto *InstancePtr = MC->getImplicitObjectArgument();
6320 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6321 Devirtualized =
true;
6322 if (!this->
visit(Stripped))
6325 if (!this->
visit(InstancePtr))
6329 if (!this->
visit(InstancePtr))
6333 }
else if (
const auto *PD =
6334 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6335 if (!this->emitCheckPseudoDtor(E))
6343 return this->emitPseudoDtor(E);
6344 }
else if (!FuncDecl) {
6348 if (!this->
visit(Callee))
6350 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6359 if (IsAssignmentOperatorCall) {
6360 assert(Args.size() == 2);
6363 if (!this->emitFlip(Arg2T, Arg1T, E))
6377 assert(HasRVO ==
Func->hasRVO());
6379 bool HasQualifier =
false;
6380 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6381 HasQualifier = ME->hasQualifier();
6383 bool IsVirtual =
false;
6384 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6385 IsVirtual = !Devirtualized && MD->isVirtual();
6390 if (IsVirtual && !HasQualifier) {
6391 uint32_t VarArgSize = 0;
6392 unsigned NumParams =
6393 Func->getNumWrittenParams() +
6395 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6398 if (!this->emitCallVirt(
Func, VarArgSize, E))
6400 }
else if (
Func->isVariadic()) {
6401 uint32_t VarArgSize = 0;
6402 unsigned NumParams =
6403 Func->getNumWrittenParams() +
6405 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6407 if (!this->emitCallVar(
Func, VarArgSize, E))
6410 if (!this->emitCall(
Func, 0, E))
6419 uint32_t ArgSize = 0;
6420 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6426 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6428 if (!this->emitGetMemberPtrDecl(E))
6431 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6434 if (!this->emitCallPtr(ArgSize, E, E))
6445template <
class Emitter>
6452template <
class Emitter>
6459template <
class Emitter>
6464 return this->emitConstBool(E->
getValue(), E);
6467template <
class Emitter>
6473 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6474 return this->emitNullPtr(Val,
nullptr, E);
6477template <
class Emitter>
6485 return this->emitZero(
T, E);
6488template <
class Emitter>
6493 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6494 if (this->LambdaThisCapture.Offset > 0) {
6495 if (this->LambdaThisCapture.IsPtr)
6496 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6497 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6506 return this->emitThis(E);
6521 unsigned StartIndex = 0;
6522 unsigned EndIndex = 0;
6524 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6526 EndIndex = StartIndex;
6533 for (; StartIndex > 0; --StartIndex) {
6544 if (StartIndex == 0 && EndIndex == 0)
6555 assert(StartIndex <= EndIndex);
6558 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6570 case Stmt::CompoundStmtClass:
6572 case Stmt::DeclStmtClass:
6574 case Stmt::ReturnStmtClass:
6576 case Stmt::IfStmtClass:
6578 case Stmt::WhileStmtClass:
6580 case Stmt::DoStmtClass:
6582 case Stmt::ForStmtClass:
6584 case Stmt::CXXForRangeStmtClass:
6586 case Stmt::BreakStmtClass:
6588 case Stmt::ContinueStmtClass:
6590 case Stmt::SwitchStmtClass:
6592 case Stmt::CaseStmtClass:
6594 case Stmt::DefaultStmtClass:
6596 case Stmt::AttributedStmtClass:
6598 case Stmt::CXXTryStmtClass:
6600 case Stmt::NullStmtClass:
6603 case Stmt::GCCAsmStmtClass:
6604 case Stmt::MSAsmStmtClass:
6605 case Stmt::GotoStmtClass:
6606 return this->emitInvalid(S);
6607 case Stmt::LabelStmtClass:
6609 case Stmt::CXXExpansionStmtInstantiationClass:
6613 if (
const auto *E = dyn_cast<Expr>(S))
6620template <
class Emitter>
6623 for (
const auto *InnerStmt : S->
body())
6626 return Scope.destroyLocals();
6629template <
class Emitter>
6630bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6631 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6632 for (
auto *BD : DD->flat_bindings())
6633 if (
auto *KD = BD->getHoldingVar();
6634 KD && !this->visitVarDecl(KD, KD->getInit()))
6648template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6650 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6651 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6658 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6663 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6664 ICE && (ICE->getCastKind() == CK_NoOp ||
6665 ICE->getCastKind() == CK_DerivedToBase ||
6666 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6667 E = ICE->getSubExpr();
6671 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6672 const auto *ThisRecord =
6673 This->getType()->getPointeeType()->getAsRecordDecl();
6674 if (!ThisRecord->isUnion())
6677 if (
const auto *Ctor =
6678 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6679 return Ctor->getParent() == ThisRecord;
6688template <
class Emitter>
6690 bool EvaluateConditionDecl) {
6691 for (
const auto *D : DS->
decls()) {
6696 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6697 assert(ESD->getInstantiations() &&
"not expanded?");
6698 if (!this->
visitStmt(ESD->getInstantiations()))
6703 const auto *VD = dyn_cast<VarDecl>(D);
6710 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6717template <
class Emitter>
6720 return this->emitUnsupported(RS);
6726 if (!this->
visit(RE))
6732 if (RE->getType()->isVoidType()) {
6733 if (!this->
visit(RE))
6736 if (RE->containsErrors())
6741 if (!this->emitRVOPtr(RE))
6747 return this->emitRetVoid(RS);
6753 return this->emitRetVoid(RS);
6759 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6766 if (
auto *CondInit = IS->
getInit()) {
6782 return visitChildStmt(IS->
getThen());
6784 return visitChildStmt(Else);
6790 if (!this->emitIsConstantContext(IS))
6793 if (!this->emitIsConstantContext(IS))
6795 if (!this->emitInv(IS))
6809 LabelTy LabelElse = this->getLabel();
6810 LabelTy LabelEnd = this->getLabel();
6811 if (!this->jumpFalse(LabelElse, IS))
6813 if (!visitChildStmt(IS->
getThen()))
6815 if (!this->jump(LabelEnd, IS))
6817 this->emitLabel(LabelElse);
6818 if (!visitChildStmt(Else))
6820 this->emitLabel(LabelEnd);
6822 LabelTy LabelEnd = this->getLabel();
6823 if (!this->jumpFalse(LabelEnd, IS))
6825 if (!visitChildStmt(IS->
getThen()))
6827 this->emitLabel(LabelEnd);
6836template <
class Emitter>
6841 LabelTy CondLabel = this->getLabel();
6842 LabelTy EndLabel = this->getLabel();
6846 this->fallthrough(CondLabel);
6847 this->emitLabel(CondLabel);
6863 if (!this->jumpFalse(EndLabel, S))
6873 if (!this->jump(CondLabel, S))
6875 this->fallthrough(EndLabel);
6876 this->emitLabel(EndLabel);
6885 LabelTy StartLabel = this->getLabel();
6886 LabelTy EndLabel = this->getLabel();
6887 LabelTy CondLabel = this->getLabel();
6891 this->fallthrough(StartLabel);
6892 this->emitLabel(StartLabel);
6898 this->fallthrough(CondLabel);
6899 this->emitLabel(CondLabel);
6906 if (!this->jumpTrue(StartLabel, S))
6909 this->fallthrough(EndLabel);
6910 this->emitLabel(EndLabel);
6914template <
class Emitter>
6922 LabelTy EndLabel = this->getLabel();
6923 LabelTy CondLabel = this->getLabel();
6924 LabelTy IncLabel = this->getLabel();
6931 this->fallthrough(CondLabel);
6932 this->emitLabel(CondLabel);
6944 if (!this->jumpFalse(EndLabel, S))
6953 this->fallthrough(IncLabel);
6954 this->emitLabel(IncLabel);
6960 if (!this->jump(CondLabel, S))
6964 this->emitLabel(EndLabel);
6970template <
class Emitter>
6980 LabelTy EndLabel = this->getLabel();
6981 LabelTy CondLabel = this->getLabel();
6982 LabelTy IncLabel = this->getLabel();
6998 this->fallthrough(CondLabel);
6999 this->emitLabel(CondLabel);
7002 if (!this->jumpFalse(EndLabel, S))
7013 this->fallthrough(IncLabel);
7014 this->emitLabel(IncLabel);
7021 if (!this->jump(CondLabel, S))
7024 this->fallthrough(EndLabel);
7025 this->emitLabel(EndLabel);
7029template <
class Emitter>
7040 if (LI.BreakLabel) {
7041 TargetLabel = *LI.BreakLabel;
7042 BreakScope = LI.BreakOrContinueScope;
7048 if (LI.Name == TargetLoop) {
7049 TargetLabel = *LI.BreakLabel;
7050 BreakScope = LI.BreakOrContinueScope;
7061 C =
C->getParent()) {
7062 if (!
C->destroyLocals())
7066 return this->jump(*TargetLabel, S);
7069template <
class Emitter>
7080 if (LI.ContinueLabel) {
7081 TargetLabel = *LI.ContinueLabel;
7082 ContinueScope = LI.BreakOrContinueScope;
7088 if (LI.Name == TargetLoop) {
7089 TargetLabel = *LI.ContinueLabel;
7090 ContinueScope = LI.BreakOrContinueScope;
7100 C =
C->getParent()) {
7101 if (!
C->destroyLocals())
7105 return this->jump(*TargetLabel, S);
7108template <
class Emitter>
7118 LabelTy EndLabel = this->getLabel();
7123 if (
const auto *CondInit = S->
getInit())
7132 if (!this->
visit(Cond))
7134 if (!this->emitSetLocal(CondT, CondVar, S))
7144 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7147 if (CS->caseStmtIsGNURange()) {
7148 LabelTy EndOfRangeCheck = this->getLabel();
7149 const Expr *Low = CS->getLHS();
7150 const Expr *High = CS->getRHS();
7154 if (!this->emitGetLocal(CondT, CondVar, CS))
7156 if (!this->
visit(Low))
7159 if (!this->emitGE(
LT, S))
7161 if (!this->jumpFalse(EndOfRangeCheck, S))
7164 if (!this->emitGetLocal(CondT, CondVar, CS))
7166 if (!this->
visit(High))
7169 if (!this->emitLE(HT, S))
7173 this->emitLabel(EndOfRangeCheck);
7178 if (
Value->isValueDependent())
7183 if (!this->emitGetLocal(CondT, CondVar, CS))
7189 if (!this->emitEQ(ValueT, S))
7194 assert(!DefaultLabel);
7195 DefaultLabel = this->getLabel();
7202 if (!this->jump(*DefaultLabel, S))
7205 if (!this->jump(EndLabel, S))
7213 this->fallthrough(EndLabel);
7214 this->emitLabel(EndLabel);
7219template <
class Emitter>
7227 return this->emitUnsupported(S);
7232template <
class Emitter>
7239 if (LI.DefaultLabel) {
7240 DefaultLabel = *LI.DefaultLabel;
7245 this->emitLabel(DefaultLabel);
7249template <
class Emitter>
7256 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7259 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7260 !this->Ctx.getLangOpts().MSVCCompat) {
7262 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7268 const Expr *Assumption = AA->getAssumption();
7279 if (!this->emitAssume(Assumption))
7288 if (IsMSVCConstexprAttr)
7289 return this->emitPopMSVCCE(S);
7293template <
class Emitter>
7306template <
class Emitter>
7316 LabelTy EndLabel = this->getLabel();
7318 LabelTy ContinueLabel = this->getLabel();
7323 this->emitLabel(ContinueLabel);
7326 this->emitLabel(EndLabel);
7331template <
class Emitter>
7332bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7339 assert(ClosureClass->
captures().empty());
7343 "A generic lambda's static-invoker function must be a "
7344 "template specialization");
7348 llvm::FoldingSetInsertToken InsertToken;
7349 const FunctionDecl *CorrespondingCallOpSpecialization =
7351 assert(CorrespondingCallOpSpecialization);
7352 LambdaCallOp = CorrespondingCallOpSpecialization;
7356 assert(ClosureClass->
captures().empty());
7357 const Function *
Func = this->getFunction(LambdaCallOp);
7360 assert(
Func->hasThisPointer());
7363 if (
Func->hasRVO()) {
7364 if (!this->emitRVOPtr(MD))
7372 if (!this->emitNullPtr(0,
nullptr, MD))
7377 auto It = this->Params.find(PVD);
7378 assert(It != this->Params.end());
7382 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7383 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7387 if (!this->emitCall(
Func, 0, LambdaCallOp))
7392 return this->emitRet(*ReturnType, MD);
7395 return this->emitRetVoid(MD);
7398template <
class Emitter>
7399bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7400 if (Ctx.getLangOpts().CPlusPlus23)
7410 const Expr *InitExpr =
Init->getInit();
7412 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7416 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7426template <
class Emitter>
7428 assert(!ReturnType);
7431 if (!this->emitStartThisLifetime1(Ctor))
7434 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7435 const Expr *InitExpr,
7438 if (InitExpr->getType().isNull())
7442 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7445 if (!this->visit(InitExpr))
7448 if (F->isBitField())
7449 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7451 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7456 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7459 if (
Activate && !this->emitActivate(InitExpr))
7462 return this->visitInitializerPop(InitExpr);
7466 const Record *
R = this->getRecord(RD);
7469 bool IsUnion =
R->isUnion();
7479 if (!this->emitThis(Ctor))
7482 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7485 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7486 this->emitRetVoid(Ctor);
7489 unsigned FieldInits = 0;
7492 if (
R->getNumVirtualBases() > 0) {
7493 if (!this->emitThis(Ctor))
7495 LabelTy AfterVirtBasesLabel = this->getLabel();
7498 if (!this->emitIsBaseClass({}))
7500 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7503 for (
const auto *
Init : Ctor->
inits()) {
7506 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7508 assert(
R->findVirtualBase(BaseDecl));
7509 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7511 if (!this->visitInitializerPop(
Init->getInit()))
7516 this->fallthrough(AfterVirtBasesLabel);
7517 this->emitLabel(AfterVirtBasesLabel);
7519 if (!this->emitPopPtr(Ctor))
7523 for (
const auto *
Init : Ctor->
inits()) {
7527 const Expr *InitExpr =
Init->getInit();
7529 const Record::Field *F =
R->getField(
Member);
7533 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7537 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7540 if (
Init->isBaseVirtual()) {
7546 const Record::Base *B =
R->getBase(BaseDecl);
7548 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7552 if (!this->visitInitializerPop(InitExpr))
7557 unsigned ChainSize = IFD->getChainingSize();
7558 assert(ChainSize >= 2);
7560 unsigned NestedFieldOffset = 0;
7561 const Record::Field *NestedField =
nullptr;
7562 for (
unsigned I = 0; I != ChainSize; ++I) {
7564 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7565 assert(FieldRecord);
7567 NestedField = FieldRecord->
getField(FD);
7568 assert(NestedField);
7569 IsUnion = IsUnion || FieldRecord->
isUnion();
7571 NestedFieldOffset += NestedField->Offset;
7574 if (I != ChainSize - 1)
7577 assert(NestedField);
7580 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7585 unsigned InitFieldOffset = 0;
7586 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7588 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7589 assert(FieldRecord);
7590 NestedField = FieldRecord->
getField(FD);
7591 InitFieldOffset += NestedField->Offset;
7592 assert(NestedField);
7593 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7595 if (!this->emitFinishInitPop(InitExpr))
7599 InitStack.pop_back_n(ChainSize - 1);
7602 assert(
Init->isDelegatingInitializer());
7603 if (!this->emitThis(InitExpr))
7605 if (!this->visitInitializerPop(
Init->getInit()))
7609 if (!
Scope.destroyLocals())
7613 if (FieldInits !=
R->getNumFields()) {
7614 assert(FieldInits < R->getNumFields());
7616 if (!this->emitStartThisLifetime(Ctor))
7623 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7624 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7631 if (!visitStmt(Body))
7638template <
class Emitter>
7641 const Record *
R = this->getRecord(RD);
7645 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7646 if (!this->visitStmt(
Dtor->getBody()))
7650 if (!this->emitThis(
Dtor))
7653 if (!this->emitCheckDestruction(
Dtor))
7657 if (!
R->isUnion()) {
7661 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7665 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7667 if (!this->emitDestructionPop(D,
SourceInfo{}))
7672 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7673 if (
Base.R->hasTrivialDtor())
7677 if (!this->emitRecordDestructionPop(
Base.R, {}))
7681 if (
R->getNumVirtualBases() > 0) {
7682 LabelTy EndLabel = this->getLabel();
7684 if (!this->emitIsBaseClass({}))
7686 if (!this->jumpTrue(EndLabel, {}))
7689 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7690 if (
Base.R->hasTrivialDtor())
7695 if (!this->emitRecordDestructionPop(
Base.R, {}))
7699 this->fallthrough(EndLabel);
7700 this->emitLabel(EndLabel);
7703 if (!this->emitMarkDestroyed(
Dtor))
7706 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7709template <
class Emitter>
7710bool Compiler<Emitter>::compileUnionAssignmentOperator(
7712 if (!this->emitThis(MD))
7715 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7718 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7721template <
class Emitter>
7731 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7732 return this->compileConstructor(Ctor);
7733 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7734 return this->compileDestructor(
Dtor);
7737 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7742 return this->compileUnionAssignmentOperator(MD);
7745 return this->emitLambdaStaticInvokerBody(MD);
7749 if (
const auto *Body = F->
getBody())
7763 return FD->getBitWidthValue();
7766template <
class Emitter>
7782 if (!
Ctx.getLangOpts().CPlusPlus14)
7783 return this->emitInvalid(E);
7785 return this->emitError(E);
7787 if (!this->
visit(SubExpr))
7791 if (!this->emitIncPtr(E))
7798 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7799 : this->emitIncf(getFPOptions(E), E);
7811 if (!
Ctx.getLangOpts().CPlusPlus14)
7812 return this->emitInvalid(E);
7814 return this->emitError(E);
7816 if (!this->
visit(SubExpr))
7820 if (!this->emitDecPtr(E))
7827 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7828 : this->emitDecf(getFPOptions(E), E);
7841 if (!
Ctx.getLangOpts().CPlusPlus14)
7842 return this->emitInvalid(E);
7844 return this->emitError(E);
7846 if (!this->
visit(SubExpr))
7850 if (!this->emitLoadPtr(E))
7852 if (!this->emitConstUint8(1, E))
7854 if (!this->emitAddOffsetUint8(E))
7856 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7862 return this->emitIncfPop(getFPOptions(E), E);
7872 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7873 if (!this->emitLoadFloat(E))
7875 APFloat F(TargetSemantics, 1);
7876 if (!this->emitFloat(F, E))
7879 if (!this->emitAddf(getFPOptions(E), E))
7881 if (!this->emitStoreFloat(E))
7893 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7896 if (!
Ctx.getLangOpts().CPlusPlus14)
7897 return this->emitInvalid(E);
7899 return this->emitError(E);
7901 if (!this->
visit(SubExpr))
7905 if (!this->emitLoadPtr(E))
7907 if (!this->emitConstUint8(1, E))
7909 if (!this->emitSubOffsetUint8(E))
7911 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7917 return this->emitDecfPop(getFPOptions(E), E);
7927 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7928 if (!this->emitLoadFloat(E))
7930 APFloat F(TargetSemantics, 1);
7931 if (!this->emitFloat(F, E))
7934 if (!this->emitSubf(getFPOptions(E), E))
7936 if (!this->emitStoreFloat(E))
7948 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7952 return this->emitError(E);
7955 return this->
discard(SubExpr);
7960 if (!this->emitInv(E))
7964 return this->emitCast(
PT_Bool, ET, E);
7968 return this->emitError(E);
7970 if (!this->
visit(SubExpr))
7975 return this->emitError(E);
7977 if (!this->
visit(SubExpr))
7993 if (!
Ctx.getLangOpts().CPlusPlus) {
7996 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7997 Deref && Deref->getOpcode() == UO_Deref) {
7999 return this->
discard(Deref->getSubExpr());
8000 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8005 return this->
discard(SubExpr);
8006 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8009 return this->
discard(SubExpr);
8011 if (!this->
visit(SubExpr))
8018 return this->emitNarrowPtr(E);
8023 return this->emitError(E);
8025 if (!this->
visit(SubExpr))
8039 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
8044 assert(
false &&
"Unhandled opcode");
8050template <
class Emitter>
8056 return this->
discard(SubExpr);
8059 auto prepareResult = [=]() ->
bool {
8064 return this->emitGetPtrLocal(*LocalIndex, E);
8071 unsigned SubExprOffset = ~0u;
8072 auto createTemp = [=, &SubExprOffset]() ->
bool {
8075 if (!this->
visit(SubExpr))
8077 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8081 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8082 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8084 return this->emitArrayElemPop(ElemT, Index, E);
8089 if (!prepareResult())
8093 for (
unsigned I = 0; I != 2; ++I) {
8094 if (!getElem(SubExprOffset, I))
8096 if (!this->emitNeg(ElemT, E))
8098 if (!this->emitInitElem(ElemT, I, E))
8109 if (!this->
visit(SubExpr))
8111 if (!this->emitComplexBoolCast(SubExpr))
8113 if (!this->emitInv(E))
8116 return this->emitCast(
PT_Bool, ET, E);
8120 return this->emitComplexReal(SubExpr);
8123 if (!this->
visit(SubExpr))
8127 if (!this->emitConstUint8(1, E))
8129 return this->emitArrayElemPtrPopUint8(E);
8140 if (!this->emitArrayElem(ElemT, 1, E))
8142 if (!this->emitNeg(ElemT, E))
8144 if (!this->emitInitElem(ElemT, 1, E))
8152 return this->emitInvalid(E);
8158template <
class Emitter>
8164 return this->
discard(SubExpr);
8167 if (UnaryOp == UO_Extension)
8170 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8171 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8172 return this->emitInvalid(E);
8175 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8182 if (!this->emitGetPtrLocal(*LocalIndex, E))
8187 unsigned SubExprOffset =
8189 if (!this->
visit(SubExpr))
8191 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8196 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8197 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8199 return this->emitArrayElemPop(ElemT, Index, E);
8204 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8205 if (!getElem(SubExprOffset, I))
8207 if (!this->emitNeg(ElemT, E))
8209 if (!this->emitInitElem(ElemT, I, E))
8224 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8225 if (!getElem(SubExprOffset, I))
8228 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8230 if (!this->emitInv(E))
8232 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8234 if (!this->emitNeg(ElemT, E))
8236 if (ElemT != ResultVecElemT &&
8237 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8239 if (!this->emitInitElem(ResultVecElemT, I, E))
8245 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8246 if (!getElem(SubExprOffset, I))
8249 if (!this->emitInv(E))
8252 if (!this->emitComp(ElemT, E))
8255 if (!this->emitInitElem(ElemT, I, E))
8260 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8265template <
class Emitter>
8267 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8270 return this->emitConst(ECD->getInitVal(), E);
8272 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8276 return F && this->emitGetFnPtr(F, E);
8278 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8279 TPOD = TPOD->getFirstDecl();
8283 return this->emitGetPtrGlobal(*GlobalIndex, E);
8289 return this->emitInitGlobal(*
T, *Index, E);
8292 if (!this->emitGetPtrGlobal(*Index, E))
8296 return this->emitFinishInit(E);
8308 auto maybePopPtr = [&]() ->
bool {
8310 return this->emitPopPtr(E);
8317 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8321 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8326 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8327 if (IsReference || !It->second.IsPtr)
8328 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8330 return this->emitGetPtrParam(It->second.Index, E);
8333 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8340 const unsigned Offset = It->second.Offset;
8343 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8345 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8348 if (
auto GlobalIndex =
P.getGlobal(D)) {
8350 if (!
Ctx.getLangOpts().CPlusPlus11)
8351 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8352 if (!
Ctx.getLangOpts().CPlusPlus23)
8353 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8355 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8358 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8362 auto revisit = [&](
const VarDecl *VD,
8363 bool IsConstexprUnknown =
true) ->
bool {
8365 IsConstexprUnknown);
8366 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8372 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8373 if (!this->emitPopCC(E))
8377 if (VarState.notCreated())
8385 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8387 if (
auto It = this->LambdaCaptures.find(D);
8388 It != this->LambdaCaptures.end()) {
8389 auto [Offset, IsPtr] = It->second;
8392 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8393 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8397 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8398 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8399 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8403 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8404 return this->
delegate(BD->getBinding());
8410 return this->emitDummyPtr(D, E);
8415 const auto *VD = dyn_cast<VarDecl>(D);
8417 return this->emitError(E);
8420 if (!
Ctx.getLangOpts().CPlusPlus) {
8424 return revisit(VD,
false);
8428 return this->emitDummyPtr(D, E);
8432 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8433 if (
T.isConstant(
Ctx.getASTContext()))
8435 return T->isReferenceType();
8439 typeShouldBeVisited(DeclType)) {
8441 Init && !
Init->isValueDependent()) {
8446 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8459 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8464 return revisit(VD, IsConstexprUnknown);
8465 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8466 return revisit(VD,
true);
8475 return this->emitDummyPtr(
8479template <
class Emitter>
8485template <
class Emitter>
8495 if (!
C->destroyLocals())
8501template <
class Emitter>
8502unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8505 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8507 return Ty->getAsCXXRecordDecl();
8509 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8510 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8512 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8516template <
class Emitter>
8523 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8528 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8529 getFPOptions(E), E);
8531 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8532 getFPOptions(E), E);
8536 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8541 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8543 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8547 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8551 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8552 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8559template <
class Emitter>
8562 assert(FromT != ToT);
8565 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8567 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8569 return this->emitCast(FromT, ToT, E);
8573template <
class Emitter>
8574bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8578 return this->
discard(SubExpr);
8580 if (!this->visit(SubExpr))
8583 if (!this->emitConstUint8(0, SubExpr))
8585 return this->emitArrayElemPtrPopUint8(SubExpr);
8589 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8593template <
class Emitter>
8594bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8595 assert(!DiscardResult);
8599 if (!this->emitArrayElem(ElemT, 0, E))
8602 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8605 if (!this->emitCast(ElemT,
PT_Bool, E))
8610 LabelTy LabelTrue = this->getLabel();
8611 if (!this->jumpTrue(LabelTrue, E))
8614 if (!this->emitArrayElemPop(ElemT, 1, E))
8617 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8620 if (!this->emitCast(ElemT,
PT_Bool, E))
8624 LabelTy EndLabel = this->getLabel();
8625 this->jump(EndLabel, E);
8627 this->emitLabel(LabelTrue);
8628 if (!this->emitPopPtr(E))
8630 if (!this->emitConstBool(
true, E))
8633 this->fallthrough(EndLabel);
8634 this->emitLabel(EndLabel);
8639template <
class Emitter>
8640bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8651 LHSIsComplex =
true;
8652 ElemT = classifyComplexElementType(LHS->
getType());
8653 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8654 if (!this->visit(LHS))
8656 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8659 LHSIsComplex =
false;
8661 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8662 if (!this->visit(LHS))
8664 if (!this->emitSetLocal(LHST, LHSOffset, E))
8671 RHSIsComplex =
true;
8672 ElemT = classifyComplexElementType(RHS->
getType());
8673 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8674 if (!this->visit(RHS))
8676 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8679 RHSIsComplex =
false;
8681 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8682 if (!this->visit(RHS))
8684 if (!this->emitSetLocal(RHST, RHSOffset, E))
8688 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8689 bool IsComplex) ->
bool {
8691 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8693 return this->emitArrayElemPop(ElemT, Index, E);
8695 return this->emitGetLocal(ElemT, LocalOffset, E);
8698 for (
unsigned I = 0; I != 2; ++I) {
8700 if (!getElem(LHSOffset, I, LHSIsComplex))
8702 if (!getElem(RHSOffset, I, RHSIsComplex))
8705 if (!this->emitEQ(ElemT, E))
8708 if (!this->emitCastBoolUint8(E))
8713 if (!this->emitAddUint8(E))
8715 if (!this->emitConstUint8(2, E))
8719 if (!this->emitEQUint8(E))
8722 if (!this->emitNEUint8(E))
8729 return this->emitCast(
PT_Bool, ResT, E);
8736template <
class Emitter>
8737bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8740 assert(!
R->hasTrivialDtor());
8743 const Function *DtorFunc = getFunction(
Dtor);
8746 assert(DtorFunc->hasThisPointer());
8747 assert(DtorFunc->getNumParams() == 1);
8748 return this->emitCall(DtorFunc, 0, Loc);
8753template <
class Emitter>
8754bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8766 return this->emitPopPtr(Loc);
8768 for (ssize_t I = N - 1; I >= 1; --I) {
8769 if (!this->emitConstUint64(I, Loc))
8771 if (!this->emitArrayElemPtrUint64(Loc))
8773 if (!this->emitDestructionPop(ElemDesc, Loc))
8777 if (!this->emitConstUint64(0, Loc))
8779 if (!this->emitArrayElemPtrPopUint64(Loc))
8781 return this->emitDestructionPop(ElemDesc, Loc);
8786 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8791template <
class Emitter>
8792bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8793 assert(!DiscardResult &&
"Should've been checked before");
8794 return this->emitGetOpaquePtr(D, CU, E);
8797template <
class Emitter>
8800 return this->emitConstFloat(
Floating(F), Info);
8802 APInt I = F.bitcastToAPInt();
8803 return this->emitConstFloat(
8804 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8805 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8816template <
class Emitter>
8817bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8830 if (!this->emitGetPtrLocal(*LocalIndex, E))
8840 if (!this->visit(SubExpr))
8842 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8843 unsigned TempOffset =
8844 allocateLocalPrimitive(SubExpr, *FromT,
true);
8845 if (!this->visit(SubExpr))
8847 if (!this->emitSetLocal(*FromT, TempOffset, E))
8849 if (!this->emitGetPtrLocal(TempOffset, E))
8856 if (!this->emitBitCast(E))
8858 return DiscardResult ? this->emitPopPtr(E) :
true;
8862 const llvm::fltSemantics *TargetSemantics =
nullptr;
8864 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8870 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8872 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8873 ResultBitWidth, TargetSemantics,
8878 return this->emitPop(*ToT, E);
8887template <
class Emitter>
8888bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8893 unsigned NumElems = 0;
8896 NumElems = VT->getNumElements();
8897 ElemType = VT->getElementType();
8899 NumElems = MT->getNumElementsFlattened();
8900 ElemType = MT->getElementType();
8903 PrimType ElemT = classifyPrim(ElemType);
8904 for (
unsigned I = 0; I != NumElems; ++I) {
8905 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8907 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8909 if (!this->emitInitElem(ElemT, I, E))
8919 QualType ArrElemType = CAT->getElementType();
8920 unsigned ArrSize = CAT->getZExtSize();
8923 for (
unsigned I = 0; I != ArrSize; ++I) {
8924 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8926 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8928 if (!this->emitInitElem(*ElemT, I, E))
8932 for (
unsigned I = 0; I != ArrSize; ++I) {
8933 if (!this->emitConstUint32(I, E))
8935 if (!this->emitArrayElemPtrUint32(E))
8937 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8939 if (!this->emitFinishInitPop(E))
8949 const Record *
R = getRecord(DestType);
8953 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8955 const Record::Base *B =
R->getBase(BS.getType());
8957 if (!this->emitGetPtrBase(B->Offset, E))
8959 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8961 if (!this->emitFinishInitPop(E))
8966 for (
const Record::Field &F :
R->fields()) {
8967 if (F.isUnnamedBitField())
8970 QualType FieldType = F.Decl->getType();
8972 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8974 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8976 if (F.isBitField()) {
8977 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8980 if (!this->emitInitField(*FieldT, F.Offset, E))
8984 if (!this->emitGetPtrField(F.Offset, E))
8986 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8988 if (!this->emitPopPtr(E))
9001template <
class Emitter>
9002unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9005 return VT->getNumElements();
9007 return MT->getNumElementsFlattened();
9011 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9015 const Record *
R = getRecord(Ty);
9019 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9021 Count += countHLSLFlatElements(BS.getType());
9023 for (
const Record::Field &F :
R->fields()) {
9024 if (F.isUnnamedBitField())
9026 Count += countHLSLFlatElements(F.Decl->getType());
9031 if (canClassify(Ty))
9040template <
class Emitter>
9041bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9042 QualType SrcType,
unsigned SrcOffset,
9047 auto saveToLocal = [&](
PrimType T) ->
bool {
9048 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9049 if (!this->emitSetLocal(
T, Offset, E))
9051 Elements.push_back({Offset,
T});
9057 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9058 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9059 return std::nullopt;
9064 unsigned NumElems = 0;
9067 NumElems = VT->getNumElements();
9068 ElemType = VT->getElementType();
9070 NumElems = MT->getNumElementsFlattened();
9071 ElemType = MT->getElementType();
9074 PrimType ElemT = classifyPrim(ElemType);
9075 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9076 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9078 if (!this->emitArrayElemPop(ElemT, I, E))
9080 if (!saveToLocal(ElemT))
9090 QualType ArrElemType = CAT->getElementType();
9091 unsigned ArrSize = CAT->getZExtSize();
9094 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9095 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9097 if (!this->emitArrayElemPop(*ElemT, I, E))
9099 if (!saveToLocal(*ElemT))
9103 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9104 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9106 if (!this->emitConstUint32(I, E))
9108 if (!this->emitArrayElemPtrPopUint32(E))
9113 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9124 const Record *
R = getRecord(SrcType);
9128 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9130 if (Elements.size() >= MaxElements)
9132 const Record::Base *B =
R->getBase(BS.getType());
9134 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9136 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9141 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9147 for (
const Record::Field &F :
R->fields()) {
9148 if (Elements.size() >= MaxElements)
9150 if (F.isUnnamedBitField())
9153 QualType FieldType = F.Decl->getType();
9154 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9156 if (!this->emitGetPtrFieldPop(F.Offset, E))
9160 if (!this->emitLoadPop(*FieldT, E))
9162 if (!saveToLocal(*FieldT))
9166 if (!FieldPtrOffset)
9168 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9184template <
class Emitter>
9185bool Compiler<Emitter>::emitHLSLConstructAggregate(
9191 const auto &Src = Elements[ElemIdx++];
9192 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9194 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9198 unsigned NumElems = 0;
9201 NumElems = VT->getNumElements();
9202 ElemType = VT->getElementType();
9204 NumElems = MT->getNumElementsFlattened();
9205 ElemType = MT->getElementType();
9208 PrimType DestElemT = classifyPrim(ElemType);
9209 for (
unsigned I = 0; I != NumElems; ++I) {
9210 if (!loadAndCast(DestElemT, ElemType))
9212 if (!this->emitInitElem(DestElemT, I, E))
9222 QualType ArrElemType = CAT->getElementType();
9223 unsigned ArrSize = CAT->getZExtSize();
9226 for (
unsigned I = 0; I != ArrSize; ++I) {
9227 if (!loadAndCast(*ElemT, ArrElemType))
9229 if (!this->emitInitElem(*ElemT, I, E))
9233 for (
unsigned I = 0; I != ArrSize; ++I) {
9234 if (!this->emitConstUint32(I, E))
9236 if (!this->emitArrayElemPtrUint32(E))
9238 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9240 if (!this->emitFinishInitPop(E))
9250 const Record *
R = getRecord(DestType);
9254 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9256 const Record::Base *B =
R->getBase(BS.getType());
9258 if (!this->emitGetPtrBase(B->Offset, E))
9260 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9262 if (!this->emitFinishInitPop(E))
9267 for (
const Record::Field &F :
R->fields()) {
9268 if (F.isUnnamedBitField())
9271 QualType FieldType = F.Decl->getType();
9273 if (!loadAndCast(*FieldT, FieldType))
9275 if (F.isBitField()) {
9276 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9279 if (!this->emitInitField(*FieldT, F.Offset, E))
9283 if (!this->emitGetPtrField(F.Offset, E))
9285 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9287 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 bool isTrivialMemoryOperation(const CXXMethodDecl *MD)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
const Expr * ignorePointerCastsAndParens(const Expr *E)
A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. This ignores some c...
bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD)
Determine whether a type would actually be read by an lvalue-to-rvalue conversion.
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
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() 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]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
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.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
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, llvm::FoldingSetInsertToken &InsertToken)
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
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
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...
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
bool isStoredAsComparisonResult() 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.
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
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.
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 visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
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)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
const VarDecl * InitializingDecl
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)
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.
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)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
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)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
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 VarDecl *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 * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * findVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
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)
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)
static bool isSideEffectFree(const Expr *E)
Check if E has side-effects.
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)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ 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
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...
EvalResult is a struct with detailed info about an evaluated expression.
const ValueDecl * asValueDecl() const
const Expr * asExpr() const
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.
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 Base(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()