20#include "llvm/Support/SaveAndRestore.h"
31 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
32 CE && CE->hasAPValueResult() &&
34 return CE->getResultAsAPSInt().getBoolValue();
66 llvm_unreachable(
"Shouldn't be called");
132 this->
Ctx->emitDestroy(*
Idx, E);
138 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
139 this->
Ctx->Descriptors.emplace_back();
140 this->
Ctx->emitInitScope(*
Idx, {});
144 this->
Ctx->Descriptors[*
Idx].emplace_back(Local);
154 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
155 this->
Ctx->Descriptors.emplace_back();
156 this->
Ctx->emitInitScope(*
Idx, {});
167 if (Local.Desc->hasTrivialDtor())
170 if (!Local.EnabledByDefault) {
171 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
172 if (!this->
Ctx->emitGetLocalEnabled(Local.Offset, E))
174 if (!this->
Ctx->jumpFalse(EndLabel, E))
177 if (!this->
Ctx->emitGetPtrLocal(Local.Offset, E))
180 if (!this->
Ctx->emitDestructionPop(Local.Desc, Local.Desc->getLoc()))
183 this->
Ctx->fallthrough(EndLabel);
184 this->
Ctx->emitLabel(EndLabel);
186 if (!this->
Ctx->emitGetPtrLocal(Local.Offset, E))
188 if (!this->
Ctx->emitDestructionPop(Local.Desc, Local.Desc->getLoc()))
207 if (
const auto *OVE =
208 llvm::dyn_cast_if_present<OpaqueValueExpr>(Local.Desc->asExpr())) {
209 this->
Ctx->OpaqueExprs.erase(OVE);
220 OldArrayIndex = Ctx->ArrayIndex;
221 Ctx->ArrayIndex = Index;
228 std::optional<uint64_t> OldArrayIndex;
236 if (!Ctx->SourceLocDefaultExpr) {
238 Ctx->SourceLocDefaultExpr = DefaultExpr;
244 Ctx->SourceLocDefaultExpr =
nullptr;
249 bool Enabled =
false;
255 Ctx->InitStack.push_back(std::move(
Link));
267 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
268 Ctx->InitStackActive = Active;
274 this->Ctx->InitStackActive = OldValue;
276 Ctx->InitStack.pop_back();
290 OldInitializingDecl(
Ctx->InitializingDecl) {
291 Ctx->InitializingDecl = VD;
296 this->
Ctx->InitializingDecl = OldInitializingDecl;
297 this->
Ctx->InitStack.pop_back();
302 const VarDecl *OldInitializingDecl;
310 bool NewInitializing,
bool NewToLValue)
311 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
312 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
313 Ctx->DiscardResult = NewDiscardResult;
314 Ctx->Initializing = NewInitializing;
315 Ctx->ToLValue = NewToLValue;
319 Ctx->DiscardResult = OldDiscardResult;
320 Ctx->Initializing = OldInitializing;
321 Ctx->ToLValue = OldToLValue;
328 bool OldDiscardResult;
329 bool OldInitializing;
333template <
class Emitter>
337 return Ctx->emitThis(E);
340 return Ctx->emitGetPtrFieldPop(
Offset, E);
342 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
344 return Ctx->emitGetPtrLocal(
Offset, E);
348 if (!Ctx->emitConstUint32(
Offset, E))
350 return Ctx->emitArrayElemPtrPopUint32(E);
352 return Ctx->emitRVOPtr(E);
356 llvm_unreachable(
"Unhandled InitLink kind");
372 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
373 assert(LI.Name != Name);
376 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
397 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
399 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
400 assert(LI.Name != Name);
403 this->Ctx->CaseLabels = std::move(CaseLabels);
404 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
406 DefaultLabel, Ctx->VarScope);
410 this->Ctx->CaseLabels = std::move(OldCaseLabels);
411 this->Ctx->LabelInfoStack.pop_back();
416 CaseMap OldCaseLabels;
427 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
430 Ctx->LocOverride = NewValue;
435 Ctx->LocOverride = OldFlag;
440 std::optional<SourceInfo> OldFlag;
447template <
class Emitter>
455 case CK_LValueToRValue: {
466 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
472 if (
auto GlobalIndex =
P.getGlobal(D))
473 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
474 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
475 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
476 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
477 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
478 return this->emitGetParam(*SubExprT, It->second.Index, E);
490 if (!this->emitGetPtrLocal(*LocalIndex, E))
494 if (!this->
visit(SubExpr))
498 return this->emitLoadPop(*SubExprT, E);
503 return this->emitMemcpy(E);
506 case CK_DerivedToBaseMemberPointer: {
517 ->getMostRecentCXXRecordDecl();
519 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
520 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
522 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
530 case CK_BaseToDerivedMemberPointer: {
541 ->getMostRecentCXXRecordDecl();
545 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
547 PathI != PathE; ++PathI) {
548 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
549 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
551 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
558 assert(ToDecl != CurDecl);
559 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
561 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
567 case CK_UncheckedDerivedToBase:
568 case CK_DerivedToBase: {
573 if (
const auto *PT = dyn_cast<PointerType>(Ty))
574 return PT->getPointeeType()->getAsCXXRecordDecl();
575 return Ty->getAsCXXRecordDecl();
582 if (B->isVirtual()) {
583 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
585 CurType = B->getType();
587 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
588 if (!this->emitGetPtrBasePop(
591 CurType = B->getType();
598 case CK_BaseToDerived: {
601 unsigned DerivedOffset =
607 return this->emitGetPtrDerivedPop(DerivedOffset,
612 case CK_FloatingCast: {
615 return this->emitVectorConversion(E->
getSubExpr(), E);
619 if (!this->
visit(SubExpr))
621 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
625 case CK_IntegralToFloating: {
627 return this->emitVectorConversion(E->
getSubExpr(), E);
630 if (!this->
visit(SubExpr))
632 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
633 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
634 TargetSemantics, getFPOptions(E), E);
637 case CK_FloatingToBoolean: {
639 return this->emitVectorConversion(E->
getSubExpr(), E);
643 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
644 return this->emitConstBool(FL->getValue().isNonZero(), E);
645 if (!this->
visit(SubExpr))
647 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
650 case CK_FloatingToIntegral: {
652 return this->emitVectorConversion(E->
getSubExpr(), E);
655 if (!this->
visit(SubExpr))
659 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
662 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
665 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
668 case CK_NullToPointer:
669 case CK_NullToMemberPointer: {
672 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
677 case CK_PointerToIntegral: {
678 if (!this->
visit(SubExpr))
684 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
690 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
692 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
693 return this->emitCastPointerIntegral(
T, E);
696 case CK_ArrayToPointerDecay: {
697 if (!this->
visit(SubExpr))
699 return this->emitArrayDecay(E);
702 case CK_IntegralToPointer: {
704 assert(IntType->isIntegralOrEnumerationType());
705 if (!this->
visit(SubExpr))
719 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
722 case CK_AtomicToNonAtomic:
723 case CK_ConstructorConversion:
724 case CK_FunctionToPointerDecay:
725 case CK_NonAtomicToAtomic:
727 case CK_UserDefinedConversion:
728 case CK_AddressSpaceConversion:
729 case CK_CPointerToObjCPointerCast:
746 return this->emitBuiltinBitCast(E);
761 if (!this->
visit(SubExpr))
769 return this->emitFnPtrCast(E);
776 if (!this->
visit(SubExpr))
778 return this->emitDecayPtr(*FromT, *ToT, E);
780 case CK_IntegralToBoolean:
781 case CK_FixedPointToBoolean: {
783 return this->emitVectorConversion(E->
getSubExpr(), E);
789 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
790 return this->emitConst(IL->getValue(), E);
791 if (!this->
visit(SubExpr))
796 case CK_IntegralCast:
798 return this->emitVectorConversion(E->
getSubExpr(), E);
800 case CK_BooleanToSignedIntegral: {
807 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
812 if (!this->emitConst(IL->getValue(), SubExpr))
815 if (!this->
visit(SubExpr))
823 if (!ED->isFixed()) {
824 if (!this->emitCheckEnumValue(*FromT, ED, E))
830 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
833 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
838 if (!this->emitCast(*FromT, *ToT, E))
841 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
842 return this->emitNeg(*ToT, E);
846 case CK_PointerToBoolean:
847 case CK_MemberPointerToBoolean: {
850 if (!this->
visit(SubExpr))
852 return this->emitIsNonNull(PtrT, E);
855 case CK_IntegralComplexToBoolean:
856 case CK_FloatingComplexToBoolean: {
857 if (!this->
visit(SubExpr))
859 return this->emitComplexBoolCast(SubExpr);
862 case CK_IntegralComplexToReal:
863 case CK_FloatingComplexToReal:
864 return this->emitComplexReal(SubExpr);
866 case CK_IntegralRealToComplex:
867 case CK_FloatingRealToComplex: {
874 if (!this->emitGetPtrLocal(*LocalIndex, E))
883 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
885 return this->emitInitElem(
T, 1, SubExpr);
888 case CK_IntegralComplexCast:
889 case CK_FloatingComplexCast:
890 case CK_IntegralComplexToFloatingComplex:
891 case CK_FloatingComplexToIntegralComplex: {
898 if (!this->emitGetPtrLocal(*LocalIndex, E))
905 unsigned SubExprOffset =
907 if (!this->
visit(SubExpr))
909 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
917 for (
unsigned I = 0; I != 2; ++I) {
918 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
920 if (!this->emitArrayElemPop(SourceElemT, I, E))
924 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
928 if (!this->emitInitElem(DestElemT, I, E))
934 case CK_VectorSplat: {
945 if (!this->emitGetPtrLocal(*LocalIndex, E))
951 unsigned ElemOffset =
955 if (!this->
visit(SubExpr))
960 if (!this->emitSetLocal(ElemT, ElemOffset, E))
963 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
964 if (!this->emitGetLocal(ElemT, ElemOffset, E))
966 if (!this->emitInitElem(ElemT, I, E))
973 case CK_HLSLVectorTruncation: {
978 if (!this->
visit(SubExpr))
980 return this->emitArrayElemPop(*ResultT, 0, E);
989 if (!this->emitGetPtrLocal(*LocalIndex, E))
994 if (!this->
visit(SubExpr))
996 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1000 case CK_IntegralToFixedPoint: {
1001 if (!this->
visit(SubExpr))
1005 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1010 return this->emitPopFixedPoint(E);
1013 case CK_FloatingToFixedPoint: {
1014 if (!this->
visit(SubExpr))
1018 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1019 if (!this->emitCastFloatingFixedPoint(Sem, E))
1022 return this->emitPopFixedPoint(E);
1025 case CK_FixedPointToFloating: {
1026 if (!this->
visit(SubExpr))
1028 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1029 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1032 return this->emitPopFloat(E);
1035 case CK_FixedPointToIntegral: {
1036 if (!this->
visit(SubExpr))
1039 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1042 return this->emitPop(IntegralT, E);
1045 case CK_FixedPointCast: {
1046 if (!this->
visit(SubExpr))
1049 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1050 if (!this->emitCastFixedPoint(Sem, E))
1053 return this->emitPopFixedPoint(E);
1061 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1063 case CK_LValueBitCast:
1068 case CK_HLSLArrayRValue: {
1075 if (!this->emitGetPtrLocal(*LocalIndex, E))
1078 if (!this->
visit(SubExpr))
1080 return this->emitMemcpy(E);
1083 case CK_HLSLMatrixTruncation: {
1088 if (!this->
visit(SubExpr))
1090 return this->emitArrayElemPop(*ResultT, 0, E);
1099 if (!this->emitGetPtrLocal(*LocalIndex, E))
1104 if (!this->
visit(SubExpr))
1106 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1110 case CK_HLSLAggregateSplatCast: {
1120 if (!this->emitGetPtrLocal(*LocalIndex, E))
1127 unsigned SrcOffset =
1130 if (!this->
visit(SubExpr))
1132 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1136 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1139 case CK_HLSLElementwiseCast: {
1150 unsigned SrcPtrOffset =
1152 if (!this->
visit(SubExpr))
1154 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1158 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1160 if (Elements.empty())
1163 const HLSLFlatElement &Src = Elements[0];
1164 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1166 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1173 if (!this->emitGetPtrLocal(*LocalIndex, E))
1177 unsigned SrcOffset =
1179 if (!this->
visit(SubExpr))
1181 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1185 unsigned ElemCount = countHLSLFlatElements(DestType);
1188 Elements.reserve(ElemCount);
1189 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1194 assert(Elements.size() == ElemCount &&
1195 "Source type has fewer scalar elements than the destination type");
1197 return emitHLSLConstructAggregate(DestType, Elements, E);
1204 const Record::Field *RF = R->getField(UnionField);
1205 QualType FieldType = RF->Decl->getType();
1208 if (!this->
visit(SubExpr))
1210 if (RF->isBitField())
1211 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1213 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1216 if (!this->emitGetPtrField(RF->Offset, E))
1218 if (!this->emitActivate(E))
1224 return this->emitInvalid(E);
1226 llvm_unreachable(
"Unhandled clang::CastKind enum");
1229template <
class Emitter>
1231 return this->emitBuiltinBitCast(E);
1234template <
class Emitter>
1239 return this->emitConst(
LE->getValue(),
LE);
1242template <
class Emitter>
1248 return this->emitFloat(F, E);
1251template <
class Emitter>
1261 if (!this->emitGetPtrLocal(*LocalIndex, E))
1268 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1270 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1275template <
class Emitter>
1283 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1288template <
class Emitter>
1293template <
class Emitter>
1320 return this->emitComplexComparison(LHS, RHS, E);
1328 if (!this->
visit(LHS))
1331 if (!this->
visit(RHS))
1334 if (!this->emitToMemberPtr(E))
1340 if (!this->emitCastMemberPtrPtr(E))
1357 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1363 if (!this->emitGetPtrLocal(*ResultIndex, E))
1370 return this->emitCMP3(*
LT, CmpInfo, E);
1373 if (!
LT || !RT || !
T)
1383 return this->visitAssignment(LHS, RHS, E);
1390 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1394 return this->emitPopBool(E);
1396 return this->emitCast(
PT_Bool, *
T, E);
1400 auto Discard = [
this,
T, E](
bool Result) {
1408 return MaybeCastToBool(this->emitEQ(*
LT, E));
1410 return MaybeCastToBool(this->emitNE(*
LT, E));
1412 return MaybeCastToBool(this->emitLT(*
LT, E));
1414 return MaybeCastToBool(this->emitLE(*
LT, E));
1416 return MaybeCastToBool(this->emitGT(*
LT, E));
1418 return MaybeCastToBool(this->emitGE(*
LT, E));
1421 return Discard(this->emitSubf(getFPOptions(E), E));
1422 return Discard(this->emitSub(*
T, E));
1425 return Discard(this->emitAddf(getFPOptions(E), E));
1426 return Discard(this->emitAdd(*
T, E));
1429 return Discard(this->emitMulf(getFPOptions(E), E));
1430 return Discard(this->emitMul(*
T, E));
1432 return Discard(this->emitRem(*
T, E));
1435 return Discard(this->emitDivf(getFPOptions(E), E));
1436 return Discard(this->emitDiv(*
T, E));
1438 return Discard(this->emitBitAnd(*
T, E));
1440 return Discard(this->emitBitOr(*
T, E));
1442 return Discard(this->emitShl(*
LT, *RT, E));
1444 return Discard(this->emitShr(*
LT, *RT, E));
1446 return Discard(this->emitBitXor(*
T, E));
1449 llvm_unreachable(
"Already handled earlier");
1454 llvm_unreachable(
"Unhandled binary op");
1459template <
class Emitter>
1465 if ((Op != BO_Add && Op != BO_Sub) ||
1476 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1477 if (!this->
visit(E))
1480 return this->emitDecayPtr(
T,
PT_Ptr, E);
1489 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1497 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1500 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1507 if (!visitAsPointer(RHS, *RT))
1509 if (!this->
visit(LHS))
1513 if (!visitAsPointer(LHS, *
LT))
1515 if (!this->
visit(RHS))
1526 if (!this->emitAddOffset(OffsetType, E))
1530 if (!this->emitSubOffset(OffsetType, E))
1547template <
class Emitter>
1557 LabelTy LabelTrue = this->getLabel();
1558 LabelTy LabelEnd = this->getLabel();
1562 if (!this->jumpTrue(LabelTrue, E))
1567 if (!this->jump(LabelEnd, E))
1570 this->emitLabel(LabelTrue);
1571 this->emitConstBool(
true, E);
1572 this->fallthrough(LabelEnd);
1573 this->emitLabel(LabelEnd);
1576 assert(Op == BO_LAnd);
1579 LabelTy LabelFalse = this->getLabel();
1580 LabelTy LabelEnd = this->getLabel();
1584 if (!this->jumpFalse(LabelFalse, E))
1589 if (!this->jump(LabelEnd, E))
1592 this->emitLabel(LabelFalse);
1593 this->emitConstBool(
false, E);
1594 this->fallthrough(LabelEnd);
1595 this->emitLabel(LabelEnd);
1599 return this->emitPopBool(E);
1604 return this->emitCast(
PT_Bool, *
T, E);
1608template <
class Emitter>
1615 if (!this->emitGetPtrLocal(*LocalIndex, E))
1624 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1625 unsigned ResultOffset = ~0u;
1631 if (!this->emitDupPtr(E))
1633 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1638 LHSType = AT->getValueType();
1641 RHSType = AT->getValueType();
1650 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1655 if (!this->
visit(LHS))
1657 if (!this->
visit(RHS))
1659 if (!this->emitMulc(ElemT, E))
1662 return this->emitPopPtr(E);
1666 if (Op == BO_Div && RHSIsComplex) {
1673 if (!LHSIsComplex) {
1678 LHSOffset = *LocalIndex;
1680 if (!this->emitGetPtrLocal(LHSOffset, E))
1683 if (!this->
visit(LHS))
1686 if (!this->emitInitElem(ElemT, 0, E))
1689 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1691 if (!this->emitInitElem(ElemT, 1, E))
1694 if (!this->
visit(LHS))
1698 if (!this->
visit(RHS))
1700 if (!this->emitDivc(ElemT, E))
1703 return this->emitPopPtr(E);
1710 if (!this->
visit(LHS))
1712 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1717 if (!this->
visit(LHS))
1719 if (!this->emitSetLocal(LHST, LHSOffset, E))
1727 if (!this->
visit(RHS))
1729 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1734 if (!this->
visit(RHS))
1736 if (!this->emitSetLocal(RHST, RHSOffset, E))
1743 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1744 unsigned ElemIndex,
unsigned Offset,
1745 const Expr *E) ->
bool {
1747 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1749 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1752 if (ElemIndex == 0 || !LoadZero)
1759 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1762 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1769 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1772 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1775 if (!this->emitAddf(getFPOptions(E), E))
1778 if (!this->emitAdd(ResultElemT, E))
1783 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1786 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1789 if (!this->emitSubf(getFPOptions(E), E))
1792 if (!this->emitSub(ResultElemT, E))
1797 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1800 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1804 if (!this->emitMulf(getFPOptions(E), E))
1807 if (!this->emitMul(ResultElemT, E))
1812 assert(!RHSIsComplex);
1813 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1816 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1820 if (!this->emitDivf(getFPOptions(E), E))
1823 if (!this->emitDiv(ResultElemT, E))
1834 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1837 if (!this->emitPop(ResultElemT, E))
1842 return this->emitPopPtr(E);
1848template <
class Emitter>
1853 "Comma op should be handled in VisitBinaryOperator");
1867 if (!this->emitGetPtrLocal(*LocalIndex, E))
1881 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1884 if (!this->
visit(LHS))
1886 if (!this->
visit(RHS))
1888 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1891 return this->emitPopPtr(E);
1896 unsigned LHSOffset =
1898 if (!this->
visit(LHS))
1900 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1904 unsigned RHSOffset =
1906 if (!this->
visit(RHS))
1908 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1920 if (NeedIntPromot) {
1922 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1927 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1928 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1930 if (!this->emitArrayElemPop(ElemT, Index, E))
1933 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1935 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1937 }
else if (NeedIntPromot) {
1938 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1944#define EMIT_ARITH_OP(OP) \
1946 if (ElemT == PT_Float) { \
1947 if (!this->emit##OP##f(getFPOptions(E), E)) \
1950 if (!this->emit##OP(ElemT, E)) \
1956 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1957 if (!getElem(LHSOffset, ElemT, I))
1959 if (!getElem(RHSOffset, RHSElemT, I))
1971 if (!this->emitRem(ElemT, E))
1975 if (!this->emitBitAnd(OpT, E))
1979 if (!this->emitBitOr(OpT, E))
1983 if (!this->emitBitXor(OpT, E))
1987 if (!this->emitShl(OpT, RHSElemT, E))
1991 if (!this->emitShr(OpT, RHSElemT, E))
1995 if (!this->emitEQ(ElemT, E))
1999 if (!this->emitNE(ElemT, E))
2003 if (!this->emitLE(ElemT, E))
2007 if (!this->emitLT(ElemT, E))
2011 if (!this->emitGE(ElemT, E))
2015 if (!this->emitGT(ElemT, E))
2020 if (!this->emitBitAnd(ResultElemT, E))
2025 if (!this->emitBitOr(ResultElemT, E))
2029 return this->emitInvalid(E);
2038 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2040 if (!this->emitNeg(ResultElemT, E))
2046 if (NeedIntPromot &&
2047 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2051 if (!this->emitInitElem(ResultElemT, I, E))
2060template <
class Emitter>
2070 auto LHSSemaInt = LHSSema.toOpaqueInt();
2072 auto RHSSemaInt = RHSSema.toOpaqueInt();
2074 if (!this->
visit(LHS))
2082 if (!this->
visit(RHS))
2091 auto ConvertResult = [&](
bool R) ->
bool {
2095 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2096 if (ResultSema != CommonSema)
2097 return this->emitCastFixedPoint(ResultSema, E);
2101 auto MaybeCastToBool = [&](
bool Result) {
2106 return this->emitPop(
T, E);
2108 return this->emitCast(
PT_Bool,
T, E);
2114 return MaybeCastToBool(this->emitEQFixedPoint(E));
2116 return MaybeCastToBool(this->emitNEFixedPoint(E));
2118 return MaybeCastToBool(this->emitLTFixedPoint(E));
2120 return MaybeCastToBool(this->emitLEFixedPoint(E));
2122 return MaybeCastToBool(this->emitGTFixedPoint(E));
2124 return MaybeCastToBool(this->emitGEFixedPoint(E));
2126 return ConvertResult(this->emitAddFixedPoint(E));
2128 return ConvertResult(this->emitSubFixedPoint(E));
2130 return ConvertResult(this->emitMulFixedPoint(E));
2132 return ConvertResult(this->emitDivFixedPoint(E));
2134 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2136 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2139 return this->emitInvalid(E);
2142 llvm_unreachable(
"unhandled binop opcode");
2145template <
class Emitter>
2154 if (!this->
visit(SubExpr))
2156 if (!this->emitNegFixedPoint(E))
2159 return this->emitPopFixedPoint(E);
2165 llvm_unreachable(
"Unhandled unary opcode");
2168template <
class Emitter>
2177 return this->visitZeroInitializer(*
T, QT, E);
2190 return this->visitZeroRecordInitializer(R, E);
2197 return this->visitZeroArrayInitializer(QT, E);
2201 QualType ElemQT = ComplexTy->getElementType();
2203 for (
unsigned I = 0; I < 2; ++I) {
2204 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2206 if (!this->emitInitElem(ElemT, I, E))
2213 unsigned NumVecElements = VecT->getNumElements();
2214 QualType ElemQT = VecT->getElementType();
2217 for (
unsigned I = 0; I < NumVecElements; ++I) {
2218 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2220 if (!this->emitInitElem(ElemT, I, E))
2227 unsigned NumElems = MT->getNumElementsFlattened();
2228 QualType ElemQT = MT->getElementType();
2231 for (
unsigned I = 0; I != NumElems; ++I) {
2232 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2234 if (!this->emitInitElem(ElemT, I, E))
2243template <
class Emitter>
2256 for (
const Expr *SubExpr : {LHS, RHS}) {
2257 if (!this->
visit(SubExpr)) {
2264 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2265 if (!this->emitExpandPtr(E))
2276 return this->emitError(E);
2279 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2283 if (!this->emitArrayElemPtrPop(*IndexT, E))
2286 return this->emitPopPtr(E);
2292 return this->emitLoadPop(*
T, E);
2295template <
class Emitter>
2297 const Expr *ArrayFiller,
const Expr *E) {
2302 QT = AT->getValueType();
2305 if (
Inits.size() == 0)
2307 return this->emitInvalid(E);
2322 if (
Inits.size() == 0)
2323 return this->visitZeroInitializer(*
T, QT, E);
2324 assert(
Inits.size() == 1);
2337 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2344 bool BitField = FieldToInit->isBitField();
2346 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2347 FieldToInit->bitWidth(), E);
2349 return this->emitInitBitField(
T, FieldToInit->Offset,
2350 FieldToInit->bitWidth(), E);
2352 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2353 return this->emitInitField(
T, FieldToInit->Offset, E);
2356 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2364 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2367 if (
Activate && !this->emitActivate(E))
2374 if (
Inits.size() == 0) {
2375 if (!this->visitZeroRecordInitializer(R, E))
2380 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2381 FToInit = ILE->getInitializedFieldInUnion();
2385 const Record::Field *FieldToInit = R->getField(FToInit);
2387 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2390 if (!initCompositeField(FieldToInit,
Init,
true))
2394 return this->emitFinishInit(E);
2397 assert(!R->isUnion());
2398 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2400 const Record::Base *B = R->getBase(BI);
2403 if (!this->emitGetPtrBase(B->Offset,
Init))
2409 unsigned FieldIndex = 0;
2410 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2411 const Record::Field *FieldToInit = R->getField(FieldIndex);
2412 if (FieldToInit->isUnnamedBitField()) {
2427 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2429 }
else if (!initCompositeField(FieldToInit,
Init)) {
2437 assert(R->getNumVirtualBases() == 0);
2439 return this->emitFinishInit(E);
2444 Ctx.getASTContext().getAsConstantArrayType(QT);
2449 !this->emitCheckArrayDestSize(NumElems, E))
2452 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2456 unsigned ElementIndex = 0;
2458 if (
const auto *EmbedS =
2459 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2467 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2468 getFPOptions(E), E))
2474 return this->emitInitElem(TargetT, ElemIndex, IL);
2476 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2492 for (; ElementIndex != NumElems; ++ElementIndex) {
2498 return this->emitFinishInit(E);
2502 unsigned NumInits =
Inits.size();
2507 QualType ElemQT = ComplexTy->getElementType();
2509 if (NumInits == 0) {
2511 for (
unsigned I = 0; I < 2; ++I) {
2512 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2514 if (!this->emitInitElem(ElemT, I, E))
2517 }
else if (NumInits == 2) {
2518 unsigned InitIndex = 0;
2523 if (!this->emitInitElem(ElemT, InitIndex, E))
2532 unsigned NumVecElements = VecT->getNumElements();
2533 assert(NumVecElements >=
Inits.size());
2535 QualType ElemQT = VecT->getElementType();
2539 unsigned InitIndex = 0;
2546 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2547 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2548 InitVecT->getNumElements(), E))
2550 InitIndex += InitVecT->getNumElements();
2552 if (!this->emitInitElem(ElemT, InitIndex, E))
2558 assert(InitIndex <= NumVecElements);
2561 for (; InitIndex != NumVecElements; ++InitIndex) {
2562 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2564 if (!this->emitInitElem(ElemT, InitIndex, E))
2571 unsigned NumElems = MT->getNumElementsFlattened();
2572 assert(
Inits.size() == NumElems);
2574 QualType ElemQT = MT->getElementType();
2580 for (
unsigned I = 0; I != NumElems; ++I) {
2583 if (!this->emitInitElem(ElemT, I, E))
2594template <
class Emitter>
2601 return this->emitInitElem(*InitT, ElemIndex,
Init);
2607 if (!this->emitConstUint32(ElemIndex,
Init))
2609 if (!this->emitArrayElemPtrUint32(
Init))
2614template <
class Emitter>
2617 bool Activate,
bool IsOperatorCall) {
2619 llvm::BitVector NonNullArgs;
2620 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2623 bool ExplicitMemberFn =
false;
2624 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2625 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2627 unsigned ArgIndex = 0;
2628 for (
const Expr *Arg : Args) {
2630 if (!this->
visit(Arg))
2638 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2639 if (DeclIndex < FuncDecl->getNumParams())
2640 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2649 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2657 if (!this->emitActivate(Arg))
2661 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2664 if (!this->emitCheckNonNullArg(ArgT, Arg))
2675template <
class Emitter>
2680template <
class Emitter>
2686template <
class Emitter>
2692template <
class Emitter>
2710template <
class Emitter>
2712 auto It = E->
begin();
2713 return this->
visit(*It);
2717 UnaryExprOrTypeTrait Kind) {
2718 bool AlignOfReturnsPreferred =
2725 T = Ref->getPointeeType();
2727 if (
T.getQualifiers().hasUnaligned())
2733 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2739template <
class Emitter>
2743 UnaryExprOrTypeTrait Kind = E->
getKind();
2746 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2752 ArgType = Ref->getPointeeType();
2758 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2759 return this->emitInvalid(E);
2761 if (Kind == UETT_SizeOf)
2770 return this->emitConst(Size.getQuantity(), E);
2773 if (Kind == UETT_CountOf) {
2779 if (
const auto *CAT =
2783 return this->emitConst(CAT->getSize(), E);
2793 if (VAT->getElementType()->isArrayType()) {
2794 std::optional<APSInt> Res =
2796 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2801 return this->emitConst(*Res, E);
2806 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2826 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2829 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2839 return this->emitConst(Size.getQuantity(), E);
2842 if (Kind == UETT_VectorElements) {
2847 return this->emitConst(VT->getNumElements(), E);
2849 return this->emitSizelessVectorElementSize(E);
2852 if (Kind == UETT_VecStep) {
2854 unsigned N = VT->getNumElements();
2861 return this->emitConst(N, E);
2863 return this->emitConst(1, E);
2866 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2875 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2877 return this->emitInvalid(E);
2879 return this->emitConst(
2880 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2888template <
class Emitter>
2897 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2900 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2901 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2903 if (
Member->getType()->isReferenceType())
2904 return this->emitLoadPopPtr(E);
2913 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2914 MD && !MD->isStatic()) {
2918 if (!this->
discard(Base) && !this->emitSideEffect(E))
2933 const Record::Field *F = R->getField(FD);
2937 const auto maybeLoadValue = [&]() ->
bool {
2941 return this->emitLoadPop(*
T, E);
2946 if (F->Decl->getType()->isReferenceType())
2947 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2948 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2951template <
class Emitter>
2961template <
class Emitter>
2975 if (!this->
visit(Common))
2977 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2991 for (
size_t I = 0; I != Size; ++I) {
3003template <
class Emitter>
3018 return this->emitGetLocal(SubExprT, It->second, E);
3021 if (!this->
visit(SourceExpr))
3028 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3037 return this->emitGetLocal(SubExprT, LocalIndex, E);
3041template <
class Emitter>
3054 bool IsBcpCall =
false;
3055 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3056 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3060 LabelTy LabelEnd = this->getLabel();
3061 LabelTy LabelFalse = this->getLabel();
3064 if (!this->emitPushIgnoreDiags(E))
3072 if (this->checkingForUndefinedBehavior()) {
3075 if (!this->
discard(FalseExpr))
3092 if (!this->jumpFalse(LabelFalse, E))
3097 if (!this->jump(LabelEnd, E))
3099 this->emitLabel(LabelFalse);
3103 this->fallthrough(LabelEnd);
3104 this->emitLabel(LabelEnd);
3107 return this->emitPopIgnoreDiags(E);
3111template <
class Emitter>
3117 unsigned StringIndex =
P.createGlobalString(E);
3118 return this->emitGetPtrGlobal(StringIndex, E);
3123 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3124 assert(CAT &&
"a string literal that's not a constant array?");
3129 unsigned N = std::min(ArraySize, E->
getLength());
3132 for (
unsigned I = 0; I != N; ++I) {
3135 if (CharWidth == 1) {
3136 this->emitConstSint8(CodeUnit, E);
3137 this->emitInitElemSint8(I, E);
3138 }
else if (CharWidth == 2) {
3139 this->emitConstUint16(CodeUnit, E);
3140 this->emitInitElemUint16(I, E);
3141 }
else if (CharWidth == 4) {
3142 this->emitConstUint32(CodeUnit, E);
3143 this->emitInitElemUint32(I, E);
3145 llvm_unreachable(
"unsupported character width");
3150 for (
unsigned I = N; I != ArraySize; ++I) {
3151 if (CharWidth == 1) {
3152 this->emitConstSint8(0, E);
3153 this->emitInitElemSint8(I, E);
3154 }
else if (CharWidth == 2) {
3155 this->emitConstUint16(0, E);
3156 this->emitInitElemUint16(I, E);
3157 }
else if (CharWidth == 4) {
3158 this->emitConstUint32(0, E);
3159 this->emitInitElemUint32(I, E);
3161 llvm_unreachable(
"unsupported character width");
3168template <
class Emitter>
3172 return this->emitDummyPtr(E, E);
3175template <
class Emitter>
3177 auto &A =
Ctx.getASTContext();
3186template <
class Emitter>
3194 auto &A =
Ctx.getASTContext();
3198 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3199 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3206 unsigned StringIndex =
P.createGlobalString(SL);
3207 return this->emitGetPtrGlobal(StringIndex, E);
3210template <
class Emitter>
3214 return this->emitConst(E->
getValue(), E);
3217template <
class Emitter>
3239 if (!this->emitLoad(LHST, E))
3242 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3243 LHSComputationType, E))
3255 unsigned TempOffset =
3257 if (!this->emitSetLocal(*RT, TempOffset, E))
3263 if (!this->emitLoad(LHST, E))
3267 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3268 LHSComputationType, E))
3272 if (!this->emitGetLocal(*RT, TempOffset, E))
3278 if (!this->emitAddf(getFPOptions(E), E))
3282 if (!this->emitSubf(getFPOptions(E), E))
3286 if (!this->emitMulf(getFPOptions(E), E))
3290 if (!this->emitDivf(getFPOptions(E), E))
3301 return this->emitStorePop(LHST, E);
3302 return this->emitStore(LHST, E);
3305template <
class Emitter>
3314 if (Op != BO_AddAssign && Op != BO_SubAssign)
3323 if (!this->emitLoad(*
LT, LHS))
3329 if (Op == BO_AddAssign) {
3330 if (!this->emitAddOffset(*RT, E))
3333 if (!this->emitSubOffset(*RT, E))
3338 return this->emitStorePopPtr(E);
3339 return this->emitStorePtr(E);
3342template <
class Emitter>
3355 if (!
Ctx.getLangOpts().CPlusPlus14)
3356 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3358 if (!
LT || !RT || !ResultT || !LHSComputationT)
3375 if (!this->emitLoad(*
LT, E))
3377 if (
LT != LHSComputationT &&
3378 !this->emitIntegralCast(*
LT, *LHSComputationT,
3392 unsigned TempOffset =
3395 if (!this->emitSetLocal(*RT, TempOffset, E))
3402 if (!this->emitLoad(*
LT, E))
3404 if (
LT != LHSComputationT &&
3405 !this->emitIntegralCast(*
LT, *LHSComputationT,
3410 if (!this->emitGetLocal(*RT, TempOffset, E))
3417 if (!this->emitAdd(*LHSComputationT, E))
3421 if (!this->emitSub(*LHSComputationT, E))
3425 if (!this->emitMul(*LHSComputationT, E))
3429 if (!this->emitDiv(*LHSComputationT, E))
3433 if (!this->emitRem(*LHSComputationT, E))
3437 if (!this->emitShl(*LHSComputationT, *RT, E))
3441 if (!this->emitShr(*LHSComputationT, *RT, E))
3445 if (!this->emitBitAnd(*LHSComputationT, E))
3449 if (!this->emitBitXor(*LHSComputationT, E))
3453 if (!this->emitBitOr(*LHSComputationT, E))
3457 llvm_unreachable(
"Unimplemented compound assign operator");
3461 if (ResultT != LHSComputationT &&
3462 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3468 return this->emitStoreBitFieldPop(*ResultT, E);
3469 return this->emitStorePop(*ResultT, E);
3472 return this->emitStoreBitField(*ResultT, E);
3473 return this->emitStore(*ResultT, E);
3476template <
class Emitter>
3484template <
class Emitter>
3499 if (!
Ctx.getLangOpts().CPlusPlus11)
3506 for (
const Expr *LHS : CommaLHSs) {
3528 if (!this->
visit(Inner))
3533 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3536 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3539 return this->emitGetPtrGlobal(*GlobalIndex, E);
3542 if (!this->checkLiteralType(Inner))
3545 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3551 return this->emitInitGlobalTempComp(TempDecl, E);
3564 unsigned LocalIndex =
3566 if (!this->VarScope->LocalsAlwaysEnabled &&
3567 !this->emitEnableLocal(LocalIndex, E))
3570 if (!this->
visit(Inner))
3572 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3575 return this->emitGetPtrLocal(LocalIndex, E);
3578 if (!this->checkLiteralType(Inner))
3585 if (!this->VarScope->LocalsAlwaysEnabled &&
3586 !this->emitEnableLocal(*LocalIndex, E))
3589 if (!this->emitGetPtrLocal(*LocalIndex, E))
3596template <
class Emitter>
3607 if (!this->
visit(SubExpr))
3611 return this->emitPopPtr(E);
3615template <
class Emitter>
3636 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3641 if (
P.isGlobalInitialized(*GlobalIndex))
3647 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3659 unsigned LocalIndex;
3663 LocalIndex = *MaybeIndex;
3667 if (!this->emitGetPtrLocal(LocalIndex, E))
3671 return this->
visit(
Init) && this->emitInit(*
T, E);
3675template <
class Emitter>
3688template <
class Emitter>
3692 return this->emitConst(E->
getValue(), E);
3695template <
class Emitter>
3708 for (
const Record::Field &F : R->fields()) {
3710 if (!
Init ||
Init->containsErrors())
3718 if (!this->emitInitField(*
T, F.Offset, E))
3721 if (!this->emitGetPtrField(F.Offset, E))
3732template <
class Emitter>
3739 return this->emitGetPtrGlobal(StringIndex, E);
3745template <
class Emitter>
3750 return this->emitInvalid(E);
3753template <
class Emitter>
3773 bool Fatal = (ToT != FromT);
3780template <
class Emitter>
3782 if (!
Ctx.getLangOpts().CPlusPlus20) {
3803 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3808 return this->emitPopPtr(E);
3812template <
class Emitter>
3818 return this->emitConstBool(E->
getValue(), E);
3821template <
class Emitter>
3826 if (
T->isRecordType()) {
3840 if (!this->emitGetPtrLocal(*LocalIndex, E))
3848 T->getAsCXXRecordDecl()))
3858 if (!this->visitZeroRecordInitializer(R, E))
3870 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3872 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3873 if (!this->emitCheckFunctionDecl(Ctor, E))
3884 assert(
Func->hasThisPointer());
3885 assert(!
Func->hasRVO());
3889 if (!this->emitDupPtr(E))
3893 for (
const auto *Arg : E->
arguments()) {
3894 if (!this->
visit(Arg))
3898 if (
Func->isVariadic()) {
3899 uint32_t VarArgSize = 0;
3900 unsigned NumParams =
Func->getNumWrittenParams();
3901 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3905 if (!this->emitCallVar(
Func, VarArgSize, E))
3908 if (!this->emitCall(
Func, 0, E)) {
3913 (void)this->emitPopPtr(E);
3919 return this->emitPopPtr(E);
3923 if (
T->isArrayType()) {
3928 if (!this->emitDupPtr(E))
3932 initArrayDimension = [&](
QualType T) ->
bool {
3933 if (!
T->isArrayType()) {
3935 for (
const auto *Arg : E->
arguments()) {
3936 if (!this->
visit(Arg))
3940 return this->emitCall(
Func, 0, E);
3944 Ctx.getASTContext().getAsConstantArrayType(
T);
3949 for (
size_t I = 0; I != NumElems; ++I) {
3950 if (!this->emitConstUint64(I, E))
3952 if (!this->emitArrayElemPtrUint64(E))
3954 if (!initArrayDimension(ElemTy))
3957 return this->emitPopPtr(E);
3960 return initArrayDimension(E->
getType());
3966template <
class Emitter>
3976 assert(Val.
isInt());
3978 return this->emitConst(I, E);
3985 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3986 return this->
visit(LValueExpr);
4001 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4005 const APValue &
V = UGCD->getValue();
4006 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4007 const Record::Field *F = R->getField(I);
4008 const APValue &FieldValue =
V.getStructField(I);
4014 if (!this->emitInitField(FieldT, F->Offset, E))
4022template <
class Emitter>
4028 for (
unsigned I = 0; I != N; ++I) {
4035 if (!this->
discard(ArrayIndexExpr))
4041 if (!this->
visit(ArrayIndexExpr))
4043 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4047 if (!this->
visit(ArrayIndexExpr))
4051 if (!this->emitCast(IndexT,
PT_Sint64, E))
4061 return this->emitOffsetOf(
T, E, E);
4064template <
class Emitter>
4073 return this->visitZeroInitializer(*
T, Ty, E);
4080 if (!this->emitGetPtrLocal(*LocalIndex, E))
4088 ElemQT = CT->getElementType();
4091 NumElems = VT->getNumElements();
4092 ElemQT = VT->getElementType();
4098 for (
unsigned I = 0; I != NumElems; ++I) {
4099 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4101 if (!this->emitInitElem(ElemT, I, E))
4110template <
class Emitter>
4115template <
class Emitter>
4121template <
class Emitter>
4126template <
class Emitter>
4131 return this->emitConst(E->
getValue(), E);
4134template <
class Emitter>
4139 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4154 unsigned ParamIndex = 0;
4158 if (!this->emitGetParam(PT, ParamIndex, E))
4163 return this->emitCall(F, 0, E);
4168template <
class Emitter>
4176 const Expr *PlacementDest =
nullptr;
4177 bool IsNoThrow =
false;
4182 if (PlacementArgs != 0) {
4191 if (PlacementArgs == 1) {
4199 if (!this->emitInvalidNewDeleteExpr(E, E))
4204 if (OperatorNew->isReservedGlobalPlacementOperator())
4205 PlacementDest = Arg1;
4209 return this->emitInvalid(E);
4211 }
else if (!OperatorNew
4212 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4213 return this->emitInvalidNewDeleteExpr(E, E);
4216 if (!PlacementDest) {
4221 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
4224 Desc =
P.createDescriptor(
4227 false,
false,
false,
4233 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4237 const Expr *Stripped = *ArraySizeExpr;
4238 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4239 Stripped = ICE->getSubExpr())
4240 if (ICE->getCastKind() != CK_NoOp &&
4241 ICE->getCastKind() != CK_IntegralCast)
4249 if (!this->
visit(Stripped))
4251 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4254 if (PlacementDest) {
4255 if (!this->
visit(PlacementDest))
4257 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4259 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4262 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4267 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4271 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4278 size_t StaticInitElems = 0;
4279 const Expr *DynamicInit =
nullptr;
4283 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4284 StaticInitElems = CAT->getZExtSize();
4289 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4290 if (ILE->hasArrayFiller())
4291 DynamicInit = ILE->getArrayFiller();
4310 const Function *CtorFunc =
nullptr;
4311 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4315 }
else if (!DynamicInit && !ElemT)
4318 LabelTy EndLabel = this->getLabel();
4319 LabelTy StartLabel = this->getLabel();
4324 if (!this->emitDupPtr(E))
4326 if (!this->emitNullPtr(0,
nullptr, E))
4328 if (!this->emitEQPtr(E))
4330 if (!this->jumpTrue(EndLabel, E))
4337 if (!this->emitConst(StaticInitElems,
SizeT, E))
4339 if (!this->emitSetLocal(
SizeT, Iter, E))
4342 this->fallthrough(StartLabel);
4343 this->emitLabel(StartLabel);
4345 if (!this->emitGetLocal(
SizeT, Iter, E))
4347 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4349 if (!this->emitLT(
SizeT, E))
4351 if (!this->jumpFalse(EndLabel, E))
4355 if (!this->emitGetLocal(
SizeT, Iter, E))
4357 if (!this->emitArrayElemPtr(
SizeT, E))
4360 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4365 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4367 if (!this->emitStorePop(*InitT, E))
4371 if (!this->visitZeroArrayInitializer(ElemType, E))
4374 }
else if (DynamicInit) {
4376 if (!this->
visit(DynamicInit))
4378 if (!this->emitStorePop(*InitT, E))
4385 if (!this->visitZeroInitializer(
4389 if (!this->emitStorePop(*ElemT, E))
4393 if (!this->emitCall(CtorFunc, 0, E))
4398 if (!this->emitGetPtrLocal(Iter, E))
4400 if (!this->emitIncPop(
SizeT,
false, E))
4403 if (!this->jump(StartLabel, E))
4406 this->fallthrough(EndLabel);
4407 this->emitLabel(EndLabel);
4411 if (PlacementDest) {
4412 if (!this->
visit(PlacementDest))
4414 if (!this->emitCheckNewTypeMismatch(E, E))
4419 if (!this->emitAlloc(Desc, E))
4428 if (!this->emitInit(*ElemT, E))
4439 return this->emitPopPtr(E);
4444template <
class Emitter>
4450 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4451 return this->emitInvalidNewDeleteExpr(E, E);
4460template <
class Emitter>
4466 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4471 return this->emitGetFnPtr(
Func, E);
4474template <
class Emitter>
4478 auto canonType = [](
const Type *
T) {
4479 return T->getCanonicalTypeUnqualified().getTypePtr();
4487 return this->emitGetTypeid(
4491 return this->emitGetTypeid(
4500 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4506 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4509 return this->emitPopPtr(E);
4513template <
class Emitter>
4517 return this->emitDummyPtr(E, E);
4518 return this->emitError(E);
4521template <
class Emitter>
4524 return this->emitDummyPtr(E, E);
4525 return this->emitError(E);
4528template <
class Emitter>
4530 assert(
Ctx.getLangOpts().CPlusPlus);
4531 return this->emitConstBool(E->
getValue(), E);
4534template <
class Emitter>
4546 return this->emitDummyPtr(GuidDecl, E);
4551 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4560 assert(
V.isStruct());
4561 assert(
V.getStructNumBases() == 0);
4565 return this->emitFinishInit(E);
4568template <
class Emitter>
4578template <
class Emitter>
4587template <
class Emitter>
4593template <
class Emitter>
4597 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4601 if (OVE->isUnique())
4617template <
class Emitter>
4622template <
class Emitter>
4624 return this->emitError(E);
4627template <
class Emitter>
4633 return this->emitDummyPtr(E, E);
4636template <
class Emitter>
4637bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4642 QualType ElemType = VT->getElementType();
4643 PrimType ElemT = classifyPrim(ElemType);
4645 PrimType SrcElemT = classifyVectorElementType(SrcType);
4651 if (!this->emitGetPtrLocal(*LocalIndex, E))
4655 unsigned SrcOffset =
4656 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4657 if (!this->visit(Src))
4659 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4662 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4663 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4665 if (!this->emitArrayElemPop(SrcElemT, I, E))
4669 if (SrcElemT != ElemT) {
4670 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4672 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4673 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4677 if (!this->emitInitElem(ElemT, I, E))
4683template <
class Emitter>
4685 return emitVectorConversion(E->
getSrcExpr(), E);
4688template <
class Emitter>
4692 return this->emitInvalid(E);
4701 assert(NumOutputElems > 0);
4707 if (!this->emitGetPtrLocal(*LocalIndex, E))
4712 unsigned VectorOffsets[2];
4713 for (
unsigned I = 0; I != 2; ++I) {
4716 if (!this->
visit(Vecs[I]))
4718 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4721 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4723 assert(ShuffleIndex >= -1);
4724 if (ShuffleIndex == -1)
4725 return this->emitInvalidShuffleVectorIndex(I, E);
4727 assert(ShuffleIndex < (NumInputElems * 2));
4728 if (!this->emitGetLocal(
PT_Ptr,
4729 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4731 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4732 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4735 if (!this->emitInitElem(ElemT, I, E))
4740 return this->emitPopPtr(E);
4745template <
class Emitter>
4750 Base->getType()->isVectorType() ||
4756 if (Indices.size() == 1) {
4761 if (!this->emitConstUint32(Indices[0], E))
4763 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4773 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4781 if (!this->emitGetPtrLocal(*ResultIndex, E))
4789 uint32_t DstIndex = 0;
4790 for (uint32_t I : Indices) {
4791 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4793 if (!this->emitArrayElemPop(ElemT, I, E))
4795 if (!this->emitInitElem(ElemT, DstIndex, E))
4805template <
class Emitter>
4809 return this->
discard(SubExpr) && this->emitInvalid(E);
4815 return this->emitDummyPtr(E, E);
4818template <
class Emitter>
4823 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4828 if (!this->
visit(SubExpr))
4830 if (!this->emitConstUint8(0, E))
4832 if (!this->emitArrayElemPtrPopUint8(E))
4834 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4839 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4841 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4843 assert(SecondFieldT ==
PT_Ptr);
4845 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4847 if (!this->emitExpandPtr(E))
4851 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4853 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4856template <
class Emitter>
4871 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4875 return this->emitUnsupported(E);
4884 return this->
Visit(E);
4891 return this->
Visit(E);
4895 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4898 if (
const auto *CE = dyn_cast<CastExpr>(E);
4900 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4907 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4910 if (
const auto *CE = dyn_cast<CastExpr>(E);
4911 CE && (CE->getCastKind() == CK_DerivedToBase ||
4912 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4913 CE->getCastKind() == CK_NoOp))
4933 if (!this->emitGetPtrLocal(*LocalIndex, E))
4943 return this->
Visit(E);
4946template <
class Emitter>
4952 return this->
Visit(E) && this->emitFinishInit(E);
4955template <
class Emitter>
4961 return this->
Visit(E) && this->emitFinishInitPop(E);
4967 return this->
Visit(E);
4978 if (!this->
visit(E))
4980 return this->emitComplexBoolCast(E);
4985 if (!this->
visit(E))
4993 return this->emitIsNonNullPtr(E);
4997 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5000 return this->emitCast(*
T,
PT_Bool, E);
5003template <
class Emitter>
5007 QT = AT->getValueType();
5011 return this->emitZeroBool(E);
5013 return this->emitZeroSint8(E);
5015 return this->emitZeroUint8(E);
5017 return this->emitZeroSint16(E);
5019 return this->emitZeroUint16(E);
5021 return this->emitZeroSint32(E);
5023 return this->emitZeroUint32(E);
5025 return this->emitZeroSint64(E);
5027 return this->emitZeroUint64(E);
5029 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5031 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5033 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5036 return this->emitNullMemberPtr(0,
nullptr, E);
5038 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5039 return this->emitFloat(F, E);
5042 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5046 llvm_unreachable(
"unknown primitive type");
5049template <
class Emitter>
5050bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5052 bool IsCompleteClass) {
5056 for (
const Record::Field &Field :
R->fields()) {
5057 if (Field.isUnnamedBitField())
5064 if (!this->visitZeroInitializer(
T, QT, E))
5067 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5071 if (!this->emitInitField(
T, Field.Offset, E))
5076 if (!this->emitGetPtrField(Field.Offset, E))
5083 if (!this->visitZeroInitializer(
T, ET, E))
5085 if (!this->emitInitElem(
T, I, E))
5090 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5093 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5101 if (!this->emitFinishInitActivatePop(E))
5105 if (!this->emitFinishInitPop(E))
5109 for (
const Record::Base &B :
R->bases()) {
5110 if (!this->emitGetPtrBase(B.Offset, E))
5112 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5114 if (!this->emitFinishInitPop(E))
5118 if (IsCompleteClass) {
5119 for (
const Record::Base &B :
R->virtual_bases()) {
5122 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5124 if (!this->emitFinishInitPop(E))
5132template <
class Emitter>
5133bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5134 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5135 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5140 for (
size_t I = 0; I != NumElems; ++I) {
5141 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5143 if (!this->emitInitElem(*ElemT, I, E))
5149 const Record *
R = getRecord(ElemType);
5153 for (
size_t I = 0; I != NumElems; ++I) {
5154 if (!this->emitConstUint32(I, E))
5156 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5158 if (!this->visitZeroRecordInitializer(R, E))
5160 if (!this->emitPopPtr(E))
5166 for (
size_t I = 0; I != NumElems; ++I) {
5167 if (!this->emitConstUint32(I, E))
5169 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5171 if (!this->visitZeroArrayInitializer(ElemType, E))
5173 if (!this->emitPopPtr(E))
5182template <
class Emitter>
5183bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5185 if (!canClassify(E->
getType()))
5190 if (!this->visit(LHS))
5192 if (!this->visit(RHS))
5195 if (!this->visit(RHS))
5197 if (!this->visit(LHS))
5205 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5209 bool Activates = refersToUnion(LHS);
5212 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5215 if (DiscardResult) {
5216 if (BitField && Activates)
5217 return this->emitStoreBitFieldActivatePop(RHT, E);
5219 return this->emitStoreBitFieldPop(RHT, E);
5221 return this->emitStoreActivatePop(RHT, E);
5223 return this->emitStorePop(RHT, E);
5226 auto maybeLoad = [&](
bool Result) ->
bool {
5232 return this->emitLoadPop(RHT, E);
5236 if (BitField && Activates)
5237 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5239 return maybeLoad(this->emitStoreBitField(RHT, E));
5241 return maybeLoad(this->emitStoreActivate(RHT, E));
5243 return maybeLoad(this->emitStore(RHT, E));
5246template <
class Emitter>
5247template <
typename T>
5251 return this->emitConstSint8(
Value, Info);
5253 return this->emitConstUint8(
Value, Info);
5255 return this->emitConstSint16(
Value, Info);
5257 return this->emitConstUint16(
Value, Info);
5259 return this->emitConstSint32(
Value, Info);
5261 return this->emitConstUint32(
Value, Info);
5263 return this->emitConstSint64(
Value, Info);
5265 return this->emitConstUint64(
Value, Info);
5267 return this->emitConstBool(
Value, Info);
5274 llvm_unreachable(
"Invalid integral type");
5277 llvm_unreachable(
"unknown primitive type");
5280template <
class Emitter>
5281template <
typename T>
5282bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5283 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5286template <
class Emitter>
5290 return this->emitConstIntAPS(
Value, Info);
5292 return this->emitConstIntAP(
Value, Info);
5294 if (
Value.isSigned())
5295 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5296 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5299template <
class Emitter>
5303 return this->emitConstIntAPS(
Value, Info);
5305 return this->emitConstIntAP(
Value, Info);
5308 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5309 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5312template <
class Emitter>
5313bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5314 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5317template <
class Emitter>
5326 IsConst, Src.isExpr(),
5330 if (
auto *VD = Src.asValueDecl())
5331 Locals.insert({VD, Local});
5332 VarScope->addForScopeKind(Local, SC);
5333 return Local.Offset;
5336template <
class Emitter>
5341 bool IsTemporary =
false;
5342 if (
auto *VD = Src.asValueDecl()) {
5345 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5346 Init = VarD->getInit();
5348 if (
const auto *E = Src.asExpr()) {
5359 return std::nullopt;
5364 Locals.insert({Key, Local});
5365 VarScope->addForScopeKind(Local, SC);
5366 return Local.Offset;
5369template <
class Emitter>
5379 return std::nullopt;
5389 return Local.Offset;
5392template <
class Emitter>
5394 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5395 return PT->getPointeeType()->getAsCanonical<RecordType>();
5401 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5405template <
class Emitter>
5407 return P.getOrCreateRecord(RD);
5410template <
class Emitter>
5412 return Ctx.getOrCreateFunction(FD);
5415template <
class Emitter>
5419 auto maybeDestroyLocals = [&]() ->
bool {
5420 if (DestroyToplevelScope)
5421 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5422 return this->emitCheckAllocations(E);
5429 return this->emitRetVoid(E) && maybeDestroyLocals();
5437 return this->emitRet(*
T, E) && maybeDestroyLocals();
5445 if (!this->emitGetPtrLocal(*LocalOffset, E))
5453 return this->emitRetValue(E) && maybeDestroyLocals();
5456 return maybeDestroyLocals() &&
false;
5459template <
class Emitter>
5461 bool DestroyToplevelScope) {
5465 return this->
visitExpr(E, DestroyToplevelScope);
5468template <
class Emitter>
5480 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5481 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5495template <
class Emitter>
5497 bool ConstantContext) {
5500 if (!ConstantContext) {
5515 auto GlobalIndex =
P.getGlobal(VD);
5516 assert(GlobalIndex);
5518 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5521 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5525 auto Local =
Locals.find(VD);
5526 assert(Local !=
Locals.end());
5529 if (!this->emitGetRefLocal(Local->second.Offset, VD))
5531 }
else if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5534 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5544 auto GlobalIndex =
P.getGlobal(VD);
5545 assert(GlobalIndex);
5546 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5555 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5558template <
class Emitter>
5569 if (!this->isActive())
5574 if (
Init &&
Init->isValueDependent())
5578 auto checkDecl = [&]() ->
bool {
5580 return !NeedsOp || this->emitCheckDecl(VD, VD);
5587 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5590 if (
P.isGlobalInitialized(*GlobalIndex))
5594 }
else if ((GlobalIndex =
5609 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5612 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5615 if (!this->emitStartInit(
Init))
5621 if (!this->emitEndInit(
Init))
5624 return this->emitFinishInitGlobal(
Init);
5634 if (!
Init ||
Init->getType()->isVoidType())
5643 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5655 if (!this->emitCheckRefInit(
Init))
5659 return this->emitSetLocal(*VarT, Offset, VD);
5667 if (!this->emitGetPtrLocal(*Offset,
Init))
5675template <
class Emitter>
5696 Locals.insert({VD, Local});
5699 if (!this->emitGetPtrLocal(Local.Offset, VD))
5705 return this->emitDestructionPop(D, VD);
5714 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5738template <
class Emitter>
5753 unsigned ParamIndex = 0;
5760 const Expr *Arg = Args[ParamIndex];
5761 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5763 unsigned ArgOffset =
5765 if (!this->
visit(Arg))
5767 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5773 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5785 if (
This->getType()->isPointerType()) {
5788 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5795 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5817template <
class Emitter>
5823 return this->emitConst(Val.
getInt(), ValType, Info);
5826 return this->emitFloat(F, Info);
5831 if (!this->emitGetMemberPtr(MemberDecl, Info))
5837 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5843 return this->emitNullMemberPtr(0,
nullptr, Info);
5848 return this->emitNull(ValType, 0,
nullptr, Info);
5853 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5854 return this->
visit(BaseExpr);
5859 QualType EntryType = VD->getType();
5860 for (
auto &Entry : Path) {
5862 uint64_t Index = Entry.getAsArrayIndex();
5865 if (!this->emitConst(Index,
PT_Uint64, Info))
5867 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5869 EntryType = ElemType;
5876 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5877 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5879 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5881 EntryType = FD->getType();
5885 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
5890 if (!this->emitGetPtrVirtBasePop(
Base, Info))
5893 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5905template <
class Emitter>
5908 bool IsCompleteClass) {
5914 if (IsCompleteClass)
5921 const Record::Base *RB = R->getBase(I);
5922 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5924 if (!this->emitGetPtrBase(RB->Offset, Info))
5929 if (!this->emitFinishInitPop(Info))
5937 const Record::Field *RF = R->getField(I);
5938 QualType FieldType = RF->Decl->getType();
5943 if (!this->emitInitField(*PT, RF->Offset, Info))
5946 if (!this->emitGetPtrField(RF->Offset, Info))
5950 if (!this->emitFinishInitPop(Info))
5956 if (IsCompleteClass) {
5961 const Record::Base *RB = R->getVirtualBase(I);
5962 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5970 if (!this->emitFinishInitPop(Info))
5986 const Record::Field *RF = R->getField(UnionField);
5987 QualType FieldType = RF->Decl->getType();
5992 if (RF->isBitField())
5993 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5995 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
5998 if (!this->emitGetPtrField(RF->Offset, Info))
6000 if (!this->emitActivate(Info))
6004 return this->emitPopPtr(Info);
6008 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6009 QualType ElemType = ArrType->getElementType();
6012 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6013 const APValue &Elem = A >= InitializedElems
6022 if (!this->emitInitElem(*ElemT, A, Info))
6025 if (!this->emitConstUint32(A, Info))
6027 if (!this->emitArrayElemPtrUint32(Info))
6031 if (!this->emitPopPtr(Info))
6042template <
class Emitter>
6044 unsigned BuiltinID) {
6045 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6050 return this->emitConst(0, E);
6053 if (!this->emitStartSpeculation(E))
6055 LabelTy EndLabel = this->getLabel();
6056 if (!this->speculate(E, EndLabel))
6058 if (!this->emitEndSpeculation(E))
6060 this->fallthrough(EndLabel);
6068 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6069 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6070 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6071 BuiltinID == Builtin::BI__builtin_function_start) {
6074 return this->emitDummyPtr(E, E);
6085 if (!this->emitGetPtrLocal(*LocalIndex, E))
6090 switch (BuiltinID) {
6091 case Builtin::BI__builtin_object_size:
6092 case Builtin::BI__builtin_dynamic_object_size: {
6096 if (!this->
visit(Arg0))
6107 case Builtin::BI__assume:
6108 case Builtin::BI__builtin_assume:
6111 case Builtin::BI__atomic_is_lock_free:
6112 case Builtin::BI__atomic_always_lock_free: {
6123 for (
const auto *Arg : E->
arguments()) {
6124 if (!this->
visit(Arg))
6130 if (!this->emitCallBI(E, BuiltinID, E))
6139template <
class Emitter>
6160 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6161 DD && DD->isTrivial()) {
6163 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6165 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6166 this->emitPopPtr(E);
6182 if (!this->emitGetPtrLocal(*LocalIndex, E))
6190 if (!this->emitGetPtrLocal(*LocalIndex, E))
6194 if (!this->emitDupPtr(E))
6201 bool IsAssignmentOperatorCall =
false;
6202 bool ActivateLHS =
false;
6203 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6204 OCE && OCE->isAssignmentOp()) {
6208 assert(Args.size() == 2);
6209 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6211 IsAssignmentOperatorCall =
true;
6212 std::reverse(Args.begin(), Args.end());
6218 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6219 MD && MD->isStatic()) {
6223 Args.erase(Args.begin());
6227 bool Devirtualized =
false;
6230 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6238 if (!this->
visit(Callee))
6240 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6242 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6244 if (!this->emitGetMemberPtrBase(E))
6247 const auto *InstancePtr = MC->getImplicitObjectArgument();
6254 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6255 Devirtualized =
true;
6256 if (!this->
visit(Stripped))
6259 if (!this->
visit(InstancePtr))
6263 if (!this->
visit(InstancePtr))
6267 }
else if (
const auto *PD =
6268 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6269 if (!this->emitCheckPseudoDtor(E))
6277 return this->emitPseudoDtor(E);
6278 }
else if (!FuncDecl) {
6282 if (!this->
visit(Callee))
6284 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6293 if (IsAssignmentOperatorCall) {
6294 assert(Args.size() == 2);
6297 if (!this->emitFlip(Arg2T, Arg1T, E))
6311 assert(HasRVO ==
Func->hasRVO());
6313 bool HasQualifier =
false;
6314 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6315 HasQualifier = ME->hasQualifier();
6317 bool IsVirtual =
false;
6318 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6319 IsVirtual = !Devirtualized && MD->isVirtual();
6324 if (IsVirtual && !HasQualifier) {
6325 uint32_t VarArgSize = 0;
6326 unsigned NumParams =
6327 Func->getNumWrittenParams() +
6329 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6332 if (!this->emitCallVirt(
Func, VarArgSize, E))
6334 }
else if (
Func->isVariadic()) {
6335 uint32_t VarArgSize = 0;
6336 unsigned NumParams =
6337 Func->getNumWrittenParams() +
6339 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6341 if (!this->emitCallVar(
Func, VarArgSize, E))
6344 if (!this->emitCall(
Func, 0, E))
6353 uint32_t ArgSize = 0;
6354 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6360 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6362 if (!this->emitGetMemberPtrDecl(E))
6365 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6368 if (!this->emitCallPtr(ArgSize, E, E))
6379template <
class Emitter>
6386template <
class Emitter>
6393template <
class Emitter>
6398 return this->emitConstBool(E->
getValue(), E);
6401template <
class Emitter>
6407 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6408 return this->emitNullPtr(Val,
nullptr, E);
6411template <
class Emitter>
6419 return this->emitZero(
T, E);
6422template <
class Emitter>
6427 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6428 if (this->LambdaThisCapture.Offset > 0) {
6429 if (this->LambdaThisCapture.IsPtr)
6430 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6431 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6440 return this->emitThis(E);
6455 unsigned StartIndex = 0;
6456 unsigned EndIndex = 0;
6458 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6460 EndIndex = StartIndex;
6467 for (; StartIndex > 0; --StartIndex) {
6478 if (StartIndex == 0 && EndIndex == 0)
6489 assert(StartIndex <= EndIndex);
6492 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6504 case Stmt::CompoundStmtClass:
6506 case Stmt::DeclStmtClass:
6508 case Stmt::ReturnStmtClass:
6510 case Stmt::IfStmtClass:
6512 case Stmt::WhileStmtClass:
6514 case Stmt::DoStmtClass:
6516 case Stmt::ForStmtClass:
6518 case Stmt::CXXForRangeStmtClass:
6520 case Stmt::BreakStmtClass:
6522 case Stmt::ContinueStmtClass:
6524 case Stmt::SwitchStmtClass:
6526 case Stmt::CaseStmtClass:
6528 case Stmt::DefaultStmtClass:
6530 case Stmt::AttributedStmtClass:
6532 case Stmt::CXXTryStmtClass:
6534 case Stmt::NullStmtClass:
6537 case Stmt::GCCAsmStmtClass:
6538 case Stmt::MSAsmStmtClass:
6539 case Stmt::GotoStmtClass:
6540 return this->emitInvalid(S);
6541 case Stmt::LabelStmtClass:
6543 case Stmt::CXXExpansionStmtInstantiationClass:
6547 if (
const auto *E = dyn_cast<Expr>(S))
6554template <
class Emitter>
6557 for (
const auto *InnerStmt : S->
body())
6560 return Scope.destroyLocals();
6563template <
class Emitter>
6564bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6565 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6566 for (
auto *BD : DD->flat_bindings())
6567 if (
auto *KD = BD->getHoldingVar();
6568 KD && !this->visitVarDecl(KD, KD->getInit()))
6582template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6584 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6585 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6592 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6597 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6598 ICE && (ICE->getCastKind() == CK_NoOp ||
6599 ICE->getCastKind() == CK_DerivedToBase ||
6600 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6601 E = ICE->getSubExpr();
6605 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6606 const auto *ThisRecord =
6607 This->getType()->getPointeeType()->getAsRecordDecl();
6608 if (!ThisRecord->isUnion())
6611 if (
const auto *Ctor =
6612 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6613 return Ctor->getParent() == ThisRecord;
6622template <
class Emitter>
6624 bool EvaluateConditionDecl) {
6625 for (
const auto *D : DS->
decls()) {
6630 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6631 assert(ESD->getInstantiations() &&
"not expanded?");
6632 if (!this->
visitStmt(ESD->getInstantiations()))
6637 const auto *VD = dyn_cast<VarDecl>(D);
6644 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6651template <
class Emitter>
6654 return this->emitUnsupported(RS);
6660 if (!this->
visit(RE))
6666 if (RE->getType()->isVoidType()) {
6667 if (!this->
visit(RE))
6670 if (RE->containsErrors())
6675 if (!this->emitRVOPtr(RE))
6681 return this->emitRetVoid(RS);
6687 return this->emitRetVoid(RS);
6693 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6700 if (
auto *CondInit = IS->
getInit()) {
6716 return visitChildStmt(IS->
getThen());
6718 return visitChildStmt(Else);
6724 if (!this->emitIsConstantContext(IS))
6727 if (!this->emitIsConstantContext(IS))
6729 if (!this->emitInv(IS))
6743 LabelTy LabelElse = this->getLabel();
6744 LabelTy LabelEnd = this->getLabel();
6745 if (!this->jumpFalse(LabelElse, IS))
6747 if (!visitChildStmt(IS->
getThen()))
6749 if (!this->jump(LabelEnd, IS))
6751 this->emitLabel(LabelElse);
6752 if (!visitChildStmt(Else))
6754 this->emitLabel(LabelEnd);
6756 LabelTy LabelEnd = this->getLabel();
6757 if (!this->jumpFalse(LabelEnd, IS))
6759 if (!visitChildStmt(IS->
getThen()))
6761 this->emitLabel(LabelEnd);
6770template <
class Emitter>
6775 LabelTy CondLabel = this->getLabel();
6776 LabelTy EndLabel = this->getLabel();
6780 this->fallthrough(CondLabel);
6781 this->emitLabel(CondLabel);
6797 if (!this->jumpFalse(EndLabel, S))
6807 if (!this->jump(CondLabel, S))
6809 this->fallthrough(EndLabel);
6810 this->emitLabel(EndLabel);
6819 LabelTy StartLabel = this->getLabel();
6820 LabelTy EndLabel = this->getLabel();
6821 LabelTy CondLabel = this->getLabel();
6825 this->fallthrough(StartLabel);
6826 this->emitLabel(StartLabel);
6832 this->fallthrough(CondLabel);
6833 this->emitLabel(CondLabel);
6840 if (!this->jumpTrue(StartLabel, S))
6843 this->fallthrough(EndLabel);
6844 this->emitLabel(EndLabel);
6848template <
class Emitter>
6856 LabelTy EndLabel = this->getLabel();
6857 LabelTy CondLabel = this->getLabel();
6858 LabelTy IncLabel = this->getLabel();
6865 this->fallthrough(CondLabel);
6866 this->emitLabel(CondLabel);
6878 if (!this->jumpFalse(EndLabel, S))
6887 this->fallthrough(IncLabel);
6888 this->emitLabel(IncLabel);
6894 if (!this->jump(CondLabel, S))
6898 this->emitLabel(EndLabel);
6904template <
class Emitter>
6914 LabelTy EndLabel = this->getLabel();
6915 LabelTy CondLabel = this->getLabel();
6916 LabelTy IncLabel = this->getLabel();
6931 this->fallthrough(CondLabel);
6932 this->emitLabel(CondLabel);
6935 if (!this->jumpFalse(EndLabel, S))
6946 this->fallthrough(IncLabel);
6947 this->emitLabel(IncLabel);
6952 if (!this->jump(CondLabel, S))
6955 this->fallthrough(EndLabel);
6956 this->emitLabel(EndLabel);
6960template <
class Emitter>
6971 if (LI.BreakLabel) {
6972 TargetLabel = *LI.BreakLabel;
6973 BreakScope = LI.BreakOrContinueScope;
6979 if (LI.Name == TargetLoop) {
6980 TargetLabel = *LI.BreakLabel;
6981 BreakScope = LI.BreakOrContinueScope;
6992 C =
C->getParent()) {
6993 if (!
C->destroyLocals())
6997 return this->jump(*TargetLabel, S);
7000template <
class Emitter>
7011 if (LI.ContinueLabel) {
7012 TargetLabel = *LI.ContinueLabel;
7013 ContinueScope = LI.BreakOrContinueScope;
7019 if (LI.Name == TargetLoop) {
7020 TargetLabel = *LI.ContinueLabel;
7021 ContinueScope = LI.BreakOrContinueScope;
7026 assert(TargetLabel);
7029 C =
C->getParent()) {
7030 if (!
C->destroyLocals())
7034 return this->jump(*TargetLabel, S);
7037template <
class Emitter>
7040 if (
Cond->containsErrors())
7047 LabelTy EndLabel = this->getLabel();
7052 if (
const auto *CondInit = S->
getInit())
7063 if (!this->emitSetLocal(CondT, CondVar, S))
7073 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7076 if (CS->caseStmtIsGNURange()) {
7077 LabelTy EndOfRangeCheck = this->getLabel();
7078 const Expr *Low = CS->getLHS();
7079 const Expr *High = CS->getRHS();
7083 if (!this->emitGetLocal(CondT, CondVar, CS))
7085 if (!this->
visit(Low))
7088 if (!this->emitGE(
LT, S))
7090 if (!this->jumpFalse(EndOfRangeCheck, S))
7093 if (!this->emitGetLocal(CondT, CondVar, CS))
7095 if (!this->
visit(High))
7098 if (!this->emitLE(HT, S))
7102 this->emitLabel(EndOfRangeCheck);
7107 if (
Value->isValueDependent())
7112 if (!this->emitGetLocal(CondT, CondVar, CS))
7118 if (!this->emitEQ(ValueT, S))
7123 assert(!DefaultLabel);
7124 DefaultLabel = this->getLabel();
7131 if (!this->jump(*DefaultLabel, S))
7134 if (!this->jump(EndLabel, S))
7142 this->fallthrough(EndLabel);
7143 this->emitLabel(EndLabel);
7148template <
class Emitter>
7156 return this->emitUnsupported(S);
7161template <
class Emitter>
7168 if (LI.DefaultLabel) {
7169 DefaultLabel = *LI.DefaultLabel;
7174 this->emitLabel(DefaultLabel);
7178template <
class Emitter>
7185 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7188 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7189 !this->Ctx.getLangOpts().MSVCCompat) {
7191 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7197 const Expr *Assumption = AA->getAssumption();
7208 if (!this->emitAssume(Assumption))
7217 if (IsMSVCConstexprAttr)
7218 return this->emitPopMSVCCE(S);
7222template <
class Emitter>
7235template <
class Emitter>
7245 LabelTy EndLabel = this->getLabel();
7247 LabelTy ContinueLabel = this->getLabel();
7252 this->emitLabel(ContinueLabel);
7255 this->emitLabel(EndLabel);
7260template <
class Emitter>
7261bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7268 assert(ClosureClass->
captures().empty());
7272 "A generic lambda's static-invoker function must be a "
7273 "template specialization");
7277 void *InsertPos =
nullptr;
7278 const FunctionDecl *CorrespondingCallOpSpecialization =
7280 assert(CorrespondingCallOpSpecialization);
7281 LambdaCallOp = CorrespondingCallOpSpecialization;
7285 assert(ClosureClass->
captures().empty());
7286 const Function *
Func = this->getFunction(LambdaCallOp);
7289 assert(
Func->hasThisPointer());
7292 if (
Func->hasRVO()) {
7293 if (!this->emitRVOPtr(MD))
7301 if (!this->emitNullPtr(0,
nullptr, MD))
7306 auto It = this->Params.find(PVD);
7307 assert(It != this->Params.end());
7311 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7312 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7316 if (!this->emitCall(
Func, 0, LambdaCallOp))
7321 return this->emitRet(*ReturnType, MD);
7324 return this->emitRetVoid(MD);
7327template <
class Emitter>
7328bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7329 if (Ctx.getLangOpts().CPlusPlus23)
7339 const Expr *InitExpr =
Init->getInit();
7341 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7345 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7355template <
class Emitter>
7357 assert(!ReturnType);
7360 if (!this->emitStartThisLifetime1(Ctor))
7363 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7364 const Expr *InitExpr,
7367 if (InitExpr->getType().isNull())
7371 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7374 if (!this->visit(InitExpr))
7377 if (F->isBitField())
7378 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7380 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7385 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7388 if (
Activate && !this->emitActivate(InitExpr))
7391 return this->visitInitializerPop(InitExpr);
7395 const Record *
R = this->getRecord(RD);
7398 bool IsUnion =
R->isUnion();
7408 if (!this->emitThis(Ctor))
7411 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7414 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7415 this->emitRetVoid(Ctor);
7418 unsigned FieldInits = 0;
7421 if (
R->getNumVirtualBases() > 0) {
7422 if (!this->emitThis(Ctor))
7424 LabelTy AfterVirtBasesLabel = this->getLabel();
7427 if (!this->emitIsBaseClass({}))
7429 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7432 for (
const auto *
Init : Ctor->
inits()) {
7435 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7437 assert(
R->getVirtualBase(BaseDecl));
7438 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7440 if (!this->visitInitializerPop(
Init->getInit()))
7445 this->fallthrough(AfterVirtBasesLabel);
7446 this->emitLabel(AfterVirtBasesLabel);
7448 if (!this->emitPopPtr(Ctor))
7452 for (
const auto *
Init : Ctor->
inits()) {
7456 const Expr *InitExpr =
Init->getInit();
7458 const Record::Field *F =
R->getField(
Member);
7462 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7466 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7469 if (
Init->isBaseVirtual()) {
7475 const Record::Base *B =
R->getBase(BaseDecl);
7477 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7481 if (!this->visitInitializerPop(InitExpr))
7486 unsigned ChainSize = IFD->getChainingSize();
7487 assert(ChainSize >= 2);
7489 unsigned NestedFieldOffset = 0;
7490 const Record::Field *NestedField =
nullptr;
7491 for (
unsigned I = 0; I != ChainSize; ++I) {
7493 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7494 assert(FieldRecord);
7496 NestedField = FieldRecord->
getField(FD);
7497 assert(NestedField);
7498 IsUnion = IsUnion || FieldRecord->
isUnion();
7500 NestedFieldOffset += NestedField->Offset;
7503 if (I != ChainSize - 1)
7506 assert(NestedField);
7509 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7514 unsigned InitFieldOffset = 0;
7515 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7517 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7518 assert(FieldRecord);
7519 NestedField = FieldRecord->
getField(FD);
7520 InitFieldOffset += NestedField->Offset;
7521 assert(NestedField);
7522 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7524 if (!this->emitFinishInitPop(InitExpr))
7528 InitStack.pop_back_n(ChainSize - 1);
7531 assert(
Init->isDelegatingInitializer());
7532 if (!this->emitThis(InitExpr))
7534 if (!this->visitInitializerPop(
Init->getInit()))
7538 if (!
Scope.destroyLocals())
7542 if (FieldInits !=
R->getNumFields()) {
7543 assert(FieldInits < R->getNumFields());
7545 if (!this->emitStartThisLifetime(Ctor))
7552 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7553 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7560 if (!visitStmt(Body))
7567template <
class Emitter>
7570 const Record *
R = this->getRecord(RD);
7574 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7575 if (!this->visitStmt(
Dtor->getBody()))
7579 if (!this->emitThis(
Dtor))
7582 if (!this->emitCheckDestruction(
Dtor))
7586 if (!
R->isUnion()) {
7590 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7594 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7596 if (!this->emitDestructionPop(D,
SourceInfo{}))
7601 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7602 if (
Base.R->hasTrivialDtor())
7606 if (!this->emitRecordDestructionPop(
Base.R, {}))
7610 if (
R->getNumVirtualBases() > 0) {
7611 LabelTy EndLabel = this->getLabel();
7613 if (!this->emitIsBaseClass({}))
7615 if (!this->jumpTrue(EndLabel, {}))
7618 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7619 if (
Base.R->hasTrivialDtor())
7624 if (!this->emitRecordDestructionPop(
Base.R, {}))
7628 this->fallthrough(EndLabel);
7629 this->emitLabel(EndLabel);
7632 if (!this->emitMarkDestroyed(
Dtor))
7635 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7638template <
class Emitter>
7639bool Compiler<Emitter>::compileUnionAssignmentOperator(
7641 if (!this->emitThis(MD))
7644 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7647 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7650template <
class Emitter>
7660 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7661 return this->compileConstructor(Ctor);
7662 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7663 return this->compileDestructor(
Dtor);
7666 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7671 return this->compileUnionAssignmentOperator(MD);
7674 return this->emitLambdaStaticInvokerBody(MD);
7678 if (
const auto *Body = F->
getBody())
7692 return FD->getBitWidthValue();
7695template <
class Emitter>
7711 if (!
Ctx.getLangOpts().CPlusPlus14)
7712 return this->emitInvalid(E);
7714 return this->emitError(E);
7716 if (!this->
visit(SubExpr))
7720 if (!this->emitIncPtr(E))
7727 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7728 : this->emitIncf(getFPOptions(E), E);
7740 if (!
Ctx.getLangOpts().CPlusPlus14)
7741 return this->emitInvalid(E);
7743 return this->emitError(E);
7745 if (!this->
visit(SubExpr))
7749 if (!this->emitDecPtr(E))
7756 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7757 : this->emitDecf(getFPOptions(E), E);
7770 if (!
Ctx.getLangOpts().CPlusPlus14)
7771 return this->emitInvalid(E);
7773 return this->emitError(E);
7775 if (!this->
visit(SubExpr))
7779 if (!this->emitLoadPtr(E))
7781 if (!this->emitConstUint8(1, E))
7783 if (!this->emitAddOffsetUint8(E))
7785 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7791 return this->emitIncfPop(getFPOptions(E), E);
7801 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7802 if (!this->emitLoadFloat(E))
7804 APFloat F(TargetSemantics, 1);
7805 if (!this->emitFloat(F, E))
7808 if (!this->emitAddf(getFPOptions(E), E))
7810 if (!this->emitStoreFloat(E))
7822 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7825 if (!
Ctx.getLangOpts().CPlusPlus14)
7826 return this->emitInvalid(E);
7828 return this->emitError(E);
7830 if (!this->
visit(SubExpr))
7834 if (!this->emitLoadPtr(E))
7836 if (!this->emitConstUint8(1, E))
7838 if (!this->emitSubOffsetUint8(E))
7840 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7846 return this->emitDecfPop(getFPOptions(E), E);
7856 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7857 if (!this->emitLoadFloat(E))
7859 APFloat F(TargetSemantics, 1);
7860 if (!this->emitFloat(F, E))
7863 if (!this->emitSubf(getFPOptions(E), E))
7865 if (!this->emitStoreFloat(E))
7877 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7881 return this->emitError(E);
7884 return this->
discard(SubExpr);
7889 if (!this->emitInv(E))
7893 return this->emitCast(
PT_Bool, ET, E);
7897 return this->emitError(E);
7899 if (!this->
visit(SubExpr))
7904 return this->emitError(E);
7906 if (!this->
visit(SubExpr))
7922 if (!
Ctx.getLangOpts().CPlusPlus) {
7924 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7925 Deref && Deref->getOpcode() == UO_Deref)
7926 return this->
delegate(Deref->getSubExpr());
7932 return this->
discard(SubExpr);
7934 if (!this->
visit(SubExpr))
7941 return this->emitNarrowPtr(E);
7946 return this->emitError(E);
7948 if (!this->
visit(SubExpr))
7962 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
7967 assert(
false &&
"Unhandled opcode");
7973template <
class Emitter>
7979 return this->
discard(SubExpr);
7982 auto prepareResult = [=]() ->
bool {
7987 return this->emitGetPtrLocal(*LocalIndex, E);
7994 unsigned SubExprOffset = ~0u;
7995 auto createTemp = [=, &SubExprOffset]() ->
bool {
7998 if (!this->
visit(SubExpr))
8000 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8004 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8005 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8007 return this->emitArrayElemPop(ElemT, Index, E);
8012 if (!prepareResult())
8016 for (
unsigned I = 0; I != 2; ++I) {
8017 if (!getElem(SubExprOffset, I))
8019 if (!this->emitNeg(ElemT, E))
8021 if (!this->emitInitElem(ElemT, I, E))
8032 if (!this->
visit(SubExpr))
8034 if (!this->emitComplexBoolCast(SubExpr))
8036 if (!this->emitInv(E))
8039 return this->emitCast(
PT_Bool, ET, E);
8043 return this->emitComplexReal(SubExpr);
8046 if (!this->
visit(SubExpr))
8050 if (!this->emitConstUint8(1, E))
8052 return this->emitArrayElemPtrPopUint8(E);
8063 if (!this->emitArrayElem(ElemT, 1, E))
8065 if (!this->emitNeg(ElemT, E))
8067 if (!this->emitInitElem(ElemT, 1, E))
8075 return this->emitInvalid(E);
8081template <
class Emitter>
8087 return this->
discard(SubExpr);
8090 if (UnaryOp == UO_Extension)
8093 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8094 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8095 return this->emitInvalid(E);
8098 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8105 if (!this->emitGetPtrLocal(*LocalIndex, E))
8110 unsigned SubExprOffset =
8112 if (!this->
visit(SubExpr))
8114 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8119 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8120 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8122 return this->emitArrayElemPop(ElemT, Index, E);
8127 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8128 if (!getElem(SubExprOffset, I))
8130 if (!this->emitNeg(ElemT, E))
8132 if (!this->emitInitElem(ElemT, I, E))
8147 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8148 if (!getElem(SubExprOffset, I))
8151 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8153 if (!this->emitInv(E))
8155 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8157 if (!this->emitNeg(ElemT, E))
8159 if (ElemT != ResultVecElemT &&
8160 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8162 if (!this->emitInitElem(ResultVecElemT, I, E))
8168 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8169 if (!getElem(SubExprOffset, I))
8172 if (!this->emitInv(E))
8175 if (!this->emitComp(ElemT, E))
8178 if (!this->emitInitElem(ElemT, I, E))
8183 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8188template <
class Emitter>
8190 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8193 return this->emitConst(ECD->getInitVal(), E);
8195 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8199 return F && this->emitGetFnPtr(F, E);
8201 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8202 TPOD = TPOD->getFirstDecl();
8206 return this->emitGetPtrGlobal(*GlobalIndex, E);
8212 return this->emitInitGlobal(*
T, *Index, E);
8215 if (!this->emitGetPtrGlobal(*Index, E))
8219 return this->emitFinishInit(E);
8231 auto maybePopPtr = [&]() ->
bool {
8233 return this->emitPopPtr(E);
8240 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8244 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8249 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8250 if (IsReference || !It->second.IsPtr)
8251 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8253 return this->emitGetPtrParam(It->second.Index, E);
8256 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8263 const unsigned Offset = It->second.Offset;
8266 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8268 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8271 if (
auto GlobalIndex =
P.getGlobal(D)) {
8273 if (!
Ctx.getLangOpts().CPlusPlus11)
8274 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8275 if (!
Ctx.getLangOpts().CPlusPlus23)
8276 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8278 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8281 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8285 auto revisit = [&](
const VarDecl *VD,
8286 bool IsConstexprUnknown =
true) ->
bool {
8288 IsConstexprUnknown);
8289 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8295 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8296 if (!this->emitPopCC(E))
8300 if (VarState.notCreated())
8308 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8310 if (
auto It = this->LambdaCaptures.find(D);
8311 It != this->LambdaCaptures.end()) {
8312 auto [Offset, IsPtr] = It->second;
8315 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8316 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8320 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8321 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8322 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8326 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8327 return this->
delegate(BD->getBinding());
8333 return this->emitDummyPtr(D, E);
8338 const auto *VD = dyn_cast<VarDecl>(D);
8340 return this->emitError(E);
8343 if (!
Ctx.getLangOpts().CPlusPlus) {
8347 return revisit(VD,
false);
8351 return this->emitDummyPtr(D, E);
8355 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8356 if (
T.isConstant(
Ctx.getASTContext()))
8358 return T->isReferenceType();
8362 typeShouldBeVisited(DeclType)) {
8364 Init && !
Init->isValueDependent()) {
8369 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8382 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8387 return revisit(VD, IsConstexprUnknown);
8388 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8389 return revisit(VD,
true);
8398 return this->emitDummyPtr(
8402template <
class Emitter>
8408template <
class Emitter>
8418 if (!
C->destroyLocals())
8424template <
class Emitter>
8425unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8428 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8430 return Ty->getAsCXXRecordDecl();
8432 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8433 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8435 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8439template <
class Emitter>
8446 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8451 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8452 getFPOptions(E), E);
8454 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8455 getFPOptions(E), E);
8459 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8464 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8466 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8470 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8474 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8475 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8482template <
class Emitter>
8485 assert(FromT != ToT);
8488 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8490 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8492 return this->emitCast(FromT, ToT, E);
8496template <
class Emitter>
8497bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8501 return this->
discard(SubExpr);
8503 if (!this->visit(SubExpr))
8506 if (!this->emitConstUint8(0, SubExpr))
8508 return this->emitArrayElemPtrPopUint8(SubExpr);
8512 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8516template <
class Emitter>
8517bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8518 assert(!DiscardResult);
8522 if (!this->emitArrayElem(ElemT, 0, E))
8525 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8528 if (!this->emitCast(ElemT,
PT_Bool, E))
8533 LabelTy LabelTrue = this->getLabel();
8534 if (!this->jumpTrue(LabelTrue, E))
8537 if (!this->emitArrayElemPop(ElemT, 1, E))
8540 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8543 if (!this->emitCast(ElemT,
PT_Bool, E))
8547 LabelTy EndLabel = this->getLabel();
8548 this->jump(EndLabel, E);
8550 this->emitLabel(LabelTrue);
8551 if (!this->emitPopPtr(E))
8553 if (!this->emitConstBool(
true, E))
8556 this->fallthrough(EndLabel);
8557 this->emitLabel(EndLabel);
8562template <
class Emitter>
8563bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8574 LHSIsComplex =
true;
8575 ElemT = classifyComplexElementType(LHS->
getType());
8576 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8577 if (!this->visit(LHS))
8579 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8582 LHSIsComplex =
false;
8584 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8585 if (!this->visit(LHS))
8587 if (!this->emitSetLocal(LHST, LHSOffset, E))
8594 RHSIsComplex =
true;
8595 ElemT = classifyComplexElementType(RHS->
getType());
8596 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8597 if (!this->visit(RHS))
8599 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8602 RHSIsComplex =
false;
8604 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8605 if (!this->visit(RHS))
8607 if (!this->emitSetLocal(RHST, RHSOffset, E))
8611 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8612 bool IsComplex) ->
bool {
8614 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8616 return this->emitArrayElemPop(ElemT, Index, E);
8618 return this->emitGetLocal(ElemT, LocalOffset, E);
8621 for (
unsigned I = 0; I != 2; ++I) {
8623 if (!getElem(LHSOffset, I, LHSIsComplex))
8625 if (!getElem(RHSOffset, I, RHSIsComplex))
8628 if (!this->emitEQ(ElemT, E))
8631 if (!this->emitCastBoolUint8(E))
8636 if (!this->emitAddUint8(E))
8638 if (!this->emitConstUint8(2, E))
8642 if (!this->emitEQUint8(E))
8645 if (!this->emitNEUint8(E))
8652 return this->emitCast(
PT_Bool, ResT, E);
8659template <
class Emitter>
8660bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8663 assert(!
R->hasTrivialDtor());
8666 const Function *DtorFunc = getFunction(
Dtor);
8669 assert(DtorFunc->hasThisPointer());
8670 assert(DtorFunc->getNumParams() == 1);
8671 return this->emitCall(DtorFunc, 0, Loc);
8676template <
class Emitter>
8677bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8689 return this->emitPopPtr(Loc);
8691 for (ssize_t I = N - 1; I >= 1; --I) {
8692 if (!this->emitConstUint64(I, Loc))
8694 if (!this->emitArrayElemPtrUint64(Loc))
8696 if (!this->emitDestructionPop(ElemDesc, Loc))
8700 if (!this->emitConstUint64(0, Loc))
8702 if (!this->emitArrayElemPtrPopUint64(Loc))
8704 return this->emitDestructionPop(ElemDesc, Loc);
8709 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8714template <
class Emitter>
8715bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8716 assert(!DiscardResult &&
"Should've been checked before");
8717 unsigned DummyID = P.getOrCreateDummy(D, CU);
8719 if (!this->emitGetPtrGlobal(DummyID, E))
8727 return this->emitDecayPtr(
PT_Ptr, PT, E);
8733template <
class Emitter>
8736 return this->emitConstFloat(
Floating(F), Info);
8738 APInt I = F.bitcastToAPInt();
8739 return this->emitConstFloat(
8740 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8741 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8752template <
class Emitter>
8753bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8766 if (!this->emitGetPtrLocal(*LocalIndex, E))
8776 if (!this->visit(SubExpr))
8778 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8779 unsigned TempOffset =
8780 allocateLocalPrimitive(SubExpr, *FromT,
true);
8781 if (!this->visit(SubExpr))
8783 if (!this->emitSetLocal(*FromT, TempOffset, E))
8785 if (!this->emitGetPtrLocal(TempOffset, E))
8792 if (!this->emitBitCast(E))
8794 return DiscardResult ? this->emitPopPtr(E) :
true;
8798 const llvm::fltSemantics *TargetSemantics =
nullptr;
8800 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8806 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8808 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8809 ResultBitWidth, TargetSemantics,
8814 return this->emitPop(*ToT, E);
8823template <
class Emitter>
8824bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8829 unsigned NumElems = 0;
8832 NumElems = VT->getNumElements();
8833 ElemType = VT->getElementType();
8835 NumElems = MT->getNumElementsFlattened();
8836 ElemType = MT->getElementType();
8839 PrimType ElemT = classifyPrim(ElemType);
8840 for (
unsigned I = 0; I != NumElems; ++I) {
8841 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8843 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8845 if (!this->emitInitElem(ElemT, I, E))
8855 QualType ArrElemType = CAT->getElementType();
8856 unsigned ArrSize = CAT->getZExtSize();
8859 for (
unsigned I = 0; I != ArrSize; ++I) {
8860 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8862 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8864 if (!this->emitInitElem(*ElemT, I, E))
8868 for (
unsigned I = 0; I != ArrSize; ++I) {
8869 if (!this->emitConstUint32(I, E))
8871 if (!this->emitArrayElemPtrUint32(E))
8873 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8875 if (!this->emitFinishInitPop(E))
8885 const Record *
R = getRecord(DestType);
8889 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8891 const Record::Base *B =
R->getBase(BS.getType());
8893 if (!this->emitGetPtrBase(B->Offset, E))
8895 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8897 if (!this->emitFinishInitPop(E))
8902 for (
const Record::Field &F :
R->fields()) {
8903 if (F.isUnnamedBitField())
8906 QualType FieldType = F.Decl->getType();
8908 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8910 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8912 if (F.isBitField()) {
8913 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8916 if (!this->emitInitField(*FieldT, F.Offset, E))
8920 if (!this->emitGetPtrField(F.Offset, E))
8922 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8924 if (!this->emitPopPtr(E))
8937template <
class Emitter>
8938unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8941 return VT->getNumElements();
8943 return MT->getNumElementsFlattened();
8947 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8951 const Record *
R = getRecord(Ty);
8955 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8957 Count += countHLSLFlatElements(BS.getType());
8959 for (
const Record::Field &F :
R->fields()) {
8960 if (F.isUnnamedBitField())
8962 Count += countHLSLFlatElements(F.Decl->getType());
8967 if (canClassify(Ty))
8976template <
class Emitter>
8977bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8978 QualType SrcType,
unsigned SrcOffset,
8983 auto saveToLocal = [&](
PrimType T) ->
bool {
8984 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
8985 if (!this->emitSetLocal(
T, Offset, E))
8987 Elements.push_back({Offset,
T});
8993 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8994 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8995 return std::nullopt;
9000 unsigned NumElems = 0;
9003 NumElems = VT->getNumElements();
9004 ElemType = VT->getElementType();
9006 NumElems = MT->getNumElementsFlattened();
9007 ElemType = MT->getElementType();
9010 PrimType ElemT = classifyPrim(ElemType);
9011 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9012 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9014 if (!this->emitArrayElemPop(ElemT, I, E))
9016 if (!saveToLocal(ElemT))
9026 QualType ArrElemType = CAT->getElementType();
9027 unsigned ArrSize = CAT->getZExtSize();
9030 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9031 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9033 if (!this->emitArrayElemPop(*ElemT, I, E))
9035 if (!saveToLocal(*ElemT))
9039 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9040 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9042 if (!this->emitConstUint32(I, E))
9044 if (!this->emitArrayElemPtrPopUint32(E))
9049 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9060 const Record *
R = getRecord(SrcType);
9064 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9066 if (Elements.size() >= MaxElements)
9068 const Record::Base *B =
R->getBase(BS.getType());
9070 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9072 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9077 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9083 for (
const Record::Field &F :
R->fields()) {
9084 if (Elements.size() >= MaxElements)
9086 if (F.isUnnamedBitField())
9089 QualType FieldType = F.Decl->getType();
9090 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9092 if (!this->emitGetPtrFieldPop(F.Offset, E))
9096 if (!this->emitLoadPop(*FieldT, E))
9098 if (!saveToLocal(*FieldT))
9102 if (!FieldPtrOffset)
9104 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9120template <
class Emitter>
9121bool Compiler<Emitter>::emitHLSLConstructAggregate(
9127 const auto &Src = Elements[ElemIdx++];
9128 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9130 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9134 unsigned NumElems = 0;
9137 NumElems = VT->getNumElements();
9138 ElemType = VT->getElementType();
9140 NumElems = MT->getNumElementsFlattened();
9141 ElemType = MT->getElementType();
9144 PrimType DestElemT = classifyPrim(ElemType);
9145 for (
unsigned I = 0; I != NumElems; ++I) {
9146 if (!loadAndCast(DestElemT, ElemType))
9148 if (!this->emitInitElem(DestElemT, I, E))
9158 QualType ArrElemType = CAT->getElementType();
9159 unsigned ArrSize = CAT->getZExtSize();
9162 for (
unsigned I = 0; I != ArrSize; ++I) {
9163 if (!loadAndCast(*ElemT, ArrElemType))
9165 if (!this->emitInitElem(*ElemT, I, E))
9169 for (
unsigned I = 0; I != ArrSize; ++I) {
9170 if (!this->emitConstUint32(I, E))
9172 if (!this->emitArrayElemPtrUint32(E))
9174 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9176 if (!this->emitFinishInitPop(E))
9186 const Record *
R = getRecord(DestType);
9190 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9192 const Record::Base *B =
R->getBase(BS.getType());
9194 if (!this->emitGetPtrBase(B->Offset, E))
9196 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9198 if (!this->emitFinishInitPop(E))
9203 for (
const Record::Field &F :
R->fields()) {
9204 if (F.isUnnamedBitField())
9207 QualType FieldType = F.Decl->getType();
9209 if (!loadAndCast(*FieldT, FieldType))
9211 if (F.isBitField()) {
9212 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9215 if (!this->emitInitField(*FieldT, F.Offset, E))
9219 if (!this->emitGetPtrField(F.Offset, E))
9221 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9223 if (!this->emitPopPtr(E))
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
Result
Implement __builtin_bit_cast and related operations.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
APValue & getArrayFiller()
bool isIndeterminate() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
A rewritten comparison expression that was originally written using operator syntax.
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Represents the this expression in C++.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
CXXTryStmt - A C++ try block, including all handlers.
CompoundStmt * getTryBlock()
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
const FieldDecl * getTargetUnionField() const
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
bool isCompatibleWith(ClangABI Version) const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
uint32_t getCodeUnit(size_t i) const
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
ArrayIndexScope(Compiler< Emitter > *Ctx, uint64_t Index)
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
const VarDecl * InitializingDecl
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
UnsignedOrNone allocateLocal(DeclOrExpr &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
unsigned allocateLocalPrimitive(DeclOrExpr &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const VarDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * getVirtualBase(unsigned I) const
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool This(InterpState &S, CodePtr OpPC)
constexpr bool isIntegerOrBoolType(PrimType T)
bool InitScope(InterpState &S, uint32_t I)
static void discard(InterpStack &Stk, PrimType T)
static bool isSideEffectFree(const Expr *E)
Check if E has side-effects.
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
static bool Activate(InterpState &S)
bool Init(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
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
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
EvalResult is a struct with detailed info about an evaluated expression.
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
static constexpr MetadataSize InlineDescMD
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink 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()