21#include "llvm/Support/SaveAndRestore.h"
32 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
33 CE && CE->hasAPValueResult() &&
35 return CE->getResultAsAPSInt().getBoolValue();
57 if (NumElems > std::numeric_limits<unsigned>::max())
59 uint64_t Limit = LangOpts.ConstexprStepLimit;
60 return Limit != 0 && NumElems > Limit;
67 : Ctx(Ctx), Local(Local), VarScope(VarScope) {}
90 llvm_unreachable(
"Shouldn't be called");
144 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
160 this->
Ctx->emitDestroy(*
Idx, E);
167 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
168 this->
Ctx->Descriptors.emplace_back();
182 if (
Local.Desc->hasTrivialDtor())
185 if (!
Local.EnabledByDefault) {
186 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
187 if (!this->
Ctx->emitGetLocalEnabled(
Local.Offset, E))
189 if (!this->
Ctx->jumpFalse(EndLabel, E))
192 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
195 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
198 this->
Ctx->fallthrough(EndLabel);
199 this->
Ctx->emitLabel(EndLabel);
201 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
203 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
222 if (
const auto *OVE =
223 llvm::dyn_cast_if_present<OpaqueValueExpr>(
Local.Desc->asExpr())) {
224 this->
Ctx->OpaqueExprs.erase(OVE);
236 OldArrayIndex = Ctx->ArrayIndex;
237 Ctx->ArrayIndex = Index;
244 std::optional<uint64_t> OldArrayIndex;
252 if (!Ctx->SourceLocDefaultExpr) {
254 Ctx->SourceLocDefaultExpr = DefaultExpr;
260 Ctx->SourceLocDefaultExpr =
nullptr;
265 bool Enabled =
false;
271 Ctx->InitStack.push_back(std::move(
Link));
283 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
286 Ctx->InitStackActive = OldValue || Active;
292 this->Ctx->InitStackActive = OldValue;
294 Ctx->InitStack.pop_back();
308 OldInitializingDecl(
Ctx->InitializingDecl) {
309 Ctx->InitializingDecl = VD;
314 this->
Ctx->InitializingDecl = OldInitializingDecl;
315 this->
Ctx->InitStack.pop_back();
320 const VarDecl *OldInitializingDecl;
328 bool NewInitializing,
bool NewToLValue)
329 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
330 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
331 Ctx->DiscardResult = NewDiscardResult;
332 Ctx->Initializing = NewInitializing;
333 Ctx->ToLValue = NewToLValue;
337 Ctx->DiscardResult = OldDiscardResult;
338 Ctx->Initializing = OldInitializing;
339 Ctx->ToLValue = OldToLValue;
346 bool OldDiscardResult;
347 bool OldInitializing;
351template <
class Emitter>
355 return Ctx->emitThis(E);
358 return Ctx->emitGetPtrFieldPop(
Offset, E);
360 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
362 return Ctx->emitGetPtrLocal(
Offset, E);
366 if (!Ctx->emitConstUint32(
Offset, E))
368 return Ctx->emitArrayElemPtrPopUint32(E);
370 return Ctx->emitRVOPtr(E);
374 llvm_unreachable(
"Unhandled InitLink kind");
390 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
391 assert(LI.Name != Name);
394 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
415 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
417 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
418 assert(LI.Name != Name);
421 this->Ctx->CaseLabels = std::move(CaseLabels);
422 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
424 DefaultLabel, Ctx->VarScope);
428 this->Ctx->CaseLabels = std::move(OldCaseLabels);
429 this->Ctx->LabelInfoStack.pop_back();
434 CaseMap OldCaseLabels;
445 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
448 Ctx->LocOverride = NewValue;
453 Ctx->LocOverride = OldFlag;
458 std::optional<SourceInfo> OldFlag;
465template <
class Emitter>
473 case CK_LValueToRValue: {
481 if (!this->
visit(SubExpr))
483 return this->emitLoadPopL(E);
493 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
499 if (
auto GlobalIndex =
P.getGlobal(D))
500 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
501 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
502 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
503 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
504 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
505 return this->emitGetParam(*SubExprT, It->second.Index, E);
517 if (!this->emitGetPtrLocal(*LocalIndex, E))
521 if (!this->
visit(SubExpr))
525 return this->emitLoadPop(*SubExprT, E);
530 return this->emitMemcpy(E);
533 case CK_DerivedToBaseMemberPointer: {
544 ->getMostRecentCXXRecordDecl();
546 const CXXRecordDecl *ToDecl = B->getType()->castAsCXXRecordDecl();
547 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
549 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
557 case CK_BaseToDerivedMemberPointer: {
568 ->getMostRecentCXXRecordDecl();
572 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
574 PathI != PathE; ++PathI) {
575 const CXXRecordDecl *ToDecl = (*PathI)->getType()->castAsCXXRecordDecl();
576 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
578 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
585 assert(ToDecl != CurDecl);
586 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
588 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
594 case CK_UncheckedDerivedToBase:
595 case CK_DerivedToBase: {
600 if (
const auto *PT = dyn_cast<PointerType>(Ty))
601 return PT->getPointeeType()->castAsCXXRecordDecl();
602 return Ty->castAsCXXRecordDecl();
609 if (B->isVirtual()) {
610 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
612 CurType = B->getType();
614 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
615 if (!this->emitGetPtrBasePop(
618 CurType = B->getType();
625 case CK_BaseToDerived: {
629 auto unwrapPointerType = [](
const Type *T) ->
const Type * {
630 if (T->isPointerOrReferenceType())
631 return T->getPointeeType().getTypePtr();
643 llvm::drop_begin(llvm::reverse(E->
path()))) {
644 const Type *TargetType = unwrapPointerType(B->getType().getTypePtr());
645 if (!this->emitGetPtrDerivedPop(NullOK, TargetType, FinalType, E))
649 return this->emitGetPtrDerivedPop(NullOK, FinalType, FinalType, E);
652 case CK_FloatingCast: {
655 return this->emitVectorConversion(E->
getSubExpr(), E);
659 if (!this->
visit(SubExpr))
661 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
665 case CK_IntegralToFloating: {
667 return this->emitVectorConversion(E->
getSubExpr(), E);
670 if (!this->
visit(SubExpr))
672 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
673 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
674 TargetSemantics, getFPOptions(E), E);
677 case CK_FloatingToBoolean: {
679 return this->emitVectorConversion(E->
getSubExpr(), E);
683 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
684 return this->emitConstBool(FL->getValue().isNonZero(), E);
685 if (!this->
visit(SubExpr))
687 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
690 case CK_FloatingToIntegral: {
692 return this->emitVectorConversion(E->
getSubExpr(), E);
695 if (!this->
visit(SubExpr))
699 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
702 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
705 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
708 case CK_NullToPointer:
709 case CK_NullToMemberPointer: {
712 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
717 case CK_PointerToIntegral: {
718 if (!this->
visit(SubExpr))
724 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
730 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
732 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
733 return this->emitCastPointerIntegral(T, E);
736 case CK_ArrayToPointerDecay: {
737 if (!this->
visit(SubExpr))
739 return this->emitArrayDecay(E);
742 case CK_IntegralToPointer: {
744 assert(IntType->isIntegralOrEnumerationType());
745 if (!this->
visit(SubExpr))
759 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
762 case CK_AtomicToNonAtomic:
763 case CK_ConstructorConversion:
764 case CK_FunctionToPointerDecay:
765 case CK_NonAtomicToAtomic:
767 case CK_UserDefinedConversion:
768 case CK_CPointerToObjCPointerCast:
771 case CK_AddressSpaceConversion: {
775 if (!this->
visit(SubExpr))
780 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
787 return this->emitPopPtr(E);
805 return this->emitBuiltinBitCast(E);
820 if (!this->
visit(SubExpr))
828 return this->emitFnPtrCast(E);
836 if (!this->
visit(SubExpr))
838 return this->emitDecayPtr(*FromT, *ToT, E);
840 case CK_IntegralToBoolean:
841 case CK_FixedPointToBoolean: {
843 return this->emitVectorConversion(E->
getSubExpr(), E);
849 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
850 return this->emitConst(IL->getValue(), E);
851 if (!this->
visit(SubExpr))
856 case CK_IntegralCast:
858 return this->emitVectorConversion(E->
getSubExpr(), E);
860 case CK_BooleanToSignedIntegral: {
867 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
872 if (!this->emitConst(IL->getValue(), SubExpr))
875 if (!this->
visit(SubExpr))
883 if (!ED->isFixed()) {
884 if (!this->emitCheckEnumValue(*FromT, ED, E))
890 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
893 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
898 if (!this->emitCast(*FromT, *ToT, E))
901 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
902 return this->emitNeg(*ToT, E);
906 case CK_PointerToBoolean:
907 if (!this->
visit(SubExpr))
909 return this->emitIsNonNullPtr(E);
911 case CK_MemberPointerToBoolean:
912 if (!this->
visit(SubExpr))
914 return this->emitIsNonNullMemberPtr(E);
916 case CK_IntegralComplexToBoolean:
917 case CK_FloatingComplexToBoolean: {
918 if (!this->
visit(SubExpr))
920 return this->emitComplexBoolCast(SubExpr);
923 case CK_IntegralComplexToReal:
924 case CK_FloatingComplexToReal:
925 return this->emitComplexReal(SubExpr);
927 case CK_IntegralRealToComplex:
928 case CK_FloatingRealToComplex: {
935 if (!this->emitGetPtrLocal(*LocalIndex, E))
944 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
946 return this->emitInitElem(T, 1, SubExpr);
949 case CK_IntegralComplexCast:
950 case CK_FloatingComplexCast:
951 case CK_IntegralComplexToFloatingComplex:
952 case CK_FloatingComplexToIntegralComplex: {
959 if (!this->emitGetPtrLocal(*LocalIndex, E))
966 unsigned SubExprOffset =
968 if (!this->
visit(SubExpr))
970 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
978 for (
unsigned I = 0; I != 2; ++I) {
979 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
981 if (!this->emitArrayElemPop(SourceElemT, I, E))
985 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
989 if (!this->emitInitElem(DestElemT, I, E))
995 case CK_VectorSplat: {
1006 if (!this->emitGetPtrLocal(*LocalIndex, E))
1012 unsigned ElemOffset =
1016 if (!this->
visit(SubExpr))
1021 if (!this->emitSetLocal(ElemT, ElemOffset, E))
1024 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
1025 if (!this->emitGetLocal(ElemT, ElemOffset, E))
1027 if (!this->emitInitElem(ElemT, I, E))
1034 case CK_HLSLVectorTruncation: {
1039 if (!this->
visit(SubExpr))
1041 return this->emitArrayElemPop(*ResultT, 0, E);
1050 if (!this->emitGetPtrLocal(*LocalIndex, E))
1055 if (!this->
visit(SubExpr))
1057 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1061 case CK_IntegralToFixedPoint: {
1062 if (!this->
visit(SubExpr))
1066 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1071 return this->emitPopFixedPoint(E);
1074 case CK_FloatingToFixedPoint: {
1075 if (!this->
visit(SubExpr))
1079 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1080 if (!this->emitCastFloatingFixedPoint(Sem, E))
1083 return this->emitPopFixedPoint(E);
1086 case CK_FixedPointToFloating: {
1087 if (!this->
visit(SubExpr))
1089 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1090 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1093 return this->emitPopFloat(E);
1096 case CK_FixedPointToIntegral: {
1097 if (!this->
visit(SubExpr))
1100 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1103 return this->emitPop(IntegralT, E);
1106 case CK_FixedPointCast: {
1107 if (!this->
visit(SubExpr))
1110 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1111 if (!this->emitCastFixedPoint(Sem, E))
1114 return this->emitPopFixedPoint(E);
1122 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1124 case CK_LValueBitCast:
1129 case CK_HLSLArrayRValue: {
1136 if (!this->emitGetPtrLocal(*LocalIndex, E))
1139 if (!this->
visit(SubExpr))
1141 return this->emitMemcpy(E);
1144 case CK_HLSLMatrixTruncation: {
1149 if (!this->
visit(SubExpr))
1151 return this->emitArrayElemPop(*ResultT, 0, E);
1160 if (!this->emitGetPtrLocal(*LocalIndex, E))
1165 if (!this->
visit(SubExpr))
1167 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1171 case CK_HLSLAggregateSplatCast: {
1181 if (!this->emitGetPtrLocal(*LocalIndex, E))
1188 unsigned SrcOffset =
1191 if (!this->
visit(SubExpr))
1193 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1197 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1200 case CK_HLSLElementwiseCast: {
1211 unsigned SrcPtrOffset =
1213 if (!this->
visit(SubExpr))
1215 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1219 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1221 if (Elements.empty())
1224 const HLSLFlatElement &Src = Elements[0];
1225 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1227 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1234 if (!this->emitGetPtrLocal(*LocalIndex, E))
1238 unsigned SrcOffset =
1240 if (!this->
visit(SubExpr))
1242 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1246 unsigned ElemCount = countHLSLFlatElements(DestType);
1249 Elements.reserve(ElemCount);
1250 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1255 assert(Elements.size() == ElemCount &&
1256 "Source type has fewer scalar elements than the destination type");
1258 return emitHLSLConstructAggregate(DestType, Elements, E);
1265 const Record::Field *RF = R->getField(UnionField);
1268 if (!this->
visit(SubExpr))
1270 if (RF->isBitField())
1271 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1273 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1276 if (!this->emitGetPtrField(RF->Offset, E))
1278 if (!this->emitActivate(E))
1284 return this->emitInvalid(E);
1286 llvm_unreachable(
"Unhandled clang::CastKind enum");
1289template <
class Emitter>
1291 return this->emitBuiltinBitCast(E);
1294template <
class Emitter>
1299 return this->emitConst(
LE->getValue(),
LE);
1302template <
class Emitter>
1308 return this->emitFloat(F, E);
1311template <
class Emitter>
1321 if (!this->emitGetPtrLocal(*LocalIndex, E))
1328 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1330 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1334 return this->emitFinishInit(E);
1337template <
class Emitter>
1345 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1350template <
class Emitter>
1355template <
class Emitter>
1382 return this->emitComplexComparison(LHS, RHS, E);
1390 if (!this->
visit(LHS))
1393 if (!this->
visit(RHS))
1396 if (!this->emitToMemberPtr(E))
1402 if (!this->emitCastMemberPtrPtr(E))
1419 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1425 if (!this->emitGetPtrLocal(*ResultIndex, E))
1432 return this->emitCMP3(*
LT, CmpInfo, E);
1435 if (!
LT || !RT || !T)
1445 return this->visitAssignment(LHS, RHS, E);
1452 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1456 return this->emitPopBool(E);
1458 return this->emitCast(
PT_Bool, *T, E);
1462 auto Discard = [
this, T, E](
bool Result) {
1470 return MaybeCastToBool(this->emitEQ(*
LT, E));
1472 return MaybeCastToBool(this->emitNE(*
LT, E));
1474 return MaybeCastToBool(this->emitLT(*
LT, E));
1476 return MaybeCastToBool(this->emitLE(*
LT, E));
1478 return MaybeCastToBool(this->emitGT(*
LT, E));
1480 return MaybeCastToBool(this->emitGE(*
LT, E));
1483 return Discard(this->emitSubf(getFPOptions(E), E));
1484 return Discard(this->emitSub(*T, E));
1487 return Discard(this->emitAddf(getFPOptions(E), E));
1488 return Discard(this->emitAdd(*T, E));
1491 return Discard(this->emitMulf(getFPOptions(E), E));
1492 return Discard(this->emitMul(*T, E));
1494 return Discard(this->emitRem(*T, E));
1497 return Discard(this->emitDivf(getFPOptions(E), E));
1498 return Discard(this->emitDiv(*T, E));
1500 return Discard(this->emitBitAnd(*T, E));
1502 return Discard(this->emitBitOr(*T, E));
1504 return Discard(this->emitShl(*
LT, *RT, E));
1506 return Discard(this->emitShr(*
LT, *RT, E));
1508 return Discard(this->emitBitXor(*T, E));
1511 llvm_unreachable(
"Already handled earlier");
1516 llvm_unreachable(
"Unhandled binary op");
1521template <
class Emitter>
1527 if ((Op != BO_Add && Op != BO_Sub) ||
1538 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1539 if (!this->
visit(E))
1542 return this->emitDecayPtr(T,
PT_Ptr, E);
1551 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1559 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1562 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1569 if (!visitAsPointer(RHS, *RT))
1571 if (!this->
visit(LHS))
1575 if (!visitAsPointer(LHS, *
LT))
1577 if (!this->
visit(RHS))
1588 if (!this->emitAddOffset(OffsetType, E))
1592 if (!this->emitSubOffset(OffsetType, E))
1601 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1606 return this->emitPop(ExprT, E);
1610template <
class Emitter>
1619 LabelTy LabelTrue = this->getLabel();
1620 LabelTy LabelEnd = this->getLabel();
1624 if (!this->jumpTrue(LabelTrue, E))
1629 if (!this->jump(LabelEnd, E))
1632 this->emitLabel(LabelTrue);
1633 this->emitConstBool(
true, E);
1634 this->fallthrough(LabelEnd);
1635 this->emitLabel(LabelEnd);
1638 assert(Op == BO_LAnd);
1641 LabelTy LabelFalse = this->getLabel();
1642 LabelTy LabelEnd = this->getLabel();
1646 if (!this->jumpFalse(LabelFalse, E))
1651 if (!this->jump(LabelEnd, E))
1654 this->emitLabel(LabelFalse);
1655 this->emitConstBool(
false, E);
1656 this->fallthrough(LabelEnd);
1657 this->emitLabel(LabelEnd);
1661 return this->emitPopBool(E);
1666 return this->emitCast(
PT_Bool, T, E);
1671template <
class Emitter>
1678 if (!this->emitGetPtrLocal(*LocalIndex, E))
1687 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1688 unsigned ResultOffset = ~0u;
1694 if (!this->emitDupPtr(E))
1696 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1701 LHSType = AT->getValueType();
1704 RHSType = AT->getValueType();
1713 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1718 if (!this->
visit(LHS))
1720 if (!this->
visit(RHS))
1722 if (!this->emitMulc(ElemT, E))
1725 return this->emitPopPtr(E);
1729 if (Op == BO_Div && RHSIsComplex) {
1736 if (!LHSIsComplex) {
1741 LHSOffset = *LocalIndex;
1743 if (!this->emitGetPtrLocal(LHSOffset, E))
1746 if (!this->
visit(LHS))
1749 if (!this->emitInitElem(ElemT, 0, E))
1752 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1754 if (!this->emitInitElem(ElemT, 1, E))
1757 if (!this->
visit(LHS))
1761 if (!this->
visit(RHS))
1763 if (!this->emitDivc(ElemT, E))
1766 return this->emitPopPtr(E);
1773 if (!this->
visit(LHS))
1775 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1780 if (!this->
visit(LHS))
1782 if (!this->emitSetLocal(LHST, LHSOffset, E))
1790 if (!this->
visit(RHS))
1792 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1797 if (!this->
visit(RHS))
1799 if (!this->emitSetLocal(RHST, RHSOffset, E))
1806 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1807 unsigned ElemIndex,
unsigned Offset,
1808 const Expr *E) ->
bool {
1810 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1812 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1815 if (ElemIndex == 0 || !LoadZero)
1822 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1825 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1832 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1835 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1838 if (!this->emitAddf(getFPOptions(E), E))
1841 if (!this->emitAdd(ResultElemT, E))
1846 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1849 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1852 if (!this->emitSubf(getFPOptions(E), E))
1855 if (!this->emitSub(ResultElemT, E))
1860 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1863 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1867 if (!this->emitMulf(getFPOptions(E), E))
1870 if (!this->emitMul(ResultElemT, E))
1875 assert(!RHSIsComplex);
1876 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1879 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1883 if (!this->emitDivf(getFPOptions(E), E))
1886 if (!this->emitDiv(ResultElemT, E))
1897 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1900 if (!this->emitPop(ResultElemT, E))
1905 return this->emitPopPtr(E);
1908 return this->emitFinishInit(E);
1911template <
class Emitter>
1916 "Comma op should be handled in VisitBinaryOperator");
1920 LHSType = AT->getValueType();
1923 RHSType = AT->getValueType();
1937 if (!this->emitGetPtrLocal(*LocalIndex, E))
1946 PrimType ElemT = this->classifyVectorElementType(LHSType);
1947 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1951 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1954 if (!this->
visit(LHS))
1956 if (!this->
visit(RHS))
1958 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1961 return this->emitPopPtr(E);
1966 unsigned LHSOffset =
1968 if (!this->
visit(LHS))
1970 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1974 unsigned RHSOffset =
1976 if (!this->
visit(RHS))
1978 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1990 if (NeedIntPromot) {
1992 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1997 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1998 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
2000 if (!this->emitArrayElemPop(ElemT, Index, E))
2003 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
2005 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2007 }
else if (NeedIntPromot) {
2008 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
2014#define EMIT_ARITH_OP(OP) \
2016 if (ElemT == PT_Float) { \
2017 if (!this->emit##OP##f(getFPOptions(E), E)) \
2020 if (!this->emit##OP(ElemT, E)) \
2026 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
2027 if (!getElem(LHSOffset, ElemT, I))
2029 if (!getElem(RHSOffset, RHSElemT, I))
2041 if (!this->emitRem(ElemT, E))
2045 if (!this->emitBitAnd(OpT, E))
2049 if (!this->emitBitOr(OpT, E))
2053 if (!this->emitBitXor(OpT, E))
2057 if (!this->emitShl(OpT, RHSElemT, E))
2061 if (!this->emitShr(OpT, RHSElemT, E))
2065 if (!this->emitEQ(ElemT, E))
2069 if (!this->emitNE(ElemT, E))
2073 if (!this->emitLE(ElemT, E))
2077 if (!this->emitLT(ElemT, E))
2081 if (!this->emitGE(ElemT, E))
2085 if (!this->emitGT(ElemT, E))
2090 if (!this->emitBitAnd(ResultElemT, E))
2095 if (!this->emitBitOr(ResultElemT, E))
2099 return this->emitInvalid(E);
2108 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2110 if (!this->emitNeg(ResultElemT, E))
2116 if (NeedIntPromot &&
2117 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2121 if (!this->emitInitElem(ResultElemT, I, E))
2130template <
class Emitter>
2140 auto LHSSemaInt = LHSSema.toOpaqueInt();
2142 auto RHSSemaInt = RHSSema.toOpaqueInt();
2144 if (!this->
visit(LHS))
2152 if (!this->
visit(RHS))
2161 auto ConvertResult = [&](
bool R) ->
bool {
2165 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2166 if (ResultSema != CommonSema)
2167 return this->emitCastFixedPoint(ResultSema, E);
2171 auto MaybeCastToBool = [&](
bool Result) {
2176 return this->emitPop(T, E);
2178 return this->emitCast(
PT_Bool, T, E);
2184 return MaybeCastToBool(this->emitEQFixedPoint(E));
2186 return MaybeCastToBool(this->emitNEFixedPoint(E));
2188 return MaybeCastToBool(this->emitLTFixedPoint(E));
2190 return MaybeCastToBool(this->emitLEFixedPoint(E));
2192 return MaybeCastToBool(this->emitGTFixedPoint(E));
2194 return MaybeCastToBool(this->emitGEFixedPoint(E));
2196 return ConvertResult(this->emitAddFixedPoint(E));
2198 return ConvertResult(this->emitSubFixedPoint(E));
2200 return ConvertResult(this->emitMulFixedPoint(E));
2202 return ConvertResult(this->emitDivFixedPoint(E));
2204 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2206 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2209 return this->emitInvalid(E);
2212 llvm_unreachable(
"unhandled binop opcode");
2215template <
class Emitter>
2224 if (!this->
visit(SubExpr))
2226 if (!this->emitNegFixedPoint(E))
2229 return this->emitPopFixedPoint(E);
2235 llvm_unreachable(
"Unhandled unary opcode");
2238template <
class Emitter>
2247 return this->visitZeroInitializer(*T, QT, E);
2260 return this->visitZeroRecordInitializer(R, E);
2267 return this->visitZeroArrayInitializer(QT, E);
2271 QualType ElemQT = ComplexTy->getElementType();
2273 for (
unsigned I = 0; I < 2; ++I) {
2274 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2276 if (!this->emitInitElem(ElemT, I, E))
2283 unsigned NumVecElements = VecT->getNumElements();
2284 QualType ElemQT = VecT->getElementType();
2287 for (
unsigned I = 0; I < NumVecElements; ++I) {
2288 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2290 if (!this->emitInitElem(ElemT, I, E))
2297 unsigned NumElems = MT->getNumElementsFlattened();
2298 QualType ElemQT = MT->getElementType();
2301 for (
unsigned I = 0; I != NumElems; ++I) {
2302 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2304 if (!this->emitInitElem(ElemT, I, E))
2313template <
class Emitter>
2326 for (
const Expr *SubExpr : {LHS, RHS}) {
2327 if (!this->
visit(SubExpr)) {
2334 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2335 if (!this->emitExpandPtr(E))
2346 return this->emitError(E);
2349 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2353 if (!this->emitArrayElemPtrPop(*IndexT, E))
2356 return this->emitPopPtr(E);
2362 return this->emitLoadPop(*T, E);
2365template <
class Emitter>
2367 const Expr *ArrayFiller,
const Expr *E) {
2372 QT = AT->getValueType();
2375 if (
Inits.size() == 0)
2377 return this->emitInvalid(E);
2390 if (
Inits.size() == 0)
2391 return this->visitZeroInitializer(*T, QT, E);
2392 assert(
Inits.size() == 1);
2406 if (!this->emitGetPtrLocal(*LocalIndex, E))
2421 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2427 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2436 bool BitField = FieldToInit->isBitField();
2438 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2439 FieldToInit->bitWidth(), E);
2441 return this->emitInitBitField(T, FieldToInit->Offset,
2442 FieldToInit->bitWidth(), E);
2444 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2445 return this->emitInitField(T, FieldToInit->Offset, E);
2448 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2456 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2459 if (
Activate && !this->emitActivate(E))
2462 if (!this->emitStartInit(
Init))
2469 if (
Inits.size() == 0) {
2470 if (!this->visitZeroRecordInitializer(R, E))
2475 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2476 FToInit = ILE->getInitializedFieldInUnion();
2480 const Record::Field *FieldToInit = R->getField(FToInit);
2482 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2485 if (!initCompositeField(FieldToInit,
Init,
true))
2489 return this->emitFinishInit(E);
2492 assert(!R->isUnion());
2493 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2495 const Record::Base *B = R->getBase(BI);
2498 if (!this->emitGetPtrBase(B->Offset,
Init))
2504 unsigned FieldIndex = 0;
2505 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2506 const Record::Field *FieldToInit = R->getField(FieldIndex);
2507 if (FieldToInit->isUnnamedBitField()) {
2522 if (!initPrimitiveField(FieldToInit,
Init, *T))
2524 }
else if (!initCompositeField(FieldToInit,
Init)) {
2532 assert(R->getNumVirtualBases() == 0);
2534 return this->emitFinishInit(E);
2539 Ctx.getASTContext().getAsConstantArrayType(QT);
2544 !this->emitCheckArrayDestSize(NumElems, E))
2547 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2551 unsigned ElementIndex = 0;
2553 if (
const auto *EmbedS =
2554 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2562 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2563 getFPOptions(E), E))
2569 return this->emitInitElem(TargetT, ElemIndex, IL);
2571 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2587 for (; ElementIndex != NumElems; ++ElementIndex) {
2593 return this->emitFinishInit(E);
2597 unsigned NumInits =
Inits.size();
2602 QualType ElemQT = ComplexTy->getElementType();
2604 if (NumInits == 0) {
2606 for (
unsigned I = 0; I < 2; ++I) {
2607 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2609 if (!this->emitInitElem(ElemT, I, E))
2612 }
else if (NumInits == 2) {
2613 unsigned InitIndex = 0;
2618 if (!this->emitInitElem(ElemT, InitIndex, E))
2627 unsigned NumVecElements = VecT->getNumElements();
2628 assert(NumVecElements >=
Inits.size());
2630 QualType ElemQT = VecT->getElementType();
2634 unsigned InitIndex = 0;
2641 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2642 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2643 InitVecT->getNumElements(), E))
2645 InitIndex += InitVecT->getNumElements();
2647 if (!this->emitInitElem(ElemT, InitIndex, E))
2653 assert(InitIndex <= NumVecElements);
2656 for (; InitIndex != NumVecElements; ++InitIndex) {
2657 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2659 if (!this->emitInitElem(ElemT, InitIndex, E))
2666 unsigned NumElems = MT->getNumElementsFlattened();
2667 assert(
Inits.size() == NumElems);
2669 QualType ElemQT = MT->getElementType();
2675 for (
unsigned I = 0; I != NumElems; ++I) {
2678 if (!this->emitInitElem(ElemT, I, E))
2689template <
class Emitter>
2696 return this->emitInitElem(*InitT, ElemIndex,
Init);
2702 if (!this->emitConstUint32(ElemIndex,
Init))
2704 if (!this->emitArrayElemPtrUint32(
Init))
2709template <
class Emitter>
2712 bool Activate,
bool IsOperatorCall) {
2714 llvm::BitVector NonNullArgs;
2715 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2718 bool ExplicitMemberFn =
false;
2719 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2720 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2722 unsigned ArgIndex = 0;
2723 for (
const Expr *Arg : Args) {
2725 if (!this->
visit(Arg))
2733 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2734 if (DeclIndex < FuncDecl->getNumParams())
2735 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2744 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2752 if (!this->emitActivate(Arg))
2756 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2759 if (!this->emitCheckNonNullArg(ArgT, Arg))
2770template <
class Emitter>
2775template <
class Emitter>
2781template <
class Emitter>
2787template <
class Emitter>
2807 if (!this->emitGetPtrLocal(*LocalIndex, E))
2813template <
class Emitter>
2815 auto It = E->
begin();
2816 return this->
visit(*It);
2820 UnaryExprOrTypeTrait Kind) {
2825 T = Ref->getPointeeType();
2827 if (T.getQualifiers().hasUnaligned())
2830 bool AlignOfReturnsPreferred =
2835 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2841template <
class Emitter>
2845 UnaryExprOrTypeTrait Kind = E->
getKind();
2848 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2854 ArgType = Ref->getPointeeType();
2860 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2861 return this->emitInvalid(E);
2863 if (Kind == UETT_SizeOf)
2872 return this->emitConst(Size.getQuantity(), E);
2875 if (Kind == UETT_CountOf) {
2881 if (
const auto *CAT =
2885 return this->emitConst(CAT->getSize(), E);
2895 if (VAT->getElementType()->isArrayType()) {
2896 std::optional<APSInt> Res =
2898 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2903 return this->emitConst(*Res, E);
2908 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2928 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2931 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2941 return this->emitConst(Size.getQuantity(), E);
2944 if (Kind == UETT_VectorElements) {
2949 return this->emitConst(VT->getNumElements(), E);
2951 return this->emitSizelessVectorElementSize(E);
2954 if (Kind == UETT_VecStep) {
2956 unsigned N = VT->getNumElements();
2963 return this->emitConst(N, E);
2965 return this->emitConst(1, E);
2968 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2977 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2979 return this->emitInvalid(E);
2981 return this->emitConst(
2990template <
class Emitter>
2999 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
3004 if (VD->getInit() && !VD->getInit()->isValueDependent())
3005 VD->evaluateValue();
3006 if (
auto GlobalIndex =
P.getGlobal(VD)) {
3007 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3009 if (
Member->getType()->isReferenceType())
3010 return this->emitLoadPopPtr(E);
3019 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
3020 MD && !MD->isStatic()) {
3024 if (!this->
discard(Base) && !this->emitSideEffect(E))
3039 const Record::Field *F = R->getField(FD);
3043 const auto maybeLoadValue = [&]() ->
bool {
3047 return this->emitLoadPop(*T, E);
3052 if (F->Decl->getType()->isReferenceType())
3053 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3054 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3057template <
class Emitter>
3067template <
class Emitter>
3077 return this->emitCheckArraySize(Size, E);
3083 if (!this->
visit(Common))
3085 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3099 for (
size_t I = 0; I != Size; ++I) {
3111template <
class Emitter>
3126 return this->emitGetLocal(SubExprT, It->second, E);
3129 if (!this->
visit(SourceExpr))
3136 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3145 return this->emitGetLocal(SubExprT, LocalIndex, E);
3149template <
class Emitter>
3162 bool IsBcpCall =
false;
3163 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3164 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3168 LabelTy LabelEnd = this->getLabel();
3169 LabelTy LabelFalse = this->getLabel();
3172 if (!this->emitPushIgnoreDiags(E))
3180 if (this->checkingForUndefinedBehavior()) {
3183 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))
3686 std::optional<Scope::Local>
Local =
3693 if (!this->VarScope->LocalsAlwaysEnabled &&
3694 !this->emitEnableLocal(
Local->Offset, E))
3697 if (!this->emitGetPtrLocal(
Local->Offset, E))
3702template <
class Emitter>
3713 if (!this->
visit(SubExpr))
3717 return this->emitPopPtr(E);
3721template <
class Emitter>
3742 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3747 if (
P.isGlobalInitialized(*GlobalIndex))
3753 return this->emitInitGlobal(*T, *GlobalIndex, E);
3765 unsigned LocalIndex;
3769 LocalIndex = *MaybeIndex;
3773 if (!this->emitGetPtrLocal(LocalIndex, E))
3777 return this->
visit(
Init) && this->emitInit(*T, E);
3781template <
class Emitter>
3792 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3796 if (!R || R->getNumFields() == 0)
3798 const Record::Field *Field = R->getField(0
U);
3803 return this->emitInitField(*Field->T, Field->Offset, E);
3810template <
class Emitter>
3814 return this->emitConst(E->
getValue(), E);
3817template <
class Emitter>
3830 for (
const Record::Field &F : R->fields()) {
3832 if (!
Init ||
Init->containsErrors())
3840 if (!this->emitInitField(*T, F.Offset, E))
3843 if (!this->emitGetPtrField(F.Offset, E))
3854template <
class Emitter>
3860 return this->emitGetStringPtr(E, E);
3864template <
class Emitter>
3869 return this->emitInvalid(E);
3872template <
class Emitter>
3886 if (!this->emitInvalidCast(
CastKind,
false, E))
3894 bool Fatal = (ToT != FromT);
3901template <
class Emitter>
3903 if (!
Ctx.getLangOpts().CPlusPlus20) {
3924 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3929 return this->emitPopPtr(E);
3933template <
class Emitter>
3939 return this->emitConstBool(E->
getValue(), E);
3942template <
class Emitter>
3947 if (T->isRecordType()) {
3961 if (!this->emitGetPtrLocal(*LocalIndex, E))
3969 T->castAsCXXRecordDecl()))
3979 if (!this->visitZeroRecordInitializer(R, E))
3990 if (!this->emitDefaultInit(Ctor, E))
3993 return this->emitPopPtr(E);
4001 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
4003 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
4004 if (!this->emitCheckFunctionDecl(Ctor, E))
4015 assert(
Func->hasThisPointer());
4016 assert(!
Func->hasRVO());
4020 if (!this->emitDupPtr(E))
4024 for (
const auto *Arg : E->
arguments()) {
4025 if (!this->
visit(Arg))
4029 if (
Func->isVariadic()) {
4030 uint32_t VarArgSize = 0;
4031 unsigned NumParams =
Func->getNumWrittenParams();
4032 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
4036 if (!this->emitCallVar(
Func, VarArgSize, E))
4039 if (!this->emitCall(
Func, 0, E)) {
4044 (void)this->emitPopPtr(E);
4050 return this->emitPopPtr(E);
4054 if (T->isArrayType()) {
4059 if (!this->emitDupPtr(E))
4063 initArrayDimension = [&](
QualType T) ->
bool {
4064 if (!T->isArrayType()) {
4066 for (
const auto *Arg : E->
arguments()) {
4067 if (!this->
visit(Arg))
4071 return this->emitCall(
Func, 0, E);
4075 Ctx.getASTContext().getAsConstantArrayType(T);
4081 return this->emitCheckArraySize(NumElems, E);
4082 for (uint64_t I = 0; I != NumElems; ++I) {
4083 if (!this->emitConstUint64(I, E))
4085 if (!this->emitArrayElemPtrUint64(E))
4087 if (!initArrayDimension(ElemTy))
4090 return this->emitPopPtr(E);
4093 return initArrayDimension(E->
getType());
4099template <
class Emitter>
4109 assert(Val.
isInt());
4111 return this->emitConst(I, E);
4118 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4119 return this->
visit(LValueExpr);
4134 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4138 const APValue &
V = UGCD->getValue();
4139 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4140 const Record::Field *F = R->getField(I);
4141 const APValue &FieldValue =
V.getStructField(I);
4145 if (!this->emitInitField(*F->T, F->Offset, E))
4153template <
class Emitter>
4159 for (
unsigned I = 0; I != N; ++I) {
4166 if (!this->
discard(ArrayIndexExpr))
4172 if (!this->
visit(ArrayIndexExpr))
4174 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4178 if (!this->
visit(ArrayIndexExpr))
4182 if (!this->emitCast(IndexT,
PT_Sint64, E))
4192 return this->emitOffsetOf(T, E, E);
4195template <
class Emitter>
4204 return this->visitZeroInitializer(*T, Ty, E);
4211 if (!this->emitGetPtrLocal(*LocalIndex, E))
4219 ElemQT = CT->getElementType();
4222 NumElems = VT->getNumElements();
4223 ElemQT = VT->getElementType();
4229 for (
unsigned I = 0; I != NumElems; ++I) {
4230 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4232 if (!this->emitInitElem(ElemT, I, E))
4241template <
class Emitter>
4246template <
class Emitter>
4252template <
class Emitter>
4257template <
class Emitter>
4262 return this->emitConst(E->
getValue(), E);
4265template <
class Emitter>
4287 unsigned ParamIndex = 0;
4291 if (!this->emitGetParam(PT, ParamIndex, E))
4296 return this->emitCall(F, 0, E);
4301template <
class Emitter>
4309 const Expr *PlacementDest =
nullptr;
4310 bool IsNoThrow =
false;
4315 if (PlacementArgs != 0) {
4324 if (PlacementArgs == 1) {
4326 if (OperatorNew->isReservedGlobalPlacementOperator()) {
4327 if (!this->emitCheckPlacementNew(E, E))
4329 PlacementDest = Arg1;
4333 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4340 return this->emitInvalidNewDeleteExpr(E, E);
4344 return this->emitInvalid(E);
4346 }
else if (!OperatorNew
4347 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4348 return this->emitInvalidNewDeleteExpr(E, E);
4351 if (!PlacementDest) {
4356 Desc =
P.createDescriptor(E, *ElemT);
4358 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4365 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4369 const Expr *Stripped = *ArraySizeExpr;
4370 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4371 Stripped = ICE->getSubExpr())
4372 if (ICE->getCastKind() != CK_NoOp &&
4373 ICE->getCastKind() != CK_IntegralCast)
4381 if (!this->
visit(Stripped))
4383 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4386 if (PlacementDest) {
4387 if (!this->
visit(PlacementDest))
4389 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4391 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4394 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4399 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4403 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4410 size_t StaticInitElems = 0;
4411 const Expr *DynamicInit =
nullptr;
4415 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4416 StaticInitElems = CAT->getZExtSize();
4421 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4422 if (ILE->hasArrayFiller())
4423 DynamicInit = ILE->getArrayFiller();
4442 const Function *CtorFunc =
nullptr;
4443 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4447 }
else if (!DynamicInit && !ElemT)
4450 LabelTy EndLabel = this->getLabel();
4451 LabelTy StartLabel = this->getLabel();
4456 if (!this->emitDupPtr(E))
4458 if (!this->emitIsNonNullPtr(E))
4460 if (!this->jumpFalse(EndLabel, E))
4467 if (!this->emitConst(StaticInitElems,
SizeT, E))
4469 if (!this->emitSetLocal(
SizeT, Iter, E))
4472 this->fallthrough(StartLabel);
4473 this->emitLabel(StartLabel);
4475 if (!this->emitGetLocal(
SizeT, Iter, E))
4477 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4479 if (!this->emitLT(
SizeT, E))
4481 if (!this->jumpFalse(EndLabel, E))
4485 if (!this->emitGetLocal(
SizeT, Iter, E))
4487 if (!this->emitArrayElemPtr(
SizeT, E))
4490 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4495 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4497 if (!this->emitStorePop(*InitT, E))
4501 if (!this->visitZeroArrayInitializer(ElemType, E))
4504 }
else if (DynamicInit) {
4506 if (!this->
visit(DynamicInit))
4508 if (!this->emitStorePop(*InitT, E))
4515 if (!this->visitZeroInitializer(
4519 if (!this->emitStorePop(*ElemT, E))
4523 if (!this->emitCall(CtorFunc, 0, E))
4528 if (!this->emitGetPtrLocal(Iter, E))
4530 if (!this->emitIncPop(
SizeT,
false, E))
4533 if (!this->jump(StartLabel, E))
4536 this->fallthrough(EndLabel);
4537 this->emitLabel(EndLabel);
4541 if (PlacementDest) {
4542 if (!this->
visit(PlacementDest))
4544 if (!this->emitCheckNewTypeMismatch(E, E))
4549 if (!this->emitAlloc(Desc, E))
4558 if (!this->emitInit(*ElemT, E))
4569 return this->emitPopPtr(E);
4574template <
class Emitter>
4580 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4581 return this->emitInvalidNewDeleteExpr(E, E);
4590template <
class Emitter>
4596 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4601 return this->emitGetFnPtr(
Func, E);
4604template <
class Emitter>
4611 auto canonType = [](
const Type *T) {
4612 return T->getCanonicalTypeUnqualified().getTypePtr();
4620 return this->emitGetTypeid(
4624 return this->emitGetTypeid(
4633 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4639 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4642 return this->emitPopPtr(E);
4646template <
class Emitter>
4650 return this->emitDummyPtr(E, E);
4651 return this->emitError(E);
4654template <
class Emitter>
4657 return this->emitDummyPtr(E, E);
4658 return this->emitError(E);
4661template <
class Emitter>
4668 assert(
false &&
"null reflection can't be constructed from parsing a "
4669 "reflection operand");
4677 assert(
false &&
"unknown or unimplemented reflection entities");
4681template <
class Emitter>
4683 assert(
Ctx.getLangOpts().CPlusPlus);
4684 return this->emitConstBool(E->
getValue(), E);
4687template <
class Emitter>
4699 return this->emitDummyPtr(GuidDecl, E);
4704 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4713 assert(
V.isStruct());
4714 assert(
V.getStructNumBases() == 0);
4718 return this->emitFinishInit(E);
4721template <
class Emitter>
4731template <
class Emitter>
4740template <
class Emitter>
4746template <
class Emitter>
4755 const auto *ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl());
4758 const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext());
4759 if (ED && ED->hasAttr<BPFPreserveAccessIndexAttr>())
4768 if (ED->getDeclName())
4769 EnumTy =
Ctx.getASTContext().getCanonicalTagType(ED);
4771 EnumTy =
Ctx.getASTContext().getTypeDeclType(TD);
4775 return this->emitInvalidAccessIndexAttr(ECD, EnumTy.
getTypePtr(), E);
4779 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4783 if (OVE->isUnique())
4799template <
class Emitter>
4804template <
class Emitter>
4806 return this->emitError(E);
4809template <
class Emitter>
4815 return this->emitDummyPtr(E, E);
4818template <
class Emitter>
4819bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4824 QualType ElemType = VT->getElementType();
4825 PrimType ElemT = classifyPrim(ElemType);
4827 PrimType SrcElemT = classifyVectorElementType(SrcType);
4833 if (!this->emitGetPtrLocal(*LocalIndex, E))
4837 unsigned SrcOffset =
4838 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4839 if (!this->visit(Src))
4841 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4844 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4845 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4847 if (!this->emitArrayElemPop(SrcElemT, I, E))
4851 if (SrcElemT != ElemT) {
4852 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4854 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4855 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4859 if (!this->emitInitElem(ElemT, I, E))
4865template <
class Emitter>
4867 return emitVectorConversion(E->
getSrcExpr(), E);
4870template <
class Emitter>
4874 return this->emitInvalid(E);
4883 assert(NumOutputElems > 0);
4889 if (!this->emitGetPtrLocal(*LocalIndex, E))
4894 unsigned VectorOffsets[2];
4895 for (
unsigned I = 0; I != 2; ++I) {
4898 if (!this->
visit(Vecs[I]))
4900 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4903 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4905 assert(ShuffleIndex >= -1);
4906 if (ShuffleIndex == -1)
4907 return this->emitInvalidShuffleVectorIndex(I, E);
4909 assert(ShuffleIndex < (NumInputElems * 2));
4910 if (!this->emitGetLocal(
PT_Ptr,
4911 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4913 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4914 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4917 if (!this->emitInitElem(ElemT, I, E))
4922 return this->emitPopPtr(E);
4927template <
class Emitter>
4932 Base->getType()->isVectorType() ||
4938 if (Indices.size() == 1) {
4943 if (!this->emitConstUint32(Indices[0], E))
4945 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4955 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4963 if (!this->emitGetPtrLocal(*ResultIndex, E))
4971 uint32_t DstIndex = 0;
4972 for (uint32_t I : Indices) {
4973 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4975 if (!this->emitArrayElemPop(ElemT, I, E))
4977 if (!this->emitInitElem(ElemT, DstIndex, E))
4987template <
class Emitter>
4991 return this->
discard(SubExpr) && this->emitInvalid(E);
4997 return this->emitDummyPtr(E, E);
5000template <
class Emitter>
5005 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
5014 if (!this->emitGetPtrLocal(*LocalIndex, E))
5018 if (!this->
visit(SubExpr))
5020 if (!this->emitConstUint8(0, E))
5022 if (!this->emitArrayElemPtrPopUint8(E))
5024 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
5027 PrimType SecondFieldT = *R->getField(1u)->T;
5029 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
5031 if (!this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E))
5034 return this->emitPopPtr(E);
5037 assert(SecondFieldT ==
PT_Ptr);
5039 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
5041 if (!this->emitExpandPtr(E))
5045 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5048 if (!this->emitInitFieldPtr(R->getField(1u)->Offset, E))
5051 return this->emitPopPtr(E);
5055template <
class Emitter>
5070 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
5074 return this->emitUnsupported(E);
5083 return this->
Visit(E);
5090 return this->
Visit(E);
5094 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5097 if (
const auto *CE = dyn_cast<CastExpr>(E);
5099 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
5106 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5109 if (
const auto *CE = dyn_cast<CastExpr>(E);
5110 CE && (CE->getCastKind() == CK_DerivedToBase ||
5111 CE->getCastKind() == CK_UncheckedDerivedToBase ||
5112 CE->getCastKind() == CK_NoOp))
5127 std::optional<Scope::Local>
Local =
5134 if (!this->emitGetPtrLocal(
Local->Offset, E))
5143 return this->
Visit(E);
5146template <
class Emitter>
5152 return this->
Visit(E) && this->emitFinishInit(E);
5155template <
class Emitter>
5161 return this->
Visit(E) && this->emitFinishInitPop(E);
5167 return this->
Visit(E);
5178 if (!this->
visit(E))
5180 return this->emitComplexBoolCast(E);
5185 if (!this->
visit(E))
5193 return this->emitIsNonNullPtr(E);
5197 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5200 return this->emitCast(*T,
PT_Bool, E);
5203template <
class Emitter>
5207 QT = AT->getValueType();
5211 return this->emitZeroBool(E);
5213 return this->emitZeroSint8(E);
5215 return this->emitZeroUint8(E);
5217 return this->emitZeroSint16(E);
5219 return this->emitZeroUint16(E);
5221 return this->emitZeroSint32(E);
5223 return this->emitZeroUint32(E);
5225 return this->emitZeroSint64(E);
5227 return this->emitZeroUint64(E);
5229 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5231 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5233 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5236 return this->emitNullMemberPtr(0,
nullptr, E);
5238 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5239 return this->emitFloat(F, E);
5242 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5248 llvm_unreachable(
"unknown primitive type");
5251template <
class Emitter>
5252bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5254 bool IsCompleteClass) {
5258 for (
const Record::Field &Field :
R->fields()) {
5259 if (Field.isUnnamedBitField())
5266 if (!this->visitZeroInitializer(T, QT, E))
5269 if (!this->emitInitFieldActivate(T, Field.Offset, E))
5273 if (!this->emitInitField(T, Field.Offset, E))
5278 if (!this->emitGetPtrField(Field.Offset, E))
5285 if (!this->visitZeroInitializer(T, ET, E))
5287 if (!this->emitInitElem(T, I, E))
5292 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5295 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5303 if (!this->emitFinishInitActivatePop(E))
5307 if (!this->emitFinishInitPop(E))
5311 for (
const Record::Base &B :
R->bases()) {
5312 if (!this->emitGetPtrBase(B.Offset, E))
5314 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5316 if (!this->emitFinishInitPop(E))
5320 if (IsCompleteClass) {
5321 for (
const Record::Base &B :
R->virtual_bases()) {
5324 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5326 if (!this->emitFinishInitPop(E))
5334template <
class Emitter>
5335bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5336 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
5342 for (
size_t I = 0; I != NumElems; ++I) {
5343 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5345 if (!this->emitInitElem(*ElemT, I, E))
5351 const Record *
R = getRecord(ElemType);
5355 for (
size_t I = 0; I != NumElems; ++I) {
5356 if (!this->emitConstUint32(I, E))
5358 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5360 if (!this->visitZeroRecordInitializer(R, E))
5362 if (!this->emitPopPtr(E))
5368 for (
size_t I = 0; I != NumElems; ++I) {
5369 if (!this->emitConstUint32(I, E))
5371 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5373 if (!this->visitZeroArrayInitializer(ElemType, E))
5375 if (!this->emitPopPtr(E))
5384template <
class Emitter>
5385bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5387 if (!canClassify(E->
getType()))
5392 if (!this->visit(LHS))
5394 if (!this->visit(RHS))
5397 if (!this->visit(RHS))
5399 if (!this->visit(LHS))
5407 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5411 bool Activates = refersToUnion(LHS);
5414 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5417 if (DiscardResult) {
5418 if (BitField && Activates)
5419 return this->emitStoreBitFieldActivatePop(RHT, E);
5421 return this->emitStoreBitFieldPop(RHT, E);
5423 return this->emitStoreActivatePop(RHT, E);
5425 return this->emitStorePop(RHT, E);
5428 auto maybeLoad = [&](
bool Result) ->
bool {
5434 return this->emitLoadPop(RHT, E);
5438 if (BitField && Activates)
5439 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5441 return maybeLoad(this->emitStoreBitField(RHT, E));
5443 return maybeLoad(this->emitStoreActivate(RHT, E));
5445 return maybeLoad(this->emitStore(RHT, E));
5448template <
class Emitter>
5449template <
typename T>
5453 return this->emitConstSint8(
Value, Info);
5455 return this->emitConstUint8(
Value, Info);
5457 return this->emitConstSint16(
Value, Info);
5459 return this->emitConstUint16(
Value, Info);
5461 return this->emitConstSint32(
Value, Info);
5463 return this->emitConstUint32(
Value, Info);
5465 return this->emitConstSint64(
Value, Info);
5467 return this->emitConstUint64(
Value, Info);
5469 return this->emitConstBool(
Value, Info);
5477 llvm_unreachable(
"Invalid integral type");
5480 llvm_unreachable(
"unknown primitive type");
5483template <
class Emitter>
5484template <
typename T>
5485bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
5486 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5489template <
class Emitter>
5493 return this->emitConstIntAPS(
Value, Info);
5495 return this->emitConstIntAP(
Value, Info);
5497 if (
Value.isSigned())
5498 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5499 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5502template <
class Emitter>
5506 return this->emitConstIntAPS(
Value, Info);
5508 return this->emitConstIntAP(
Value, Info);
5511 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5512 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5515template <
class Emitter>
5516bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5517 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5520template <
class Emitter>
5534 return Local.Offset;
5537template <
class Emitter>
5542 return std::nullopt;
5544 return Local->Offset;
5547template <
class Emitter>
5548std::optional<Scope::Local>
5552 bool IsTemporary =
false;
5556 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5557 Init = VarD->getInit();
5559 if (
const auto *E = Src.
asExpr()) {
5569 return std::nullopt;
5577template <
class Emitter>
5586 return std::nullopt;
5596 return Local.Offset;
5599template <
class Emitter>
5601 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5602 return PT->getPointeeType()->getAsCanonical<RecordType>();
5608 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5612template <
class Emitter>
5614 return P.getOrCreateRecord(RD);
5617template <
class Emitter>
5619 return Ctx.getOrCreateFunction(FD);
5622template <
class Emitter>
5628 auto maybeDestroyLocals = [&]() ->
bool {
5629 if (DestroyToplevelScope)
5630 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5631 return this->emitCheckAllocations(E);
5638 return this->emitRetVoid(E) && maybeDestroyLocals();
5646 return this->emitRet(*T, E) && maybeDestroyLocals();
5654 if (!this->emitGetPtrLocal(*LocalOffset, E))
5662 return this->emitRetValue(E) && maybeDestroyLocals();
5665 return maybeDestroyLocals() &&
false;
5668template <
class Emitter>
5670 bool DestroyToplevelScope) {
5674 return this->
visitExpr(E, DestroyToplevelScope);
5677template <
class Emitter>
5689 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5690 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5704template <
class Emitter>
5706 bool ConstantContext) {
5709 if (!ConstantContext) {
5724 auto GlobalIndex =
P.getGlobal(VD);
5725 assert(GlobalIndex);
5727 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5730 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5738 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5740 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5743 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5753 auto GlobalIndex =
P.getGlobal(VD);
5754 assert(GlobalIndex);
5755 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5764 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5767template <
class Emitter>
5778 if (!this->isActive())
5783 if (
Init &&
Init->isValueDependent())
5787 auto checkDecl = [&]() ->
bool {
5789 return !NeedsOp || this->emitCheckDecl(VD, VD);
5796 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5799 if (
P.isGlobalInitialized(*GlobalIndex))
5803 }
else if ((GlobalIndex =
5818 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5821 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5824 if (!this->emitStartInit(
Init))
5830 if (!this->emitEndInit(
Init))
5833 return this->emitFinishInitGlobal(
Init);
5843 if (!
Init ||
Init->getType()->isVoidType())
5852 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5864 if (!this->emitCheckRefInit(
Init))
5868 return this->emitSetLocal(*VarT, Offset, VD);
5877 if (!this->emitGetPtrLocal(
Local->Offset,
Init))
5882template <
class Emitter>
5905 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5911 return this->emitDestructionPop(D, VD);
5920 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5944template <
class Emitter>
5959 unsigned ParamIndex = 0;
5966 const Expr *Arg = Args[ParamIndex];
5967 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5969 unsigned ArgOffset =
5971 if (!this->
visit(Arg))
5973 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5979 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5991 if (
This->getType()->isPointerType()) {
5994 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
6001 if (!this->emitGetPtrLocal(*ArgOffset,
This))
6023template <
class Emitter>
6029 return this->emitConst(Val.
getInt(), ValType, Info);
6031 return this->emitFloat(Val.
getFloat(), Info);
6035 if (!this->emitGetMemberPtr(MemberDecl, Info))
6041 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
6047 return this->emitNullMemberPtr(0,
nullptr, Info);
6052 return this->emitNull(ValType, 0,
nullptr, Info);
6056 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>()) {
6059 GlobalIndex &&
P.isGlobalInitialized(*GlobalIndex)) {
6060 if (!this->emitGetPtrGlobal(*GlobalIndex, Info))
6063 if (!this->
visit(BaseExpr))
6066 EntryType = BaseExpr->getType();
6067 }
else if (
const auto *VD =
Base.dyn_cast<
const ValueDecl *>()) {
6070 EntryType = VD->getType();
6075 ->getCanonicalTypeUnqualified()
6077 EntryType =
Base.getTypeInfoType();
6078 if (!this->emitGetTypeid(OperandType, EntryType.
getTypePtr(), Info))
6086 ?
Ctx.getASTContext().getPointerType(E->
getType())
6089 if (!this->emitConstUint64(Offset, Info))
6091 if (!this->emitGetIntPtrUint64(PtrType.
getTypePtr(), Info))
6101 uint64_t Index = Entry.getAsArrayIndex();
6104 if (!this->emitConst(Index,
PT_Uint64, Info))
6106 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
6108 EntryType = ElemType;
6115 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
6116 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
6118 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
6120 EntryType = FD->getType();
6124 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
6129 if (!this->emitGetPtrVirtBasePop(
Base, Info))
6132 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
6147 uint32_t BitWidth =
Ctx.getBitWidth(E->
getType());
6149 ? this->emitCastPointerIntegralAP(BitWidth, Info)
6150 : this->emitCastPointerIntegralAPS(BitWidth, Info);
6152 return this->emitCastPointerIntegral(ValType, Info);
6158template <
class Emitter>
6161 bool IsCompleteClass) {
6167 if (IsCompleteClass)
6174 const Record::Base *RB = R->getBase(I);
6175 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6177 if (!this->emitGetPtrBase(RB->Offset, Info))
6182 if (!this->emitFinishInitPop(Info))
6190 const Record::Field *RF = R->getField(I);
6191 QualType FieldType = RF->Decl->getType();
6196 if (!this->emitInitField(*PT, RF->Offset, Info))
6199 if (!this->emitGetPtrField(RF->Offset, Info))
6203 if (!this->emitFinishInitPop(Info))
6209 if (IsCompleteClass) {
6214 const Record::Base *RB = R->getVirtualBase(I);
6215 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6223 if (!this->emitFinishInitPop(Info))
6239 const Record::Field *RF = R->getField(UnionField);
6240 QualType FieldType = RF->Decl->getType();
6245 if (RF->isBitField())
6246 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6248 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6251 if (!this->emitGetPtrField(RF->Offset, Info))
6253 if (!this->emitActivate(Info))
6257 return this->emitPopPtr(Info);
6261 const auto *ArrType = T->getAsArrayTypeUnsafe();
6262 QualType ElemType = ArrType->getElementType();
6265 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6266 const APValue &Elem = A >= InitializedElems
6275 if (!this->emitInitElem(*ElemT, A, Info))
6278 if (!this->emitConstUint32(A, Info))
6280 if (!this->emitArrayElemPtrUint32(Info))
6284 if (!this->emitPopPtr(Info))
6291 assert(T->isComplexType());
6294 if (!this->emitInitElemFloat(0, Info))
6298 if (!this->emitInitElemFloat(1, Info))
6303 assert(T->isComplexIntegerType());
6307 if (!this->emitInitElem(IntT, 0, Info))
6311 if (!this->emitInitElem(IntT, 1, Info))
6316 assert(T->isVectorType());
6324 if (!this->emitInitElem(ElemT, I, Info))
6334template <
class Emitter>
6336 if (
P.getGlobal(VD))
6340 P.createGlobal(VD,
nullptr,
false,
6343 llvm_unreachable(
"Why didn't that work?");
6347 "registerRedecl should only be called with primitive values");
6352 return this->emitInitGlobal(T, *GlobalIndex, {});
6355template <
class Emitter>
6357 unsigned BuiltinID) {
6363 if (!
Ctx.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
6364 return this->emitInvalid(E);
6373 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6378 return this->emitConst(0, E);
6381 if (!this->emitStartSpeculation(E))
6383 LabelTy EndLabel = this->getLabel();
6384 if (!this->speculate(E, EndLabel))
6386 if (!this->emitEndSpeculation(E))
6388 this->fallthrough(EndLabel);
6396 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6397 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6398 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6399 BuiltinID == Builtin::BI__builtin_function_start) {
6402 return this->emitDummyPtr(E, E);
6413 if (!this->emitGetPtrLocal(*LocalIndex, E))
6418 switch (BuiltinID) {
6419 case Builtin::BI__builtin_object_size:
6420 case Builtin::BI__builtin_dynamic_object_size: {
6424 if (!this->
visit(Arg0))
6435 case Builtin::BI__assume:
6436 case Builtin::BI__builtin_assume:
6439 case Builtin::BI__atomic_is_lock_free:
6440 case Builtin::BI__atomic_always_lock_free: {
6451 for (
const auto *Arg : E->
arguments()) {
6452 if (!this->
visit(Arg))
6458 if (!this->emitCallBI(E, BuiltinID, E))
6477template <
class Emitter>
6498 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6499 DD && DD->isTrivial()) {
6501 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6503 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6504 this->emitPopPtr(E);
6509 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6510 MD && MD->getParent()->isInvalidDecl())
6515 bool ActivateLHS =
false;
6523 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6524 OCE && OCE->isAssignmentOp()) {
6525 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6528 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6529 if (!this->
visit(MCE->getImplicitObjectArgument()))
6536 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6546 bool HasRVO = !
ReturnType->isVoidType() && !T;
6554 if (!this->emitGetPtrLocal(*LocalIndex, E))
6562 if (!this->emitGetPtrLocal(*LocalIndex, E))
6566 if (!this->emitDupPtr(E))
6571 const Expr *ReversedArgs[2];
6572 bool IsAssignmentOperatorCall =
false;
6573 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6574 OCE && OCE->isAssignmentOp()) {
6578 assert(Args.size() == 2);
6579 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6581 IsAssignmentOperatorCall =
true;
6582 ReversedArgs[0] = Args[1];
6583 ReversedArgs[1] = Args[0];
6584 Args = ReversedArgs;
6591 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6592 MD && MD->isStatic()) {
6596 Args = Args.drop_front();
6600 bool Devirtualized =
false;
6603 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6611 if (!this->
visit(Callee))
6613 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6615 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6617 if (!this->emitGetMemberPtrBase(E))
6620 const auto *InstancePtr = MC->getImplicitObjectArgument();
6627 Stripped->getType()->getPointeeType()->castAsCXXRecordDecl());
6628 Devirtualized =
true;
6629 if (!this->
visit(Stripped))
6632 if (!this->
visit(InstancePtr))
6636 if (!this->
visit(InstancePtr))
6640 }
else if (
const auto *PD =
6641 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6642 if (!this->emitCheckPseudoDtor(E))
6650 return this->emitPseudoDtor(E);
6651 }
else if (!FuncDecl) {
6655 if (!this->
visit(Callee))
6657 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6666 if (IsAssignmentOperatorCall) {
6667 assert(Args.size() == 2);
6670 if (!this->emitFlip(Arg2T, Arg1T, E))
6684 assert(HasRVO ==
Func->hasRVO());
6686 bool HasQualifier =
false;
6687 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6688 HasQualifier = ME->hasQualifier();
6690 bool IsVirtual =
false;
6691 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6692 IsVirtual = !Devirtualized && MD->isVirtual();
6697 if (IsVirtual && !HasQualifier) {
6698 uint32_t VarArgSize = 0;
6699 unsigned NumParams =
6700 Func->getNumWrittenParams() +
6702 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6705 if (!this->emitCallVirt(
Func, VarArgSize, E))
6707 }
else if (
Func->isVariadic()) {
6708 uint32_t VarArgSize = 0;
6709 unsigned NumParams =
6710 Func->getNumWrittenParams() +
6712 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6714 if (!this->emitCallVar(
Func, VarArgSize, E))
6717 if (!this->emitCall(
Func, 0, E))
6726 uint32_t ArgSize = 0;
6727 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6733 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6735 if (!this->emitGetMemberPtrDecl(E))
6738 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6741 if (!this->emitCallPtr(ArgSize, E, E))
6752template <
class Emitter>
6759template <
class Emitter>
6766template <
class Emitter>
6771 return this->emitConstBool(E->
getValue(), E);
6774template <
class Emitter>
6780 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6781 return this->emitNullPtr(Val,
nullptr, E);
6784template <
class Emitter>
6792 return this->emitZero(T, E);
6795template <
class Emitter>
6800 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6801 if (this->LambdaThisCapture.Offset > 0) {
6802 if (this->LambdaThisCapture.IsPtr)
6803 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6804 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6813 return this->emitThis(E);
6828 unsigned StartIndex = 0;
6829 unsigned EndIndex = 0;
6831 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6833 EndIndex = StartIndex;
6840 for (; StartIndex > 0; --StartIndex) {
6851 if (StartIndex == 0 && EndIndex == 0)
6862 assert(StartIndex <= EndIndex);
6865 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6877 case Stmt::CompoundStmtClass:
6879 case Stmt::DeclStmtClass:
6881 case Stmt::ReturnStmtClass:
6883 case Stmt::IfStmtClass:
6885 case Stmt::WhileStmtClass:
6887 case Stmt::DoStmtClass:
6889 case Stmt::ForStmtClass:
6891 case Stmt::CXXForRangeStmtClass:
6893 case Stmt::BreakStmtClass:
6895 case Stmt::ContinueStmtClass:
6897 case Stmt::SwitchStmtClass:
6899 case Stmt::CaseStmtClass:
6901 case Stmt::DefaultStmtClass:
6903 case Stmt::AttributedStmtClass:
6905 case Stmt::CXXTryStmtClass:
6907 case Stmt::NullStmtClass:
6910 case Stmt::GCCAsmStmtClass:
6911 case Stmt::MSAsmStmtClass:
6912 case Stmt::GotoStmtClass:
6913 return this->emitInvalid(S);
6914 case Stmt::LabelStmtClass:
6916 case Stmt::CXXExpansionStmtInstantiationClass:
6920 if (
const auto *E = dyn_cast<Expr>(S))
6927template <
class Emitter>
6930 for (
const auto *InnerStmt : S->
body())
6933 return Scope.destroyLocals();
6936template <
class Emitter>
6937bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6938 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6939 for (
auto *BD : DD->flat_bindings())
6940 if (
auto *KD = BD->getHoldingVar();
6941 KD && !this->visitVarDecl(KD, KD->getInit()))
6955template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6957 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6958 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6965 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6970 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6971 ICE && (ICE->getCastKind() == CK_NoOp ||
6972 ICE->getCastKind() == CK_DerivedToBase ||
6973 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6974 E = ICE->getSubExpr();
6978 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6979 const auto *ThisRecord =
6980 This->getType()->getPointeeType()->getAsRecordDecl();
6981 if (!ThisRecord->isUnion())
6984 if (
const auto *Ctor =
6985 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6986 return Ctor->getParent() == ThisRecord;
6995template <
class Emitter>
6997 bool EvaluateConditionDecl) {
6998 for (
const auto *D : DS->
decls()) {
7003 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
7004 assert(ESD->getInstantiations() &&
"not expanded?");
7005 if (!this->
visitStmt(ESD->getInstantiations()))
7010 const auto *VD = dyn_cast<VarDecl>(D);
7017 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
7024template <
class Emitter>
7027 return this->emitUnsupported(RS);
7033 if (!this->
visit(RE))
7039 if (RE->getType()->isVoidType()) {
7040 if (!this->
visit(RE))
7043 if (RE->containsErrors())
7048 if (!this->emitRVOPtr(RE))
7054 return this->emitRetVoid(RS);
7064 return this->emitRetVoid(RS);
7070 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
7077 if (
auto *CondInit = IS->
getInit()) {
7093 return visitChildStmt(IS->
getThen());
7095 return visitChildStmt(Else);
7101 if (!this->emitIsConstantContext(IS))
7104 if (!this->emitIsConstantContext(IS))
7106 if (!this->emitInv(IS))
7120 LabelTy LabelElse = this->getLabel();
7121 LabelTy LabelEnd = this->getLabel();
7122 if (!this->jumpFalse(LabelElse, IS))
7124 if (!visitChildStmt(IS->
getThen()))
7126 if (!this->jump(LabelEnd, IS))
7128 this->emitLabel(LabelElse);
7129 if (!visitChildStmt(Else))
7131 this->emitLabel(LabelEnd);
7133 LabelTy LabelEnd = this->getLabel();
7134 if (!this->jumpFalse(LabelEnd, IS))
7136 if (!visitChildStmt(IS->
getThen()))
7138 this->emitLabel(LabelEnd);
7147template <
class Emitter>
7152 LabelTy CondLabel = this->getLabel();
7153 LabelTy EndLabel = this->getLabel();
7157 this->fallthrough(CondLabel);
7158 this->emitLabel(CondLabel);
7174 if (!this->jumpFalse(EndLabel, S))
7184 if (!this->jump(CondLabel, S))
7186 this->fallthrough(EndLabel);
7187 this->emitLabel(EndLabel);
7196 LabelTy StartLabel = this->getLabel();
7197 LabelTy EndLabel = this->getLabel();
7198 LabelTy CondLabel = this->getLabel();
7202 this->fallthrough(StartLabel);
7203 this->emitLabel(StartLabel);
7209 this->fallthrough(CondLabel);
7210 this->emitLabel(CondLabel);
7217 if (!this->jumpTrue(StartLabel, S))
7220 this->fallthrough(EndLabel);
7221 this->emitLabel(EndLabel);
7225template <
class Emitter>
7233 LabelTy EndLabel = this->getLabel();
7234 LabelTy CondLabel = this->getLabel();
7235 LabelTy IncLabel = this->getLabel();
7242 this->fallthrough(CondLabel);
7243 this->emitLabel(CondLabel);
7255 if (!this->jumpFalse(EndLabel, S))
7264 this->fallthrough(IncLabel);
7265 this->emitLabel(IncLabel);
7271 if (!this->jump(CondLabel, S))
7275 this->emitLabel(EndLabel);
7281template <
class Emitter>
7291 LabelTy EndLabel = this->getLabel();
7292 LabelTy CondLabel = this->getLabel();
7293 LabelTy IncLabel = this->getLabel();
7309 this->fallthrough(CondLabel);
7310 this->emitLabel(CondLabel);
7313 if (!this->jumpFalse(EndLabel, S))
7324 this->fallthrough(IncLabel);
7325 this->emitLabel(IncLabel);
7332 if (!this->jump(CondLabel, S))
7335 this->fallthrough(EndLabel);
7336 this->emitLabel(EndLabel);
7340template <
class Emitter>
7343 return this->emitInvalidTargetLabel(
false, S);
7351 if (LI.BreakLabel) {
7352 TargetLabel = *LI.BreakLabel;
7353 BreakScope = LI.BreakOrContinueScope;
7362 return this->emitInvalidTargetLabel(
false, S);
7365 if (LI.Name == TargetLoop) {
7366 TargetLabel = *LI.BreakLabel;
7367 BreakScope = LI.BreakOrContinueScope;
7378 C =
C->getParent()) {
7379 if (!
C->destroyLocals())
7383 return this->jump(*TargetLabel, S);
7386template <
class Emitter>
7389 return this->emitInvalidTargetLabel(
true, S);
7396 if (LI.ContinueLabel) {
7397 TargetLabel = *LI.ContinueLabel;
7398 ContinueScope = LI.BreakOrContinueScope;
7407 return this->emitInvalidTargetLabel(
true, S);
7410 if (LI.Name == TargetLoop) {
7411 TargetLabel = *LI.ContinueLabel;
7412 ContinueScope = LI.BreakOrContinueScope;
7422 C =
C->getParent()) {
7423 if (!
C->destroyLocals())
7427 return this->jump(*TargetLabel, S);
7430template <
class Emitter>
7440 LabelTy EndLabel = this->getLabel();
7445 if (
const auto *CondInit = S->
getInit())
7454 if (!this->
visit(Cond))
7456 if (!this->emitSetLocal(CondT, CondVar, S))
7466 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7469 if (CS->caseStmtIsGNURange()) {
7470 LabelTy EndOfRangeCheck = this->getLabel();
7471 const Expr *Low = CS->getLHS();
7472 const Expr *High = CS->getRHS();
7476 if (!this->emitGetLocal(CondT, CondVar, CS))
7478 if (!this->
visit(Low))
7481 if (!this->emitGE(
LT, S))
7483 if (!this->jumpFalse(EndOfRangeCheck, S))
7486 if (!this->emitGetLocal(CondT, CondVar, CS))
7488 if (!this->
visit(High))
7491 if (!this->emitLE(HT, S))
7495 this->emitLabel(EndOfRangeCheck);
7500 if (
Value->isValueDependent())
7505 if (!this->emitGetLocal(CondT, CondVar, CS))
7511 if (!this->emitEQ(ValueT, S))
7516 assert(!DefaultLabel);
7517 DefaultLabel = this->getLabel();
7524 if (!this->jump(*DefaultLabel, S))
7527 if (!this->jump(EndLabel, S))
7535 this->fallthrough(EndLabel);
7536 this->emitLabel(EndLabel);
7541template <
class Emitter>
7549 return this->emitUnsupported(S);
7554template <
class Emitter>
7561 if (LI.DefaultLabel) {
7562 DefaultLabel = *LI.DefaultLabel;
7567 this->emitLabel(DefaultLabel);
7571template <
class Emitter>
7578 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7581 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7582 !this->Ctx.getLangOpts().MSVCCompat) {
7584 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7590 const Expr *Assumption = AA->getAssumption();
7601 if (!this->emitAssume(Assumption))
7610 if (IsMSVCConstexprAttr)
7611 return this->emitPopMSVCCE(S);
7615template <
class Emitter>
7628template <
class Emitter>
7638 LabelTy EndLabel = this->getLabel();
7640 LabelTy ContinueLabel = this->getLabel();
7645 this->emitLabel(ContinueLabel);
7648 this->emitLabel(EndLabel);
7653template <
class Emitter>
7654bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7661 assert(ClosureClass->
captures().empty());
7665 "A generic lambda's static-invoker function must be a "
7666 "template specialization");
7670 llvm::FoldingSetInsertToken InsertToken;
7671 const FunctionDecl *CorrespondingCallOpSpecialization =
7673 assert(CorrespondingCallOpSpecialization);
7674 LambdaCallOp = CorrespondingCallOpSpecialization;
7678 assert(ClosureClass->
captures().empty());
7679 const Function *
Func = this->getFunction(LambdaCallOp);
7682 assert(
Func->hasThisPointer());
7685 if (
Func->hasRVO()) {
7686 if (!this->emitRVOPtr(MD))
7694 if (!this->emitNullPtr(0,
nullptr, MD))
7699 auto It = this->Params.find(PVD);
7700 assert(It != this->Params.end());
7704 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7705 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7709 if (!this->emitCall(
Func, 0, LambdaCallOp))
7714 return this->emitRet(*ReturnType, MD);
7717 return this->emitRetVoid(MD);
7720template <
class Emitter>
7721bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7722 if (Ctx.getLangOpts().CPlusPlus23)
7732 const Expr *InitExpr =
Init->getInit();
7734 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7738 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7748template <
class Emitter>
7750 assert(!ReturnType);
7753 if (!this->emitStartThisLifetime1(Ctor))
7756 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7757 const Expr *InitExpr,
7760 if (InitExpr->getType().isNull())
7764 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7767 if (!this->visit(InitExpr))
7770 if (F->isBitField())
7771 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
7773 return this->emitInitThisField(*T, FieldOffset, InitExpr);
7778 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7781 if (
Activate && !this->emitActivate(InitExpr))
7784 return this->visitInitializerPop(InitExpr);
7788 const Record *
R = this->getRecord(RD);
7791 bool IsUnion =
R->isUnion();
7801 if (!this->emitThis(Ctor))
7804 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7807 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7808 this->emitRetVoid(Ctor);
7811 unsigned FieldInits = 0;
7814 if (
R->getNumVirtualBases() > 0) {
7815 if (!this->emitThis(Ctor))
7817 LabelTy AfterVirtBasesLabel = this->getLabel();
7820 if (!this->emitIsBaseClass({}))
7822 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7825 for (
const auto *
Init : Ctor->
inits()) {
7826 LocalScope<Emitter> VirtLocalScope(
this);
7829 const auto *BaseDecl =
Base->castAsCXXRecordDecl();
7830 assert(
R->findVirtualBase(BaseDecl));
7831 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7833 if (!this->visitInitializerPop(
Init->getInit()))
7836 if (!VirtLocalScope.destroyLocals())
7840 this->fallthrough(AfterVirtBasesLabel);
7841 this->emitLabel(AfterVirtBasesLabel);
7843 if (!this->emitPopPtr(Ctor))
7847 for (
const auto *
Init : Ctor->
inits()) {
7851 const Expr *InitExpr =
Init->getInit();
7853 const Record::Field *F =
R->getField(
Member);
7857 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7861 const auto *BaseDecl =
Base->castAsCXXRecordDecl();
7863 if (
Init->isBaseVirtual()) {
7869 const Record::Base *B =
R->getBase(BaseDecl);
7871 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7875 if (!this->visitInitializerPop(InitExpr))
7880 unsigned ChainSize = IFD->getChainingSize();
7881 assert(ChainSize >= 2);
7883 unsigned NestedFieldOffset = 0;
7884 const Record::Field *NestedField =
nullptr;
7885 for (
unsigned I = 0; I != ChainSize; ++I) {
7887 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7888 assert(FieldRecord);
7890 NestedField = FieldRecord->
getField(FD);
7891 assert(NestedField);
7892 IsUnion = IsUnion || FieldRecord->
isUnion();
7894 NestedFieldOffset += NestedField->Offset;
7897 if (I != ChainSize - 1)
7900 assert(NestedField);
7903 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7908 unsigned InitFieldOffset = 0;
7909 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7911 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7912 assert(FieldRecord);
7913 NestedField = FieldRecord->
getField(FD);
7914 InitFieldOffset += NestedField->Offset;
7915 assert(NestedField);
7916 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7918 if (!this->emitFinishInitPop(InitExpr))
7922 InitStack.pop_back_n(ChainSize - 1);
7925 assert(
Init->isDelegatingInitializer());
7926 if (!this->emitThis(InitExpr))
7928 if (!this->visitInitializerPop(
Init->getInit()))
7932 if (!
Scope.destroyLocals())
7936 if (FieldInits !=
R->getNumFields()) {
7937 assert(FieldInits < R->getNumFields());
7939 if (!this->emitStartThisLifetime(Ctor))
7946 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7947 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7954 if (!visitStmt(Body))
7961template <
class Emitter>
7964 const Record *
R = this->getRecord(RD);
7968 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7971 LabelTy EpilogLabel = this->getLabel();
7974 if (!this->visitStmt(
Dtor->getBody()))
7977 this->fallthrough(EpilogLabel);
7978 this->emitLabel(EpilogLabel);
7981 if (!this->emitThis(
Dtor))
7984 if (!this->emitCheckDestruction(
Dtor))
7988 if (!
R->isUnion()) {
7992 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7996 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7998 if (!this->emitDestructionPop(D,
SourceInfo{}))
8003 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
8004 if (
Base.R->hasTrivialDtor())
8008 if (!this->emitRecordDestructionPop(
Base.R, {}))
8012 if (
R->getNumVirtualBases() > 0) {
8013 LabelTy EndLabel = this->getLabel();
8015 if (!this->emitIsBaseClass({}))
8017 if (!this->jumpTrue(EndLabel, {}))
8020 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
8021 if (
Base.R->hasTrivialDtor())
8026 if (!this->emitRecordDestructionPop(
Base.R, {}))
8030 this->fallthrough(EndLabel);
8031 this->emitLabel(EndLabel);
8034 if (!this->emitMarkDestroyed(
Dtor))
8037 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
8040template <
class Emitter>
8041bool Compiler<Emitter>::compileUnionAssignmentOperator(
8043 if (!this->emitThis(MD))
8046 if (!this->emitGetParam(
PT_Ptr, 0, MD))
8049 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
8052template <
class Emitter>
8062 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
8063 return this->compileConstructor(Ctor);
8064 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
8065 return this->compileDestructor(
Dtor);
8068 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
8073 return this->compileUnionAssignmentOperator(MD);
8076 return this->emitLambdaStaticInvokerBody(MD);
8080 if (
const auto *Body = F->
getBody())
8094 return FD->getBitWidthValue();
8097template <
class Emitter>
8113 if (!
Ctx.getLangOpts().CPlusPlus14)
8114 return this->emitInvalid(E);
8116 return this->emitError(E);
8118 if (!this->
visit(SubExpr))
8122 if (!this->emitIncPtr(E))
8129 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
8130 : this->emitIncf(getFPOptions(E), E);
8142 if (!
Ctx.getLangOpts().CPlusPlus14)
8143 return this->emitInvalid(E);
8145 return this->emitError(E);
8147 if (!this->
visit(SubExpr))
8151 if (!this->emitDecPtr(E))
8158 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
8159 : this->emitDecf(getFPOptions(E), E);
8172 if (!
Ctx.getLangOpts().CPlusPlus14)
8173 return this->emitInvalid(E);
8175 return this->emitError(E);
8177 if (!this->
visit(SubExpr))
8181 if (!this->emitLoadPtr(E))
8183 if (!this->emitConstUint8(1, E))
8185 if (!this->emitAddOffsetUint8(E))
8187 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8193 return this->emitIncfPop(getFPOptions(E), E);
8203 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8204 if (!this->emitLoadFloat(E))
8206 APFloat F(TargetSemantics, 1);
8207 if (!this->emitFloat(F, E))
8210 if (!this->emitAddf(getFPOptions(E), E))
8212 if (!this->emitStoreFloat(E))
8224 return E->
isGLValue() || this->emitLoadPop(*T, E);
8227 if (!
Ctx.getLangOpts().CPlusPlus14)
8228 return this->emitInvalid(E);
8230 return this->emitError(E);
8232 if (!this->
visit(SubExpr))
8236 if (!this->emitLoadPtr(E))
8238 if (!this->emitConstUint8(1, E))
8240 if (!this->emitSubOffsetUint8(E))
8242 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8248 return this->emitDecfPop(getFPOptions(E), E);
8258 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8259 if (!this->emitLoadFloat(E))
8261 APFloat F(TargetSemantics, 1);
8262 if (!this->emitFloat(F, E))
8265 if (!this->emitSubf(getFPOptions(E), E))
8267 if (!this->emitStoreFloat(E))
8279 return E->
isGLValue() || this->emitLoadPop(*T, E);
8283 return this->emitError(E);
8286 return this->
discard(SubExpr);
8291 if (!this->emitInv(E))
8295 return this->emitCast(
PT_Bool, ET, E);
8299 return this->emitError(E);
8301 if (!this->
visit(SubExpr))
8303 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
8306 return this->emitError(E);
8308 if (!this->
visit(SubExpr))
8324 if (!
Ctx.getLangOpts().CPlusPlus) {
8327 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8328 Deref && Deref->getOpcode() == UO_Deref) {
8330 return this->
discard(Deref->getSubExpr());
8331 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8336 return this->
discard(SubExpr);
8337 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8340 return this->
discard(SubExpr);
8342 if (!this->
visit(SubExpr))
8349 return this->emitNarrowPtr(E);
8354 return this->emitError(E);
8356 if (!this->
visit(SubExpr))
8358 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
8370 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
8375 assert(
false &&
"Unhandled opcode");
8381template <
class Emitter>
8387 return this->
discard(SubExpr);
8390 auto prepareResult = [=]() ->
bool {
8395 return this->emitGetPtrLocal(*LocalIndex, E);
8402 unsigned SubExprOffset = ~0u;
8403 auto createTemp = [=, &SubExprOffset]() ->
bool {
8406 if (!this->
visit(SubExpr))
8408 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8412 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8413 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8415 return this->emitArrayElemPop(ElemT, Index, E);
8420 if (!prepareResult())
8424 for (
unsigned I = 0; I != 2; ++I) {
8425 if (!getElem(SubExprOffset, I))
8427 if (!this->emitNeg(ElemT, E))
8429 if (!this->emitInitElem(ElemT, I, E))
8440 if (!this->
visit(SubExpr))
8442 if (!this->emitComplexBoolCast(SubExpr))
8444 if (!this->emitInv(E))
8447 return this->emitCast(
PT_Bool, ET, E);
8451 return this->emitComplexReal(SubExpr);
8454 if (!this->
visit(SubExpr))
8458 if (!this->emitConstUint8(1, E))
8460 return this->emitArrayElemPtrPopUint8(E);
8471 if (!this->emitArrayElem(ElemT, 1, E))
8473 if (!this->emitNeg(ElemT, E))
8475 if (!this->emitInitElem(ElemT, 1, E))
8483 return this->emitInvalid(E);
8489template <
class Emitter>
8495 return this->
discard(SubExpr);
8498 if (UnaryOp == UO_Extension)
8501 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8502 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8503 return this->emitInvalid(E);
8506 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8513 if (!this->emitGetPtrLocal(*LocalIndex, E))
8518 unsigned SubExprOffset =
8520 if (!this->
visit(SubExpr))
8522 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8527 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8528 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8530 return this->emitArrayElemPop(ElemT, Index, E);
8535 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8536 if (!getElem(SubExprOffset, I))
8538 if (!this->emitNeg(ElemT, E))
8540 if (!this->emitInitElem(ElemT, I, E))
8555 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8556 if (!getElem(SubExprOffset, I))
8559 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8561 if (!this->emitInv(E))
8563 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8565 if (!this->emitNeg(ElemT, E))
8567 if (ElemT != ResultVecElemT &&
8568 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8570 if (!this->emitInitElem(ResultVecElemT, I, E))
8576 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8577 if (!getElem(SubExprOffset, I))
8580 if (!this->emitInv(E))
8583 if (!this->emitComp(ElemT, E))
8586 if (!this->emitInitElem(ElemT, I, E))
8591 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8596template <
class Emitter>
8598 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8601 return this->emitConst(ECD->getInitVal(), E);
8603 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8607 return F && this->emitGetFnPtr(F, E);
8609 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8610 TPOD = TPOD->getFirstDecl();
8614 return this->emitGetPtrGlobal(*GlobalIndex, E);
8620 return this->emitInitGlobal(*T, *Index, E);
8623 if (!this->emitGetPtrGlobal(*Index, E))
8627 return this->emitFinishInit(E);
8639 auto maybePopPtr = [&]() ->
bool {
8641 return this->emitPopPtr(E);
8648 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8652 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8657 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8658 if (IsReference || !It->second.IsPtr)
8659 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8661 return this->emitGetPtrParam(It->second.Index, E);
8664 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8671 const unsigned Offset = It->second.Offset;
8674 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8676 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8679 if (
auto GlobalIndex =
P.getGlobal(D)) {
8681 if (!
Ctx.getLangOpts().CPlusPlus11)
8682 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8683 if (!
Ctx.getLangOpts().CPlusPlus23)
8684 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8686 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8689 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8693 auto revisit = [&](
const VarDecl *VD,
8694 bool IsConstexprUnknown =
true) ->
bool {
8696 IsConstexprUnknown);
8697 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8703 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8704 if (!this->emitPopCC(E))
8708 if (VarState.notCreated())
8716 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8718 if (
auto It = this->LambdaCaptures.find(D);
8719 It != this->LambdaCaptures.end()) {
8720 auto [Offset, IsPtr] = It->second;
8723 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8724 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8728 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8729 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8730 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8734 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8735 return this->
delegate(BD->getBinding());
8741 return this->emitDummyPtr(D, E);
8746 const auto *VD = dyn_cast<VarDecl>(D);
8748 return this->emitError(E);
8751 if (!
Ctx.getLangOpts().CPlusPlus) {
8755 return revisit(VD,
false);
8759 return this->emitDummyPtr(D, E);
8763 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8764 if (T.isConstant(
Ctx.getASTContext()))
8766 return T->isReferenceType();
8770 typeShouldBeVisited(DeclType)) {
8772 Init && !
Init->isValueDependent()) {
8777 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8790 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8795 return revisit(VD, IsConstexprUnknown);
8796 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8797 return revisit(VD,
true);
8806 return this->emitDummyPtr(
8810template <
class Emitter>
8816template <
class Emitter>
8826 if (!
C->destroyLocals())
8832template <
class Emitter>
8833unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8836 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8838 return Ty->castAsCXXRecordDecl();
8840 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8841 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8843 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8847template <
class Emitter>
8854 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8859 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8860 getFPOptions(E), E);
8862 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8863 getFPOptions(E), E);
8867 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8872 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8874 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8878 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8882 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8883 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8890template <
class Emitter>
8893 assert(FromT != ToT);
8896 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8898 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8900 return this->emitCast(FromT, ToT, E);
8904template <
class Emitter>
8905bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8909 return this->
discard(SubExpr);
8911 if (!this->visit(SubExpr))
8914 if (!this->emitConstUint8(0, SubExpr))
8916 return this->emitArrayElemPtrPopUint8(SubExpr);
8920 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8924template <
class Emitter>
8925bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8926 assert(!DiscardResult);
8930 if (!this->emitArrayElem(ElemT, 0, E))
8933 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8936 if (!this->emitCast(ElemT,
PT_Bool, E))
8941 LabelTy LabelTrue = this->getLabel();
8942 if (!this->jumpTrue(LabelTrue, E))
8945 if (!this->emitArrayElemPop(ElemT, 1, E))
8948 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8951 if (!this->emitCast(ElemT,
PT_Bool, E))
8955 LabelTy EndLabel = this->getLabel();
8956 this->jump(EndLabel, E);
8958 this->emitLabel(LabelTrue);
8959 if (!this->emitPopPtr(E))
8961 if (!this->emitConstBool(
true, E))
8964 this->fallthrough(EndLabel);
8965 this->emitLabel(EndLabel);
8970template <
class Emitter>
8971bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8982 LHSIsComplex =
true;
8983 ElemT = classifyComplexElementType(LHS->
getType());
8984 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8985 if (!this->visit(LHS))
8987 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8990 LHSIsComplex =
false;
8992 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8993 if (!this->visit(LHS))
8995 if (!this->emitSetLocal(LHST, LHSOffset, E))
9002 RHSIsComplex =
true;
9003 ElemT = classifyComplexElementType(RHS->
getType());
9004 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
9005 if (!this->visit(RHS))
9007 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
9010 RHSIsComplex =
false;
9012 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
9013 if (!this->visit(RHS))
9015 if (!this->emitSetLocal(RHST, RHSOffset, E))
9019 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
9020 bool IsComplex) ->
bool {
9022 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
9024 return this->emitArrayElemPop(ElemT, Index, E);
9026 return this->emitGetLocal(ElemT, LocalOffset, E);
9029 for (
unsigned I = 0; I != 2; ++I) {
9031 if (!getElem(LHSOffset, I, LHSIsComplex))
9033 if (!getElem(RHSOffset, I, RHSIsComplex))
9036 if (!this->emitEQ(ElemT, E))
9039 if (!this->emitCastBoolUint8(E))
9044 if (!this->emitAddUint8(E))
9046 if (!this->emitConstUint8(2, E))
9050 if (!this->emitEQUint8(E))
9053 if (!this->emitNEUint8(E))
9060 return this->emitCast(
PT_Bool, ResT, E);
9067template <
class Emitter>
9068bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
9071 assert(!
R->hasTrivialDtor());
9074 const Function *DtorFunc = getFunction(
Dtor);
9077 assert(DtorFunc->hasThisPointer());
9078 assert(DtorFunc->getNumParams() == 1);
9079 return this->emitCall(DtorFunc, 0, Loc);
9084template <
class Emitter>
9085bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
9097 return this->emitPopPtr(Loc);
9099 for (ssize_t I = N - 1; I >= 1; --I) {
9100 if (!this->emitConstUint64(I, Loc))
9102 if (!this->emitArrayElemPtrUint64(Loc))
9104 if (!this->emitDestructionPop(ElemDesc, Loc))
9108 if (!this->emitConstUint64(0, Loc))
9110 if (!this->emitArrayElemPtrPopUint64(Loc))
9112 return this->emitDestructionPop(ElemDesc, Loc);
9117 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
9122template <
class Emitter>
9123bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
9124 assert(!DiscardResult &&
"Should've been checked before");
9125 return this->emitGetOpaquePtr(D, CU, E);
9128template <
class Emitter>
9131 return this->emitConstFloat(
Floating(F), Info);
9133 APInt I = F.bitcastToAPInt();
9134 return this->emitConstFloat(
9136 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
9147template <
class Emitter>
9148bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
9161 if (!this->emitGetPtrLocal(*LocalIndex, E))
9171 if (!this->visit(SubExpr))
9173 }
else if (
OptPrimType FromT = classify(SubExpr)) {
9174 unsigned TempOffset =
9175 allocateLocalPrimitive(SubExpr, *FromT,
true);
9176 if (!this->visit(SubExpr))
9178 if (!this->emitSetLocal(*FromT, TempOffset, E))
9180 if (!this->emitGetPtrLocal(TempOffset, E))
9187 if (!this->emitBitCast(E))
9189 return DiscardResult ? this->emitPopPtr(E) :
true;
9193 const llvm::fltSemantics *TargetSemantics =
nullptr;
9195 TargetSemantics = &Ctx.getFloatSemantics(ToType);
9201 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
9203 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
9204 ResultBitWidth, TargetSemantics,
9209 return this->emitPop(*ToT, E);
9218template <
class Emitter>
9219bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
9224 unsigned NumElems = 0;
9227 NumElems = VT->getNumElements();
9228 ElemType = VT->getElementType();
9230 NumElems = MT->getNumElementsFlattened();
9231 ElemType = MT->getElementType();
9234 PrimType ElemT = classifyPrim(ElemType);
9235 for (
unsigned I = 0; I != NumElems; ++I) {
9236 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9238 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
9240 if (!this->emitInitElem(ElemT, I, E))
9250 QualType ArrElemType = CAT->getElementType();
9251 unsigned ArrSize = CAT->getZExtSize();
9254 for (
unsigned I = 0; I != ArrSize; ++I) {
9255 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9257 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9259 if (!this->emitInitElem(*ElemT, I, E))
9263 for (
unsigned I = 0; I != ArrSize; ++I) {
9264 if (!this->emitConstUint32(I, E))
9266 if (!this->emitArrayElemPtrUint32(E))
9268 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9270 if (!this->emitFinishInitPop(E))
9280 const Record *
R = getRecord(DestType);
9284 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9286 const Record::Base *B =
R->getBase(BS.getType());
9288 if (!this->emitGetPtrBase(B->Offset, E))
9290 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9292 if (!this->emitFinishInitPop(E))
9297 for (
const Record::Field &F :
R->fields()) {
9298 if (F.isUnnamedBitField())
9301 QualType FieldType = F.Decl->getType();
9303 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9305 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9307 if (F.isBitField()) {
9308 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9311 if (!this->emitInitField(*FieldT, F.Offset, E))
9315 if (!this->emitGetPtrField(F.Offset, E))
9317 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9319 if (!this->emitPopPtr(E))
9332template <
class Emitter>
9333unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9336 return VT->getNumElements();
9338 return MT->getNumElementsFlattened();
9342 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9346 const Record *
R = getRecord(Ty);
9350 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9352 Count += countHLSLFlatElements(BS.getType());
9354 for (
const Record::Field &F :
R->fields()) {
9355 if (F.isUnnamedBitField())
9357 Count += countHLSLFlatElements(F.Decl->getType());
9362 if (canClassify(Ty))
9371template <
class Emitter>
9372bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9373 QualType SrcType,
unsigned SrcOffset,
9378 auto saveToLocal = [&](
PrimType T) ->
bool {
9379 unsigned Offset = allocateLocalPrimitive(E, T,
true);
9380 if (!this->emitSetLocal(T, Offset, E))
9382 Elements.push_back({Offset, T});
9388 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9389 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9390 return std::nullopt;
9395 unsigned NumElems = 0;
9398 NumElems = VT->getNumElements();
9399 ElemType = VT->getElementType();
9401 NumElems = MT->getNumElementsFlattened();
9402 ElemType = MT->getElementType();
9405 PrimType ElemT = classifyPrim(ElemType);
9406 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9407 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9409 if (!this->emitArrayElemPop(ElemT, I, E))
9411 if (!saveToLocal(ElemT))
9421 QualType ArrElemType = CAT->getElementType();
9422 unsigned ArrSize = CAT->getZExtSize();
9425 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9426 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9428 if (!this->emitArrayElemPop(*ElemT, I, E))
9430 if (!saveToLocal(*ElemT))
9434 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9435 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9437 if (!this->emitConstUint32(I, E))
9439 if (!this->emitArrayElemPtrPopUint32(E))
9444 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9455 const Record *
R = getRecord(SrcType);
9459 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9461 if (Elements.size() >= MaxElements)
9463 const Record::Base *B =
R->getBase(BS.getType());
9465 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9467 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9472 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9478 for (
const Record::Field &F :
R->fields()) {
9479 if (Elements.size() >= MaxElements)
9481 if (F.isUnnamedBitField())
9484 QualType FieldType = F.Decl->getType();
9485 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9487 if (!this->emitGetPtrFieldPop(F.Offset, E))
9491 if (!this->emitLoadPop(*FieldT, E))
9493 if (!saveToLocal(*FieldT))
9497 if (!FieldPtrOffset)
9499 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9515template <
class Emitter>
9516bool Compiler<Emitter>::emitHLSLConstructAggregate(
9522 const auto &Src = Elements[ElemIdx++];
9523 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9525 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9529 unsigned NumElems = 0;
9532 NumElems = VT->getNumElements();
9533 ElemType = VT->getElementType();
9535 NumElems = MT->getNumElementsFlattened();
9536 ElemType = MT->getElementType();
9539 PrimType DestElemT = classifyPrim(ElemType);
9540 for (
unsigned I = 0; I != NumElems; ++I) {
9541 if (!loadAndCast(DestElemT, ElemType))
9543 if (!this->emitInitElem(DestElemT, I, E))
9553 QualType ArrElemType = CAT->getElementType();
9554 unsigned ArrSize = CAT->getZExtSize();
9557 for (
unsigned I = 0; I != ArrSize; ++I) {
9558 if (!loadAndCast(*ElemT, ArrElemType))
9560 if (!this->emitInitElem(*ElemT, I, E))
9564 for (
unsigned I = 0; I != ArrSize; ++I) {
9565 if (!this->emitConstUint32(I, E))
9567 if (!this->emitArrayElemPtrUint32(E))
9569 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9571 if (!this->emitFinishInitPop(E))
9581 const Record *
R = getRecord(DestType);
9585 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9587 const Record::Base *B =
R->getBase(BS.getType());
9589 if (!this->emitGetPtrBase(B->Offset, E))
9591 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9593 if (!this->emitFinishInitPop(E))
9598 for (
const Record::Field &F :
R->fields()) {
9599 if (F.isUnnamedBitField())
9602 QualType FieldType = F.Decl->getType();
9604 if (!loadAndCast(*FieldT, FieldType))
9606 if (F.isBitField()) {
9607 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9610 if (!this->emitInitField(*FieldT, F.Offset, E))
9614 if (!this->emitGetPtrField(F.Offset, E))
9616 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9618 if (!this->emitPopPtr(E))
static bool visitAPValue(const APValue &Value, llvm::function_ref< bool(const APValue &)> Visitor)
static bool emit(llvm::SmallVectorImpl< std::byte > &Code, const T &Val)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static uint32_t getBitWidth(const Expr *E)
static CharUnits alignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
#define EMIT_ARITH_OP(OP)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static bool isTrivialMemoryOperation(const CXXMethodDecl *MD)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
const Expr * ignorePointerCastsAndParens(const Expr *E)
A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. This ignores some c...
bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD)
Determine whether a type would actually be read by an lvalue-to-rvalue conversion.
unsigned ConvertBuiltinIDToX86BuiltinID(const ASTContext &Ctx, unsigned BuiltinOp)
Convert a builtin ID to the canonical x86 builtin ID the constant evaluators dispatch on in their x86...
Result
Implement __builtin_bit_cast and related operations.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
APSInt & getComplexIntImag()
unsigned getStructNumFields() const
bool isComplexInt() const
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() const
bool hasLValuePath() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
CharUnits & getLValueOffset()
bool isComplexFloat() const
APValue & getVectorElt(unsigned I)
APValue & getArrayFiller()
unsigned getVectorLength() const
bool isIndeterminate() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APSInt & getComplexIntReal()
APFloat & getComplexFloatImag()
APFloat & getComplexFloatReal()
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Represents a C++26 reflect expression [expr.reflect].
ReflectionKind getKind() const
const void * getOpaqueValue() const
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
A rewritten comparison expression that was originally written using operator syntax.
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Represents the this expression in C++.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
CXXTryStmt - A C++ try block, including all handlers.
CompoundStmt * getTryBlock()
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
const FieldDecl * getTargetUnionField() const
This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits One()
Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
An expression that occurs in a constant context and the result of evaluating the expression.
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
An instance of this object exists for each enum constant that is defined.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompatibleWith(ClangABI Version) const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Symbolic representation of typeid(T) for some type T.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
bool isStoredAsComparisonResult() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
ArrayIndexScope(Compiler< Emitter > *Ctx, uint64_t Index)
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
std::optional< Scope::Local > allocateLocalUnscoped(DeclOrExpr Decl, QualType Ty=QualType())
Like allocateLocal(), but doesn't add the local to a scope.
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
const VarDecl * InitializingDecl
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
bool VisitCXXReflectExpr(const CXXReflectExpr *E)
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool registerRedecl(const VarDecl *VD, const APValue &V)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
OptLabelTy DtorEpilogLabel
In a destructor body: where a return jumps to, so the subobjects are still destroyed.
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const VarDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * findVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
RegisterLocalScope(Compiler< Emitter > *Ctx, Scope::Local Local, ScopeKind VarScope=ScopeKind::Block)
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
VariableScope * getParent() const
uint16_t getPointerAuthTypeDiscriminator(CodeGenModule &CGM, QualType FunctionType)
Return a type discriminator for the given function type.
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool This(InterpState &S, CodePtr OpPC)
constexpr bool isIntegerOrBoolType(PrimType T)
static void discard(InterpStack &Stk, PrimType T)
static bool isSideEffectFree(const Expr *E)
Check if E has side-effects.
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
static bool Activate(InterpState &S)
static bool exceedsArraySizeLimit(const LangOptions &LangOpts, uint64_t NumElems)
Whether the CheckArraySize op rejects an array with NumElems elements.
bool Init(InterpState &S, CodePtr OpPC)
bool DefaultInit(InterpState &S, CodePtr OpPC, const CXXConstructorDecl *Ctor)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
U cast(CodeGen::Address addr)
int const char * function
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...
EvalResult is a struct with detailed info about an evaluated expression.
const ValueDecl * asValueDecl() const
const Expr * asExpr() const
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink Base(unsigned Offset)
static InitLink Decl(const ValueDecl *D)
static InitLink Temp(unsigned Offset)
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()