21#include "llvm/Support/SaveAndRestore.h"
32 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
33 CE && CE->hasAPValueResult() &&
35 return CE->getResultAsAPSInt().getBoolValue();
67 llvm_unreachable(
"Shouldn't be called");
133 this->
Ctx->emitDestroy(*
Idx, E);
140 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
141 this->
Ctx->Descriptors.emplace_back();
142 this->
Ctx->emitInitScope(*
Idx, {});
146 this->
Ctx->Descriptors[*
Idx].emplace_back(Local);
156 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
157 this->
Ctx->Descriptors.emplace_back();
158 this->
Ctx->emitInitScope(*
Idx, {});
169 if (Local.Desc->hasTrivialDtor())
172 if (!Local.EnabledByDefault) {
173 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
174 if (!this->
Ctx->emitGetLocalEnabled(Local.Offset, E))
176 if (!this->
Ctx->jumpFalse(EndLabel, E))
179 if (!this->
Ctx->emitGetPtrLocal(Local.Offset, E))
182 if (!this->
Ctx->emitDestructionPop(Local.Desc, Local.Desc->getLoc()))
185 this->
Ctx->fallthrough(EndLabel);
186 this->
Ctx->emitLabel(EndLabel);
188 if (!this->
Ctx->emitGetPtrLocal(Local.Offset, E))
190 if (!this->
Ctx->emitDestructionPop(Local.Desc, Local.Desc->getLoc()))
209 if (
const auto *OVE =
210 llvm::dyn_cast_if_present<OpaqueValueExpr>(Local.Desc->asExpr())) {
211 this->
Ctx->OpaqueExprs.erase(OVE);
223 OldArrayIndex = Ctx->ArrayIndex;
224 Ctx->ArrayIndex = Index;
231 std::optional<uint64_t> OldArrayIndex;
239 if (!Ctx->SourceLocDefaultExpr) {
241 Ctx->SourceLocDefaultExpr = DefaultExpr;
247 Ctx->SourceLocDefaultExpr =
nullptr;
252 bool Enabled =
false;
258 Ctx->InitStack.push_back(std::move(
Link));
270 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
271 Ctx->InitStackActive = Active;
277 this->Ctx->InitStackActive = OldValue;
279 Ctx->InitStack.pop_back();
293 OldInitializingDecl(
Ctx->InitializingDecl) {
294 Ctx->InitializingDecl = VD;
299 this->
Ctx->InitializingDecl = OldInitializingDecl;
300 this->
Ctx->InitStack.pop_back();
305 const VarDecl *OldInitializingDecl;
313 bool NewInitializing,
bool NewToLValue)
314 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
315 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
316 Ctx->DiscardResult = NewDiscardResult;
317 Ctx->Initializing = NewInitializing;
318 Ctx->ToLValue = NewToLValue;
322 Ctx->DiscardResult = OldDiscardResult;
323 Ctx->Initializing = OldInitializing;
324 Ctx->ToLValue = OldToLValue;
331 bool OldDiscardResult;
332 bool OldInitializing;
336template <
class Emitter>
340 return Ctx->emitThis(E);
343 return Ctx->emitGetPtrFieldPop(
Offset, E);
345 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
347 return Ctx->emitGetPtrLocal(
Offset, E);
351 if (!Ctx->emitConstUint32(
Offset, E))
353 return Ctx->emitArrayElemPtrPopUint32(E);
355 return Ctx->emitRVOPtr(E);
359 llvm_unreachable(
"Unhandled InitLink kind");
375 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
376 assert(LI.Name != Name);
379 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
400 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
402 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
403 assert(LI.Name != Name);
406 this->Ctx->CaseLabels = std::move(CaseLabels);
407 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
409 DefaultLabel, Ctx->VarScope);
413 this->Ctx->CaseLabels = std::move(OldCaseLabels);
414 this->Ctx->LabelInfoStack.pop_back();
419 CaseMap OldCaseLabels;
430 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
433 Ctx->LocOverride = NewValue;
438 Ctx->LocOverride = OldFlag;
443 std::optional<SourceInfo> OldFlag;
450template <
class Emitter>
458 case CK_LValueToRValue: {
461 if (!this->
visit(SubExpr))
463 return this->emitLoadPopL(E);
473 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
479 if (
auto GlobalIndex =
P.getGlobal(D))
480 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
481 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
482 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
483 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
484 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
485 return this->emitGetParam(*SubExprT, It->second.Index, E);
497 if (!this->emitGetPtrLocal(*LocalIndex, E))
501 if (!this->
visit(SubExpr))
505 return this->emitLoadPop(*SubExprT, E);
510 return this->emitMemcpy(E);
513 case CK_DerivedToBaseMemberPointer: {
524 ->getMostRecentCXXRecordDecl();
526 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
527 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
529 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
537 case CK_BaseToDerivedMemberPointer: {
548 ->getMostRecentCXXRecordDecl();
552 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
554 PathI != PathE; ++PathI) {
555 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
556 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
558 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
565 assert(ToDecl != CurDecl);
566 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
568 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
574 case CK_UncheckedDerivedToBase:
575 case CK_DerivedToBase: {
580 if (
const auto *PT = dyn_cast<PointerType>(Ty))
581 return PT->getPointeeType()->getAsCXXRecordDecl();
582 return Ty->getAsCXXRecordDecl();
589 if (B->isVirtual()) {
590 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
592 CurType = B->getType();
594 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
595 if (!this->emitGetPtrBasePop(
598 CurType = B->getType();
605 case CK_BaseToDerived: {
608 unsigned DerivedOffset =
614 return this->emitGetPtrDerivedPop(DerivedOffset,
619 case CK_FloatingCast: {
622 return this->emitVectorConversion(E->
getSubExpr(), E);
626 if (!this->
visit(SubExpr))
628 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
632 case CK_IntegralToFloating: {
634 return this->emitVectorConversion(E->
getSubExpr(), E);
637 if (!this->
visit(SubExpr))
639 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
640 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
641 TargetSemantics, getFPOptions(E), E);
644 case CK_FloatingToBoolean: {
646 return this->emitVectorConversion(E->
getSubExpr(), E);
650 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
651 return this->emitConstBool(FL->getValue().isNonZero(), E);
652 if (!this->
visit(SubExpr))
654 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
657 case CK_FloatingToIntegral: {
659 return this->emitVectorConversion(E->
getSubExpr(), E);
662 if (!this->
visit(SubExpr))
666 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
669 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
672 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
675 case CK_NullToPointer:
676 case CK_NullToMemberPointer: {
679 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
684 case CK_PointerToIntegral: {
685 if (!this->
visit(SubExpr))
691 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
697 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
699 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
700 return this->emitCastPointerIntegral(
T, E);
703 case CK_ArrayToPointerDecay: {
704 if (!this->
visit(SubExpr))
706 return this->emitArrayDecay(E);
709 case CK_IntegralToPointer: {
711 assert(IntType->isIntegralOrEnumerationType());
712 if (!this->
visit(SubExpr))
726 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
729 case CK_AtomicToNonAtomic:
730 case CK_ConstructorConversion:
731 case CK_FunctionToPointerDecay:
732 case CK_NonAtomicToAtomic:
734 case CK_UserDefinedConversion:
735 case CK_AddressSpaceConversion:
736 case CK_CPointerToObjCPointerCast:
753 return this->emitBuiltinBitCast(E);
768 if (!this->
visit(SubExpr))
776 return this->emitFnPtrCast(E);
783 if (!this->
visit(SubExpr))
785 return this->emitDecayPtr(*FromT, *ToT, E);
787 case CK_IntegralToBoolean:
788 case CK_FixedPointToBoolean: {
790 return this->emitVectorConversion(E->
getSubExpr(), E);
796 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
797 return this->emitConst(IL->getValue(), E);
798 if (!this->
visit(SubExpr))
803 case CK_IntegralCast:
805 return this->emitVectorConversion(E->
getSubExpr(), E);
807 case CK_BooleanToSignedIntegral: {
814 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
819 if (!this->emitConst(IL->getValue(), SubExpr))
822 if (!this->
visit(SubExpr))
830 if (!ED->isFixed()) {
831 if (!this->emitCheckEnumValue(*FromT, ED, E))
837 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
840 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
845 if (!this->emitCast(*FromT, *ToT, E))
848 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
849 return this->emitNeg(*ToT, E);
853 case CK_PointerToBoolean:
854 case CK_MemberPointerToBoolean: {
857 if (!this->
visit(SubExpr))
859 return this->emitIsNonNull(PtrT, E);
862 case CK_IntegralComplexToBoolean:
863 case CK_FloatingComplexToBoolean: {
864 if (!this->
visit(SubExpr))
866 return this->emitComplexBoolCast(SubExpr);
869 case CK_IntegralComplexToReal:
870 case CK_FloatingComplexToReal:
871 return this->emitComplexReal(SubExpr);
873 case CK_IntegralRealToComplex:
874 case CK_FloatingRealToComplex: {
881 if (!this->emitGetPtrLocal(*LocalIndex, E))
890 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
892 return this->emitInitElem(
T, 1, SubExpr);
895 case CK_IntegralComplexCast:
896 case CK_FloatingComplexCast:
897 case CK_IntegralComplexToFloatingComplex:
898 case CK_FloatingComplexToIntegralComplex: {
905 if (!this->emitGetPtrLocal(*LocalIndex, E))
912 unsigned SubExprOffset =
914 if (!this->
visit(SubExpr))
916 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
924 for (
unsigned I = 0; I != 2; ++I) {
925 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
927 if (!this->emitArrayElemPop(SourceElemT, I, E))
931 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
935 if (!this->emitInitElem(DestElemT, I, E))
941 case CK_VectorSplat: {
952 if (!this->emitGetPtrLocal(*LocalIndex, E))
958 unsigned ElemOffset =
962 if (!this->
visit(SubExpr))
967 if (!this->emitSetLocal(ElemT, ElemOffset, E))
970 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
971 if (!this->emitGetLocal(ElemT, ElemOffset, E))
973 if (!this->emitInitElem(ElemT, I, E))
980 case CK_HLSLVectorTruncation: {
985 if (!this->
visit(SubExpr))
987 return this->emitArrayElemPop(*ResultT, 0, E);
996 if (!this->emitGetPtrLocal(*LocalIndex, E))
1001 if (!this->
visit(SubExpr))
1003 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1007 case CK_IntegralToFixedPoint: {
1008 if (!this->
visit(SubExpr))
1012 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1017 return this->emitPopFixedPoint(E);
1020 case CK_FloatingToFixedPoint: {
1021 if (!this->
visit(SubExpr))
1025 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1026 if (!this->emitCastFloatingFixedPoint(Sem, E))
1029 return this->emitPopFixedPoint(E);
1032 case CK_FixedPointToFloating: {
1033 if (!this->
visit(SubExpr))
1035 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1036 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1039 return this->emitPopFloat(E);
1042 case CK_FixedPointToIntegral: {
1043 if (!this->
visit(SubExpr))
1046 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1049 return this->emitPop(IntegralT, E);
1052 case CK_FixedPointCast: {
1053 if (!this->
visit(SubExpr))
1056 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1057 if (!this->emitCastFixedPoint(Sem, E))
1060 return this->emitPopFixedPoint(E);
1068 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1070 case CK_LValueBitCast:
1075 case CK_HLSLArrayRValue: {
1082 if (!this->emitGetPtrLocal(*LocalIndex, E))
1085 if (!this->
visit(SubExpr))
1087 return this->emitMemcpy(E);
1090 case CK_HLSLMatrixTruncation: {
1095 if (!this->
visit(SubExpr))
1097 return this->emitArrayElemPop(*ResultT, 0, E);
1106 if (!this->emitGetPtrLocal(*LocalIndex, E))
1111 if (!this->
visit(SubExpr))
1113 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1117 case CK_HLSLAggregateSplatCast: {
1127 if (!this->emitGetPtrLocal(*LocalIndex, E))
1134 unsigned SrcOffset =
1137 if (!this->
visit(SubExpr))
1139 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1143 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1146 case CK_HLSLElementwiseCast: {
1157 unsigned SrcPtrOffset =
1159 if (!this->
visit(SubExpr))
1161 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1165 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1167 if (Elements.empty())
1170 const HLSLFlatElement &Src = Elements[0];
1171 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1173 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1180 if (!this->emitGetPtrLocal(*LocalIndex, E))
1184 unsigned SrcOffset =
1186 if (!this->
visit(SubExpr))
1188 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1192 unsigned ElemCount = countHLSLFlatElements(DestType);
1195 Elements.reserve(ElemCount);
1196 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1201 assert(Elements.size() == ElemCount &&
1202 "Source type has fewer scalar elements than the destination type");
1204 return emitHLSLConstructAggregate(DestType, Elements, E);
1211 const Record::Field *RF = R->getField(UnionField);
1212 QualType FieldType = RF->Decl->getType();
1215 if (!this->
visit(SubExpr))
1217 if (RF->isBitField())
1218 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1220 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1223 if (!this->emitGetPtrField(RF->Offset, E))
1225 if (!this->emitActivate(E))
1231 return this->emitInvalid(E);
1233 llvm_unreachable(
"Unhandled clang::CastKind enum");
1236template <
class Emitter>
1238 return this->emitBuiltinBitCast(E);
1241template <
class Emitter>
1246 return this->emitConst(
LE->getValue(),
LE);
1249template <
class Emitter>
1255 return this->emitFloat(F, E);
1258template <
class Emitter>
1268 if (!this->emitGetPtrLocal(*LocalIndex, E))
1275 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1277 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1282template <
class Emitter>
1290 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1295template <
class Emitter>
1300template <
class Emitter>
1327 return this->emitComplexComparison(LHS, RHS, E);
1335 if (!this->
visit(LHS))
1338 if (!this->
visit(RHS))
1341 if (!this->emitToMemberPtr(E))
1347 if (!this->emitCastMemberPtrPtr(E))
1364 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1370 if (!this->emitGetPtrLocal(*ResultIndex, E))
1377 return this->emitCMP3(*
LT, CmpInfo, E);
1380 if (!
LT || !RT || !
T)
1390 return this->visitAssignment(LHS, RHS, E);
1397 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1401 return this->emitPopBool(E);
1403 return this->emitCast(
PT_Bool, *
T, E);
1407 auto Discard = [
this,
T, E](
bool Result) {
1415 return MaybeCastToBool(this->emitEQ(*
LT, E));
1417 return MaybeCastToBool(this->emitNE(*
LT, E));
1419 return MaybeCastToBool(this->emitLT(*
LT, E));
1421 return MaybeCastToBool(this->emitLE(*
LT, E));
1423 return MaybeCastToBool(this->emitGT(*
LT, E));
1425 return MaybeCastToBool(this->emitGE(*
LT, E));
1428 return Discard(this->emitSubf(getFPOptions(E), E));
1429 return Discard(this->emitSub(*
T, E));
1432 return Discard(this->emitAddf(getFPOptions(E), E));
1433 return Discard(this->emitAdd(*
T, E));
1436 return Discard(this->emitMulf(getFPOptions(E), E));
1437 return Discard(this->emitMul(*
T, E));
1439 return Discard(this->emitRem(*
T, E));
1442 return Discard(this->emitDivf(getFPOptions(E), E));
1443 return Discard(this->emitDiv(*
T, E));
1445 return Discard(this->emitBitAnd(*
T, E));
1447 return Discard(this->emitBitOr(*
T, E));
1449 return Discard(this->emitShl(*
LT, *RT, E));
1451 return Discard(this->emitShr(*
LT, *RT, E));
1453 return Discard(this->emitBitXor(*
T, E));
1456 llvm_unreachable(
"Already handled earlier");
1461 llvm_unreachable(
"Unhandled binary op");
1466template <
class Emitter>
1472 if ((Op != BO_Add && Op != BO_Sub) ||
1483 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1484 if (!this->
visit(E))
1487 return this->emitDecayPtr(
T,
PT_Ptr, E);
1496 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1504 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1507 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1514 if (!visitAsPointer(RHS, *RT))
1516 if (!this->
visit(LHS))
1520 if (!visitAsPointer(LHS, *
LT))
1522 if (!this->
visit(RHS))
1533 if (!this->emitAddOffset(OffsetType, E))
1537 if (!this->emitSubOffset(OffsetType, E))
1546 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1551 return this->emitPop(ExprT, E);
1555template <
class Emitter>
1564 LabelTy LabelTrue = this->getLabel();
1565 LabelTy LabelEnd = this->getLabel();
1569 if (!this->jumpTrue(LabelTrue, E))
1574 if (!this->jump(LabelEnd, E))
1577 this->emitLabel(LabelTrue);
1578 this->emitConstBool(
true, E);
1579 this->fallthrough(LabelEnd);
1580 this->emitLabel(LabelEnd);
1583 assert(Op == BO_LAnd);
1586 LabelTy LabelFalse = this->getLabel();
1587 LabelTy LabelEnd = this->getLabel();
1591 if (!this->jumpFalse(LabelFalse, E))
1596 if (!this->jump(LabelEnd, E))
1599 this->emitLabel(LabelFalse);
1600 this->emitConstBool(
false, E);
1601 this->fallthrough(LabelEnd);
1602 this->emitLabel(LabelEnd);
1606 return this->emitPopBool(E);
1611 return this->emitCast(
PT_Bool,
T, E);
1616template <
class Emitter>
1623 if (!this->emitGetPtrLocal(*LocalIndex, E))
1632 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1633 unsigned ResultOffset = ~0u;
1639 if (!this->emitDupPtr(E))
1641 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1646 LHSType = AT->getValueType();
1649 RHSType = AT->getValueType();
1658 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1663 if (!this->
visit(LHS))
1665 if (!this->
visit(RHS))
1667 if (!this->emitMulc(ElemT, E))
1670 return this->emitPopPtr(E);
1674 if (Op == BO_Div && RHSIsComplex) {
1681 if (!LHSIsComplex) {
1686 LHSOffset = *LocalIndex;
1688 if (!this->emitGetPtrLocal(LHSOffset, E))
1691 if (!this->
visit(LHS))
1694 if (!this->emitInitElem(ElemT, 0, E))
1697 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1699 if (!this->emitInitElem(ElemT, 1, E))
1702 if (!this->
visit(LHS))
1706 if (!this->
visit(RHS))
1708 if (!this->emitDivc(ElemT, E))
1711 return this->emitPopPtr(E);
1718 if (!this->
visit(LHS))
1720 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1725 if (!this->
visit(LHS))
1727 if (!this->emitSetLocal(LHST, LHSOffset, E))
1735 if (!this->
visit(RHS))
1737 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1742 if (!this->
visit(RHS))
1744 if (!this->emitSetLocal(RHST, RHSOffset, E))
1751 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1752 unsigned ElemIndex,
unsigned Offset,
1753 const Expr *E) ->
bool {
1755 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1757 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1760 if (ElemIndex == 0 || !LoadZero)
1767 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1770 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1777 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1780 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1783 if (!this->emitAddf(getFPOptions(E), E))
1786 if (!this->emitAdd(ResultElemT, E))
1791 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1794 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1797 if (!this->emitSubf(getFPOptions(E), E))
1800 if (!this->emitSub(ResultElemT, E))
1805 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1808 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1812 if (!this->emitMulf(getFPOptions(E), E))
1815 if (!this->emitMul(ResultElemT, E))
1820 assert(!RHSIsComplex);
1821 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1824 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1828 if (!this->emitDivf(getFPOptions(E), E))
1831 if (!this->emitDiv(ResultElemT, E))
1842 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1845 if (!this->emitPop(ResultElemT, E))
1850 return this->emitPopPtr(E);
1856template <
class Emitter>
1861 "Comma op should be handled in VisitBinaryOperator");
1875 if (!this->emitGetPtrLocal(*LocalIndex, E))
1889 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1892 if (!this->
visit(LHS))
1894 if (!this->
visit(RHS))
1896 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1899 return this->emitPopPtr(E);
1904 unsigned LHSOffset =
1906 if (!this->
visit(LHS))
1908 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1912 unsigned RHSOffset =
1914 if (!this->
visit(RHS))
1916 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1928 if (NeedIntPromot) {
1930 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1935 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1936 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1938 if (!this->emitArrayElemPop(ElemT, Index, E))
1941 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1943 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1945 }
else if (NeedIntPromot) {
1946 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1952#define EMIT_ARITH_OP(OP) \
1954 if (ElemT == PT_Float) { \
1955 if (!this->emit##OP##f(getFPOptions(E), E)) \
1958 if (!this->emit##OP(ElemT, E)) \
1964 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1965 if (!getElem(LHSOffset, ElemT, I))
1967 if (!getElem(RHSOffset, RHSElemT, I))
1979 if (!this->emitRem(ElemT, E))
1983 if (!this->emitBitAnd(OpT, E))
1987 if (!this->emitBitOr(OpT, E))
1991 if (!this->emitBitXor(OpT, E))
1995 if (!this->emitShl(OpT, RHSElemT, E))
1999 if (!this->emitShr(OpT, RHSElemT, E))
2003 if (!this->emitEQ(ElemT, E))
2007 if (!this->emitNE(ElemT, E))
2011 if (!this->emitLE(ElemT, E))
2015 if (!this->emitLT(ElemT, E))
2019 if (!this->emitGE(ElemT, E))
2023 if (!this->emitGT(ElemT, E))
2028 if (!this->emitBitAnd(ResultElemT, E))
2033 if (!this->emitBitOr(ResultElemT, E))
2037 return this->emitInvalid(E);
2046 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2048 if (!this->emitNeg(ResultElemT, E))
2054 if (NeedIntPromot &&
2055 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2059 if (!this->emitInitElem(ResultElemT, I, E))
2068template <
class Emitter>
2078 auto LHSSemaInt = LHSSema.toOpaqueInt();
2080 auto RHSSemaInt = RHSSema.toOpaqueInt();
2082 if (!this->
visit(LHS))
2090 if (!this->
visit(RHS))
2099 auto ConvertResult = [&](
bool R) ->
bool {
2103 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2104 if (ResultSema != CommonSema)
2105 return this->emitCastFixedPoint(ResultSema, E);
2109 auto MaybeCastToBool = [&](
bool Result) {
2114 return this->emitPop(
T, E);
2116 return this->emitCast(
PT_Bool,
T, E);
2122 return MaybeCastToBool(this->emitEQFixedPoint(E));
2124 return MaybeCastToBool(this->emitNEFixedPoint(E));
2126 return MaybeCastToBool(this->emitLTFixedPoint(E));
2128 return MaybeCastToBool(this->emitLEFixedPoint(E));
2130 return MaybeCastToBool(this->emitGTFixedPoint(E));
2132 return MaybeCastToBool(this->emitGEFixedPoint(E));
2134 return ConvertResult(this->emitAddFixedPoint(E));
2136 return ConvertResult(this->emitSubFixedPoint(E));
2138 return ConvertResult(this->emitMulFixedPoint(E));
2140 return ConvertResult(this->emitDivFixedPoint(E));
2142 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2144 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2147 return this->emitInvalid(E);
2150 llvm_unreachable(
"unhandled binop opcode");
2153template <
class Emitter>
2162 if (!this->
visit(SubExpr))
2164 if (!this->emitNegFixedPoint(E))
2167 return this->emitPopFixedPoint(E);
2173 llvm_unreachable(
"Unhandled unary opcode");
2176template <
class Emitter>
2185 return this->visitZeroInitializer(*
T, QT, E);
2198 return this->visitZeroRecordInitializer(R, E);
2205 return this->visitZeroArrayInitializer(QT, E);
2209 QualType ElemQT = ComplexTy->getElementType();
2211 for (
unsigned I = 0; I < 2; ++I) {
2212 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2214 if (!this->emitInitElem(ElemT, I, E))
2221 unsigned NumVecElements = VecT->getNumElements();
2222 QualType ElemQT = VecT->getElementType();
2225 for (
unsigned I = 0; I < NumVecElements; ++I) {
2226 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2228 if (!this->emitInitElem(ElemT, I, E))
2235 unsigned NumElems = MT->getNumElementsFlattened();
2236 QualType ElemQT = MT->getElementType();
2239 for (
unsigned I = 0; I != NumElems; ++I) {
2240 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2242 if (!this->emitInitElem(ElemT, I, E))
2251template <
class Emitter>
2264 for (
const Expr *SubExpr : {LHS, RHS}) {
2265 if (!this->
visit(SubExpr)) {
2272 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2273 if (!this->emitExpandPtr(E))
2284 return this->emitError(E);
2287 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2291 if (!this->emitArrayElemPtrPop(*IndexT, E))
2294 return this->emitPopPtr(E);
2300 return this->emitLoadPop(*
T, E);
2303template <
class Emitter>
2305 const Expr *ArrayFiller,
const Expr *E) {
2310 QT = AT->getValueType();
2313 if (
Inits.size() == 0)
2315 return this->emitInvalid(E);
2330 if (
Inits.size() == 0)
2331 return this->visitZeroInitializer(*
T, QT, E);
2332 assert(
Inits.size() == 1);
2345 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2352 bool BitField = FieldToInit->isBitField();
2354 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2355 FieldToInit->bitWidth(), E);
2357 return this->emitInitBitField(
T, FieldToInit->Offset,
2358 FieldToInit->bitWidth(), E);
2360 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2361 return this->emitInitField(
T, FieldToInit->Offset, E);
2364 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2372 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2375 if (
Activate && !this->emitActivate(E))
2382 if (
Inits.size() == 0) {
2383 if (!this->visitZeroRecordInitializer(R, E))
2388 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2389 FToInit = ILE->getInitializedFieldInUnion();
2393 const Record::Field *FieldToInit = R->getField(FToInit);
2395 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2398 if (!initCompositeField(FieldToInit,
Init,
true))
2402 return this->emitFinishInit(E);
2405 assert(!R->isUnion());
2406 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2408 const Record::Base *B = R->getBase(BI);
2411 if (!this->emitGetPtrBase(B->Offset,
Init))
2417 unsigned FieldIndex = 0;
2418 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2419 const Record::Field *FieldToInit = R->getField(FieldIndex);
2420 if (FieldToInit->isUnnamedBitField()) {
2435 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2437 }
else if (!initCompositeField(FieldToInit,
Init)) {
2445 assert(R->getNumVirtualBases() == 0);
2447 return this->emitFinishInit(E);
2452 Ctx.getASTContext().getAsConstantArrayType(QT);
2457 !this->emitCheckArrayDestSize(NumElems, E))
2460 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2464 unsigned ElementIndex = 0;
2466 if (
const auto *EmbedS =
2467 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2475 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2476 getFPOptions(E), E))
2482 return this->emitInitElem(TargetT, ElemIndex, IL);
2484 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2500 for (; ElementIndex != NumElems; ++ElementIndex) {
2506 return this->emitFinishInit(E);
2510 unsigned NumInits =
Inits.size();
2515 QualType ElemQT = ComplexTy->getElementType();
2517 if (NumInits == 0) {
2519 for (
unsigned I = 0; I < 2; ++I) {
2520 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2522 if (!this->emitInitElem(ElemT, I, E))
2525 }
else if (NumInits == 2) {
2526 unsigned InitIndex = 0;
2531 if (!this->emitInitElem(ElemT, InitIndex, E))
2540 unsigned NumVecElements = VecT->getNumElements();
2541 assert(NumVecElements >=
Inits.size());
2543 QualType ElemQT = VecT->getElementType();
2547 unsigned InitIndex = 0;
2554 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2555 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2556 InitVecT->getNumElements(), E))
2558 InitIndex += InitVecT->getNumElements();
2560 if (!this->emitInitElem(ElemT, InitIndex, E))
2566 assert(InitIndex <= NumVecElements);
2569 for (; InitIndex != NumVecElements; ++InitIndex) {
2570 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2572 if (!this->emitInitElem(ElemT, InitIndex, E))
2579 unsigned NumElems = MT->getNumElementsFlattened();
2580 assert(
Inits.size() == NumElems);
2582 QualType ElemQT = MT->getElementType();
2588 for (
unsigned I = 0; I != NumElems; ++I) {
2591 if (!this->emitInitElem(ElemT, I, E))
2602template <
class Emitter>
2609 return this->emitInitElem(*InitT, ElemIndex,
Init);
2615 if (!this->emitConstUint32(ElemIndex,
Init))
2617 if (!this->emitArrayElemPtrUint32(
Init))
2622template <
class Emitter>
2625 bool Activate,
bool IsOperatorCall) {
2627 llvm::BitVector NonNullArgs;
2628 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2631 bool ExplicitMemberFn =
false;
2632 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2633 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2635 unsigned ArgIndex = 0;
2636 for (
const Expr *Arg : Args) {
2638 if (!this->
visit(Arg))
2646 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2647 if (DeclIndex < FuncDecl->getNumParams())
2648 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2657 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2665 if (!this->emitActivate(Arg))
2669 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2672 if (!this->emitCheckNonNullArg(ArgT, Arg))
2683template <
class Emitter>
2688template <
class Emitter>
2694template <
class Emitter>
2700template <
class Emitter>
2718template <
class Emitter>
2720 auto It = E->
begin();
2721 return this->
visit(*It);
2725 UnaryExprOrTypeTrait Kind) {
2726 bool AlignOfReturnsPreferred =
2733 T = Ref->getPointeeType();
2735 if (
T.getQualifiers().hasUnaligned())
2741 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2747template <
class Emitter>
2751 UnaryExprOrTypeTrait Kind = E->
getKind();
2754 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2760 ArgType = Ref->getPointeeType();
2766 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2767 return this->emitInvalid(E);
2769 if (Kind == UETT_SizeOf)
2778 return this->emitConst(Size.getQuantity(), E);
2781 if (Kind == UETT_CountOf) {
2787 if (
const auto *CAT =
2791 return this->emitConst(CAT->getSize(), E);
2801 if (VAT->getElementType()->isArrayType()) {
2802 std::optional<APSInt> Res =
2804 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2809 return this->emitConst(*Res, E);
2814 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2834 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2837 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2847 return this->emitConst(Size.getQuantity(), E);
2850 if (Kind == UETT_VectorElements) {
2855 return this->emitConst(VT->getNumElements(), E);
2857 return this->emitSizelessVectorElementSize(E);
2860 if (Kind == UETT_VecStep) {
2862 unsigned N = VT->getNumElements();
2869 return this->emitConst(N, E);
2871 return this->emitConst(1, E);
2874 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2883 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2885 return this->emitInvalid(E);
2887 return this->emitConst(
2888 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2896template <
class Emitter>
2905 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2908 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2909 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2911 if (
Member->getType()->isReferenceType())
2912 return this->emitLoadPopPtr(E);
2921 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2922 MD && !MD->isStatic()) {
2926 if (!this->
discard(Base) && !this->emitSideEffect(E))
2941 const Record::Field *F = R->getField(FD);
2945 const auto maybeLoadValue = [&]() ->
bool {
2949 return this->emitLoadPop(*
T, E);
2954 if (F->Decl->getType()->isReferenceType())
2955 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2956 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2959template <
class Emitter>
2969template <
class Emitter>
2983 if (!this->
visit(Common))
2985 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2999 for (
size_t I = 0; I != Size; ++I) {
3011template <
class Emitter>
3026 return this->emitGetLocal(SubExprT, It->second, E);
3029 if (!this->
visit(SourceExpr))
3036 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3045 return this->emitGetLocal(SubExprT, LocalIndex, E);
3049template <
class Emitter>
3062 bool IsBcpCall =
false;
3063 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3064 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3068 LabelTy LabelEnd = this->getLabel();
3069 LabelTy LabelFalse = this->getLabel();
3072 if (!this->emitPushIgnoreDiags(E))
3080 if (this->checkingForUndefinedBehavior()) {
3083 if (!this->
discard(FalseExpr))
3100 if (!this->jumpFalse(LabelFalse, E))
3105 if (!this->jump(LabelEnd, E))
3107 this->emitLabel(LabelFalse);
3111 this->fallthrough(LabelEnd);
3112 this->emitLabel(LabelEnd);
3115 return this->emitPopIgnoreDiags(E);
3119template <
class Emitter>
3125 return this->emitGetStringPtr(E, E);
3129 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3130 assert(CAT &&
"a string literal that's not a constant array?");
3135 unsigned N = std::min(ArraySize, E->
getLength());
3138 for (
unsigned I = 0; I != N; ++I) {
3141 if (CharWidth == 1) {
3142 this->emitConstSint8(CodeUnit, E);
3143 this->emitInitElemSint8(I, E);
3144 }
else if (CharWidth == 2) {
3145 this->emitConstUint16(CodeUnit, E);
3146 this->emitInitElemUint16(I, E);
3147 }
else if (CharWidth == 4) {
3148 this->emitConstUint32(CodeUnit, E);
3149 this->emitInitElemUint32(I, E);
3151 llvm_unreachable(
"unsupported character width");
3156 for (
unsigned I = N; I != ArraySize; ++I) {
3157 if (CharWidth == 1) {
3158 this->emitConstSint8(0, E);
3159 this->emitInitElemSint8(I, E);
3160 }
else if (CharWidth == 2) {
3161 this->emitConstUint16(0, E);
3162 this->emitInitElemUint16(I, E);
3163 }
else if (CharWidth == 4) {
3164 this->emitConstUint32(0, E);
3165 this->emitInitElemUint32(I, E);
3167 llvm_unreachable(
"unsupported character width");
3174template <
class Emitter>
3178 return this->emitDummyPtr(E, E);
3181template <
class Emitter>
3183 auto &A =
Ctx.getASTContext();
3192template <
class Emitter>
3200 auto &A =
Ctx.getASTContext();
3204 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3205 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3211 return this->emitGetStringPtr(SL, E);
3214template <
class Emitter>
3218 return this->emitConst(E->
getValue(), E);
3221template <
class Emitter>
3243 if (!this->emitLoad(LHST, E))
3246 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3247 LHSComputationType, E))
3259 unsigned TempOffset =
3261 if (!this->emitSetLocal(*RT, TempOffset, E))
3267 if (!this->emitLoad(LHST, E))
3271 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3272 LHSComputationType, E))
3276 if (!this->emitGetLocal(*RT, TempOffset, E))
3282 if (!this->emitAddf(getFPOptions(E), E))
3286 if (!this->emitSubf(getFPOptions(E), E))
3290 if (!this->emitMulf(getFPOptions(E), E))
3294 if (!this->emitDivf(getFPOptions(E), E))
3305 return this->emitStorePop(LHST, E);
3306 return this->emitStore(LHST, E);
3309template <
class Emitter>
3318 if (Op != BO_AddAssign && Op != BO_SubAssign)
3327 if (!this->emitLoad(*
LT, LHS))
3333 if (Op == BO_AddAssign) {
3334 if (!this->emitAddOffset(*RT, E))
3337 if (!this->emitSubOffset(*RT, E))
3342 return this->emitStorePopPtr(E);
3343 return this->emitStorePtr(E);
3346template <
class Emitter>
3359 if (!
Ctx.getLangOpts().CPlusPlus14)
3360 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3362 if (!
LT || !RT || !ResultT || !LHSComputationT)
3379 if (!this->emitLoad(*
LT, E))
3381 if (
LT != LHSComputationT &&
3382 !this->emitIntegralCast(*
LT, *LHSComputationT,
3396 unsigned TempOffset =
3399 if (!this->emitSetLocal(*RT, TempOffset, E))
3406 if (!this->emitLoad(*
LT, E))
3408 if (
LT != LHSComputationT &&
3409 !this->emitIntegralCast(*
LT, *LHSComputationT,
3414 if (!this->emitGetLocal(*RT, TempOffset, E))
3421 if (!this->emitAdd(*LHSComputationT, E))
3425 if (!this->emitSub(*LHSComputationT, E))
3429 if (!this->emitMul(*LHSComputationT, E))
3433 if (!this->emitDiv(*LHSComputationT, E))
3437 if (!this->emitRem(*LHSComputationT, E))
3441 if (!this->emitShl(*LHSComputationT, *RT, E))
3445 if (!this->emitShr(*LHSComputationT, *RT, E))
3449 if (!this->emitBitAnd(*LHSComputationT, E))
3453 if (!this->emitBitXor(*LHSComputationT, E))
3457 if (!this->emitBitOr(*LHSComputationT, E))
3461 llvm_unreachable(
"Unimplemented compound assign operator");
3465 if (ResultT != LHSComputationT &&
3466 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3472 return this->emitStoreBitFieldPop(*ResultT, E);
3473 return this->emitStorePop(*ResultT, E);
3476 return this->emitStoreBitField(*ResultT, E);
3477 return this->emitStore(*ResultT, E);
3480template <
class Emitter>
3488template <
class Emitter>
3503 if (!
Ctx.getLangOpts().CPlusPlus11)
3510 for (
const Expr *LHS : CommaLHSs) {
3532 if (!this->
visit(Inner))
3537 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3540 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3543 return this->emitGetPtrGlobal(*GlobalIndex, E);
3546 if (!this->checkLiteralType(Inner))
3549 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3555 return this->emitInitGlobalTempComp(TempDecl, E);
3568 unsigned LocalIndex =
3570 if (!this->VarScope->LocalsAlwaysEnabled &&
3571 !this->emitEnableLocal(LocalIndex, E))
3574 if (!this->
visit(Inner))
3576 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3579 return this->emitGetPtrLocal(LocalIndex, E);
3582 if (!this->checkLiteralType(Inner))
3589 if (!this->VarScope->LocalsAlwaysEnabled &&
3590 !this->emitEnableLocal(*LocalIndex, E))
3593 if (!this->emitGetPtrLocal(*LocalIndex, E))
3600template <
class Emitter>
3611 if (!this->
visit(SubExpr))
3615 return this->emitPopPtr(E);
3619template <
class Emitter>
3640 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3645 if (
P.isGlobalInitialized(*GlobalIndex))
3651 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3663 unsigned LocalIndex;
3667 LocalIndex = *MaybeIndex;
3671 if (!this->emitGetPtrLocal(LocalIndex, E))
3675 return this->
visit(
Init) && this->emitInit(*
T, E);
3679template <
class Emitter>
3690 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3694 if (!R || R->getNumFields() == 0)
3696 const Record::Field *Field = R->getField(0
U);
3701 return this->emitInitField(FieldT, Field->Offset, E);
3708template <
class Emitter>
3712 return this->emitConst(E->
getValue(), E);
3715template <
class Emitter>
3728 for (
const Record::Field &F : R->fields()) {
3730 if (!
Init ||
Init->containsErrors())
3738 if (!this->emitInitField(*
T, F.Offset, E))
3741 if (!this->emitGetPtrField(F.Offset, E))
3752template <
class Emitter>
3758 return this->emitGetStringPtr(E, E);
3762template <
class Emitter>
3767 return this->emitInvalid(E);
3770template <
class Emitter>
3784 if (!this->emitInvalidCast(
CastKind,
false, E))
3792 bool Fatal = (ToT != FromT);
3799template <
class Emitter>
3801 if (!
Ctx.getLangOpts().CPlusPlus20) {
3822 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3827 return this->emitPopPtr(E);
3831template <
class Emitter>
3837 return this->emitConstBool(E->
getValue(), E);
3840template <
class Emitter>
3845 if (
T->isRecordType()) {
3859 if (!this->emitGetPtrLocal(*LocalIndex, E))
3867 T->getAsCXXRecordDecl()))
3877 if (!this->visitZeroRecordInitializer(R, E))
3889 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3891 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3892 if (!this->emitCheckFunctionDecl(Ctor, E))
3903 assert(
Func->hasThisPointer());
3904 assert(!
Func->hasRVO());
3908 if (!this->emitDupPtr(E))
3912 for (
const auto *Arg : E->
arguments()) {
3913 if (!this->
visit(Arg))
3917 if (
Func->isVariadic()) {
3918 uint32_t VarArgSize = 0;
3919 unsigned NumParams =
Func->getNumWrittenParams();
3920 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3924 if (!this->emitCallVar(
Func, VarArgSize, E))
3927 if (!this->emitCall(
Func, 0, E)) {
3932 (void)this->emitPopPtr(E);
3938 return this->emitPopPtr(E);
3942 if (
T->isArrayType()) {
3947 if (!this->emitDupPtr(E))
3951 initArrayDimension = [&](
QualType T) ->
bool {
3952 if (!
T->isArrayType()) {
3954 for (
const auto *Arg : E->
arguments()) {
3955 if (!this->
visit(Arg))
3959 return this->emitCall(
Func, 0, E);
3963 Ctx.getASTContext().getAsConstantArrayType(
T);
3968 for (
size_t I = 0; I != NumElems; ++I) {
3969 if (!this->emitConstUint64(I, E))
3971 if (!this->emitArrayElemPtrUint64(E))
3973 if (!initArrayDimension(ElemTy))
3976 return this->emitPopPtr(E);
3979 return initArrayDimension(E->
getType());
3985template <
class Emitter>
3995 assert(Val.
isInt());
3997 return this->emitConst(I, E);
4004 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4005 return this->
visit(LValueExpr);
4020 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4024 const APValue &
V = UGCD->getValue();
4025 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4026 const Record::Field *F = R->getField(I);
4027 const APValue &FieldValue =
V.getStructField(I);
4033 if (!this->emitInitField(FieldT, F->Offset, E))
4041template <
class Emitter>
4047 for (
unsigned I = 0; I != N; ++I) {
4054 if (!this->
discard(ArrayIndexExpr))
4060 if (!this->
visit(ArrayIndexExpr))
4062 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4066 if (!this->
visit(ArrayIndexExpr))
4070 if (!this->emitCast(IndexT,
PT_Sint64, E))
4080 return this->emitOffsetOf(
T, E, E);
4083template <
class Emitter>
4092 return this->visitZeroInitializer(*
T, Ty, E);
4099 if (!this->emitGetPtrLocal(*LocalIndex, E))
4107 ElemQT = CT->getElementType();
4110 NumElems = VT->getNumElements();
4111 ElemQT = VT->getElementType();
4117 for (
unsigned I = 0; I != NumElems; ++I) {
4118 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4120 if (!this->emitInitElem(ElemT, I, E))
4129template <
class Emitter>
4134template <
class Emitter>
4140template <
class Emitter>
4145template <
class Emitter>
4150 return this->emitConst(E->
getValue(), E);
4153template <
class Emitter>
4158 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4173 unsigned ParamIndex = 0;
4177 if (!this->emitGetParam(PT, ParamIndex, E))
4182 return this->emitCall(F, 0, E);
4187template <
class Emitter>
4195 const Expr *PlacementDest =
nullptr;
4196 bool IsNoThrow =
false;
4201 if (PlacementArgs != 0) {
4210 if (PlacementArgs == 1) {
4218 if (!this->emitInvalidNewDeleteExpr(E, E))
4223 if (OperatorNew->isReservedGlobalPlacementOperator())
4224 PlacementDest = Arg1;
4228 return this->emitInvalid(E);
4230 }
else if (!OperatorNew
4231 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4232 return this->emitInvalidNewDeleteExpr(E, E);
4235 if (!PlacementDest) {
4240 Desc =
P.createDescriptor(E, *ElemT);
4242 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4249 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4253 const Expr *Stripped = *ArraySizeExpr;
4254 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4255 Stripped = ICE->getSubExpr())
4256 if (ICE->getCastKind() != CK_NoOp &&
4257 ICE->getCastKind() != CK_IntegralCast)
4265 if (!this->
visit(Stripped))
4267 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4270 if (PlacementDest) {
4271 if (!this->
visit(PlacementDest))
4273 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4275 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4278 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4283 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4287 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4294 size_t StaticInitElems = 0;
4295 const Expr *DynamicInit =
nullptr;
4299 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4300 StaticInitElems = CAT->getZExtSize();
4305 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4306 if (ILE->hasArrayFiller())
4307 DynamicInit = ILE->getArrayFiller();
4326 const Function *CtorFunc =
nullptr;
4327 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4331 }
else if (!DynamicInit && !ElemT)
4334 LabelTy EndLabel = this->getLabel();
4335 LabelTy StartLabel = this->getLabel();
4340 if (!this->emitDupPtr(E))
4342 if (!this->emitNullPtr(0,
nullptr, E))
4344 if (!this->emitEQPtr(E))
4346 if (!this->jumpTrue(EndLabel, E))
4353 if (!this->emitConst(StaticInitElems,
SizeT, E))
4355 if (!this->emitSetLocal(
SizeT, Iter, E))
4358 this->fallthrough(StartLabel);
4359 this->emitLabel(StartLabel);
4361 if (!this->emitGetLocal(
SizeT, Iter, E))
4363 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4365 if (!this->emitLT(
SizeT, E))
4367 if (!this->jumpFalse(EndLabel, E))
4371 if (!this->emitGetLocal(
SizeT, Iter, E))
4373 if (!this->emitArrayElemPtr(
SizeT, E))
4376 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4381 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4383 if (!this->emitStorePop(*InitT, E))
4387 if (!this->visitZeroArrayInitializer(ElemType, E))
4390 }
else if (DynamicInit) {
4392 if (!this->
visit(DynamicInit))
4394 if (!this->emitStorePop(*InitT, E))
4401 if (!this->visitZeroInitializer(
4405 if (!this->emitStorePop(*ElemT, E))
4409 if (!this->emitCall(CtorFunc, 0, E))
4414 if (!this->emitGetPtrLocal(Iter, E))
4416 if (!this->emitIncPop(
SizeT,
false, E))
4419 if (!this->jump(StartLabel, E))
4422 this->fallthrough(EndLabel);
4423 this->emitLabel(EndLabel);
4427 if (PlacementDest) {
4428 if (!this->
visit(PlacementDest))
4430 if (!this->emitCheckNewTypeMismatch(E, E))
4435 if (!this->emitAlloc(Desc, E))
4444 if (!this->emitInit(*ElemT, E))
4455 return this->emitPopPtr(E);
4460template <
class Emitter>
4466 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4467 return this->emitInvalidNewDeleteExpr(E, E);
4476template <
class Emitter>
4482 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4487 return this->emitGetFnPtr(
Func, E);
4490template <
class Emitter>
4494 auto canonType = [](
const Type *
T) {
4495 return T->getCanonicalTypeUnqualified().getTypePtr();
4503 return this->emitGetTypeid(
4507 return this->emitGetTypeid(
4516 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4522 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4525 return this->emitPopPtr(E);
4529template <
class Emitter>
4533 return this->emitDummyPtr(E, E);
4534 return this->emitError(E);
4537template <
class Emitter>
4540 return this->emitDummyPtr(E, E);
4541 return this->emitError(E);
4544template <
class Emitter>
4546 assert(
Ctx.getLangOpts().CPlusPlus);
4547 return this->emitConstBool(E->
getValue(), E);
4550template <
class Emitter>
4562 return this->emitDummyPtr(GuidDecl, E);
4567 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4576 assert(
V.isStruct());
4577 assert(
V.getStructNumBases() == 0);
4581 return this->emitFinishInit(E);
4584template <
class Emitter>
4594template <
class Emitter>
4603template <
class Emitter>
4609template <
class Emitter>
4613 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4617 if (OVE->isUnique())
4633template <
class Emitter>
4638template <
class Emitter>
4640 return this->emitError(E);
4643template <
class Emitter>
4649 return this->emitDummyPtr(E, E);
4652template <
class Emitter>
4653bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4658 QualType ElemType = VT->getElementType();
4659 PrimType ElemT = classifyPrim(ElemType);
4661 PrimType SrcElemT = classifyVectorElementType(SrcType);
4667 if (!this->emitGetPtrLocal(*LocalIndex, E))
4671 unsigned SrcOffset =
4672 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4673 if (!this->visit(Src))
4675 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4678 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4679 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4681 if (!this->emitArrayElemPop(SrcElemT, I, E))
4685 if (SrcElemT != ElemT) {
4686 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4688 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4689 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4693 if (!this->emitInitElem(ElemT, I, E))
4699template <
class Emitter>
4701 return emitVectorConversion(E->
getSrcExpr(), E);
4704template <
class Emitter>
4708 return this->emitInvalid(E);
4717 assert(NumOutputElems > 0);
4723 if (!this->emitGetPtrLocal(*LocalIndex, E))
4728 unsigned VectorOffsets[2];
4729 for (
unsigned I = 0; I != 2; ++I) {
4732 if (!this->
visit(Vecs[I]))
4734 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4737 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4739 assert(ShuffleIndex >= -1);
4740 if (ShuffleIndex == -1)
4741 return this->emitInvalidShuffleVectorIndex(I, E);
4743 assert(ShuffleIndex < (NumInputElems * 2));
4744 if (!this->emitGetLocal(
PT_Ptr,
4745 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4747 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4748 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4751 if (!this->emitInitElem(ElemT, I, E))
4756 return this->emitPopPtr(E);
4761template <
class Emitter>
4766 Base->getType()->isVectorType() ||
4772 if (Indices.size() == 1) {
4777 if (!this->emitConstUint32(Indices[0], E))
4779 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4789 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4797 if (!this->emitGetPtrLocal(*ResultIndex, E))
4805 uint32_t DstIndex = 0;
4806 for (uint32_t I : Indices) {
4807 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4809 if (!this->emitArrayElemPop(ElemT, I, E))
4811 if (!this->emitInitElem(ElemT, DstIndex, E))
4821template <
class Emitter>
4825 return this->
discard(SubExpr) && this->emitInvalid(E);
4831 return this->emitDummyPtr(E, E);
4834template <
class Emitter>
4839 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4844 if (!this->
visit(SubExpr))
4846 if (!this->emitConstUint8(0, E))
4848 if (!this->emitArrayElemPtrPopUint8(E))
4850 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4855 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4857 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4859 assert(SecondFieldT ==
PT_Ptr);
4861 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4863 if (!this->emitExpandPtr(E))
4867 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4869 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4872template <
class Emitter>
4887 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4891 return this->emitUnsupported(E);
4900 return this->
Visit(E);
4907 return this->
Visit(E);
4911 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4914 if (
const auto *CE = dyn_cast<CastExpr>(E);
4916 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4923 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4926 if (
const auto *CE = dyn_cast<CastExpr>(E);
4927 CE && (CE->getCastKind() == CK_DerivedToBase ||
4928 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4929 CE->getCastKind() == CK_NoOp))
4949 if (!this->emitGetPtrLocal(*LocalIndex, E))
4959 return this->
Visit(E);
4962template <
class Emitter>
4968 return this->
Visit(E) && this->emitFinishInit(E);
4971template <
class Emitter>
4977 return this->
Visit(E) && this->emitFinishInitPop(E);
4983 return this->
Visit(E);
4994 if (!this->
visit(E))
4996 return this->emitComplexBoolCast(E);
5001 if (!this->
visit(E))
5009 return this->emitIsNonNullPtr(E);
5013 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5016 return this->emitCast(*
T,
PT_Bool, E);
5019template <
class Emitter>
5023 QT = AT->getValueType();
5027 return this->emitZeroBool(E);
5029 return this->emitZeroSint8(E);
5031 return this->emitZeroUint8(E);
5033 return this->emitZeroSint16(E);
5035 return this->emitZeroUint16(E);
5037 return this->emitZeroSint32(E);
5039 return this->emitZeroUint32(E);
5041 return this->emitZeroSint64(E);
5043 return this->emitZeroUint64(E);
5045 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5047 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5049 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5052 return this->emitNullMemberPtr(0,
nullptr, E);
5054 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5055 return this->emitFloat(F, E);
5058 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5062 llvm_unreachable(
"unknown primitive type");
5065template <
class Emitter>
5066bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5068 bool IsCompleteClass) {
5072 for (
const Record::Field &Field :
R->fields()) {
5073 if (Field.isUnnamedBitField())
5080 if (!this->visitZeroInitializer(
T, QT, E))
5083 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5087 if (!this->emitInitField(
T, Field.Offset, E))
5092 if (!this->emitGetPtrField(Field.Offset, E))
5099 if (!this->visitZeroInitializer(
T, ET, E))
5101 if (!this->emitInitElem(
T, I, E))
5106 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5109 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5117 if (!this->emitFinishInitActivatePop(E))
5121 if (!this->emitFinishInitPop(E))
5125 for (
const Record::Base &B :
R->bases()) {
5126 if (!this->emitGetPtrBase(B.Offset, E))
5128 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5130 if (!this->emitFinishInitPop(E))
5134 if (IsCompleteClass) {
5135 for (
const Record::Base &B :
R->virtual_bases()) {
5138 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5140 if (!this->emitFinishInitPop(E))
5148template <
class Emitter>
5149bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5150 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5151 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5156 for (
size_t I = 0; I != NumElems; ++I) {
5157 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5159 if (!this->emitInitElem(*ElemT, I, E))
5165 const Record *
R = getRecord(ElemType);
5169 for (
size_t I = 0; I != NumElems; ++I) {
5170 if (!this->emitConstUint32(I, E))
5172 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5174 if (!this->visitZeroRecordInitializer(R, E))
5176 if (!this->emitPopPtr(E))
5182 for (
size_t I = 0; I != NumElems; ++I) {
5183 if (!this->emitConstUint32(I, E))
5185 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5187 if (!this->visitZeroArrayInitializer(ElemType, E))
5189 if (!this->emitPopPtr(E))
5198template <
class Emitter>
5199bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5201 if (!canClassify(E->
getType()))
5206 if (!this->visit(LHS))
5208 if (!this->visit(RHS))
5211 if (!this->visit(RHS))
5213 if (!this->visit(LHS))
5221 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5225 bool Activates = refersToUnion(LHS);
5228 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5231 if (DiscardResult) {
5232 if (BitField && Activates)
5233 return this->emitStoreBitFieldActivatePop(RHT, E);
5235 return this->emitStoreBitFieldPop(RHT, E);
5237 return this->emitStoreActivatePop(RHT, E);
5239 return this->emitStorePop(RHT, E);
5242 auto maybeLoad = [&](
bool Result) ->
bool {
5248 return this->emitLoadPop(RHT, E);
5252 if (BitField && Activates)
5253 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5255 return maybeLoad(this->emitStoreBitField(RHT, E));
5257 return maybeLoad(this->emitStoreActivate(RHT, E));
5259 return maybeLoad(this->emitStore(RHT, E));
5262template <
class Emitter>
5263template <
typename T>
5267 return this->emitConstSint8(
Value, Info);
5269 return this->emitConstUint8(
Value, Info);
5271 return this->emitConstSint16(
Value, Info);
5273 return this->emitConstUint16(
Value, Info);
5275 return this->emitConstSint32(
Value, Info);
5277 return this->emitConstUint32(
Value, Info);
5279 return this->emitConstSint64(
Value, Info);
5281 return this->emitConstUint64(
Value, Info);
5283 return this->emitConstBool(
Value, Info);
5290 llvm_unreachable(
"Invalid integral type");
5293 llvm_unreachable(
"unknown primitive type");
5296template <
class Emitter>
5297template <
typename T>
5298bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5299 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5302template <
class Emitter>
5306 return this->emitConstIntAPS(
Value, Info);
5308 return this->emitConstIntAP(
Value, Info);
5310 if (
Value.isSigned())
5311 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5312 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5315template <
class Emitter>
5319 return this->emitConstIntAPS(
Value, Info);
5321 return this->emitConstIntAP(
Value, Info);
5324 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5325 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5328template <
class Emitter>
5329bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5330 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5333template <
class Emitter>
5346 Locals.insert({VD, Local});
5347 VarScope->addForScopeKind(Local, SC);
5348 return Local.Offset;
5351template <
class Emitter>
5356 bool IsTemporary =
false;
5360 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5361 Init = VarD->getInit();
5363 if (
const auto *E = Src.
asExpr()) {
5373 return std::nullopt;
5378 Locals.insert({Key, Local});
5379 VarScope->addForScopeKind(Local, SC);
5380 return Local.Offset;
5383template <
class Emitter>
5392 return std::nullopt;
5402 return Local.Offset;
5405template <
class Emitter>
5407 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5408 return PT->getPointeeType()->getAsCanonical<RecordType>();
5414 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5418template <
class Emitter>
5420 return P.getOrCreateRecord(RD);
5423template <
class Emitter>
5425 return Ctx.getOrCreateFunction(FD);
5428template <
class Emitter>
5432 auto maybeDestroyLocals = [&]() ->
bool {
5433 if (DestroyToplevelScope)
5434 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5435 return this->emitCheckAllocations(E);
5442 return this->emitRetVoid(E) && maybeDestroyLocals();
5450 return this->emitRet(*
T, E) && maybeDestroyLocals();
5458 if (!this->emitGetPtrLocal(*LocalOffset, E))
5466 return this->emitRetValue(E) && maybeDestroyLocals();
5469 return maybeDestroyLocals() &&
false;
5472template <
class Emitter>
5474 bool DestroyToplevelScope) {
5478 return this->
visitExpr(E, DestroyToplevelScope);
5481template <
class Emitter>
5493 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5494 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5508template <
class Emitter>
5510 bool ConstantContext) {
5513 if (!ConstantContext) {
5528 auto GlobalIndex =
P.getGlobal(VD);
5529 assert(GlobalIndex);
5531 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5534 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5538 auto Local =
Locals.find(VD);
5539 assert(Local !=
Locals.end());
5542 if (!this->emitGetRefLocal(Local->second.Offset, VD))
5544 }
else if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5547 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5557 auto GlobalIndex =
P.getGlobal(VD);
5558 assert(GlobalIndex);
5559 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5568 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5571template <
class Emitter>
5582 if (!this->isActive())
5587 if (
Init &&
Init->isValueDependent())
5591 auto checkDecl = [&]() ->
bool {
5593 return !NeedsOp || this->emitCheckDecl(VD, VD);
5600 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5603 if (
P.isGlobalInitialized(*GlobalIndex))
5607 }
else if ((GlobalIndex =
5622 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5625 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5628 if (!this->emitStartInit(
Init))
5634 if (!this->emitEndInit(
Init))
5637 return this->emitFinishInitGlobal(
Init);
5647 if (!
Init ||
Init->getType()->isVoidType())
5656 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5668 if (!this->emitCheckRefInit(
Init))
5672 return this->emitSetLocal(*VarT, Offset, VD);
5680 if (!this->emitGetPtrLocal(*Offset,
Init))
5688template <
class Emitter>
5708 Locals.insert({VD, Local});
5711 if (!this->emitGetPtrLocal(Local.Offset, VD))
5717 return this->emitDestructionPop(D, VD);
5726 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5750template <
class Emitter>
5765 unsigned ParamIndex = 0;
5772 const Expr *Arg = Args[ParamIndex];
5773 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5775 unsigned ArgOffset =
5777 if (!this->
visit(Arg))
5779 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5785 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5797 if (
This->getType()->isPointerType()) {
5800 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5807 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5829template <
class Emitter>
5835 return this->emitConst(Val.
getInt(), ValType, Info);
5837 return this->emitFloat(Val.
getFloat(), Info);
5841 if (!this->emitGetMemberPtr(MemberDecl, Info))
5847 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5853 return this->emitNullMemberPtr(0,
nullptr, Info);
5858 return this->emitNull(ValType, 0,
nullptr, Info);
5863 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5864 return this->
visit(BaseExpr);
5869 QualType EntryType = VD->getType();
5870 for (
auto &Entry : Path) {
5872 uint64_t Index = Entry.getAsArrayIndex();
5875 if (!this->emitConst(Index,
PT_Uint64, Info))
5877 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5879 EntryType = ElemType;
5886 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5887 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5889 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5891 EntryType = FD->getType();
5895 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
5900 if (!this->emitGetPtrVirtBasePop(
Base, Info))
5903 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5915template <
class Emitter>
5918 bool IsCompleteClass) {
5924 if (IsCompleteClass)
5931 const Record::Base *RB = R->getBase(I);
5932 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5934 if (!this->emitGetPtrBase(RB->Offset, Info))
5939 if (!this->emitFinishInitPop(Info))
5947 const Record::Field *RF = R->getField(I);
5948 QualType FieldType = RF->Decl->getType();
5953 if (!this->emitInitField(*PT, RF->Offset, Info))
5956 if (!this->emitGetPtrField(RF->Offset, Info))
5960 if (!this->emitFinishInitPop(Info))
5966 if (IsCompleteClass) {
5971 const Record::Base *RB = R->getVirtualBase(I);
5972 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5980 if (!this->emitFinishInitPop(Info))
5996 const Record::Field *RF = R->getField(UnionField);
5997 QualType FieldType = RF->Decl->getType();
6002 if (RF->isBitField())
6003 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6005 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6008 if (!this->emitGetPtrField(RF->Offset, Info))
6010 if (!this->emitActivate(Info))
6014 return this->emitPopPtr(Info);
6018 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6019 QualType ElemType = ArrType->getElementType();
6022 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6023 const APValue &Elem = A >= InitializedElems
6032 if (!this->emitInitElem(*ElemT, A, Info))
6035 if (!this->emitConstUint32(A, Info))
6037 if (!this->emitArrayElemPtrUint32(Info))
6041 if (!this->emitPopPtr(Info))
6052template <
class Emitter>
6054 unsigned BuiltinID) {
6055 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6060 return this->emitConst(0, E);
6063 if (!this->emitStartSpeculation(E))
6065 LabelTy EndLabel = this->getLabel();
6066 if (!this->speculate(E, EndLabel))
6068 if (!this->emitEndSpeculation(E))
6070 this->fallthrough(EndLabel);
6078 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6079 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6080 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6081 BuiltinID == Builtin::BI__builtin_function_start) {
6084 return this->emitDummyPtr(E, E);
6095 if (!this->emitGetPtrLocal(*LocalIndex, E))
6100 switch (BuiltinID) {
6101 case Builtin::BI__builtin_object_size:
6102 case Builtin::BI__builtin_dynamic_object_size: {
6106 if (!this->
visit(Arg0))
6117 case Builtin::BI__assume:
6118 case Builtin::BI__builtin_assume:
6121 case Builtin::BI__atomic_is_lock_free:
6122 case Builtin::BI__atomic_always_lock_free: {
6133 for (
const auto *Arg : E->
arguments()) {
6134 if (!this->
visit(Arg))
6140 if (!this->emitCallBI(E, BuiltinID, E))
6149template <
class Emitter>
6170 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6171 DD && DD->isTrivial()) {
6173 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6175 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6176 this->emitPopPtr(E);
6192 if (!this->emitGetPtrLocal(*LocalIndex, E))
6200 if (!this->emitGetPtrLocal(*LocalIndex, E))
6204 if (!this->emitDupPtr(E))
6210 const Expr *ReversedArgs[2];
6212 bool IsAssignmentOperatorCall =
false;
6213 bool ActivateLHS =
false;
6214 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6215 OCE && OCE->isAssignmentOp()) {
6219 assert(Args.size() == 2);
6220 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6222 IsAssignmentOperatorCall =
true;
6223 ReversedArgs[0] = Args[1];
6224 ReversedArgs[1] = Args[0];
6225 Args = ReversedArgs;
6231 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6232 MD && MD->isStatic()) {
6236 Args = Args.drop_front();
6240 bool Devirtualized =
false;
6243 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6251 if (!this->
visit(Callee))
6253 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6255 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6257 if (!this->emitGetMemberPtrBase(E))
6260 const auto *InstancePtr = MC->getImplicitObjectArgument();
6267 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6268 Devirtualized =
true;
6269 if (!this->
visit(Stripped))
6272 if (!this->
visit(InstancePtr))
6276 if (!this->
visit(InstancePtr))
6280 }
else if (
const auto *PD =
6281 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6282 if (!this->emitCheckPseudoDtor(E))
6290 return this->emitPseudoDtor(E);
6291 }
else if (!FuncDecl) {
6295 if (!this->
visit(Callee))
6297 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6306 if (IsAssignmentOperatorCall) {
6307 assert(Args.size() == 2);
6310 if (!this->emitFlip(Arg2T, Arg1T, E))
6324 assert(HasRVO ==
Func->hasRVO());
6326 bool HasQualifier =
false;
6327 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6328 HasQualifier = ME->hasQualifier();
6330 bool IsVirtual =
false;
6331 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6332 IsVirtual = !Devirtualized && MD->isVirtual();
6337 if (IsVirtual && !HasQualifier) {
6338 uint32_t VarArgSize = 0;
6339 unsigned NumParams =
6340 Func->getNumWrittenParams() +
6342 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6345 if (!this->emitCallVirt(
Func, VarArgSize, E))
6347 }
else if (
Func->isVariadic()) {
6348 uint32_t VarArgSize = 0;
6349 unsigned NumParams =
6350 Func->getNumWrittenParams() +
6352 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6354 if (!this->emitCallVar(
Func, VarArgSize, E))
6357 if (!this->emitCall(
Func, 0, E))
6366 uint32_t ArgSize = 0;
6367 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6373 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6375 if (!this->emitGetMemberPtrDecl(E))
6378 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6381 if (!this->emitCallPtr(ArgSize, E, E))
6392template <
class Emitter>
6399template <
class Emitter>
6406template <
class Emitter>
6411 return this->emitConstBool(E->
getValue(), E);
6414template <
class Emitter>
6420 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6421 return this->emitNullPtr(Val,
nullptr, E);
6424template <
class Emitter>
6432 return this->emitZero(
T, E);
6435template <
class Emitter>
6440 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6441 if (this->LambdaThisCapture.Offset > 0) {
6442 if (this->LambdaThisCapture.IsPtr)
6443 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6444 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6453 return this->emitThis(E);
6468 unsigned StartIndex = 0;
6469 unsigned EndIndex = 0;
6471 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6473 EndIndex = StartIndex;
6480 for (; StartIndex > 0; --StartIndex) {
6491 if (StartIndex == 0 && EndIndex == 0)
6502 assert(StartIndex <= EndIndex);
6505 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6517 case Stmt::CompoundStmtClass:
6519 case Stmt::DeclStmtClass:
6521 case Stmt::ReturnStmtClass:
6523 case Stmt::IfStmtClass:
6525 case Stmt::WhileStmtClass:
6527 case Stmt::DoStmtClass:
6529 case Stmt::ForStmtClass:
6531 case Stmt::CXXForRangeStmtClass:
6533 case Stmt::BreakStmtClass:
6535 case Stmt::ContinueStmtClass:
6537 case Stmt::SwitchStmtClass:
6539 case Stmt::CaseStmtClass:
6541 case Stmt::DefaultStmtClass:
6543 case Stmt::AttributedStmtClass:
6545 case Stmt::CXXTryStmtClass:
6547 case Stmt::NullStmtClass:
6550 case Stmt::GCCAsmStmtClass:
6551 case Stmt::MSAsmStmtClass:
6552 case Stmt::GotoStmtClass:
6553 return this->emitInvalid(S);
6554 case Stmt::LabelStmtClass:
6556 case Stmt::CXXExpansionStmtInstantiationClass:
6560 if (
const auto *E = dyn_cast<Expr>(S))
6567template <
class Emitter>
6570 for (
const auto *InnerStmt : S->
body())
6573 return Scope.destroyLocals();
6576template <
class Emitter>
6577bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6578 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6579 for (
auto *BD : DD->flat_bindings())
6580 if (
auto *KD = BD->getHoldingVar();
6581 KD && !this->visitVarDecl(KD, KD->getInit()))
6595template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6597 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6598 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6605 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6610 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6611 ICE && (ICE->getCastKind() == CK_NoOp ||
6612 ICE->getCastKind() == CK_DerivedToBase ||
6613 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6614 E = ICE->getSubExpr();
6618 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6619 const auto *ThisRecord =
6620 This->getType()->getPointeeType()->getAsRecordDecl();
6621 if (!ThisRecord->isUnion())
6624 if (
const auto *Ctor =
6625 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6626 return Ctor->getParent() == ThisRecord;
6635template <
class Emitter>
6637 bool EvaluateConditionDecl) {
6638 for (
const auto *D : DS->
decls()) {
6643 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6644 assert(ESD->getInstantiations() &&
"not expanded?");
6645 if (!this->
visitStmt(ESD->getInstantiations()))
6650 const auto *VD = dyn_cast<VarDecl>(D);
6657 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6664template <
class Emitter>
6667 return this->emitUnsupported(RS);
6673 if (!this->
visit(RE))
6679 if (RE->getType()->isVoidType()) {
6680 if (!this->
visit(RE))
6683 if (RE->containsErrors())
6688 if (!this->emitRVOPtr(RE))
6694 return this->emitRetVoid(RS);
6700 return this->emitRetVoid(RS);
6706 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6713 if (
auto *CondInit = IS->
getInit()) {
6729 return visitChildStmt(IS->
getThen());
6731 return visitChildStmt(Else);
6737 if (!this->emitIsConstantContext(IS))
6740 if (!this->emitIsConstantContext(IS))
6742 if (!this->emitInv(IS))
6756 LabelTy LabelElse = this->getLabel();
6757 LabelTy LabelEnd = this->getLabel();
6758 if (!this->jumpFalse(LabelElse, IS))
6760 if (!visitChildStmt(IS->
getThen()))
6762 if (!this->jump(LabelEnd, IS))
6764 this->emitLabel(LabelElse);
6765 if (!visitChildStmt(Else))
6767 this->emitLabel(LabelEnd);
6769 LabelTy LabelEnd = this->getLabel();
6770 if (!this->jumpFalse(LabelEnd, IS))
6772 if (!visitChildStmt(IS->
getThen()))
6774 this->emitLabel(LabelEnd);
6783template <
class Emitter>
6788 LabelTy CondLabel = this->getLabel();
6789 LabelTy EndLabel = this->getLabel();
6793 this->fallthrough(CondLabel);
6794 this->emitLabel(CondLabel);
6810 if (!this->jumpFalse(EndLabel, S))
6820 if (!this->jump(CondLabel, S))
6822 this->fallthrough(EndLabel);
6823 this->emitLabel(EndLabel);
6832 LabelTy StartLabel = this->getLabel();
6833 LabelTy EndLabel = this->getLabel();
6834 LabelTy CondLabel = this->getLabel();
6838 this->fallthrough(StartLabel);
6839 this->emitLabel(StartLabel);
6845 this->fallthrough(CondLabel);
6846 this->emitLabel(CondLabel);
6853 if (!this->jumpTrue(StartLabel, S))
6856 this->fallthrough(EndLabel);
6857 this->emitLabel(EndLabel);
6861template <
class Emitter>
6869 LabelTy EndLabel = this->getLabel();
6870 LabelTy CondLabel = this->getLabel();
6871 LabelTy IncLabel = this->getLabel();
6878 this->fallthrough(CondLabel);
6879 this->emitLabel(CondLabel);
6891 if (!this->jumpFalse(EndLabel, S))
6900 this->fallthrough(IncLabel);
6901 this->emitLabel(IncLabel);
6907 if (!this->jump(CondLabel, S))
6911 this->emitLabel(EndLabel);
6917template <
class Emitter>
6927 LabelTy EndLabel = this->getLabel();
6928 LabelTy CondLabel = this->getLabel();
6929 LabelTy IncLabel = this->getLabel();
6944 this->fallthrough(CondLabel);
6945 this->emitLabel(CondLabel);
6948 if (!this->jumpFalse(EndLabel, S))
6959 this->fallthrough(IncLabel);
6960 this->emitLabel(IncLabel);
6965 if (!this->jump(CondLabel, S))
6968 this->fallthrough(EndLabel);
6969 this->emitLabel(EndLabel);
6973template <
class Emitter>
6984 if (LI.BreakLabel) {
6985 TargetLabel = *LI.BreakLabel;
6986 BreakScope = LI.BreakOrContinueScope;
6992 if (LI.Name == TargetLoop) {
6993 TargetLabel = *LI.BreakLabel;
6994 BreakScope = LI.BreakOrContinueScope;
7005 C =
C->getParent()) {
7006 if (!
C->destroyLocals())
7010 return this->jump(*TargetLabel, S);
7013template <
class Emitter>
7024 if (LI.ContinueLabel) {
7025 TargetLabel = *LI.ContinueLabel;
7026 ContinueScope = LI.BreakOrContinueScope;
7032 if (LI.Name == TargetLoop) {
7033 TargetLabel = *LI.ContinueLabel;
7034 ContinueScope = LI.BreakOrContinueScope;
7044 C =
C->getParent()) {
7045 if (!
C->destroyLocals())
7049 return this->jump(*TargetLabel, S);
7052template <
class Emitter>
7062 LabelTy EndLabel = this->getLabel();
7067 if (
const auto *CondInit = S->
getInit())
7076 if (!this->
visit(Cond))
7078 if (!this->emitSetLocal(CondT, CondVar, S))
7088 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7091 if (CS->caseStmtIsGNURange()) {
7092 LabelTy EndOfRangeCheck = this->getLabel();
7093 const Expr *Low = CS->getLHS();
7094 const Expr *High = CS->getRHS();
7098 if (!this->emitGetLocal(CondT, CondVar, CS))
7100 if (!this->
visit(Low))
7103 if (!this->emitGE(
LT, S))
7105 if (!this->jumpFalse(EndOfRangeCheck, S))
7108 if (!this->emitGetLocal(CondT, CondVar, CS))
7110 if (!this->
visit(High))
7113 if (!this->emitLE(HT, S))
7117 this->emitLabel(EndOfRangeCheck);
7122 if (
Value->isValueDependent())
7127 if (!this->emitGetLocal(CondT, CondVar, CS))
7133 if (!this->emitEQ(ValueT, S))
7138 assert(!DefaultLabel);
7139 DefaultLabel = this->getLabel();
7146 if (!this->jump(*DefaultLabel, S))
7149 if (!this->jump(EndLabel, S))
7157 this->fallthrough(EndLabel);
7158 this->emitLabel(EndLabel);
7163template <
class Emitter>
7171 return this->emitUnsupported(S);
7176template <
class Emitter>
7183 if (LI.DefaultLabel) {
7184 DefaultLabel = *LI.DefaultLabel;
7189 this->emitLabel(DefaultLabel);
7193template <
class Emitter>
7200 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7203 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7204 !this->Ctx.getLangOpts().MSVCCompat) {
7206 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7212 const Expr *Assumption = AA->getAssumption();
7223 if (!this->emitAssume(Assumption))
7232 if (IsMSVCConstexprAttr)
7233 return this->emitPopMSVCCE(S);
7237template <
class Emitter>
7250template <
class Emitter>
7260 LabelTy EndLabel = this->getLabel();
7262 LabelTy ContinueLabel = this->getLabel();
7267 this->emitLabel(ContinueLabel);
7270 this->emitLabel(EndLabel);
7275template <
class Emitter>
7276bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7283 assert(ClosureClass->
captures().empty());
7287 "A generic lambda's static-invoker function must be a "
7288 "template specialization");
7292 llvm::FoldingSetInsertToken InsertToken;
7293 const FunctionDecl *CorrespondingCallOpSpecialization =
7295 assert(CorrespondingCallOpSpecialization);
7296 LambdaCallOp = CorrespondingCallOpSpecialization;
7300 assert(ClosureClass->
captures().empty());
7301 const Function *
Func = this->getFunction(LambdaCallOp);
7304 assert(
Func->hasThisPointer());
7307 if (
Func->hasRVO()) {
7308 if (!this->emitRVOPtr(MD))
7316 if (!this->emitNullPtr(0,
nullptr, MD))
7321 auto It = this->Params.find(PVD);
7322 assert(It != this->Params.end());
7326 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7327 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7331 if (!this->emitCall(
Func, 0, LambdaCallOp))
7336 return this->emitRet(*ReturnType, MD);
7339 return this->emitRetVoid(MD);
7342template <
class Emitter>
7343bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7344 if (Ctx.getLangOpts().CPlusPlus23)
7354 const Expr *InitExpr =
Init->getInit();
7356 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7360 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7370template <
class Emitter>
7372 assert(!ReturnType);
7375 if (!this->emitStartThisLifetime1(Ctor))
7378 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7379 const Expr *InitExpr,
7382 if (InitExpr->getType().isNull())
7386 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7389 if (!this->visit(InitExpr))
7392 if (F->isBitField())
7393 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7395 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7400 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7403 if (
Activate && !this->emitActivate(InitExpr))
7406 return this->visitInitializerPop(InitExpr);
7410 const Record *
R = this->getRecord(RD);
7413 bool IsUnion =
R->isUnion();
7423 if (!this->emitThis(Ctor))
7426 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7429 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7430 this->emitRetVoid(Ctor);
7433 unsigned FieldInits = 0;
7436 if (
R->getNumVirtualBases() > 0) {
7437 if (!this->emitThis(Ctor))
7439 LabelTy AfterVirtBasesLabel = this->getLabel();
7442 if (!this->emitIsBaseClass({}))
7444 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7447 for (
const auto *
Init : Ctor->
inits()) {
7450 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7452 assert(
R->getVirtualBase(BaseDecl));
7453 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7455 if (!this->visitInitializerPop(
Init->getInit()))
7460 this->fallthrough(AfterVirtBasesLabel);
7461 this->emitLabel(AfterVirtBasesLabel);
7463 if (!this->emitPopPtr(Ctor))
7467 for (
const auto *
Init : Ctor->
inits()) {
7471 const Expr *InitExpr =
Init->getInit();
7473 const Record::Field *F =
R->getField(
Member);
7477 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7481 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7484 if (
Init->isBaseVirtual()) {
7490 const Record::Base *B =
R->getBase(BaseDecl);
7492 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7496 if (!this->visitInitializerPop(InitExpr))
7501 unsigned ChainSize = IFD->getChainingSize();
7502 assert(ChainSize >= 2);
7504 unsigned NestedFieldOffset = 0;
7505 const Record::Field *NestedField =
nullptr;
7506 for (
unsigned I = 0; I != ChainSize; ++I) {
7508 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7509 assert(FieldRecord);
7511 NestedField = FieldRecord->
getField(FD);
7512 assert(NestedField);
7513 IsUnion = IsUnion || FieldRecord->
isUnion();
7515 NestedFieldOffset += NestedField->Offset;
7518 if (I != ChainSize - 1)
7521 assert(NestedField);
7524 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7529 unsigned InitFieldOffset = 0;
7530 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7532 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7533 assert(FieldRecord);
7534 NestedField = FieldRecord->
getField(FD);
7535 InitFieldOffset += NestedField->Offset;
7536 assert(NestedField);
7537 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7539 if (!this->emitFinishInitPop(InitExpr))
7543 InitStack.pop_back_n(ChainSize - 1);
7546 assert(
Init->isDelegatingInitializer());
7547 if (!this->emitThis(InitExpr))
7549 if (!this->visitInitializerPop(
Init->getInit()))
7553 if (!
Scope.destroyLocals())
7557 if (FieldInits !=
R->getNumFields()) {
7558 assert(FieldInits < R->getNumFields());
7560 if (!this->emitStartThisLifetime(Ctor))
7567 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7568 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7575 if (!visitStmt(Body))
7582template <
class Emitter>
7585 const Record *
R = this->getRecord(RD);
7589 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7590 if (!this->visitStmt(
Dtor->getBody()))
7594 if (!this->emitThis(
Dtor))
7597 if (!this->emitCheckDestruction(
Dtor))
7601 if (!
R->isUnion()) {
7605 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7609 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7611 if (!this->emitDestructionPop(D,
SourceInfo{}))
7616 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7617 if (
Base.R->hasTrivialDtor())
7621 if (!this->emitRecordDestructionPop(
Base.R, {}))
7625 if (
R->getNumVirtualBases() > 0) {
7626 LabelTy EndLabel = this->getLabel();
7628 if (!this->emitIsBaseClass({}))
7630 if (!this->jumpTrue(EndLabel, {}))
7633 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7634 if (
Base.R->hasTrivialDtor())
7639 if (!this->emitRecordDestructionPop(
Base.R, {}))
7643 this->fallthrough(EndLabel);
7644 this->emitLabel(EndLabel);
7647 if (!this->emitMarkDestroyed(
Dtor))
7650 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7653template <
class Emitter>
7654bool Compiler<Emitter>::compileUnionAssignmentOperator(
7656 if (!this->emitThis(MD))
7659 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7662 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7665template <
class Emitter>
7675 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7676 return this->compileConstructor(Ctor);
7677 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7678 return this->compileDestructor(
Dtor);
7681 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7686 return this->compileUnionAssignmentOperator(MD);
7689 return this->emitLambdaStaticInvokerBody(MD);
7693 if (
const auto *Body = F->
getBody())
7707 return FD->getBitWidthValue();
7710template <
class Emitter>
7726 if (!
Ctx.getLangOpts().CPlusPlus14)
7727 return this->emitInvalid(E);
7729 return this->emitError(E);
7731 if (!this->
visit(SubExpr))
7735 if (!this->emitIncPtr(E))
7742 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7743 : this->emitIncf(getFPOptions(E), E);
7755 if (!
Ctx.getLangOpts().CPlusPlus14)
7756 return this->emitInvalid(E);
7758 return this->emitError(E);
7760 if (!this->
visit(SubExpr))
7764 if (!this->emitDecPtr(E))
7771 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7772 : this->emitDecf(getFPOptions(E), E);
7785 if (!
Ctx.getLangOpts().CPlusPlus14)
7786 return this->emitInvalid(E);
7788 return this->emitError(E);
7790 if (!this->
visit(SubExpr))
7794 if (!this->emitLoadPtr(E))
7796 if (!this->emitConstUint8(1, E))
7798 if (!this->emitAddOffsetUint8(E))
7800 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7806 return this->emitIncfPop(getFPOptions(E), E);
7816 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7817 if (!this->emitLoadFloat(E))
7819 APFloat F(TargetSemantics, 1);
7820 if (!this->emitFloat(F, E))
7823 if (!this->emitAddf(getFPOptions(E), E))
7825 if (!this->emitStoreFloat(E))
7837 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7840 if (!
Ctx.getLangOpts().CPlusPlus14)
7841 return this->emitInvalid(E);
7843 return this->emitError(E);
7845 if (!this->
visit(SubExpr))
7849 if (!this->emitLoadPtr(E))
7851 if (!this->emitConstUint8(1, E))
7853 if (!this->emitSubOffsetUint8(E))
7855 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7861 return this->emitDecfPop(getFPOptions(E), E);
7871 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7872 if (!this->emitLoadFloat(E))
7874 APFloat F(TargetSemantics, 1);
7875 if (!this->emitFloat(F, E))
7878 if (!this->emitSubf(getFPOptions(E), E))
7880 if (!this->emitStoreFloat(E))
7892 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7896 return this->emitError(E);
7899 return this->
discard(SubExpr);
7904 if (!this->emitInv(E))
7908 return this->emitCast(
PT_Bool, ET, E);
7912 return this->emitError(E);
7914 if (!this->
visit(SubExpr))
7919 return this->emitError(E);
7921 if (!this->
visit(SubExpr))
7937 if (!
Ctx.getLangOpts().CPlusPlus) {
7939 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7940 Deref && Deref->getOpcode() == UO_Deref)
7941 return this->
delegate(Deref->getSubExpr());
7947 return this->
discard(SubExpr);
7949 if (!this->
visit(SubExpr))
7956 return this->emitNarrowPtr(E);
7961 return this->emitError(E);
7963 if (!this->
visit(SubExpr))
7977 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
7982 assert(
false &&
"Unhandled opcode");
7988template <
class Emitter>
7994 return this->
discard(SubExpr);
7997 auto prepareResult = [=]() ->
bool {
8002 return this->emitGetPtrLocal(*LocalIndex, E);
8009 unsigned SubExprOffset = ~0u;
8010 auto createTemp = [=, &SubExprOffset]() ->
bool {
8013 if (!this->
visit(SubExpr))
8015 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8019 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8020 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8022 return this->emitArrayElemPop(ElemT, Index, E);
8027 if (!prepareResult())
8031 for (
unsigned I = 0; I != 2; ++I) {
8032 if (!getElem(SubExprOffset, I))
8034 if (!this->emitNeg(ElemT, E))
8036 if (!this->emitInitElem(ElemT, I, E))
8047 if (!this->
visit(SubExpr))
8049 if (!this->emitComplexBoolCast(SubExpr))
8051 if (!this->emitInv(E))
8054 return this->emitCast(
PT_Bool, ET, E);
8058 return this->emitComplexReal(SubExpr);
8061 if (!this->
visit(SubExpr))
8065 if (!this->emitConstUint8(1, E))
8067 return this->emitArrayElemPtrPopUint8(E);
8078 if (!this->emitArrayElem(ElemT, 1, E))
8080 if (!this->emitNeg(ElemT, E))
8082 if (!this->emitInitElem(ElemT, 1, E))
8090 return this->emitInvalid(E);
8096template <
class Emitter>
8102 return this->
discard(SubExpr);
8105 if (UnaryOp == UO_Extension)
8108 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8109 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8110 return this->emitInvalid(E);
8113 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8120 if (!this->emitGetPtrLocal(*LocalIndex, E))
8125 unsigned SubExprOffset =
8127 if (!this->
visit(SubExpr))
8129 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8134 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8135 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8137 return this->emitArrayElemPop(ElemT, Index, E);
8142 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8143 if (!getElem(SubExprOffset, I))
8145 if (!this->emitNeg(ElemT, E))
8147 if (!this->emitInitElem(ElemT, I, E))
8162 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8163 if (!getElem(SubExprOffset, I))
8166 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8168 if (!this->emitInv(E))
8170 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8172 if (!this->emitNeg(ElemT, E))
8174 if (ElemT != ResultVecElemT &&
8175 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8177 if (!this->emitInitElem(ResultVecElemT, I, E))
8183 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8184 if (!getElem(SubExprOffset, I))
8187 if (!this->emitInv(E))
8190 if (!this->emitComp(ElemT, E))
8193 if (!this->emitInitElem(ElemT, I, E))
8198 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8203template <
class Emitter>
8205 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8208 return this->emitConst(ECD->getInitVal(), E);
8210 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8214 return F && this->emitGetFnPtr(F, E);
8216 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8217 TPOD = TPOD->getFirstDecl();
8221 return this->emitGetPtrGlobal(*GlobalIndex, E);
8227 return this->emitInitGlobal(*
T, *Index, E);
8230 if (!this->emitGetPtrGlobal(*Index, E))
8234 return this->emitFinishInit(E);
8246 auto maybePopPtr = [&]() ->
bool {
8248 return this->emitPopPtr(E);
8255 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8259 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8264 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8265 if (IsReference || !It->second.IsPtr)
8266 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8268 return this->emitGetPtrParam(It->second.Index, E);
8271 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8278 const unsigned Offset = It->second.Offset;
8281 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8283 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8286 if (
auto GlobalIndex =
P.getGlobal(D)) {
8288 if (!
Ctx.getLangOpts().CPlusPlus11)
8289 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8290 if (!
Ctx.getLangOpts().CPlusPlus23)
8291 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8293 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8296 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8300 auto revisit = [&](
const VarDecl *VD,
8301 bool IsConstexprUnknown =
true) ->
bool {
8303 IsConstexprUnknown);
8304 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8310 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8311 if (!this->emitPopCC(E))
8315 if (VarState.notCreated())
8323 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8325 if (
auto It = this->LambdaCaptures.find(D);
8326 It != this->LambdaCaptures.end()) {
8327 auto [Offset, IsPtr] = It->second;
8330 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8331 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8335 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8336 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8337 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8341 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8342 return this->
delegate(BD->getBinding());
8348 return this->emitDummyPtr(D, E);
8353 const auto *VD = dyn_cast<VarDecl>(D);
8355 return this->emitError(E);
8358 if (!
Ctx.getLangOpts().CPlusPlus) {
8362 return revisit(VD,
false);
8366 return this->emitDummyPtr(D, E);
8370 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8371 if (
T.isConstant(
Ctx.getASTContext()))
8373 return T->isReferenceType();
8377 typeShouldBeVisited(DeclType)) {
8379 Init && !
Init->isValueDependent()) {
8384 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8397 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8402 return revisit(VD, IsConstexprUnknown);
8403 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8404 return revisit(VD,
true);
8413 return this->emitDummyPtr(
8417template <
class Emitter>
8423template <
class Emitter>
8433 if (!
C->destroyLocals())
8439template <
class Emitter>
8440unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8443 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8445 return Ty->getAsCXXRecordDecl();
8447 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8448 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8450 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8454template <
class Emitter>
8461 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8466 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8467 getFPOptions(E), E);
8469 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8470 getFPOptions(E), E);
8474 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8479 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8481 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8485 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8489 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8490 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8497template <
class Emitter>
8500 assert(FromT != ToT);
8503 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8505 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8507 return this->emitCast(FromT, ToT, E);
8511template <
class Emitter>
8512bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8516 return this->
discard(SubExpr);
8518 if (!this->visit(SubExpr))
8521 if (!this->emitConstUint8(0, SubExpr))
8523 return this->emitArrayElemPtrPopUint8(SubExpr);
8527 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8531template <
class Emitter>
8532bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8533 assert(!DiscardResult);
8537 if (!this->emitArrayElem(ElemT, 0, E))
8540 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8543 if (!this->emitCast(ElemT,
PT_Bool, E))
8548 LabelTy LabelTrue = this->getLabel();
8549 if (!this->jumpTrue(LabelTrue, E))
8552 if (!this->emitArrayElemPop(ElemT, 1, E))
8555 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8558 if (!this->emitCast(ElemT,
PT_Bool, E))
8562 LabelTy EndLabel = this->getLabel();
8563 this->jump(EndLabel, E);
8565 this->emitLabel(LabelTrue);
8566 if (!this->emitPopPtr(E))
8568 if (!this->emitConstBool(
true, E))
8571 this->fallthrough(EndLabel);
8572 this->emitLabel(EndLabel);
8577template <
class Emitter>
8578bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8589 LHSIsComplex =
true;
8590 ElemT = classifyComplexElementType(LHS->
getType());
8591 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8592 if (!this->visit(LHS))
8594 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8597 LHSIsComplex =
false;
8599 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8600 if (!this->visit(LHS))
8602 if (!this->emitSetLocal(LHST, LHSOffset, E))
8609 RHSIsComplex =
true;
8610 ElemT = classifyComplexElementType(RHS->
getType());
8611 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8612 if (!this->visit(RHS))
8614 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8617 RHSIsComplex =
false;
8619 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8620 if (!this->visit(RHS))
8622 if (!this->emitSetLocal(RHST, RHSOffset, E))
8626 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8627 bool IsComplex) ->
bool {
8629 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8631 return this->emitArrayElemPop(ElemT, Index, E);
8633 return this->emitGetLocal(ElemT, LocalOffset, E);
8636 for (
unsigned I = 0; I != 2; ++I) {
8638 if (!getElem(LHSOffset, I, LHSIsComplex))
8640 if (!getElem(RHSOffset, I, RHSIsComplex))
8643 if (!this->emitEQ(ElemT, E))
8646 if (!this->emitCastBoolUint8(E))
8651 if (!this->emitAddUint8(E))
8653 if (!this->emitConstUint8(2, E))
8657 if (!this->emitEQUint8(E))
8660 if (!this->emitNEUint8(E))
8667 return this->emitCast(
PT_Bool, ResT, E);
8674template <
class Emitter>
8675bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8678 assert(!
R->hasTrivialDtor());
8681 const Function *DtorFunc = getFunction(
Dtor);
8684 assert(DtorFunc->hasThisPointer());
8685 assert(DtorFunc->getNumParams() == 1);
8686 return this->emitCall(DtorFunc, 0, Loc);
8691template <
class Emitter>
8692bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8704 return this->emitPopPtr(Loc);
8706 for (ssize_t I = N - 1; I >= 1; --I) {
8707 if (!this->emitConstUint64(I, Loc))
8709 if (!this->emitArrayElemPtrUint64(Loc))
8711 if (!this->emitDestructionPop(ElemDesc, Loc))
8715 if (!this->emitConstUint64(0, Loc))
8717 if (!this->emitArrayElemPtrPopUint64(Loc))
8719 return this->emitDestructionPop(ElemDesc, Loc);
8724 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8729template <
class Emitter>
8730bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8731 assert(!DiscardResult &&
"Should've been checked before");
8735 return this->emitGetOpaquePtr(VD, CU, E);
8738 unsigned DummyID = P.getOrCreateDummy(D, CU);
8739 if (!this->emitGetPtrGlobal(DummyID, E))
8747 return this->emitDecayPtr(
PT_Ptr, PT, E);
8753template <
class Emitter>
8756 return this->emitConstFloat(
Floating(F), Info);
8758 APInt I = F.bitcastToAPInt();
8759 return this->emitConstFloat(
8760 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8761 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8772template <
class Emitter>
8773bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8786 if (!this->emitGetPtrLocal(*LocalIndex, E))
8796 if (!this->visit(SubExpr))
8798 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8799 unsigned TempOffset =
8800 allocateLocalPrimitive(SubExpr, *FromT,
true);
8801 if (!this->visit(SubExpr))
8803 if (!this->emitSetLocal(*FromT, TempOffset, E))
8805 if (!this->emitGetPtrLocal(TempOffset, E))
8812 if (!this->emitBitCast(E))
8814 return DiscardResult ? this->emitPopPtr(E) :
true;
8818 const llvm::fltSemantics *TargetSemantics =
nullptr;
8820 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8826 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8828 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8829 ResultBitWidth, TargetSemantics,
8834 return this->emitPop(*ToT, E);
8843template <
class Emitter>
8844bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8849 unsigned NumElems = 0;
8852 NumElems = VT->getNumElements();
8853 ElemType = VT->getElementType();
8855 NumElems = MT->getNumElementsFlattened();
8856 ElemType = MT->getElementType();
8859 PrimType ElemT = classifyPrim(ElemType);
8860 for (
unsigned I = 0; I != NumElems; ++I) {
8861 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8863 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8865 if (!this->emitInitElem(ElemT, I, E))
8875 QualType ArrElemType = CAT->getElementType();
8876 unsigned ArrSize = CAT->getZExtSize();
8879 for (
unsigned I = 0; I != ArrSize; ++I) {
8880 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8882 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8884 if (!this->emitInitElem(*ElemT, I, E))
8888 for (
unsigned I = 0; I != ArrSize; ++I) {
8889 if (!this->emitConstUint32(I, E))
8891 if (!this->emitArrayElemPtrUint32(E))
8893 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8895 if (!this->emitFinishInitPop(E))
8905 const Record *
R = getRecord(DestType);
8909 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8911 const Record::Base *B =
R->getBase(BS.getType());
8913 if (!this->emitGetPtrBase(B->Offset, E))
8915 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8917 if (!this->emitFinishInitPop(E))
8922 for (
const Record::Field &F :
R->fields()) {
8923 if (F.isUnnamedBitField())
8926 QualType FieldType = F.Decl->getType();
8928 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8930 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8932 if (F.isBitField()) {
8933 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8936 if (!this->emitInitField(*FieldT, F.Offset, E))
8940 if (!this->emitGetPtrField(F.Offset, E))
8942 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8944 if (!this->emitPopPtr(E))
8957template <
class Emitter>
8958unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8961 return VT->getNumElements();
8963 return MT->getNumElementsFlattened();
8967 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8971 const Record *
R = getRecord(Ty);
8975 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8977 Count += countHLSLFlatElements(BS.getType());
8979 for (
const Record::Field &F :
R->fields()) {
8980 if (F.isUnnamedBitField())
8982 Count += countHLSLFlatElements(F.Decl->getType());
8987 if (canClassify(Ty))
8996template <
class Emitter>
8997bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8998 QualType SrcType,
unsigned SrcOffset,
9003 auto saveToLocal = [&](
PrimType T) ->
bool {
9004 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9005 if (!this->emitSetLocal(
T, Offset, E))
9007 Elements.push_back({Offset,
T});
9013 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9014 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9015 return std::nullopt;
9020 unsigned NumElems = 0;
9023 NumElems = VT->getNumElements();
9024 ElemType = VT->getElementType();
9026 NumElems = MT->getNumElementsFlattened();
9027 ElemType = MT->getElementType();
9030 PrimType ElemT = classifyPrim(ElemType);
9031 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9032 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9034 if (!this->emitArrayElemPop(ElemT, I, E))
9036 if (!saveToLocal(ElemT))
9046 QualType ArrElemType = CAT->getElementType();
9047 unsigned ArrSize = CAT->getZExtSize();
9050 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9051 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9053 if (!this->emitArrayElemPop(*ElemT, I, E))
9055 if (!saveToLocal(*ElemT))
9059 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9060 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9062 if (!this->emitConstUint32(I, E))
9064 if (!this->emitArrayElemPtrPopUint32(E))
9069 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9080 const Record *
R = getRecord(SrcType);
9084 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9086 if (Elements.size() >= MaxElements)
9088 const Record::Base *B =
R->getBase(BS.getType());
9090 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9092 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9097 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9103 for (
const Record::Field &F :
R->fields()) {
9104 if (Elements.size() >= MaxElements)
9106 if (F.isUnnamedBitField())
9109 QualType FieldType = F.Decl->getType();
9110 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9112 if (!this->emitGetPtrFieldPop(F.Offset, E))
9116 if (!this->emitLoadPop(*FieldT, E))
9118 if (!saveToLocal(*FieldT))
9122 if (!FieldPtrOffset)
9124 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9140template <
class Emitter>
9141bool Compiler<Emitter>::emitHLSLConstructAggregate(
9147 const auto &Src = Elements[ElemIdx++];
9148 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9150 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9154 unsigned NumElems = 0;
9157 NumElems = VT->getNumElements();
9158 ElemType = VT->getElementType();
9160 NumElems = MT->getNumElementsFlattened();
9161 ElemType = MT->getElementType();
9164 PrimType DestElemT = classifyPrim(ElemType);
9165 for (
unsigned I = 0; I != NumElems; ++I) {
9166 if (!loadAndCast(DestElemT, ElemType))
9168 if (!this->emitInitElem(DestElemT, I, E))
9178 QualType ArrElemType = CAT->getElementType();
9179 unsigned ArrSize = CAT->getZExtSize();
9182 for (
unsigned I = 0; I != ArrSize; ++I) {
9183 if (!loadAndCast(*ElemT, ArrElemType))
9185 if (!this->emitInitElem(*ElemT, I, E))
9189 for (
unsigned I = 0; I != ArrSize; ++I) {
9190 if (!this->emitConstUint32(I, E))
9192 if (!this->emitArrayElemPtrUint32(E))
9194 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9196 if (!this->emitFinishInitPop(E))
9206 const Record *
R = getRecord(DestType);
9210 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9212 const Record::Base *B =
R->getBase(BS.getType());
9214 if (!this->emitGetPtrBase(B->Offset, E))
9216 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9218 if (!this->emitFinishInitPop(E))
9223 for (
const Record::Field &F :
R->fields()) {
9224 if (F.isUnnamedBitField())
9227 QualType FieldType = F.Decl->getType();
9229 if (!loadAndCast(*FieldT, FieldType))
9231 if (F.isBitField()) {
9232 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9235 if (!this->emitInitField(*FieldT, F.Offset, E))
9239 if (!this->emitGetPtrField(F.Offset, E))
9241 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9243 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)
const Expr * ignorePointerCastsAndParens(const Expr *E)
A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. This ignores some c...
Result
Implement __builtin_bit_cast and related operations.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
APValue & getArrayFiller()
bool isIndeterminate() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
A rewritten comparison expression that was originally written using operator syntax.
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Represents the this expression in C++.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
CXXTryStmt - A C++ try block, including all handlers.
CompoundStmt * getTryBlock()
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
const FieldDecl * getTargetUnionField() const
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
bool isCompatibleWith(ClangABI Version) const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
bool isStoredAsComparisonResult() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
ArrayIndexScope(Compiler< Emitter > *Ctx, uint64_t Index)
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
const VarDecl * InitializingDecl
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const VarDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * 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)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...
EvalResult is a struct with detailed info about an evaluated expression.
const ValueDecl * asValueDecl() const
const Expr * asExpr() const
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink Base(unsigned Offset)
static InitLink Decl(const ValueDecl *D)
static InitLink Temp(unsigned Offset)
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()