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: {
468 if (!this->
visit(SubExpr))
470 return this->emitLoadPopL(E);
480 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
486 if (
auto GlobalIndex =
P.getGlobal(D))
487 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
488 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
489 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
490 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
491 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
492 return this->emitGetParam(*SubExprT, It->second.Index, E);
504 if (!this->emitGetPtrLocal(*LocalIndex, E))
508 if (!this->
visit(SubExpr))
512 return this->emitLoadPop(*SubExprT, E);
517 return this->emitMemcpy(E);
520 case CK_DerivedToBaseMemberPointer: {
531 ->getMostRecentCXXRecordDecl();
533 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
534 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
536 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
544 case CK_BaseToDerivedMemberPointer: {
555 ->getMostRecentCXXRecordDecl();
559 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
561 PathI != PathE; ++PathI) {
562 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
563 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
565 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
572 assert(ToDecl != CurDecl);
573 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
575 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
581 case CK_UncheckedDerivedToBase:
582 case CK_DerivedToBase: {
587 if (
const auto *PT = dyn_cast<PointerType>(Ty))
588 return PT->getPointeeType()->getAsCXXRecordDecl();
589 return Ty->getAsCXXRecordDecl();
596 if (B->isVirtual()) {
597 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
599 CurType = B->getType();
601 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
602 if (!this->emitGetPtrBasePop(
605 CurType = B->getType();
612 case CK_BaseToDerived: {
615 unsigned DerivedOffset =
621 return this->emitGetPtrDerivedPop(DerivedOffset,
626 case CK_FloatingCast: {
629 return this->emitVectorConversion(E->
getSubExpr(), E);
633 if (!this->
visit(SubExpr))
635 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
639 case CK_IntegralToFloating: {
641 return this->emitVectorConversion(E->
getSubExpr(), E);
644 if (!this->
visit(SubExpr))
646 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
647 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
648 TargetSemantics, getFPOptions(E), E);
651 case CK_FloatingToBoolean: {
653 return this->emitVectorConversion(E->
getSubExpr(), E);
657 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
658 return this->emitConstBool(FL->getValue().isNonZero(), E);
659 if (!this->
visit(SubExpr))
661 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
664 case CK_FloatingToIntegral: {
666 return this->emitVectorConversion(E->
getSubExpr(), E);
669 if (!this->
visit(SubExpr))
673 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
676 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
679 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
682 case CK_NullToPointer:
683 case CK_NullToMemberPointer: {
686 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
691 case CK_PointerToIntegral: {
692 if (!this->
visit(SubExpr))
698 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
704 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
706 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
707 return this->emitCastPointerIntegral(
T, E);
710 case CK_ArrayToPointerDecay: {
711 if (!this->
visit(SubExpr))
713 return this->emitArrayDecay(E);
716 case CK_IntegralToPointer: {
718 assert(IntType->isIntegralOrEnumerationType());
719 if (!this->
visit(SubExpr))
733 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
736 case CK_AtomicToNonAtomic:
737 case CK_ConstructorConversion:
738 case CK_FunctionToPointerDecay:
739 case CK_NonAtomicToAtomic:
741 case CK_UserDefinedConversion:
742 case CK_CPointerToObjCPointerCast:
745 case CK_AddressSpaceConversion: {
749 if (!this->
visit(SubExpr))
754 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
761 return this->emitPopPtr(E);
779 return this->emitBuiltinBitCast(E);
794 if (!this->
visit(SubExpr))
802 return this->emitFnPtrCast(E);
810 if (!this->
visit(SubExpr))
812 return this->emitDecayPtr(*FromT, *ToT, E);
814 case CK_IntegralToBoolean:
815 case CK_FixedPointToBoolean: {
817 return this->emitVectorConversion(E->
getSubExpr(), E);
823 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
824 return this->emitConst(IL->getValue(), E);
825 if (!this->
visit(SubExpr))
830 case CK_IntegralCast:
832 return this->emitVectorConversion(E->
getSubExpr(), E);
834 case CK_BooleanToSignedIntegral: {
841 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
846 if (!this->emitConst(IL->getValue(), SubExpr))
849 if (!this->
visit(SubExpr))
857 if (!ED->isFixed()) {
858 if (!this->emitCheckEnumValue(*FromT, ED, E))
864 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
867 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
872 if (!this->emitCast(*FromT, *ToT, E))
875 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
876 return this->emitNeg(*ToT, E);
880 case CK_PointerToBoolean:
881 if (!this->
visit(SubExpr))
883 return this->emitIsNonNullPtr(E);
885 case CK_MemberPointerToBoolean:
886 if (!this->
visit(SubExpr))
888 return this->emitIsNonNullMemberPtr(E);
890 case CK_IntegralComplexToBoolean:
891 case CK_FloatingComplexToBoolean: {
892 if (!this->
visit(SubExpr))
894 return this->emitComplexBoolCast(SubExpr);
897 case CK_IntegralComplexToReal:
898 case CK_FloatingComplexToReal:
899 return this->emitComplexReal(SubExpr);
901 case CK_IntegralRealToComplex:
902 case CK_FloatingRealToComplex: {
909 if (!this->emitGetPtrLocal(*LocalIndex, E))
918 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
920 return this->emitInitElem(
T, 1, SubExpr);
923 case CK_IntegralComplexCast:
924 case CK_FloatingComplexCast:
925 case CK_IntegralComplexToFloatingComplex:
926 case CK_FloatingComplexToIntegralComplex: {
933 if (!this->emitGetPtrLocal(*LocalIndex, E))
940 unsigned SubExprOffset =
942 if (!this->
visit(SubExpr))
944 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
952 for (
unsigned I = 0; I != 2; ++I) {
953 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
955 if (!this->emitArrayElemPop(SourceElemT, I, E))
959 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
963 if (!this->emitInitElem(DestElemT, I, E))
969 case CK_VectorSplat: {
980 if (!this->emitGetPtrLocal(*LocalIndex, E))
986 unsigned ElemOffset =
990 if (!this->
visit(SubExpr))
995 if (!this->emitSetLocal(ElemT, ElemOffset, E))
998 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
999 if (!this->emitGetLocal(ElemT, ElemOffset, E))
1001 if (!this->emitInitElem(ElemT, I, E))
1008 case CK_HLSLVectorTruncation: {
1013 if (!this->
visit(SubExpr))
1015 return this->emitArrayElemPop(*ResultT, 0, E);
1024 if (!this->emitGetPtrLocal(*LocalIndex, E))
1029 if (!this->
visit(SubExpr))
1031 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1035 case CK_IntegralToFixedPoint: {
1036 if (!this->
visit(SubExpr))
1040 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1045 return this->emitPopFixedPoint(E);
1048 case CK_FloatingToFixedPoint: {
1049 if (!this->
visit(SubExpr))
1053 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1054 if (!this->emitCastFloatingFixedPoint(Sem, E))
1057 return this->emitPopFixedPoint(E);
1060 case CK_FixedPointToFloating: {
1061 if (!this->
visit(SubExpr))
1063 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1064 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1067 return this->emitPopFloat(E);
1070 case CK_FixedPointToIntegral: {
1071 if (!this->
visit(SubExpr))
1074 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1077 return this->emitPop(IntegralT, E);
1080 case CK_FixedPointCast: {
1081 if (!this->
visit(SubExpr))
1084 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1085 if (!this->emitCastFixedPoint(Sem, E))
1088 return this->emitPopFixedPoint(E);
1096 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1098 case CK_LValueBitCast:
1103 case CK_HLSLArrayRValue: {
1110 if (!this->emitGetPtrLocal(*LocalIndex, E))
1113 if (!this->
visit(SubExpr))
1115 return this->emitMemcpy(E);
1118 case CK_HLSLMatrixTruncation: {
1123 if (!this->
visit(SubExpr))
1125 return this->emitArrayElemPop(*ResultT, 0, E);
1134 if (!this->emitGetPtrLocal(*LocalIndex, E))
1139 if (!this->
visit(SubExpr))
1141 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1145 case CK_HLSLAggregateSplatCast: {
1155 if (!this->emitGetPtrLocal(*LocalIndex, E))
1162 unsigned SrcOffset =
1165 if (!this->
visit(SubExpr))
1167 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1171 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1174 case CK_HLSLElementwiseCast: {
1185 unsigned SrcPtrOffset =
1187 if (!this->
visit(SubExpr))
1189 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1193 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1195 if (Elements.empty())
1198 const HLSLFlatElement &Src = Elements[0];
1199 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1201 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1208 if (!this->emitGetPtrLocal(*LocalIndex, E))
1212 unsigned SrcOffset =
1214 if (!this->
visit(SubExpr))
1216 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1220 unsigned ElemCount = countHLSLFlatElements(DestType);
1223 Elements.reserve(ElemCount);
1224 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1229 assert(Elements.size() == ElemCount &&
1230 "Source type has fewer scalar elements than the destination type");
1232 return emitHLSLConstructAggregate(DestType, Elements, E);
1239 const Record::Field *RF = R->getField(UnionField);
1242 if (!this->
visit(SubExpr))
1244 if (RF->isBitField())
1245 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1247 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1250 if (!this->emitGetPtrField(RF->Offset, E))
1252 if (!this->emitActivate(E))
1258 return this->emitInvalid(E);
1260 llvm_unreachable(
"Unhandled clang::CastKind enum");
1263template <
class Emitter>
1265 return this->emitBuiltinBitCast(E);
1268template <
class Emitter>
1273 return this->emitConst(
LE->getValue(),
LE);
1276template <
class Emitter>
1282 return this->emitFloat(F, E);
1285template <
class Emitter>
1295 if (!this->emitGetPtrLocal(*LocalIndex, E))
1302 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1304 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1309template <
class Emitter>
1317 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1322template <
class Emitter>
1327template <
class Emitter>
1354 return this->emitComplexComparison(LHS, RHS, E);
1362 if (!this->
visit(LHS))
1365 if (!this->
visit(RHS))
1368 if (!this->emitToMemberPtr(E))
1374 if (!this->emitCastMemberPtrPtr(E))
1391 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1397 if (!this->emitGetPtrLocal(*ResultIndex, E))
1404 return this->emitCMP3(*
LT, CmpInfo, E);
1407 if (!
LT || !RT || !
T)
1417 return this->visitAssignment(LHS, RHS, E);
1424 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1428 return this->emitPopBool(E);
1430 return this->emitCast(
PT_Bool, *
T, E);
1434 auto Discard = [
this,
T, E](
bool Result) {
1442 return MaybeCastToBool(this->emitEQ(*
LT, E));
1444 return MaybeCastToBool(this->emitNE(*
LT, E));
1446 return MaybeCastToBool(this->emitLT(*
LT, E));
1448 return MaybeCastToBool(this->emitLE(*
LT, E));
1450 return MaybeCastToBool(this->emitGT(*
LT, E));
1452 return MaybeCastToBool(this->emitGE(*
LT, E));
1455 return Discard(this->emitSubf(getFPOptions(E), E));
1456 return Discard(this->emitSub(*
T, E));
1459 return Discard(this->emitAddf(getFPOptions(E), E));
1460 return Discard(this->emitAdd(*
T, E));
1463 return Discard(this->emitMulf(getFPOptions(E), E));
1464 return Discard(this->emitMul(*
T, E));
1466 return Discard(this->emitRem(*
T, E));
1469 return Discard(this->emitDivf(getFPOptions(E), E));
1470 return Discard(this->emitDiv(*
T, E));
1472 return Discard(this->emitBitAnd(*
T, E));
1474 return Discard(this->emitBitOr(*
T, E));
1476 return Discard(this->emitShl(*
LT, *RT, E));
1478 return Discard(this->emitShr(*
LT, *RT, E));
1480 return Discard(this->emitBitXor(*
T, E));
1483 llvm_unreachable(
"Already handled earlier");
1488 llvm_unreachable(
"Unhandled binary op");
1493template <
class Emitter>
1499 if ((Op != BO_Add && Op != BO_Sub) ||
1510 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1511 if (!this->
visit(E))
1514 return this->emitDecayPtr(
T,
PT_Ptr, E);
1523 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1531 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1534 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1541 if (!visitAsPointer(RHS, *RT))
1543 if (!this->
visit(LHS))
1547 if (!visitAsPointer(LHS, *
LT))
1549 if (!this->
visit(RHS))
1560 if (!this->emitAddOffset(OffsetType, E))
1564 if (!this->emitSubOffset(OffsetType, E))
1573 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1578 return this->emitPop(ExprT, E);
1582template <
class Emitter>
1591 LabelTy LabelTrue = this->getLabel();
1592 LabelTy LabelEnd = this->getLabel();
1596 if (!this->jumpTrue(LabelTrue, E))
1601 if (!this->jump(LabelEnd, E))
1604 this->emitLabel(LabelTrue);
1605 this->emitConstBool(
true, E);
1606 this->fallthrough(LabelEnd);
1607 this->emitLabel(LabelEnd);
1610 assert(Op == BO_LAnd);
1613 LabelTy LabelFalse = this->getLabel();
1614 LabelTy LabelEnd = this->getLabel();
1618 if (!this->jumpFalse(LabelFalse, E))
1623 if (!this->jump(LabelEnd, E))
1626 this->emitLabel(LabelFalse);
1627 this->emitConstBool(
false, E);
1628 this->fallthrough(LabelEnd);
1629 this->emitLabel(LabelEnd);
1633 return this->emitPopBool(E);
1638 return this->emitCast(
PT_Bool,
T, E);
1643template <
class Emitter>
1650 if (!this->emitGetPtrLocal(*LocalIndex, E))
1659 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1660 unsigned ResultOffset = ~0u;
1666 if (!this->emitDupPtr(E))
1668 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1673 LHSType = AT->getValueType();
1676 RHSType = AT->getValueType();
1685 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1690 if (!this->
visit(LHS))
1692 if (!this->
visit(RHS))
1694 if (!this->emitMulc(ElemT, E))
1697 return this->emitPopPtr(E);
1701 if (Op == BO_Div && RHSIsComplex) {
1708 if (!LHSIsComplex) {
1713 LHSOffset = *LocalIndex;
1715 if (!this->emitGetPtrLocal(LHSOffset, E))
1718 if (!this->
visit(LHS))
1721 if (!this->emitInitElem(ElemT, 0, E))
1724 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1726 if (!this->emitInitElem(ElemT, 1, E))
1729 if (!this->
visit(LHS))
1733 if (!this->
visit(RHS))
1735 if (!this->emitDivc(ElemT, E))
1738 return this->emitPopPtr(E);
1745 if (!this->
visit(LHS))
1747 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1752 if (!this->
visit(LHS))
1754 if (!this->emitSetLocal(LHST, LHSOffset, E))
1762 if (!this->
visit(RHS))
1764 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1769 if (!this->
visit(RHS))
1771 if (!this->emitSetLocal(RHST, RHSOffset, E))
1778 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1779 unsigned ElemIndex,
unsigned Offset,
1780 const Expr *E) ->
bool {
1782 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1784 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1787 if (ElemIndex == 0 || !LoadZero)
1794 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1797 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1804 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1807 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1810 if (!this->emitAddf(getFPOptions(E), E))
1813 if (!this->emitAdd(ResultElemT, E))
1818 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1821 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1824 if (!this->emitSubf(getFPOptions(E), E))
1827 if (!this->emitSub(ResultElemT, E))
1832 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1835 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1839 if (!this->emitMulf(getFPOptions(E), E))
1842 if (!this->emitMul(ResultElemT, E))
1847 assert(!RHSIsComplex);
1848 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1851 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1855 if (!this->emitDivf(getFPOptions(E), E))
1858 if (!this->emitDiv(ResultElemT, E))
1869 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1872 if (!this->emitPop(ResultElemT, E))
1877 return this->emitPopPtr(E);
1883template <
class Emitter>
1888 "Comma op should be handled in VisitBinaryOperator");
1892 LHSType = AT->getValueType();
1895 RHSType = AT->getValueType();
1909 if (!this->emitGetPtrLocal(*LocalIndex, E))
1918 PrimType ElemT = this->classifyVectorElementType(LHSType);
1919 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1923 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1926 if (!this->
visit(LHS))
1928 if (!this->
visit(RHS))
1930 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1933 return this->emitPopPtr(E);
1938 unsigned LHSOffset =
1940 if (!this->
visit(LHS))
1942 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1946 unsigned RHSOffset =
1948 if (!this->
visit(RHS))
1950 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1962 if (NeedIntPromot) {
1964 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1969 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1970 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1972 if (!this->emitArrayElemPop(ElemT, Index, E))
1975 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1977 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1979 }
else if (NeedIntPromot) {
1980 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1986#define EMIT_ARITH_OP(OP) \
1988 if (ElemT == PT_Float) { \
1989 if (!this->emit##OP##f(getFPOptions(E), E)) \
1992 if (!this->emit##OP(ElemT, E)) \
1998 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1999 if (!getElem(LHSOffset, ElemT, I))
2001 if (!getElem(RHSOffset, RHSElemT, I))
2013 if (!this->emitRem(ElemT, E))
2017 if (!this->emitBitAnd(OpT, E))
2021 if (!this->emitBitOr(OpT, E))
2025 if (!this->emitBitXor(OpT, E))
2029 if (!this->emitShl(OpT, RHSElemT, E))
2033 if (!this->emitShr(OpT, RHSElemT, E))
2037 if (!this->emitEQ(ElemT, E))
2041 if (!this->emitNE(ElemT, E))
2045 if (!this->emitLE(ElemT, E))
2049 if (!this->emitLT(ElemT, E))
2053 if (!this->emitGE(ElemT, E))
2057 if (!this->emitGT(ElemT, E))
2062 if (!this->emitBitAnd(ResultElemT, E))
2067 if (!this->emitBitOr(ResultElemT, E))
2071 return this->emitInvalid(E);
2080 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2082 if (!this->emitNeg(ResultElemT, E))
2088 if (NeedIntPromot &&
2089 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2093 if (!this->emitInitElem(ResultElemT, I, E))
2102template <
class Emitter>
2112 auto LHSSemaInt = LHSSema.toOpaqueInt();
2114 auto RHSSemaInt = RHSSema.toOpaqueInt();
2116 if (!this->
visit(LHS))
2124 if (!this->
visit(RHS))
2133 auto ConvertResult = [&](
bool R) ->
bool {
2137 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2138 if (ResultSema != CommonSema)
2139 return this->emitCastFixedPoint(ResultSema, E);
2143 auto MaybeCastToBool = [&](
bool Result) {
2148 return this->emitPop(
T, E);
2150 return this->emitCast(
PT_Bool,
T, E);
2156 return MaybeCastToBool(this->emitEQFixedPoint(E));
2158 return MaybeCastToBool(this->emitNEFixedPoint(E));
2160 return MaybeCastToBool(this->emitLTFixedPoint(E));
2162 return MaybeCastToBool(this->emitLEFixedPoint(E));
2164 return MaybeCastToBool(this->emitGTFixedPoint(E));
2166 return MaybeCastToBool(this->emitGEFixedPoint(E));
2168 return ConvertResult(this->emitAddFixedPoint(E));
2170 return ConvertResult(this->emitSubFixedPoint(E));
2172 return ConvertResult(this->emitMulFixedPoint(E));
2174 return ConvertResult(this->emitDivFixedPoint(E));
2176 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2178 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2181 return this->emitInvalid(E);
2184 llvm_unreachable(
"unhandled binop opcode");
2187template <
class Emitter>
2196 if (!this->
visit(SubExpr))
2198 if (!this->emitNegFixedPoint(E))
2201 return this->emitPopFixedPoint(E);
2207 llvm_unreachable(
"Unhandled unary opcode");
2210template <
class Emitter>
2219 return this->visitZeroInitializer(*
T, QT, E);
2232 return this->visitZeroRecordInitializer(R, E);
2239 return this->visitZeroArrayInitializer(QT, E);
2243 QualType ElemQT = ComplexTy->getElementType();
2245 for (
unsigned I = 0; I < 2; ++I) {
2246 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2248 if (!this->emitInitElem(ElemT, I, E))
2255 unsigned NumVecElements = VecT->getNumElements();
2256 QualType ElemQT = VecT->getElementType();
2259 for (
unsigned I = 0; I < NumVecElements; ++I) {
2260 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2262 if (!this->emitInitElem(ElemT, I, E))
2269 unsigned NumElems = MT->getNumElementsFlattened();
2270 QualType ElemQT = MT->getElementType();
2273 for (
unsigned I = 0; I != NumElems; ++I) {
2274 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2276 if (!this->emitInitElem(ElemT, I, E))
2285template <
class Emitter>
2298 for (
const Expr *SubExpr : {LHS, RHS}) {
2299 if (!this->
visit(SubExpr)) {
2306 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2307 if (!this->emitExpandPtr(E))
2318 return this->emitError(E);
2321 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2325 if (!this->emitArrayElemPtrPop(*IndexT, E))
2328 return this->emitPopPtr(E);
2334 return this->emitLoadPop(*
T, E);
2337template <
class Emitter>
2339 const Expr *ArrayFiller,
const Expr *E) {
2344 QT = AT->getValueType();
2347 if (
Inits.size() == 0)
2349 return this->emitInvalid(E);
2362 if (
Inits.size() == 0)
2363 return this->visitZeroInitializer(*
T, QT, E);
2364 assert(
Inits.size() == 1);
2378 if (!this->emitGetPtrLocal(*LocalIndex, E))
2393 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2399 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2408 bool BitField = FieldToInit->isBitField();
2410 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2411 FieldToInit->bitWidth(), E);
2413 return this->emitInitBitField(
T, FieldToInit->Offset,
2414 FieldToInit->bitWidth(), E);
2416 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2417 return this->emitInitField(
T, FieldToInit->Offset, E);
2420 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2428 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2431 if (
Activate && !this->emitActivate(E))
2434 if (!this->emitStartInit(
Init))
2441 if (
Inits.size() == 0) {
2442 if (!this->visitZeroRecordInitializer(R, E))
2447 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2448 FToInit = ILE->getInitializedFieldInUnion();
2452 const Record::Field *FieldToInit = R->getField(FToInit);
2454 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2457 if (!initCompositeField(FieldToInit,
Init,
true))
2461 return this->emitFinishInit(E);
2464 assert(!R->isUnion());
2465 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2467 const Record::Base *B = R->getBase(BI);
2470 if (!this->emitGetPtrBase(B->Offset,
Init))
2476 unsigned FieldIndex = 0;
2477 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2478 const Record::Field *FieldToInit = R->getField(FieldIndex);
2479 if (FieldToInit->isUnnamedBitField()) {
2494 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2496 }
else if (!initCompositeField(FieldToInit,
Init)) {
2504 assert(R->getNumVirtualBases() == 0);
2506 return this->emitFinishInit(E);
2511 Ctx.getASTContext().getAsConstantArrayType(QT);
2516 !this->emitCheckArrayDestSize(NumElems, E))
2519 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2523 unsigned ElementIndex = 0;
2525 if (
const auto *EmbedS =
2526 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2534 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2535 getFPOptions(E), E))
2541 return this->emitInitElem(TargetT, ElemIndex, IL);
2543 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2559 for (; ElementIndex != NumElems; ++ElementIndex) {
2565 return this->emitFinishInit(E);
2569 unsigned NumInits =
Inits.size();
2574 QualType ElemQT = ComplexTy->getElementType();
2576 if (NumInits == 0) {
2578 for (
unsigned I = 0; I < 2; ++I) {
2579 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2581 if (!this->emitInitElem(ElemT, I, E))
2584 }
else if (NumInits == 2) {
2585 unsigned InitIndex = 0;
2590 if (!this->emitInitElem(ElemT, InitIndex, E))
2599 unsigned NumVecElements = VecT->getNumElements();
2600 assert(NumVecElements >=
Inits.size());
2602 QualType ElemQT = VecT->getElementType();
2606 unsigned InitIndex = 0;
2613 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2614 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2615 InitVecT->getNumElements(), E))
2617 InitIndex += InitVecT->getNumElements();
2619 if (!this->emitInitElem(ElemT, InitIndex, E))
2625 assert(InitIndex <= NumVecElements);
2628 for (; InitIndex != NumVecElements; ++InitIndex) {
2629 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2631 if (!this->emitInitElem(ElemT, InitIndex, E))
2638 unsigned NumElems = MT->getNumElementsFlattened();
2639 assert(
Inits.size() == NumElems);
2641 QualType ElemQT = MT->getElementType();
2647 for (
unsigned I = 0; I != NumElems; ++I) {
2650 if (!this->emitInitElem(ElemT, I, E))
2661template <
class Emitter>
2668 return this->emitInitElem(*InitT, ElemIndex,
Init);
2674 if (!this->emitConstUint32(ElemIndex,
Init))
2676 if (!this->emitArrayElemPtrUint32(
Init))
2681template <
class Emitter>
2684 bool Activate,
bool IsOperatorCall) {
2686 llvm::BitVector NonNullArgs;
2687 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2690 bool ExplicitMemberFn =
false;
2691 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2692 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2694 unsigned ArgIndex = 0;
2695 for (
const Expr *Arg : Args) {
2697 if (!this->
visit(Arg))
2705 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2706 if (DeclIndex < FuncDecl->getNumParams())
2707 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2716 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2724 if (!this->emitActivate(Arg))
2728 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2731 if (!this->emitCheckNonNullArg(ArgT, Arg))
2742template <
class Emitter>
2747template <
class Emitter>
2753template <
class Emitter>
2759template <
class Emitter>
2777template <
class Emitter>
2779 auto It = E->
begin();
2780 return this->
visit(*It);
2784 UnaryExprOrTypeTrait Kind) {
2785 bool AlignOfReturnsPreferred =
2792 T = Ref->getPointeeType();
2794 if (
T.getQualifiers().hasUnaligned())
2800 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2806template <
class Emitter>
2810 UnaryExprOrTypeTrait Kind = E->
getKind();
2813 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2819 ArgType = Ref->getPointeeType();
2825 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2826 return this->emitInvalid(E);
2828 if (Kind == UETT_SizeOf)
2837 return this->emitConst(Size.getQuantity(), E);
2840 if (Kind == UETT_CountOf) {
2846 if (
const auto *CAT =
2850 return this->emitConst(CAT->getSize(), E);
2860 if (VAT->getElementType()->isArrayType()) {
2861 std::optional<APSInt> Res =
2863 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2868 return this->emitConst(*Res, E);
2873 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2893 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2896 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2906 return this->emitConst(Size.getQuantity(), E);
2909 if (Kind == UETT_VectorElements) {
2914 return this->emitConst(VT->getNumElements(), E);
2916 return this->emitSizelessVectorElementSize(E);
2919 if (Kind == UETT_VecStep) {
2921 unsigned N = VT->getNumElements();
2928 return this->emitConst(N, E);
2930 return this->emitConst(1, E);
2933 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2942 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2944 return this->emitInvalid(E);
2946 return this->emitConst(
2947 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2955template <
class Emitter>
2964 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2969 if (VD->getInit() && !VD->getInit()->isValueDependent())
2970 VD->evaluateValue();
2971 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2972 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2974 if (
Member->getType()->isReferenceType())
2975 return this->emitLoadPopPtr(E);
2984 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2985 MD && !MD->isStatic()) {
2989 if (!this->
discard(Base) && !this->emitSideEffect(E))
3004 const Record::Field *F = R->getField(FD);
3008 const auto maybeLoadValue = [&]() ->
bool {
3012 return this->emitLoadPop(*
T, E);
3017 if (F->Decl->getType()->isReferenceType())
3018 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3019 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3022template <
class Emitter>
3032template <
class Emitter>
3046 if (!this->
visit(Common))
3048 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3062 for (
size_t I = 0; I != Size; ++I) {
3074template <
class Emitter>
3089 return this->emitGetLocal(SubExprT, It->second, E);
3092 if (!this->
visit(SourceExpr))
3099 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3108 return this->emitGetLocal(SubExprT, LocalIndex, E);
3112template <
class Emitter>
3125 bool IsBcpCall =
false;
3126 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3127 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3131 LabelTy LabelEnd = this->getLabel();
3132 LabelTy LabelFalse = this->getLabel();
3135 if (!this->emitPushIgnoreDiags(E))
3143 if (this->checkingForUndefinedBehavior()) {
3146 if (!this->
discard(FalseExpr))
3163 if (!this->jumpFalse(LabelFalse, E))
3168 if (!this->jump(LabelEnd, E))
3170 this->emitLabel(LabelFalse);
3174 this->fallthrough(LabelEnd);
3175 this->emitLabel(LabelEnd);
3178 return this->emitPopIgnoreDiags(E);
3182template <
class Emitter>
3188 return this->emitGetStringPtr(E, E);
3192 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3193 assert(CAT &&
"a string literal that's not a constant array?");
3198 unsigned N = std::min(ArraySize, E->
getLength());
3201 for (
unsigned I = 0; I != N; ++I) {
3204 if (CharWidth == 1) {
3205 this->emitConstSint8(CodeUnit, E);
3206 this->emitInitElemSint8(I, E);
3207 }
else if (CharWidth == 2) {
3208 this->emitConstUint16(CodeUnit, E);
3209 this->emitInitElemUint16(I, E);
3210 }
else if (CharWidth == 4) {
3211 this->emitConstUint32(CodeUnit, E);
3212 this->emitInitElemUint32(I, E);
3214 llvm_unreachable(
"unsupported character width");
3219 for (
unsigned I = N; I != ArraySize; ++I) {
3220 if (CharWidth == 1) {
3221 this->emitConstSint8(0, E);
3222 this->emitInitElemSint8(I, E);
3223 }
else if (CharWidth == 2) {
3224 this->emitConstUint16(0, E);
3225 this->emitInitElemUint16(I, E);
3226 }
else if (CharWidth == 4) {
3227 this->emitConstUint32(0, E);
3228 this->emitInitElemUint32(I, E);
3230 llvm_unreachable(
"unsupported character width");
3237template <
class Emitter>
3241 return this->emitDummyPtr(E, E);
3244template <
class Emitter>
3246 auto &A =
Ctx.getASTContext();
3255template <
class Emitter>
3263 auto &A =
Ctx.getASTContext();
3267 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3268 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3274 return this->emitGetStringPtr(SL, E);
3277template <
class Emitter>
3281 return this->emitConst(E->
getValue(), E);
3284template <
class Emitter>
3306 if (!this->emitLoad(LHST, E))
3309 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3310 LHSComputationType, E))
3322 unsigned TempOffset =
3324 if (!this->emitSetLocal(*RT, TempOffset, E))
3330 if (!this->emitLoad(LHST, E))
3334 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3335 LHSComputationType, E))
3339 if (!this->emitGetLocal(*RT, TempOffset, E))
3345 if (!this->emitAddf(getFPOptions(E), E))
3349 if (!this->emitSubf(getFPOptions(E), E))
3353 if (!this->emitMulf(getFPOptions(E), E))
3357 if (!this->emitDivf(getFPOptions(E), E))
3368 return this->emitStorePop(LHST, E);
3369 return this->emitStore(LHST, E);
3372template <
class Emitter>
3381 if (Op != BO_AddAssign && Op != BO_SubAssign)
3390 if (!this->emitLoad(*
LT, LHS))
3396 if (Op == BO_AddAssign) {
3397 if (!this->emitAddOffset(*RT, E))
3400 if (!this->emitSubOffset(*RT, E))
3405 return this->emitStorePopPtr(E);
3406 return this->emitStorePtr(E);
3409template <
class Emitter>
3422 if (!
Ctx.getLangOpts().CPlusPlus14)
3423 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3425 if (!
LT || !RT || !ResultT || !LHSComputationT)
3442 if (!this->emitLoad(*
LT, E))
3444 if (
LT != LHSComputationT &&
3445 !this->emitIntegralCast(*
LT, *LHSComputationT,
3459 unsigned TempOffset =
3462 if (!this->emitSetLocal(*RT, TempOffset, E))
3469 if (!this->emitLoad(*
LT, E))
3471 if (
LT != LHSComputationT &&
3472 !this->emitIntegralCast(*
LT, *LHSComputationT,
3477 if (!this->emitGetLocal(*RT, TempOffset, E))
3484 if (!this->emitAdd(*LHSComputationT, E))
3488 if (!this->emitSub(*LHSComputationT, E))
3492 if (!this->emitMul(*LHSComputationT, E))
3496 if (!this->emitDiv(*LHSComputationT, E))
3500 if (!this->emitRem(*LHSComputationT, E))
3504 if (!this->emitShl(*LHSComputationT, *RT, E))
3508 if (!this->emitShr(*LHSComputationT, *RT, E))
3512 if (!this->emitBitAnd(*LHSComputationT, E))
3516 if (!this->emitBitXor(*LHSComputationT, E))
3520 if (!this->emitBitOr(*LHSComputationT, E))
3524 llvm_unreachable(
"Unimplemented compound assign operator");
3528 if (ResultT != LHSComputationT &&
3529 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3535 return this->emitStoreBitFieldPop(*ResultT, E);
3536 return this->emitStorePop(*ResultT, E);
3539 return this->emitStoreBitField(*ResultT, E);
3540 return this->emitStore(*ResultT, E);
3543template <
class Emitter>
3551template <
class Emitter>
3566 if (!
Ctx.getLangOpts().CPlusPlus11)
3573 for (
const Expr *LHS : CommaLHSs) {
3588 if (this->constantFolding())
3599 if (!this->
visit(Inner))
3604 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3607 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3610 return this->emitGetPtrGlobal(*GlobalIndex, E);
3613 if (!this->checkLiteralType(Inner))
3616 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3622 return this->emitInitGlobalTempComp(TempDecl, E);
3635 unsigned LocalIndex =
3637 if (!this->VarScope->LocalsAlwaysEnabled &&
3638 !this->emitEnableLocal(LocalIndex, E))
3641 if (!this->
visit(Inner))
3643 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3646 return this->emitGetPtrLocal(LocalIndex, E);
3649 if (!this->checkLiteralType(Inner))
3656 if (!this->VarScope->LocalsAlwaysEnabled &&
3657 !this->emitEnableLocal(*LocalIndex, E))
3660 if (!this->emitGetPtrLocal(*LocalIndex, E))
3667template <
class Emitter>
3678 if (!this->
visit(SubExpr))
3682 return this->emitPopPtr(E);
3686template <
class Emitter>
3707 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3712 if (
P.isGlobalInitialized(*GlobalIndex))
3718 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3730 unsigned LocalIndex;
3734 LocalIndex = *MaybeIndex;
3738 if (!this->emitGetPtrLocal(LocalIndex, E))
3742 return this->
visit(
Init) && this->emitInit(*
T, E);
3746template <
class Emitter>
3757 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3761 if (!R || R->getNumFields() == 0)
3763 const Record::Field *Field = R->getField(0
U);
3768 return this->emitInitField(*Field->T, Field->Offset, E);
3775template <
class Emitter>
3779 return this->emitConst(E->
getValue(), E);
3782template <
class Emitter>
3795 for (
const Record::Field &F : R->fields()) {
3797 if (!
Init ||
Init->containsErrors())
3805 if (!this->emitInitField(*
T, F.Offset, E))
3808 if (!this->emitGetPtrField(F.Offset, E))
3819template <
class Emitter>
3825 return this->emitGetStringPtr(E, E);
3829template <
class Emitter>
3834 return this->emitInvalid(E);
3837template <
class Emitter>
3851 if (!this->emitInvalidCast(
CastKind,
false, E))
3859 bool Fatal = (ToT != FromT);
3866template <
class Emitter>
3868 if (!
Ctx.getLangOpts().CPlusPlus20) {
3889 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3894 return this->emitPopPtr(E);
3898template <
class Emitter>
3904 return this->emitConstBool(E->
getValue(), E);
3907template <
class Emitter>
3912 if (
T->isRecordType()) {
3926 if (!this->emitGetPtrLocal(*LocalIndex, E))
3934 T->getAsCXXRecordDecl()))
3944 if (!this->visitZeroRecordInitializer(R, E))
3955 if (!this->emitDefaultInit(Ctor, E))
3958 return this->emitPopPtr(E);
3966 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3968 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3969 if (!this->emitCheckFunctionDecl(Ctor, E))
3980 assert(
Func->hasThisPointer());
3981 assert(!
Func->hasRVO());
3985 if (!this->emitDupPtr(E))
3989 for (
const auto *Arg : E->
arguments()) {
3990 if (!this->
visit(Arg))
3994 if (
Func->isVariadic()) {
3995 uint32_t VarArgSize = 0;
3996 unsigned NumParams =
Func->getNumWrittenParams();
3997 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
4001 if (!this->emitCallVar(
Func, VarArgSize, E))
4004 if (!this->emitCall(
Func, 0, E)) {
4009 (void)this->emitPopPtr(E);
4015 return this->emitPopPtr(E);
4019 if (
T->isArrayType()) {
4024 if (!this->emitDupPtr(E))
4028 initArrayDimension = [&](
QualType T) ->
bool {
4029 if (!
T->isArrayType()) {
4031 for (
const auto *Arg : E->
arguments()) {
4032 if (!this->
visit(Arg))
4036 return this->emitCall(
Func, 0, E);
4040 Ctx.getASTContext().getAsConstantArrayType(
T);
4045 for (
size_t I = 0; I != NumElems; ++I) {
4046 if (!this->emitConstUint64(I, E))
4048 if (!this->emitArrayElemPtrUint64(E))
4050 if (!initArrayDimension(ElemTy))
4053 return this->emitPopPtr(E);
4056 return initArrayDimension(E->
getType());
4062template <
class Emitter>
4072 assert(Val.
isInt());
4074 return this->emitConst(I, E);
4081 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4082 return this->
visit(LValueExpr);
4097 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4101 const APValue &
V = UGCD->getValue();
4102 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4103 const Record::Field *F = R->getField(I);
4104 const APValue &FieldValue =
V.getStructField(I);
4108 if (!this->emitInitField(*F->T, F->Offset, E))
4116template <
class Emitter>
4122 for (
unsigned I = 0; I != N; ++I) {
4129 if (!this->
discard(ArrayIndexExpr))
4135 if (!this->
visit(ArrayIndexExpr))
4137 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4141 if (!this->
visit(ArrayIndexExpr))
4145 if (!this->emitCast(IndexT,
PT_Sint64, E))
4155 return this->emitOffsetOf(
T, E, E);
4158template <
class Emitter>
4167 return this->visitZeroInitializer(*
T, Ty, E);
4174 if (!this->emitGetPtrLocal(*LocalIndex, E))
4182 ElemQT = CT->getElementType();
4185 NumElems = VT->getNumElements();
4186 ElemQT = VT->getElementType();
4192 for (
unsigned I = 0; I != NumElems; ++I) {
4193 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4195 if (!this->emitInitElem(ElemT, I, E))
4204template <
class Emitter>
4209template <
class Emitter>
4215template <
class Emitter>
4220template <
class Emitter>
4225 return this->emitConst(E->
getValue(), E);
4228template <
class Emitter>
4233 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4248 unsigned ParamIndex = 0;
4252 if (!this->emitGetParam(PT, ParamIndex, E))
4257 return this->emitCall(F, 0, E);
4262template <
class Emitter>
4270 const Expr *PlacementDest =
nullptr;
4271 bool IsNoThrow =
false;
4276 if (PlacementArgs != 0) {
4285 if (PlacementArgs == 1) {
4287 if (OperatorNew->isReservedGlobalPlacementOperator()) {
4288 if (!this->emitCheckPlacementNew(E, E))
4290 PlacementDest = Arg1;
4294 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4301 return this->emitInvalidNewDeleteExpr(E, E);
4305 return this->emitInvalid(E);
4307 }
else if (!OperatorNew
4308 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4309 return this->emitInvalidNewDeleteExpr(E, E);
4312 if (!PlacementDest) {
4317 Desc =
P.createDescriptor(E, *ElemT);
4319 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4326 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4330 const Expr *Stripped = *ArraySizeExpr;
4331 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4332 Stripped = ICE->getSubExpr())
4333 if (ICE->getCastKind() != CK_NoOp &&
4334 ICE->getCastKind() != CK_IntegralCast)
4342 if (!this->
visit(Stripped))
4344 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4347 if (PlacementDest) {
4348 if (!this->
visit(PlacementDest))
4350 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4352 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4355 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4360 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4364 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4371 size_t StaticInitElems = 0;
4372 const Expr *DynamicInit =
nullptr;
4376 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4377 StaticInitElems = CAT->getZExtSize();
4382 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4383 if (ILE->hasArrayFiller())
4384 DynamicInit = ILE->getArrayFiller();
4403 const Function *CtorFunc =
nullptr;
4404 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4408 }
else if (!DynamicInit && !ElemT)
4411 LabelTy EndLabel = this->getLabel();
4412 LabelTy StartLabel = this->getLabel();
4417 if (!this->emitDupPtr(E))
4419 if (!this->emitIsNonNullPtr(E))
4421 if (!this->jumpFalse(EndLabel, E))
4428 if (!this->emitConst(StaticInitElems,
SizeT, E))
4430 if (!this->emitSetLocal(
SizeT, Iter, E))
4433 this->fallthrough(StartLabel);
4434 this->emitLabel(StartLabel);
4436 if (!this->emitGetLocal(
SizeT, Iter, E))
4438 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4440 if (!this->emitLT(
SizeT, E))
4442 if (!this->jumpFalse(EndLabel, E))
4446 if (!this->emitGetLocal(
SizeT, Iter, E))
4448 if (!this->emitArrayElemPtr(
SizeT, E))
4451 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4456 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4458 if (!this->emitStorePop(*InitT, E))
4462 if (!this->visitZeroArrayInitializer(ElemType, E))
4465 }
else if (DynamicInit) {
4467 if (!this->
visit(DynamicInit))
4469 if (!this->emitStorePop(*InitT, E))
4476 if (!this->visitZeroInitializer(
4480 if (!this->emitStorePop(*ElemT, E))
4484 if (!this->emitCall(CtorFunc, 0, E))
4489 if (!this->emitGetPtrLocal(Iter, E))
4491 if (!this->emitIncPop(
SizeT,
false, E))
4494 if (!this->jump(StartLabel, E))
4497 this->fallthrough(EndLabel);
4498 this->emitLabel(EndLabel);
4502 if (PlacementDest) {
4503 if (!this->
visit(PlacementDest))
4505 if (!this->emitCheckNewTypeMismatch(E, E))
4510 if (!this->emitAlloc(Desc, E))
4519 if (!this->emitInit(*ElemT, E))
4530 return this->emitPopPtr(E);
4535template <
class Emitter>
4541 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4542 return this->emitInvalidNewDeleteExpr(E, E);
4551template <
class Emitter>
4557 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4562 return this->emitGetFnPtr(
Func, E);
4565template <
class Emitter>
4569 auto canonType = [](
const Type *
T) {
4570 return T->getCanonicalTypeUnqualified().getTypePtr();
4578 return this->emitGetTypeid(
4582 return this->emitGetTypeid(
4591 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4597 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4600 return this->emitPopPtr(E);
4604template <
class Emitter>
4608 return this->emitDummyPtr(E, E);
4609 return this->emitError(E);
4612template <
class Emitter>
4615 return this->emitDummyPtr(E, E);
4616 return this->emitError(E);
4619template <
class Emitter>
4621 assert(
Ctx.getLangOpts().CPlusPlus);
4622 return this->emitConstBool(E->
getValue(), E);
4625template <
class Emitter>
4637 return this->emitDummyPtr(GuidDecl, E);
4642 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4651 assert(
V.isStruct());
4652 assert(
V.getStructNumBases() == 0);
4656 return this->emitFinishInit(E);
4659template <
class Emitter>
4669template <
class Emitter>
4678template <
class Emitter>
4684template <
class Emitter>
4688 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4692 if (OVE->isUnique())
4708template <
class Emitter>
4713template <
class Emitter>
4715 return this->emitError(E);
4718template <
class Emitter>
4724 return this->emitDummyPtr(E, E);
4727template <
class Emitter>
4728bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4733 QualType ElemType = VT->getElementType();
4734 PrimType ElemT = classifyPrim(ElemType);
4736 PrimType SrcElemT = classifyVectorElementType(SrcType);
4742 if (!this->emitGetPtrLocal(*LocalIndex, E))
4746 unsigned SrcOffset =
4747 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4748 if (!this->visit(Src))
4750 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4753 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4754 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4756 if (!this->emitArrayElemPop(SrcElemT, I, E))
4760 if (SrcElemT != ElemT) {
4761 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4763 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4764 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4768 if (!this->emitInitElem(ElemT, I, E))
4774template <
class Emitter>
4776 return emitVectorConversion(E->
getSrcExpr(), E);
4779template <
class Emitter>
4783 return this->emitInvalid(E);
4792 assert(NumOutputElems > 0);
4798 if (!this->emitGetPtrLocal(*LocalIndex, E))
4803 unsigned VectorOffsets[2];
4804 for (
unsigned I = 0; I != 2; ++I) {
4807 if (!this->
visit(Vecs[I]))
4809 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4812 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4814 assert(ShuffleIndex >= -1);
4815 if (ShuffleIndex == -1)
4816 return this->emitInvalidShuffleVectorIndex(I, E);
4818 assert(ShuffleIndex < (NumInputElems * 2));
4819 if (!this->emitGetLocal(
PT_Ptr,
4820 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4822 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4823 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4826 if (!this->emitInitElem(ElemT, I, E))
4831 return this->emitPopPtr(E);
4836template <
class Emitter>
4841 Base->getType()->isVectorType() ||
4847 if (Indices.size() == 1) {
4852 if (!this->emitConstUint32(Indices[0], E))
4854 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4864 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4872 if (!this->emitGetPtrLocal(*ResultIndex, E))
4880 uint32_t DstIndex = 0;
4881 for (uint32_t I : Indices) {
4882 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4884 if (!this->emitArrayElemPop(ElemT, I, E))
4886 if (!this->emitInitElem(ElemT, DstIndex, E))
4896template <
class Emitter>
4900 return this->
discard(SubExpr) && this->emitInvalid(E);
4906 return this->emitDummyPtr(E, E);
4909template <
class Emitter>
4914 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4923 if (!this->emitGetPtrLocal(*LocalIndex, E))
4927 if (!this->
visit(SubExpr))
4929 if (!this->emitConstUint8(0, E))
4931 if (!this->emitArrayElemPtrPopUint8(E))
4933 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4936 PrimType SecondFieldT = *R->getField(1u)->T;
4938 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4940 if (!this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E))
4943 return this->emitPopPtr(E);
4946 assert(SecondFieldT ==
PT_Ptr);
4948 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4950 if (!this->emitExpandPtr(E))
4954 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4957 if (!this->emitInitFieldPtr(R->getField(1u)->Offset, E))
4960 return this->emitPopPtr(E);
4964template <
class Emitter>
4979 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4983 return this->emitUnsupported(E);
4992 return this->
Visit(E);
4999 return this->
Visit(E);
5003 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5006 if (
const auto *CE = dyn_cast<CastExpr>(E);
5008 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
5015 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5018 if (
const auto *CE = dyn_cast<CastExpr>(E);
5019 CE && (CE->getCastKind() == CK_DerivedToBase ||
5020 CE->getCastKind() == CK_UncheckedDerivedToBase ||
5021 CE->getCastKind() == CK_NoOp))
5041 if (!this->emitGetPtrLocal(*LocalIndex, E))
5051 return this->
Visit(E);
5054template <
class Emitter>
5060 return this->
Visit(E) && this->emitFinishInit(E);
5063template <
class Emitter>
5069 return this->
Visit(E) && this->emitFinishInitPop(E);
5075 return this->
Visit(E);
5086 if (!this->
visit(E))
5088 return this->emitComplexBoolCast(E);
5093 if (!this->
visit(E))
5101 return this->emitIsNonNullPtr(E);
5105 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5108 return this->emitCast(*
T,
PT_Bool, E);
5111template <
class Emitter>
5115 QT = AT->getValueType();
5119 return this->emitZeroBool(E);
5121 return this->emitZeroSint8(E);
5123 return this->emitZeroUint8(E);
5125 return this->emitZeroSint16(E);
5127 return this->emitZeroUint16(E);
5129 return this->emitZeroSint32(E);
5131 return this->emitZeroUint32(E);
5133 return this->emitZeroSint64(E);
5135 return this->emitZeroUint64(E);
5137 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5139 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5141 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5144 return this->emitNullMemberPtr(0,
nullptr, E);
5146 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5147 return this->emitFloat(F, E);
5150 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5154 llvm_unreachable(
"unknown primitive type");
5157template <
class Emitter>
5158bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5160 bool IsCompleteClass) {
5164 for (
const Record::Field &Field :
R->fields()) {
5165 if (Field.isUnnamedBitField())
5172 if (!this->visitZeroInitializer(
T, QT, E))
5175 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5179 if (!this->emitInitField(
T, Field.Offset, E))
5184 if (!this->emitGetPtrField(Field.Offset, E))
5191 if (!this->visitZeroInitializer(
T, ET, E))
5193 if (!this->emitInitElem(
T, I, E))
5198 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5201 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5209 if (!this->emitFinishInitActivatePop(E))
5213 if (!this->emitFinishInitPop(E))
5217 for (
const Record::Base &B :
R->bases()) {
5218 if (!this->emitGetPtrBase(B.Offset, E))
5220 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5222 if (!this->emitFinishInitPop(E))
5226 if (IsCompleteClass) {
5227 for (
const Record::Base &B :
R->virtual_bases()) {
5230 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5232 if (!this->emitFinishInitPop(E))
5240template <
class Emitter>
5241bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5242 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5243 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5248 for (
size_t I = 0; I != NumElems; ++I) {
5249 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5251 if (!this->emitInitElem(*ElemT, I, E))
5257 const Record *
R = getRecord(ElemType);
5261 for (
size_t I = 0; I != NumElems; ++I) {
5262 if (!this->emitConstUint32(I, E))
5264 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5266 if (!this->visitZeroRecordInitializer(R, E))
5268 if (!this->emitPopPtr(E))
5274 for (
size_t I = 0; I != NumElems; ++I) {
5275 if (!this->emitConstUint32(I, E))
5277 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5279 if (!this->visitZeroArrayInitializer(ElemType, E))
5281 if (!this->emitPopPtr(E))
5290template <
class Emitter>
5291bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5293 if (!canClassify(E->
getType()))
5298 if (!this->visit(LHS))
5300 if (!this->visit(RHS))
5303 if (!this->visit(RHS))
5305 if (!this->visit(LHS))
5313 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5317 bool Activates = refersToUnion(LHS);
5320 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5323 if (DiscardResult) {
5324 if (BitField && Activates)
5325 return this->emitStoreBitFieldActivatePop(RHT, E);
5327 return this->emitStoreBitFieldPop(RHT, E);
5329 return this->emitStoreActivatePop(RHT, E);
5331 return this->emitStorePop(RHT, E);
5334 auto maybeLoad = [&](
bool Result) ->
bool {
5340 return this->emitLoadPop(RHT, E);
5344 if (BitField && Activates)
5345 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5347 return maybeLoad(this->emitStoreBitField(RHT, E));
5349 return maybeLoad(this->emitStoreActivate(RHT, E));
5351 return maybeLoad(this->emitStore(RHT, E));
5354template <
class Emitter>
5355template <
typename T>
5359 return this->emitConstSint8(
Value, Info);
5361 return this->emitConstUint8(
Value, Info);
5363 return this->emitConstSint16(
Value, Info);
5365 return this->emitConstUint16(
Value, Info);
5367 return this->emitConstSint32(
Value, Info);
5369 return this->emitConstUint32(
Value, Info);
5371 return this->emitConstSint64(
Value, Info);
5373 return this->emitConstUint64(
Value, Info);
5375 return this->emitConstBool(
Value, Info);
5382 llvm_unreachable(
"Invalid integral type");
5385 llvm_unreachable(
"unknown primitive type");
5388template <
class Emitter>
5389template <
typename T>
5390bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5391 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5394template <
class Emitter>
5398 return this->emitConstIntAPS(
Value, Info);
5400 return this->emitConstIntAP(
Value, Info);
5402 if (
Value.isSigned())
5403 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5404 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5407template <
class Emitter>
5411 return this->emitConstIntAPS(
Value, Info);
5413 return this->emitConstIntAP(
Value, Info);
5416 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5417 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5420template <
class Emitter>
5421bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5422 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5425template <
class Emitter>
5440 return Local.Offset;
5443template <
class Emitter>
5448 bool IsTemporary =
false;
5452 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5453 Init = VarD->getInit();
5455 if (
const auto *E = Src.
asExpr()) {
5465 return std::nullopt;
5472 return Local.Offset;
5475template <
class Emitter>
5484 return std::nullopt;
5494 return Local.Offset;
5497template <
class Emitter>
5499 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5500 return PT->getPointeeType()->getAsCanonical<RecordType>();
5506 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5510template <
class Emitter>
5512 return P.getOrCreateRecord(RD);
5515template <
class Emitter>
5517 return Ctx.getOrCreateFunction(FD);
5520template <
class Emitter>
5526 auto maybeDestroyLocals = [&]() ->
bool {
5527 if (DestroyToplevelScope)
5528 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5529 return this->emitCheckAllocations(E);
5536 return this->emitRetVoid(E) && maybeDestroyLocals();
5544 return this->emitRet(*
T, E) && maybeDestroyLocals();
5552 if (!this->emitGetPtrLocal(*LocalOffset, E))
5560 return this->emitRetValue(E) && maybeDestroyLocals();
5563 return maybeDestroyLocals() &&
false;
5566template <
class Emitter>
5568 bool DestroyToplevelScope) {
5572 return this->
visitExpr(E, DestroyToplevelScope);
5575template <
class Emitter>
5587 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5588 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5602template <
class Emitter>
5604 bool ConstantContext) {
5607 if (!ConstantContext) {
5622 auto GlobalIndex =
P.getGlobal(VD);
5623 assert(GlobalIndex);
5625 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5628 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5636 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5638 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5641 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5651 auto GlobalIndex =
P.getGlobal(VD);
5652 assert(GlobalIndex);
5653 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5662 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5665template <
class Emitter>
5676 if (!this->isActive())
5681 if (
Init &&
Init->isValueDependent())
5685 auto checkDecl = [&]() ->
bool {
5687 return !NeedsOp || this->emitCheckDecl(VD, VD);
5694 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5697 if (
P.isGlobalInitialized(*GlobalIndex))
5701 }
else if ((GlobalIndex =
5716 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5719 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5722 if (!this->emitStartInit(
Init))
5728 if (!this->emitEndInit(
Init))
5731 return this->emitFinishInitGlobal(
Init);
5741 if (!
Init ||
Init->getType()->isVoidType())
5750 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5762 if (!this->emitCheckRefInit(
Init))
5766 return this->emitSetLocal(*VarT, Offset, VD);
5774 if (!this->emitGetPtrLocal(*Offset,
Init))
5782template <
class Emitter>
5805 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5811 return this->emitDestructionPop(D, VD);
5820 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5844template <
class Emitter>
5859 unsigned ParamIndex = 0;
5866 const Expr *Arg = Args[ParamIndex];
5867 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5869 unsigned ArgOffset =
5871 if (!this->
visit(Arg))
5873 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5879 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5891 if (
This->getType()->isPointerType()) {
5894 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5901 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5923template <
class Emitter>
5929 return this->emitConst(Val.
getInt(), ValType, Info);
5931 return this->emitFloat(Val.
getFloat(), Info);
5935 if (!this->emitGetMemberPtr(MemberDecl, Info))
5941 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5947 return this->emitNullMemberPtr(0,
nullptr, Info);
5952 return this->emitNull(ValType, 0,
nullptr, Info);
5956 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5957 return this->
visit(BaseExpr);
5962 QualType EntryType = VD->getType();
5965 for (
auto &Entry : Path) {
5967 uint64_t Index = Entry.getAsArrayIndex();
5970 if (!this->emitConst(Index,
PT_Uint64, Info))
5972 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5974 EntryType = ElemType;
5981 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5982 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5984 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5986 EntryType = FD->getType();
5990 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
5995 if (!this->emitGetPtrVirtBasePop(
Base, Info))
5998 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
6011template <
class Emitter>
6014 bool IsCompleteClass) {
6020 if (IsCompleteClass)
6027 const Record::Base *RB = R->getBase(I);
6028 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6030 if (!this->emitGetPtrBase(RB->Offset, Info))
6035 if (!this->emitFinishInitPop(Info))
6043 const Record::Field *RF = R->getField(I);
6044 QualType FieldType = RF->Decl->getType();
6049 if (!this->emitInitField(*PT, RF->Offset, Info))
6052 if (!this->emitGetPtrField(RF->Offset, Info))
6056 if (!this->emitFinishInitPop(Info))
6062 if (IsCompleteClass) {
6067 const Record::Base *RB = R->getVirtualBase(I);
6068 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6076 if (!this->emitFinishInitPop(Info))
6092 const Record::Field *RF = R->getField(UnionField);
6093 QualType FieldType = RF->Decl->getType();
6098 if (RF->isBitField())
6099 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6101 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6104 if (!this->emitGetPtrField(RF->Offset, Info))
6106 if (!this->emitActivate(Info))
6110 return this->emitPopPtr(Info);
6114 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6115 QualType ElemType = ArrType->getElementType();
6118 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6119 const APValue &Elem = A >= InitializedElems
6128 if (!this->emitInitElem(*ElemT, A, Info))
6131 if (!this->emitConstUint32(A, Info))
6133 if (!this->emitArrayElemPtrUint32(Info))
6137 if (!this->emitPopPtr(Info))
6148template <
class Emitter>
6150 if (
P.getGlobal(VD))
6155 llvm_unreachable(
"Why didn't that work?");
6159 "registerRedecl should only be called with primitive values");
6164 return this->emitInitGlobal(
T, *GlobalIndex, {});
6167template <
class Emitter>
6169 unsigned BuiltinID) {
6175 if (!
Ctx.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
6176 return this->emitInvalid(E);
6185 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6190 return this->emitConst(0, E);
6193 if (!this->emitStartSpeculation(E))
6195 LabelTy EndLabel = this->getLabel();
6196 if (!this->speculate(E, EndLabel))
6198 if (!this->emitEndSpeculation(E))
6200 this->fallthrough(EndLabel);
6208 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6209 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6210 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6211 BuiltinID == Builtin::BI__builtin_function_start) {
6214 return this->emitDummyPtr(E, E);
6225 if (!this->emitGetPtrLocal(*LocalIndex, E))
6230 switch (BuiltinID) {
6231 case Builtin::BI__builtin_object_size:
6232 case Builtin::BI__builtin_dynamic_object_size: {
6236 if (!this->
visit(Arg0))
6247 case Builtin::BI__assume:
6248 case Builtin::BI__builtin_assume:
6251 case Builtin::BI__atomic_is_lock_free:
6252 case Builtin::BI__atomic_always_lock_free: {
6263 for (
const auto *Arg : E->
arguments()) {
6264 if (!this->
visit(Arg))
6270 if (!this->emitCallBI(E, BuiltinID, E))
6288template <
class Emitter>
6309 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6310 DD && DD->isTrivial()) {
6312 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6314 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6315 this->emitPopPtr(E);
6321 bool ActivateLHS =
false;
6329 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6330 OCE && OCE->isAssignmentOp()) {
6331 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6334 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6335 if (!this->
visit(MCE->getImplicitObjectArgument()))
6342 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6360 if (!this->emitGetPtrLocal(*LocalIndex, E))
6368 if (!this->emitGetPtrLocal(*LocalIndex, E))
6372 if (!this->emitDupPtr(E))
6377 const Expr *ReversedArgs[2];
6378 bool IsAssignmentOperatorCall =
false;
6379 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6380 OCE && OCE->isAssignmentOp()) {
6384 assert(Args.size() == 2);
6385 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6387 IsAssignmentOperatorCall =
true;
6388 ReversedArgs[0] = Args[1];
6389 ReversedArgs[1] = Args[0];
6390 Args = ReversedArgs;
6397 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6398 MD && MD->isStatic()) {
6402 Args = Args.drop_front();
6406 bool Devirtualized =
false;
6409 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6417 if (!this->
visit(Callee))
6419 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6421 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6423 if (!this->emitGetMemberPtrBase(E))
6426 const auto *InstancePtr = MC->getImplicitObjectArgument();
6433 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6434 Devirtualized =
true;
6435 if (!this->
visit(Stripped))
6438 if (!this->
visit(InstancePtr))
6442 if (!this->
visit(InstancePtr))
6446 }
else if (
const auto *PD =
6447 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6448 if (!this->emitCheckPseudoDtor(E))
6456 return this->emitPseudoDtor(E);
6457 }
else if (!FuncDecl) {
6461 if (!this->
visit(Callee))
6463 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6472 if (IsAssignmentOperatorCall) {
6473 assert(Args.size() == 2);
6476 if (!this->emitFlip(Arg2T, Arg1T, E))
6490 assert(HasRVO ==
Func->hasRVO());
6492 bool HasQualifier =
false;
6493 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6494 HasQualifier = ME->hasQualifier();
6496 bool IsVirtual =
false;
6497 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6498 IsVirtual = !Devirtualized && MD->isVirtual();
6503 if (IsVirtual && !HasQualifier) {
6504 uint32_t VarArgSize = 0;
6505 unsigned NumParams =
6506 Func->getNumWrittenParams() +
6508 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6511 if (!this->emitCallVirt(
Func, VarArgSize, E))
6513 }
else if (
Func->isVariadic()) {
6514 uint32_t VarArgSize = 0;
6515 unsigned NumParams =
6516 Func->getNumWrittenParams() +
6518 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6520 if (!this->emitCallVar(
Func, VarArgSize, E))
6523 if (!this->emitCall(
Func, 0, E))
6532 uint32_t ArgSize = 0;
6533 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6539 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6541 if (!this->emitGetMemberPtrDecl(E))
6544 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6547 if (!this->emitCallPtr(ArgSize, E, E))
6558template <
class Emitter>
6565template <
class Emitter>
6572template <
class Emitter>
6577 return this->emitConstBool(E->
getValue(), E);
6580template <
class Emitter>
6586 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6587 return this->emitNullPtr(Val,
nullptr, E);
6590template <
class Emitter>
6598 return this->emitZero(
T, E);
6601template <
class Emitter>
6606 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6607 if (this->LambdaThisCapture.Offset > 0) {
6608 if (this->LambdaThisCapture.IsPtr)
6609 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6610 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6619 return this->emitThis(E);
6634 unsigned StartIndex = 0;
6635 unsigned EndIndex = 0;
6637 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6639 EndIndex = StartIndex;
6646 for (; StartIndex > 0; --StartIndex) {
6657 if (StartIndex == 0 && EndIndex == 0)
6668 assert(StartIndex <= EndIndex);
6671 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6683 case Stmt::CompoundStmtClass:
6685 case Stmt::DeclStmtClass:
6687 case Stmt::ReturnStmtClass:
6689 case Stmt::IfStmtClass:
6691 case Stmt::WhileStmtClass:
6693 case Stmt::DoStmtClass:
6695 case Stmt::ForStmtClass:
6697 case Stmt::CXXForRangeStmtClass:
6699 case Stmt::BreakStmtClass:
6701 case Stmt::ContinueStmtClass:
6703 case Stmt::SwitchStmtClass:
6705 case Stmt::CaseStmtClass:
6707 case Stmt::DefaultStmtClass:
6709 case Stmt::AttributedStmtClass:
6711 case Stmt::CXXTryStmtClass:
6713 case Stmt::NullStmtClass:
6716 case Stmt::GCCAsmStmtClass:
6717 case Stmt::MSAsmStmtClass:
6718 case Stmt::GotoStmtClass:
6719 return this->emitInvalid(S);
6720 case Stmt::LabelStmtClass:
6722 case Stmt::CXXExpansionStmtInstantiationClass:
6726 if (
const auto *E = dyn_cast<Expr>(S))
6733template <
class Emitter>
6736 for (
const auto *InnerStmt : S->
body())
6739 return Scope.destroyLocals();
6742template <
class Emitter>
6743bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6744 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6745 for (
auto *BD : DD->flat_bindings())
6746 if (
auto *KD = BD->getHoldingVar();
6747 KD && !this->visitVarDecl(KD, KD->getInit()))
6761template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6763 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6764 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6771 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6776 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6777 ICE && (ICE->getCastKind() == CK_NoOp ||
6778 ICE->getCastKind() == CK_DerivedToBase ||
6779 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6780 E = ICE->getSubExpr();
6784 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6785 const auto *ThisRecord =
6786 This->getType()->getPointeeType()->getAsRecordDecl();
6787 if (!ThisRecord->isUnion())
6790 if (
const auto *Ctor =
6791 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6792 return Ctor->getParent() == ThisRecord;
6801template <
class Emitter>
6803 bool EvaluateConditionDecl) {
6804 for (
const auto *D : DS->
decls()) {
6809 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6810 assert(ESD->getInstantiations() &&
"not expanded?");
6811 if (!this->
visitStmt(ESD->getInstantiations()))
6816 const auto *VD = dyn_cast<VarDecl>(D);
6823 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6830template <
class Emitter>
6833 return this->emitUnsupported(RS);
6839 if (!this->
visit(RE))
6845 if (RE->getType()->isVoidType()) {
6846 if (!this->
visit(RE))
6849 if (RE->containsErrors())
6854 if (!this->emitRVOPtr(RE))
6860 return this->emitRetVoid(RS);
6866 return this->emitRetVoid(RS);
6872 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6879 if (
auto *CondInit = IS->
getInit()) {
6895 return visitChildStmt(IS->
getThen());
6897 return visitChildStmt(Else);
6903 if (!this->emitIsConstantContext(IS))
6906 if (!this->emitIsConstantContext(IS))
6908 if (!this->emitInv(IS))
6922 LabelTy LabelElse = this->getLabel();
6923 LabelTy LabelEnd = this->getLabel();
6924 if (!this->jumpFalse(LabelElse, IS))
6926 if (!visitChildStmt(IS->
getThen()))
6928 if (!this->jump(LabelEnd, IS))
6930 this->emitLabel(LabelElse);
6931 if (!visitChildStmt(Else))
6933 this->emitLabel(LabelEnd);
6935 LabelTy LabelEnd = this->getLabel();
6936 if (!this->jumpFalse(LabelEnd, IS))
6938 if (!visitChildStmt(IS->
getThen()))
6940 this->emitLabel(LabelEnd);
6949template <
class Emitter>
6954 LabelTy CondLabel = this->getLabel();
6955 LabelTy EndLabel = this->getLabel();
6959 this->fallthrough(CondLabel);
6960 this->emitLabel(CondLabel);
6976 if (!this->jumpFalse(EndLabel, S))
6986 if (!this->jump(CondLabel, S))
6988 this->fallthrough(EndLabel);
6989 this->emitLabel(EndLabel);
6998 LabelTy StartLabel = this->getLabel();
6999 LabelTy EndLabel = this->getLabel();
7000 LabelTy CondLabel = this->getLabel();
7004 this->fallthrough(StartLabel);
7005 this->emitLabel(StartLabel);
7011 this->fallthrough(CondLabel);
7012 this->emitLabel(CondLabel);
7019 if (!this->jumpTrue(StartLabel, S))
7022 this->fallthrough(EndLabel);
7023 this->emitLabel(EndLabel);
7027template <
class Emitter>
7035 LabelTy EndLabel = this->getLabel();
7036 LabelTy CondLabel = this->getLabel();
7037 LabelTy IncLabel = this->getLabel();
7044 this->fallthrough(CondLabel);
7045 this->emitLabel(CondLabel);
7057 if (!this->jumpFalse(EndLabel, S))
7066 this->fallthrough(IncLabel);
7067 this->emitLabel(IncLabel);
7073 if (!this->jump(CondLabel, S))
7077 this->emitLabel(EndLabel);
7083template <
class Emitter>
7093 LabelTy EndLabel = this->getLabel();
7094 LabelTy CondLabel = this->getLabel();
7095 LabelTy IncLabel = this->getLabel();
7111 this->fallthrough(CondLabel);
7112 this->emitLabel(CondLabel);
7115 if (!this->jumpFalse(EndLabel, S))
7126 this->fallthrough(IncLabel);
7127 this->emitLabel(IncLabel);
7134 if (!this->jump(CondLabel, S))
7137 this->fallthrough(EndLabel);
7138 this->emitLabel(EndLabel);
7142template <
class Emitter>
7153 if (LI.BreakLabel) {
7154 TargetLabel = *LI.BreakLabel;
7155 BreakScope = LI.BreakOrContinueScope;
7161 if (LI.Name == TargetLoop) {
7162 TargetLabel = *LI.BreakLabel;
7163 BreakScope = LI.BreakOrContinueScope;
7174 C =
C->getParent()) {
7175 if (!
C->destroyLocals())
7179 return this->jump(*TargetLabel, S);
7182template <
class Emitter>
7193 if (LI.ContinueLabel) {
7194 TargetLabel = *LI.ContinueLabel;
7195 ContinueScope = LI.BreakOrContinueScope;
7201 if (LI.Name == TargetLoop) {
7202 TargetLabel = *LI.ContinueLabel;
7203 ContinueScope = LI.BreakOrContinueScope;
7213 C =
C->getParent()) {
7214 if (!
C->destroyLocals())
7218 return this->jump(*TargetLabel, S);
7221template <
class Emitter>
7231 LabelTy EndLabel = this->getLabel();
7236 if (
const auto *CondInit = S->
getInit())
7245 if (!this->
visit(Cond))
7247 if (!this->emitSetLocal(CondT, CondVar, S))
7257 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7260 if (CS->caseStmtIsGNURange()) {
7261 LabelTy EndOfRangeCheck = this->getLabel();
7262 const Expr *Low = CS->getLHS();
7263 const Expr *High = CS->getRHS();
7267 if (!this->emitGetLocal(CondT, CondVar, CS))
7269 if (!this->
visit(Low))
7272 if (!this->emitGE(
LT, S))
7274 if (!this->jumpFalse(EndOfRangeCheck, S))
7277 if (!this->emitGetLocal(CondT, CondVar, CS))
7279 if (!this->
visit(High))
7282 if (!this->emitLE(HT, S))
7286 this->emitLabel(EndOfRangeCheck);
7291 if (
Value->isValueDependent())
7296 if (!this->emitGetLocal(CondT, CondVar, CS))
7302 if (!this->emitEQ(ValueT, S))
7307 assert(!DefaultLabel);
7308 DefaultLabel = this->getLabel();
7315 if (!this->jump(*DefaultLabel, S))
7318 if (!this->jump(EndLabel, S))
7326 this->fallthrough(EndLabel);
7327 this->emitLabel(EndLabel);
7332template <
class Emitter>
7340 return this->emitUnsupported(S);
7345template <
class Emitter>
7352 if (LI.DefaultLabel) {
7353 DefaultLabel = *LI.DefaultLabel;
7358 this->emitLabel(DefaultLabel);
7362template <
class Emitter>
7369 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7372 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7373 !this->Ctx.getLangOpts().MSVCCompat) {
7375 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7381 const Expr *Assumption = AA->getAssumption();
7392 if (!this->emitAssume(Assumption))
7401 if (IsMSVCConstexprAttr)
7402 return this->emitPopMSVCCE(S);
7406template <
class Emitter>
7419template <
class Emitter>
7429 LabelTy EndLabel = this->getLabel();
7431 LabelTy ContinueLabel = this->getLabel();
7436 this->emitLabel(ContinueLabel);
7439 this->emitLabel(EndLabel);
7444template <
class Emitter>
7445bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7452 assert(ClosureClass->
captures().empty());
7456 "A generic lambda's static-invoker function must be a "
7457 "template specialization");
7461 llvm::FoldingSetInsertToken InsertToken;
7462 const FunctionDecl *CorrespondingCallOpSpecialization =
7464 assert(CorrespondingCallOpSpecialization);
7465 LambdaCallOp = CorrespondingCallOpSpecialization;
7469 assert(ClosureClass->
captures().empty());
7470 const Function *
Func = this->getFunction(LambdaCallOp);
7473 assert(
Func->hasThisPointer());
7476 if (
Func->hasRVO()) {
7477 if (!this->emitRVOPtr(MD))
7485 if (!this->emitNullPtr(0,
nullptr, MD))
7490 auto It = this->Params.find(PVD);
7491 assert(It != this->Params.end());
7495 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7496 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7500 if (!this->emitCall(
Func, 0, LambdaCallOp))
7505 return this->emitRet(*ReturnType, MD);
7508 return this->emitRetVoid(MD);
7511template <
class Emitter>
7512bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7513 if (Ctx.getLangOpts().CPlusPlus23)
7523 const Expr *InitExpr =
Init->getInit();
7525 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7529 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7539template <
class Emitter>
7541 assert(!ReturnType);
7544 if (!this->emitStartThisLifetime1(Ctor))
7547 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7548 const Expr *InitExpr,
7551 if (InitExpr->getType().isNull())
7555 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7558 if (!this->visit(InitExpr))
7561 if (F->isBitField())
7562 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7564 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7569 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7572 if (
Activate && !this->emitActivate(InitExpr))
7575 return this->visitInitializerPop(InitExpr);
7579 const Record *
R = this->getRecord(RD);
7582 bool IsUnion =
R->isUnion();
7592 if (!this->emitThis(Ctor))
7595 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7598 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7599 this->emitRetVoid(Ctor);
7602 unsigned FieldInits = 0;
7605 if (
R->getNumVirtualBases() > 0) {
7606 if (!this->emitThis(Ctor))
7608 LabelTy AfterVirtBasesLabel = this->getLabel();
7611 if (!this->emitIsBaseClass({}))
7613 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7616 for (
const auto *
Init : Ctor->
inits()) {
7619 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7621 assert(
R->findVirtualBase(BaseDecl));
7622 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7624 if (!this->visitInitializerPop(
Init->getInit()))
7629 this->fallthrough(AfterVirtBasesLabel);
7630 this->emitLabel(AfterVirtBasesLabel);
7632 if (!this->emitPopPtr(Ctor))
7636 for (
const auto *
Init : Ctor->
inits()) {
7640 const Expr *InitExpr =
Init->getInit();
7642 const Record::Field *F =
R->getField(
Member);
7646 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7650 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7653 if (
Init->isBaseVirtual()) {
7659 const Record::Base *B =
R->getBase(BaseDecl);
7661 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7665 if (!this->visitInitializerPop(InitExpr))
7670 unsigned ChainSize = IFD->getChainingSize();
7671 assert(ChainSize >= 2);
7673 unsigned NestedFieldOffset = 0;
7674 const Record::Field *NestedField =
nullptr;
7675 for (
unsigned I = 0; I != ChainSize; ++I) {
7677 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7678 assert(FieldRecord);
7680 NestedField = FieldRecord->
getField(FD);
7681 assert(NestedField);
7682 IsUnion = IsUnion || FieldRecord->
isUnion();
7684 NestedFieldOffset += NestedField->Offset;
7687 if (I != ChainSize - 1)
7690 assert(NestedField);
7693 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7698 unsigned InitFieldOffset = 0;
7699 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7701 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7702 assert(FieldRecord);
7703 NestedField = FieldRecord->
getField(FD);
7704 InitFieldOffset += NestedField->Offset;
7705 assert(NestedField);
7706 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7708 if (!this->emitFinishInitPop(InitExpr))
7712 InitStack.pop_back_n(ChainSize - 1);
7715 assert(
Init->isDelegatingInitializer());
7716 if (!this->emitThis(InitExpr))
7718 if (!this->visitInitializerPop(
Init->getInit()))
7722 if (!
Scope.destroyLocals())
7726 if (FieldInits !=
R->getNumFields()) {
7727 assert(FieldInits < R->getNumFields());
7729 if (!this->emitStartThisLifetime(Ctor))
7736 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7737 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7744 if (!visitStmt(Body))
7751template <
class Emitter>
7754 const Record *
R = this->getRecord(RD);
7758 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7759 if (!this->visitStmt(
Dtor->getBody()))
7763 if (!this->emitThis(
Dtor))
7766 if (!this->emitCheckDestruction(
Dtor))
7770 if (!
R->isUnion()) {
7774 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7778 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7780 if (!this->emitDestructionPop(D,
SourceInfo{}))
7785 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7786 if (
Base.R->hasTrivialDtor())
7790 if (!this->emitRecordDestructionPop(
Base.R, {}))
7794 if (
R->getNumVirtualBases() > 0) {
7795 LabelTy EndLabel = this->getLabel();
7797 if (!this->emitIsBaseClass({}))
7799 if (!this->jumpTrue(EndLabel, {}))
7802 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7803 if (
Base.R->hasTrivialDtor())
7808 if (!this->emitRecordDestructionPop(
Base.R, {}))
7812 this->fallthrough(EndLabel);
7813 this->emitLabel(EndLabel);
7816 if (!this->emitMarkDestroyed(
Dtor))
7819 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7822template <
class Emitter>
7823bool Compiler<Emitter>::compileUnionAssignmentOperator(
7825 if (!this->emitThis(MD))
7828 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7831 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7834template <
class Emitter>
7844 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7845 return this->compileConstructor(Ctor);
7846 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7847 return this->compileDestructor(
Dtor);
7850 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7855 return this->compileUnionAssignmentOperator(MD);
7858 return this->emitLambdaStaticInvokerBody(MD);
7862 if (
const auto *Body = F->
getBody())
7876 return FD->getBitWidthValue();
7879template <
class Emitter>
7895 if (!
Ctx.getLangOpts().CPlusPlus14)
7896 return this->emitInvalid(E);
7898 return this->emitError(E);
7900 if (!this->
visit(SubExpr))
7904 if (!this->emitIncPtr(E))
7911 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7912 : this->emitIncf(getFPOptions(E), E);
7924 if (!
Ctx.getLangOpts().CPlusPlus14)
7925 return this->emitInvalid(E);
7927 return this->emitError(E);
7929 if (!this->
visit(SubExpr))
7933 if (!this->emitDecPtr(E))
7940 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7941 : this->emitDecf(getFPOptions(E), E);
7954 if (!
Ctx.getLangOpts().CPlusPlus14)
7955 return this->emitInvalid(E);
7957 return this->emitError(E);
7959 if (!this->
visit(SubExpr))
7963 if (!this->emitLoadPtr(E))
7965 if (!this->emitConstUint8(1, E))
7967 if (!this->emitAddOffsetUint8(E))
7969 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7975 return this->emitIncfPop(getFPOptions(E), E);
7985 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7986 if (!this->emitLoadFloat(E))
7988 APFloat F(TargetSemantics, 1);
7989 if (!this->emitFloat(F, E))
7992 if (!this->emitAddf(getFPOptions(E), E))
7994 if (!this->emitStoreFloat(E))
8006 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8009 if (!
Ctx.getLangOpts().CPlusPlus14)
8010 return this->emitInvalid(E);
8012 return this->emitError(E);
8014 if (!this->
visit(SubExpr))
8018 if (!this->emitLoadPtr(E))
8020 if (!this->emitConstUint8(1, E))
8022 if (!this->emitSubOffsetUint8(E))
8024 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8030 return this->emitDecfPop(getFPOptions(E), E);
8040 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8041 if (!this->emitLoadFloat(E))
8043 APFloat F(TargetSemantics, 1);
8044 if (!this->emitFloat(F, E))
8047 if (!this->emitSubf(getFPOptions(E), E))
8049 if (!this->emitStoreFloat(E))
8061 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8065 return this->emitError(E);
8068 return this->
discard(SubExpr);
8073 if (!this->emitInv(E))
8077 return this->emitCast(
PT_Bool, ET, E);
8081 return this->emitError(E);
8083 if (!this->
visit(SubExpr))
8088 return this->emitError(E);
8090 if (!this->
visit(SubExpr))
8106 if (!
Ctx.getLangOpts().CPlusPlus) {
8109 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8110 Deref && Deref->getOpcode() == UO_Deref) {
8112 return this->
discard(Deref->getSubExpr());
8113 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8118 return this->
discard(SubExpr);
8119 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8122 return this->
discard(SubExpr);
8124 if (!this->
visit(SubExpr))
8131 return this->emitNarrowPtr(E);
8136 return this->emitError(E);
8138 if (!this->
visit(SubExpr))
8152 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
8157 assert(
false &&
"Unhandled opcode");
8163template <
class Emitter>
8169 return this->
discard(SubExpr);
8172 auto prepareResult = [=]() ->
bool {
8177 return this->emitGetPtrLocal(*LocalIndex, E);
8184 unsigned SubExprOffset = ~0u;
8185 auto createTemp = [=, &SubExprOffset]() ->
bool {
8188 if (!this->
visit(SubExpr))
8190 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8194 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8195 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8197 return this->emitArrayElemPop(ElemT, Index, E);
8202 if (!prepareResult())
8206 for (
unsigned I = 0; I != 2; ++I) {
8207 if (!getElem(SubExprOffset, I))
8209 if (!this->emitNeg(ElemT, E))
8211 if (!this->emitInitElem(ElemT, I, E))
8222 if (!this->
visit(SubExpr))
8224 if (!this->emitComplexBoolCast(SubExpr))
8226 if (!this->emitInv(E))
8229 return this->emitCast(
PT_Bool, ET, E);
8233 return this->emitComplexReal(SubExpr);
8236 if (!this->
visit(SubExpr))
8240 if (!this->emitConstUint8(1, E))
8242 return this->emitArrayElemPtrPopUint8(E);
8253 if (!this->emitArrayElem(ElemT, 1, E))
8255 if (!this->emitNeg(ElemT, E))
8257 if (!this->emitInitElem(ElemT, 1, E))
8265 return this->emitInvalid(E);
8271template <
class Emitter>
8277 return this->
discard(SubExpr);
8280 if (UnaryOp == UO_Extension)
8283 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8284 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8285 return this->emitInvalid(E);
8288 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8295 if (!this->emitGetPtrLocal(*LocalIndex, E))
8300 unsigned SubExprOffset =
8302 if (!this->
visit(SubExpr))
8304 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8309 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8310 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8312 return this->emitArrayElemPop(ElemT, Index, E);
8317 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8318 if (!getElem(SubExprOffset, I))
8320 if (!this->emitNeg(ElemT, E))
8322 if (!this->emitInitElem(ElemT, I, E))
8337 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8338 if (!getElem(SubExprOffset, I))
8341 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8343 if (!this->emitInv(E))
8345 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8347 if (!this->emitNeg(ElemT, E))
8349 if (ElemT != ResultVecElemT &&
8350 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8352 if (!this->emitInitElem(ResultVecElemT, I, E))
8358 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8359 if (!getElem(SubExprOffset, I))
8362 if (!this->emitInv(E))
8365 if (!this->emitComp(ElemT, E))
8368 if (!this->emitInitElem(ElemT, I, E))
8373 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8378template <
class Emitter>
8380 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8383 return this->emitConst(ECD->getInitVal(), E);
8385 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8389 return F && this->emitGetFnPtr(F, E);
8391 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8392 TPOD = TPOD->getFirstDecl();
8396 return this->emitGetPtrGlobal(*GlobalIndex, E);
8402 return this->emitInitGlobal(*
T, *Index, E);
8405 if (!this->emitGetPtrGlobal(*Index, E))
8409 return this->emitFinishInit(E);
8421 auto maybePopPtr = [&]() ->
bool {
8423 return this->emitPopPtr(E);
8430 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8434 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8439 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8440 if (IsReference || !It->second.IsPtr)
8441 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8443 return this->emitGetPtrParam(It->second.Index, E);
8446 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8453 const unsigned Offset = It->second.Offset;
8456 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8458 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8461 if (
auto GlobalIndex =
P.getGlobal(D)) {
8463 if (!
Ctx.getLangOpts().CPlusPlus11)
8464 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8465 if (!
Ctx.getLangOpts().CPlusPlus23)
8466 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8468 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8471 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8475 auto revisit = [&](
const VarDecl *VD,
8476 bool IsConstexprUnknown =
true) ->
bool {
8478 IsConstexprUnknown);
8479 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8485 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8486 if (!this->emitPopCC(E))
8490 if (VarState.notCreated())
8498 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8500 if (
auto It = this->LambdaCaptures.find(D);
8501 It != this->LambdaCaptures.end()) {
8502 auto [Offset, IsPtr] = It->second;
8505 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8506 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8510 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8511 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8512 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8516 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8517 return this->
delegate(BD->getBinding());
8523 return this->emitDummyPtr(D, E);
8528 const auto *VD = dyn_cast<VarDecl>(D);
8530 return this->emitError(E);
8533 if (!
Ctx.getLangOpts().CPlusPlus) {
8537 return revisit(VD,
false);
8541 return this->emitDummyPtr(D, E);
8545 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8546 if (
T.isConstant(
Ctx.getASTContext()))
8548 return T->isReferenceType();
8552 typeShouldBeVisited(DeclType)) {
8554 Init && !
Init->isValueDependent()) {
8559 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8572 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8577 return revisit(VD, IsConstexprUnknown);
8578 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8579 return revisit(VD,
true);
8588 return this->emitDummyPtr(
8592template <
class Emitter>
8598template <
class Emitter>
8608 if (!
C->destroyLocals())
8614template <
class Emitter>
8615unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8618 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8620 return Ty->getAsCXXRecordDecl();
8622 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8623 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8625 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8629template <
class Emitter>
8636 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8641 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8642 getFPOptions(E), E);
8644 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8645 getFPOptions(E), E);
8649 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8654 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8656 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8660 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8664 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8665 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8672template <
class Emitter>
8675 assert(FromT != ToT);
8678 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8680 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8682 return this->emitCast(FromT, ToT, E);
8686template <
class Emitter>
8687bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8691 return this->
discard(SubExpr);
8693 if (!this->visit(SubExpr))
8696 if (!this->emitConstUint8(0, SubExpr))
8698 return this->emitArrayElemPtrPopUint8(SubExpr);
8702 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8706template <
class Emitter>
8707bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8708 assert(!DiscardResult);
8712 if (!this->emitArrayElem(ElemT, 0, E))
8715 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8718 if (!this->emitCast(ElemT,
PT_Bool, E))
8723 LabelTy LabelTrue = this->getLabel();
8724 if (!this->jumpTrue(LabelTrue, E))
8727 if (!this->emitArrayElemPop(ElemT, 1, E))
8730 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8733 if (!this->emitCast(ElemT,
PT_Bool, E))
8737 LabelTy EndLabel = this->getLabel();
8738 this->jump(EndLabel, E);
8740 this->emitLabel(LabelTrue);
8741 if (!this->emitPopPtr(E))
8743 if (!this->emitConstBool(
true, E))
8746 this->fallthrough(EndLabel);
8747 this->emitLabel(EndLabel);
8752template <
class Emitter>
8753bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8764 LHSIsComplex =
true;
8765 ElemT = classifyComplexElementType(LHS->
getType());
8766 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8767 if (!this->visit(LHS))
8769 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8772 LHSIsComplex =
false;
8774 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8775 if (!this->visit(LHS))
8777 if (!this->emitSetLocal(LHST, LHSOffset, E))
8784 RHSIsComplex =
true;
8785 ElemT = classifyComplexElementType(RHS->
getType());
8786 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8787 if (!this->visit(RHS))
8789 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8792 RHSIsComplex =
false;
8794 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8795 if (!this->visit(RHS))
8797 if (!this->emitSetLocal(RHST, RHSOffset, E))
8801 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8802 bool IsComplex) ->
bool {
8804 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8806 return this->emitArrayElemPop(ElemT, Index, E);
8808 return this->emitGetLocal(ElemT, LocalOffset, E);
8811 for (
unsigned I = 0; I != 2; ++I) {
8813 if (!getElem(LHSOffset, I, LHSIsComplex))
8815 if (!getElem(RHSOffset, I, RHSIsComplex))
8818 if (!this->emitEQ(ElemT, E))
8821 if (!this->emitCastBoolUint8(E))
8826 if (!this->emitAddUint8(E))
8828 if (!this->emitConstUint8(2, E))
8832 if (!this->emitEQUint8(E))
8835 if (!this->emitNEUint8(E))
8842 return this->emitCast(
PT_Bool, ResT, E);
8849template <
class Emitter>
8850bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8853 assert(!
R->hasTrivialDtor());
8856 const Function *DtorFunc = getFunction(
Dtor);
8859 assert(DtorFunc->hasThisPointer());
8860 assert(DtorFunc->getNumParams() == 1);
8861 return this->emitCall(DtorFunc, 0, Loc);
8866template <
class Emitter>
8867bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8879 return this->emitPopPtr(Loc);
8881 for (ssize_t I = N - 1; I >= 1; --I) {
8882 if (!this->emitConstUint64(I, Loc))
8884 if (!this->emitArrayElemPtrUint64(Loc))
8886 if (!this->emitDestructionPop(ElemDesc, Loc))
8890 if (!this->emitConstUint64(0, Loc))
8892 if (!this->emitArrayElemPtrPopUint64(Loc))
8894 return this->emitDestructionPop(ElemDesc, Loc);
8899 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8904template <
class Emitter>
8905bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8906 assert(!DiscardResult &&
"Should've been checked before");
8907 return this->emitGetOpaquePtr(D, CU, E);
8910template <
class Emitter>
8913 return this->emitConstFloat(
Floating(F), Info);
8915 APInt I = F.bitcastToAPInt();
8916 return this->emitConstFloat(
8917 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8918 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8929template <
class Emitter>
8930bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8943 if (!this->emitGetPtrLocal(*LocalIndex, E))
8953 if (!this->visit(SubExpr))
8955 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8956 unsigned TempOffset =
8957 allocateLocalPrimitive(SubExpr, *FromT,
true);
8958 if (!this->visit(SubExpr))
8960 if (!this->emitSetLocal(*FromT, TempOffset, E))
8962 if (!this->emitGetPtrLocal(TempOffset, E))
8969 if (!this->emitBitCast(E))
8971 return DiscardResult ? this->emitPopPtr(E) :
true;
8975 const llvm::fltSemantics *TargetSemantics =
nullptr;
8977 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8983 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8985 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8986 ResultBitWidth, TargetSemantics,
8991 return this->emitPop(*ToT, E);
9000template <
class Emitter>
9001bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
9006 unsigned NumElems = 0;
9009 NumElems = VT->getNumElements();
9010 ElemType = VT->getElementType();
9012 NumElems = MT->getNumElementsFlattened();
9013 ElemType = MT->getElementType();
9016 PrimType ElemT = classifyPrim(ElemType);
9017 for (
unsigned I = 0; I != NumElems; ++I) {
9018 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9020 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
9022 if (!this->emitInitElem(ElemT, I, E))
9032 QualType ArrElemType = CAT->getElementType();
9033 unsigned ArrSize = CAT->getZExtSize();
9036 for (
unsigned I = 0; I != ArrSize; ++I) {
9037 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9039 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9041 if (!this->emitInitElem(*ElemT, I, E))
9045 for (
unsigned I = 0; I != ArrSize; ++I) {
9046 if (!this->emitConstUint32(I, E))
9048 if (!this->emitArrayElemPtrUint32(E))
9050 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9052 if (!this->emitFinishInitPop(E))
9062 const Record *
R = getRecord(DestType);
9066 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9068 const Record::Base *B =
R->getBase(BS.getType());
9070 if (!this->emitGetPtrBase(B->Offset, E))
9072 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9074 if (!this->emitFinishInitPop(E))
9079 for (
const Record::Field &F :
R->fields()) {
9080 if (F.isUnnamedBitField())
9083 QualType FieldType = F.Decl->getType();
9085 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9087 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9089 if (F.isBitField()) {
9090 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9093 if (!this->emitInitField(*FieldT, F.Offset, E))
9097 if (!this->emitGetPtrField(F.Offset, E))
9099 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9101 if (!this->emitPopPtr(E))
9114template <
class Emitter>
9115unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9118 return VT->getNumElements();
9120 return MT->getNumElementsFlattened();
9124 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9128 const Record *
R = getRecord(Ty);
9132 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9134 Count += countHLSLFlatElements(BS.getType());
9136 for (
const Record::Field &F :
R->fields()) {
9137 if (F.isUnnamedBitField())
9139 Count += countHLSLFlatElements(F.Decl->getType());
9144 if (canClassify(Ty))
9153template <
class Emitter>
9154bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9155 QualType SrcType,
unsigned SrcOffset,
9160 auto saveToLocal = [&](
PrimType T) ->
bool {
9161 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9162 if (!this->emitSetLocal(
T, Offset, E))
9164 Elements.push_back({Offset,
T});
9170 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9171 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9172 return std::nullopt;
9177 unsigned NumElems = 0;
9180 NumElems = VT->getNumElements();
9181 ElemType = VT->getElementType();
9183 NumElems = MT->getNumElementsFlattened();
9184 ElemType = MT->getElementType();
9187 PrimType ElemT = classifyPrim(ElemType);
9188 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9189 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9191 if (!this->emitArrayElemPop(ElemT, I, E))
9193 if (!saveToLocal(ElemT))
9203 QualType ArrElemType = CAT->getElementType();
9204 unsigned ArrSize = CAT->getZExtSize();
9207 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9208 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9210 if (!this->emitArrayElemPop(*ElemT, I, E))
9212 if (!saveToLocal(*ElemT))
9216 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9217 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9219 if (!this->emitConstUint32(I, E))
9221 if (!this->emitArrayElemPtrPopUint32(E))
9226 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9237 const Record *
R = getRecord(SrcType);
9241 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9243 if (Elements.size() >= MaxElements)
9245 const Record::Base *B =
R->getBase(BS.getType());
9247 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9249 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9254 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9260 for (
const Record::Field &F :
R->fields()) {
9261 if (Elements.size() >= MaxElements)
9263 if (F.isUnnamedBitField())
9266 QualType FieldType = F.Decl->getType();
9267 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9269 if (!this->emitGetPtrFieldPop(F.Offset, E))
9273 if (!this->emitLoadPop(*FieldT, E))
9275 if (!saveToLocal(*FieldT))
9279 if (!FieldPtrOffset)
9281 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9297template <
class Emitter>
9298bool Compiler<Emitter>::emitHLSLConstructAggregate(
9304 const auto &Src = Elements[ElemIdx++];
9305 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9307 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9311 unsigned NumElems = 0;
9314 NumElems = VT->getNumElements();
9315 ElemType = VT->getElementType();
9317 NumElems = MT->getNumElementsFlattened();
9318 ElemType = MT->getElementType();
9321 PrimType DestElemT = classifyPrim(ElemType);
9322 for (
unsigned I = 0; I != NumElems; ++I) {
9323 if (!loadAndCast(DestElemT, ElemType))
9325 if (!this->emitInitElem(DestElemT, I, E))
9335 QualType ArrElemType = CAT->getElementType();
9336 unsigned ArrSize = CAT->getZExtSize();
9339 for (
unsigned I = 0; I != ArrSize; ++I) {
9340 if (!loadAndCast(*ElemT, ArrElemType))
9342 if (!this->emitInitElem(*ElemT, I, E))
9346 for (
unsigned I = 0; I != ArrSize; ++I) {
9347 if (!this->emitConstUint32(I, E))
9349 if (!this->emitArrayElemPtrUint32(E))
9351 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9353 if (!this->emitFinishInitPop(E))
9363 const Record *
R = getRecord(DestType);
9367 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9369 const Record::Base *B =
R->getBase(BS.getType());
9371 if (!this->emitGetPtrBase(B->Offset, E))
9373 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9375 if (!this->emitFinishInitPop(E))
9380 for (
const Record::Field &F :
R->fields()) {
9381 if (F.isUnnamedBitField())
9384 QualType FieldType = F.Decl->getType();
9386 if (!loadAndCast(*FieldT, FieldType))
9388 if (F.isBitField()) {
9389 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9392 if (!this->emitInitField(*FieldT, F.Offset, E))
9396 if (!this->emitGetPtrField(F.Offset, E))
9398 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9400 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.
unsigned ConvertBuiltinIDToX86BuiltinID(const ASTContext &Ctx, unsigned BuiltinOp)
Convert a builtin ID to the canonical x86 builtin ID the constant evaluators dispatch on in their x86...
Result
Implement __builtin_bit_cast and related operations.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
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
This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits One()
Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
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
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()