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;
76 llvm_unreachable(
"Shouldn't be called");
142 this->
Ctx->emitDestroy(*
Idx, E);
149 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
150 this->
Ctx->Descriptors.emplace_back();
152 if constexpr (!std::is_same_v<Emitter, EvalEmitter>)
153 this->
Ctx->emitInitScope(*
Idx, {});
167 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
168 this->
Ctx->Descriptors.emplace_back();
169 if constexpr (!std::is_same_v<Emitter, EvalEmitter>)
170 this->
Ctx->emitInitScope(*
Idx, {});
181 if (
Local.Desc->hasTrivialDtor())
184 if (!
Local.EnabledByDefault) {
185 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
186 if (!this->
Ctx->emitGetLocalEnabled(
Local.Offset, E))
188 if (!this->
Ctx->jumpFalse(EndLabel, E))
191 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
194 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
197 this->
Ctx->fallthrough(EndLabel);
198 this->
Ctx->emitLabel(EndLabel);
200 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
202 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
221 if (
const auto *OVE =
222 llvm::dyn_cast_if_present<OpaqueValueExpr>(
Local.Desc->asExpr())) {
223 this->
Ctx->OpaqueExprs.erase(OVE);
235 OldArrayIndex = Ctx->ArrayIndex;
236 Ctx->ArrayIndex = Index;
243 std::optional<uint64_t> OldArrayIndex;
251 if (!Ctx->SourceLocDefaultExpr) {
253 Ctx->SourceLocDefaultExpr = DefaultExpr;
259 Ctx->SourceLocDefaultExpr =
nullptr;
264 bool Enabled =
false;
270 Ctx->InitStack.push_back(std::move(
Link));
282 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
285 Ctx->InitStackActive = OldValue || Active;
291 this->Ctx->InitStackActive = OldValue;
293 Ctx->InitStack.pop_back();
307 OldInitializingDecl(
Ctx->InitializingDecl) {
308 Ctx->InitializingDecl = VD;
313 this->
Ctx->InitializingDecl = OldInitializingDecl;
314 this->
Ctx->InitStack.pop_back();
319 const VarDecl *OldInitializingDecl;
327 bool NewInitializing,
bool NewToLValue)
328 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
329 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
330 Ctx->DiscardResult = NewDiscardResult;
331 Ctx->Initializing = NewInitializing;
332 Ctx->ToLValue = NewToLValue;
336 Ctx->DiscardResult = OldDiscardResult;
337 Ctx->Initializing = OldInitializing;
338 Ctx->ToLValue = OldToLValue;
345 bool OldDiscardResult;
346 bool OldInitializing;
350template <
class Emitter>
354 return Ctx->emitThis(E);
357 return Ctx->emitGetPtrFieldPop(
Offset, E);
359 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
361 return Ctx->emitGetPtrLocal(
Offset, E);
365 if (!Ctx->emitConstUint32(
Offset, E))
367 return Ctx->emitArrayElemPtrPopUint32(E);
369 return Ctx->emitRVOPtr(E);
373 llvm_unreachable(
"Unhandled InitLink kind");
389 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
390 assert(LI.Name != Name);
393 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
414 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
416 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
417 assert(LI.Name != Name);
420 this->Ctx->CaseLabels = std::move(CaseLabels);
421 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
423 DefaultLabel, Ctx->VarScope);
427 this->Ctx->CaseLabels = std::move(OldCaseLabels);
428 this->Ctx->LabelInfoStack.pop_back();
433 CaseMap OldCaseLabels;
444 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
447 Ctx->LocOverride = NewValue;
452 Ctx->LocOverride = OldFlag;
457 std::optional<SourceInfo> OldFlag;
464template <
class Emitter>
472 case CK_LValueToRValue: {
480 if (!this->
visit(SubExpr))
482 return this->emitLoadPopL(E);
492 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
498 if (
auto GlobalIndex =
P.getGlobal(D))
499 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
500 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
501 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
502 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
503 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
504 return this->emitGetParam(*SubExprT, It->second.Index, E);
516 if (!this->emitGetPtrLocal(*LocalIndex, E))
520 if (!this->
visit(SubExpr))
524 return this->emitLoadPop(*SubExprT, E);
529 return this->emitMemcpy(E);
532 case CK_DerivedToBaseMemberPointer: {
543 ->getMostRecentCXXRecordDecl();
545 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
546 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
548 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
556 case CK_BaseToDerivedMemberPointer: {
567 ->getMostRecentCXXRecordDecl();
571 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
573 PathI != PathE; ++PathI) {
574 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
575 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
577 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
584 assert(ToDecl != CurDecl);
585 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
587 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
593 case CK_UncheckedDerivedToBase:
594 case CK_DerivedToBase: {
599 if (
const auto *PT = dyn_cast<PointerType>(Ty))
600 return PT->getPointeeType()->getAsCXXRecordDecl();
601 return Ty->getAsCXXRecordDecl();
608 if (B->isVirtual()) {
609 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
611 CurType = B->getType();
613 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
614 if (!this->emitGetPtrBasePop(
617 CurType = B->getType();
624 case CK_BaseToDerived: {
628 auto unwrapPointerType = [](
const Type *
T) ->
const Type * {
629 if (
T->isPointerOrReferenceType())
630 return T->getPointeeType().getTypePtr();
642 llvm::drop_begin(llvm::reverse(E->
path()))) {
643 const Type *TargetType = unwrapPointerType(B->getType().getTypePtr());
644 if (!this->emitGetPtrDerivedPop(NullOK, TargetType, FinalType, E))
648 return this->emitGetPtrDerivedPop(NullOK, FinalType, FinalType, E);
651 case CK_FloatingCast: {
654 return this->emitVectorConversion(E->
getSubExpr(), E);
658 if (!this->
visit(SubExpr))
660 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
664 case CK_IntegralToFloating: {
666 return this->emitVectorConversion(E->
getSubExpr(), E);
669 if (!this->
visit(SubExpr))
671 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
672 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
673 TargetSemantics, getFPOptions(E), E);
676 case CK_FloatingToBoolean: {
678 return this->emitVectorConversion(E->
getSubExpr(), E);
682 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
683 return this->emitConstBool(FL->getValue().isNonZero(), E);
684 if (!this->
visit(SubExpr))
686 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
689 case CK_FloatingToIntegral: {
691 return this->emitVectorConversion(E->
getSubExpr(), E);
694 if (!this->
visit(SubExpr))
698 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
701 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
704 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
707 case CK_NullToPointer:
708 case CK_NullToMemberPointer: {
711 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
716 case CK_PointerToIntegral: {
717 if (!this->
visit(SubExpr))
723 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
729 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
731 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
732 return this->emitCastPointerIntegral(
T, E);
735 case CK_ArrayToPointerDecay: {
736 if (!this->
visit(SubExpr))
738 return this->emitArrayDecay(E);
741 case CK_IntegralToPointer: {
743 assert(IntType->isIntegralOrEnumerationType());
744 if (!this->
visit(SubExpr))
758 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
761 case CK_AtomicToNonAtomic:
762 case CK_ConstructorConversion:
763 case CK_FunctionToPointerDecay:
764 case CK_NonAtomicToAtomic:
766 case CK_UserDefinedConversion:
767 case CK_CPointerToObjCPointerCast:
770 case CK_AddressSpaceConversion: {
774 if (!this->
visit(SubExpr))
779 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
786 return this->emitPopPtr(E);
804 return this->emitBuiltinBitCast(E);
819 if (!this->
visit(SubExpr))
827 return this->emitFnPtrCast(E);
835 if (!this->
visit(SubExpr))
837 return this->emitDecayPtr(*FromT, *ToT, E);
839 case CK_IntegralToBoolean:
840 case CK_FixedPointToBoolean: {
842 return this->emitVectorConversion(E->
getSubExpr(), E);
848 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
849 return this->emitConst(IL->getValue(), E);
850 if (!this->
visit(SubExpr))
855 case CK_IntegralCast:
857 return this->emitVectorConversion(E->
getSubExpr(), E);
859 case CK_BooleanToSignedIntegral: {
866 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
871 if (!this->emitConst(IL->getValue(), SubExpr))
874 if (!this->
visit(SubExpr))
882 if (!ED->isFixed()) {
883 if (!this->emitCheckEnumValue(*FromT, ED, E))
889 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
892 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
897 if (!this->emitCast(*FromT, *ToT, E))
900 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
901 return this->emitNeg(*ToT, E);
905 case CK_PointerToBoolean:
906 if (!this->
visit(SubExpr))
908 return this->emitIsNonNullPtr(E);
910 case CK_MemberPointerToBoolean:
911 if (!this->
visit(SubExpr))
913 return this->emitIsNonNullMemberPtr(E);
915 case CK_IntegralComplexToBoolean:
916 case CK_FloatingComplexToBoolean: {
917 if (!this->
visit(SubExpr))
919 return this->emitComplexBoolCast(SubExpr);
922 case CK_IntegralComplexToReal:
923 case CK_FloatingComplexToReal:
924 return this->emitComplexReal(SubExpr);
926 case CK_IntegralRealToComplex:
927 case CK_FloatingRealToComplex: {
934 if (!this->emitGetPtrLocal(*LocalIndex, E))
943 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
945 return this->emitInitElem(
T, 1, SubExpr);
948 case CK_IntegralComplexCast:
949 case CK_FloatingComplexCast:
950 case CK_IntegralComplexToFloatingComplex:
951 case CK_FloatingComplexToIntegralComplex: {
958 if (!this->emitGetPtrLocal(*LocalIndex, E))
965 unsigned SubExprOffset =
967 if (!this->
visit(SubExpr))
969 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
977 for (
unsigned I = 0; I != 2; ++I) {
978 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
980 if (!this->emitArrayElemPop(SourceElemT, I, E))
984 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
988 if (!this->emitInitElem(DestElemT, I, E))
994 case CK_VectorSplat: {
1005 if (!this->emitGetPtrLocal(*LocalIndex, E))
1011 unsigned ElemOffset =
1015 if (!this->
visit(SubExpr))
1020 if (!this->emitSetLocal(ElemT, ElemOffset, E))
1023 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
1024 if (!this->emitGetLocal(ElemT, ElemOffset, E))
1026 if (!this->emitInitElem(ElemT, I, E))
1033 case CK_HLSLVectorTruncation: {
1038 if (!this->
visit(SubExpr))
1040 return this->emitArrayElemPop(*ResultT, 0, E);
1049 if (!this->emitGetPtrLocal(*LocalIndex, E))
1054 if (!this->
visit(SubExpr))
1056 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1060 case CK_IntegralToFixedPoint: {
1061 if (!this->
visit(SubExpr))
1065 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1070 return this->emitPopFixedPoint(E);
1073 case CK_FloatingToFixedPoint: {
1074 if (!this->
visit(SubExpr))
1078 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1079 if (!this->emitCastFloatingFixedPoint(Sem, E))
1082 return this->emitPopFixedPoint(E);
1085 case CK_FixedPointToFloating: {
1086 if (!this->
visit(SubExpr))
1088 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1089 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1092 return this->emitPopFloat(E);
1095 case CK_FixedPointToIntegral: {
1096 if (!this->
visit(SubExpr))
1099 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1102 return this->emitPop(IntegralT, E);
1105 case CK_FixedPointCast: {
1106 if (!this->
visit(SubExpr))
1109 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1110 if (!this->emitCastFixedPoint(Sem, E))
1113 return this->emitPopFixedPoint(E);
1121 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1123 case CK_LValueBitCast:
1128 case CK_HLSLArrayRValue: {
1135 if (!this->emitGetPtrLocal(*LocalIndex, E))
1138 if (!this->
visit(SubExpr))
1140 return this->emitMemcpy(E);
1143 case CK_HLSLMatrixTruncation: {
1148 if (!this->
visit(SubExpr))
1150 return this->emitArrayElemPop(*ResultT, 0, E);
1159 if (!this->emitGetPtrLocal(*LocalIndex, E))
1164 if (!this->
visit(SubExpr))
1166 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1170 case CK_HLSLAggregateSplatCast: {
1180 if (!this->emitGetPtrLocal(*LocalIndex, E))
1187 unsigned SrcOffset =
1190 if (!this->
visit(SubExpr))
1192 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1196 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1199 case CK_HLSLElementwiseCast: {
1210 unsigned SrcPtrOffset =
1212 if (!this->
visit(SubExpr))
1214 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1218 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1220 if (Elements.empty())
1223 const HLSLFlatElement &Src = Elements[0];
1224 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1226 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1233 if (!this->emitGetPtrLocal(*LocalIndex, E))
1237 unsigned SrcOffset =
1239 if (!this->
visit(SubExpr))
1241 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1245 unsigned ElemCount = countHLSLFlatElements(DestType);
1248 Elements.reserve(ElemCount);
1249 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1254 assert(Elements.size() == ElemCount &&
1255 "Source type has fewer scalar elements than the destination type");
1257 return emitHLSLConstructAggregate(DestType, Elements, E);
1264 const Record::Field *RF = R->getField(UnionField);
1267 if (!this->
visit(SubExpr))
1269 if (RF->isBitField())
1270 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1272 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1275 if (!this->emitGetPtrField(RF->Offset, E))
1277 if (!this->emitActivate(E))
1283 return this->emitInvalid(E);
1285 llvm_unreachable(
"Unhandled clang::CastKind enum");
1288template <
class Emitter>
1290 return this->emitBuiltinBitCast(E);
1293template <
class Emitter>
1298 return this->emitConst(
LE->getValue(),
LE);
1301template <
class Emitter>
1307 return this->emitFloat(F, E);
1310template <
class Emitter>
1320 if (!this->emitGetPtrLocal(*LocalIndex, E))
1327 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1329 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1334template <
class Emitter>
1342 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1347template <
class Emitter>
1352template <
class Emitter>
1379 return this->emitComplexComparison(LHS, RHS, E);
1387 if (!this->
visit(LHS))
1390 if (!this->
visit(RHS))
1393 if (!this->emitToMemberPtr(E))
1399 if (!this->emitCastMemberPtrPtr(E))
1416 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1422 if (!this->emitGetPtrLocal(*ResultIndex, E))
1429 return this->emitCMP3(*
LT, CmpInfo, E);
1432 if (!
LT || !RT || !
T)
1442 return this->visitAssignment(LHS, RHS, E);
1449 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1453 return this->emitPopBool(E);
1455 return this->emitCast(
PT_Bool, *
T, E);
1459 auto Discard = [
this,
T, E](
bool Result) {
1467 return MaybeCastToBool(this->emitEQ(*
LT, E));
1469 return MaybeCastToBool(this->emitNE(*
LT, E));
1471 return MaybeCastToBool(this->emitLT(*
LT, E));
1473 return MaybeCastToBool(this->emitLE(*
LT, E));
1475 return MaybeCastToBool(this->emitGT(*
LT, E));
1477 return MaybeCastToBool(this->emitGE(*
LT, E));
1480 return Discard(this->emitSubf(getFPOptions(E), E));
1481 return Discard(this->emitSub(*
T, E));
1484 return Discard(this->emitAddf(getFPOptions(E), E));
1485 return Discard(this->emitAdd(*
T, E));
1488 return Discard(this->emitMulf(getFPOptions(E), E));
1489 return Discard(this->emitMul(*
T, E));
1491 return Discard(this->emitRem(*
T, E));
1494 return Discard(this->emitDivf(getFPOptions(E), E));
1495 return Discard(this->emitDiv(*
T, E));
1497 return Discard(this->emitBitAnd(*
T, E));
1499 return Discard(this->emitBitOr(*
T, E));
1501 return Discard(this->emitShl(*
LT, *RT, E));
1503 return Discard(this->emitShr(*
LT, *RT, E));
1505 return Discard(this->emitBitXor(*
T, E));
1508 llvm_unreachable(
"Already handled earlier");
1513 llvm_unreachable(
"Unhandled binary op");
1518template <
class Emitter>
1524 if ((Op != BO_Add && Op != BO_Sub) ||
1535 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1536 if (!this->
visit(E))
1539 return this->emitDecayPtr(
T,
PT_Ptr, E);
1548 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1556 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1559 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1566 if (!visitAsPointer(RHS, *RT))
1568 if (!this->
visit(LHS))
1572 if (!visitAsPointer(LHS, *
LT))
1574 if (!this->
visit(RHS))
1585 if (!this->emitAddOffset(OffsetType, E))
1589 if (!this->emitSubOffset(OffsetType, E))
1598 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1603 return this->emitPop(ExprT, E);
1607template <
class Emitter>
1616 LabelTy LabelTrue = this->getLabel();
1617 LabelTy LabelEnd = this->getLabel();
1621 if (!this->jumpTrue(LabelTrue, E))
1626 if (!this->jump(LabelEnd, E))
1629 this->emitLabel(LabelTrue);
1630 this->emitConstBool(
true, E);
1631 this->fallthrough(LabelEnd);
1632 this->emitLabel(LabelEnd);
1635 assert(Op == BO_LAnd);
1638 LabelTy LabelFalse = this->getLabel();
1639 LabelTy LabelEnd = this->getLabel();
1643 if (!this->jumpFalse(LabelFalse, E))
1648 if (!this->jump(LabelEnd, E))
1651 this->emitLabel(LabelFalse);
1652 this->emitConstBool(
false, E);
1653 this->fallthrough(LabelEnd);
1654 this->emitLabel(LabelEnd);
1658 return this->emitPopBool(E);
1663 return this->emitCast(
PT_Bool,
T, E);
1668template <
class Emitter>
1675 if (!this->emitGetPtrLocal(*LocalIndex, E))
1684 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1685 unsigned ResultOffset = ~0u;
1691 if (!this->emitDupPtr(E))
1693 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1698 LHSType = AT->getValueType();
1701 RHSType = AT->getValueType();
1710 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1715 if (!this->
visit(LHS))
1717 if (!this->
visit(RHS))
1719 if (!this->emitMulc(ElemT, E))
1722 return this->emitPopPtr(E);
1726 if (Op == BO_Div && RHSIsComplex) {
1733 if (!LHSIsComplex) {
1738 LHSOffset = *LocalIndex;
1740 if (!this->emitGetPtrLocal(LHSOffset, E))
1743 if (!this->
visit(LHS))
1746 if (!this->emitInitElem(ElemT, 0, E))
1749 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1751 if (!this->emitInitElem(ElemT, 1, E))
1754 if (!this->
visit(LHS))
1758 if (!this->
visit(RHS))
1760 if (!this->emitDivc(ElemT, E))
1763 return this->emitPopPtr(E);
1770 if (!this->
visit(LHS))
1772 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1777 if (!this->
visit(LHS))
1779 if (!this->emitSetLocal(LHST, LHSOffset, E))
1787 if (!this->
visit(RHS))
1789 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1794 if (!this->
visit(RHS))
1796 if (!this->emitSetLocal(RHST, RHSOffset, E))
1803 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1804 unsigned ElemIndex,
unsigned Offset,
1805 const Expr *E) ->
bool {
1807 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1809 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1812 if (ElemIndex == 0 || !LoadZero)
1819 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1822 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1829 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1832 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1835 if (!this->emitAddf(getFPOptions(E), E))
1838 if (!this->emitAdd(ResultElemT, E))
1843 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1846 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1849 if (!this->emitSubf(getFPOptions(E), E))
1852 if (!this->emitSub(ResultElemT, E))
1857 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1860 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1864 if (!this->emitMulf(getFPOptions(E), E))
1867 if (!this->emitMul(ResultElemT, E))
1872 assert(!RHSIsComplex);
1873 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1876 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1880 if (!this->emitDivf(getFPOptions(E), E))
1883 if (!this->emitDiv(ResultElemT, E))
1894 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1897 if (!this->emitPop(ResultElemT, E))
1902 return this->emitPopPtr(E);
1908template <
class Emitter>
1913 "Comma op should be handled in VisitBinaryOperator");
1917 LHSType = AT->getValueType();
1920 RHSType = AT->getValueType();
1934 if (!this->emitGetPtrLocal(*LocalIndex, E))
1943 PrimType ElemT = this->classifyVectorElementType(LHSType);
1944 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1948 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1951 if (!this->
visit(LHS))
1953 if (!this->
visit(RHS))
1955 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1958 return this->emitPopPtr(E);
1963 unsigned LHSOffset =
1965 if (!this->
visit(LHS))
1967 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1971 unsigned RHSOffset =
1973 if (!this->
visit(RHS))
1975 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1987 if (NeedIntPromot) {
1989 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1994 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1995 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1997 if (!this->emitArrayElemPop(ElemT, Index, E))
2000 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
2002 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2004 }
else if (NeedIntPromot) {
2005 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
2011#define EMIT_ARITH_OP(OP) \
2013 if (ElemT == PT_Float) { \
2014 if (!this->emit##OP##f(getFPOptions(E), E)) \
2017 if (!this->emit##OP(ElemT, E)) \
2023 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
2024 if (!getElem(LHSOffset, ElemT, I))
2026 if (!getElem(RHSOffset, RHSElemT, I))
2038 if (!this->emitRem(ElemT, E))
2042 if (!this->emitBitAnd(OpT, E))
2046 if (!this->emitBitOr(OpT, E))
2050 if (!this->emitBitXor(OpT, E))
2054 if (!this->emitShl(OpT, RHSElemT, E))
2058 if (!this->emitShr(OpT, RHSElemT, E))
2062 if (!this->emitEQ(ElemT, E))
2066 if (!this->emitNE(ElemT, E))
2070 if (!this->emitLE(ElemT, E))
2074 if (!this->emitLT(ElemT, E))
2078 if (!this->emitGE(ElemT, E))
2082 if (!this->emitGT(ElemT, E))
2087 if (!this->emitBitAnd(ResultElemT, E))
2092 if (!this->emitBitOr(ResultElemT, E))
2096 return this->emitInvalid(E);
2105 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2107 if (!this->emitNeg(ResultElemT, E))
2113 if (NeedIntPromot &&
2114 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2118 if (!this->emitInitElem(ResultElemT, I, E))
2127template <
class Emitter>
2137 auto LHSSemaInt = LHSSema.toOpaqueInt();
2139 auto RHSSemaInt = RHSSema.toOpaqueInt();
2141 if (!this->
visit(LHS))
2149 if (!this->
visit(RHS))
2158 auto ConvertResult = [&](
bool R) ->
bool {
2162 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2163 if (ResultSema != CommonSema)
2164 return this->emitCastFixedPoint(ResultSema, E);
2168 auto MaybeCastToBool = [&](
bool Result) {
2173 return this->emitPop(
T, E);
2175 return this->emitCast(
PT_Bool,
T, E);
2181 return MaybeCastToBool(this->emitEQFixedPoint(E));
2183 return MaybeCastToBool(this->emitNEFixedPoint(E));
2185 return MaybeCastToBool(this->emitLTFixedPoint(E));
2187 return MaybeCastToBool(this->emitLEFixedPoint(E));
2189 return MaybeCastToBool(this->emitGTFixedPoint(E));
2191 return MaybeCastToBool(this->emitGEFixedPoint(E));
2193 return ConvertResult(this->emitAddFixedPoint(E));
2195 return ConvertResult(this->emitSubFixedPoint(E));
2197 return ConvertResult(this->emitMulFixedPoint(E));
2199 return ConvertResult(this->emitDivFixedPoint(E));
2201 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2203 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2206 return this->emitInvalid(E);
2209 llvm_unreachable(
"unhandled binop opcode");
2212template <
class Emitter>
2221 if (!this->
visit(SubExpr))
2223 if (!this->emitNegFixedPoint(E))
2226 return this->emitPopFixedPoint(E);
2232 llvm_unreachable(
"Unhandled unary opcode");
2235template <
class Emitter>
2244 return this->visitZeroInitializer(*
T, QT, E);
2257 return this->visitZeroRecordInitializer(R, E);
2264 return this->visitZeroArrayInitializer(QT, E);
2268 QualType ElemQT = ComplexTy->getElementType();
2270 for (
unsigned I = 0; I < 2; ++I) {
2271 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2273 if (!this->emitInitElem(ElemT, I, E))
2280 unsigned NumVecElements = VecT->getNumElements();
2281 QualType ElemQT = VecT->getElementType();
2284 for (
unsigned I = 0; I < NumVecElements; ++I) {
2285 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2287 if (!this->emitInitElem(ElemT, I, E))
2294 unsigned NumElems = MT->getNumElementsFlattened();
2295 QualType ElemQT = MT->getElementType();
2298 for (
unsigned I = 0; I != NumElems; ++I) {
2299 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2301 if (!this->emitInitElem(ElemT, I, E))
2310template <
class Emitter>
2323 for (
const Expr *SubExpr : {LHS, RHS}) {
2324 if (!this->
visit(SubExpr)) {
2331 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2332 if (!this->emitExpandPtr(E))
2343 return this->emitError(E);
2346 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2350 if (!this->emitArrayElemPtrPop(*IndexT, E))
2353 return this->emitPopPtr(E);
2359 return this->emitLoadPop(*
T, E);
2362template <
class Emitter>
2364 const Expr *ArrayFiller,
const Expr *E) {
2369 QT = AT->getValueType();
2372 if (
Inits.size() == 0)
2374 return this->emitInvalid(E);
2387 if (
Inits.size() == 0)
2388 return this->visitZeroInitializer(*
T, QT, E);
2389 assert(
Inits.size() == 1);
2403 if (!this->emitGetPtrLocal(*LocalIndex, E))
2418 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2424 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2433 bool BitField = FieldToInit->isBitField();
2435 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2436 FieldToInit->bitWidth(), E);
2438 return this->emitInitBitField(
T, FieldToInit->Offset,
2439 FieldToInit->bitWidth(), E);
2441 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2442 return this->emitInitField(
T, FieldToInit->Offset, E);
2445 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2453 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2456 if (
Activate && !this->emitActivate(E))
2459 if (!this->emitStartInit(
Init))
2466 if (
Inits.size() == 0) {
2467 if (!this->visitZeroRecordInitializer(R, E))
2472 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2473 FToInit = ILE->getInitializedFieldInUnion();
2477 const Record::Field *FieldToInit = R->getField(FToInit);
2479 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2482 if (!initCompositeField(FieldToInit,
Init,
true))
2486 return this->emitFinishInit(E);
2489 assert(!R->isUnion());
2490 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2492 const Record::Base *B = R->getBase(BI);
2495 if (!this->emitGetPtrBase(B->Offset,
Init))
2501 unsigned FieldIndex = 0;
2502 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2503 const Record::Field *FieldToInit = R->getField(FieldIndex);
2504 if (FieldToInit->isUnnamedBitField()) {
2519 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2521 }
else if (!initCompositeField(FieldToInit,
Init)) {
2529 assert(R->getNumVirtualBases() == 0);
2531 return this->emitFinishInit(E);
2536 Ctx.getASTContext().getAsConstantArrayType(QT);
2541 !this->emitCheckArrayDestSize(NumElems, E))
2544 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2548 unsigned ElementIndex = 0;
2550 if (
const auto *EmbedS =
2551 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2559 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2560 getFPOptions(E), E))
2566 return this->emitInitElem(TargetT, ElemIndex, IL);
2568 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2584 for (; ElementIndex != NumElems; ++ElementIndex) {
2590 return this->emitFinishInit(E);
2594 unsigned NumInits =
Inits.size();
2599 QualType ElemQT = ComplexTy->getElementType();
2601 if (NumInits == 0) {
2603 for (
unsigned I = 0; I < 2; ++I) {
2604 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2606 if (!this->emitInitElem(ElemT, I, E))
2609 }
else if (NumInits == 2) {
2610 unsigned InitIndex = 0;
2615 if (!this->emitInitElem(ElemT, InitIndex, E))
2624 unsigned NumVecElements = VecT->getNumElements();
2625 assert(NumVecElements >=
Inits.size());
2627 QualType ElemQT = VecT->getElementType();
2631 unsigned InitIndex = 0;
2638 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2639 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2640 InitVecT->getNumElements(), E))
2642 InitIndex += InitVecT->getNumElements();
2644 if (!this->emitInitElem(ElemT, InitIndex, E))
2650 assert(InitIndex <= NumVecElements);
2653 for (; InitIndex != NumVecElements; ++InitIndex) {
2654 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2656 if (!this->emitInitElem(ElemT, InitIndex, E))
2663 unsigned NumElems = MT->getNumElementsFlattened();
2664 assert(
Inits.size() == NumElems);
2666 QualType ElemQT = MT->getElementType();
2672 for (
unsigned I = 0; I != NumElems; ++I) {
2675 if (!this->emitInitElem(ElemT, I, E))
2686template <
class Emitter>
2693 return this->emitInitElem(*InitT, ElemIndex,
Init);
2699 if (!this->emitConstUint32(ElemIndex,
Init))
2701 if (!this->emitArrayElemPtrUint32(
Init))
2706template <
class Emitter>
2709 bool Activate,
bool IsOperatorCall) {
2711 llvm::BitVector NonNullArgs;
2712 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2715 bool ExplicitMemberFn =
false;
2716 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2717 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2719 unsigned ArgIndex = 0;
2720 for (
const Expr *Arg : Args) {
2722 if (!this->
visit(Arg))
2730 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2731 if (DeclIndex < FuncDecl->getNumParams())
2732 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2741 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2749 if (!this->emitActivate(Arg))
2753 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2756 if (!this->emitCheckNonNullArg(ArgT, Arg))
2767template <
class Emitter>
2772template <
class Emitter>
2778template <
class Emitter>
2784template <
class Emitter>
2804 if (!this->emitGetPtrLocal(*LocalIndex, E))
2810template <
class Emitter>
2812 auto It = E->
begin();
2813 return this->
visit(*It);
2817 UnaryExprOrTypeTrait Kind) {
2822 T = Ref->getPointeeType();
2824 if (
T.getQualifiers().hasUnaligned())
2827 bool AlignOfReturnsPreferred =
2832 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2838template <
class Emitter>
2842 UnaryExprOrTypeTrait Kind = E->
getKind();
2845 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2851 ArgType = Ref->getPointeeType();
2857 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2858 return this->emitInvalid(E);
2860 if (Kind == UETT_SizeOf)
2869 return this->emitConst(Size.getQuantity(), E);
2872 if (Kind == UETT_CountOf) {
2878 if (
const auto *CAT =
2882 return this->emitConst(CAT->getSize(), E);
2892 if (VAT->getElementType()->isArrayType()) {
2893 std::optional<APSInt> Res =
2895 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2900 return this->emitConst(*Res, E);
2905 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2925 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2928 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2938 return this->emitConst(Size.getQuantity(), E);
2941 if (Kind == UETT_VectorElements) {
2946 return this->emitConst(VT->getNumElements(), E);
2948 return this->emitSizelessVectorElementSize(E);
2951 if (Kind == UETT_VecStep) {
2953 unsigned N = VT->getNumElements();
2960 return this->emitConst(N, E);
2962 return this->emitConst(1, E);
2965 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2974 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2976 return this->emitInvalid(E);
2978 return this->emitConst(
2987template <
class Emitter>
2996 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
3001 if (VD->getInit() && !VD->getInit()->isValueDependent())
3002 VD->evaluateValue();
3003 if (
auto GlobalIndex =
P.getGlobal(VD)) {
3004 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3006 if (
Member->getType()->isReferenceType())
3007 return this->emitLoadPopPtr(E);
3016 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
3017 MD && !MD->isStatic()) {
3021 if (!this->
discard(Base) && !this->emitSideEffect(E))
3036 const Record::Field *F = R->getField(FD);
3040 const auto maybeLoadValue = [&]() ->
bool {
3044 return this->emitLoadPop(*
T, E);
3049 if (F->Decl->getType()->isReferenceType())
3050 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3051 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3054template <
class Emitter>
3064template <
class Emitter>
3074 return this->emitCheckArraySize(Size, E);
3080 if (!this->
visit(Common))
3082 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3096 for (
size_t I = 0; I != Size; ++I) {
3108template <
class Emitter>
3123 return this->emitGetLocal(SubExprT, It->second, E);
3126 if (!this->
visit(SourceExpr))
3133 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3142 return this->emitGetLocal(SubExprT, LocalIndex, E);
3146template <
class Emitter>
3159 bool IsBcpCall =
false;
3160 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3161 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3165 LabelTy LabelEnd = this->getLabel();
3166 LabelTy LabelFalse = this->getLabel();
3169 if (!this->emitPushIgnoreDiags(E))
3177 if (this->checkingForUndefinedBehavior()) {
3180 if (!this->
discard(FalseExpr))
3197 if (!this->jumpFalse(LabelFalse, E))
3202 if (!this->jump(LabelEnd, E))
3204 this->emitLabel(LabelFalse);
3208 this->fallthrough(LabelEnd);
3209 this->emitLabel(LabelEnd);
3212 return this->emitPopIgnoreDiags(E);
3216template <
class Emitter>
3222 return this->emitGetStringPtr(E, E);
3226 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3227 assert(CAT &&
"a string literal that's not a constant array?");
3232 unsigned N = std::min(ArraySize, E->
getLength());
3235 for (
unsigned I = 0; I != N; ++I) {
3238 if (CharWidth == 1) {
3239 this->emitConstSint8(CodeUnit, E);
3240 this->emitInitElemSint8(I, E);
3241 }
else if (CharWidth == 2) {
3242 this->emitConstUint16(CodeUnit, E);
3243 this->emitInitElemUint16(I, E);
3244 }
else if (CharWidth == 4) {
3245 this->emitConstUint32(CodeUnit, E);
3246 this->emitInitElemUint32(I, E);
3248 llvm_unreachable(
"unsupported character width");
3253 for (
unsigned I = N; I != ArraySize; ++I) {
3254 if (CharWidth == 1) {
3255 this->emitConstSint8(0, E);
3256 this->emitInitElemSint8(I, E);
3257 }
else if (CharWidth == 2) {
3258 this->emitConstUint16(0, E);
3259 this->emitInitElemUint16(I, E);
3260 }
else if (CharWidth == 4) {
3261 this->emitConstUint32(0, E);
3262 this->emitInitElemUint32(I, E);
3264 llvm_unreachable(
"unsupported character width");
3271template <
class Emitter>
3275 return this->emitDummyPtr(E, E);
3278template <
class Emitter>
3280 auto &A =
Ctx.getASTContext();
3289template <
class Emitter>
3297 auto &A =
Ctx.getASTContext();
3301 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3302 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3308 return this->emitGetStringPtr(SL, E);
3311template <
class Emitter>
3315 return this->emitConst(E->
getValue(), E);
3318template <
class Emitter>
3340 if (!this->emitLoad(LHST, E))
3343 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3344 LHSComputationType, E))
3356 unsigned TempOffset =
3358 if (!this->emitSetLocal(*RT, TempOffset, E))
3364 if (!this->emitLoad(LHST, E))
3368 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3369 LHSComputationType, E))
3373 if (!this->emitGetLocal(*RT, TempOffset, E))
3379 if (!this->emitAddf(getFPOptions(E), E))
3383 if (!this->emitSubf(getFPOptions(E), E))
3387 if (!this->emitMulf(getFPOptions(E), E))
3391 if (!this->emitDivf(getFPOptions(E), E))
3402 return this->emitStorePop(LHST, E);
3403 return this->emitStore(LHST, E);
3406template <
class Emitter>
3415 if (Op != BO_AddAssign && Op != BO_SubAssign)
3424 if (!this->emitLoad(*
LT, LHS))
3430 if (Op == BO_AddAssign) {
3431 if (!this->emitAddOffset(*RT, E))
3434 if (!this->emitSubOffset(*RT, E))
3439 return this->emitStorePopPtr(E);
3440 return this->emitStorePtr(E);
3443template <
class Emitter>
3456 if (!
Ctx.getLangOpts().CPlusPlus14)
3457 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3459 if (!
LT || !RT || !ResultT || !LHSComputationT)
3476 if (!this->emitLoad(*
LT, E))
3478 if (
LT != LHSComputationT &&
3479 !this->emitIntegralCast(*
LT, *LHSComputationT,
3493 unsigned TempOffset =
3496 if (!this->emitSetLocal(*RT, TempOffset, E))
3503 if (!this->emitLoad(*
LT, E))
3505 if (
LT != LHSComputationT &&
3506 !this->emitIntegralCast(*
LT, *LHSComputationT,
3511 if (!this->emitGetLocal(*RT, TempOffset, E))
3518 if (!this->emitAdd(*LHSComputationT, E))
3522 if (!this->emitSub(*LHSComputationT, E))
3526 if (!this->emitMul(*LHSComputationT, E))
3530 if (!this->emitDiv(*LHSComputationT, E))
3534 if (!this->emitRem(*LHSComputationT, E))
3538 if (!this->emitShl(*LHSComputationT, *RT, E))
3542 if (!this->emitShr(*LHSComputationT, *RT, E))
3546 if (!this->emitBitAnd(*LHSComputationT, E))
3550 if (!this->emitBitXor(*LHSComputationT, E))
3554 if (!this->emitBitOr(*LHSComputationT, E))
3558 llvm_unreachable(
"Unimplemented compound assign operator");
3562 if (ResultT != LHSComputationT &&
3563 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3569 return this->emitStoreBitFieldPop(*ResultT, E);
3570 return this->emitStorePop(*ResultT, E);
3573 return this->emitStoreBitField(*ResultT, E);
3574 return this->emitStore(*ResultT, E);
3577template <
class Emitter>
3585template <
class Emitter>
3600 if (!
Ctx.getLangOpts().CPlusPlus11)
3607 for (
const Expr *LHS : CommaLHSs) {
3622 if (this->constantFolding())
3633 if (!this->
visit(Inner))
3638 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3641 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3644 return this->emitGetPtrGlobal(*GlobalIndex, E);
3647 if (!this->checkLiteralType(Inner))
3650 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3656 return this->emitInitGlobalTempComp(TempDecl, E);
3669 unsigned LocalIndex =
3671 if (!this->VarScope->LocalsAlwaysEnabled &&
3672 !this->emitEnableLocal(LocalIndex, E))
3675 if (!this->
visit(Inner))
3677 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3680 return this->emitGetPtrLocal(LocalIndex, E);
3683 if (!this->checkLiteralType(Inner))
3690 if (!this->VarScope->LocalsAlwaysEnabled &&
3691 !this->emitEnableLocal(*LocalIndex, E))
3694 if (!this->emitGetPtrLocal(*LocalIndex, E))
3701template <
class Emitter>
3712 if (!this->
visit(SubExpr))
3716 return this->emitPopPtr(E);
3720template <
class Emitter>
3741 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3746 if (
P.isGlobalInitialized(*GlobalIndex))
3752 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3764 unsigned LocalIndex;
3768 LocalIndex = *MaybeIndex;
3772 if (!this->emitGetPtrLocal(LocalIndex, E))
3776 return this->
visit(
Init) && this->emitInit(*
T, E);
3780template <
class Emitter>
3791 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3795 if (!R || R->getNumFields() == 0)
3797 const Record::Field *Field = R->getField(0
U);
3802 return this->emitInitField(*Field->T, Field->Offset, E);
3809template <
class Emitter>
3813 return this->emitConst(E->
getValue(), E);
3816template <
class Emitter>
3829 for (
const Record::Field &F : R->fields()) {
3831 if (!
Init ||
Init->containsErrors())
3839 if (!this->emitInitField(*
T, F.Offset, E))
3842 if (!this->emitGetPtrField(F.Offset, E))
3853template <
class Emitter>
3859 return this->emitGetStringPtr(E, E);
3863template <
class Emitter>
3868 return this->emitInvalid(E);
3871template <
class Emitter>
3885 if (!this->emitInvalidCast(
CastKind,
false, E))
3893 bool Fatal = (ToT != FromT);
3900template <
class Emitter>
3902 if (!
Ctx.getLangOpts().CPlusPlus20) {
3923 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3928 return this->emitPopPtr(E);
3932template <
class Emitter>
3938 return this->emitConstBool(E->
getValue(), E);
3941template <
class Emitter>
3946 if (
T->isRecordType()) {
3960 if (!this->emitGetPtrLocal(*LocalIndex, E))
3968 T->getAsCXXRecordDecl()))
3978 if (!this->visitZeroRecordInitializer(R, E))
3989 if (!this->emitDefaultInit(Ctor, E))
3992 return this->emitPopPtr(E);
4000 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
4002 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
4003 if (!this->emitCheckFunctionDecl(Ctor, E))
4014 assert(
Func->hasThisPointer());
4015 assert(!
Func->hasRVO());
4019 if (!this->emitDupPtr(E))
4023 for (
const auto *Arg : E->
arguments()) {
4024 if (!this->
visit(Arg))
4028 if (
Func->isVariadic()) {
4029 uint32_t VarArgSize = 0;
4030 unsigned NumParams =
Func->getNumWrittenParams();
4031 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
4035 if (!this->emitCallVar(
Func, VarArgSize, E))
4038 if (!this->emitCall(
Func, 0, E)) {
4043 (void)this->emitPopPtr(E);
4049 return this->emitPopPtr(E);
4053 if (
T->isArrayType()) {
4058 if (!this->emitDupPtr(E))
4062 initArrayDimension = [&](
QualType T) ->
bool {
4063 if (!
T->isArrayType()) {
4065 for (
const auto *Arg : E->
arguments()) {
4066 if (!this->
visit(Arg))
4070 return this->emitCall(
Func, 0, E);
4074 Ctx.getASTContext().getAsConstantArrayType(
T);
4080 return this->emitCheckArraySize(NumElems, E);
4081 for (uint64_t I = 0; I != NumElems; ++I) {
4082 if (!this->emitConstUint64(I, E))
4084 if (!this->emitArrayElemPtrUint64(E))
4086 if (!initArrayDimension(ElemTy))
4089 return this->emitPopPtr(E);
4092 return initArrayDimension(E->
getType());
4098template <
class Emitter>
4108 assert(Val.
isInt());
4110 return this->emitConst(I, E);
4117 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4118 return this->
visit(LValueExpr);
4133 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4137 const APValue &
V = UGCD->getValue();
4138 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4139 const Record::Field *F = R->getField(I);
4140 const APValue &FieldValue =
V.getStructField(I);
4144 if (!this->emitInitField(*F->T, F->Offset, E))
4152template <
class Emitter>
4158 for (
unsigned I = 0; I != N; ++I) {
4165 if (!this->
discard(ArrayIndexExpr))
4171 if (!this->
visit(ArrayIndexExpr))
4173 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4177 if (!this->
visit(ArrayIndexExpr))
4181 if (!this->emitCast(IndexT,
PT_Sint64, E))
4191 return this->emitOffsetOf(
T, E, E);
4194template <
class Emitter>
4203 return this->visitZeroInitializer(*
T, Ty, E);
4210 if (!this->emitGetPtrLocal(*LocalIndex, E))
4218 ElemQT = CT->getElementType();
4221 NumElems = VT->getNumElements();
4222 ElemQT = VT->getElementType();
4228 for (
unsigned I = 0; I != NumElems; ++I) {
4229 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4231 if (!this->emitInitElem(ElemT, I, E))
4240template <
class Emitter>
4245template <
class Emitter>
4251template <
class Emitter>
4256template <
class Emitter>
4261 return this->emitConst(E->
getValue(), E);
4264template <
class Emitter>
4286 unsigned ParamIndex = 0;
4290 if (!this->emitGetParam(PT, ParamIndex, E))
4295 return this->emitCall(F, 0, E);
4300template <
class Emitter>
4308 const Expr *PlacementDest =
nullptr;
4309 bool IsNoThrow =
false;
4314 if (PlacementArgs != 0) {
4323 if (PlacementArgs == 1) {
4325 if (OperatorNew->isReservedGlobalPlacementOperator()) {
4326 if (!this->emitCheckPlacementNew(E, E))
4328 PlacementDest = Arg1;
4332 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4339 return this->emitInvalidNewDeleteExpr(E, E);
4343 return this->emitInvalid(E);
4345 }
else if (!OperatorNew
4346 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4347 return this->emitInvalidNewDeleteExpr(E, E);
4350 if (!PlacementDest) {
4355 Desc =
P.createDescriptor(E, *ElemT);
4357 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4364 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4368 const Expr *Stripped = *ArraySizeExpr;
4369 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4370 Stripped = ICE->getSubExpr())
4371 if (ICE->getCastKind() != CK_NoOp &&
4372 ICE->getCastKind() != CK_IntegralCast)
4380 if (!this->
visit(Stripped))
4382 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4385 if (PlacementDest) {
4386 if (!this->
visit(PlacementDest))
4388 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4390 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4393 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4398 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4402 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4409 size_t StaticInitElems = 0;
4410 const Expr *DynamicInit =
nullptr;
4414 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4415 StaticInitElems = CAT->getZExtSize();
4420 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4421 if (ILE->hasArrayFiller())
4422 DynamicInit = ILE->getArrayFiller();
4441 const Function *CtorFunc =
nullptr;
4442 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4446 }
else if (!DynamicInit && !ElemT)
4449 LabelTy EndLabel = this->getLabel();
4450 LabelTy StartLabel = this->getLabel();
4455 if (!this->emitDupPtr(E))
4457 if (!this->emitIsNonNullPtr(E))
4459 if (!this->jumpFalse(EndLabel, E))
4466 if (!this->emitConst(StaticInitElems,
SizeT, E))
4468 if (!this->emitSetLocal(
SizeT, Iter, E))
4471 this->fallthrough(StartLabel);
4472 this->emitLabel(StartLabel);
4474 if (!this->emitGetLocal(
SizeT, Iter, E))
4476 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4478 if (!this->emitLT(
SizeT, E))
4480 if (!this->jumpFalse(EndLabel, E))
4484 if (!this->emitGetLocal(
SizeT, Iter, E))
4486 if (!this->emitArrayElemPtr(
SizeT, E))
4489 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4494 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4496 if (!this->emitStorePop(*InitT, E))
4500 if (!this->visitZeroArrayInitializer(ElemType, E))
4503 }
else if (DynamicInit) {
4505 if (!this->
visit(DynamicInit))
4507 if (!this->emitStorePop(*InitT, E))
4514 if (!this->visitZeroInitializer(
4518 if (!this->emitStorePop(*ElemT, E))
4522 if (!this->emitCall(CtorFunc, 0, E))
4527 if (!this->emitGetPtrLocal(Iter, E))
4529 if (!this->emitIncPop(
SizeT,
false, E))
4532 if (!this->jump(StartLabel, E))
4535 this->fallthrough(EndLabel);
4536 this->emitLabel(EndLabel);
4540 if (PlacementDest) {
4541 if (!this->
visit(PlacementDest))
4543 if (!this->emitCheckNewTypeMismatch(E, E))
4548 if (!this->emitAlloc(Desc, E))
4557 if (!this->emitInit(*ElemT, E))
4568 return this->emitPopPtr(E);
4573template <
class Emitter>
4579 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4580 return this->emitInvalidNewDeleteExpr(E, E);
4589template <
class Emitter>
4595 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4600 return this->emitGetFnPtr(
Func, E);
4603template <
class Emitter>
4607 auto canonType = [](
const Type *
T) {
4608 return T->getCanonicalTypeUnqualified().getTypePtr();
4616 return this->emitGetTypeid(
4620 return this->emitGetTypeid(
4629 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4635 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4638 return this->emitPopPtr(E);
4642template <
class Emitter>
4646 return this->emitDummyPtr(E, E);
4647 return this->emitError(E);
4650template <
class Emitter>
4653 return this->emitDummyPtr(E, E);
4654 return this->emitError(E);
4657template <
class Emitter>
4664 assert(
false &&
"null reflection can't be constructed from parsing a "
4665 "reflection operand");
4673 assert(
false &&
"unknown or unimplemented reflection entities");
4677template <
class Emitter>
4679 assert(
Ctx.getLangOpts().CPlusPlus);
4680 return this->emitConstBool(E->
getValue(), E);
4683template <
class Emitter>
4695 return this->emitDummyPtr(GuidDecl, E);
4700 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4709 assert(
V.isStruct());
4710 assert(
V.getStructNumBases() == 0);
4714 return this->emitFinishInit(E);
4717template <
class Emitter>
4727template <
class Emitter>
4736template <
class Emitter>
4742template <
class Emitter>
4746 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4750 if (OVE->isUnique())
4766template <
class Emitter>
4771template <
class Emitter>
4773 return this->emitError(E);
4776template <
class Emitter>
4782 return this->emitDummyPtr(E, E);
4785template <
class Emitter>
4786bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4791 QualType ElemType = VT->getElementType();
4792 PrimType ElemT = classifyPrim(ElemType);
4794 PrimType SrcElemT = classifyVectorElementType(SrcType);
4800 if (!this->emitGetPtrLocal(*LocalIndex, E))
4804 unsigned SrcOffset =
4805 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4806 if (!this->visit(Src))
4808 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4811 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4812 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4814 if (!this->emitArrayElemPop(SrcElemT, I, E))
4818 if (SrcElemT != ElemT) {
4819 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4821 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4822 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4826 if (!this->emitInitElem(ElemT, I, E))
4832template <
class Emitter>
4834 return emitVectorConversion(E->
getSrcExpr(), E);
4837template <
class Emitter>
4841 return this->emitInvalid(E);
4850 assert(NumOutputElems > 0);
4856 if (!this->emitGetPtrLocal(*LocalIndex, E))
4861 unsigned VectorOffsets[2];
4862 for (
unsigned I = 0; I != 2; ++I) {
4865 if (!this->
visit(Vecs[I]))
4867 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4870 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4872 assert(ShuffleIndex >= -1);
4873 if (ShuffleIndex == -1)
4874 return this->emitInvalidShuffleVectorIndex(I, E);
4876 assert(ShuffleIndex < (NumInputElems * 2));
4877 if (!this->emitGetLocal(
PT_Ptr,
4878 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4880 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4881 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4884 if (!this->emitInitElem(ElemT, I, E))
4889 return this->emitPopPtr(E);
4894template <
class Emitter>
4899 Base->getType()->isVectorType() ||
4905 if (Indices.size() == 1) {
4910 if (!this->emitConstUint32(Indices[0], E))
4912 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4922 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4930 if (!this->emitGetPtrLocal(*ResultIndex, E))
4938 uint32_t DstIndex = 0;
4939 for (uint32_t I : Indices) {
4940 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4942 if (!this->emitArrayElemPop(ElemT, I, E))
4944 if (!this->emitInitElem(ElemT, DstIndex, E))
4954template <
class Emitter>
4958 return this->
discard(SubExpr) && this->emitInvalid(E);
4964 return this->emitDummyPtr(E, E);
4967template <
class Emitter>
4972 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4981 if (!this->emitGetPtrLocal(*LocalIndex, E))
4985 if (!this->
visit(SubExpr))
4987 if (!this->emitConstUint8(0, E))
4989 if (!this->emitArrayElemPtrPopUint8(E))
4991 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4994 PrimType SecondFieldT = *R->getField(1u)->T;
4996 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4998 if (!this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E))
5001 return this->emitPopPtr(E);
5004 assert(SecondFieldT ==
PT_Ptr);
5006 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
5008 if (!this->emitExpandPtr(E))
5012 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5015 if (!this->emitInitFieldPtr(R->getField(1u)->Offset, E))
5018 return this->emitPopPtr(E);
5022template <
class Emitter>
5037 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
5041 return this->emitUnsupported(E);
5050 return this->
Visit(E);
5057 return this->
Visit(E);
5061 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5064 if (
const auto *CE = dyn_cast<CastExpr>(E);
5066 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
5073 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5076 if (
const auto *CE = dyn_cast<CastExpr>(E);
5077 CE && (CE->getCastKind() == CK_DerivedToBase ||
5078 CE->getCastKind() == CK_UncheckedDerivedToBase ||
5079 CE->getCastKind() == CK_NoOp))
5099 if (!this->emitGetPtrLocal(*LocalIndex, E))
5109 return this->
Visit(E);
5112template <
class Emitter>
5118 return this->
Visit(E) && this->emitFinishInit(E);
5121template <
class Emitter>
5127 return this->
Visit(E) && this->emitFinishInitPop(E);
5133 return this->
Visit(E);
5144 if (!this->
visit(E))
5146 return this->emitComplexBoolCast(E);
5151 if (!this->
visit(E))
5159 return this->emitIsNonNullPtr(E);
5163 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5166 return this->emitCast(*
T,
PT_Bool, E);
5169template <
class Emitter>
5173 QT = AT->getValueType();
5177 return this->emitZeroBool(E);
5179 return this->emitZeroSint8(E);
5181 return this->emitZeroUint8(E);
5183 return this->emitZeroSint16(E);
5185 return this->emitZeroUint16(E);
5187 return this->emitZeroSint32(E);
5189 return this->emitZeroUint32(E);
5191 return this->emitZeroSint64(E);
5193 return this->emitZeroUint64(E);
5195 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5197 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5199 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5202 return this->emitNullMemberPtr(0,
nullptr, E);
5204 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5205 return this->emitFloat(F, E);
5208 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5214 llvm_unreachable(
"unknown primitive type");
5217template <
class Emitter>
5218bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5220 bool IsCompleteClass) {
5224 for (
const Record::Field &Field :
R->fields()) {
5225 if (Field.isUnnamedBitField())
5232 if (!this->visitZeroInitializer(
T, QT, E))
5235 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5239 if (!this->emitInitField(
T, Field.Offset, E))
5244 if (!this->emitGetPtrField(Field.Offset, E))
5251 if (!this->visitZeroInitializer(
T, ET, E))
5253 if (!this->emitInitElem(
T, I, E))
5258 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5261 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5269 if (!this->emitFinishInitActivatePop(E))
5273 if (!this->emitFinishInitPop(E))
5277 for (
const Record::Base &B :
R->bases()) {
5278 if (!this->emitGetPtrBase(B.Offset, E))
5280 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5282 if (!this->emitFinishInitPop(E))
5286 if (IsCompleteClass) {
5287 for (
const Record::Base &B :
R->virtual_bases()) {
5290 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5292 if (!this->emitFinishInitPop(E))
5300template <
class Emitter>
5301bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5302 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5303 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5308 for (
size_t I = 0; I != NumElems; ++I) {
5309 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5311 if (!this->emitInitElem(*ElemT, I, E))
5317 const Record *
R = getRecord(ElemType);
5321 for (
size_t I = 0; I != NumElems; ++I) {
5322 if (!this->emitConstUint32(I, E))
5324 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5326 if (!this->visitZeroRecordInitializer(R, E))
5328 if (!this->emitPopPtr(E))
5334 for (
size_t I = 0; I != NumElems; ++I) {
5335 if (!this->emitConstUint32(I, E))
5337 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5339 if (!this->visitZeroArrayInitializer(ElemType, E))
5341 if (!this->emitPopPtr(E))
5350template <
class Emitter>
5351bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5353 if (!canClassify(E->
getType()))
5358 if (!this->visit(LHS))
5360 if (!this->visit(RHS))
5363 if (!this->visit(RHS))
5365 if (!this->visit(LHS))
5373 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5377 bool Activates = refersToUnion(LHS);
5380 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5383 if (DiscardResult) {
5384 if (BitField && Activates)
5385 return this->emitStoreBitFieldActivatePop(RHT, E);
5387 return this->emitStoreBitFieldPop(RHT, E);
5389 return this->emitStoreActivatePop(RHT, E);
5391 return this->emitStorePop(RHT, E);
5394 auto maybeLoad = [&](
bool Result) ->
bool {
5400 return this->emitLoadPop(RHT, E);
5404 if (BitField && Activates)
5405 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5407 return maybeLoad(this->emitStoreBitField(RHT, E));
5409 return maybeLoad(this->emitStoreActivate(RHT, E));
5411 return maybeLoad(this->emitStore(RHT, E));
5414template <
class Emitter>
5415template <
typename T>
5419 return this->emitConstSint8(
Value, Info);
5421 return this->emitConstUint8(
Value, Info);
5423 return this->emitConstSint16(
Value, Info);
5425 return this->emitConstUint16(
Value, Info);
5427 return this->emitConstSint32(
Value, Info);
5429 return this->emitConstUint32(
Value, Info);
5431 return this->emitConstSint64(
Value, Info);
5433 return this->emitConstUint64(
Value, Info);
5435 return this->emitConstBool(
Value, Info);
5443 llvm_unreachable(
"Invalid integral type");
5446 llvm_unreachable(
"unknown primitive type");
5449template <
class Emitter>
5450template <
typename T>
5451bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5452 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5455template <
class Emitter>
5459 return this->emitConstIntAPS(
Value, Info);
5461 return this->emitConstIntAP(
Value, Info);
5463 if (
Value.isSigned())
5464 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5465 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5468template <
class Emitter>
5472 return this->emitConstIntAPS(
Value, Info);
5474 return this->emitConstIntAP(
Value, Info);
5477 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5478 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5481template <
class Emitter>
5482bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5483 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5486template <
class Emitter>
5501 return Local.Offset;
5504template <
class Emitter>
5509 bool IsTemporary =
false;
5513 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5514 Init = VarD->getInit();
5516 if (
const auto *E = Src.
asExpr()) {
5526 return std::nullopt;
5533 return Local.Offset;
5536template <
class Emitter>
5545 return std::nullopt;
5555 return Local.Offset;
5558template <
class Emitter>
5560 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5561 return PT->getPointeeType()->getAsCanonical<RecordType>();
5567 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5571template <
class Emitter>
5573 return P.getOrCreateRecord(RD);
5576template <
class Emitter>
5578 return Ctx.getOrCreateFunction(FD);
5581template <
class Emitter>
5587 auto maybeDestroyLocals = [&]() ->
bool {
5588 if (DestroyToplevelScope)
5589 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5590 return this->emitCheckAllocations(E);
5597 return this->emitRetVoid(E) && maybeDestroyLocals();
5605 return this->emitRet(*
T, E) && maybeDestroyLocals();
5613 if (!this->emitGetPtrLocal(*LocalOffset, E))
5621 return this->emitRetValue(E) && maybeDestroyLocals();
5624 return maybeDestroyLocals() &&
false;
5627template <
class Emitter>
5629 bool DestroyToplevelScope) {
5633 return this->
visitExpr(E, DestroyToplevelScope);
5636template <
class Emitter>
5648 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5649 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5663template <
class Emitter>
5665 bool ConstantContext) {
5668 if (!ConstantContext) {
5683 auto GlobalIndex =
P.getGlobal(VD);
5684 assert(GlobalIndex);
5686 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5689 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5697 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5699 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5702 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5712 auto GlobalIndex =
P.getGlobal(VD);
5713 assert(GlobalIndex);
5714 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5723 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5726template <
class Emitter>
5737 if (!this->isActive())
5742 if (
Init &&
Init->isValueDependent())
5746 auto checkDecl = [&]() ->
bool {
5748 return !NeedsOp || this->emitCheckDecl(VD, VD);
5755 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5758 if (
P.isGlobalInitialized(*GlobalIndex))
5762 }
else if ((GlobalIndex =
5777 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5780 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5783 if (!this->emitStartInit(
Init))
5789 if (!this->emitEndInit(
Init))
5792 return this->emitFinishInitGlobal(
Init);
5802 if (!
Init ||
Init->getType()->isVoidType())
5811 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5823 if (!this->emitCheckRefInit(
Init))
5827 return this->emitSetLocal(*VarT, Offset, VD);
5835 if (!this->emitGetPtrLocal(*Offset,
Init))
5843template <
class Emitter>
5866 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5872 return this->emitDestructionPop(D, VD);
5881 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5905template <
class Emitter>
5920 unsigned ParamIndex = 0;
5927 const Expr *Arg = Args[ParamIndex];
5928 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5930 unsigned ArgOffset =
5932 if (!this->
visit(Arg))
5934 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5940 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5952 if (
This->getType()->isPointerType()) {
5955 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5962 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5984template <
class Emitter>
5990 return this->emitConst(Val.
getInt(), ValType, Info);
5992 return this->emitFloat(Val.
getFloat(), Info);
5996 if (!this->emitGetMemberPtr(MemberDecl, Info))
6002 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
6008 return this->emitNullMemberPtr(0,
nullptr, Info);
6013 return this->emitNull(ValType, 0,
nullptr, Info);
6017 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>()) {
6018 if (!this->
visit(BaseExpr))
6020 EntryType = BaseExpr->getType();
6021 }
else if (
const auto *VD =
Base.dyn_cast<
const ValueDecl *>()) {
6024 EntryType = VD->getType();
6029 ->getCanonicalTypeUnqualified()
6031 EntryType =
Base.getTypeInfoType();
6032 if (!this->emitGetTypeid(OperandType, EntryType.
getTypePtr(), Info))
6040 ?
Ctx.getASTContext().getPointerType(E->
getType())
6043 if (!this->emitConstUint64(Offset, Info))
6045 if (!this->emitGetIntPtrUint64(PtrType.
getTypePtr(), Info))
6055 uint64_t Index = Entry.getAsArrayIndex();
6058 if (!this->emitConst(Index,
PT_Uint64, Info))
6060 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
6062 EntryType = ElemType;
6069 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
6070 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
6072 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
6074 EntryType = FD->getType();
6078 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
6083 if (!this->emitGetPtrVirtBasePop(
Base, Info))
6086 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
6101 uint32_t BitWidth =
Ctx.getBitWidth(E->
getType());
6103 ? this->emitCastPointerIntegralAP(BitWidth, Info)
6104 : this->emitCastPointerIntegralAPS(BitWidth, Info);
6106 return this->emitCastPointerIntegral(ValType, Info);
6112template <
class Emitter>
6115 bool IsCompleteClass) {
6121 if (IsCompleteClass)
6128 const Record::Base *RB = R->getBase(I);
6129 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6131 if (!this->emitGetPtrBase(RB->Offset, Info))
6136 if (!this->emitFinishInitPop(Info))
6144 const Record::Field *RF = R->getField(I);
6145 QualType FieldType = RF->Decl->getType();
6150 if (!this->emitInitField(*PT, RF->Offset, Info))
6153 if (!this->emitGetPtrField(RF->Offset, Info))
6157 if (!this->emitFinishInitPop(Info))
6163 if (IsCompleteClass) {
6168 const Record::Base *RB = R->getVirtualBase(I);
6169 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6177 if (!this->emitFinishInitPop(Info))
6193 const Record::Field *RF = R->getField(UnionField);
6194 QualType FieldType = RF->Decl->getType();
6199 if (RF->isBitField())
6200 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6202 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6205 if (!this->emitGetPtrField(RF->Offset, Info))
6207 if (!this->emitActivate(Info))
6211 return this->emitPopPtr(Info);
6215 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6216 QualType ElemType = ArrType->getElementType();
6219 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6220 const APValue &Elem = A >= InitializedElems
6229 if (!this->emitInitElem(*ElemT, A, Info))
6232 if (!this->emitConstUint32(A, Info))
6234 if (!this->emitArrayElemPtrUint32(Info))
6238 if (!this->emitPopPtr(Info))
6245 assert(
T->isComplexType());
6248 if (!this->emitInitElemFloat(0, Info))
6252 if (!this->emitInitElemFloat(1, Info))
6257 assert(
T->isComplexIntegerType());
6261 if (!this->emitInitElem(IntT, 0, Info))
6265 if (!this->emitInitElem(IntT, 1, Info))
6270 assert(
T->isVectorType());
6278 if (!this->emitInitElem(ElemT, I, Info))
6288template <
class Emitter>
6290 if (
P.getGlobal(VD))
6295 llvm_unreachable(
"Why didn't that work?");
6299 "registerRedecl should only be called with primitive values");
6304 return this->emitInitGlobal(
T, *GlobalIndex, {});
6307template <
class Emitter>
6309 unsigned BuiltinID) {
6315 if (!
Ctx.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
6316 return this->emitInvalid(E);
6325 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6330 return this->emitConst(0, E);
6333 if (!this->emitStartSpeculation(E))
6335 LabelTy EndLabel = this->getLabel();
6336 if (!this->speculate(E, EndLabel))
6338 if (!this->emitEndSpeculation(E))
6340 this->fallthrough(EndLabel);
6348 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6349 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6350 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6351 BuiltinID == Builtin::BI__builtin_function_start) {
6354 return this->emitDummyPtr(E, E);
6365 if (!this->emitGetPtrLocal(*LocalIndex, E))
6370 switch (BuiltinID) {
6371 case Builtin::BI__builtin_object_size:
6372 case Builtin::BI__builtin_dynamic_object_size: {
6376 if (!this->
visit(Arg0))
6387 case Builtin::BI__assume:
6388 case Builtin::BI__builtin_assume:
6391 case Builtin::BI__atomic_is_lock_free:
6392 case Builtin::BI__atomic_always_lock_free: {
6403 for (
const auto *Arg : E->
arguments()) {
6404 if (!this->
visit(Arg))
6410 if (!this->emitCallBI(E, BuiltinID, E))
6428template <
class Emitter>
6449 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6450 DD && DD->isTrivial()) {
6452 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6454 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6455 this->emitPopPtr(E);
6461 bool ActivateLHS =
false;
6469 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6470 OCE && OCE->isAssignmentOp()) {
6471 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6474 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6475 if (!this->
visit(MCE->getImplicitObjectArgument()))
6482 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6500 if (!this->emitGetPtrLocal(*LocalIndex, E))
6508 if (!this->emitGetPtrLocal(*LocalIndex, E))
6512 if (!this->emitDupPtr(E))
6517 const Expr *ReversedArgs[2];
6518 bool IsAssignmentOperatorCall =
false;
6519 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6520 OCE && OCE->isAssignmentOp()) {
6524 assert(Args.size() == 2);
6525 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6527 IsAssignmentOperatorCall =
true;
6528 ReversedArgs[0] = Args[1];
6529 ReversedArgs[1] = Args[0];
6530 Args = ReversedArgs;
6537 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6538 MD && MD->isStatic()) {
6542 Args = Args.drop_front();
6546 bool Devirtualized =
false;
6549 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6557 if (!this->
visit(Callee))
6559 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6561 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6563 if (!this->emitGetMemberPtrBase(E))
6566 const auto *InstancePtr = MC->getImplicitObjectArgument();
6573 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6574 Devirtualized =
true;
6575 if (!this->
visit(Stripped))
6578 if (!this->
visit(InstancePtr))
6582 if (!this->
visit(InstancePtr))
6586 }
else if (
const auto *PD =
6587 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6588 if (!this->emitCheckPseudoDtor(E))
6596 return this->emitPseudoDtor(E);
6597 }
else if (!FuncDecl) {
6601 if (!this->
visit(Callee))
6603 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6612 if (IsAssignmentOperatorCall) {
6613 assert(Args.size() == 2);
6616 if (!this->emitFlip(Arg2T, Arg1T, E))
6630 assert(HasRVO ==
Func->hasRVO());
6632 bool HasQualifier =
false;
6633 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6634 HasQualifier = ME->hasQualifier();
6636 bool IsVirtual =
false;
6637 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6638 IsVirtual = !Devirtualized && MD->isVirtual();
6643 if (IsVirtual && !HasQualifier) {
6644 uint32_t VarArgSize = 0;
6645 unsigned NumParams =
6646 Func->getNumWrittenParams() +
6648 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6651 if (!this->emitCallVirt(
Func, VarArgSize, E))
6653 }
else if (
Func->isVariadic()) {
6654 uint32_t VarArgSize = 0;
6655 unsigned NumParams =
6656 Func->getNumWrittenParams() +
6658 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6660 if (!this->emitCallVar(
Func, VarArgSize, E))
6663 if (!this->emitCall(
Func, 0, E))
6672 uint32_t ArgSize = 0;
6673 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6679 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6681 if (!this->emitGetMemberPtrDecl(E))
6684 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6687 if (!this->emitCallPtr(ArgSize, E, E))
6698template <
class Emitter>
6705template <
class Emitter>
6712template <
class Emitter>
6717 return this->emitConstBool(E->
getValue(), E);
6720template <
class Emitter>
6726 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6727 return this->emitNullPtr(Val,
nullptr, E);
6730template <
class Emitter>
6738 return this->emitZero(
T, E);
6741template <
class Emitter>
6746 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6747 if (this->LambdaThisCapture.Offset > 0) {
6748 if (this->LambdaThisCapture.IsPtr)
6749 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6750 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6759 return this->emitThis(E);
6774 unsigned StartIndex = 0;
6775 unsigned EndIndex = 0;
6777 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6779 EndIndex = StartIndex;
6786 for (; StartIndex > 0; --StartIndex) {
6797 if (StartIndex == 0 && EndIndex == 0)
6808 assert(StartIndex <= EndIndex);
6811 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6823 case Stmt::CompoundStmtClass:
6825 case Stmt::DeclStmtClass:
6827 case Stmt::ReturnStmtClass:
6829 case Stmt::IfStmtClass:
6831 case Stmt::WhileStmtClass:
6833 case Stmt::DoStmtClass:
6835 case Stmt::ForStmtClass:
6837 case Stmt::CXXForRangeStmtClass:
6839 case Stmt::BreakStmtClass:
6841 case Stmt::ContinueStmtClass:
6843 case Stmt::SwitchStmtClass:
6845 case Stmt::CaseStmtClass:
6847 case Stmt::DefaultStmtClass:
6849 case Stmt::AttributedStmtClass:
6851 case Stmt::CXXTryStmtClass:
6853 case Stmt::NullStmtClass:
6856 case Stmt::GCCAsmStmtClass:
6857 case Stmt::MSAsmStmtClass:
6858 case Stmt::GotoStmtClass:
6859 return this->emitInvalid(S);
6860 case Stmt::LabelStmtClass:
6862 case Stmt::CXXExpansionStmtInstantiationClass:
6866 if (
const auto *E = dyn_cast<Expr>(S))
6873template <
class Emitter>
6876 for (
const auto *InnerStmt : S->
body())
6879 return Scope.destroyLocals();
6882template <
class Emitter>
6883bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6884 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6885 for (
auto *BD : DD->flat_bindings())
6886 if (
auto *KD = BD->getHoldingVar();
6887 KD && !this->visitVarDecl(KD, KD->getInit()))
6901template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6903 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6904 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6911 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6916 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6917 ICE && (ICE->getCastKind() == CK_NoOp ||
6918 ICE->getCastKind() == CK_DerivedToBase ||
6919 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6920 E = ICE->getSubExpr();
6924 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6925 const auto *ThisRecord =
6926 This->getType()->getPointeeType()->getAsRecordDecl();
6927 if (!ThisRecord->isUnion())
6930 if (
const auto *Ctor =
6931 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6932 return Ctor->getParent() == ThisRecord;
6941template <
class Emitter>
6943 bool EvaluateConditionDecl) {
6944 for (
const auto *D : DS->
decls()) {
6949 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6950 assert(ESD->getInstantiations() &&
"not expanded?");
6951 if (!this->
visitStmt(ESD->getInstantiations()))
6956 const auto *VD = dyn_cast<VarDecl>(D);
6963 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6970template <
class Emitter>
6973 return this->emitUnsupported(RS);
6979 if (!this->
visit(RE))
6985 if (RE->getType()->isVoidType()) {
6986 if (!this->
visit(RE))
6989 if (RE->containsErrors())
6994 if (!this->emitRVOPtr(RE))
7000 return this->emitRetVoid(RS);
7006 return this->emitRetVoid(RS);
7012 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
7019 if (
auto *CondInit = IS->
getInit()) {
7035 return visitChildStmt(IS->
getThen());
7037 return visitChildStmt(Else);
7043 if (!this->emitIsConstantContext(IS))
7046 if (!this->emitIsConstantContext(IS))
7048 if (!this->emitInv(IS))
7062 LabelTy LabelElse = this->getLabel();
7063 LabelTy LabelEnd = this->getLabel();
7064 if (!this->jumpFalse(LabelElse, IS))
7066 if (!visitChildStmt(IS->
getThen()))
7068 if (!this->jump(LabelEnd, IS))
7070 this->emitLabel(LabelElse);
7071 if (!visitChildStmt(Else))
7073 this->emitLabel(LabelEnd);
7075 LabelTy LabelEnd = this->getLabel();
7076 if (!this->jumpFalse(LabelEnd, IS))
7078 if (!visitChildStmt(IS->
getThen()))
7080 this->emitLabel(LabelEnd);
7089template <
class Emitter>
7094 LabelTy CondLabel = this->getLabel();
7095 LabelTy EndLabel = this->getLabel();
7099 this->fallthrough(CondLabel);
7100 this->emitLabel(CondLabel);
7116 if (!this->jumpFalse(EndLabel, S))
7126 if (!this->jump(CondLabel, S))
7128 this->fallthrough(EndLabel);
7129 this->emitLabel(EndLabel);
7138 LabelTy StartLabel = this->getLabel();
7139 LabelTy EndLabel = this->getLabel();
7140 LabelTy CondLabel = this->getLabel();
7144 this->fallthrough(StartLabel);
7145 this->emitLabel(StartLabel);
7151 this->fallthrough(CondLabel);
7152 this->emitLabel(CondLabel);
7159 if (!this->jumpTrue(StartLabel, S))
7162 this->fallthrough(EndLabel);
7163 this->emitLabel(EndLabel);
7167template <
class Emitter>
7175 LabelTy EndLabel = this->getLabel();
7176 LabelTy CondLabel = this->getLabel();
7177 LabelTy IncLabel = this->getLabel();
7184 this->fallthrough(CondLabel);
7185 this->emitLabel(CondLabel);
7197 if (!this->jumpFalse(EndLabel, S))
7206 this->fallthrough(IncLabel);
7207 this->emitLabel(IncLabel);
7213 if (!this->jump(CondLabel, S))
7217 this->emitLabel(EndLabel);
7223template <
class Emitter>
7233 LabelTy EndLabel = this->getLabel();
7234 LabelTy CondLabel = this->getLabel();
7235 LabelTy IncLabel = this->getLabel();
7251 this->fallthrough(CondLabel);
7252 this->emitLabel(CondLabel);
7255 if (!this->jumpFalse(EndLabel, S))
7266 this->fallthrough(IncLabel);
7267 this->emitLabel(IncLabel);
7274 if (!this->jump(CondLabel, S))
7277 this->fallthrough(EndLabel);
7278 this->emitLabel(EndLabel);
7282template <
class Emitter>
7293 if (LI.BreakLabel) {
7294 TargetLabel = *LI.BreakLabel;
7295 BreakScope = LI.BreakOrContinueScope;
7301 if (LI.Name == TargetLoop) {
7302 TargetLabel = *LI.BreakLabel;
7303 BreakScope = LI.BreakOrContinueScope;
7314 C =
C->getParent()) {
7315 if (!
C->destroyLocals())
7319 return this->jump(*TargetLabel, S);
7322template <
class Emitter>
7333 if (LI.ContinueLabel) {
7334 TargetLabel = *LI.ContinueLabel;
7335 ContinueScope = LI.BreakOrContinueScope;
7341 if (LI.Name == TargetLoop) {
7342 TargetLabel = *LI.ContinueLabel;
7343 ContinueScope = LI.BreakOrContinueScope;
7353 C =
C->getParent()) {
7354 if (!
C->destroyLocals())
7358 return this->jump(*TargetLabel, S);
7361template <
class Emitter>
7371 LabelTy EndLabel = this->getLabel();
7376 if (
const auto *CondInit = S->
getInit())
7385 if (!this->
visit(Cond))
7387 if (!this->emitSetLocal(CondT, CondVar, S))
7397 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7400 if (CS->caseStmtIsGNURange()) {
7401 LabelTy EndOfRangeCheck = this->getLabel();
7402 const Expr *Low = CS->getLHS();
7403 const Expr *High = CS->getRHS();
7407 if (!this->emitGetLocal(CondT, CondVar, CS))
7409 if (!this->
visit(Low))
7412 if (!this->emitGE(
LT, S))
7414 if (!this->jumpFalse(EndOfRangeCheck, S))
7417 if (!this->emitGetLocal(CondT, CondVar, CS))
7419 if (!this->
visit(High))
7422 if (!this->emitLE(HT, S))
7426 this->emitLabel(EndOfRangeCheck);
7431 if (
Value->isValueDependent())
7436 if (!this->emitGetLocal(CondT, CondVar, CS))
7442 if (!this->emitEQ(ValueT, S))
7447 assert(!DefaultLabel);
7448 DefaultLabel = this->getLabel();
7455 if (!this->jump(*DefaultLabel, S))
7458 if (!this->jump(EndLabel, S))
7466 this->fallthrough(EndLabel);
7467 this->emitLabel(EndLabel);
7472template <
class Emitter>
7480 return this->emitUnsupported(S);
7485template <
class Emitter>
7492 if (LI.DefaultLabel) {
7493 DefaultLabel = *LI.DefaultLabel;
7498 this->emitLabel(DefaultLabel);
7502template <
class Emitter>
7509 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7512 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7513 !this->Ctx.getLangOpts().MSVCCompat) {
7515 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7521 const Expr *Assumption = AA->getAssumption();
7532 if (!this->emitAssume(Assumption))
7541 if (IsMSVCConstexprAttr)
7542 return this->emitPopMSVCCE(S);
7546template <
class Emitter>
7559template <
class Emitter>
7569 LabelTy EndLabel = this->getLabel();
7571 LabelTy ContinueLabel = this->getLabel();
7576 this->emitLabel(ContinueLabel);
7579 this->emitLabel(EndLabel);
7584template <
class Emitter>
7585bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7592 assert(ClosureClass->
captures().empty());
7596 "A generic lambda's static-invoker function must be a "
7597 "template specialization");
7601 llvm::FoldingSetInsertToken InsertToken;
7602 const FunctionDecl *CorrespondingCallOpSpecialization =
7604 assert(CorrespondingCallOpSpecialization);
7605 LambdaCallOp = CorrespondingCallOpSpecialization;
7609 assert(ClosureClass->
captures().empty());
7610 const Function *
Func = this->getFunction(LambdaCallOp);
7613 assert(
Func->hasThisPointer());
7616 if (
Func->hasRVO()) {
7617 if (!this->emitRVOPtr(MD))
7625 if (!this->emitNullPtr(0,
nullptr, MD))
7630 auto It = this->Params.find(PVD);
7631 assert(It != this->Params.end());
7635 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7636 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7640 if (!this->emitCall(
Func, 0, LambdaCallOp))
7645 return this->emitRet(*ReturnType, MD);
7648 return this->emitRetVoid(MD);
7651template <
class Emitter>
7652bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7653 if (Ctx.getLangOpts().CPlusPlus23)
7663 const Expr *InitExpr =
Init->getInit();
7665 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7669 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7679template <
class Emitter>
7681 assert(!ReturnType);
7684 if (!this->emitStartThisLifetime1(Ctor))
7687 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7688 const Expr *InitExpr,
7691 if (InitExpr->getType().isNull())
7695 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7698 if (!this->visit(InitExpr))
7701 if (F->isBitField())
7702 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7704 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7709 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7712 if (
Activate && !this->emitActivate(InitExpr))
7715 return this->visitInitializerPop(InitExpr);
7719 const Record *
R = this->getRecord(RD);
7722 bool IsUnion =
R->isUnion();
7732 if (!this->emitThis(Ctor))
7735 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7738 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7739 this->emitRetVoid(Ctor);
7742 unsigned FieldInits = 0;
7745 if (
R->getNumVirtualBases() > 0) {
7746 if (!this->emitThis(Ctor))
7748 LabelTy AfterVirtBasesLabel = this->getLabel();
7751 if (!this->emitIsBaseClass({}))
7753 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7756 for (
const auto *
Init : Ctor->
inits()) {
7759 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7761 assert(
R->findVirtualBase(BaseDecl));
7762 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7764 if (!this->visitInitializerPop(
Init->getInit()))
7769 this->fallthrough(AfterVirtBasesLabel);
7770 this->emitLabel(AfterVirtBasesLabel);
7772 if (!this->emitPopPtr(Ctor))
7776 for (
const auto *
Init : Ctor->
inits()) {
7780 const Expr *InitExpr =
Init->getInit();
7782 const Record::Field *F =
R->getField(
Member);
7786 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7790 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7793 if (
Init->isBaseVirtual()) {
7799 const Record::Base *B =
R->getBase(BaseDecl);
7801 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7805 if (!this->visitInitializerPop(InitExpr))
7810 unsigned ChainSize = IFD->getChainingSize();
7811 assert(ChainSize >= 2);
7813 unsigned NestedFieldOffset = 0;
7814 const Record::Field *NestedField =
nullptr;
7815 for (
unsigned I = 0; I != ChainSize; ++I) {
7817 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7818 assert(FieldRecord);
7820 NestedField = FieldRecord->
getField(FD);
7821 assert(NestedField);
7822 IsUnion = IsUnion || FieldRecord->
isUnion();
7824 NestedFieldOffset += NestedField->Offset;
7827 if (I != ChainSize - 1)
7830 assert(NestedField);
7833 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7838 unsigned InitFieldOffset = 0;
7839 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7841 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7842 assert(FieldRecord);
7843 NestedField = FieldRecord->
getField(FD);
7844 InitFieldOffset += NestedField->Offset;
7845 assert(NestedField);
7846 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7848 if (!this->emitFinishInitPop(InitExpr))
7852 InitStack.pop_back_n(ChainSize - 1);
7855 assert(
Init->isDelegatingInitializer());
7856 if (!this->emitThis(InitExpr))
7858 if (!this->visitInitializerPop(
Init->getInit()))
7862 if (!
Scope.destroyLocals())
7866 if (FieldInits !=
R->getNumFields()) {
7867 assert(FieldInits < R->getNumFields());
7869 if (!this->emitStartThisLifetime(Ctor))
7876 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7877 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7884 if (!visitStmt(Body))
7891template <
class Emitter>
7894 const Record *
R = this->getRecord(RD);
7898 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7899 if (!this->visitStmt(
Dtor->getBody()))
7903 if (!this->emitThis(
Dtor))
7906 if (!this->emitCheckDestruction(
Dtor))
7910 if (!
R->isUnion()) {
7914 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7918 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7920 if (!this->emitDestructionPop(D,
SourceInfo{}))
7925 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7926 if (
Base.R->hasTrivialDtor())
7930 if (!this->emitRecordDestructionPop(
Base.R, {}))
7934 if (
R->getNumVirtualBases() > 0) {
7935 LabelTy EndLabel = this->getLabel();
7937 if (!this->emitIsBaseClass({}))
7939 if (!this->jumpTrue(EndLabel, {}))
7942 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7943 if (
Base.R->hasTrivialDtor())
7948 if (!this->emitRecordDestructionPop(
Base.R, {}))
7952 this->fallthrough(EndLabel);
7953 this->emitLabel(EndLabel);
7956 if (!this->emitMarkDestroyed(
Dtor))
7959 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7962template <
class Emitter>
7963bool Compiler<Emitter>::compileUnionAssignmentOperator(
7965 if (!this->emitThis(MD))
7968 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7971 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7974template <
class Emitter>
7984 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7985 return this->compileConstructor(Ctor);
7986 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7987 return this->compileDestructor(
Dtor);
7990 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7995 return this->compileUnionAssignmentOperator(MD);
7998 return this->emitLambdaStaticInvokerBody(MD);
8002 if (
const auto *Body = F->
getBody())
8016 return FD->getBitWidthValue();
8019template <
class Emitter>
8035 if (!
Ctx.getLangOpts().CPlusPlus14)
8036 return this->emitInvalid(E);
8038 return this->emitError(E);
8040 if (!this->
visit(SubExpr))
8044 if (!this->emitIncPtr(E))
8051 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
8052 : this->emitIncf(getFPOptions(E), E);
8064 if (!
Ctx.getLangOpts().CPlusPlus14)
8065 return this->emitInvalid(E);
8067 return this->emitError(E);
8069 if (!this->
visit(SubExpr))
8073 if (!this->emitDecPtr(E))
8080 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
8081 : this->emitDecf(getFPOptions(E), E);
8094 if (!
Ctx.getLangOpts().CPlusPlus14)
8095 return this->emitInvalid(E);
8097 return this->emitError(E);
8099 if (!this->
visit(SubExpr))
8103 if (!this->emitLoadPtr(E))
8105 if (!this->emitConstUint8(1, E))
8107 if (!this->emitAddOffsetUint8(E))
8109 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8115 return this->emitIncfPop(getFPOptions(E), E);
8125 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8126 if (!this->emitLoadFloat(E))
8128 APFloat F(TargetSemantics, 1);
8129 if (!this->emitFloat(F, E))
8132 if (!this->emitAddf(getFPOptions(E), E))
8134 if (!this->emitStoreFloat(E))
8146 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8149 if (!
Ctx.getLangOpts().CPlusPlus14)
8150 return this->emitInvalid(E);
8152 return this->emitError(E);
8154 if (!this->
visit(SubExpr))
8158 if (!this->emitLoadPtr(E))
8160 if (!this->emitConstUint8(1, E))
8162 if (!this->emitSubOffsetUint8(E))
8164 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8170 return this->emitDecfPop(getFPOptions(E), E);
8180 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8181 if (!this->emitLoadFloat(E))
8183 APFloat F(TargetSemantics, 1);
8184 if (!this->emitFloat(F, E))
8187 if (!this->emitSubf(getFPOptions(E), E))
8189 if (!this->emitStoreFloat(E))
8201 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8205 return this->emitError(E);
8208 return this->
discard(SubExpr);
8213 if (!this->emitInv(E))
8217 return this->emitCast(
PT_Bool, ET, E);
8221 return this->emitError(E);
8223 if (!this->
visit(SubExpr))
8228 return this->emitError(E);
8230 if (!this->
visit(SubExpr))
8246 if (!
Ctx.getLangOpts().CPlusPlus) {
8249 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8250 Deref && Deref->getOpcode() == UO_Deref) {
8252 return this->
discard(Deref->getSubExpr());
8253 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8258 return this->
discard(SubExpr);
8259 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8262 return this->
discard(SubExpr);
8264 if (!this->
visit(SubExpr))
8271 return this->emitNarrowPtr(E);
8276 return this->emitError(E);
8278 if (!this->
visit(SubExpr))
8292 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
8297 assert(
false &&
"Unhandled opcode");
8303template <
class Emitter>
8309 return this->
discard(SubExpr);
8312 auto prepareResult = [=]() ->
bool {
8317 return this->emitGetPtrLocal(*LocalIndex, E);
8324 unsigned SubExprOffset = ~0u;
8325 auto createTemp = [=, &SubExprOffset]() ->
bool {
8328 if (!this->
visit(SubExpr))
8330 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8334 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8335 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8337 return this->emitArrayElemPop(ElemT, Index, E);
8342 if (!prepareResult())
8346 for (
unsigned I = 0; I != 2; ++I) {
8347 if (!getElem(SubExprOffset, I))
8349 if (!this->emitNeg(ElemT, E))
8351 if (!this->emitInitElem(ElemT, I, E))
8362 if (!this->
visit(SubExpr))
8364 if (!this->emitComplexBoolCast(SubExpr))
8366 if (!this->emitInv(E))
8369 return this->emitCast(
PT_Bool, ET, E);
8373 return this->emitComplexReal(SubExpr);
8376 if (!this->
visit(SubExpr))
8380 if (!this->emitConstUint8(1, E))
8382 return this->emitArrayElemPtrPopUint8(E);
8393 if (!this->emitArrayElem(ElemT, 1, E))
8395 if (!this->emitNeg(ElemT, E))
8397 if (!this->emitInitElem(ElemT, 1, E))
8405 return this->emitInvalid(E);
8411template <
class Emitter>
8417 return this->
discard(SubExpr);
8420 if (UnaryOp == UO_Extension)
8423 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8424 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8425 return this->emitInvalid(E);
8428 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8435 if (!this->emitGetPtrLocal(*LocalIndex, E))
8440 unsigned SubExprOffset =
8442 if (!this->
visit(SubExpr))
8444 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8449 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8450 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8452 return this->emitArrayElemPop(ElemT, Index, E);
8457 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8458 if (!getElem(SubExprOffset, I))
8460 if (!this->emitNeg(ElemT, E))
8462 if (!this->emitInitElem(ElemT, I, E))
8477 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8478 if (!getElem(SubExprOffset, I))
8481 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8483 if (!this->emitInv(E))
8485 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8487 if (!this->emitNeg(ElemT, E))
8489 if (ElemT != ResultVecElemT &&
8490 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8492 if (!this->emitInitElem(ResultVecElemT, I, E))
8498 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8499 if (!getElem(SubExprOffset, I))
8502 if (!this->emitInv(E))
8505 if (!this->emitComp(ElemT, E))
8508 if (!this->emitInitElem(ElemT, I, E))
8513 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8518template <
class Emitter>
8520 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8523 return this->emitConst(ECD->getInitVal(), E);
8525 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8529 return F && this->emitGetFnPtr(F, E);
8531 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8532 TPOD = TPOD->getFirstDecl();
8536 return this->emitGetPtrGlobal(*GlobalIndex, E);
8542 return this->emitInitGlobal(*
T, *Index, E);
8545 if (!this->emitGetPtrGlobal(*Index, E))
8549 return this->emitFinishInit(E);
8561 auto maybePopPtr = [&]() ->
bool {
8563 return this->emitPopPtr(E);
8570 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8574 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8579 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8580 if (IsReference || !It->second.IsPtr)
8581 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8583 return this->emitGetPtrParam(It->second.Index, E);
8586 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8593 const unsigned Offset = It->second.Offset;
8596 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8598 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8601 if (
auto GlobalIndex =
P.getGlobal(D)) {
8603 if (!
Ctx.getLangOpts().CPlusPlus11)
8604 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8605 if (!
Ctx.getLangOpts().CPlusPlus23)
8606 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8608 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8611 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8615 auto revisit = [&](
const VarDecl *VD,
8616 bool IsConstexprUnknown =
true) ->
bool {
8618 IsConstexprUnknown);
8619 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8625 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8626 if (!this->emitPopCC(E))
8630 if (VarState.notCreated())
8638 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8640 if (
auto It = this->LambdaCaptures.find(D);
8641 It != this->LambdaCaptures.end()) {
8642 auto [Offset, IsPtr] = It->second;
8645 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8646 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8650 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8651 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8652 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8656 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8657 return this->
delegate(BD->getBinding());
8663 return this->emitDummyPtr(D, E);
8668 const auto *VD = dyn_cast<VarDecl>(D);
8670 return this->emitError(E);
8673 if (!
Ctx.getLangOpts().CPlusPlus) {
8677 return revisit(VD,
false);
8681 return this->emitDummyPtr(D, E);
8685 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8686 if (
T.isConstant(
Ctx.getASTContext()))
8688 return T->isReferenceType();
8692 typeShouldBeVisited(DeclType)) {
8694 Init && !
Init->isValueDependent()) {
8699 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8712 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8717 return revisit(VD, IsConstexprUnknown);
8718 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8719 return revisit(VD,
true);
8728 return this->emitDummyPtr(
8732template <
class Emitter>
8738template <
class Emitter>
8748 if (!
C->destroyLocals())
8754template <
class Emitter>
8755unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8758 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8760 return Ty->getAsCXXRecordDecl();
8762 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8763 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8765 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8769template <
class Emitter>
8776 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8781 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8782 getFPOptions(E), E);
8784 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8785 getFPOptions(E), E);
8789 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8794 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8796 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8800 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8804 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8805 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8812template <
class Emitter>
8815 assert(FromT != ToT);
8818 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8820 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8822 return this->emitCast(FromT, ToT, E);
8826template <
class Emitter>
8827bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8831 return this->
discard(SubExpr);
8833 if (!this->visit(SubExpr))
8836 if (!this->emitConstUint8(0, SubExpr))
8838 return this->emitArrayElemPtrPopUint8(SubExpr);
8842 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8846template <
class Emitter>
8847bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8848 assert(!DiscardResult);
8852 if (!this->emitArrayElem(ElemT, 0, E))
8855 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8858 if (!this->emitCast(ElemT,
PT_Bool, E))
8863 LabelTy LabelTrue = this->getLabel();
8864 if (!this->jumpTrue(LabelTrue, E))
8867 if (!this->emitArrayElemPop(ElemT, 1, E))
8870 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8873 if (!this->emitCast(ElemT,
PT_Bool, E))
8877 LabelTy EndLabel = this->getLabel();
8878 this->jump(EndLabel, E);
8880 this->emitLabel(LabelTrue);
8881 if (!this->emitPopPtr(E))
8883 if (!this->emitConstBool(
true, E))
8886 this->fallthrough(EndLabel);
8887 this->emitLabel(EndLabel);
8892template <
class Emitter>
8893bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8904 LHSIsComplex =
true;
8905 ElemT = classifyComplexElementType(LHS->
getType());
8906 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8907 if (!this->visit(LHS))
8909 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8912 LHSIsComplex =
false;
8914 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8915 if (!this->visit(LHS))
8917 if (!this->emitSetLocal(LHST, LHSOffset, E))
8924 RHSIsComplex =
true;
8925 ElemT = classifyComplexElementType(RHS->
getType());
8926 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8927 if (!this->visit(RHS))
8929 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8932 RHSIsComplex =
false;
8934 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8935 if (!this->visit(RHS))
8937 if (!this->emitSetLocal(RHST, RHSOffset, E))
8941 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8942 bool IsComplex) ->
bool {
8944 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8946 return this->emitArrayElemPop(ElemT, Index, E);
8948 return this->emitGetLocal(ElemT, LocalOffset, E);
8951 for (
unsigned I = 0; I != 2; ++I) {
8953 if (!getElem(LHSOffset, I, LHSIsComplex))
8955 if (!getElem(RHSOffset, I, RHSIsComplex))
8958 if (!this->emitEQ(ElemT, E))
8961 if (!this->emitCastBoolUint8(E))
8966 if (!this->emitAddUint8(E))
8968 if (!this->emitConstUint8(2, E))
8972 if (!this->emitEQUint8(E))
8975 if (!this->emitNEUint8(E))
8982 return this->emitCast(
PT_Bool, ResT, E);
8989template <
class Emitter>
8990bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8993 assert(!
R->hasTrivialDtor());
8996 const Function *DtorFunc = getFunction(
Dtor);
8999 assert(DtorFunc->hasThisPointer());
9000 assert(DtorFunc->getNumParams() == 1);
9001 return this->emitCall(DtorFunc, 0, Loc);
9006template <
class Emitter>
9007bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
9019 return this->emitPopPtr(Loc);
9021 for (ssize_t I = N - 1; I >= 1; --I) {
9022 if (!this->emitConstUint64(I, Loc))
9024 if (!this->emitArrayElemPtrUint64(Loc))
9026 if (!this->emitDestructionPop(ElemDesc, Loc))
9030 if (!this->emitConstUint64(0, Loc))
9032 if (!this->emitArrayElemPtrPopUint64(Loc))
9034 return this->emitDestructionPop(ElemDesc, Loc);
9039 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
9044template <
class Emitter>
9045bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
9046 assert(!DiscardResult &&
"Should've been checked before");
9047 return this->emitGetOpaquePtr(D, CU, E);
9050template <
class Emitter>
9053 return this->emitConstFloat(
Floating(F), Info);
9055 APInt I = F.bitcastToAPInt();
9056 return this->emitConstFloat(
9057 Floating(
const_cast<uint64_t *
>(I.getRawData()),
9058 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
9069template <
class Emitter>
9070bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
9083 if (!this->emitGetPtrLocal(*LocalIndex, E))
9093 if (!this->visit(SubExpr))
9095 }
else if (
OptPrimType FromT = classify(SubExpr)) {
9096 unsigned TempOffset =
9097 allocateLocalPrimitive(SubExpr, *FromT,
true);
9098 if (!this->visit(SubExpr))
9100 if (!this->emitSetLocal(*FromT, TempOffset, E))
9102 if (!this->emitGetPtrLocal(TempOffset, E))
9109 if (!this->emitBitCast(E))
9111 return DiscardResult ? this->emitPopPtr(E) :
true;
9115 const llvm::fltSemantics *TargetSemantics =
nullptr;
9117 TargetSemantics = &Ctx.getFloatSemantics(ToType);
9123 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
9125 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
9126 ResultBitWidth, TargetSemantics,
9131 return this->emitPop(*ToT, E);
9140template <
class Emitter>
9141bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
9146 unsigned NumElems = 0;
9149 NumElems = VT->getNumElements();
9150 ElemType = VT->getElementType();
9152 NumElems = MT->getNumElementsFlattened();
9153 ElemType = MT->getElementType();
9156 PrimType ElemT = classifyPrim(ElemType);
9157 for (
unsigned I = 0; I != NumElems; ++I) {
9158 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9160 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
9162 if (!this->emitInitElem(ElemT, I, E))
9172 QualType ArrElemType = CAT->getElementType();
9173 unsigned ArrSize = CAT->getZExtSize();
9176 for (
unsigned I = 0; I != ArrSize; ++I) {
9177 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9179 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9181 if (!this->emitInitElem(*ElemT, I, E))
9185 for (
unsigned I = 0; I != ArrSize; ++I) {
9186 if (!this->emitConstUint32(I, E))
9188 if (!this->emitArrayElemPtrUint32(E))
9190 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9192 if (!this->emitFinishInitPop(E))
9202 const Record *
R = getRecord(DestType);
9206 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9208 const Record::Base *B =
R->getBase(BS.getType());
9210 if (!this->emitGetPtrBase(B->Offset, E))
9212 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9214 if (!this->emitFinishInitPop(E))
9219 for (
const Record::Field &F :
R->fields()) {
9220 if (F.isUnnamedBitField())
9223 QualType FieldType = F.Decl->getType();
9225 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9227 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9229 if (F.isBitField()) {
9230 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9233 if (!this->emitInitField(*FieldT, F.Offset, E))
9237 if (!this->emitGetPtrField(F.Offset, E))
9239 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9241 if (!this->emitPopPtr(E))
9254template <
class Emitter>
9255unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9258 return VT->getNumElements();
9260 return MT->getNumElementsFlattened();
9264 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9268 const Record *
R = getRecord(Ty);
9272 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9274 Count += countHLSLFlatElements(BS.getType());
9276 for (
const Record::Field &F :
R->fields()) {
9277 if (F.isUnnamedBitField())
9279 Count += countHLSLFlatElements(F.Decl->getType());
9284 if (canClassify(Ty))
9293template <
class Emitter>
9294bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9295 QualType SrcType,
unsigned SrcOffset,
9300 auto saveToLocal = [&](
PrimType T) ->
bool {
9301 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9302 if (!this->emitSetLocal(
T, Offset, E))
9304 Elements.push_back({Offset,
T});
9310 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9311 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9312 return std::nullopt;
9317 unsigned NumElems = 0;
9320 NumElems = VT->getNumElements();
9321 ElemType = VT->getElementType();
9323 NumElems = MT->getNumElementsFlattened();
9324 ElemType = MT->getElementType();
9327 PrimType ElemT = classifyPrim(ElemType);
9328 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9329 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9331 if (!this->emitArrayElemPop(ElemT, I, E))
9333 if (!saveToLocal(ElemT))
9343 QualType ArrElemType = CAT->getElementType();
9344 unsigned ArrSize = CAT->getZExtSize();
9347 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9348 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9350 if (!this->emitArrayElemPop(*ElemT, I, E))
9352 if (!saveToLocal(*ElemT))
9356 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9357 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9359 if (!this->emitConstUint32(I, E))
9361 if (!this->emitArrayElemPtrPopUint32(E))
9366 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9377 const Record *
R = getRecord(SrcType);
9381 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9383 if (Elements.size() >= MaxElements)
9385 const Record::Base *B =
R->getBase(BS.getType());
9387 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9389 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9394 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9400 for (
const Record::Field &F :
R->fields()) {
9401 if (Elements.size() >= MaxElements)
9403 if (F.isUnnamedBitField())
9406 QualType FieldType = F.Decl->getType();
9407 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9409 if (!this->emitGetPtrFieldPop(F.Offset, E))
9413 if (!this->emitLoadPop(*FieldT, E))
9415 if (!saveToLocal(*FieldT))
9419 if (!FieldPtrOffset)
9421 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9437template <
class Emitter>
9438bool Compiler<Emitter>::emitHLSLConstructAggregate(
9444 const auto &Src = Elements[ElemIdx++];
9445 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9447 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9451 unsigned NumElems = 0;
9454 NumElems = VT->getNumElements();
9455 ElemType = VT->getElementType();
9457 NumElems = MT->getNumElementsFlattened();
9458 ElemType = MT->getElementType();
9461 PrimType DestElemT = classifyPrim(ElemType);
9462 for (
unsigned I = 0; I != NumElems; ++I) {
9463 if (!loadAndCast(DestElemT, ElemType))
9465 if (!this->emitInitElem(DestElemT, I, E))
9475 QualType ArrElemType = CAT->getElementType();
9476 unsigned ArrSize = CAT->getZExtSize();
9479 for (
unsigned I = 0; I != ArrSize; ++I) {
9480 if (!loadAndCast(*ElemT, ArrElemType))
9482 if (!this->emitInitElem(*ElemT, I, E))
9486 for (
unsigned I = 0; I != ArrSize; ++I) {
9487 if (!this->emitConstUint32(I, E))
9489 if (!this->emitArrayElemPtrUint32(E))
9491 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9493 if (!this->emitFinishInitPop(E))
9503 const Record *
R = getRecord(DestType);
9507 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9509 const Record::Base *B =
R->getBase(BS.getType());
9511 if (!this->emitGetPtrBase(B->Offset, E))
9513 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9515 if (!this->emitFinishInitPop(E))
9520 for (
const Record::Field &F :
R->fields()) {
9521 if (F.isUnnamedBitField())
9524 QualType FieldType = F.Decl->getType();
9526 if (!loadAndCast(*FieldT, FieldType))
9528 if (F.isBitField()) {
9529 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9532 if (!this->emitInitField(*FieldT, F.Offset, E))
9536 if (!this->emitGetPtrField(F.Offset, E))
9538 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9540 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.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
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()
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)
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)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const VarDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * findVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
VariableScope * getParent() const
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)
bool InitScope(InterpState &S, uint32_t I)
static void discard(InterpStack &Stk, PrimType T)
static bool isSideEffectFree(const Expr *E)
Check if E has side-effects.
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
static bool Activate(InterpState &S)
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
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
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()