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();
57 if (NumElems > std::numeric_limits<unsigned>::max())
59 uint64_t Limit = LangOpts.ConstexprStepLimit;
60 return Limit != 0 && NumElems > Limit;
67 : Ctx(Ctx), Local(Local), VarScope(VarScope) {}
90 llvm_unreachable(
"Shouldn't be called");
155 this->
Ctx->emitDestroy(*
Idx, E);
162 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
163 this->
Ctx->Descriptors.emplace_back();
177 if (
Local.Desc->hasTrivialDtor())
180 if (!
Local.EnabledByDefault) {
181 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
182 if (!this->
Ctx->emitGetLocalEnabled(
Local.Offset, E))
184 if (!this->
Ctx->jumpFalse(EndLabel, E))
187 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
190 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
193 this->
Ctx->fallthrough(EndLabel);
194 this->
Ctx->emitLabel(EndLabel);
196 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
198 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
217 if (
const auto *OVE =
218 llvm::dyn_cast_if_present<OpaqueValueExpr>(
Local.Desc->asExpr())) {
219 this->
Ctx->OpaqueExprs.erase(OVE);
231 OldArrayIndex = Ctx->ArrayIndex;
232 Ctx->ArrayIndex = Index;
239 std::optional<uint64_t> OldArrayIndex;
247 if (!Ctx->SourceLocDefaultExpr) {
249 Ctx->SourceLocDefaultExpr = DefaultExpr;
255 Ctx->SourceLocDefaultExpr =
nullptr;
260 bool Enabled =
false;
266 Ctx->InitStack.push_back(std::move(
Link));
278 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
281 Ctx->InitStackActive = OldValue || Active;
287 this->Ctx->InitStackActive = OldValue;
289 Ctx->InitStack.pop_back();
303 OldInitializingDecl(
Ctx->InitializingDecl) {
304 Ctx->InitializingDecl = VD;
309 this->
Ctx->InitializingDecl = OldInitializingDecl;
310 this->
Ctx->InitStack.pop_back();
315 const VarDecl *OldInitializingDecl;
323 bool NewInitializing,
bool NewToLValue)
324 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
325 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
326 Ctx->DiscardResult = NewDiscardResult;
327 Ctx->Initializing = NewInitializing;
328 Ctx->ToLValue = NewToLValue;
332 Ctx->DiscardResult = OldDiscardResult;
333 Ctx->Initializing = OldInitializing;
334 Ctx->ToLValue = OldToLValue;
341 bool OldDiscardResult;
342 bool OldInitializing;
346template <
class Emitter>
350 return Ctx->emitThis(E);
353 return Ctx->emitGetPtrFieldPop(
Offset, E);
355 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
357 return Ctx->emitGetPtrLocal(
Offset, E);
361 if (!Ctx->emitConstUint32(
Offset, E))
363 return Ctx->emitArrayElemPtrPopUint32(E);
365 return Ctx->emitRVOPtr(E);
369 llvm_unreachable(
"Unhandled InitLink kind");
385 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
386 assert(LI.Name != Name);
389 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
410 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
412 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
413 assert(LI.Name != Name);
416 this->Ctx->CaseLabels = std::move(CaseLabels);
417 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
419 DefaultLabel, Ctx->VarScope);
423 this->Ctx->CaseLabels = std::move(OldCaseLabels);
424 this->Ctx->LabelInfoStack.pop_back();
429 CaseMap OldCaseLabels;
440 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
443 Ctx->LocOverride = NewValue;
448 Ctx->LocOverride = OldFlag;
453 std::optional<SourceInfo> OldFlag;
460template <
class Emitter>
468 case CK_LValueToRValue: {
476 if (!this->
visit(SubExpr))
478 return this->emitLoadPopL(E);
488 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
494 if (
auto GlobalIndex =
P.getGlobal(D))
495 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
496 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
497 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
498 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
499 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
500 return this->emitGetParam(*SubExprT, It->second.Index, E);
512 if (!this->emitGetPtrLocal(*LocalIndex, E))
516 if (!this->
visit(SubExpr))
520 return this->emitLoadPop(*SubExprT, E);
525 return this->emitMemcpy(E);
528 case CK_DerivedToBaseMemberPointer: {
539 ->getMostRecentCXXRecordDecl();
541 const CXXRecordDecl *ToDecl = B->getType()->castAsCXXRecordDecl();
542 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
544 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
552 case CK_BaseToDerivedMemberPointer: {
563 ->getMostRecentCXXRecordDecl();
567 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
569 PathI != PathE; ++PathI) {
570 const CXXRecordDecl *ToDecl = (*PathI)->getType()->castAsCXXRecordDecl();
571 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
573 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
580 assert(ToDecl != CurDecl);
581 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
583 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
589 case CK_UncheckedDerivedToBase:
590 case CK_DerivedToBase: {
595 if (
const auto *PT = dyn_cast<PointerType>(Ty))
596 return PT->getPointeeType()->castAsCXXRecordDecl();
597 return Ty->castAsCXXRecordDecl();
604 if (B->isVirtual()) {
605 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
607 CurType = B->getType();
609 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
610 if (!this->emitGetPtrBasePop(
613 CurType = B->getType();
620 case CK_BaseToDerived: {
624 auto unwrapPointerType = [](
const Type *T) ->
const Type * {
625 if (T->isPointerOrReferenceType())
626 return T->getPointeeType().getTypePtr();
638 llvm::drop_begin(llvm::reverse(E->
path()))) {
639 const Type *TargetType = unwrapPointerType(B->getType().getTypePtr());
640 if (!this->emitGetPtrDerivedPop(NullOK, TargetType, FinalType, E))
644 return this->emitGetPtrDerivedPop(NullOK, FinalType, FinalType, E);
647 case CK_FloatingCast: {
650 return this->emitVectorConversion(E->
getSubExpr(), E);
654 if (!this->
visit(SubExpr))
656 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
660 case CK_IntegralToFloating: {
662 return this->emitVectorConversion(E->
getSubExpr(), E);
665 if (!this->
visit(SubExpr))
667 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
668 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
669 TargetSemantics, getFPOptions(E), E);
672 case CK_FloatingToBoolean: {
674 return this->emitVectorConversion(E->
getSubExpr(), E);
678 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
679 return this->emitConstBool(FL->getValue().isNonZero(), E);
680 if (!this->
visit(SubExpr))
682 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
685 case CK_FloatingToIntegral: {
687 return this->emitVectorConversion(E->
getSubExpr(), E);
690 if (!this->
visit(SubExpr))
694 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
697 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
700 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
703 case CK_NullToPointer:
704 case CK_NullToMemberPointer: {
707 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
712 case CK_PointerToIntegral: {
713 if (!this->
visit(SubExpr))
719 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
725 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
727 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
728 return this->emitCastPointerIntegral(T, E);
731 case CK_ArrayToPointerDecay: {
732 if (!this->
visit(SubExpr))
734 return this->emitArrayDecay(E);
737 case CK_IntegralToPointer: {
739 assert(IntType->isIntegralOrEnumerationType());
740 if (!this->
visit(SubExpr))
754 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
757 case CK_AtomicToNonAtomic:
758 case CK_ConstructorConversion:
759 case CK_FunctionToPointerDecay:
760 case CK_NonAtomicToAtomic:
762 case CK_UserDefinedConversion:
763 case CK_CPointerToObjCPointerCast:
766 case CK_AddressSpaceConversion: {
770 if (!this->
visit(SubExpr))
775 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
782 return this->emitPopPtr(E);
800 return this->emitBuiltinBitCast(E);
815 if (!this->
visit(SubExpr))
823 return this->emitFnPtrCast(E);
831 if (!this->
visit(SubExpr))
833 return this->emitDecayPtr(*FromT, *ToT, E);
835 case CK_IntegralToBoolean:
836 case CK_FixedPointToBoolean: {
838 return this->emitVectorConversion(E->
getSubExpr(), E);
844 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
845 return this->emitConst(IL->getValue(), E);
846 if (!this->
visit(SubExpr))
851 case CK_IntegralCast:
853 return this->emitVectorConversion(E->
getSubExpr(), E);
855 case CK_BooleanToSignedIntegral: {
862 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
867 if (!this->emitConst(IL->getValue(), SubExpr))
870 if (!this->
visit(SubExpr))
878 if (!ED->isFixed()) {
879 if (!this->emitCheckEnumValue(*FromT, ED, E))
885 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
888 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
893 if (!this->emitCast(*FromT, *ToT, E))
896 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
897 return this->emitNeg(*ToT, E);
901 case CK_PointerToBoolean:
902 if (!this->
visit(SubExpr))
904 return this->emitIsNonNullPtr(E);
906 case CK_MemberPointerToBoolean:
907 if (!this->
visit(SubExpr))
909 return this->emitIsNonNullMemberPtr(E);
911 case CK_IntegralComplexToBoolean:
912 case CK_FloatingComplexToBoolean: {
913 if (!this->
visit(SubExpr))
915 return this->emitComplexBoolCast(SubExpr);
918 case CK_IntegralComplexToReal:
919 case CK_FloatingComplexToReal:
920 return this->emitComplexReal(SubExpr);
922 case CK_IntegralRealToComplex:
923 case CK_FloatingRealToComplex: {
930 if (!this->emitGetPtrLocal(*LocalIndex, E))
939 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
941 return this->emitInitElem(T, 1, SubExpr);
944 case CK_IntegralComplexCast:
945 case CK_FloatingComplexCast:
946 case CK_IntegralComplexToFloatingComplex:
947 case CK_FloatingComplexToIntegralComplex: {
954 if (!this->emitGetPtrLocal(*LocalIndex, E))
961 unsigned SubExprOffset =
963 if (!this->
visit(SubExpr))
965 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
973 for (
unsigned I = 0; I != 2; ++I) {
974 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
976 if (!this->emitArrayElemPop(SourceElemT, I, E))
980 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
984 if (!this->emitInitElem(DestElemT, I, E))
990 case CK_VectorSplat: {
1001 if (!this->emitGetPtrLocal(*LocalIndex, E))
1007 unsigned ElemOffset =
1011 if (!this->
visit(SubExpr))
1016 if (!this->emitSetLocal(ElemT, ElemOffset, E))
1019 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
1020 if (!this->emitGetLocal(ElemT, ElemOffset, E))
1022 if (!this->emitInitElem(ElemT, I, E))
1029 case CK_HLSLVectorTruncation: {
1034 if (!this->
visit(SubExpr))
1036 return this->emitArrayElemPop(*ResultT, 0, E);
1045 if (!this->emitGetPtrLocal(*LocalIndex, E))
1050 if (!this->
visit(SubExpr))
1052 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1056 case CK_IntegralToFixedPoint: {
1057 if (!this->
visit(SubExpr))
1061 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1066 return this->emitPopFixedPoint(E);
1069 case CK_FloatingToFixedPoint: {
1070 if (!this->
visit(SubExpr))
1074 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1075 if (!this->emitCastFloatingFixedPoint(Sem, E))
1078 return this->emitPopFixedPoint(E);
1081 case CK_FixedPointToFloating: {
1082 if (!this->
visit(SubExpr))
1084 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1085 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1088 return this->emitPopFloat(E);
1091 case CK_FixedPointToIntegral: {
1092 if (!this->
visit(SubExpr))
1095 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1098 return this->emitPop(IntegralT, E);
1101 case CK_FixedPointCast: {
1102 if (!this->
visit(SubExpr))
1105 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1106 if (!this->emitCastFixedPoint(Sem, E))
1109 return this->emitPopFixedPoint(E);
1117 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1119 case CK_LValueBitCast:
1124 case CK_HLSLArrayRValue: {
1131 if (!this->emitGetPtrLocal(*LocalIndex, E))
1134 if (!this->
visit(SubExpr))
1136 return this->emitMemcpy(E);
1139 case CK_HLSLMatrixTruncation: {
1144 if (!this->
visit(SubExpr))
1146 return this->emitArrayElemPop(*ResultT, 0, E);
1155 if (!this->emitGetPtrLocal(*LocalIndex, E))
1160 if (!this->
visit(SubExpr))
1162 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1166 case CK_HLSLAggregateSplatCast: {
1176 if (!this->emitGetPtrLocal(*LocalIndex, E))
1183 unsigned SrcOffset =
1186 if (!this->
visit(SubExpr))
1188 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1192 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1195 case CK_HLSLElementwiseCast: {
1206 unsigned SrcPtrOffset =
1208 if (!this->
visit(SubExpr))
1210 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1214 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1216 if (Elements.empty())
1219 const HLSLFlatElement &Src = Elements[0];
1220 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1222 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1229 if (!this->emitGetPtrLocal(*LocalIndex, E))
1233 unsigned SrcOffset =
1235 if (!this->
visit(SubExpr))
1237 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1241 unsigned ElemCount = countHLSLFlatElements(DestType);
1244 Elements.reserve(ElemCount);
1245 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1250 assert(Elements.size() == ElemCount &&
1251 "Source type has fewer scalar elements than the destination type");
1253 return emitHLSLConstructAggregate(DestType, Elements, E);
1260 const Record::Field *RF = R->getField(UnionField);
1263 if (!this->
visit(SubExpr))
1265 if (RF->isBitField())
1266 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1268 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1271 if (!this->emitGetPtrField(RF->Offset, E))
1273 if (!this->emitActivate(E))
1279 return this->emitInvalid(E);
1281 llvm_unreachable(
"Unhandled clang::CastKind enum");
1284template <
class Emitter>
1286 return this->emitBuiltinBitCast(E);
1289template <
class Emitter>
1294 return this->emitConst(
LE->getValue(),
LE);
1297template <
class Emitter>
1303 return this->emitFloat(F, E);
1306template <
class Emitter>
1316 if (!this->emitGetPtrLocal(*LocalIndex, E))
1323 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1325 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1329 return this->emitFinishInit(E);
1332template <
class Emitter>
1340 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1345template <
class Emitter>
1350template <
class Emitter>
1377 return this->emitComplexComparison(LHS, RHS, E);
1385 if (!this->
visit(LHS))
1388 if (!this->
visit(RHS))
1391 if (!this->emitToMemberPtr(E))
1397 if (!this->emitCastMemberPtrPtr(E))
1414 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1420 if (!this->emitGetPtrLocal(*ResultIndex, E))
1427 return this->emitCMP3(*
LT, CmpInfo, E);
1430 if (!
LT || !RT || !T)
1440 return this->visitAssignment(LHS, RHS, E);
1447 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1451 return this->emitPopBool(E);
1453 return this->emitCast(
PT_Bool, *T, E);
1457 auto Discard = [
this, T, E](
bool Result) {
1465 return MaybeCastToBool(this->emitEQ(*
LT, E));
1467 return MaybeCastToBool(this->emitNE(*
LT, E));
1469 return MaybeCastToBool(this->emitLT(*
LT, E));
1471 return MaybeCastToBool(this->emitLE(*
LT, E));
1473 return MaybeCastToBool(this->emitGT(*
LT, E));
1475 return MaybeCastToBool(this->emitGE(*
LT, E));
1478 return Discard(this->emitSubf(getFPOptions(E), E));
1479 return Discard(this->emitSub(*T, E));
1482 return Discard(this->emitAddf(getFPOptions(E), E));
1483 return Discard(this->emitAdd(*T, E));
1486 return Discard(this->emitMulf(getFPOptions(E), E));
1487 return Discard(this->emitMul(*T, E));
1489 return Discard(this->emitRem(*T, E));
1492 return Discard(this->emitDivf(getFPOptions(E), E));
1493 return Discard(this->emitDiv(*T, E));
1495 return Discard(this->emitBitAnd(*T, E));
1497 return Discard(this->emitBitOr(*T, E));
1499 return Discard(this->emitShl(*
LT, *RT, E));
1501 return Discard(this->emitShr(*
LT, *RT, E));
1503 return Discard(this->emitBitXor(*T, E));
1506 llvm_unreachable(
"Already handled earlier");
1511 llvm_unreachable(
"Unhandled binary op");
1516template <
class Emitter>
1522 if ((Op != BO_Add && Op != BO_Sub) ||
1533 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1534 if (!this->
visit(E))
1537 return this->emitDecayPtr(T,
PT_Ptr, E);
1546 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1554 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1557 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1564 if (!visitAsPointer(RHS, *RT))
1566 if (!this->
visit(LHS))
1570 if (!visitAsPointer(LHS, *
LT))
1572 if (!this->
visit(RHS))
1583 if (!this->emitAddOffset(OffsetType, E))
1587 if (!this->emitSubOffset(OffsetType, E))
1596 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1601 return this->emitPop(ExprT, E);
1605template <
class Emitter>
1614 LabelTy LabelTrue = this->getLabel();
1615 LabelTy LabelEnd = this->getLabel();
1619 if (!this->jumpTrue(LabelTrue, E))
1624 if (!this->jump(LabelEnd, E))
1627 this->emitLabel(LabelTrue);
1628 this->emitConstBool(
true, E);
1629 this->fallthrough(LabelEnd);
1630 this->emitLabel(LabelEnd);
1633 assert(Op == BO_LAnd);
1636 LabelTy LabelFalse = this->getLabel();
1637 LabelTy LabelEnd = this->getLabel();
1641 if (!this->jumpFalse(LabelFalse, E))
1646 if (!this->jump(LabelEnd, E))
1649 this->emitLabel(LabelFalse);
1650 this->emitConstBool(
false, E);
1651 this->fallthrough(LabelEnd);
1652 this->emitLabel(LabelEnd);
1656 return this->emitPopBool(E);
1661 return this->emitCast(
PT_Bool, T, E);
1666template <
class Emitter>
1673 if (!this->emitGetPtrLocal(*LocalIndex, E))
1682 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1683 unsigned ResultOffset = ~0u;
1689 if (!this->emitDupPtr(E))
1691 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1696 LHSType = AT->getValueType();
1699 RHSType = AT->getValueType();
1708 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1713 if (!this->
visit(LHS))
1715 if (!this->
visit(RHS))
1717 if (!this->emitMulc(ElemT, E))
1720 return this->emitPopPtr(E);
1724 if (Op == BO_Div && RHSIsComplex) {
1731 if (!LHSIsComplex) {
1736 LHSOffset = *LocalIndex;
1738 if (!this->emitGetPtrLocal(LHSOffset, E))
1741 if (!this->
visit(LHS))
1744 if (!this->emitInitElem(ElemT, 0, E))
1747 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1749 if (!this->emitInitElem(ElemT, 1, E))
1752 if (!this->
visit(LHS))
1756 if (!this->
visit(RHS))
1758 if (!this->emitDivc(ElemT, E))
1761 return this->emitPopPtr(E);
1768 if (!this->
visit(LHS))
1770 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1775 if (!this->
visit(LHS))
1777 if (!this->emitSetLocal(LHST, LHSOffset, E))
1785 if (!this->
visit(RHS))
1787 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1792 if (!this->
visit(RHS))
1794 if (!this->emitSetLocal(RHST, RHSOffset, E))
1801 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1802 unsigned ElemIndex,
unsigned Offset,
1803 const Expr *E) ->
bool {
1805 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1807 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1810 if (ElemIndex == 0 || !LoadZero)
1817 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1820 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1827 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1830 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1833 if (!this->emitAddf(getFPOptions(E), E))
1836 if (!this->emitAdd(ResultElemT, E))
1841 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1844 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1847 if (!this->emitSubf(getFPOptions(E), E))
1850 if (!this->emitSub(ResultElemT, E))
1855 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1858 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1862 if (!this->emitMulf(getFPOptions(E), E))
1865 if (!this->emitMul(ResultElemT, E))
1870 assert(!RHSIsComplex);
1871 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1874 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1878 if (!this->emitDivf(getFPOptions(E), E))
1881 if (!this->emitDiv(ResultElemT, E))
1892 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1895 if (!this->emitPop(ResultElemT, E))
1900 return this->emitPopPtr(E);
1903 return this->emitFinishInit(E);
1906template <
class Emitter>
1911 "Comma op should be handled in VisitBinaryOperator");
1915 LHSType = AT->getValueType();
1918 RHSType = AT->getValueType();
1932 if (!this->emitGetPtrLocal(*LocalIndex, E))
1941 PrimType ElemT = this->classifyVectorElementType(LHSType);
1942 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1946 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1949 if (!this->
visit(LHS))
1951 if (!this->
visit(RHS))
1953 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1956 return this->emitPopPtr(E);
1961 unsigned LHSOffset =
1963 if (!this->
visit(LHS))
1965 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1969 unsigned RHSOffset =
1971 if (!this->
visit(RHS))
1973 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1985 if (NeedIntPromot) {
1987 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1992 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1993 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1995 if (!this->emitArrayElemPop(ElemT, Index, E))
1998 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
2000 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2002 }
else if (NeedIntPromot) {
2003 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
2009#define EMIT_ARITH_OP(OP) \
2011 if (ElemT == PT_Float) { \
2012 if (!this->emit##OP##f(getFPOptions(E), E)) \
2015 if (!this->emit##OP(ElemT, E)) \
2021 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
2022 if (!getElem(LHSOffset, ElemT, I))
2024 if (!getElem(RHSOffset, RHSElemT, I))
2036 if (!this->emitRem(ElemT, E))
2040 if (!this->emitBitAnd(OpT, E))
2044 if (!this->emitBitOr(OpT, E))
2048 if (!this->emitBitXor(OpT, E))
2052 if (!this->emitShl(OpT, RHSElemT, E))
2056 if (!this->emitShr(OpT, RHSElemT, E))
2060 if (!this->emitEQ(ElemT, E))
2064 if (!this->emitNE(ElemT, E))
2068 if (!this->emitLE(ElemT, E))
2072 if (!this->emitLT(ElemT, E))
2076 if (!this->emitGE(ElemT, E))
2080 if (!this->emitGT(ElemT, E))
2085 if (!this->emitBitAnd(ResultElemT, E))
2090 if (!this->emitBitOr(ResultElemT, E))
2094 return this->emitInvalid(E);
2103 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2105 if (!this->emitNeg(ResultElemT, E))
2111 if (NeedIntPromot &&
2112 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2116 if (!this->emitInitElem(ResultElemT, I, E))
2125template <
class Emitter>
2135 auto LHSSemaInt = LHSSema.toOpaqueInt();
2137 auto RHSSemaInt = RHSSema.toOpaqueInt();
2139 if (!this->
visit(LHS))
2147 if (!this->
visit(RHS))
2156 auto ConvertResult = [&](
bool R) ->
bool {
2160 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2161 if (ResultSema != CommonSema)
2162 return this->emitCastFixedPoint(ResultSema, E);
2166 auto MaybeCastToBool = [&](
bool Result) {
2171 return this->emitPop(T, E);
2173 return this->emitCast(
PT_Bool, T, E);
2179 return MaybeCastToBool(this->emitEQFixedPoint(E));
2181 return MaybeCastToBool(this->emitNEFixedPoint(E));
2183 return MaybeCastToBool(this->emitLTFixedPoint(E));
2185 return MaybeCastToBool(this->emitLEFixedPoint(E));
2187 return MaybeCastToBool(this->emitGTFixedPoint(E));
2189 return MaybeCastToBool(this->emitGEFixedPoint(E));
2191 return ConvertResult(this->emitAddFixedPoint(E));
2193 return ConvertResult(this->emitSubFixedPoint(E));
2195 return ConvertResult(this->emitMulFixedPoint(E));
2197 return ConvertResult(this->emitDivFixedPoint(E));
2199 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2201 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2204 return this->emitInvalid(E);
2207 llvm_unreachable(
"unhandled binop opcode");
2210template <
class Emitter>
2219 if (!this->
visit(SubExpr))
2221 if (!this->emitNegFixedPoint(E))
2224 return this->emitPopFixedPoint(E);
2230 llvm_unreachable(
"Unhandled unary opcode");
2233template <
class Emitter>
2242 return this->visitZeroInitializer(*T, QT, E);
2255 return this->visitZeroRecordInitializer(R, E);
2262 return this->visitZeroArrayInitializer(QT, E);
2266 QualType ElemQT = ComplexTy->getElementType();
2268 for (
unsigned I = 0; I < 2; ++I) {
2269 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2271 if (!this->emitInitElem(ElemT, I, E))
2278 unsigned NumVecElements = VecT->getNumElements();
2279 QualType ElemQT = VecT->getElementType();
2282 for (
unsigned I = 0; I < NumVecElements; ++I) {
2283 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2285 if (!this->emitInitElem(ElemT, I, E))
2292 unsigned NumElems = MT->getNumElementsFlattened();
2293 QualType ElemQT = MT->getElementType();
2296 for (
unsigned I = 0; I != NumElems; ++I) {
2297 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2299 if (!this->emitInitElem(ElemT, I, E))
2308template <
class Emitter>
2321 for (
const Expr *SubExpr : {LHS, RHS}) {
2322 if (!this->
visit(SubExpr)) {
2329 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2330 if (!this->emitExpandPtr(E))
2341 return this->emitError(E);
2344 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2348 if (!this->emitArrayElemPtrPop(*IndexT, E))
2351 return this->emitPopPtr(E);
2357 return this->emitLoadPop(*T, E);
2360template <
class Emitter>
2362 const Expr *ArrayFiller,
const Expr *E) {
2367 QT = AT->getValueType();
2370 if (
Inits.size() == 0)
2372 return this->emitInvalid(E);
2385 if (
Inits.size() == 0)
2386 return this->visitZeroInitializer(*T, QT, E);
2387 assert(
Inits.size() == 1);
2401 if (!this->emitGetPtrLocal(*LocalIndex, E))
2416 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2422 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2431 bool BitField = FieldToInit->isBitField();
2433 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2434 FieldToInit->bitWidth(), E);
2436 return this->emitInitBitField(T, FieldToInit->Offset,
2437 FieldToInit->bitWidth(), E);
2439 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2440 return this->emitInitField(T, FieldToInit->Offset, E);
2443 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2451 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2454 if (
Activate && !this->emitActivate(E))
2457 if (!this->emitStartInit(
Init))
2464 if (
Inits.size() == 0) {
2465 if (!this->visitZeroRecordInitializer(R, E))
2470 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2471 FToInit = ILE->getInitializedFieldInUnion();
2475 const Record::Field *FieldToInit = R->getField(FToInit);
2477 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2480 if (!initCompositeField(FieldToInit,
Init,
true))
2484 return this->emitFinishInit(E);
2487 assert(!R->isUnion());
2488 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2490 const Record::Base *B = R->getBase(BI);
2493 if (!this->emitGetPtrBase(B->Offset,
Init))
2499 unsigned FieldIndex = 0;
2500 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2501 const Record::Field *FieldToInit = R->getField(FieldIndex);
2502 if (FieldToInit->isUnnamedBitField()) {
2517 if (!initPrimitiveField(FieldToInit,
Init, *T))
2519 }
else if (!initCompositeField(FieldToInit,
Init)) {
2527 assert(R->getNumVirtualBases() == 0);
2529 return this->emitFinishInit(E);
2534 Ctx.getASTContext().getAsConstantArrayType(QT);
2539 !this->emitCheckArrayDestSize(NumElems, E))
2542 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2546 unsigned ElementIndex = 0;
2548 if (
const auto *EmbedS =
2549 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2557 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2558 getFPOptions(E), E))
2564 return this->emitInitElem(TargetT, ElemIndex, IL);
2566 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2582 for (; ElementIndex != NumElems; ++ElementIndex) {
2588 return this->emitFinishInit(E);
2592 unsigned NumInits =
Inits.size();
2597 QualType ElemQT = ComplexTy->getElementType();
2599 if (NumInits == 0) {
2601 for (
unsigned I = 0; I < 2; ++I) {
2602 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2604 if (!this->emitInitElem(ElemT, I, E))
2607 }
else if (NumInits == 2) {
2608 unsigned InitIndex = 0;
2613 if (!this->emitInitElem(ElemT, InitIndex, E))
2622 unsigned NumVecElements = VecT->getNumElements();
2623 assert(NumVecElements >=
Inits.size());
2625 QualType ElemQT = VecT->getElementType();
2629 unsigned InitIndex = 0;
2636 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2637 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2638 InitVecT->getNumElements(), E))
2640 InitIndex += InitVecT->getNumElements();
2642 if (!this->emitInitElem(ElemT, InitIndex, E))
2648 assert(InitIndex <= NumVecElements);
2651 for (; InitIndex != NumVecElements; ++InitIndex) {
2652 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2654 if (!this->emitInitElem(ElemT, InitIndex, E))
2661 unsigned NumElems = MT->getNumElementsFlattened();
2662 assert(
Inits.size() == NumElems);
2664 QualType ElemQT = MT->getElementType();
2670 for (
unsigned I = 0; I != NumElems; ++I) {
2673 if (!this->emitInitElem(ElemT, I, E))
2684template <
class Emitter>
2691 return this->emitInitElem(*InitT, ElemIndex,
Init);
2697 if (!this->emitConstUint32(ElemIndex,
Init))
2699 if (!this->emitArrayElemPtrUint32(
Init))
2704template <
class Emitter>
2707 bool Activate,
bool IsOperatorCall) {
2709 llvm::BitVector NonNullArgs;
2710 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2713 bool ExplicitMemberFn =
false;
2714 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2715 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2717 unsigned ArgIndex = 0;
2718 for (
const Expr *Arg : Args) {
2720 if (!this->
visit(Arg))
2728 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2729 if (DeclIndex < FuncDecl->getNumParams())
2730 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2739 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2747 if (!this->emitActivate(Arg))
2751 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2754 if (!this->emitCheckNonNullArg(ArgT, Arg))
2765template <
class Emitter>
2770template <
class Emitter>
2776template <
class Emitter>
2782template <
class Emitter>
2802 if (!this->emitGetPtrLocal(*LocalIndex, E))
2808template <
class Emitter>
2810 auto It = E->
begin();
2811 return this->
visit(*It);
2815 UnaryExprOrTypeTrait Kind) {
2820 T = Ref->getPointeeType();
2822 if (T.getQualifiers().hasUnaligned())
2825 bool AlignOfReturnsPreferred =
2830 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2836template <
class Emitter>
2840 UnaryExprOrTypeTrait Kind = E->
getKind();
2843 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2849 ArgType = Ref->getPointeeType();
2855 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2856 return this->emitInvalid(E);
2858 if (Kind == UETT_SizeOf)
2867 return this->emitConst(Size.getQuantity(), E);
2870 if (Kind == UETT_CountOf) {
2876 if (
const auto *CAT =
2880 return this->emitConst(CAT->getSize(), E);
2890 if (VAT->getElementType()->isArrayType()) {
2891 std::optional<APSInt> Res =
2893 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2898 return this->emitConst(*Res, E);
2903 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2923 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2926 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2936 return this->emitConst(Size.getQuantity(), E);
2939 if (Kind == UETT_VectorElements) {
2944 return this->emitConst(VT->getNumElements(), E);
2946 return this->emitSizelessVectorElementSize(E);
2949 if (Kind == UETT_VecStep) {
2951 unsigned N = VT->getNumElements();
2958 return this->emitConst(N, E);
2960 return this->emitConst(1, E);
2963 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2972 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2974 return this->emitInvalid(E);
2976 return this->emitConst(
2985template <
class Emitter>
2994 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2999 if (VD->getInit() && !VD->getInit()->isValueDependent())
3000 VD->evaluateValue();
3001 if (
auto GlobalIndex =
P.getGlobal(VD)) {
3002 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3004 if (
Member->getType()->isReferenceType())
3005 return this->emitLoadPopPtr(E);
3014 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
3015 MD && !MD->isStatic()) {
3019 if (!this->
discard(Base) && !this->emitSideEffect(E))
3034 const Record::Field *F = R->getField(FD);
3038 const auto maybeLoadValue = [&]() ->
bool {
3042 return this->emitLoadPop(*T, E);
3047 if (F->Decl->getType()->isReferenceType())
3048 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3049 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3052template <
class Emitter>
3062template <
class Emitter>
3072 return this->emitCheckArraySize(Size, E);
3078 if (!this->
visit(Common))
3080 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3094 for (
size_t I = 0; I != Size; ++I) {
3106template <
class Emitter>
3121 return this->emitGetLocal(SubExprT, It->second, E);
3124 if (!this->
visit(SourceExpr))
3131 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3140 return this->emitGetLocal(SubExprT, LocalIndex, E);
3144template <
class Emitter>
3157 bool IsBcpCall =
false;
3158 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3159 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3163 LabelTy LabelEnd = this->getLabel();
3164 LabelTy LabelFalse = this->getLabel();
3167 if (!this->emitPushIgnoreDiags(E))
3175 if (this->checkingForUndefinedBehavior()) {
3178 if (!this->
discard(FalseExpr))
3192 if (!this->jumpFalse(LabelFalse, E))
3197 if (!this->jump(LabelEnd, E))
3199 this->emitLabel(LabelFalse);
3203 this->fallthrough(LabelEnd);
3204 this->emitLabel(LabelEnd);
3207 return this->emitPopIgnoreDiags(E);
3211template <
class Emitter>
3217 return this->emitGetStringPtr(E, E);
3221 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3222 assert(CAT &&
"a string literal that's not a constant array?");
3227 unsigned N = std::min(ArraySize, E->
getLength());
3230 for (
unsigned I = 0; I != N; ++I) {
3233 if (CharWidth == 1) {
3234 this->emitConstSint8(CodeUnit, E);
3235 this->emitInitElemSint8(I, E);
3236 }
else if (CharWidth == 2) {
3237 this->emitConstUint16(CodeUnit, E);
3238 this->emitInitElemUint16(I, E);
3239 }
else if (CharWidth == 4) {
3240 this->emitConstUint32(CodeUnit, E);
3241 this->emitInitElemUint32(I, E);
3243 llvm_unreachable(
"unsupported character width");
3248 for (
unsigned I = N; I != ArraySize; ++I) {
3249 if (CharWidth == 1) {
3250 this->emitConstSint8(0, E);
3251 this->emitInitElemSint8(I, E);
3252 }
else if (CharWidth == 2) {
3253 this->emitConstUint16(0, E);
3254 this->emitInitElemUint16(I, E);
3255 }
else if (CharWidth == 4) {
3256 this->emitConstUint32(0, E);
3257 this->emitInitElemUint32(I, E);
3259 llvm_unreachable(
"unsupported character width");
3266template <
class Emitter>
3270 return this->emitDummyPtr(E, E);
3273template <
class Emitter>
3275 auto &A =
Ctx.getASTContext();
3284template <
class Emitter>
3292 auto &A =
Ctx.getASTContext();
3296 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3297 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3303 return this->emitGetStringPtr(SL, E);
3306template <
class Emitter>
3310 return this->emitConst(E->
getValue(), E);
3313template <
class Emitter>
3335 if (!this->emitLoad(LHST, E))
3338 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3339 LHSComputationType, E))
3351 unsigned TempOffset =
3353 if (!this->emitSetLocal(*RT, TempOffset, E))
3359 if (!this->emitLoad(LHST, E))
3363 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3364 LHSComputationType, E))
3368 if (!this->emitGetLocal(*RT, TempOffset, E))
3374 if (!this->emitAddf(getFPOptions(E), E))
3378 if (!this->emitSubf(getFPOptions(E), E))
3382 if (!this->emitMulf(getFPOptions(E), E))
3386 if (!this->emitDivf(getFPOptions(E), E))
3397 return this->emitStorePop(LHST, E);
3398 return this->emitStore(LHST, E);
3401template <
class Emitter>
3410 if (Op != BO_AddAssign && Op != BO_SubAssign)
3419 if (!this->emitLoad(*
LT, LHS))
3425 if (Op == BO_AddAssign) {
3426 if (!this->emitAddOffset(*RT, E))
3429 if (!this->emitSubOffset(*RT, E))
3434 return this->emitStorePopPtr(E);
3435 return this->emitStorePtr(E);
3438template <
class Emitter>
3451 if (!
Ctx.getLangOpts().CPlusPlus14)
3452 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3454 if (!
LT || !RT || !ResultT || !LHSComputationT)
3471 if (!this->emitLoad(*
LT, E))
3473 if (
LT != LHSComputationT &&
3474 !this->emitIntegralCast(*
LT, *LHSComputationT,
3488 unsigned TempOffset =
3491 if (!this->emitSetLocal(*RT, TempOffset, E))
3498 if (!this->emitLoad(*
LT, E))
3500 if (
LT != LHSComputationT &&
3501 !this->emitIntegralCast(*
LT, *LHSComputationT,
3506 if (!this->emitGetLocal(*RT, TempOffset, E))
3513 if (!this->emitAdd(*LHSComputationT, E))
3517 if (!this->emitSub(*LHSComputationT, E))
3521 if (!this->emitMul(*LHSComputationT, E))
3525 if (!this->emitDiv(*LHSComputationT, E))
3529 if (!this->emitRem(*LHSComputationT, E))
3533 if (!this->emitShl(*LHSComputationT, *RT, E))
3537 if (!this->emitShr(*LHSComputationT, *RT, E))
3541 if (!this->emitBitAnd(*LHSComputationT, E))
3545 if (!this->emitBitXor(*LHSComputationT, E))
3549 if (!this->emitBitOr(*LHSComputationT, E))
3553 llvm_unreachable(
"Unimplemented compound assign operator");
3557 if (ResultT != LHSComputationT &&
3558 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3564 return this->emitStoreBitFieldPop(*ResultT, E);
3565 return this->emitStorePop(*ResultT, E);
3568 return this->emitStoreBitField(*ResultT, E);
3569 return this->emitStore(*ResultT, E);
3572template <
class Emitter>
3580template <
class Emitter>
3595 if (!
Ctx.getLangOpts().CPlusPlus11)
3602 for (
const Expr *LHS : CommaLHSs) {
3617 if (this->constantFolding())
3628 if (!this->
visit(Inner))
3633 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3636 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3639 return this->emitGetPtrGlobal(*GlobalIndex, E);
3642 if (!this->checkLiteralType(Inner))
3645 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3651 return this->emitInitGlobalTempComp(TempDecl, E);
3664 unsigned LocalIndex =
3666 if (!this->VarScope->LocalsAlwaysEnabled &&
3667 !this->emitEnableLocal(LocalIndex, E))
3670 if (!this->
visit(Inner))
3672 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3675 return this->emitGetPtrLocal(LocalIndex, E);
3678 if (!this->checkLiteralType(Inner))
3681 std::optional<Scope::Local>
Local =
3688 if (!this->VarScope->LocalsAlwaysEnabled &&
3689 !this->emitEnableLocal(
Local->Offset, E))
3692 if (!this->emitGetPtrLocal(
Local->Offset, E))
3697template <
class Emitter>
3708 if (!this->
visit(SubExpr))
3712 return this->emitPopPtr(E);
3716template <
class Emitter>
3737 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3742 if (
P.isGlobalInitialized(*GlobalIndex))
3748 return this->emitInitGlobal(*T, *GlobalIndex, E);
3760 unsigned LocalIndex;
3764 LocalIndex = *MaybeIndex;
3768 if (!this->emitGetPtrLocal(LocalIndex, E))
3772 return this->
visit(
Init) && this->emitInit(*T, E);
3776template <
class Emitter>
3787 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3791 if (!R || R->getNumFields() == 0)
3793 const Record::Field *Field = R->getField(0
U);
3798 return this->emitInitField(*Field->T, Field->Offset, E);
3805template <
class Emitter>
3809 return this->emitConst(E->
getValue(), E);
3812template <
class Emitter>
3825 for (
const Record::Field &F : R->fields()) {
3827 if (!
Init ||
Init->containsErrors())
3835 if (!this->emitInitField(*T, F.Offset, E))
3838 if (!this->emitGetPtrField(F.Offset, E))
3849template <
class Emitter>
3855 return this->emitGetStringPtr(E, E);
3859template <
class Emitter>
3864 return this->emitInvalid(E);
3867template <
class Emitter>
3881 if (!this->emitInvalidCast(
CastKind,
false, E))
3889 bool Fatal = (ToT != FromT);
3896template <
class Emitter>
3898 if (!
Ctx.getLangOpts().CPlusPlus20) {
3919 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3924 return this->emitPopPtr(E);
3928template <
class Emitter>
3934 return this->emitConstBool(E->
getValue(), E);
3937template <
class Emitter>
3942 if (T->isRecordType()) {
3956 if (!this->emitGetPtrLocal(*LocalIndex, E))
3964 T->castAsCXXRecordDecl()))
3974 if (!this->visitZeroRecordInitializer(R, E))
3985 if (!this->emitDefaultInit(Ctor, E))
3988 return this->emitPopPtr(E);
3996 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3998 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3999 if (!this->emitCheckFunctionDecl(Ctor, E))
4010 assert(
Func->hasThisPointer());
4011 assert(!
Func->hasRVO());
4015 if (!this->emitDupPtr(E))
4019 for (
const auto *Arg : E->
arguments()) {
4020 if (!this->
visit(Arg))
4024 if (
Func->isVariadic()) {
4025 uint32_t VarArgSize = 0;
4026 unsigned NumParams =
Func->getNumWrittenParams();
4027 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
4031 if (!this->emitCallVar(
Func, VarArgSize, E))
4034 if (!this->emitCall(
Func, 0, E)) {
4039 (void)this->emitPopPtr(E);
4045 return this->emitPopPtr(E);
4049 if (T->isArrayType()) {
4054 if (!this->emitDupPtr(E))
4058 initArrayDimension = [&](
QualType T) ->
bool {
4059 if (!T->isArrayType()) {
4061 for (
const auto *Arg : E->
arguments()) {
4062 if (!this->
visit(Arg))
4066 return this->emitCall(
Func, 0, E);
4070 Ctx.getASTContext().getAsConstantArrayType(T);
4076 return this->emitCheckArraySize(NumElems, E);
4077 for (uint64_t I = 0; I != NumElems; ++I) {
4078 if (!this->emitConstUint64(I, E))
4080 if (!this->emitArrayElemPtrUint64(E))
4082 if (!initArrayDimension(ElemTy))
4085 return this->emitPopPtr(E);
4088 return initArrayDimension(E->
getType());
4094template <
class Emitter>
4104 assert(Val.
isInt());
4106 return this->emitConst(I, E);
4113 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4114 return this->
visit(LValueExpr);
4129 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4133 const APValue &
V = UGCD->getValue();
4134 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4135 const Record::Field *F = R->getField(I);
4136 const APValue &FieldValue =
V.getStructField(I);
4140 if (!this->emitInitField(*F->T, F->Offset, E))
4148template <
class Emitter>
4154 for (
unsigned I = 0; I != N; ++I) {
4161 if (!this->
discard(ArrayIndexExpr))
4167 if (!this->
visit(ArrayIndexExpr))
4169 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4173 if (!this->
visit(ArrayIndexExpr))
4177 if (!this->emitCast(IndexT,
PT_Sint64, E))
4187 return this->emitOffsetOf(T, E, E);
4190template <
class Emitter>
4199 return this->visitZeroInitializer(*T, Ty, E);
4206 if (!this->emitGetPtrLocal(*LocalIndex, E))
4214 ElemQT = CT->getElementType();
4217 NumElems = VT->getNumElements();
4218 ElemQT = VT->getElementType();
4224 for (
unsigned I = 0; I != NumElems; ++I) {
4225 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4227 if (!this->emitInitElem(ElemT, I, E))
4236template <
class Emitter>
4241template <
class Emitter>
4247template <
class Emitter>
4252template <
class Emitter>
4257 return this->emitConst(E->
getValue(), E);
4260template <
class Emitter>
4282 unsigned ParamIndex = 0;
4286 if (!this->emitGetParam(PT, ParamIndex, E))
4291 return this->emitCall(F, 0, E);
4296template <
class Emitter>
4304 const Expr *PlacementDest =
nullptr;
4305 bool IsNoThrow =
false;
4310 if (PlacementArgs != 0) {
4319 if (PlacementArgs == 1) {
4321 if (OperatorNew->isReservedGlobalPlacementOperator()) {
4322 if (!this->emitCheckPlacementNew(E, E))
4324 PlacementDest = Arg1;
4328 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4335 return this->emitInvalidNewDeleteExpr(E, E);
4339 return this->emitInvalid(E);
4341 }
else if (!OperatorNew
4342 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4343 return this->emitInvalidNewDeleteExpr(E, E);
4346 if (!PlacementDest) {
4351 Desc =
P.createDescriptor(E, *ElemT);
4353 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4360 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4364 const Expr *Stripped = *ArraySizeExpr;
4365 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4366 Stripped = ICE->getSubExpr())
4367 if (ICE->getCastKind() != CK_NoOp &&
4368 ICE->getCastKind() != CK_IntegralCast)
4376 if (!this->
visit(Stripped))
4378 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4381 if (PlacementDest) {
4382 if (!this->
visit(PlacementDest))
4384 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4386 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4389 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4394 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4398 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4405 size_t StaticInitElems = 0;
4406 const Expr *DynamicInit =
nullptr;
4410 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4411 StaticInitElems = CAT->getZExtSize();
4416 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4417 if (ILE->hasArrayFiller())
4418 DynamicInit = ILE->getArrayFiller();
4437 const Function *CtorFunc =
nullptr;
4438 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4442 }
else if (!DynamicInit && !ElemT)
4445 LabelTy EndLabel = this->getLabel();
4446 LabelTy StartLabel = this->getLabel();
4451 if (!this->emitDupPtr(E))
4453 if (!this->emitIsNonNullPtr(E))
4455 if (!this->jumpFalse(EndLabel, E))
4462 if (!this->emitConst(StaticInitElems,
SizeT, E))
4464 if (!this->emitSetLocal(
SizeT, Iter, E))
4467 this->fallthrough(StartLabel);
4468 this->emitLabel(StartLabel);
4470 if (!this->emitGetLocal(
SizeT, Iter, E))
4472 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4474 if (!this->emitLT(
SizeT, E))
4476 if (!this->jumpFalse(EndLabel, E))
4480 if (!this->emitGetLocal(
SizeT, Iter, E))
4482 if (!this->emitArrayElemPtr(
SizeT, E))
4485 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4490 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4492 if (!this->emitStorePop(*InitT, E))
4496 if (!this->visitZeroArrayInitializer(ElemType, E))
4499 }
else if (DynamicInit) {
4501 if (!this->
visit(DynamicInit))
4503 if (!this->emitStorePop(*InitT, E))
4510 if (!this->visitZeroInitializer(
4514 if (!this->emitStorePop(*ElemT, E))
4518 if (!this->emitCall(CtorFunc, 0, E))
4523 if (!this->emitGetPtrLocal(Iter, E))
4525 if (!this->emitIncPop(
SizeT,
false, E))
4528 if (!this->jump(StartLabel, E))
4531 this->fallthrough(EndLabel);
4532 this->emitLabel(EndLabel);
4536 if (PlacementDest) {
4537 if (!this->
visit(PlacementDest))
4539 if (!this->emitCheckNewTypeMismatch(E, E))
4544 if (!this->emitAlloc(Desc, E))
4553 if (!this->emitInit(*ElemT, E))
4564 return this->emitPopPtr(E);
4569template <
class Emitter>
4575 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4576 return this->emitInvalidNewDeleteExpr(E, E);
4585template <
class Emitter>
4591 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4596 return this->emitGetFnPtr(
Func, E);
4599template <
class Emitter>
4606 auto canonType = [](
const Type *T) {
4607 return T->getCanonicalTypeUnqualified().getTypePtr();
4615 return this->emitGetTypeid(
4619 return this->emitGetTypeid(
4628 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4634 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4637 return this->emitPopPtr(E);
4641template <
class Emitter>
4645 return this->emitDummyPtr(E, E);
4646 return this->emitError(E);
4649template <
class Emitter>
4652 return this->emitDummyPtr(E, E);
4653 return this->emitError(E);
4656template <
class Emitter>
4663 assert(
false &&
"null reflection can't be constructed from parsing a "
4664 "reflection operand");
4672 assert(
false &&
"unknown or unimplemented reflection entities");
4676template <
class Emitter>
4678 assert(
Ctx.getLangOpts().CPlusPlus);
4679 return this->emitConstBool(E->
getValue(), E);
4682template <
class Emitter>
4694 return this->emitDummyPtr(GuidDecl, E);
4699 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4708 assert(
V.isStruct());
4709 assert(
V.getStructNumBases() == 0);
4713 return this->emitFinishInit(E);
4716template <
class Emitter>
4726template <
class Emitter>
4735template <
class Emitter>
4741template <
class Emitter>
4750 const auto *ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl());
4753 const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext());
4754 if (ED && ED->hasAttr<BPFPreserveAccessIndexAttr>())
4763 if (ED->getDeclName())
4764 EnumTy =
Ctx.getASTContext().getCanonicalTagType(ED);
4766 EnumTy =
Ctx.getASTContext().getTypeDeclType(TD);
4770 return this->emitInvalidAccessIndexAttr(ECD, EnumTy.
getTypePtr(), E);
4774 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4778 if (OVE->isUnique())
4794template <
class Emitter>
4799template <
class Emitter>
4801 return this->emitError(E);
4804template <
class Emitter>
4810 return this->emitDummyPtr(E, E);
4813template <
class Emitter>
4814bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4819 QualType ElemType = VT->getElementType();
4820 PrimType ElemT = classifyPrim(ElemType);
4822 PrimType SrcElemT = classifyVectorElementType(SrcType);
4828 if (!this->emitGetPtrLocal(*LocalIndex, E))
4832 unsigned SrcOffset =
4833 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4834 if (!this->visit(Src))
4836 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4839 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4840 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4842 if (!this->emitArrayElemPop(SrcElemT, I, E))
4846 if (SrcElemT != ElemT) {
4847 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4849 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4850 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4854 if (!this->emitInitElem(ElemT, I, E))
4860template <
class Emitter>
4862 return emitVectorConversion(E->
getSrcExpr(), E);
4865template <
class Emitter>
4869 return this->emitInvalid(E);
4878 assert(NumOutputElems > 0);
4884 if (!this->emitGetPtrLocal(*LocalIndex, E))
4889 unsigned VectorOffsets[2];
4890 for (
unsigned I = 0; I != 2; ++I) {
4893 if (!this->
visit(Vecs[I]))
4895 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4898 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4900 assert(ShuffleIndex >= -1);
4901 if (ShuffleIndex == -1)
4902 return this->emitInvalidShuffleVectorIndex(I, E);
4904 assert(ShuffleIndex < (NumInputElems * 2));
4905 if (!this->emitGetLocal(
PT_Ptr,
4906 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4908 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4909 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4912 if (!this->emitInitElem(ElemT, I, E))
4917 return this->emitPopPtr(E);
4922template <
class Emitter>
4927 Base->getType()->isVectorType() ||
4933 if (Indices.size() == 1) {
4938 if (!this->emitConstUint32(Indices[0], E))
4940 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4950 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4958 if (!this->emitGetPtrLocal(*ResultIndex, E))
4966 uint32_t DstIndex = 0;
4967 for (uint32_t I : Indices) {
4968 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4970 if (!this->emitArrayElemPop(ElemT, I, E))
4972 if (!this->emitInitElem(ElemT, DstIndex, E))
4982template <
class Emitter>
4986 return this->
discard(SubExpr) && this->emitInvalid(E);
4992 return this->emitDummyPtr(E, E);
4995template <
class Emitter>
5000 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
5009 if (!this->emitGetPtrLocal(*LocalIndex, E))
5013 if (!this->
visit(SubExpr))
5015 if (!this->emitConstUint8(0, E))
5017 if (!this->emitArrayElemPtrPopUint8(E))
5019 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
5022 PrimType SecondFieldT = *R->getField(1u)->T;
5024 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
5026 if (!this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E))
5029 return this->emitPopPtr(E);
5032 assert(SecondFieldT ==
PT_Ptr);
5034 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
5036 if (!this->emitExpandPtr(E))
5040 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5043 if (!this->emitInitFieldPtr(R->getField(1u)->Offset, E))
5046 return this->emitPopPtr(E);
5050template <
class Emitter>
5065 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
5069 return this->emitUnsupported(E);
5078 return this->
Visit(E);
5085 return this->
Visit(E);
5089 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5092 if (
const auto *CE = dyn_cast<CastExpr>(E);
5094 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
5101 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5104 if (
const auto *CE = dyn_cast<CastExpr>(E);
5105 CE && (CE->getCastKind() == CK_DerivedToBase ||
5106 CE->getCastKind() == CK_UncheckedDerivedToBase ||
5107 CE->getCastKind() == CK_NoOp))
5122 std::optional<Scope::Local>
Local =
5129 if (!this->emitGetPtrLocal(
Local->Offset, E))
5138 return this->
Visit(E);
5141template <
class Emitter>
5147 return this->
Visit(E) && this->emitFinishInit(E);
5150template <
class Emitter>
5156 return this->
Visit(E) && this->emitFinishInitPop(E);
5162 return this->
Visit(E);
5173 if (!this->
visit(E))
5175 return this->emitComplexBoolCast(E);
5180 if (!this->
visit(E))
5188 return this->emitIsNonNullPtr(E);
5192 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5195 return this->emitCast(*T,
PT_Bool, E);
5198template <
class Emitter>
5202 QT = AT->getValueType();
5206 return this->emitZeroBool(E);
5208 return this->emitZeroSint8(E);
5210 return this->emitZeroUint8(E);
5212 return this->emitZeroSint16(E);
5214 return this->emitZeroUint16(E);
5216 return this->emitZeroSint32(E);
5218 return this->emitZeroUint32(E);
5220 return this->emitZeroSint64(E);
5222 return this->emitZeroUint64(E);
5224 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5226 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5228 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5231 return this->emitNullMemberPtr(0,
nullptr, E);
5233 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5234 return this->emitFloat(F, E);
5237 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5243 llvm_unreachable(
"unknown primitive type");
5246template <
class Emitter>
5247bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5249 bool IsCompleteClass) {
5253 for (
const Record::Field &Field :
R->fields()) {
5254 if (Field.isUnnamedBitField())
5261 if (!this->visitZeroInitializer(T, QT, E))
5264 if (!this->emitInitFieldActivate(T, Field.Offset, E))
5268 if (!this->emitInitField(T, Field.Offset, E))
5273 if (!this->emitGetPtrField(Field.Offset, E))
5280 if (!this->visitZeroInitializer(T, ET, E))
5282 if (!this->emitInitElem(T, I, E))
5287 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5290 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5298 if (!this->emitFinishInitActivatePop(E))
5302 if (!this->emitFinishInitPop(E))
5306 for (
const Record::Base &B :
R->bases()) {
5307 if (!this->emitGetPtrBase(B.Offset, E))
5309 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5311 if (!this->emitFinishInitPop(E))
5315 if (IsCompleteClass) {
5316 for (
const Record::Base &B :
R->virtual_bases()) {
5319 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5321 if (!this->emitFinishInitPop(E))
5329template <
class Emitter>
5330bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5331 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
5337 for (
size_t I = 0; I != NumElems; ++I) {
5338 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5340 if (!this->emitInitElem(*ElemT, I, E))
5346 const Record *
R = getRecord(ElemType);
5350 for (
size_t I = 0; I != NumElems; ++I) {
5351 if (!this->emitConstUint32(I, E))
5353 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5355 if (!this->visitZeroRecordInitializer(R, E))
5357 if (!this->emitPopPtr(E))
5363 for (
size_t I = 0; I != NumElems; ++I) {
5364 if (!this->emitConstUint32(I, E))
5366 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5368 if (!this->visitZeroArrayInitializer(ElemType, E))
5370 if (!this->emitPopPtr(E))
5379template <
class Emitter>
5380bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5382 if (!canClassify(E->
getType()))
5387 if (!this->visit(LHS))
5389 if (!this->visit(RHS))
5392 if (!this->visit(RHS))
5394 if (!this->visit(LHS))
5402 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5406 bool Activates = refersToUnion(LHS);
5409 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5412 if (DiscardResult) {
5413 if (BitField && Activates)
5414 return this->emitStoreBitFieldActivatePop(RHT, E);
5416 return this->emitStoreBitFieldPop(RHT, E);
5418 return this->emitStoreActivatePop(RHT, E);
5420 return this->emitStorePop(RHT, E);
5423 auto maybeLoad = [&](
bool Result) ->
bool {
5429 return this->emitLoadPop(RHT, E);
5433 if (BitField && Activates)
5434 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5436 return maybeLoad(this->emitStoreBitField(RHT, E));
5438 return maybeLoad(this->emitStoreActivate(RHT, E));
5440 return maybeLoad(this->emitStore(RHT, E));
5443template <
class Emitter>
5444template <
typename T>
5448 return this->emitConstSint8(
Value, Info);
5450 return this->emitConstUint8(
Value, Info);
5452 return this->emitConstSint16(
Value, Info);
5454 return this->emitConstUint16(
Value, Info);
5456 return this->emitConstSint32(
Value, Info);
5458 return this->emitConstUint32(
Value, Info);
5460 return this->emitConstSint64(
Value, Info);
5462 return this->emitConstUint64(
Value, Info);
5464 return this->emitConstBool(
Value, Info);
5472 llvm_unreachable(
"Invalid integral type");
5475 llvm_unreachable(
"unknown primitive type");
5478template <
class Emitter>
5479template <
typename T>
5480bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
5481 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5484template <
class Emitter>
5488 return this->emitConstIntAPS(
Value, Info);
5490 return this->emitConstIntAP(
Value, Info);
5492 if (
Value.isSigned())
5493 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5494 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5497template <
class Emitter>
5501 return this->emitConstIntAPS(
Value, Info);
5503 return this->emitConstIntAP(
Value, Info);
5506 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5507 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5510template <
class Emitter>
5511bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5512 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5515template <
class Emitter>
5529 return Local.Offset;
5532template <
class Emitter>
5537 return std::nullopt;
5539 return Local->Offset;
5542template <
class Emitter>
5543std::optional<Scope::Local>
5547 bool IsTemporary =
false;
5551 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5552 Init = VarD->getInit();
5554 if (
const auto *E = Src.
asExpr()) {
5564 return std::nullopt;
5572template <
class Emitter>
5581 return std::nullopt;
5591 return Local.Offset;
5594template <
class Emitter>
5596 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5597 return PT->getPointeeType()->getAsCanonical<RecordType>();
5603 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5607template <
class Emitter>
5609 return P.getOrCreateRecord(RD);
5612template <
class Emitter>
5614 return Ctx.getOrCreateFunction(FD);
5617template <
class Emitter>
5623 auto maybeDestroyLocals = [&]() ->
bool {
5624 if (DestroyToplevelScope)
5625 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5626 return this->emitCheckAllocations(E);
5633 return this->emitRetVoid(E) && maybeDestroyLocals();
5641 return this->emitRet(*T, E) && maybeDestroyLocals();
5649 if (!this->emitGetPtrLocal(*LocalOffset, E))
5657 return this->emitRetValue(E) && maybeDestroyLocals();
5660 return maybeDestroyLocals() &&
false;
5663template <
class Emitter>
5665 bool DestroyToplevelScope) {
5669 return this->
visitExpr(E, DestroyToplevelScope);
5672template <
class Emitter>
5684 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5685 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5699template <
class Emitter>
5701 bool ConstantContext) {
5704 if (!ConstantContext) {
5719 auto GlobalIndex =
P.getGlobal(VD);
5720 assert(GlobalIndex);
5722 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5725 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5733 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5735 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5738 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5748 auto GlobalIndex =
P.getGlobal(VD);
5749 assert(GlobalIndex);
5750 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5759 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5762template <
class Emitter>
5773 if (!this->isActive())
5778 if (
Init &&
Init->isValueDependent())
5782 auto checkDecl = [&]() ->
bool {
5784 return !NeedsOp || this->emitCheckDecl(VD, VD);
5791 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5794 if (
P.isGlobalInitialized(*GlobalIndex))
5798 }
else if ((GlobalIndex =
5813 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5816 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5819 if (!this->emitStartInit(
Init))
5825 if (!this->emitEndInit(
Init))
5828 return this->emitFinishInitGlobal(
Init);
5838 if (!
Init ||
Init->getType()->isVoidType())
5847 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5859 if (!this->emitCheckRefInit(
Init))
5863 return this->emitSetLocal(*VarT, Offset, VD);
5872 if (!this->emitGetPtrLocal(
Local->Offset,
Init))
5877template <
class Emitter>
5900 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5906 return this->emitDestructionPop(D, VD);
5915 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5939template <
class Emitter>
5954 unsigned ParamIndex = 0;
5961 const Expr *Arg = Args[ParamIndex];
5962 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5964 unsigned ArgOffset =
5966 if (!this->
visit(Arg))
5968 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5974 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5986 if (
This->getType()->isPointerType()) {
5989 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5996 if (!this->emitGetPtrLocal(*ArgOffset,
This))
6018template <
class Emitter>
6024 return this->emitConst(Val.
getInt(), ValType, Info);
6026 return this->emitFloat(Val.
getFloat(), Info);
6030 if (!this->emitGetMemberPtr(MemberDecl, Info))
6036 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
6042 return this->emitNullMemberPtr(0,
nullptr, Info);
6047 return this->emitNull(ValType, 0,
nullptr, Info);
6051 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>()) {
6054 GlobalIndex &&
P.isGlobalInitialized(*GlobalIndex)) {
6055 if (!this->emitGetPtrGlobal(*GlobalIndex, Info))
6058 if (!this->
visit(BaseExpr))
6061 EntryType = BaseExpr->getType();
6062 }
else if (
const auto *VD =
Base.dyn_cast<
const ValueDecl *>()) {
6065 EntryType = VD->getType();
6070 ->getCanonicalTypeUnqualified()
6072 EntryType =
Base.getTypeInfoType();
6073 if (!this->emitGetTypeid(OperandType, EntryType.
getTypePtr(), Info))
6081 ?
Ctx.getASTContext().getPointerType(E->
getType())
6084 if (!this->emitConstUint64(Offset, Info))
6086 if (!this->emitGetIntPtrUint64(PtrType.
getTypePtr(), Info))
6096 uint64_t Index = Entry.getAsArrayIndex();
6099 if (!this->emitConst(Index,
PT_Uint64, Info))
6101 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
6103 EntryType = ElemType;
6110 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
6111 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
6113 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
6115 EntryType = FD->getType();
6119 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
6124 if (!this->emitGetPtrVirtBasePop(
Base, Info))
6127 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
6142 uint32_t BitWidth =
Ctx.getBitWidth(E->
getType());
6144 ? this->emitCastPointerIntegralAP(BitWidth, Info)
6145 : this->emitCastPointerIntegralAPS(BitWidth, Info);
6147 return this->emitCastPointerIntegral(ValType, Info);
6153template <
class Emitter>
6156 bool IsCompleteClass) {
6162 if (IsCompleteClass)
6169 const Record::Base *RB = R->getBase(I);
6170 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6172 if (!this->emitGetPtrBase(RB->Offset, Info))
6177 if (!this->emitFinishInitPop(Info))
6185 const Record::Field *RF = R->getField(I);
6186 QualType FieldType = RF->Decl->getType();
6191 if (!this->emitInitField(*PT, RF->Offset, Info))
6194 if (!this->emitGetPtrField(RF->Offset, Info))
6198 if (!this->emitFinishInitPop(Info))
6204 if (IsCompleteClass) {
6209 const Record::Base *RB = R->getVirtualBase(I);
6210 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6218 if (!this->emitFinishInitPop(Info))
6234 const Record::Field *RF = R->getField(UnionField);
6235 QualType FieldType = RF->Decl->getType();
6240 if (RF->isBitField())
6241 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6243 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6246 if (!this->emitGetPtrField(RF->Offset, Info))
6248 if (!this->emitActivate(Info))
6252 return this->emitPopPtr(Info);
6256 const auto *ArrType = T->getAsArrayTypeUnsafe();
6257 QualType ElemType = ArrType->getElementType();
6260 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6261 const APValue &Elem = A >= InitializedElems
6270 if (!this->emitInitElem(*ElemT, A, Info))
6273 if (!this->emitConstUint32(A, Info))
6275 if (!this->emitArrayElemPtrUint32(Info))
6279 if (!this->emitPopPtr(Info))
6286 assert(T->isComplexType());
6289 if (!this->emitInitElemFloat(0, Info))
6293 if (!this->emitInitElemFloat(1, Info))
6298 assert(T->isComplexIntegerType());
6302 if (!this->emitInitElem(IntT, 0, Info))
6306 if (!this->emitInitElem(IntT, 1, Info))
6311 assert(T->isVectorType());
6319 if (!this->emitInitElem(ElemT, I, Info))
6329template <
class Emitter>
6331 if (
P.getGlobal(VD))
6335 P.createGlobal(VD,
nullptr,
false,
6338 llvm_unreachable(
"Why didn't that work?");
6342 "registerRedecl should only be called with primitive values");
6347 return this->emitInitGlobal(T, *GlobalIndex, {});
6350template <
class Emitter>
6352 unsigned BuiltinID) {
6358 if (!
Ctx.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
6359 return this->emitInvalid(E);
6368 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6373 return this->emitConst(0, E);
6376 if (!this->emitStartSpeculation(E))
6378 LabelTy EndLabel = this->getLabel();
6379 if (!this->speculate(E, EndLabel))
6381 if (!this->emitEndSpeculation(E))
6383 this->fallthrough(EndLabel);
6391 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6392 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6393 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6394 BuiltinID == Builtin::BI__builtin_function_start) {
6397 return this->emitDummyPtr(E, E);
6408 if (!this->emitGetPtrLocal(*LocalIndex, E))
6413 switch (BuiltinID) {
6414 case Builtin::BI__builtin_object_size:
6415 case Builtin::BI__builtin_dynamic_object_size: {
6419 if (!this->
visit(Arg0))
6430 case Builtin::BI__assume:
6431 case Builtin::BI__builtin_assume:
6434 case Builtin::BI__atomic_is_lock_free:
6435 case Builtin::BI__atomic_always_lock_free: {
6446 for (
const auto *Arg : E->
arguments()) {
6447 if (!this->
visit(Arg))
6453 if (!this->emitCallBI(E, BuiltinID, E))
6472template <
class Emitter>
6493 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6494 DD && DD->isTrivial()) {
6496 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6498 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6499 this->emitPopPtr(E);
6504 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6505 MD && MD->getParent()->isInvalidDecl())
6510 bool ActivateLHS =
false;
6518 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6519 OCE && OCE->isAssignmentOp()) {
6520 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6523 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6524 if (!this->
visit(MCE->getImplicitObjectArgument()))
6531 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6541 bool HasRVO = !
ReturnType->isVoidType() && !T;
6549 if (!this->emitGetPtrLocal(*LocalIndex, E))
6557 if (!this->emitGetPtrLocal(*LocalIndex, E))
6561 if (!this->emitDupPtr(E))
6566 const Expr *ReversedArgs[2];
6567 bool IsAssignmentOperatorCall =
false;
6568 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6569 OCE && OCE->isAssignmentOp()) {
6573 assert(Args.size() == 2);
6574 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6576 IsAssignmentOperatorCall =
true;
6577 ReversedArgs[0] = Args[1];
6578 ReversedArgs[1] = Args[0];
6579 Args = ReversedArgs;
6586 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6587 MD && MD->isStatic()) {
6591 Args = Args.drop_front();
6595 bool Devirtualized =
false;
6598 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6606 if (!this->
visit(Callee))
6608 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6610 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6612 if (!this->emitGetMemberPtrBase(E))
6615 const auto *InstancePtr = MC->getImplicitObjectArgument();
6622 Stripped->getType()->getPointeeType()->castAsCXXRecordDecl());
6623 Devirtualized =
true;
6624 if (!this->
visit(Stripped))
6627 if (!this->
visit(InstancePtr))
6631 if (!this->
visit(InstancePtr))
6635 }
else if (
const auto *PD =
6636 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6637 if (!this->emitCheckPseudoDtor(E))
6645 return this->emitPseudoDtor(E);
6646 }
else if (!FuncDecl) {
6650 if (!this->
visit(Callee))
6652 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6661 if (IsAssignmentOperatorCall) {
6662 assert(Args.size() == 2);
6665 if (!this->emitFlip(Arg2T, Arg1T, E))
6679 assert(HasRVO ==
Func->hasRVO());
6681 bool HasQualifier =
false;
6682 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6683 HasQualifier = ME->hasQualifier();
6685 bool IsVirtual =
false;
6686 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6687 IsVirtual = !Devirtualized && MD->isVirtual();
6692 if (IsVirtual && !HasQualifier) {
6693 uint32_t VarArgSize = 0;
6694 unsigned NumParams =
6695 Func->getNumWrittenParams() +
6697 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6700 if (!this->emitCallVirt(
Func, VarArgSize, E))
6702 }
else if (
Func->isVariadic()) {
6703 uint32_t VarArgSize = 0;
6704 unsigned NumParams =
6705 Func->getNumWrittenParams() +
6707 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6709 if (!this->emitCallVar(
Func, VarArgSize, E))
6712 if (!this->emitCall(
Func, 0, E))
6721 uint32_t ArgSize = 0;
6722 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6728 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6730 if (!this->emitGetMemberPtrDecl(E))
6733 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6736 if (!this->emitCallPtr(ArgSize, E, E))
6747template <
class Emitter>
6754template <
class Emitter>
6761template <
class Emitter>
6766 return this->emitConstBool(E->
getValue(), E);
6769template <
class Emitter>
6775 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6776 return this->emitNullPtr(Val,
nullptr, E);
6779template <
class Emitter>
6787 return this->emitZero(T, E);
6790template <
class Emitter>
6795 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6796 if (this->LambdaThisCapture.Offset > 0) {
6797 if (this->LambdaThisCapture.IsPtr)
6798 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6799 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6808 return this->emitThis(E);
6823 unsigned StartIndex = 0;
6824 unsigned EndIndex = 0;
6826 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6828 EndIndex = StartIndex;
6835 for (; StartIndex > 0; --StartIndex) {
6846 if (StartIndex == 0 && EndIndex == 0)
6857 assert(StartIndex <= EndIndex);
6860 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6872 case Stmt::CompoundStmtClass:
6874 case Stmt::DeclStmtClass:
6876 case Stmt::ReturnStmtClass:
6878 case Stmt::IfStmtClass:
6880 case Stmt::WhileStmtClass:
6882 case Stmt::DoStmtClass:
6884 case Stmt::ForStmtClass:
6886 case Stmt::CXXForRangeStmtClass:
6888 case Stmt::BreakStmtClass:
6890 case Stmt::ContinueStmtClass:
6892 case Stmt::SwitchStmtClass:
6894 case Stmt::CaseStmtClass:
6896 case Stmt::DefaultStmtClass:
6898 case Stmt::AttributedStmtClass:
6900 case Stmt::CXXTryStmtClass:
6902 case Stmt::NullStmtClass:
6905 case Stmt::GCCAsmStmtClass:
6906 case Stmt::MSAsmStmtClass:
6907 case Stmt::GotoStmtClass:
6908 return this->emitInvalid(S);
6909 case Stmt::LabelStmtClass:
6911 case Stmt::CXXExpansionStmtInstantiationClass:
6915 if (
const auto *E = dyn_cast<Expr>(S))
6922template <
class Emitter>
6925 for (
const auto *InnerStmt : S->
body())
6928 return Scope.destroyLocals();
6931template <
class Emitter>
6932bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6933 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6934 for (
auto *BD : DD->flat_bindings())
6935 if (
auto *KD = BD->getHoldingVar();
6936 KD && !this->visitVarDecl(KD, KD->getInit()))
6950template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6952 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6953 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6960 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6965 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6966 ICE && (ICE->getCastKind() == CK_NoOp ||
6967 ICE->getCastKind() == CK_DerivedToBase ||
6968 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6969 E = ICE->getSubExpr();
6973 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6974 const auto *ThisRecord =
6975 This->getType()->getPointeeType()->getAsRecordDecl();
6976 if (!ThisRecord->isUnion())
6979 if (
const auto *Ctor =
6980 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6981 return Ctor->getParent() == ThisRecord;
6990template <
class Emitter>
6992 bool EvaluateConditionDecl) {
6993 for (
const auto *D : DS->
decls()) {
6998 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6999 assert(ESD->getInstantiations() &&
"not expanded?");
7000 if (!this->
visitStmt(ESD->getInstantiations()))
7005 const auto *VD = dyn_cast<VarDecl>(D);
7012 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
7019template <
class Emitter>
7022 return this->emitUnsupported(RS);
7028 if (!this->
visit(RE))
7034 if (RE->getType()->isVoidType()) {
7035 if (!this->
visit(RE))
7038 if (RE->containsErrors())
7043 if (!this->emitRVOPtr(RE))
7049 return this->emitRetVoid(RS);
7059 return this->emitRetVoid(RS);
7065 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
7072 if (
auto *CondInit = IS->
getInit()) {
7088 return visitChildStmt(IS->
getThen());
7090 return visitChildStmt(Else);
7096 if (!this->emitIsConstantContext(IS))
7099 if (!this->emitIsConstantContext(IS))
7101 if (!this->emitInv(IS))
7115 LabelTy LabelElse = this->getLabel();
7116 LabelTy LabelEnd = this->getLabel();
7117 if (!this->jumpFalse(LabelElse, IS))
7119 if (!visitChildStmt(IS->
getThen()))
7121 if (!this->jump(LabelEnd, IS))
7123 this->emitLabel(LabelElse);
7124 if (!visitChildStmt(Else))
7126 this->emitLabel(LabelEnd);
7128 LabelTy LabelEnd = this->getLabel();
7129 if (!this->jumpFalse(LabelEnd, IS))
7131 if (!visitChildStmt(IS->
getThen()))
7133 this->emitLabel(LabelEnd);
7142template <
class Emitter>
7147 LabelTy CondLabel = this->getLabel();
7148 LabelTy EndLabel = this->getLabel();
7152 this->fallthrough(CondLabel);
7153 this->emitLabel(CondLabel);
7169 if (!this->jumpFalse(EndLabel, S))
7179 if (!this->jump(CondLabel, S))
7181 this->fallthrough(EndLabel);
7182 this->emitLabel(EndLabel);
7191 LabelTy StartLabel = this->getLabel();
7192 LabelTy EndLabel = this->getLabel();
7193 LabelTy CondLabel = this->getLabel();
7197 this->fallthrough(StartLabel);
7198 this->emitLabel(StartLabel);
7204 this->fallthrough(CondLabel);
7205 this->emitLabel(CondLabel);
7212 if (!this->jumpTrue(StartLabel, S))
7215 this->fallthrough(EndLabel);
7216 this->emitLabel(EndLabel);
7220template <
class Emitter>
7228 LabelTy EndLabel = this->getLabel();
7229 LabelTy CondLabel = this->getLabel();
7230 LabelTy IncLabel = this->getLabel();
7237 this->fallthrough(CondLabel);
7238 this->emitLabel(CondLabel);
7250 if (!this->jumpFalse(EndLabel, S))
7259 this->fallthrough(IncLabel);
7260 this->emitLabel(IncLabel);
7266 if (!this->jump(CondLabel, S))
7270 this->emitLabel(EndLabel);
7276template <
class Emitter>
7286 LabelTy EndLabel = this->getLabel();
7287 LabelTy CondLabel = this->getLabel();
7288 LabelTy IncLabel = this->getLabel();
7304 this->fallthrough(CondLabel);
7305 this->emitLabel(CondLabel);
7308 if (!this->jumpFalse(EndLabel, S))
7319 this->fallthrough(IncLabel);
7320 this->emitLabel(IncLabel);
7327 if (!this->jump(CondLabel, S))
7330 this->fallthrough(EndLabel);
7331 this->emitLabel(EndLabel);
7335template <
class Emitter>
7338 return this->emitInvalidTargetLabel(
false, S);
7346 if (LI.BreakLabel) {
7347 TargetLabel = *LI.BreakLabel;
7348 BreakScope = LI.BreakOrContinueScope;
7357 return this->emitInvalidTargetLabel(
false, S);
7360 if (LI.Name == TargetLoop) {
7361 TargetLabel = *LI.BreakLabel;
7362 BreakScope = LI.BreakOrContinueScope;
7373 C =
C->getParent()) {
7374 if (!
C->destroyLocals())
7378 return this->jump(*TargetLabel, S);
7381template <
class Emitter>
7384 return this->emitInvalidTargetLabel(
true, S);
7391 if (LI.ContinueLabel) {
7392 TargetLabel = *LI.ContinueLabel;
7393 ContinueScope = LI.BreakOrContinueScope;
7402 return this->emitInvalidTargetLabel(
true, S);
7405 if (LI.Name == TargetLoop) {
7406 TargetLabel = *LI.ContinueLabel;
7407 ContinueScope = LI.BreakOrContinueScope;
7417 C =
C->getParent()) {
7418 if (!
C->destroyLocals())
7422 return this->jump(*TargetLabel, S);
7425template <
class Emitter>
7435 LabelTy EndLabel = this->getLabel();
7440 if (
const auto *CondInit = S->
getInit())
7449 if (!this->
visit(Cond))
7451 if (!this->emitSetLocal(CondT, CondVar, S))
7461 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7464 if (CS->caseStmtIsGNURange()) {
7465 LabelTy EndOfRangeCheck = this->getLabel();
7466 const Expr *Low = CS->getLHS();
7467 const Expr *High = CS->getRHS();
7471 if (!this->emitGetLocal(CondT, CondVar, CS))
7473 if (!this->
visit(Low))
7476 if (!this->emitGE(
LT, S))
7478 if (!this->jumpFalse(EndOfRangeCheck, S))
7481 if (!this->emitGetLocal(CondT, CondVar, CS))
7483 if (!this->
visit(High))
7486 if (!this->emitLE(HT, S))
7490 this->emitLabel(EndOfRangeCheck);
7495 if (
Value->isValueDependent())
7500 if (!this->emitGetLocal(CondT, CondVar, CS))
7506 if (!this->emitEQ(ValueT, S))
7511 assert(!DefaultLabel);
7512 DefaultLabel = this->getLabel();
7519 if (!this->jump(*DefaultLabel, S))
7522 if (!this->jump(EndLabel, S))
7530 this->fallthrough(EndLabel);
7531 this->emitLabel(EndLabel);
7536template <
class Emitter>
7544 return this->emitUnsupported(S);
7549template <
class Emitter>
7556 if (LI.DefaultLabel) {
7557 DefaultLabel = *LI.DefaultLabel;
7562 this->emitLabel(DefaultLabel);
7566template <
class Emitter>
7573 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7576 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7577 !this->Ctx.getLangOpts().MSVCCompat) {
7579 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7585 const Expr *Assumption = AA->getAssumption();
7596 if (!this->emitAssume(Assumption))
7605 if (IsMSVCConstexprAttr)
7606 return this->emitPopMSVCCE(S);
7610template <
class Emitter>
7623template <
class Emitter>
7633 LabelTy EndLabel = this->getLabel();
7635 LabelTy ContinueLabel = this->getLabel();
7640 this->emitLabel(ContinueLabel);
7643 this->emitLabel(EndLabel);
7648template <
class Emitter>
7649bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7656 assert(ClosureClass->
captures().empty());
7660 "A generic lambda's static-invoker function must be a "
7661 "template specialization");
7665 llvm::FoldingSetInsertToken InsertToken;
7666 const FunctionDecl *CorrespondingCallOpSpecialization =
7668 assert(CorrespondingCallOpSpecialization);
7669 LambdaCallOp = CorrespondingCallOpSpecialization;
7673 assert(ClosureClass->
captures().empty());
7674 const Function *
Func = this->getFunction(LambdaCallOp);
7677 assert(
Func->hasThisPointer());
7680 if (
Func->hasRVO()) {
7681 if (!this->emitRVOPtr(MD))
7689 if (!this->emitNullPtr(0,
nullptr, MD))
7694 auto It = this->Params.find(PVD);
7695 assert(It != this->Params.end());
7699 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7700 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7704 if (!this->emitCall(
Func, 0, LambdaCallOp))
7709 return this->emitRet(*ReturnType, MD);
7712 return this->emitRetVoid(MD);
7715template <
class Emitter>
7716bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7717 if (Ctx.getLangOpts().CPlusPlus23)
7727 const Expr *InitExpr =
Init->getInit();
7729 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7733 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7743template <
class Emitter>
7745 assert(!ReturnType);
7748 if (!this->emitStartThisLifetime1(Ctor))
7751 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7752 const Expr *InitExpr,
7755 if (InitExpr->getType().isNull())
7759 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7762 if (!this->visit(InitExpr))
7765 if (F->isBitField())
7766 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
7768 return this->emitInitThisField(*T, FieldOffset, InitExpr);
7773 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7776 if (
Activate && !this->emitActivate(InitExpr))
7779 return this->visitInitializerPop(InitExpr);
7783 const Record *
R = this->getRecord(RD);
7786 bool IsUnion =
R->isUnion();
7796 if (!this->emitThis(Ctor))
7799 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7802 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7803 this->emitRetVoid(Ctor);
7806 unsigned FieldInits = 0;
7809 if (
R->getNumVirtualBases() > 0) {
7810 if (!this->emitThis(Ctor))
7812 LabelTy AfterVirtBasesLabel = this->getLabel();
7815 if (!this->emitIsBaseClass({}))
7817 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7820 for (
const auto *
Init : Ctor->
inits()) {
7821 LocalScope<Emitter> VirtLocalScope(
this);
7824 const auto *BaseDecl =
Base->castAsCXXRecordDecl();
7825 assert(
R->findVirtualBase(BaseDecl));
7826 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7828 if (!this->visitInitializerPop(
Init->getInit()))
7833 this->fallthrough(AfterVirtBasesLabel);
7834 this->emitLabel(AfterVirtBasesLabel);
7836 if (!this->emitPopPtr(Ctor))
7840 for (
const auto *
Init : Ctor->
inits()) {
7844 const Expr *InitExpr =
Init->getInit();
7846 const Record::Field *F =
R->getField(
Member);
7850 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7854 const auto *BaseDecl =
Base->castAsCXXRecordDecl();
7856 if (
Init->isBaseVirtual()) {
7862 const Record::Base *B =
R->getBase(BaseDecl);
7864 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7868 if (!this->visitInitializerPop(InitExpr))
7873 unsigned ChainSize = IFD->getChainingSize();
7874 assert(ChainSize >= 2);
7876 unsigned NestedFieldOffset = 0;
7877 const Record::Field *NestedField =
nullptr;
7878 for (
unsigned I = 0; I != ChainSize; ++I) {
7880 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7881 assert(FieldRecord);
7883 NestedField = FieldRecord->
getField(FD);
7884 assert(NestedField);
7885 IsUnion = IsUnion || FieldRecord->
isUnion();
7887 NestedFieldOffset += NestedField->Offset;
7890 if (I != ChainSize - 1)
7893 assert(NestedField);
7896 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7901 unsigned InitFieldOffset = 0;
7902 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7904 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7905 assert(FieldRecord);
7906 NestedField = FieldRecord->
getField(FD);
7907 InitFieldOffset += NestedField->Offset;
7908 assert(NestedField);
7909 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7911 if (!this->emitFinishInitPop(InitExpr))
7915 InitStack.pop_back_n(ChainSize - 1);
7918 assert(
Init->isDelegatingInitializer());
7919 if (!this->emitThis(InitExpr))
7921 if (!this->visitInitializerPop(
Init->getInit()))
7925 if (!
Scope.destroyLocals())
7929 if (FieldInits !=
R->getNumFields()) {
7930 assert(FieldInits < R->getNumFields());
7932 if (!this->emitStartThisLifetime(Ctor))
7939 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7940 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7947 if (!visitStmt(Body))
7954template <
class Emitter>
7957 const Record *
R = this->getRecord(RD);
7961 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7964 LabelTy EpilogLabel = this->getLabel();
7967 if (!this->visitStmt(
Dtor->getBody()))
7970 this->fallthrough(EpilogLabel);
7971 this->emitLabel(EpilogLabel);
7974 if (!this->emitThis(
Dtor))
7977 if (!this->emitCheckDestruction(
Dtor))
7981 if (!
R->isUnion()) {
7985 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7989 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7991 if (!this->emitDestructionPop(D,
SourceInfo{}))
7996 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7997 if (
Base.R->hasTrivialDtor())
8001 if (!this->emitRecordDestructionPop(
Base.R, {}))
8005 if (
R->getNumVirtualBases() > 0) {
8006 LabelTy EndLabel = this->getLabel();
8008 if (!this->emitIsBaseClass({}))
8010 if (!this->jumpTrue(EndLabel, {}))
8013 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
8014 if (
Base.R->hasTrivialDtor())
8019 if (!this->emitRecordDestructionPop(
Base.R, {}))
8023 this->fallthrough(EndLabel);
8024 this->emitLabel(EndLabel);
8027 if (!this->emitMarkDestroyed(
Dtor))
8030 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
8033template <
class Emitter>
8034bool Compiler<Emitter>::compileUnionAssignmentOperator(
8036 if (!this->emitThis(MD))
8039 if (!this->emitGetParam(
PT_Ptr, 0, MD))
8042 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
8045template <
class Emitter>
8055 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
8056 return this->compileConstructor(Ctor);
8057 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
8058 return this->compileDestructor(
Dtor);
8061 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
8066 return this->compileUnionAssignmentOperator(MD);
8069 return this->emitLambdaStaticInvokerBody(MD);
8073 if (
const auto *Body = F->
getBody())
8087 return FD->getBitWidthValue();
8090template <
class Emitter>
8106 if (!
Ctx.getLangOpts().CPlusPlus14)
8107 return this->emitInvalid(E);
8109 return this->emitError(E);
8111 if (!this->
visit(SubExpr))
8115 if (!this->emitIncPtr(E))
8122 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
8123 : this->emitIncf(getFPOptions(E), E);
8135 if (!
Ctx.getLangOpts().CPlusPlus14)
8136 return this->emitInvalid(E);
8138 return this->emitError(E);
8140 if (!this->
visit(SubExpr))
8144 if (!this->emitDecPtr(E))
8151 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
8152 : this->emitDecf(getFPOptions(E), E);
8165 if (!
Ctx.getLangOpts().CPlusPlus14)
8166 return this->emitInvalid(E);
8168 return this->emitError(E);
8170 if (!this->
visit(SubExpr))
8174 if (!this->emitLoadPtr(E))
8176 if (!this->emitConstUint8(1, E))
8178 if (!this->emitAddOffsetUint8(E))
8180 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8186 return this->emitIncfPop(getFPOptions(E), E);
8196 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8197 if (!this->emitLoadFloat(E))
8199 APFloat F(TargetSemantics, 1);
8200 if (!this->emitFloat(F, E))
8203 if (!this->emitAddf(getFPOptions(E), E))
8205 if (!this->emitStoreFloat(E))
8217 return E->
isGLValue() || this->emitLoadPop(*T, E);
8220 if (!
Ctx.getLangOpts().CPlusPlus14)
8221 return this->emitInvalid(E);
8223 return this->emitError(E);
8225 if (!this->
visit(SubExpr))
8229 if (!this->emitLoadPtr(E))
8231 if (!this->emitConstUint8(1, E))
8233 if (!this->emitSubOffsetUint8(E))
8235 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8241 return this->emitDecfPop(getFPOptions(E), E);
8251 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8252 if (!this->emitLoadFloat(E))
8254 APFloat F(TargetSemantics, 1);
8255 if (!this->emitFloat(F, E))
8258 if (!this->emitSubf(getFPOptions(E), E))
8260 if (!this->emitStoreFloat(E))
8272 return E->
isGLValue() || this->emitLoadPop(*T, E);
8276 return this->emitError(E);
8279 return this->
discard(SubExpr);
8284 if (!this->emitInv(E))
8288 return this->emitCast(
PT_Bool, ET, E);
8292 return this->emitError(E);
8294 if (!this->
visit(SubExpr))
8296 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
8299 return this->emitError(E);
8301 if (!this->
visit(SubExpr))
8317 if (!
Ctx.getLangOpts().CPlusPlus) {
8320 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8321 Deref && Deref->getOpcode() == UO_Deref) {
8323 return this->
discard(Deref->getSubExpr());
8324 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8329 return this->
discard(SubExpr);
8330 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8333 return this->
discard(SubExpr);
8335 if (!this->
visit(SubExpr))
8342 return this->emitNarrowPtr(E);
8347 return this->emitError(E);
8349 if (!this->
visit(SubExpr))
8351 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
8363 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
8368 assert(
false &&
"Unhandled opcode");
8374template <
class Emitter>
8380 return this->
discard(SubExpr);
8383 auto prepareResult = [=]() ->
bool {
8388 return this->emitGetPtrLocal(*LocalIndex, E);
8395 unsigned SubExprOffset = ~0u;
8396 auto createTemp = [=, &SubExprOffset]() ->
bool {
8399 if (!this->
visit(SubExpr))
8401 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8405 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8406 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8408 return this->emitArrayElemPop(ElemT, Index, E);
8413 if (!prepareResult())
8417 for (
unsigned I = 0; I != 2; ++I) {
8418 if (!getElem(SubExprOffset, I))
8420 if (!this->emitNeg(ElemT, E))
8422 if (!this->emitInitElem(ElemT, I, E))
8433 if (!this->
visit(SubExpr))
8435 if (!this->emitComplexBoolCast(SubExpr))
8437 if (!this->emitInv(E))
8440 return this->emitCast(
PT_Bool, ET, E);
8444 return this->emitComplexReal(SubExpr);
8447 if (!this->
visit(SubExpr))
8451 if (!this->emitConstUint8(1, E))
8453 return this->emitArrayElemPtrPopUint8(E);
8464 if (!this->emitArrayElem(ElemT, 1, E))
8466 if (!this->emitNeg(ElemT, E))
8468 if (!this->emitInitElem(ElemT, 1, E))
8476 return this->emitInvalid(E);
8482template <
class Emitter>
8488 return this->
discard(SubExpr);
8491 if (UnaryOp == UO_Extension)
8494 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8495 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8496 return this->emitInvalid(E);
8499 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8506 if (!this->emitGetPtrLocal(*LocalIndex, E))
8511 unsigned SubExprOffset =
8513 if (!this->
visit(SubExpr))
8515 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8520 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8521 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8523 return this->emitArrayElemPop(ElemT, Index, E);
8528 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8529 if (!getElem(SubExprOffset, I))
8531 if (!this->emitNeg(ElemT, E))
8533 if (!this->emitInitElem(ElemT, I, E))
8548 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8549 if (!getElem(SubExprOffset, I))
8552 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8554 if (!this->emitInv(E))
8556 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8558 if (!this->emitNeg(ElemT, E))
8560 if (ElemT != ResultVecElemT &&
8561 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8563 if (!this->emitInitElem(ResultVecElemT, I, E))
8569 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8570 if (!getElem(SubExprOffset, I))
8573 if (!this->emitInv(E))
8576 if (!this->emitComp(ElemT, E))
8579 if (!this->emitInitElem(ElemT, I, E))
8584 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8589template <
class Emitter>
8591 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8594 return this->emitConst(ECD->getInitVal(), E);
8596 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8600 return F && this->emitGetFnPtr(F, E);
8602 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8603 TPOD = TPOD->getFirstDecl();
8607 return this->emitGetPtrGlobal(*GlobalIndex, E);
8613 return this->emitInitGlobal(*T, *Index, E);
8616 if (!this->emitGetPtrGlobal(*Index, E))
8620 return this->emitFinishInit(E);
8632 auto maybePopPtr = [&]() ->
bool {
8634 return this->emitPopPtr(E);
8641 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8645 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8650 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8651 if (IsReference || !It->second.IsPtr)
8652 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8654 return this->emitGetPtrParam(It->second.Index, E);
8657 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8664 const unsigned Offset = It->second.Offset;
8667 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8669 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8672 if (
auto GlobalIndex =
P.getGlobal(D)) {
8674 if (!
Ctx.getLangOpts().CPlusPlus11)
8675 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8676 if (!
Ctx.getLangOpts().CPlusPlus23)
8677 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8679 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8682 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8686 auto revisit = [&](
const VarDecl *VD,
8687 bool IsConstexprUnknown =
true) ->
bool {
8689 IsConstexprUnknown);
8690 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8696 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8697 if (!this->emitPopCC(E))
8701 if (VarState.notCreated())
8709 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8711 if (
auto It = this->LambdaCaptures.find(D);
8712 It != this->LambdaCaptures.end()) {
8713 auto [Offset, IsPtr] = It->second;
8716 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8717 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8721 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8722 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8723 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8727 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8728 return this->
delegate(BD->getBinding());
8734 return this->emitDummyPtr(D, E);
8739 const auto *VD = dyn_cast<VarDecl>(D);
8741 return this->emitError(E);
8744 if (!
Ctx.getLangOpts().CPlusPlus) {
8748 return revisit(VD,
false);
8752 return this->emitDummyPtr(D, E);
8756 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8757 if (T.isConstant(
Ctx.getASTContext()))
8759 return T->isReferenceType();
8763 typeShouldBeVisited(DeclType)) {
8765 Init && !
Init->isValueDependent()) {
8770 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8783 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8788 return revisit(VD, IsConstexprUnknown);
8789 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8790 return revisit(VD,
true);
8799 return this->emitDummyPtr(
8803template <
class Emitter>
8809template <
class Emitter>
8819 if (!
C->destroyLocals())
8825template <
class Emitter>
8826unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8829 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8831 return Ty->castAsCXXRecordDecl();
8833 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8834 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8836 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8840template <
class Emitter>
8847 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8852 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8853 getFPOptions(E), E);
8855 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8856 getFPOptions(E), E);
8860 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8865 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8867 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8871 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8875 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8876 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8883template <
class Emitter>
8886 assert(FromT != ToT);
8889 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8891 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8893 return this->emitCast(FromT, ToT, E);
8897template <
class Emitter>
8898bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8902 return this->
discard(SubExpr);
8904 if (!this->visit(SubExpr))
8907 if (!this->emitConstUint8(0, SubExpr))
8909 return this->emitArrayElemPtrPopUint8(SubExpr);
8913 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8917template <
class Emitter>
8918bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8919 assert(!DiscardResult);
8923 if (!this->emitArrayElem(ElemT, 0, E))
8926 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8929 if (!this->emitCast(ElemT,
PT_Bool, E))
8934 LabelTy LabelTrue = this->getLabel();
8935 if (!this->jumpTrue(LabelTrue, E))
8938 if (!this->emitArrayElemPop(ElemT, 1, E))
8941 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8944 if (!this->emitCast(ElemT,
PT_Bool, E))
8948 LabelTy EndLabel = this->getLabel();
8949 this->jump(EndLabel, E);
8951 this->emitLabel(LabelTrue);
8952 if (!this->emitPopPtr(E))
8954 if (!this->emitConstBool(
true, E))
8957 this->fallthrough(EndLabel);
8958 this->emitLabel(EndLabel);
8963template <
class Emitter>
8964bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8975 LHSIsComplex =
true;
8976 ElemT = classifyComplexElementType(LHS->
getType());
8977 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8978 if (!this->visit(LHS))
8980 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8983 LHSIsComplex =
false;
8985 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8986 if (!this->visit(LHS))
8988 if (!this->emitSetLocal(LHST, LHSOffset, E))
8995 RHSIsComplex =
true;
8996 ElemT = classifyComplexElementType(RHS->
getType());
8997 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8998 if (!this->visit(RHS))
9000 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
9003 RHSIsComplex =
false;
9005 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
9006 if (!this->visit(RHS))
9008 if (!this->emitSetLocal(RHST, RHSOffset, E))
9012 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
9013 bool IsComplex) ->
bool {
9015 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
9017 return this->emitArrayElemPop(ElemT, Index, E);
9019 return this->emitGetLocal(ElemT, LocalOffset, E);
9022 for (
unsigned I = 0; I != 2; ++I) {
9024 if (!getElem(LHSOffset, I, LHSIsComplex))
9026 if (!getElem(RHSOffset, I, RHSIsComplex))
9029 if (!this->emitEQ(ElemT, E))
9032 if (!this->emitCastBoolUint8(E))
9037 if (!this->emitAddUint8(E))
9039 if (!this->emitConstUint8(2, E))
9043 if (!this->emitEQUint8(E))
9046 if (!this->emitNEUint8(E))
9053 return this->emitCast(
PT_Bool, ResT, E);
9060template <
class Emitter>
9061bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
9064 assert(!
R->hasTrivialDtor());
9067 const Function *DtorFunc = getFunction(
Dtor);
9070 assert(DtorFunc->hasThisPointer());
9071 assert(DtorFunc->getNumParams() == 1);
9072 return this->emitCall(DtorFunc, 0, Loc);
9077template <
class Emitter>
9078bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
9090 return this->emitPopPtr(Loc);
9092 for (ssize_t I = N - 1; I >= 1; --I) {
9093 if (!this->emitConstUint64(I, Loc))
9095 if (!this->emitArrayElemPtrUint64(Loc))
9097 if (!this->emitDestructionPop(ElemDesc, Loc))
9101 if (!this->emitConstUint64(0, Loc))
9103 if (!this->emitArrayElemPtrPopUint64(Loc))
9105 return this->emitDestructionPop(ElemDesc, Loc);
9110 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
9115template <
class Emitter>
9116bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
9117 assert(!DiscardResult &&
"Should've been checked before");
9118 return this->emitGetOpaquePtr(D, CU, E);
9121template <
class Emitter>
9124 return this->emitConstFloat(
Floating(F), Info);
9126 APInt I = F.bitcastToAPInt();
9127 return this->emitConstFloat(
9129 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
9140template <
class Emitter>
9141bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
9154 if (!this->emitGetPtrLocal(*LocalIndex, E))
9164 if (!this->visit(SubExpr))
9166 }
else if (
OptPrimType FromT = classify(SubExpr)) {
9167 unsigned TempOffset =
9168 allocateLocalPrimitive(SubExpr, *FromT,
true);
9169 if (!this->visit(SubExpr))
9171 if (!this->emitSetLocal(*FromT, TempOffset, E))
9173 if (!this->emitGetPtrLocal(TempOffset, E))
9180 if (!this->emitBitCast(E))
9182 return DiscardResult ? this->emitPopPtr(E) :
true;
9186 const llvm::fltSemantics *TargetSemantics =
nullptr;
9188 TargetSemantics = &Ctx.getFloatSemantics(ToType);
9194 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
9196 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
9197 ResultBitWidth, TargetSemantics,
9202 return this->emitPop(*ToT, E);
9211template <
class Emitter>
9212bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
9217 unsigned NumElems = 0;
9220 NumElems = VT->getNumElements();
9221 ElemType = VT->getElementType();
9223 NumElems = MT->getNumElementsFlattened();
9224 ElemType = MT->getElementType();
9227 PrimType ElemT = classifyPrim(ElemType);
9228 for (
unsigned I = 0; I != NumElems; ++I) {
9229 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9231 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
9233 if (!this->emitInitElem(ElemT, I, E))
9243 QualType ArrElemType = CAT->getElementType();
9244 unsigned ArrSize = CAT->getZExtSize();
9247 for (
unsigned I = 0; I != ArrSize; ++I) {
9248 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9250 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9252 if (!this->emitInitElem(*ElemT, I, E))
9256 for (
unsigned I = 0; I != ArrSize; ++I) {
9257 if (!this->emitConstUint32(I, E))
9259 if (!this->emitArrayElemPtrUint32(E))
9261 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9263 if (!this->emitFinishInitPop(E))
9273 const Record *
R = getRecord(DestType);
9277 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9279 const Record::Base *B =
R->getBase(BS.getType());
9281 if (!this->emitGetPtrBase(B->Offset, E))
9283 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9285 if (!this->emitFinishInitPop(E))
9290 for (
const Record::Field &F :
R->fields()) {
9291 if (F.isUnnamedBitField())
9294 QualType FieldType = F.Decl->getType();
9296 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9298 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9300 if (F.isBitField()) {
9301 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9304 if (!this->emitInitField(*FieldT, F.Offset, E))
9308 if (!this->emitGetPtrField(F.Offset, E))
9310 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9312 if (!this->emitPopPtr(E))
9325template <
class Emitter>
9326unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9329 return VT->getNumElements();
9331 return MT->getNumElementsFlattened();
9335 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9339 const Record *
R = getRecord(Ty);
9343 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9345 Count += countHLSLFlatElements(BS.getType());
9347 for (
const Record::Field &F :
R->fields()) {
9348 if (F.isUnnamedBitField())
9350 Count += countHLSLFlatElements(F.Decl->getType());
9355 if (canClassify(Ty))
9364template <
class Emitter>
9365bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9366 QualType SrcType,
unsigned SrcOffset,
9371 auto saveToLocal = [&](
PrimType T) ->
bool {
9372 unsigned Offset = allocateLocalPrimitive(E, T,
true);
9373 if (!this->emitSetLocal(T, Offset, E))
9375 Elements.push_back({Offset, T});
9381 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9382 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9383 return std::nullopt;
9388 unsigned NumElems = 0;
9391 NumElems = VT->getNumElements();
9392 ElemType = VT->getElementType();
9394 NumElems = MT->getNumElementsFlattened();
9395 ElemType = MT->getElementType();
9398 PrimType ElemT = classifyPrim(ElemType);
9399 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9400 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9402 if (!this->emitArrayElemPop(ElemT, I, E))
9404 if (!saveToLocal(ElemT))
9414 QualType ArrElemType = CAT->getElementType();
9415 unsigned ArrSize = CAT->getZExtSize();
9418 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9419 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9421 if (!this->emitArrayElemPop(*ElemT, I, E))
9423 if (!saveToLocal(*ElemT))
9427 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9428 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9430 if (!this->emitConstUint32(I, E))
9432 if (!this->emitArrayElemPtrPopUint32(E))
9437 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9448 const Record *
R = getRecord(SrcType);
9452 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9454 if (Elements.size() >= MaxElements)
9456 const Record::Base *B =
R->getBase(BS.getType());
9458 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9460 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9465 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9471 for (
const Record::Field &F :
R->fields()) {
9472 if (Elements.size() >= MaxElements)
9474 if (F.isUnnamedBitField())
9477 QualType FieldType = F.Decl->getType();
9478 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9480 if (!this->emitGetPtrFieldPop(F.Offset, E))
9484 if (!this->emitLoadPop(*FieldT, E))
9486 if (!saveToLocal(*FieldT))
9490 if (!FieldPtrOffset)
9492 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9508template <
class Emitter>
9509bool Compiler<Emitter>::emitHLSLConstructAggregate(
9515 const auto &Src = Elements[ElemIdx++];
9516 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9518 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9522 unsigned NumElems = 0;
9525 NumElems = VT->getNumElements();
9526 ElemType = VT->getElementType();
9528 NumElems = MT->getNumElementsFlattened();
9529 ElemType = MT->getElementType();
9532 PrimType DestElemT = classifyPrim(ElemType);
9533 for (
unsigned I = 0; I != NumElems; ++I) {
9534 if (!loadAndCast(DestElemT, ElemType))
9536 if (!this->emitInitElem(DestElemT, I, E))
9546 QualType ArrElemType = CAT->getElementType();
9547 unsigned ArrSize = CAT->getZExtSize();
9550 for (
unsigned I = 0; I != ArrSize; ++I) {
9551 if (!loadAndCast(*ElemT, ArrElemType))
9553 if (!this->emitInitElem(*ElemT, I, E))
9557 for (
unsigned I = 0; I != ArrSize; ++I) {
9558 if (!this->emitConstUint32(I, E))
9560 if (!this->emitArrayElemPtrUint32(E))
9562 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9564 if (!this->emitFinishInitPop(E))
9574 const Record *
R = getRecord(DestType);
9578 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9580 const Record::Base *B =
R->getBase(BS.getType());
9582 if (!this->emitGetPtrBase(B->Offset, E))
9584 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9586 if (!this->emitFinishInitPop(E))
9591 for (
const Record::Field &F :
R->fields()) {
9592 if (F.isUnnamedBitField())
9595 QualType FieldType = F.Decl->getType();
9597 if (!loadAndCast(*FieldT, FieldType))
9599 if (F.isBitField()) {
9600 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9603 if (!this->emitInitField(*FieldT, F.Offset, E))
9607 if (!this->emitGetPtrField(F.Offset, E))
9609 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9611 if (!this->emitPopPtr(E))
static bool visitAPValue(const APValue &Value, llvm::function_ref< bool(const APValue &)> Visitor)
static bool emit(llvm::SmallVectorImpl< std::byte > &Code, const T &Val)
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)
static CharUnits alignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
#define EMIT_ARITH_OP(OP)
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.
unsigned ConvertBuiltinIDToX86BuiltinID(const ASTContext &Ctx, unsigned BuiltinOp)
Convert a builtin ID to the canonical x86 builtin ID the constant evaluators dispatch on in their x86...
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
APSInt & getComplexIntImag()
unsigned getStructNumFields() const
bool isComplexInt() const
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() const
bool hasLValuePath() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
CharUnits & getLValueOffset()
bool isComplexFloat() const
APValue & getVectorElt(unsigned I)
APValue & getArrayFiller()
unsigned getVectorLength() const
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
APSInt & getComplexIntReal()
APFloat & getComplexFloatImag()
APFloat & getComplexFloatReal()
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 isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
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.
Represents a C++26 reflect expression [expr.reflect].
ReflectionKind getKind() const
const void * getOpaqueValue() const
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
This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits 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.
An expression that occurs in a constant context and the result of evaluating the expression.
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()
An instance of this object exists for each enum constant that is defined.
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.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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()
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
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.
Symbolic representation of typeid(T) for some type T.
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)
std::optional< Scope::Local > allocateLocalUnscoped(DeclOrExpr Decl, QualType Ty=QualType())
Like allocateLocal(), but doesn't add the local to a scope.
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.
bool VisitCXXReflectExpr(const CXXReflectExpr *E)
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 registerRedecl(const VarDecl *VD, const APValue &V)
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)
OptLabelTy DtorEpilogLabel
In a destructor body: where a return jumps to, so the subobjects are still destroyed.
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()
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.
RegisterLocalScope(Compiler< Emitter > *Ctx, Scope::Local Local, ScopeKind VarScope=ScopeKind::Block)
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
uint16_t getPointerAuthTypeDiscriminator(CodeGenModule &CGM, QualType FunctionType)
Return a type discriminator for the given function type.
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)
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)
static bool exceedsArraySizeLimit(const LangOptions &LangOpts, uint64_t NumElems)
Whether the CheckArraySize op rejects an array with NumElems elements.
bool Init(InterpState &S, CodePtr OpPC)
bool DefaultInit(InterpState &S, CodePtr OpPC, const CXXConstructorDecl *Ctor)
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
U cast(CodeGen::Address addr)
int const char * function
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_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()