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, {});
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) {
273 Ctx->InitStackActive = OldValue || Active;
279 this->Ctx->InitStackActive = OldValue;
281 Ctx->InitStack.pop_back();
295 OldInitializingDecl(
Ctx->InitializingDecl) {
296 Ctx->InitializingDecl = VD;
301 this->
Ctx->InitializingDecl = OldInitializingDecl;
302 this->
Ctx->InitStack.pop_back();
307 const VarDecl *OldInitializingDecl;
315 bool NewInitializing,
bool NewToLValue)
316 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
317 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
318 Ctx->DiscardResult = NewDiscardResult;
319 Ctx->Initializing = NewInitializing;
320 Ctx->ToLValue = NewToLValue;
324 Ctx->DiscardResult = OldDiscardResult;
325 Ctx->Initializing = OldInitializing;
326 Ctx->ToLValue = OldToLValue;
333 bool OldDiscardResult;
334 bool OldInitializing;
338template <
class Emitter>
342 return Ctx->emitThis(E);
345 return Ctx->emitGetPtrFieldPop(
Offset, E);
347 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
349 return Ctx->emitGetPtrLocal(
Offset, E);
353 if (!Ctx->emitConstUint32(
Offset, E))
355 return Ctx->emitArrayElemPtrPopUint32(E);
357 return Ctx->emitRVOPtr(E);
361 llvm_unreachable(
"Unhandled InitLink kind");
377 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
378 assert(LI.Name != Name);
381 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
402 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
404 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
405 assert(LI.Name != Name);
408 this->Ctx->CaseLabels = std::move(CaseLabels);
409 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
411 DefaultLabel, Ctx->VarScope);
415 this->Ctx->CaseLabels = std::move(OldCaseLabels);
416 this->Ctx->LabelInfoStack.pop_back();
421 CaseMap OldCaseLabels;
432 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
435 Ctx->LocOverride = NewValue;
440 Ctx->LocOverride = OldFlag;
445 std::optional<SourceInfo> OldFlag;
452template <
class Emitter>
460 case CK_LValueToRValue: {
463 if (!this->
visit(SubExpr))
465 return this->emitLoadPopL(E);
475 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
481 if (
auto GlobalIndex =
P.getGlobal(D))
482 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
483 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
484 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
485 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
486 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
487 return this->emitGetParam(*SubExprT, It->second.Index, E);
499 if (!this->emitGetPtrLocal(*LocalIndex, E))
503 if (!this->
visit(SubExpr))
507 return this->emitLoadPop(*SubExprT, E);
512 return this->emitMemcpy(E);
515 case CK_DerivedToBaseMemberPointer: {
526 ->getMostRecentCXXRecordDecl();
528 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
529 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
531 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
539 case CK_BaseToDerivedMemberPointer: {
550 ->getMostRecentCXXRecordDecl();
554 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
556 PathI != PathE; ++PathI) {
557 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
558 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
560 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
567 assert(ToDecl != CurDecl);
568 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
570 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
576 case CK_UncheckedDerivedToBase:
577 case CK_DerivedToBase: {
582 if (
const auto *PT = dyn_cast<PointerType>(Ty))
583 return PT->getPointeeType()->getAsCXXRecordDecl();
584 return Ty->getAsCXXRecordDecl();
591 if (B->isVirtual()) {
592 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
594 CurType = B->getType();
596 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
597 if (!this->emitGetPtrBasePop(
600 CurType = B->getType();
607 case CK_BaseToDerived: {
610 unsigned DerivedOffset =
616 return this->emitGetPtrDerivedPop(DerivedOffset,
621 case CK_FloatingCast: {
624 return this->emitVectorConversion(E->
getSubExpr(), E);
628 if (!this->
visit(SubExpr))
630 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
634 case CK_IntegralToFloating: {
636 return this->emitVectorConversion(E->
getSubExpr(), E);
639 if (!this->
visit(SubExpr))
641 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
642 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
643 TargetSemantics, getFPOptions(E), E);
646 case CK_FloatingToBoolean: {
648 return this->emitVectorConversion(E->
getSubExpr(), E);
652 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
653 return this->emitConstBool(FL->getValue().isNonZero(), E);
654 if (!this->
visit(SubExpr))
656 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
659 case CK_FloatingToIntegral: {
661 return this->emitVectorConversion(E->
getSubExpr(), E);
664 if (!this->
visit(SubExpr))
668 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
671 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
674 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
677 case CK_NullToPointer:
678 case CK_NullToMemberPointer: {
681 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
686 case CK_PointerToIntegral: {
687 if (!this->
visit(SubExpr))
693 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
699 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
701 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
702 return this->emitCastPointerIntegral(
T, E);
705 case CK_ArrayToPointerDecay: {
706 if (!this->
visit(SubExpr))
708 return this->emitArrayDecay(E);
711 case CK_IntegralToPointer: {
713 assert(IntType->isIntegralOrEnumerationType());
714 if (!this->
visit(SubExpr))
728 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
731 case CK_AtomicToNonAtomic:
732 case CK_ConstructorConversion:
733 case CK_FunctionToPointerDecay:
734 case CK_NonAtomicToAtomic:
736 case CK_UserDefinedConversion:
737 case CK_CPointerToObjCPointerCast:
740 case CK_AddressSpaceConversion: {
744 if (!this->
visit(SubExpr))
749 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
756 return this->emitPopPtr(E);
774 return this->emitBuiltinBitCast(E);
789 if (!this->
visit(SubExpr))
797 return this->emitFnPtrCast(E);
805 if (!this->
visit(SubExpr))
807 return this->emitDecayPtr(*FromT, *ToT, E);
809 case CK_IntegralToBoolean:
810 case CK_FixedPointToBoolean: {
812 return this->emitVectorConversion(E->
getSubExpr(), E);
818 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
819 return this->emitConst(IL->getValue(), E);
820 if (!this->
visit(SubExpr))
825 case CK_IntegralCast:
827 return this->emitVectorConversion(E->
getSubExpr(), E);
829 case CK_BooleanToSignedIntegral: {
836 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
841 if (!this->emitConst(IL->getValue(), SubExpr))
844 if (!this->
visit(SubExpr))
852 if (!ED->isFixed()) {
853 if (!this->emitCheckEnumValue(*FromT, ED, E))
859 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
862 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
867 if (!this->emitCast(*FromT, *ToT, E))
870 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
871 return this->emitNeg(*ToT, E);
875 case CK_PointerToBoolean:
876 if (!this->
visit(SubExpr))
878 return this->emitIsNonNullPtr(E);
880 case CK_MemberPointerToBoolean:
881 if (!this->
visit(SubExpr))
883 return this->emitIsNonNullMemberPtr(E);
885 case CK_IntegralComplexToBoolean:
886 case CK_FloatingComplexToBoolean: {
887 if (!this->
visit(SubExpr))
889 return this->emitComplexBoolCast(SubExpr);
892 case CK_IntegralComplexToReal:
893 case CK_FloatingComplexToReal:
894 return this->emitComplexReal(SubExpr);
896 case CK_IntegralRealToComplex:
897 case CK_FloatingRealToComplex: {
904 if (!this->emitGetPtrLocal(*LocalIndex, E))
913 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
915 return this->emitInitElem(
T, 1, SubExpr);
918 case CK_IntegralComplexCast:
919 case CK_FloatingComplexCast:
920 case CK_IntegralComplexToFloatingComplex:
921 case CK_FloatingComplexToIntegralComplex: {
928 if (!this->emitGetPtrLocal(*LocalIndex, E))
935 unsigned SubExprOffset =
937 if (!this->
visit(SubExpr))
939 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
947 for (
unsigned I = 0; I != 2; ++I) {
948 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
950 if (!this->emitArrayElemPop(SourceElemT, I, E))
954 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
958 if (!this->emitInitElem(DestElemT, I, E))
964 case CK_VectorSplat: {
975 if (!this->emitGetPtrLocal(*LocalIndex, E))
981 unsigned ElemOffset =
985 if (!this->
visit(SubExpr))
990 if (!this->emitSetLocal(ElemT, ElemOffset, E))
993 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
994 if (!this->emitGetLocal(ElemT, ElemOffset, E))
996 if (!this->emitInitElem(ElemT, I, E))
1003 case CK_HLSLVectorTruncation: {
1008 if (!this->
visit(SubExpr))
1010 return this->emitArrayElemPop(*ResultT, 0, E);
1019 if (!this->emitGetPtrLocal(*LocalIndex, E))
1024 if (!this->
visit(SubExpr))
1026 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1030 case CK_IntegralToFixedPoint: {
1031 if (!this->
visit(SubExpr))
1035 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1040 return this->emitPopFixedPoint(E);
1043 case CK_FloatingToFixedPoint: {
1044 if (!this->
visit(SubExpr))
1048 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1049 if (!this->emitCastFloatingFixedPoint(Sem, E))
1052 return this->emitPopFixedPoint(E);
1055 case CK_FixedPointToFloating: {
1056 if (!this->
visit(SubExpr))
1058 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1059 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1062 return this->emitPopFloat(E);
1065 case CK_FixedPointToIntegral: {
1066 if (!this->
visit(SubExpr))
1069 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1072 return this->emitPop(IntegralT, E);
1075 case CK_FixedPointCast: {
1076 if (!this->
visit(SubExpr))
1079 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1080 if (!this->emitCastFixedPoint(Sem, E))
1083 return this->emitPopFixedPoint(E);
1091 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1093 case CK_LValueBitCast:
1098 case CK_HLSLArrayRValue: {
1105 if (!this->emitGetPtrLocal(*LocalIndex, E))
1108 if (!this->
visit(SubExpr))
1110 return this->emitMemcpy(E);
1113 case CK_HLSLMatrixTruncation: {
1118 if (!this->
visit(SubExpr))
1120 return this->emitArrayElemPop(*ResultT, 0, E);
1129 if (!this->emitGetPtrLocal(*LocalIndex, E))
1134 if (!this->
visit(SubExpr))
1136 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1140 case CK_HLSLAggregateSplatCast: {
1150 if (!this->emitGetPtrLocal(*LocalIndex, E))
1157 unsigned SrcOffset =
1160 if (!this->
visit(SubExpr))
1162 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1166 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1169 case CK_HLSLElementwiseCast: {
1180 unsigned SrcPtrOffset =
1182 if (!this->
visit(SubExpr))
1184 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1188 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1190 if (Elements.empty())
1193 const HLSLFlatElement &Src = Elements[0];
1194 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1196 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1203 if (!this->emitGetPtrLocal(*LocalIndex, E))
1207 unsigned SrcOffset =
1209 if (!this->
visit(SubExpr))
1211 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1215 unsigned ElemCount = countHLSLFlatElements(DestType);
1218 Elements.reserve(ElemCount);
1219 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1224 assert(Elements.size() == ElemCount &&
1225 "Source type has fewer scalar elements than the destination type");
1227 return emitHLSLConstructAggregate(DestType, Elements, E);
1234 const Record::Field *RF = R->getField(UnionField);
1237 if (!this->
visit(SubExpr))
1239 if (RF->isBitField())
1240 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1242 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1245 if (!this->emitGetPtrField(RF->Offset, E))
1247 if (!this->emitActivate(E))
1253 return this->emitInvalid(E);
1255 llvm_unreachable(
"Unhandled clang::CastKind enum");
1258template <
class Emitter>
1260 return this->emitBuiltinBitCast(E);
1263template <
class Emitter>
1268 return this->emitConst(
LE->getValue(),
LE);
1271template <
class Emitter>
1277 return this->emitFloat(F, E);
1280template <
class Emitter>
1290 if (!this->emitGetPtrLocal(*LocalIndex, E))
1297 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1299 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1304template <
class Emitter>
1312 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1317template <
class Emitter>
1322template <
class Emitter>
1349 return this->emitComplexComparison(LHS, RHS, E);
1357 if (!this->
visit(LHS))
1360 if (!this->
visit(RHS))
1363 if (!this->emitToMemberPtr(E))
1369 if (!this->emitCastMemberPtrPtr(E))
1386 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1392 if (!this->emitGetPtrLocal(*ResultIndex, E))
1399 return this->emitCMP3(*
LT, CmpInfo, E);
1402 if (!
LT || !RT || !
T)
1412 return this->visitAssignment(LHS, RHS, E);
1419 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1423 return this->emitPopBool(E);
1425 return this->emitCast(
PT_Bool, *
T, E);
1429 auto Discard = [
this,
T, E](
bool Result) {
1437 return MaybeCastToBool(this->emitEQ(*
LT, E));
1439 return MaybeCastToBool(this->emitNE(*
LT, E));
1441 return MaybeCastToBool(this->emitLT(*
LT, E));
1443 return MaybeCastToBool(this->emitLE(*
LT, E));
1445 return MaybeCastToBool(this->emitGT(*
LT, E));
1447 return MaybeCastToBool(this->emitGE(*
LT, E));
1450 return Discard(this->emitSubf(getFPOptions(E), E));
1451 return Discard(this->emitSub(*
T, E));
1454 return Discard(this->emitAddf(getFPOptions(E), E));
1455 return Discard(this->emitAdd(*
T, E));
1458 return Discard(this->emitMulf(getFPOptions(E), E));
1459 return Discard(this->emitMul(*
T, E));
1461 return Discard(this->emitRem(*
T, E));
1464 return Discard(this->emitDivf(getFPOptions(E), E));
1465 return Discard(this->emitDiv(*
T, E));
1467 return Discard(this->emitBitAnd(*
T, E));
1469 return Discard(this->emitBitOr(*
T, E));
1471 return Discard(this->emitShl(*
LT, *RT, E));
1473 return Discard(this->emitShr(*
LT, *RT, E));
1475 return Discard(this->emitBitXor(*
T, E));
1478 llvm_unreachable(
"Already handled earlier");
1483 llvm_unreachable(
"Unhandled binary op");
1488template <
class Emitter>
1494 if ((Op != BO_Add && Op != BO_Sub) ||
1505 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1506 if (!this->
visit(E))
1509 return this->emitDecayPtr(
T,
PT_Ptr, E);
1518 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1526 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1529 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1536 if (!visitAsPointer(RHS, *RT))
1538 if (!this->
visit(LHS))
1542 if (!visitAsPointer(LHS, *
LT))
1544 if (!this->
visit(RHS))
1555 if (!this->emitAddOffset(OffsetType, E))
1559 if (!this->emitSubOffset(OffsetType, E))
1568 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1573 return this->emitPop(ExprT, E);
1577template <
class Emitter>
1586 LabelTy LabelTrue = this->getLabel();
1587 LabelTy LabelEnd = this->getLabel();
1591 if (!this->jumpTrue(LabelTrue, E))
1596 if (!this->jump(LabelEnd, E))
1599 this->emitLabel(LabelTrue);
1600 this->emitConstBool(
true, E);
1601 this->fallthrough(LabelEnd);
1602 this->emitLabel(LabelEnd);
1605 assert(Op == BO_LAnd);
1608 LabelTy LabelFalse = this->getLabel();
1609 LabelTy LabelEnd = this->getLabel();
1613 if (!this->jumpFalse(LabelFalse, E))
1618 if (!this->jump(LabelEnd, E))
1621 this->emitLabel(LabelFalse);
1622 this->emitConstBool(
false, E);
1623 this->fallthrough(LabelEnd);
1624 this->emitLabel(LabelEnd);
1628 return this->emitPopBool(E);
1633 return this->emitCast(
PT_Bool,
T, E);
1638template <
class Emitter>
1645 if (!this->emitGetPtrLocal(*LocalIndex, E))
1654 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1655 unsigned ResultOffset = ~0u;
1661 if (!this->emitDupPtr(E))
1663 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1668 LHSType = AT->getValueType();
1671 RHSType = AT->getValueType();
1680 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1685 if (!this->
visit(LHS))
1687 if (!this->
visit(RHS))
1689 if (!this->emitMulc(ElemT, E))
1692 return this->emitPopPtr(E);
1696 if (Op == BO_Div && RHSIsComplex) {
1703 if (!LHSIsComplex) {
1708 LHSOffset = *LocalIndex;
1710 if (!this->emitGetPtrLocal(LHSOffset, E))
1713 if (!this->
visit(LHS))
1716 if (!this->emitInitElem(ElemT, 0, E))
1719 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1721 if (!this->emitInitElem(ElemT, 1, E))
1724 if (!this->
visit(LHS))
1728 if (!this->
visit(RHS))
1730 if (!this->emitDivc(ElemT, E))
1733 return this->emitPopPtr(E);
1740 if (!this->
visit(LHS))
1742 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1747 if (!this->
visit(LHS))
1749 if (!this->emitSetLocal(LHST, LHSOffset, E))
1757 if (!this->
visit(RHS))
1759 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1764 if (!this->
visit(RHS))
1766 if (!this->emitSetLocal(RHST, RHSOffset, E))
1773 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1774 unsigned ElemIndex,
unsigned Offset,
1775 const Expr *E) ->
bool {
1777 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1779 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1782 if (ElemIndex == 0 || !LoadZero)
1789 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1792 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1799 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1802 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1805 if (!this->emitAddf(getFPOptions(E), E))
1808 if (!this->emitAdd(ResultElemT, E))
1813 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1816 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1819 if (!this->emitSubf(getFPOptions(E), E))
1822 if (!this->emitSub(ResultElemT, E))
1827 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1830 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1834 if (!this->emitMulf(getFPOptions(E), E))
1837 if (!this->emitMul(ResultElemT, E))
1842 assert(!RHSIsComplex);
1843 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1846 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1850 if (!this->emitDivf(getFPOptions(E), E))
1853 if (!this->emitDiv(ResultElemT, E))
1864 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1867 if (!this->emitPop(ResultElemT, E))
1872 return this->emitPopPtr(E);
1878template <
class Emitter>
1883 "Comma op should be handled in VisitBinaryOperator");
1887 LHSType = AT->getValueType();
1890 RHSType = AT->getValueType();
1904 if (!this->emitGetPtrLocal(*LocalIndex, E))
1913 PrimType ElemT = this->classifyVectorElementType(LHSType);
1914 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1918 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1921 if (!this->
visit(LHS))
1923 if (!this->
visit(RHS))
1925 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1928 return this->emitPopPtr(E);
1933 unsigned LHSOffset =
1935 if (!this->
visit(LHS))
1937 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1941 unsigned RHSOffset =
1943 if (!this->
visit(RHS))
1945 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1957 if (NeedIntPromot) {
1959 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1964 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1965 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1967 if (!this->emitArrayElemPop(ElemT, Index, E))
1970 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1972 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1974 }
else if (NeedIntPromot) {
1975 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1981#define EMIT_ARITH_OP(OP) \
1983 if (ElemT == PT_Float) { \
1984 if (!this->emit##OP##f(getFPOptions(E), E)) \
1987 if (!this->emit##OP(ElemT, E)) \
1993 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1994 if (!getElem(LHSOffset, ElemT, I))
1996 if (!getElem(RHSOffset, RHSElemT, I))
2008 if (!this->emitRem(ElemT, E))
2012 if (!this->emitBitAnd(OpT, E))
2016 if (!this->emitBitOr(OpT, E))
2020 if (!this->emitBitXor(OpT, E))
2024 if (!this->emitShl(OpT, RHSElemT, E))
2028 if (!this->emitShr(OpT, RHSElemT, E))
2032 if (!this->emitEQ(ElemT, E))
2036 if (!this->emitNE(ElemT, E))
2040 if (!this->emitLE(ElemT, E))
2044 if (!this->emitLT(ElemT, E))
2048 if (!this->emitGE(ElemT, E))
2052 if (!this->emitGT(ElemT, E))
2057 if (!this->emitBitAnd(ResultElemT, E))
2062 if (!this->emitBitOr(ResultElemT, E))
2066 return this->emitInvalid(E);
2075 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2077 if (!this->emitNeg(ResultElemT, E))
2083 if (NeedIntPromot &&
2084 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2088 if (!this->emitInitElem(ResultElemT, I, E))
2097template <
class Emitter>
2107 auto LHSSemaInt = LHSSema.toOpaqueInt();
2109 auto RHSSemaInt = RHSSema.toOpaqueInt();
2111 if (!this->
visit(LHS))
2119 if (!this->
visit(RHS))
2128 auto ConvertResult = [&](
bool R) ->
bool {
2132 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2133 if (ResultSema != CommonSema)
2134 return this->emitCastFixedPoint(ResultSema, E);
2138 auto MaybeCastToBool = [&](
bool Result) {
2143 return this->emitPop(
T, E);
2145 return this->emitCast(
PT_Bool,
T, E);
2151 return MaybeCastToBool(this->emitEQFixedPoint(E));
2153 return MaybeCastToBool(this->emitNEFixedPoint(E));
2155 return MaybeCastToBool(this->emitLTFixedPoint(E));
2157 return MaybeCastToBool(this->emitLEFixedPoint(E));
2159 return MaybeCastToBool(this->emitGTFixedPoint(E));
2161 return MaybeCastToBool(this->emitGEFixedPoint(E));
2163 return ConvertResult(this->emitAddFixedPoint(E));
2165 return ConvertResult(this->emitSubFixedPoint(E));
2167 return ConvertResult(this->emitMulFixedPoint(E));
2169 return ConvertResult(this->emitDivFixedPoint(E));
2171 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2173 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2176 return this->emitInvalid(E);
2179 llvm_unreachable(
"unhandled binop opcode");
2182template <
class Emitter>
2191 if (!this->
visit(SubExpr))
2193 if (!this->emitNegFixedPoint(E))
2196 return this->emitPopFixedPoint(E);
2202 llvm_unreachable(
"Unhandled unary opcode");
2205template <
class Emitter>
2214 return this->visitZeroInitializer(*
T, QT, E);
2227 return this->visitZeroRecordInitializer(R, E);
2234 return this->visitZeroArrayInitializer(QT, E);
2238 QualType ElemQT = ComplexTy->getElementType();
2240 for (
unsigned I = 0; I < 2; ++I) {
2241 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2243 if (!this->emitInitElem(ElemT, I, E))
2250 unsigned NumVecElements = VecT->getNumElements();
2251 QualType ElemQT = VecT->getElementType();
2254 for (
unsigned I = 0; I < NumVecElements; ++I) {
2255 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2257 if (!this->emitInitElem(ElemT, I, E))
2264 unsigned NumElems = MT->getNumElementsFlattened();
2265 QualType ElemQT = MT->getElementType();
2268 for (
unsigned I = 0; I != NumElems; ++I) {
2269 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2271 if (!this->emitInitElem(ElemT, I, E))
2280template <
class Emitter>
2293 for (
const Expr *SubExpr : {LHS, RHS}) {
2294 if (!this->
visit(SubExpr)) {
2301 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2302 if (!this->emitExpandPtr(E))
2313 return this->emitError(E);
2316 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2320 if (!this->emitArrayElemPtrPop(*IndexT, E))
2323 return this->emitPopPtr(E);
2329 return this->emitLoadPop(*
T, E);
2332template <
class Emitter>
2334 const Expr *ArrayFiller,
const Expr *E) {
2339 QT = AT->getValueType();
2342 if (
Inits.size() == 0)
2344 return this->emitInvalid(E);
2357 if (
Inits.size() == 0)
2358 return this->visitZeroInitializer(*
T, QT, E);
2359 assert(
Inits.size() == 1);
2373 if (!this->emitGetPtrLocal(*LocalIndex, E))
2388 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2394 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2403 bool BitField = FieldToInit->isBitField();
2405 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2406 FieldToInit->bitWidth(), E);
2408 return this->emitInitBitField(
T, FieldToInit->Offset,
2409 FieldToInit->bitWidth(), E);
2411 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2412 return this->emitInitField(
T, FieldToInit->Offset, E);
2415 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2423 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2426 if (
Activate && !this->emitActivate(E))
2429 if (!this->emitStartInit(
Init))
2436 if (
Inits.size() == 0) {
2437 if (!this->visitZeroRecordInitializer(R, E))
2442 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2443 FToInit = ILE->getInitializedFieldInUnion();
2447 const Record::Field *FieldToInit = R->getField(FToInit);
2449 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2452 if (!initCompositeField(FieldToInit,
Init,
true))
2456 return this->emitFinishInit(E);
2459 assert(!R->isUnion());
2460 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2462 const Record::Base *B = R->getBase(BI);
2465 if (!this->emitGetPtrBase(B->Offset,
Init))
2471 unsigned FieldIndex = 0;
2472 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2473 const Record::Field *FieldToInit = R->getField(FieldIndex);
2474 if (FieldToInit->isUnnamedBitField()) {
2489 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2491 }
else if (!initCompositeField(FieldToInit,
Init)) {
2499 assert(R->getNumVirtualBases() == 0);
2501 return this->emitFinishInit(E);
2506 Ctx.getASTContext().getAsConstantArrayType(QT);
2511 !this->emitCheckArrayDestSize(NumElems, E))
2514 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2518 unsigned ElementIndex = 0;
2520 if (
const auto *EmbedS =
2521 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2529 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2530 getFPOptions(E), E))
2536 return this->emitInitElem(TargetT, ElemIndex, IL);
2538 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2554 for (; ElementIndex != NumElems; ++ElementIndex) {
2560 return this->emitFinishInit(E);
2564 unsigned NumInits =
Inits.size();
2569 QualType ElemQT = ComplexTy->getElementType();
2571 if (NumInits == 0) {
2573 for (
unsigned I = 0; I < 2; ++I) {
2574 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2576 if (!this->emitInitElem(ElemT, I, E))
2579 }
else if (NumInits == 2) {
2580 unsigned InitIndex = 0;
2585 if (!this->emitInitElem(ElemT, InitIndex, E))
2594 unsigned NumVecElements = VecT->getNumElements();
2595 assert(NumVecElements >=
Inits.size());
2597 QualType ElemQT = VecT->getElementType();
2601 unsigned InitIndex = 0;
2608 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2609 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2610 InitVecT->getNumElements(), E))
2612 InitIndex += InitVecT->getNumElements();
2614 if (!this->emitInitElem(ElemT, InitIndex, E))
2620 assert(InitIndex <= NumVecElements);
2623 for (; InitIndex != NumVecElements; ++InitIndex) {
2624 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2626 if (!this->emitInitElem(ElemT, InitIndex, E))
2633 unsigned NumElems = MT->getNumElementsFlattened();
2634 assert(
Inits.size() == NumElems);
2636 QualType ElemQT = MT->getElementType();
2642 for (
unsigned I = 0; I != NumElems; ++I) {
2645 if (!this->emitInitElem(ElemT, I, E))
2656template <
class Emitter>
2663 return this->emitInitElem(*InitT, ElemIndex,
Init);
2669 if (!this->emitConstUint32(ElemIndex,
Init))
2671 if (!this->emitArrayElemPtrUint32(
Init))
2676template <
class Emitter>
2679 bool Activate,
bool IsOperatorCall) {
2681 llvm::BitVector NonNullArgs;
2682 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2685 bool ExplicitMemberFn =
false;
2686 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2687 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2689 unsigned ArgIndex = 0;
2690 for (
const Expr *Arg : Args) {
2692 if (!this->
visit(Arg))
2700 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2701 if (DeclIndex < FuncDecl->getNumParams())
2702 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2711 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2719 if (!this->emitActivate(Arg))
2723 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2726 if (!this->emitCheckNonNullArg(ArgT, Arg))
2737template <
class Emitter>
2742template <
class Emitter>
2748template <
class Emitter>
2754template <
class Emitter>
2772template <
class Emitter>
2774 auto It = E->
begin();
2775 return this->
visit(*It);
2779 UnaryExprOrTypeTrait Kind) {
2780 bool AlignOfReturnsPreferred =
2787 T = Ref->getPointeeType();
2789 if (
T.getQualifiers().hasUnaligned())
2795 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2801template <
class Emitter>
2805 UnaryExprOrTypeTrait Kind = E->
getKind();
2808 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2814 ArgType = Ref->getPointeeType();
2820 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2821 return this->emitInvalid(E);
2823 if (Kind == UETT_SizeOf)
2832 return this->emitConst(Size.getQuantity(), E);
2835 if (Kind == UETT_CountOf) {
2841 if (
const auto *CAT =
2845 return this->emitConst(CAT->getSize(), E);
2855 if (VAT->getElementType()->isArrayType()) {
2856 std::optional<APSInt> Res =
2858 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2863 return this->emitConst(*Res, E);
2868 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2888 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2891 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2901 return this->emitConst(Size.getQuantity(), E);
2904 if (Kind == UETT_VectorElements) {
2909 return this->emitConst(VT->getNumElements(), E);
2911 return this->emitSizelessVectorElementSize(E);
2914 if (Kind == UETT_VecStep) {
2916 unsigned N = VT->getNumElements();
2923 return this->emitConst(N, E);
2925 return this->emitConst(1, E);
2928 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2937 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2939 return this->emitInvalid(E);
2941 return this->emitConst(
2942 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2950template <
class Emitter>
2959 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2964 if (VD->getInit() && !VD->getInit()->isValueDependent())
2965 VD->evaluateValue();
2966 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2967 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2969 if (
Member->getType()->isReferenceType())
2970 return this->emitLoadPopPtr(E);
2979 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2980 MD && !MD->isStatic()) {
2984 if (!this->
discard(Base) && !this->emitSideEffect(E))
2999 const Record::Field *F = R->getField(FD);
3003 const auto maybeLoadValue = [&]() ->
bool {
3007 return this->emitLoadPop(*
T, E);
3012 if (F->Decl->getType()->isReferenceType())
3013 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3014 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3017template <
class Emitter>
3027template <
class Emitter>
3041 if (!this->
visit(Common))
3043 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3057 for (
size_t I = 0; I != Size; ++I) {
3069template <
class Emitter>
3084 return this->emitGetLocal(SubExprT, It->second, E);
3087 if (!this->
visit(SourceExpr))
3094 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3103 return this->emitGetLocal(SubExprT, LocalIndex, E);
3107template <
class Emitter>
3120 bool IsBcpCall =
false;
3121 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3122 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3126 LabelTy LabelEnd = this->getLabel();
3127 LabelTy LabelFalse = this->getLabel();
3130 if (!this->emitPushIgnoreDiags(E))
3138 if (this->checkingForUndefinedBehavior()) {
3141 if (!this->
discard(FalseExpr))
3158 if (!this->jumpFalse(LabelFalse, E))
3163 if (!this->jump(LabelEnd, E))
3165 this->emitLabel(LabelFalse);
3169 this->fallthrough(LabelEnd);
3170 this->emitLabel(LabelEnd);
3173 return this->emitPopIgnoreDiags(E);
3177template <
class Emitter>
3183 return this->emitGetStringPtr(E, E);
3187 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3188 assert(CAT &&
"a string literal that's not a constant array?");
3193 unsigned N = std::min(ArraySize, E->
getLength());
3196 for (
unsigned I = 0; I != N; ++I) {
3199 if (CharWidth == 1) {
3200 this->emitConstSint8(CodeUnit, E);
3201 this->emitInitElemSint8(I, E);
3202 }
else if (CharWidth == 2) {
3203 this->emitConstUint16(CodeUnit, E);
3204 this->emitInitElemUint16(I, E);
3205 }
else if (CharWidth == 4) {
3206 this->emitConstUint32(CodeUnit, E);
3207 this->emitInitElemUint32(I, E);
3209 llvm_unreachable(
"unsupported character width");
3214 for (
unsigned I = N; I != ArraySize; ++I) {
3215 if (CharWidth == 1) {
3216 this->emitConstSint8(0, E);
3217 this->emitInitElemSint8(I, E);
3218 }
else if (CharWidth == 2) {
3219 this->emitConstUint16(0, E);
3220 this->emitInitElemUint16(I, E);
3221 }
else if (CharWidth == 4) {
3222 this->emitConstUint32(0, E);
3223 this->emitInitElemUint32(I, E);
3225 llvm_unreachable(
"unsupported character width");
3232template <
class Emitter>
3236 return this->emitDummyPtr(E, E);
3239template <
class Emitter>
3241 auto &A =
Ctx.getASTContext();
3250template <
class Emitter>
3258 auto &A =
Ctx.getASTContext();
3262 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3263 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3269 return this->emitGetStringPtr(SL, E);
3272template <
class Emitter>
3276 return this->emitConst(E->
getValue(), E);
3279template <
class Emitter>
3301 if (!this->emitLoad(LHST, E))
3304 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3305 LHSComputationType, E))
3317 unsigned TempOffset =
3319 if (!this->emitSetLocal(*RT, TempOffset, E))
3325 if (!this->emitLoad(LHST, E))
3329 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3330 LHSComputationType, E))
3334 if (!this->emitGetLocal(*RT, TempOffset, E))
3340 if (!this->emitAddf(getFPOptions(E), E))
3344 if (!this->emitSubf(getFPOptions(E), E))
3348 if (!this->emitMulf(getFPOptions(E), E))
3352 if (!this->emitDivf(getFPOptions(E), E))
3363 return this->emitStorePop(LHST, E);
3364 return this->emitStore(LHST, E);
3367template <
class Emitter>
3376 if (Op != BO_AddAssign && Op != BO_SubAssign)
3385 if (!this->emitLoad(*
LT, LHS))
3391 if (Op == BO_AddAssign) {
3392 if (!this->emitAddOffset(*RT, E))
3395 if (!this->emitSubOffset(*RT, E))
3400 return this->emitStorePopPtr(E);
3401 return this->emitStorePtr(E);
3404template <
class Emitter>
3417 if (!
Ctx.getLangOpts().CPlusPlus14)
3418 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3420 if (!
LT || !RT || !ResultT || !LHSComputationT)
3437 if (!this->emitLoad(*
LT, E))
3439 if (
LT != LHSComputationT &&
3440 !this->emitIntegralCast(*
LT, *LHSComputationT,
3454 unsigned TempOffset =
3457 if (!this->emitSetLocal(*RT, TempOffset, E))
3464 if (!this->emitLoad(*
LT, E))
3466 if (
LT != LHSComputationT &&
3467 !this->emitIntegralCast(*
LT, *LHSComputationT,
3472 if (!this->emitGetLocal(*RT, TempOffset, E))
3479 if (!this->emitAdd(*LHSComputationT, E))
3483 if (!this->emitSub(*LHSComputationT, E))
3487 if (!this->emitMul(*LHSComputationT, E))
3491 if (!this->emitDiv(*LHSComputationT, E))
3495 if (!this->emitRem(*LHSComputationT, E))
3499 if (!this->emitShl(*LHSComputationT, *RT, E))
3503 if (!this->emitShr(*LHSComputationT, *RT, E))
3507 if (!this->emitBitAnd(*LHSComputationT, E))
3511 if (!this->emitBitXor(*LHSComputationT, E))
3515 if (!this->emitBitOr(*LHSComputationT, E))
3519 llvm_unreachable(
"Unimplemented compound assign operator");
3523 if (ResultT != LHSComputationT &&
3524 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3530 return this->emitStoreBitFieldPop(*ResultT, E);
3531 return this->emitStorePop(*ResultT, E);
3534 return this->emitStoreBitField(*ResultT, E);
3535 return this->emitStore(*ResultT, E);
3538template <
class Emitter>
3546template <
class Emitter>
3561 if (!
Ctx.getLangOpts().CPlusPlus11)
3568 for (
const Expr *LHS : CommaLHSs) {
3583 if (this->constantFolding())
3594 if (!this->
visit(Inner))
3599 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3602 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3605 return this->emitGetPtrGlobal(*GlobalIndex, E);
3608 if (!this->checkLiteralType(Inner))
3611 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3617 return this->emitInitGlobalTempComp(TempDecl, E);
3630 unsigned LocalIndex =
3632 if (!this->VarScope->LocalsAlwaysEnabled &&
3633 !this->emitEnableLocal(LocalIndex, E))
3636 if (!this->
visit(Inner))
3638 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3641 return this->emitGetPtrLocal(LocalIndex, E);
3644 if (!this->checkLiteralType(Inner))
3651 if (!this->VarScope->LocalsAlwaysEnabled &&
3652 !this->emitEnableLocal(*LocalIndex, E))
3655 if (!this->emitGetPtrLocal(*LocalIndex, E))
3662template <
class Emitter>
3673 if (!this->
visit(SubExpr))
3677 return this->emitPopPtr(E);
3681template <
class Emitter>
3702 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3707 if (
P.isGlobalInitialized(*GlobalIndex))
3713 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3725 unsigned LocalIndex;
3729 LocalIndex = *MaybeIndex;
3733 if (!this->emitGetPtrLocal(LocalIndex, E))
3737 return this->
visit(
Init) && this->emitInit(*
T, E);
3741template <
class Emitter>
3752 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3756 if (!R || R->getNumFields() == 0)
3758 const Record::Field *Field = R->getField(0
U);
3763 return this->emitInitField(*Field->T, Field->Offset, E);
3770template <
class Emitter>
3774 return this->emitConst(E->
getValue(), E);
3777template <
class Emitter>
3790 for (
const Record::Field &F : R->fields()) {
3792 if (!
Init ||
Init->containsErrors())
3800 if (!this->emitInitField(*
T, F.Offset, E))
3803 if (!this->emitGetPtrField(F.Offset, E))
3814template <
class Emitter>
3820 return this->emitGetStringPtr(E, E);
3824template <
class Emitter>
3829 return this->emitInvalid(E);
3832template <
class Emitter>
3846 if (!this->emitInvalidCast(
CastKind,
false, E))
3854 bool Fatal = (ToT != FromT);
3861template <
class Emitter>
3863 if (!
Ctx.getLangOpts().CPlusPlus20) {
3884 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3889 return this->emitPopPtr(E);
3893template <
class Emitter>
3899 return this->emitConstBool(E->
getValue(), E);
3902template <
class Emitter>
3907 if (
T->isRecordType()) {
3921 if (!this->emitGetPtrLocal(*LocalIndex, E))
3929 T->getAsCXXRecordDecl()))
3939 if (!this->visitZeroRecordInitializer(R, E))
3950 if (!this->emitDefaultInit(Ctor, E))
3953 return this->emitPopPtr(E);
3961 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3963 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3964 if (!this->emitCheckFunctionDecl(Ctor, E))
3975 assert(
Func->hasThisPointer());
3976 assert(!
Func->hasRVO());
3980 if (!this->emitDupPtr(E))
3984 for (
const auto *Arg : E->
arguments()) {
3985 if (!this->
visit(Arg))
3989 if (
Func->isVariadic()) {
3990 uint32_t VarArgSize = 0;
3991 unsigned NumParams =
Func->getNumWrittenParams();
3992 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3996 if (!this->emitCallVar(
Func, VarArgSize, E))
3999 if (!this->emitCall(
Func, 0, E)) {
4004 (void)this->emitPopPtr(E);
4010 return this->emitPopPtr(E);
4014 if (
T->isArrayType()) {
4019 if (!this->emitDupPtr(E))
4023 initArrayDimension = [&](
QualType T) ->
bool {
4024 if (!
T->isArrayType()) {
4026 for (
const auto *Arg : E->
arguments()) {
4027 if (!this->
visit(Arg))
4031 return this->emitCall(
Func, 0, E);
4035 Ctx.getASTContext().getAsConstantArrayType(
T);
4040 for (
size_t I = 0; I != NumElems; ++I) {
4041 if (!this->emitConstUint64(I, E))
4043 if (!this->emitArrayElemPtrUint64(E))
4045 if (!initArrayDimension(ElemTy))
4048 return this->emitPopPtr(E);
4051 return initArrayDimension(E->
getType());
4057template <
class Emitter>
4067 assert(Val.
isInt());
4069 return this->emitConst(I, E);
4076 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4077 return this->
visit(LValueExpr);
4092 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4096 const APValue &
V = UGCD->getValue();
4097 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4098 const Record::Field *F = R->getField(I);
4099 const APValue &FieldValue =
V.getStructField(I);
4103 if (!this->emitInitField(*F->T, F->Offset, E))
4111template <
class Emitter>
4117 for (
unsigned I = 0; I != N; ++I) {
4124 if (!this->
discard(ArrayIndexExpr))
4130 if (!this->
visit(ArrayIndexExpr))
4132 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4136 if (!this->
visit(ArrayIndexExpr))
4140 if (!this->emitCast(IndexT,
PT_Sint64, E))
4150 return this->emitOffsetOf(
T, E, E);
4153template <
class Emitter>
4162 return this->visitZeroInitializer(*
T, Ty, E);
4169 if (!this->emitGetPtrLocal(*LocalIndex, E))
4177 ElemQT = CT->getElementType();
4180 NumElems = VT->getNumElements();
4181 ElemQT = VT->getElementType();
4187 for (
unsigned I = 0; I != NumElems; ++I) {
4188 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4190 if (!this->emitInitElem(ElemT, I, E))
4199template <
class Emitter>
4204template <
class Emitter>
4210template <
class Emitter>
4215template <
class Emitter>
4220 return this->emitConst(E->
getValue(), E);
4223template <
class Emitter>
4228 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4243 unsigned ParamIndex = 0;
4247 if (!this->emitGetParam(PT, ParamIndex, E))
4252 return this->emitCall(F, 0, E);
4257template <
class Emitter>
4265 const Expr *PlacementDest =
nullptr;
4266 bool IsNoThrow =
false;
4271 if (PlacementArgs != 0) {
4280 if (PlacementArgs == 1) {
4288 if (!this->emitInvalidNewDeleteExpr(E, E))
4293 if (OperatorNew->isReservedGlobalPlacementOperator())
4294 PlacementDest = Arg1;
4298 return this->emitInvalid(E);
4300 }
else if (!OperatorNew
4301 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4302 return this->emitInvalidNewDeleteExpr(E, E);
4305 if (!PlacementDest) {
4310 Desc =
P.createDescriptor(E, *ElemT);
4312 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4319 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4323 const Expr *Stripped = *ArraySizeExpr;
4324 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4325 Stripped = ICE->getSubExpr())
4326 if (ICE->getCastKind() != CK_NoOp &&
4327 ICE->getCastKind() != CK_IntegralCast)
4335 if (!this->
visit(Stripped))
4337 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4340 if (PlacementDest) {
4341 if (!this->
visit(PlacementDest))
4343 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4345 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4348 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4353 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4357 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4364 size_t StaticInitElems = 0;
4365 const Expr *DynamicInit =
nullptr;
4369 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4370 StaticInitElems = CAT->getZExtSize();
4375 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4376 if (ILE->hasArrayFiller())
4377 DynamicInit = ILE->getArrayFiller();
4396 const Function *CtorFunc =
nullptr;
4397 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4401 }
else if (!DynamicInit && !ElemT)
4404 LabelTy EndLabel = this->getLabel();
4405 LabelTy StartLabel = this->getLabel();
4410 if (!this->emitDupPtr(E))
4412 if (!this->emitIsNonNullPtr(E))
4414 if (!this->jumpFalse(EndLabel, E))
4421 if (!this->emitConst(StaticInitElems,
SizeT, E))
4423 if (!this->emitSetLocal(
SizeT, Iter, E))
4426 this->fallthrough(StartLabel);
4427 this->emitLabel(StartLabel);
4429 if (!this->emitGetLocal(
SizeT, Iter, E))
4431 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4433 if (!this->emitLT(
SizeT, E))
4435 if (!this->jumpFalse(EndLabel, E))
4439 if (!this->emitGetLocal(
SizeT, Iter, E))
4441 if (!this->emitArrayElemPtr(
SizeT, E))
4444 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4449 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4451 if (!this->emitStorePop(*InitT, E))
4455 if (!this->visitZeroArrayInitializer(ElemType, E))
4458 }
else if (DynamicInit) {
4460 if (!this->
visit(DynamicInit))
4462 if (!this->emitStorePop(*InitT, E))
4469 if (!this->visitZeroInitializer(
4473 if (!this->emitStorePop(*ElemT, E))
4477 if (!this->emitCall(CtorFunc, 0, E))
4482 if (!this->emitGetPtrLocal(Iter, E))
4484 if (!this->emitIncPop(
SizeT,
false, E))
4487 if (!this->jump(StartLabel, E))
4490 this->fallthrough(EndLabel);
4491 this->emitLabel(EndLabel);
4495 if (PlacementDest) {
4496 if (!this->
visit(PlacementDest))
4498 if (!this->emitCheckNewTypeMismatch(E, E))
4503 if (!this->emitAlloc(Desc, E))
4512 if (!this->emitInit(*ElemT, E))
4523 return this->emitPopPtr(E);
4528template <
class Emitter>
4534 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4535 return this->emitInvalidNewDeleteExpr(E, E);
4544template <
class Emitter>
4550 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4555 return this->emitGetFnPtr(
Func, E);
4558template <
class Emitter>
4562 auto canonType = [](
const Type *
T) {
4563 return T->getCanonicalTypeUnqualified().getTypePtr();
4571 return this->emitGetTypeid(
4575 return this->emitGetTypeid(
4584 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4590 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4593 return this->emitPopPtr(E);
4597template <
class Emitter>
4601 return this->emitDummyPtr(E, E);
4602 return this->emitError(E);
4605template <
class Emitter>
4608 return this->emitDummyPtr(E, E);
4609 return this->emitError(E);
4612template <
class Emitter>
4614 assert(
Ctx.getLangOpts().CPlusPlus);
4615 return this->emitConstBool(E->
getValue(), E);
4618template <
class Emitter>
4630 return this->emitDummyPtr(GuidDecl, E);
4635 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4644 assert(
V.isStruct());
4645 assert(
V.getStructNumBases() == 0);
4649 return this->emitFinishInit(E);
4652template <
class Emitter>
4662template <
class Emitter>
4671template <
class Emitter>
4677template <
class Emitter>
4681 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4685 if (OVE->isUnique())
4701template <
class Emitter>
4706template <
class Emitter>
4708 return this->emitError(E);
4711template <
class Emitter>
4717 return this->emitDummyPtr(E, E);
4720template <
class Emitter>
4721bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4726 QualType ElemType = VT->getElementType();
4727 PrimType ElemT = classifyPrim(ElemType);
4729 PrimType SrcElemT = classifyVectorElementType(SrcType);
4735 if (!this->emitGetPtrLocal(*LocalIndex, E))
4739 unsigned SrcOffset =
4740 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4741 if (!this->visit(Src))
4743 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4746 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4747 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4749 if (!this->emitArrayElemPop(SrcElemT, I, E))
4753 if (SrcElemT != ElemT) {
4754 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4756 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4757 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4761 if (!this->emitInitElem(ElemT, I, E))
4767template <
class Emitter>
4769 return emitVectorConversion(E->
getSrcExpr(), E);
4772template <
class Emitter>
4776 return this->emitInvalid(E);
4785 assert(NumOutputElems > 0);
4791 if (!this->emitGetPtrLocal(*LocalIndex, E))
4796 unsigned VectorOffsets[2];
4797 for (
unsigned I = 0; I != 2; ++I) {
4800 if (!this->
visit(Vecs[I]))
4802 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4805 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4807 assert(ShuffleIndex >= -1);
4808 if (ShuffleIndex == -1)
4809 return this->emitInvalidShuffleVectorIndex(I, E);
4811 assert(ShuffleIndex < (NumInputElems * 2));
4812 if (!this->emitGetLocal(
PT_Ptr,
4813 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4815 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4816 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4819 if (!this->emitInitElem(ElemT, I, E))
4824 return this->emitPopPtr(E);
4829template <
class Emitter>
4834 Base->getType()->isVectorType() ||
4840 if (Indices.size() == 1) {
4845 if (!this->emitConstUint32(Indices[0], E))
4847 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4857 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4865 if (!this->emitGetPtrLocal(*ResultIndex, E))
4873 uint32_t DstIndex = 0;
4874 for (uint32_t I : Indices) {
4875 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4877 if (!this->emitArrayElemPop(ElemT, I, E))
4879 if (!this->emitInitElem(ElemT, DstIndex, E))
4889template <
class Emitter>
4893 return this->
discard(SubExpr) && this->emitInvalid(E);
4899 return this->emitDummyPtr(E, E);
4902template <
class Emitter>
4907 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4912 if (!this->
visit(SubExpr))
4914 if (!this->emitConstUint8(0, E))
4916 if (!this->emitArrayElemPtrPopUint8(E))
4918 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4921 PrimType SecondFieldT = *R->getField(1u)->T;
4923 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4925 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4927 assert(SecondFieldT ==
PT_Ptr);
4929 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4931 if (!this->emitExpandPtr(E))
4935 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4937 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4940template <
class Emitter>
4955 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4959 return this->emitUnsupported(E);
4968 return this->
Visit(E);
4975 return this->
Visit(E);
4979 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4982 if (
const auto *CE = dyn_cast<CastExpr>(E);
4984 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4991 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4994 if (
const auto *CE = dyn_cast<CastExpr>(E);
4995 CE && (CE->getCastKind() == CK_DerivedToBase ||
4996 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4997 CE->getCastKind() == CK_NoOp))
5017 if (!this->emitGetPtrLocal(*LocalIndex, E))
5027 return this->
Visit(E);
5030template <
class Emitter>
5036 return this->
Visit(E) && this->emitFinishInit(E);
5039template <
class Emitter>
5045 return this->
Visit(E) && this->emitFinishInitPop(E);
5051 return this->
Visit(E);
5062 if (!this->
visit(E))
5064 return this->emitComplexBoolCast(E);
5069 if (!this->
visit(E))
5077 return this->emitIsNonNullPtr(E);
5081 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5084 return this->emitCast(*
T,
PT_Bool, E);
5087template <
class Emitter>
5091 QT = AT->getValueType();
5095 return this->emitZeroBool(E);
5097 return this->emitZeroSint8(E);
5099 return this->emitZeroUint8(E);
5101 return this->emitZeroSint16(E);
5103 return this->emitZeroUint16(E);
5105 return this->emitZeroSint32(E);
5107 return this->emitZeroUint32(E);
5109 return this->emitZeroSint64(E);
5111 return this->emitZeroUint64(E);
5113 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5115 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5117 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5120 return this->emitNullMemberPtr(0,
nullptr, E);
5122 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5123 return this->emitFloat(F, E);
5126 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5130 llvm_unreachable(
"unknown primitive type");
5133template <
class Emitter>
5134bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5136 bool IsCompleteClass) {
5140 for (
const Record::Field &Field :
R->fields()) {
5141 if (Field.isUnnamedBitField())
5148 if (!this->visitZeroInitializer(
T, QT, E))
5151 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5155 if (!this->emitInitField(
T, Field.Offset, E))
5160 if (!this->emitGetPtrField(Field.Offset, E))
5167 if (!this->visitZeroInitializer(
T, ET, E))
5169 if (!this->emitInitElem(
T, I, E))
5174 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5177 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5185 if (!this->emitFinishInitActivatePop(E))
5189 if (!this->emitFinishInitPop(E))
5193 for (
const Record::Base &B :
R->bases()) {
5194 if (!this->emitGetPtrBase(B.Offset, E))
5196 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5198 if (!this->emitFinishInitPop(E))
5202 if (IsCompleteClass) {
5203 for (
const Record::Base &B :
R->virtual_bases()) {
5206 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5208 if (!this->emitFinishInitPop(E))
5216template <
class Emitter>
5217bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5218 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5219 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5224 for (
size_t I = 0; I != NumElems; ++I) {
5225 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5227 if (!this->emitInitElem(*ElemT, I, E))
5233 const Record *
R = getRecord(ElemType);
5237 for (
size_t I = 0; I != NumElems; ++I) {
5238 if (!this->emitConstUint32(I, E))
5240 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5242 if (!this->visitZeroRecordInitializer(R, E))
5244 if (!this->emitPopPtr(E))
5250 for (
size_t I = 0; I != NumElems; ++I) {
5251 if (!this->emitConstUint32(I, E))
5253 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5255 if (!this->visitZeroArrayInitializer(ElemType, E))
5257 if (!this->emitPopPtr(E))
5266template <
class Emitter>
5267bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5269 if (!canClassify(E->
getType()))
5274 if (!this->visit(LHS))
5276 if (!this->visit(RHS))
5279 if (!this->visit(RHS))
5281 if (!this->visit(LHS))
5289 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5293 bool Activates = refersToUnion(LHS);
5296 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5299 if (DiscardResult) {
5300 if (BitField && Activates)
5301 return this->emitStoreBitFieldActivatePop(RHT, E);
5303 return this->emitStoreBitFieldPop(RHT, E);
5305 return this->emitStoreActivatePop(RHT, E);
5307 return this->emitStorePop(RHT, E);
5310 auto maybeLoad = [&](
bool Result) ->
bool {
5316 return this->emitLoadPop(RHT, E);
5320 if (BitField && Activates)
5321 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5323 return maybeLoad(this->emitStoreBitField(RHT, E));
5325 return maybeLoad(this->emitStoreActivate(RHT, E));
5327 return maybeLoad(this->emitStore(RHT, E));
5330template <
class Emitter>
5331template <
typename T>
5335 return this->emitConstSint8(
Value, Info);
5337 return this->emitConstUint8(
Value, Info);
5339 return this->emitConstSint16(
Value, Info);
5341 return this->emitConstUint16(
Value, Info);
5343 return this->emitConstSint32(
Value, Info);
5345 return this->emitConstUint32(
Value, Info);
5347 return this->emitConstSint64(
Value, Info);
5349 return this->emitConstUint64(
Value, Info);
5351 return this->emitConstBool(
Value, Info);
5358 llvm_unreachable(
"Invalid integral type");
5361 llvm_unreachable(
"unknown primitive type");
5364template <
class Emitter>
5365template <
typename T>
5366bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5367 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5370template <
class Emitter>
5374 return this->emitConstIntAPS(
Value, Info);
5376 return this->emitConstIntAP(
Value, Info);
5378 if (
Value.isSigned())
5379 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5380 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5383template <
class Emitter>
5387 return this->emitConstIntAPS(
Value, Info);
5389 return this->emitConstIntAP(
Value, Info);
5392 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5393 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5396template <
class Emitter>
5397bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5398 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5401template <
class Emitter>
5416 return Local.Offset;
5419template <
class Emitter>
5424 bool IsTemporary =
false;
5428 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5429 Init = VarD->getInit();
5431 if (
const auto *E = Src.
asExpr()) {
5441 return std::nullopt;
5448 return Local.Offset;
5451template <
class Emitter>
5460 return std::nullopt;
5470 return Local.Offset;
5473template <
class Emitter>
5475 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5476 return PT->getPointeeType()->getAsCanonical<RecordType>();
5482 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5486template <
class Emitter>
5488 return P.getOrCreateRecord(RD);
5491template <
class Emitter>
5493 return Ctx.getOrCreateFunction(FD);
5496template <
class Emitter>
5502 auto maybeDestroyLocals = [&]() ->
bool {
5503 if (DestroyToplevelScope)
5504 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5505 return this->emitCheckAllocations(E);
5512 return this->emitRetVoid(E) && maybeDestroyLocals();
5520 return this->emitRet(*
T, E) && maybeDestroyLocals();
5528 if (!this->emitGetPtrLocal(*LocalOffset, E))
5536 return this->emitRetValue(E) && maybeDestroyLocals();
5539 return maybeDestroyLocals() &&
false;
5542template <
class Emitter>
5544 bool DestroyToplevelScope) {
5548 return this->
visitExpr(E, DestroyToplevelScope);
5551template <
class Emitter>
5563 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5564 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5578template <
class Emitter>
5580 bool ConstantContext) {
5583 if (!ConstantContext) {
5598 auto GlobalIndex =
P.getGlobal(VD);
5599 assert(GlobalIndex);
5601 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5604 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5612 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5614 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5617 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5627 auto GlobalIndex =
P.getGlobal(VD);
5628 assert(GlobalIndex);
5629 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5638 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5641template <
class Emitter>
5652 if (!this->isActive())
5657 if (
Init &&
Init->isValueDependent())
5661 auto checkDecl = [&]() ->
bool {
5663 return !NeedsOp || this->emitCheckDecl(VD, VD);
5670 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5673 if (
P.isGlobalInitialized(*GlobalIndex))
5677 }
else if ((GlobalIndex =
5692 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5695 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5698 if (!this->emitStartInit(
Init))
5704 if (!this->emitEndInit(
Init))
5707 return this->emitFinishInitGlobal(
Init);
5717 if (!
Init ||
Init->getType()->isVoidType())
5726 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5738 if (!this->emitCheckRefInit(
Init))
5742 return this->emitSetLocal(*VarT, Offset, VD);
5750 if (!this->emitGetPtrLocal(*Offset,
Init))
5758template <
class Emitter>
5781 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5787 return this->emitDestructionPop(D, VD);
5796 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5820template <
class Emitter>
5835 unsigned ParamIndex = 0;
5842 const Expr *Arg = Args[ParamIndex];
5843 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5845 unsigned ArgOffset =
5847 if (!this->
visit(Arg))
5849 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5855 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5867 if (
This->getType()->isPointerType()) {
5870 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5877 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5899template <
class Emitter>
5905 return this->emitConst(Val.
getInt(), ValType, Info);
5907 return this->emitFloat(Val.
getFloat(), Info);
5911 if (!this->emitGetMemberPtr(MemberDecl, Info))
5917 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5923 return this->emitNullMemberPtr(0,
nullptr, Info);
5928 return this->emitNull(ValType, 0,
nullptr, Info);
5932 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5933 return this->
visit(BaseExpr);
5938 QualType EntryType = VD->getType();
5941 for (
auto &Entry : Path) {
5943 uint64_t Index = Entry.getAsArrayIndex();
5946 if (!this->emitConst(Index,
PT_Uint64, Info))
5948 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5950 EntryType = ElemType;
5957 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5958 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5960 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5962 EntryType = FD->getType();
5966 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
5971 if (!this->emitGetPtrVirtBasePop(
Base, Info))
5974 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5987template <
class Emitter>
5990 bool IsCompleteClass) {
5996 if (IsCompleteClass)
6003 const Record::Base *RB = R->getBase(I);
6004 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6006 if (!this->emitGetPtrBase(RB->Offset, Info))
6011 if (!this->emitFinishInitPop(Info))
6019 const Record::Field *RF = R->getField(I);
6020 QualType FieldType = RF->Decl->getType();
6025 if (!this->emitInitField(*PT, RF->Offset, Info))
6028 if (!this->emitGetPtrField(RF->Offset, Info))
6032 if (!this->emitFinishInitPop(Info))
6038 if (IsCompleteClass) {
6043 const Record::Base *RB = R->getVirtualBase(I);
6044 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6052 if (!this->emitFinishInitPop(Info))
6068 const Record::Field *RF = R->getField(UnionField);
6069 QualType FieldType = RF->Decl->getType();
6074 if (RF->isBitField())
6075 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6077 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6080 if (!this->emitGetPtrField(RF->Offset, Info))
6082 if (!this->emitActivate(Info))
6086 return this->emitPopPtr(Info);
6090 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6091 QualType ElemType = ArrType->getElementType();
6094 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6095 const APValue &Elem = A >= InitializedElems
6104 if (!this->emitInitElem(*ElemT, A, Info))
6107 if (!this->emitConstUint32(A, Info))
6109 if (!this->emitArrayElemPtrUint32(Info))
6113 if (!this->emitPopPtr(Info))
6124template <
class Emitter>
6126 if (
P.getGlobal(VD))
6131 llvm_unreachable(
"Why didn't that work?");
6135 "registerRedecl should only be called with primitive values");
6140 return this->emitInitGlobal(
T, *GlobalIndex, {});
6143template <
class Emitter>
6145 unsigned BuiltinID) {
6146 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6151 return this->emitConst(0, E);
6154 if (!this->emitStartSpeculation(E))
6156 LabelTy EndLabel = this->getLabel();
6157 if (!this->speculate(E, EndLabel))
6159 if (!this->emitEndSpeculation(E))
6161 this->fallthrough(EndLabel);
6169 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6170 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6171 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6172 BuiltinID == Builtin::BI__builtin_function_start) {
6175 return this->emitDummyPtr(E, E);
6186 if (!this->emitGetPtrLocal(*LocalIndex, E))
6191 switch (BuiltinID) {
6192 case Builtin::BI__builtin_object_size:
6193 case Builtin::BI__builtin_dynamic_object_size: {
6197 if (!this->
visit(Arg0))
6208 case Builtin::BI__assume:
6209 case Builtin::BI__builtin_assume:
6212 case Builtin::BI__atomic_is_lock_free:
6213 case Builtin::BI__atomic_always_lock_free: {
6224 for (
const auto *Arg : E->
arguments()) {
6225 if (!this->
visit(Arg))
6231 if (!this->emitCallBI(E, BuiltinID, E))
6249template <
class Emitter>
6270 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6271 DD && DD->isTrivial()) {
6273 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6275 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6276 this->emitPopPtr(E);
6282 bool ActivateLHS =
false;
6290 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6291 OCE && OCE->isAssignmentOp()) {
6292 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6295 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6296 if (!this->
visit(MCE->getImplicitObjectArgument()))
6303 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6321 if (!this->emitGetPtrLocal(*LocalIndex, E))
6329 if (!this->emitGetPtrLocal(*LocalIndex, E))
6333 if (!this->emitDupPtr(E))
6338 const Expr *ReversedArgs[2];
6339 bool IsAssignmentOperatorCall =
false;
6340 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6341 OCE && OCE->isAssignmentOp()) {
6345 assert(Args.size() == 2);
6346 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6348 IsAssignmentOperatorCall =
true;
6349 ReversedArgs[0] = Args[1];
6350 ReversedArgs[1] = Args[0];
6351 Args = ReversedArgs;
6358 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6359 MD && MD->isStatic()) {
6363 Args = Args.drop_front();
6367 bool Devirtualized =
false;
6370 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6378 if (!this->
visit(Callee))
6380 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6382 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6384 if (!this->emitGetMemberPtrBase(E))
6387 const auto *InstancePtr = MC->getImplicitObjectArgument();
6394 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6395 Devirtualized =
true;
6396 if (!this->
visit(Stripped))
6399 if (!this->
visit(InstancePtr))
6403 if (!this->
visit(InstancePtr))
6407 }
else if (
const auto *PD =
6408 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6409 if (!this->emitCheckPseudoDtor(E))
6417 return this->emitPseudoDtor(E);
6418 }
else if (!FuncDecl) {
6422 if (!this->
visit(Callee))
6424 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6433 if (IsAssignmentOperatorCall) {
6434 assert(Args.size() == 2);
6437 if (!this->emitFlip(Arg2T, Arg1T, E))
6451 assert(HasRVO ==
Func->hasRVO());
6453 bool HasQualifier =
false;
6454 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6455 HasQualifier = ME->hasQualifier();
6457 bool IsVirtual =
false;
6458 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6459 IsVirtual = !Devirtualized && MD->isVirtual();
6464 if (IsVirtual && !HasQualifier) {
6465 uint32_t VarArgSize = 0;
6466 unsigned NumParams =
6467 Func->getNumWrittenParams() +
6469 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6472 if (!this->emitCallVirt(
Func, VarArgSize, E))
6474 }
else if (
Func->isVariadic()) {
6475 uint32_t VarArgSize = 0;
6476 unsigned NumParams =
6477 Func->getNumWrittenParams() +
6479 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6481 if (!this->emitCallVar(
Func, VarArgSize, E))
6484 if (!this->emitCall(
Func, 0, E))
6493 uint32_t ArgSize = 0;
6494 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6500 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6502 if (!this->emitGetMemberPtrDecl(E))
6505 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6508 if (!this->emitCallPtr(ArgSize, E, E))
6519template <
class Emitter>
6526template <
class Emitter>
6533template <
class Emitter>
6538 return this->emitConstBool(E->
getValue(), E);
6541template <
class Emitter>
6547 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6548 return this->emitNullPtr(Val,
nullptr, E);
6551template <
class Emitter>
6559 return this->emitZero(
T, E);
6562template <
class Emitter>
6567 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6568 if (this->LambdaThisCapture.Offset > 0) {
6569 if (this->LambdaThisCapture.IsPtr)
6570 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6571 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6580 return this->emitThis(E);
6595 unsigned StartIndex = 0;
6596 unsigned EndIndex = 0;
6598 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6600 EndIndex = StartIndex;
6607 for (; StartIndex > 0; --StartIndex) {
6618 if (StartIndex == 0 && EndIndex == 0)
6629 assert(StartIndex <= EndIndex);
6632 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6644 case Stmt::CompoundStmtClass:
6646 case Stmt::DeclStmtClass:
6648 case Stmt::ReturnStmtClass:
6650 case Stmt::IfStmtClass:
6652 case Stmt::WhileStmtClass:
6654 case Stmt::DoStmtClass:
6656 case Stmt::ForStmtClass:
6658 case Stmt::CXXForRangeStmtClass:
6660 case Stmt::BreakStmtClass:
6662 case Stmt::ContinueStmtClass:
6664 case Stmt::SwitchStmtClass:
6666 case Stmt::CaseStmtClass:
6668 case Stmt::DefaultStmtClass:
6670 case Stmt::AttributedStmtClass:
6672 case Stmt::CXXTryStmtClass:
6674 case Stmt::NullStmtClass:
6677 case Stmt::GCCAsmStmtClass:
6678 case Stmt::MSAsmStmtClass:
6679 case Stmt::GotoStmtClass:
6680 return this->emitInvalid(S);
6681 case Stmt::LabelStmtClass:
6683 case Stmt::CXXExpansionStmtInstantiationClass:
6687 if (
const auto *E = dyn_cast<Expr>(S))
6694template <
class Emitter>
6697 for (
const auto *InnerStmt : S->
body())
6700 return Scope.destroyLocals();
6703template <
class Emitter>
6704bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6705 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6706 for (
auto *BD : DD->flat_bindings())
6707 if (
auto *KD = BD->getHoldingVar();
6708 KD && !this->visitVarDecl(KD, KD->getInit()))
6722template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6724 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6725 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6732 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6737 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6738 ICE && (ICE->getCastKind() == CK_NoOp ||
6739 ICE->getCastKind() == CK_DerivedToBase ||
6740 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6741 E = ICE->getSubExpr();
6745 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6746 const auto *ThisRecord =
6747 This->getType()->getPointeeType()->getAsRecordDecl();
6748 if (!ThisRecord->isUnion())
6751 if (
const auto *Ctor =
6752 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6753 return Ctor->getParent() == ThisRecord;
6762template <
class Emitter>
6764 bool EvaluateConditionDecl) {
6765 for (
const auto *D : DS->
decls()) {
6770 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6771 assert(ESD->getInstantiations() &&
"not expanded?");
6772 if (!this->
visitStmt(ESD->getInstantiations()))
6777 const auto *VD = dyn_cast<VarDecl>(D);
6784 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6791template <
class Emitter>
6794 return this->emitUnsupported(RS);
6800 if (!this->
visit(RE))
6806 if (RE->getType()->isVoidType()) {
6807 if (!this->
visit(RE))
6810 if (RE->containsErrors())
6815 if (!this->emitRVOPtr(RE))
6821 return this->emitRetVoid(RS);
6827 return this->emitRetVoid(RS);
6833 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6840 if (
auto *CondInit = IS->
getInit()) {
6856 return visitChildStmt(IS->
getThen());
6858 return visitChildStmt(Else);
6864 if (!this->emitIsConstantContext(IS))
6867 if (!this->emitIsConstantContext(IS))
6869 if (!this->emitInv(IS))
6883 LabelTy LabelElse = this->getLabel();
6884 LabelTy LabelEnd = this->getLabel();
6885 if (!this->jumpFalse(LabelElse, IS))
6887 if (!visitChildStmt(IS->
getThen()))
6889 if (!this->jump(LabelEnd, IS))
6891 this->emitLabel(LabelElse);
6892 if (!visitChildStmt(Else))
6894 this->emitLabel(LabelEnd);
6896 LabelTy LabelEnd = this->getLabel();
6897 if (!this->jumpFalse(LabelEnd, IS))
6899 if (!visitChildStmt(IS->
getThen()))
6901 this->emitLabel(LabelEnd);
6910template <
class Emitter>
6915 LabelTy CondLabel = this->getLabel();
6916 LabelTy EndLabel = this->getLabel();
6920 this->fallthrough(CondLabel);
6921 this->emitLabel(CondLabel);
6937 if (!this->jumpFalse(EndLabel, S))
6947 if (!this->jump(CondLabel, S))
6949 this->fallthrough(EndLabel);
6950 this->emitLabel(EndLabel);
6959 LabelTy StartLabel = this->getLabel();
6960 LabelTy EndLabel = this->getLabel();
6961 LabelTy CondLabel = this->getLabel();
6965 this->fallthrough(StartLabel);
6966 this->emitLabel(StartLabel);
6972 this->fallthrough(CondLabel);
6973 this->emitLabel(CondLabel);
6980 if (!this->jumpTrue(StartLabel, S))
6983 this->fallthrough(EndLabel);
6984 this->emitLabel(EndLabel);
6988template <
class Emitter>
6996 LabelTy EndLabel = this->getLabel();
6997 LabelTy CondLabel = this->getLabel();
6998 LabelTy IncLabel = this->getLabel();
7005 this->fallthrough(CondLabel);
7006 this->emitLabel(CondLabel);
7018 if (!this->jumpFalse(EndLabel, S))
7027 this->fallthrough(IncLabel);
7028 this->emitLabel(IncLabel);
7034 if (!this->jump(CondLabel, S))
7038 this->emitLabel(EndLabel);
7044template <
class Emitter>
7054 LabelTy EndLabel = this->getLabel();
7055 LabelTy CondLabel = this->getLabel();
7056 LabelTy IncLabel = this->getLabel();
7072 this->fallthrough(CondLabel);
7073 this->emitLabel(CondLabel);
7076 if (!this->jumpFalse(EndLabel, S))
7087 this->fallthrough(IncLabel);
7088 this->emitLabel(IncLabel);
7095 if (!this->jump(CondLabel, S))
7098 this->fallthrough(EndLabel);
7099 this->emitLabel(EndLabel);
7103template <
class Emitter>
7114 if (LI.BreakLabel) {
7115 TargetLabel = *LI.BreakLabel;
7116 BreakScope = LI.BreakOrContinueScope;
7122 if (LI.Name == TargetLoop) {
7123 TargetLabel = *LI.BreakLabel;
7124 BreakScope = LI.BreakOrContinueScope;
7135 C =
C->getParent()) {
7136 if (!
C->destroyLocals())
7140 return this->jump(*TargetLabel, S);
7143template <
class Emitter>
7154 if (LI.ContinueLabel) {
7155 TargetLabel = *LI.ContinueLabel;
7156 ContinueScope = LI.BreakOrContinueScope;
7162 if (LI.Name == TargetLoop) {
7163 TargetLabel = *LI.ContinueLabel;
7164 ContinueScope = LI.BreakOrContinueScope;
7174 C =
C->getParent()) {
7175 if (!
C->destroyLocals())
7179 return this->jump(*TargetLabel, S);
7182template <
class Emitter>
7192 LabelTy EndLabel = this->getLabel();
7197 if (
const auto *CondInit = S->
getInit())
7206 if (!this->
visit(Cond))
7208 if (!this->emitSetLocal(CondT, CondVar, S))
7218 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7221 if (CS->caseStmtIsGNURange()) {
7222 LabelTy EndOfRangeCheck = this->getLabel();
7223 const Expr *Low = CS->getLHS();
7224 const Expr *High = CS->getRHS();
7228 if (!this->emitGetLocal(CondT, CondVar, CS))
7230 if (!this->
visit(Low))
7233 if (!this->emitGE(
LT, S))
7235 if (!this->jumpFalse(EndOfRangeCheck, S))
7238 if (!this->emitGetLocal(CondT, CondVar, CS))
7240 if (!this->
visit(High))
7243 if (!this->emitLE(HT, S))
7247 this->emitLabel(EndOfRangeCheck);
7252 if (
Value->isValueDependent())
7257 if (!this->emitGetLocal(CondT, CondVar, CS))
7263 if (!this->emitEQ(ValueT, S))
7268 assert(!DefaultLabel);
7269 DefaultLabel = this->getLabel();
7276 if (!this->jump(*DefaultLabel, S))
7279 if (!this->jump(EndLabel, S))
7287 this->fallthrough(EndLabel);
7288 this->emitLabel(EndLabel);
7293template <
class Emitter>
7301 return this->emitUnsupported(S);
7306template <
class Emitter>
7313 if (LI.DefaultLabel) {
7314 DefaultLabel = *LI.DefaultLabel;
7319 this->emitLabel(DefaultLabel);
7323template <
class Emitter>
7330 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7333 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7334 !this->Ctx.getLangOpts().MSVCCompat) {
7336 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7342 const Expr *Assumption = AA->getAssumption();
7353 if (!this->emitAssume(Assumption))
7362 if (IsMSVCConstexprAttr)
7363 return this->emitPopMSVCCE(S);
7367template <
class Emitter>
7380template <
class Emitter>
7390 LabelTy EndLabel = this->getLabel();
7392 LabelTy ContinueLabel = this->getLabel();
7397 this->emitLabel(ContinueLabel);
7400 this->emitLabel(EndLabel);
7405template <
class Emitter>
7406bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7413 assert(ClosureClass->
captures().empty());
7417 "A generic lambda's static-invoker function must be a "
7418 "template specialization");
7422 llvm::FoldingSetInsertToken InsertToken;
7423 const FunctionDecl *CorrespondingCallOpSpecialization =
7425 assert(CorrespondingCallOpSpecialization);
7426 LambdaCallOp = CorrespondingCallOpSpecialization;
7430 assert(ClosureClass->
captures().empty());
7431 const Function *
Func = this->getFunction(LambdaCallOp);
7434 assert(
Func->hasThisPointer());
7437 if (
Func->hasRVO()) {
7438 if (!this->emitRVOPtr(MD))
7446 if (!this->emitNullPtr(0,
nullptr, MD))
7451 auto It = this->Params.find(PVD);
7452 assert(It != this->Params.end());
7456 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7457 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7461 if (!this->emitCall(
Func, 0, LambdaCallOp))
7466 return this->emitRet(*ReturnType, MD);
7469 return this->emitRetVoid(MD);
7472template <
class Emitter>
7473bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7474 if (Ctx.getLangOpts().CPlusPlus23)
7484 const Expr *InitExpr =
Init->getInit();
7486 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7490 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7500template <
class Emitter>
7502 assert(!ReturnType);
7505 if (!this->emitStartThisLifetime1(Ctor))
7508 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7509 const Expr *InitExpr,
7512 if (InitExpr->getType().isNull())
7516 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7519 if (!this->visit(InitExpr))
7522 if (F->isBitField())
7523 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7525 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7530 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7533 if (
Activate && !this->emitActivate(InitExpr))
7536 return this->visitInitializerPop(InitExpr);
7540 const Record *
R = this->getRecord(RD);
7543 bool IsUnion =
R->isUnion();
7553 if (!this->emitThis(Ctor))
7556 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7559 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7560 this->emitRetVoid(Ctor);
7563 unsigned FieldInits = 0;
7566 if (
R->getNumVirtualBases() > 0) {
7567 if (!this->emitThis(Ctor))
7569 LabelTy AfterVirtBasesLabel = this->getLabel();
7572 if (!this->emitIsBaseClass({}))
7574 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7577 for (
const auto *
Init : Ctor->
inits()) {
7580 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7582 assert(
R->findVirtualBase(BaseDecl));
7583 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7585 if (!this->visitInitializerPop(
Init->getInit()))
7590 this->fallthrough(AfterVirtBasesLabel);
7591 this->emitLabel(AfterVirtBasesLabel);
7593 if (!this->emitPopPtr(Ctor))
7597 for (
const auto *
Init : Ctor->
inits()) {
7601 const Expr *InitExpr =
Init->getInit();
7603 const Record::Field *F =
R->getField(
Member);
7607 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7611 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7614 if (
Init->isBaseVirtual()) {
7620 const Record::Base *B =
R->getBase(BaseDecl);
7622 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7626 if (!this->visitInitializerPop(InitExpr))
7631 unsigned ChainSize = IFD->getChainingSize();
7632 assert(ChainSize >= 2);
7634 unsigned NestedFieldOffset = 0;
7635 const Record::Field *NestedField =
nullptr;
7636 for (
unsigned I = 0; I != ChainSize; ++I) {
7638 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7639 assert(FieldRecord);
7641 NestedField = FieldRecord->
getField(FD);
7642 assert(NestedField);
7643 IsUnion = IsUnion || FieldRecord->
isUnion();
7645 NestedFieldOffset += NestedField->Offset;
7648 if (I != ChainSize - 1)
7651 assert(NestedField);
7654 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7659 unsigned InitFieldOffset = 0;
7660 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7662 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7663 assert(FieldRecord);
7664 NestedField = FieldRecord->
getField(FD);
7665 InitFieldOffset += NestedField->Offset;
7666 assert(NestedField);
7667 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7669 if (!this->emitFinishInitPop(InitExpr))
7673 InitStack.pop_back_n(ChainSize - 1);
7676 assert(
Init->isDelegatingInitializer());
7677 if (!this->emitThis(InitExpr))
7679 if (!this->visitInitializerPop(
Init->getInit()))
7683 if (!
Scope.destroyLocals())
7687 if (FieldInits !=
R->getNumFields()) {
7688 assert(FieldInits < R->getNumFields());
7690 if (!this->emitStartThisLifetime(Ctor))
7697 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7698 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7705 if (!visitStmt(Body))
7712template <
class Emitter>
7715 const Record *
R = this->getRecord(RD);
7719 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7720 if (!this->visitStmt(
Dtor->getBody()))
7724 if (!this->emitThis(
Dtor))
7727 if (!this->emitCheckDestruction(
Dtor))
7731 if (!
R->isUnion()) {
7735 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7739 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7741 if (!this->emitDestructionPop(D,
SourceInfo{}))
7746 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7747 if (
Base.R->hasTrivialDtor())
7751 if (!this->emitRecordDestructionPop(
Base.R, {}))
7755 if (
R->getNumVirtualBases() > 0) {
7756 LabelTy EndLabel = this->getLabel();
7758 if (!this->emitIsBaseClass({}))
7760 if (!this->jumpTrue(EndLabel, {}))
7763 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7764 if (
Base.R->hasTrivialDtor())
7769 if (!this->emitRecordDestructionPop(
Base.R, {}))
7773 this->fallthrough(EndLabel);
7774 this->emitLabel(EndLabel);
7777 if (!this->emitMarkDestroyed(
Dtor))
7780 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7783template <
class Emitter>
7784bool Compiler<Emitter>::compileUnionAssignmentOperator(
7786 if (!this->emitThis(MD))
7789 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7792 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7795template <
class Emitter>
7805 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7806 return this->compileConstructor(Ctor);
7807 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7808 return this->compileDestructor(
Dtor);
7811 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7816 return this->compileUnionAssignmentOperator(MD);
7819 return this->emitLambdaStaticInvokerBody(MD);
7823 if (
const auto *Body = F->
getBody())
7837 return FD->getBitWidthValue();
7840template <
class Emitter>
7856 if (!
Ctx.getLangOpts().CPlusPlus14)
7857 return this->emitInvalid(E);
7859 return this->emitError(E);
7861 if (!this->
visit(SubExpr))
7865 if (!this->emitIncPtr(E))
7872 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7873 : this->emitIncf(getFPOptions(E), E);
7885 if (!
Ctx.getLangOpts().CPlusPlus14)
7886 return this->emitInvalid(E);
7888 return this->emitError(E);
7890 if (!this->
visit(SubExpr))
7894 if (!this->emitDecPtr(E))
7901 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7902 : this->emitDecf(getFPOptions(E), E);
7915 if (!
Ctx.getLangOpts().CPlusPlus14)
7916 return this->emitInvalid(E);
7918 return this->emitError(E);
7920 if (!this->
visit(SubExpr))
7924 if (!this->emitLoadPtr(E))
7926 if (!this->emitConstUint8(1, E))
7928 if (!this->emitAddOffsetUint8(E))
7930 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7936 return this->emitIncfPop(getFPOptions(E), E);
7946 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7947 if (!this->emitLoadFloat(E))
7949 APFloat F(TargetSemantics, 1);
7950 if (!this->emitFloat(F, E))
7953 if (!this->emitAddf(getFPOptions(E), E))
7955 if (!this->emitStoreFloat(E))
7967 return E->
isGLValue() || this->emitLoadPop(*
T, E);
7970 if (!
Ctx.getLangOpts().CPlusPlus14)
7971 return this->emitInvalid(E);
7973 return this->emitError(E);
7975 if (!this->
visit(SubExpr))
7979 if (!this->emitLoadPtr(E))
7981 if (!this->emitConstUint8(1, E))
7983 if (!this->emitSubOffsetUint8(E))
7985 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7991 return this->emitDecfPop(getFPOptions(E), E);
8001 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8002 if (!this->emitLoadFloat(E))
8004 APFloat F(TargetSemantics, 1);
8005 if (!this->emitFloat(F, E))
8008 if (!this->emitSubf(getFPOptions(E), E))
8010 if (!this->emitStoreFloat(E))
8022 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8026 return this->emitError(E);
8029 return this->
discard(SubExpr);
8034 if (!this->emitInv(E))
8038 return this->emitCast(
PT_Bool, ET, E);
8042 return this->emitError(E);
8044 if (!this->
visit(SubExpr))
8049 return this->emitError(E);
8051 if (!this->
visit(SubExpr))
8067 if (!
Ctx.getLangOpts().CPlusPlus) {
8070 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8071 Deref && Deref->getOpcode() == UO_Deref) {
8073 return this->
discard(Deref->getSubExpr());
8074 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8079 return this->
discard(SubExpr);
8080 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8083 return this->
discard(SubExpr);
8085 if (!this->
visit(SubExpr))
8092 return this->emitNarrowPtr(E);
8097 return this->emitError(E);
8099 if (!this->
visit(SubExpr))
8113 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
8118 assert(
false &&
"Unhandled opcode");
8124template <
class Emitter>
8130 return this->
discard(SubExpr);
8133 auto prepareResult = [=]() ->
bool {
8138 return this->emitGetPtrLocal(*LocalIndex, E);
8145 unsigned SubExprOffset = ~0u;
8146 auto createTemp = [=, &SubExprOffset]() ->
bool {
8149 if (!this->
visit(SubExpr))
8151 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8155 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8156 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8158 return this->emitArrayElemPop(ElemT, Index, E);
8163 if (!prepareResult())
8167 for (
unsigned I = 0; I != 2; ++I) {
8168 if (!getElem(SubExprOffset, I))
8170 if (!this->emitNeg(ElemT, E))
8172 if (!this->emitInitElem(ElemT, I, E))
8183 if (!this->
visit(SubExpr))
8185 if (!this->emitComplexBoolCast(SubExpr))
8187 if (!this->emitInv(E))
8190 return this->emitCast(
PT_Bool, ET, E);
8194 return this->emitComplexReal(SubExpr);
8197 if (!this->
visit(SubExpr))
8201 if (!this->emitConstUint8(1, E))
8203 return this->emitArrayElemPtrPopUint8(E);
8214 if (!this->emitArrayElem(ElemT, 1, E))
8216 if (!this->emitNeg(ElemT, E))
8218 if (!this->emitInitElem(ElemT, 1, E))
8226 return this->emitInvalid(E);
8232template <
class Emitter>
8238 return this->
discard(SubExpr);
8241 if (UnaryOp == UO_Extension)
8244 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8245 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8246 return this->emitInvalid(E);
8249 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8256 if (!this->emitGetPtrLocal(*LocalIndex, E))
8261 unsigned SubExprOffset =
8263 if (!this->
visit(SubExpr))
8265 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8270 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8271 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8273 return this->emitArrayElemPop(ElemT, Index, E);
8278 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8279 if (!getElem(SubExprOffset, I))
8281 if (!this->emitNeg(ElemT, E))
8283 if (!this->emitInitElem(ElemT, I, E))
8298 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8299 if (!getElem(SubExprOffset, I))
8302 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8304 if (!this->emitInv(E))
8306 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8308 if (!this->emitNeg(ElemT, E))
8310 if (ElemT != ResultVecElemT &&
8311 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8313 if (!this->emitInitElem(ResultVecElemT, I, E))
8319 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8320 if (!getElem(SubExprOffset, I))
8323 if (!this->emitInv(E))
8326 if (!this->emitComp(ElemT, E))
8329 if (!this->emitInitElem(ElemT, I, E))
8334 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8339template <
class Emitter>
8341 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8344 return this->emitConst(ECD->getInitVal(), E);
8346 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8350 return F && this->emitGetFnPtr(F, E);
8352 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8353 TPOD = TPOD->getFirstDecl();
8357 return this->emitGetPtrGlobal(*GlobalIndex, E);
8363 return this->emitInitGlobal(*
T, *Index, E);
8366 if (!this->emitGetPtrGlobal(*Index, E))
8370 return this->emitFinishInit(E);
8382 auto maybePopPtr = [&]() ->
bool {
8384 return this->emitPopPtr(E);
8391 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8395 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8400 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8401 if (IsReference || !It->second.IsPtr)
8402 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8404 return this->emitGetPtrParam(It->second.Index, E);
8407 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8414 const unsigned Offset = It->second.Offset;
8417 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8419 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8422 if (
auto GlobalIndex =
P.getGlobal(D)) {
8424 if (!
Ctx.getLangOpts().CPlusPlus11)
8425 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8426 if (!
Ctx.getLangOpts().CPlusPlus23)
8427 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8429 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8432 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8436 auto revisit = [&](
const VarDecl *VD,
8437 bool IsConstexprUnknown =
true) ->
bool {
8439 IsConstexprUnknown);
8440 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8446 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8447 if (!this->emitPopCC(E))
8451 if (VarState.notCreated())
8459 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8461 if (
auto It = this->LambdaCaptures.find(D);
8462 It != this->LambdaCaptures.end()) {
8463 auto [Offset, IsPtr] = It->second;
8466 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8467 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8471 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8472 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8473 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8477 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8478 return this->
delegate(BD->getBinding());
8484 return this->emitDummyPtr(D, E);
8489 const auto *VD = dyn_cast<VarDecl>(D);
8491 return this->emitError(E);
8494 if (!
Ctx.getLangOpts().CPlusPlus) {
8498 return revisit(VD,
false);
8502 return this->emitDummyPtr(D, E);
8506 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8507 if (
T.isConstant(
Ctx.getASTContext()))
8509 return T->isReferenceType();
8513 typeShouldBeVisited(DeclType)) {
8515 Init && !
Init->isValueDependent()) {
8520 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8533 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8538 return revisit(VD, IsConstexprUnknown);
8539 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8540 return revisit(VD,
true);
8549 return this->emitDummyPtr(
8553template <
class Emitter>
8559template <
class Emitter>
8569 if (!
C->destroyLocals())
8575template <
class Emitter>
8576unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8579 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8581 return Ty->getAsCXXRecordDecl();
8583 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8584 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8586 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8590template <
class Emitter>
8597 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8602 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8603 getFPOptions(E), E);
8605 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8606 getFPOptions(E), E);
8610 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8615 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8617 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8621 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8625 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8626 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8633template <
class Emitter>
8636 assert(FromT != ToT);
8639 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8641 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8643 return this->emitCast(FromT, ToT, E);
8647template <
class Emitter>
8648bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8652 return this->
discard(SubExpr);
8654 if (!this->visit(SubExpr))
8657 if (!this->emitConstUint8(0, SubExpr))
8659 return this->emitArrayElemPtrPopUint8(SubExpr);
8663 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8667template <
class Emitter>
8668bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8669 assert(!DiscardResult);
8673 if (!this->emitArrayElem(ElemT, 0, E))
8676 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8679 if (!this->emitCast(ElemT,
PT_Bool, E))
8684 LabelTy LabelTrue = this->getLabel();
8685 if (!this->jumpTrue(LabelTrue, E))
8688 if (!this->emitArrayElemPop(ElemT, 1, E))
8691 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8694 if (!this->emitCast(ElemT,
PT_Bool, E))
8698 LabelTy EndLabel = this->getLabel();
8699 this->jump(EndLabel, E);
8701 this->emitLabel(LabelTrue);
8702 if (!this->emitPopPtr(E))
8704 if (!this->emitConstBool(
true, E))
8707 this->fallthrough(EndLabel);
8708 this->emitLabel(EndLabel);
8713template <
class Emitter>
8714bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8725 LHSIsComplex =
true;
8726 ElemT = classifyComplexElementType(LHS->
getType());
8727 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8728 if (!this->visit(LHS))
8730 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8733 LHSIsComplex =
false;
8735 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8736 if (!this->visit(LHS))
8738 if (!this->emitSetLocal(LHST, LHSOffset, E))
8745 RHSIsComplex =
true;
8746 ElemT = classifyComplexElementType(RHS->
getType());
8747 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8748 if (!this->visit(RHS))
8750 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8753 RHSIsComplex =
false;
8755 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8756 if (!this->visit(RHS))
8758 if (!this->emitSetLocal(RHST, RHSOffset, E))
8762 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8763 bool IsComplex) ->
bool {
8765 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8767 return this->emitArrayElemPop(ElemT, Index, E);
8769 return this->emitGetLocal(ElemT, LocalOffset, E);
8772 for (
unsigned I = 0; I != 2; ++I) {
8774 if (!getElem(LHSOffset, I, LHSIsComplex))
8776 if (!getElem(RHSOffset, I, RHSIsComplex))
8779 if (!this->emitEQ(ElemT, E))
8782 if (!this->emitCastBoolUint8(E))
8787 if (!this->emitAddUint8(E))
8789 if (!this->emitConstUint8(2, E))
8793 if (!this->emitEQUint8(E))
8796 if (!this->emitNEUint8(E))
8803 return this->emitCast(
PT_Bool, ResT, E);
8810template <
class Emitter>
8811bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8814 assert(!
R->hasTrivialDtor());
8817 const Function *DtorFunc = getFunction(
Dtor);
8820 assert(DtorFunc->hasThisPointer());
8821 assert(DtorFunc->getNumParams() == 1);
8822 return this->emitCall(DtorFunc, 0, Loc);
8827template <
class Emitter>
8828bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8840 return this->emitPopPtr(Loc);
8842 for (ssize_t I = N - 1; I >= 1; --I) {
8843 if (!this->emitConstUint64(I, Loc))
8845 if (!this->emitArrayElemPtrUint64(Loc))
8847 if (!this->emitDestructionPop(ElemDesc, Loc))
8851 if (!this->emitConstUint64(0, Loc))
8853 if (!this->emitArrayElemPtrPopUint64(Loc))
8855 return this->emitDestructionPop(ElemDesc, Loc);
8860 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8865template <
class Emitter>
8866bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8867 assert(!DiscardResult &&
"Should've been checked before");
8868 return this->emitGetOpaquePtr(D, CU, E);
8871template <
class Emitter>
8874 return this->emitConstFloat(
Floating(F), Info);
8876 APInt I = F.bitcastToAPInt();
8877 return this->emitConstFloat(
8878 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8879 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8890template <
class Emitter>
8891bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8904 if (!this->emitGetPtrLocal(*LocalIndex, E))
8914 if (!this->visit(SubExpr))
8916 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8917 unsigned TempOffset =
8918 allocateLocalPrimitive(SubExpr, *FromT,
true);
8919 if (!this->visit(SubExpr))
8921 if (!this->emitSetLocal(*FromT, TempOffset, E))
8923 if (!this->emitGetPtrLocal(TempOffset, E))
8930 if (!this->emitBitCast(E))
8932 return DiscardResult ? this->emitPopPtr(E) :
true;
8936 const llvm::fltSemantics *TargetSemantics =
nullptr;
8938 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8944 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8946 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8947 ResultBitWidth, TargetSemantics,
8952 return this->emitPop(*ToT, E);
8961template <
class Emitter>
8962bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8967 unsigned NumElems = 0;
8970 NumElems = VT->getNumElements();
8971 ElemType = VT->getElementType();
8973 NumElems = MT->getNumElementsFlattened();
8974 ElemType = MT->getElementType();
8977 PrimType ElemT = classifyPrim(ElemType);
8978 for (
unsigned I = 0; I != NumElems; ++I) {
8979 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8981 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8983 if (!this->emitInitElem(ElemT, I, E))
8993 QualType ArrElemType = CAT->getElementType();
8994 unsigned ArrSize = CAT->getZExtSize();
8997 for (
unsigned I = 0; I != ArrSize; ++I) {
8998 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9000 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9002 if (!this->emitInitElem(*ElemT, I, E))
9006 for (
unsigned I = 0; I != ArrSize; ++I) {
9007 if (!this->emitConstUint32(I, E))
9009 if (!this->emitArrayElemPtrUint32(E))
9011 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9013 if (!this->emitFinishInitPop(E))
9023 const Record *
R = getRecord(DestType);
9027 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9029 const Record::Base *B =
R->getBase(BS.getType());
9031 if (!this->emitGetPtrBase(B->Offset, E))
9033 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9035 if (!this->emitFinishInitPop(E))
9040 for (
const Record::Field &F :
R->fields()) {
9041 if (F.isUnnamedBitField())
9044 QualType FieldType = F.Decl->getType();
9046 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9048 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9050 if (F.isBitField()) {
9051 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9054 if (!this->emitInitField(*FieldT, F.Offset, E))
9058 if (!this->emitGetPtrField(F.Offset, E))
9060 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9062 if (!this->emitPopPtr(E))
9075template <
class Emitter>
9076unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9079 return VT->getNumElements();
9081 return MT->getNumElementsFlattened();
9085 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9089 const Record *
R = getRecord(Ty);
9093 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9095 Count += countHLSLFlatElements(BS.getType());
9097 for (
const Record::Field &F :
R->fields()) {
9098 if (F.isUnnamedBitField())
9100 Count += countHLSLFlatElements(F.Decl->getType());
9105 if (canClassify(Ty))
9114template <
class Emitter>
9115bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9116 QualType SrcType,
unsigned SrcOffset,
9121 auto saveToLocal = [&](
PrimType T) ->
bool {
9122 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9123 if (!this->emitSetLocal(
T, Offset, E))
9125 Elements.push_back({Offset,
T});
9131 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9132 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9133 return std::nullopt;
9138 unsigned NumElems = 0;
9141 NumElems = VT->getNumElements();
9142 ElemType = VT->getElementType();
9144 NumElems = MT->getNumElementsFlattened();
9145 ElemType = MT->getElementType();
9148 PrimType ElemT = classifyPrim(ElemType);
9149 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9150 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9152 if (!this->emitArrayElemPop(ElemT, I, E))
9154 if (!saveToLocal(ElemT))
9164 QualType ArrElemType = CAT->getElementType();
9165 unsigned ArrSize = CAT->getZExtSize();
9168 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9169 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9171 if (!this->emitArrayElemPop(*ElemT, I, E))
9173 if (!saveToLocal(*ElemT))
9177 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9178 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9180 if (!this->emitConstUint32(I, E))
9182 if (!this->emitArrayElemPtrPopUint32(E))
9187 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9198 const Record *
R = getRecord(SrcType);
9202 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9204 if (Elements.size() >= MaxElements)
9206 const Record::Base *B =
R->getBase(BS.getType());
9208 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9210 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9215 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9221 for (
const Record::Field &F :
R->fields()) {
9222 if (Elements.size() >= MaxElements)
9224 if (F.isUnnamedBitField())
9227 QualType FieldType = F.Decl->getType();
9228 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9230 if (!this->emitGetPtrFieldPop(F.Offset, E))
9234 if (!this->emitLoadPop(*FieldT, E))
9236 if (!saveToLocal(*FieldT))
9240 if (!FieldPtrOffset)
9242 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9258template <
class Emitter>
9259bool Compiler<Emitter>::emitHLSLConstructAggregate(
9265 const auto &Src = Elements[ElemIdx++];
9266 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9268 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9272 unsigned NumElems = 0;
9275 NumElems = VT->getNumElements();
9276 ElemType = VT->getElementType();
9278 NumElems = MT->getNumElementsFlattened();
9279 ElemType = MT->getElementType();
9282 PrimType DestElemT = classifyPrim(ElemType);
9283 for (
unsigned I = 0; I != NumElems; ++I) {
9284 if (!loadAndCast(DestElemT, ElemType))
9286 if (!this->emitInitElem(DestElemT, I, E))
9296 QualType ArrElemType = CAT->getElementType();
9297 unsigned ArrSize = CAT->getZExtSize();
9300 for (
unsigned I = 0; I != ArrSize; ++I) {
9301 if (!loadAndCast(*ElemT, ArrElemType))
9303 if (!this->emitInitElem(*ElemT, I, E))
9307 for (
unsigned I = 0; I != ArrSize; ++I) {
9308 if (!this->emitConstUint32(I, E))
9310 if (!this->emitArrayElemPtrUint32(E))
9312 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9314 if (!this->emitFinishInitPop(E))
9324 const Record *
R = getRecord(DestType);
9328 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9330 const Record::Base *B =
R->getBase(BS.getType());
9332 if (!this->emitGetPtrBase(B->Offset, E))
9334 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9336 if (!this->emitFinishInitPop(E))
9341 for (
const Record::Field &F :
R->fields()) {
9342 if (F.isUnnamedBitField())
9345 QualType FieldType = F.Decl->getType();
9347 if (!loadAndCast(*FieldT, FieldType))
9349 if (F.isBitField()) {
9350 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9353 if (!this->emitInitField(*FieldT, F.Offset, E))
9357 if (!this->emitGetPtrField(F.Offset, E))
9359 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9361 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 bool isTrivialMemoryOperation(const CXXMethodDecl *MD)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
const Expr * ignorePointerCastsAndParens(const Expr *E)
A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. This ignores some c...
bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD)
Determine whether a type would actually be read by an lvalue-to-rvalue conversion.
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
bool hasLValuePath() 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 isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
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 registerRedecl(const VarDecl *VD, const APValue &V)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const VarDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * findVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
VariableScope * getParent() const
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 DefaultInit(InterpState &S, CodePtr OpPC, const CXXConstructorDecl *Ctor)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __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()