19#include "llvm/Support/SaveAndRestore.h"
30 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
31 CE && CE->hasAPValueResult() &&
33 return CE->getResultAsAPSInt().getBoolValue();
44 OldInitializingDecl(
Ctx->InitializingDecl) {
45 Ctx->InitializingDecl = VD;
50 this->
Ctx->InitializingDecl = OldInitializingDecl;
51 this->
Ctx->InitStack.pop_back();
64 bool NewInitializing,
bool NewToLValue)
65 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
66 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
67 Ctx->DiscardResult = NewDiscardResult;
68 Ctx->Initializing = NewInitializing;
69 Ctx->ToLValue = NewToLValue;
73 Ctx->DiscardResult = OldDiscardResult;
74 Ctx->Initializing = OldInitializing;
75 Ctx->ToLValue = OldToLValue;
82 bool OldDiscardResult;
87template <
class Emitter>
91 return Ctx->emitThis(E);
94 return Ctx->emitGetPtrFieldPop(
Offset, E);
96 return Ctx->emitGetPtrLocal(
Offset, E);
100 if (!Ctx->emitConstUint32(
Offset, E))
102 return Ctx->emitArrayElemPtrPopUint32(E);
104 return Ctx->emitRVOPtr(E);
108 llvm_unreachable(
"Unhandled InitLink kind");
124 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
125 assert(LI.Name != Name);
128 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
149 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
151 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
152 assert(LI.Name != Name);
155 this->Ctx->CaseLabels = std::move(CaseLabels);
156 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
158 DefaultLabel, Ctx->VarScope);
162 this->Ctx->CaseLabels = std::move(OldCaseLabels);
163 this->Ctx->LabelInfoStack.pop_back();
168 CaseMap OldCaseLabels;
174 Ctx->InStmtExpr =
true;
192 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
195 Ctx->LocOverride = NewValue;
200 Ctx->LocOverride = OldFlag;
205 std::optional<SourceInfo> OldFlag;
212template <
class Emitter>
220 case CK_LValueToRValue: {
231 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
237 if (
auto GlobalIndex =
P.getGlobal(D))
238 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
239 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
240 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
241 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
242 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
243 return this->emitGetParam(*SubExprT, It->second.Index, E);
255 if (!this->emitGetPtrLocal(*LocalIndex, E))
259 if (!this->
visit(SubExpr))
263 return this->emitLoadPop(*SubExprT, E);
268 return this->emitMemcpy(E);
271 case CK_DerivedToBaseMemberPointer: {
282 ->getMostRecentCXXRecordDecl();
284 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
285 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
287 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
295 case CK_BaseToDerivedMemberPointer: {
306 ->getMostRecentCXXRecordDecl();
310 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
312 PathI != PathE; ++PathI) {
313 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
314 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
316 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
323 assert(ToDecl != CurDecl);
324 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
326 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
332 case CK_UncheckedDerivedToBase:
333 case CK_DerivedToBase: {
338 if (
const auto *PT = dyn_cast<PointerType>(Ty))
339 return PT->getPointeeType()->getAsCXXRecordDecl();
340 return Ty->getAsCXXRecordDecl();
347 if (B->isVirtual()) {
348 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
350 CurType = B->getType();
352 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
353 if (!this->emitGetPtrBasePop(
356 CurType = B->getType();
363 case CK_BaseToDerived: {
366 unsigned DerivedOffset =
372 return this->emitGetPtrDerivedPop(DerivedOffset,
377 case CK_FloatingCast: {
382 if (!this->
visit(SubExpr))
384 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
388 case CK_IntegralToFloating: {
391 if (!this->
visit(SubExpr))
393 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
394 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
395 TargetSemantics, getFPOptions(E), E);
398 case CK_FloatingToBoolean: {
402 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
403 return this->emitConstBool(FL->getValue().isNonZero(), E);
404 if (!this->
visit(SubExpr))
406 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
409 case CK_FloatingToIntegral: {
412 if (!this->
visit(SubExpr))
416 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
419 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
422 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
425 case CK_NullToPointer:
426 case CK_NullToMemberPointer: {
431 if (!PointeeType.
isNull()) {
433 Desc =
P.createDescriptor(SubExpr, *T);
435 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
439 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
443 case CK_PointerToIntegral: {
444 if (!this->
visit(SubExpr))
450 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
456 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
458 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
459 return this->emitCastPointerIntegral(T, E);
462 case CK_ArrayToPointerDecay: {
463 if (!this->
visit(SubExpr))
465 return this->emitArrayDecay(E);
468 case CK_IntegralToPointer: {
470 assert(IntType->isIntegralOrEnumerationType());
471 if (!this->
visit(SubExpr))
479 Desc =
P.createDescriptor(SubExpr, *T);
486 if (!this->emitGetIntPtr(T, Desc, E))
494 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
497 case CK_AtomicToNonAtomic:
498 case CK_ConstructorConversion:
499 case CK_FunctionToPointerDecay:
500 case CK_NonAtomicToAtomic:
502 case CK_UserDefinedConversion:
503 case CK_AddressSpaceConversion:
504 case CK_CPointerToObjCPointerCast:
521 return this->emitBuiltinBitCast(E);
536 if (!this->
visit(SubExpr))
544 return this->emitFnPtrCast(E);
551 if (!this->
visit(SubExpr))
553 return this->emitDecayPtr(*FromT, *ToT, E);
555 case CK_IntegralToBoolean:
556 case CK_FixedPointToBoolean: {
562 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
563 return this->emitConst(IL->getValue(), E);
564 if (!this->
visit(SubExpr))
569 case CK_BooleanToSignedIntegral:
570 case CK_IntegralCast: {
577 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
582 if (!this->emitConst(IL->getValue(), SubExpr))
585 if (!this->
visit(SubExpr))
593 if (!ED->isFixed()) {
594 if (!this->emitCheckEnumValue(*FromT, ED, E))
600 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
603 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
608 if (!this->emitCast(*FromT, *ToT, E))
611 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
612 return this->emitNeg(*ToT, E);
616 case CK_PointerToBoolean:
617 case CK_MemberPointerToBoolean: {
620 if (!this->
visit(SubExpr))
622 return this->emitIsNonNull(PtrT, E);
625 case CK_IntegralComplexToBoolean:
626 case CK_FloatingComplexToBoolean: {
627 if (!this->
visit(SubExpr))
629 return this->emitComplexBoolCast(SubExpr);
632 case CK_IntegralComplexToReal:
633 case CK_FloatingComplexToReal:
634 return this->emitComplexReal(SubExpr);
636 case CK_IntegralRealToComplex:
637 case CK_FloatingRealToComplex: {
644 if (!this->emitGetPtrLocal(*LocalIndex, E))
653 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
655 return this->emitInitElem(T, 1, SubExpr);
658 case CK_IntegralComplexCast:
659 case CK_FloatingComplexCast:
660 case CK_IntegralComplexToFloatingComplex:
661 case CK_FloatingComplexToIntegralComplex: {
668 if (!this->emitGetPtrLocal(*LocalIndex, E))
675 unsigned SubExprOffset =
677 if (!this->
visit(SubExpr))
679 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
687 for (
unsigned I = 0; I != 2; ++I) {
688 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
690 if (!this->emitArrayElemPop(SourceElemT, I, E))
694 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
698 if (!this->emitInitElem(DestElemT, I, E))
704 case CK_VectorSplat: {
713 if (!this->emitGetPtrLocal(*LocalIndex, E))
719 unsigned ElemOffset =
723 if (!this->
visit(SubExpr))
728 if (!this->emitSetLocal(ElemT, ElemOffset, E))
731 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
732 if (!this->emitGetLocal(ElemT, ElemOffset, E))
734 if (!this->emitInitElem(ElemT, I, E))
741 case CK_HLSLVectorTruncation: {
746 if (!this->
visit(SubExpr))
748 return this->emitArrayElemPop(*ResultT, 0, E);
757 if (!this->emitGetPtrLocal(*LocalIndex, E))
762 if (!this->
visit(SubExpr))
764 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
768 case CK_IntegralToFixedPoint: {
769 if (!this->
visit(SubExpr))
773 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
777 case CK_FloatingToFixedPoint: {
778 if (!this->
visit(SubExpr))
782 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
783 return this->emitCastFloatingFixedPoint(Sem, E);
785 case CK_FixedPointToFloating: {
786 if (!this->
visit(SubExpr))
788 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
789 return this->emitCastFixedPointFloating(TargetSemantics, E);
791 case CK_FixedPointToIntegral: {
792 if (!this->
visit(SubExpr))
796 case CK_FixedPointCast: {
797 if (!this->
visit(SubExpr))
800 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
801 return this->emitCastFixedPoint(Sem, E);
812 case CK_LValueBitCast:
815 case CK_HLSLArrayRValue: {
822 if (!this->emitGetPtrLocal(*LocalIndex, E))
825 if (!this->
visit(SubExpr))
827 return this->emitMemcpy(E);
830 case CK_HLSLMatrixTruncation: {
835 if (!this->
visit(SubExpr))
837 return this->emitArrayElemPop(*ResultT, 0, E);
846 if (!this->emitGetPtrLocal(*LocalIndex, E))
851 if (!this->
visit(SubExpr))
853 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
857 case CK_HLSLAggregateSplatCast: {
868 NumElems = VT->getNumElements();
869 DestElemType = VT->getElementType();
871 NumElems = MT->getNumElementsFlattened();
872 DestElemType = MT->getElementType();
882 if (!this->emitGetPtrLocal(*LocalIndex, E))
890 if (!this->
visit(SubExpr))
892 if (SrcElemT != DestElemT) {
893 if (!this->emitPrimCast(SrcElemT, DestElemT, DestElemType, E))
896 if (!this->emitSetLocal(DestElemT, SrcOffset, E))
899 for (
unsigned I = 0; I != NumElems; ++I) {
900 if (!this->emitGetLocal(DestElemT, SrcOffset, E))
902 if (!this->emitInitElem(DestElemT, I, E))
908 case CK_HLSLElementwiseCast: {
921 const auto *SrcCAT = SrcAT ? dyn_cast<ConstantArrayType>(SrcAT) :
nullptr;
927 const auto *DestCAT =
928 DestAT ? dyn_cast<ConstantArrayType>(DestAT) :
nullptr;
931 if (!SrcVT && !SrcMT && !SrcCAT)
933 if (!DestVT && !DestMT && !DestCAT && !DestPT)
936 unsigned SrcNumElems;
939 SrcNumElems = SrcVT->getNumElements();
942 SrcNumElems = SrcMT->getNumElementsFlattened();
945 SrcNumElems = SrcCAT->getZExtSize();
951 if (!this->
visit(SubExpr))
953 if (!this->emitArrayElemPop(SrcElemT, 0, E))
955 if (SrcElemT != *DestPT) {
956 if (!this->emitPrimCast(SrcElemT, *DestPT, DestType, E))
962 unsigned DestNumElems;
966 DestNumElems = DestVT->getNumElements();
967 DestElemType = DestVT->getElementType();
969 DestNumElems = DestMT->getNumElementsFlattened();
971 }
else if (DestCAT) {
972 DestNumElems = DestCAT->getZExtSize();
973 DestElemType = DestCAT->getElementType();
981 if (!this->emitGetPtrLocal(*LocalIndex, E))
987 if (!this->
visit(SubExpr))
989 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
992 unsigned NumElems = std::min(SrcNumElems, DestNumElems);
993 for (
unsigned I = 0; I != NumElems; ++I) {
994 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
996 if (!this->emitArrayElemPop(SrcElemT, I, E))
998 if (SrcElemT != DestElemT) {
999 if (!this->emitPrimCast(SrcElemT, DestElemT, DestElemType, E))
1002 if (!this->emitInitElem(DestElemT, I, E))
1009 return this->emitInvalid(E);
1011 llvm_unreachable(
"Unhandled clang::CastKind enum");
1014template <
class Emitter>
1016 return this->emitBuiltinBitCast(E);
1019template <
class Emitter>
1024 return this->emitConst(
LE->getValue(),
LE);
1027template <
class Emitter>
1033 return this->emitFloat(F, E);
1036template <
class Emitter>
1046 if (!this->emitGetPtrLocal(*LocalIndex, E))
1053 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1055 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1060template <
class Emitter>
1068 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1073template <
class Emitter>
1078template <
class Emitter>
1105 return this->emitComplexComparison(LHS, RHS, E);
1113 if (!this->
visit(LHS))
1116 if (!this->
visit(RHS))
1119 if (!this->emitToMemberPtr(E))
1125 if (!this->emitCastMemberPtrPtr(E))
1142 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1148 if (!this->emitGetPtrLocal(*ResultIndex, E))
1155 return this->emitCMP3(*
LT, CmpInfo, E);
1158 if (!
LT || !RT || !T)
1168 return this->visitAssignment(LHS, RHS, E);
1175 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1179 return this->emitPopBool(E);
1181 return this->emitCast(
PT_Bool, *T, E);
1185 auto Discard = [
this, T, E](
bool Result) {
1193 return MaybeCastToBool(this->emitEQ(*
LT, E));
1195 return MaybeCastToBool(this->emitNE(*
LT, E));
1197 return MaybeCastToBool(this->emitLT(*
LT, E));
1199 return MaybeCastToBool(this->emitLE(*
LT, E));
1201 return MaybeCastToBool(this->emitGT(*
LT, E));
1203 return MaybeCastToBool(this->emitGE(*
LT, E));
1206 return Discard(this->emitSubf(getFPOptions(E), E));
1207 return Discard(this->emitSub(*T, E));
1210 return Discard(this->emitAddf(getFPOptions(E), E));
1211 return Discard(this->emitAdd(*T, E));
1214 return Discard(this->emitMulf(getFPOptions(E), E));
1215 return Discard(this->emitMul(*T, E));
1217 return Discard(this->emitRem(*T, E));
1220 return Discard(this->emitDivf(getFPOptions(E), E));
1221 return Discard(this->emitDiv(*T, E));
1223 return Discard(this->emitBitAnd(*T, E));
1225 return Discard(this->emitBitOr(*T, E));
1227 return Discard(this->emitShl(*
LT, *RT, E));
1229 return Discard(this->emitShr(*
LT, *RT, E));
1231 return Discard(this->emitBitXor(*T, E));
1234 llvm_unreachable(
"Already handled earlier");
1239 llvm_unreachable(
"Unhandled binary op");
1244template <
class Emitter>
1250 if ((Op != BO_Add && Op != BO_Sub) ||
1261 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1262 if (!this->
visit(E))
1265 return this->emitDecayPtr(T,
PT_Ptr, E);
1274 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1282 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1285 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1292 if (!visitAsPointer(RHS, *RT))
1294 if (!this->
visit(LHS))
1298 if (!visitAsPointer(LHS, *
LT))
1300 if (!this->
visit(RHS))
1311 if (!this->emitAddOffset(OffsetType, E))
1315 if (!this->emitSubOffset(OffsetType, E))
1332template <
class Emitter>
1342 LabelTy LabelTrue = this->getLabel();
1343 LabelTy LabelEnd = this->getLabel();
1347 if (!this->jumpTrue(LabelTrue, E))
1352 if (!this->jump(LabelEnd, E))
1355 this->emitLabel(LabelTrue);
1356 this->emitConstBool(
true, E);
1357 this->fallthrough(LabelEnd);
1358 this->emitLabel(LabelEnd);
1361 assert(Op == BO_LAnd);
1364 LabelTy LabelFalse = this->getLabel();
1365 LabelTy LabelEnd = this->getLabel();
1369 if (!this->jumpFalse(LabelFalse, E))
1374 if (!this->jump(LabelEnd, E))
1377 this->emitLabel(LabelFalse);
1378 this->emitConstBool(
false, E);
1379 this->fallthrough(LabelEnd);
1380 this->emitLabel(LabelEnd);
1384 return this->emitPopBool(E);
1389 return this->emitCast(
PT_Bool, *T, E);
1393template <
class Emitter>
1400 if (!this->emitGetPtrLocal(*LocalIndex, E))
1409 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1410 unsigned ResultOffset = ~0u;
1416 if (!this->emitDupPtr(E))
1418 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1423 LHSType = AT->getValueType();
1426 RHSType = AT->getValueType();
1435 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1440 if (!this->
visit(LHS))
1442 if (!this->
visit(RHS))
1444 if (!this->emitMulc(ElemT, E))
1447 return this->emitPopPtr(E);
1451 if (Op == BO_Div && RHSIsComplex) {
1458 if (!LHSIsComplex) {
1463 LHSOffset = *LocalIndex;
1465 if (!this->emitGetPtrLocal(LHSOffset, E))
1468 if (!this->
visit(LHS))
1471 if (!this->emitInitElem(ElemT, 0, E))
1474 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1476 if (!this->emitInitElem(ElemT, 1, E))
1479 if (!this->
visit(LHS))
1483 if (!this->
visit(RHS))
1485 if (!this->emitDivc(ElemT, E))
1488 return this->emitPopPtr(E);
1495 if (!this->
visit(LHS))
1497 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1502 if (!this->
visit(LHS))
1504 if (!this->emitSetLocal(LHST, LHSOffset, E))
1512 if (!this->
visit(RHS))
1514 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1519 if (!this->
visit(RHS))
1521 if (!this->emitSetLocal(RHST, RHSOffset, E))
1528 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1529 unsigned ElemIndex,
unsigned Offset,
1530 const Expr *E) ->
bool {
1532 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1534 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1537 if (ElemIndex == 0 || !LoadZero)
1544 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1547 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1554 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1557 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1560 if (!this->emitAddf(getFPOptions(E), E))
1563 if (!this->emitAdd(ResultElemT, E))
1568 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1571 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1574 if (!this->emitSubf(getFPOptions(E), E))
1577 if (!this->emitSub(ResultElemT, E))
1582 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1585 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1589 if (!this->emitMulf(getFPOptions(E), E))
1592 if (!this->emitMul(ResultElemT, E))
1597 assert(!RHSIsComplex);
1598 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1601 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1605 if (!this->emitDivf(getFPOptions(E), E))
1608 if (!this->emitDiv(ResultElemT, E))
1619 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1622 if (!this->emitPop(ResultElemT, E))
1627 return this->emitPopPtr(E);
1633template <
class Emitter>
1638 "Comma op should be handled in VisitBinaryOperator");
1652 if (!this->emitGetPtrLocal(*LocalIndex, E))
1666 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1669 if (!this->
visit(LHS))
1671 if (!this->
visit(RHS))
1673 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1676 return this->emitPopPtr(E);
1681 unsigned LHSOffset =
1683 if (!this->
visit(LHS))
1685 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1689 unsigned RHSOffset =
1691 if (!this->
visit(RHS))
1693 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1705 if (NeedIntPromot) {
1707 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1712 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1713 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1715 if (!this->emitArrayElemPop(ElemT, Index, E))
1718 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1720 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1722 }
else if (NeedIntPromot) {
1723 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1729#define EMIT_ARITH_OP(OP) \
1731 if (ElemT == PT_Float) { \
1732 if (!this->emit##OP##f(getFPOptions(E), E)) \
1735 if (!this->emit##OP(ElemT, E)) \
1741 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1742 if (!getElem(LHSOffset, ElemT, I))
1744 if (!getElem(RHSOffset, RHSElemT, I))
1756 if (!this->emitRem(ElemT, E))
1760 if (!this->emitBitAnd(OpT, E))
1764 if (!this->emitBitOr(OpT, E))
1768 if (!this->emitBitXor(OpT, E))
1772 if (!this->emitShl(OpT, RHSElemT, E))
1776 if (!this->emitShr(OpT, RHSElemT, E))
1780 if (!this->emitEQ(ElemT, E))
1784 if (!this->emitNE(ElemT, E))
1788 if (!this->emitLE(ElemT, E))
1792 if (!this->emitLT(ElemT, E))
1796 if (!this->emitGE(ElemT, E))
1800 if (!this->emitGT(ElemT, E))
1805 if (!this->emitBitAnd(ResultElemT, E))
1810 if (!this->emitBitOr(ResultElemT, E))
1814 return this->emitInvalid(E);
1823 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1825 if (!this->emitNeg(ResultElemT, E))
1831 if (NeedIntPromot &&
1832 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1836 if (!this->emitInitElem(ResultElemT, I, E))
1845template <
class Emitter>
1855 auto LHSSemaInt = LHSSema.toOpaqueInt();
1857 auto RHSSemaInt = RHSSema.toOpaqueInt();
1859 if (!this->
visit(LHS))
1867 if (!this->
visit(RHS))
1876 auto ConvertResult = [&](
bool R) ->
bool {
1880 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1881 if (ResultSema != CommonSema)
1882 return this->emitCastFixedPoint(ResultSema, E);
1886 auto MaybeCastToBool = [&](
bool Result) {
1891 return this->emitPop(T, E);
1893 return this->emitCast(
PT_Bool, T, E);
1899 return MaybeCastToBool(this->emitEQFixedPoint(E));
1901 return MaybeCastToBool(this->emitNEFixedPoint(E));
1903 return MaybeCastToBool(this->emitLTFixedPoint(E));
1905 return MaybeCastToBool(this->emitLEFixedPoint(E));
1907 return MaybeCastToBool(this->emitGTFixedPoint(E));
1909 return MaybeCastToBool(this->emitGEFixedPoint(E));
1911 return ConvertResult(this->emitAddFixedPoint(E));
1913 return ConvertResult(this->emitSubFixedPoint(E));
1915 return ConvertResult(this->emitMulFixedPoint(E));
1917 return ConvertResult(this->emitDivFixedPoint(E));
1919 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1921 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1924 return this->emitInvalid(E);
1927 llvm_unreachable(
"unhandled binop opcode");
1930template <
class Emitter>
1939 if (!this->
visit(SubExpr))
1941 return this->emitNegFixedPoint(E);
1946 llvm_unreachable(
"Unhandled unary opcode");
1949template <
class Emitter>
1958 return this->visitZeroInitializer(*T, QT, E);
1966 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1967 CXXRD && CXXRD->getNumVBases() > 0) {
1977 return this->visitZeroRecordInitializer(R, E);
1984 return this->visitZeroArrayInitializer(QT, E);
1988 QualType ElemQT = ComplexTy->getElementType();
1990 for (
unsigned I = 0; I < 2; ++I) {
1991 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1993 if (!this->emitInitElem(ElemT, I, E))
2000 unsigned NumVecElements = VecT->getNumElements();
2001 QualType ElemQT = VecT->getElementType();
2004 for (
unsigned I = 0; I < NumVecElements; ++I) {
2005 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2007 if (!this->emitInitElem(ElemT, I, E))
2014 unsigned NumElems = MT->getNumElementsFlattened();
2015 QualType ElemQT = MT->getElementType();
2018 for (
unsigned I = 0; I != NumElems; ++I) {
2019 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2021 if (!this->emitInitElem(ElemT, I, E))
2030template <
class Emitter>
2043 for (
const Expr *SubExpr : {LHS, RHS}) {
2044 if (!this->
visit(SubExpr)) {
2051 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2052 if (!this->emitExpandPtr(E))
2063 return this->emitError(E);
2066 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2070 if (!this->emitArrayElemPtrPop(*IndexT, E))
2073 return this->emitPopPtr(E);
2079 return this->emitLoadPop(*T, E);
2082template <
class Emitter>
2084 const Expr *ArrayFiller,
const Expr *E) {
2089 QT = AT->getValueType();
2092 if (
Inits.size() == 0)
2094 return this->emitInvalid(E);
2109 if (
Inits.size() == 0)
2110 return this->visitZeroInitializer(*T, QT, E);
2111 assert(
Inits.size() == 1);
2124 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2131 bool BitField = FieldToInit->isBitField();
2133 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2134 FieldToInit->bitWidth(), E);
2136 return this->emitInitBitField(T, FieldToInit->Offset,
2137 FieldToInit->bitWidth(), E);
2139 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2140 return this->emitInitField(T, FieldToInit->Offset, E);
2143 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2151 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2154 if (
Activate && !this->emitActivate(E))
2159 return this->emitPopPtr(E);
2163 if (
Inits.size() == 0) {
2164 if (!this->visitZeroRecordInitializer(R, E))
2169 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2170 FToInit = ILE->getInitializedFieldInUnion();
2174 const Record::Field *FieldToInit = R->getField(FToInit);
2176 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2179 if (!initCompositeField(FieldToInit,
Init,
true))
2183 return this->emitFinishInit(E);
2186 assert(!R->isUnion());
2187 unsigned InitIndex = 0;
2190 while (InitIndex < R->getNumFields() &&
2191 R->getField(InitIndex)->isUnnamedBitField())
2195 const Record::Field *FieldToInit = R->getField(InitIndex);
2196 if (!initPrimitiveField(FieldToInit,
Init, *T))
2201 if (
const Record::Base *B = R->getBase(
Init->getType())) {
2202 if (!this->emitGetPtrBase(B->Offset,
Init))
2208 if (!this->emitFinishInitPop(E))
2213 const Record::Field *FieldToInit = R->getField(InitIndex);
2214 if (!initCompositeField(FieldToInit,
Init))
2220 return this->emitFinishInit(E);
2224 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2228 Ctx.getASTContext().getAsConstantArrayType(QT);
2231 if (!this->emitCheckArraySize(NumElems, E))
2235 unsigned ElementIndex = 0;
2237 if (
const auto *EmbedS =
2238 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2246 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2247 getFPOptions(E), E))
2253 return this->emitInitElem(TargetT, ElemIndex, IL);
2255 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2267 for (; ElementIndex != NumElems; ++ElementIndex) {
2273 return this->emitFinishInit(E);
2277 unsigned NumInits =
Inits.size();
2282 QualType ElemQT = ComplexTy->getElementType();
2284 if (NumInits == 0) {
2286 for (
unsigned I = 0; I < 2; ++I) {
2287 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2289 if (!this->emitInitElem(ElemT, I, E))
2292 }
else if (NumInits == 2) {
2293 unsigned InitIndex = 0;
2298 if (!this->emitInitElem(ElemT, InitIndex, E))
2307 unsigned NumVecElements = VecT->getNumElements();
2308 assert(NumVecElements >=
Inits.size());
2310 QualType ElemQT = VecT->getElementType();
2314 unsigned InitIndex = 0;
2321 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2322 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2323 InitVecT->getNumElements(), E))
2325 InitIndex += InitVecT->getNumElements();
2327 if (!this->emitInitElem(ElemT, InitIndex, E))
2333 assert(InitIndex <= NumVecElements);
2336 for (; InitIndex != NumVecElements; ++InitIndex) {
2337 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2339 if (!this->emitInitElem(ElemT, InitIndex, E))
2346 unsigned NumElems = MT->getNumElementsFlattened();
2347 assert(
Inits.size() == NumElems);
2349 QualType ElemQT = MT->getElementType();
2355 for (
unsigned I = 0; I != NumElems; ++I) {
2358 if (!this->emitInitElem(ElemT, I, E))
2369template <
class Emitter>
2376 return this->emitInitElem(*InitT, ElemIndex,
Init);
2382 if (!this->emitConstUint32(ElemIndex,
Init))
2384 if (!this->emitArrayElemPtrUint32(
Init))
2388 return this->emitFinishInitPop(
Init);
2391template <
class Emitter>
2394 bool Activate,
bool IsOperatorCall) {
2396 llvm::BitVector NonNullArgs;
2397 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2400 bool ExplicitMemberFn =
false;
2401 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2402 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2404 unsigned ArgIndex = 0;
2405 for (
const Expr *Arg : Args) {
2407 if (!this->
visit(Arg))
2415 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2416 if (DeclIndex < FuncDecl->getNumParams())
2417 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2426 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2434 if (!this->emitActivate(Arg))
2438 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2441 if (!this->emitCheckNonNullArg(ArgT, Arg))
2452template <
class Emitter>
2457template <
class Emitter>
2463template <
class Emitter>
2469template <
class Emitter>
2485template <
class Emitter>
2487 auto It = E->
begin();
2488 return this->
visit(*It);
2493 bool AlignOfReturnsPreferred =
2494 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2500 T = Ref->getPointeeType();
2502 if (T.getQualifiers().hasUnaligned())
2508 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2514template <
class Emitter>
2521 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2527 ArgType = Ref->getPointeeType();
2533 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2534 return this->emitInvalid(E);
2536 if (Kind == UETT_SizeOf)
2545 return this->emitConst(Size.getQuantity(), E);
2548 if (Kind == UETT_CountOf) {
2554 if (
const auto *CAT =
2558 return this->emitConst(CAT->getSize(), E);
2568 if (VAT->getElementType()->isArrayType()) {
2569 std::optional<APSInt> Res =
2571 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2576 return this->emitConst(*Res, E);
2581 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2601 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2604 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2614 return this->emitConst(Size.getQuantity(), E);
2617 if (Kind == UETT_VectorElements) {
2622 return this->emitConst(VT->getNumElements(), E);
2624 return this->emitSizelessVectorElementSize(E);
2627 if (Kind == UETT_VecStep) {
2629 unsigned N = VT->getNumElements();
2636 return this->emitConst(N, E);
2638 return this->emitConst(1, E);
2641 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2648 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2650 return this->emitInvalid(E);
2652 return this->emitConst(
2653 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2661template <
class Emitter>
2672 const auto maybeLoadValue = [&]() ->
bool {
2676 return this->emitLoadPop(*T, E);
2680 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2684 if (
auto GlobalIndex =
P.getGlobal(VD))
2685 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2690 if (!this->
discard(Base) && !this->emitSideEffect(E))
2705 const Record::Field *F = R->getField(FD);
2707 if (F->Decl->getType()->isReferenceType())
2708 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2709 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2712template <
class Emitter>
2722template <
class Emitter>
2741 for (
size_t I = 0; I != Size; ++I) {
2753template <
class Emitter>
2768 return this->emitGetLocal(SubExprT, It->second, E);
2771 if (!this->
visit(SourceExpr))
2778 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2787 return this->emitGetLocal(SubExprT, LocalIndex, E);
2791template <
class Emitter>
2814 bool IsBcpCall =
false;
2815 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2816 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2820 LabelTy LabelEnd = this->getLabel();
2821 LabelTy LabelFalse = this->getLabel();
2824 if (!this->emitPushIgnoreDiags(E))
2832 if (this->checkingForUndefinedBehavior()) {
2835 if (!this->
discard(FalseExpr))
2841 if (!this->jumpFalse(LabelFalse, E))
2846 if (!this->jump(LabelEnd, E))
2848 this->emitLabel(LabelFalse);
2852 this->fallthrough(LabelEnd);
2853 this->emitLabel(LabelEnd);
2856 return this->emitPopIgnoreDiags(E);
2860template <
class Emitter>
2866 unsigned StringIndex =
P.createGlobalString(E);
2867 return this->emitGetPtrGlobal(StringIndex, E);
2872 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2873 assert(CAT &&
"a string literal that's not a constant array?");
2878 unsigned N = std::min(ArraySize, E->
getLength());
2881 for (
unsigned I = 0; I != N; ++I) {
2884 if (CharWidth == 1) {
2885 this->emitConstSint8(CodeUnit, E);
2886 this->emitInitElemSint8(I, E);
2887 }
else if (CharWidth == 2) {
2888 this->emitConstUint16(CodeUnit, E);
2889 this->emitInitElemUint16(I, E);
2890 }
else if (CharWidth == 4) {
2891 this->emitConstUint32(CodeUnit, E);
2892 this->emitInitElemUint32(I, E);
2894 llvm_unreachable(
"unsupported character width");
2899 for (
unsigned I = N; I != ArraySize; ++I) {
2900 if (CharWidth == 1) {
2901 this->emitConstSint8(0, E);
2902 this->emitInitElemSint8(I, E);
2903 }
else if (CharWidth == 2) {
2904 this->emitConstUint16(0, E);
2905 this->emitInitElemUint16(I, E);
2906 }
else if (CharWidth == 4) {
2907 this->emitConstUint32(0, E);
2908 this->emitInitElemUint32(I, E);
2910 llvm_unreachable(
"unsupported character width");
2917template <
class Emitter>
2921 return this->emitDummyPtr(E, E);
2924template <
class Emitter>
2926 auto &A =
Ctx.getASTContext();
2935template <
class Emitter>
2943 auto &A =
Ctx.getASTContext();
2947 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2948 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2955 unsigned StringIndex =
P.createGlobalString(SL);
2956 return this->emitGetPtrGlobal(StringIndex, E);
2959template <
class Emitter>
2963 return this->emitConst(E->
getValue(), E);
2966template <
class Emitter>
2992 if (!this->emitSetLocal(*RT, TempOffset, E))
2998 if (!this->emitLoad(LHST, E))
3002 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3003 LHSComputationType, E))
3007 if (!this->emitGetLocal(*RT, TempOffset, E))
3012 if (!this->emitAddf(getFPOptions(E), E))
3016 if (!this->emitSubf(getFPOptions(E), E))
3020 if (!this->emitMulf(getFPOptions(E), E))
3024 if (!this->emitDivf(getFPOptions(E), E))
3035 return this->emitStorePop(LHST, E);
3036 return this->emitStore(LHST, E);
3039template <
class Emitter>
3048 if (Op != BO_AddAssign && Op != BO_SubAssign)
3057 if (!this->emitLoad(*
LT, LHS))
3063 if (Op == BO_AddAssign) {
3064 if (!this->emitAddOffset(*RT, E))
3067 if (!this->emitSubOffset(*RT, E))
3072 return this->emitStorePopPtr(E);
3073 return this->emitStorePtr(E);
3076template <
class Emitter>
3089 if (!
Ctx.getLangOpts().CPlusPlus14)
3090 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3092 if (!
LT || !RT || !ResultT || !LHSComputationT)
3117 if (!this->emitSetLocal(*RT, TempOffset, E))
3124 if (!this->emitLoad(*
LT, E))
3126 if (
LT != LHSComputationT &&
3132 if (!this->emitGetLocal(*RT, TempOffset, E))
3138 if (!this->emitAdd(*LHSComputationT, E))
3142 if (!this->emitSub(*LHSComputationT, E))
3146 if (!this->emitMul(*LHSComputationT, E))
3150 if (!this->emitDiv(*LHSComputationT, E))
3154 if (!this->emitRem(*LHSComputationT, E))
3158 if (!this->emitShl(*LHSComputationT, *RT, E))
3162 if (!this->emitShr(*LHSComputationT, *RT, E))
3166 if (!this->emitBitAnd(*LHSComputationT, E))
3170 if (!this->emitBitXor(*LHSComputationT, E))
3174 if (!this->emitBitOr(*LHSComputationT, E))
3178 llvm_unreachable(
"Unimplemented compound assign operator");
3182 if (ResultT != LHSComputationT &&
3183 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3189 return this->emitStoreBitFieldPop(*ResultT, E);
3190 return this->emitStorePop(*ResultT, E);
3193 return this->emitStoreBitField(*ResultT, E);
3194 return this->emitStore(*ResultT, E);
3197template <
class Emitter>
3205template <
class Emitter>
3220 if (!
Ctx.getLangOpts().CPlusPlus11)
3227 for (
const Expr *LHS : CommaLHSs) {
3247 if (!this->
visit(Inner))
3249 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3251 return this->emitGetPtrGlobal(*GlobalIndex, E);
3254 if (!this->checkLiteralType(Inner))
3257 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3261 return this->emitInitGlobalTempComp(TempDecl, E);
3272 unsigned LocalIndex =
3274 if (!this->VarScope->LocalsAlwaysEnabled &&
3275 !this->emitEnableLocal(LocalIndex, E))
3278 if (!this->
visit(Inner))
3280 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3283 return this->emitGetPtrLocal(LocalIndex, E);
3286 if (!this->checkLiteralType(Inner))
3293 if (!this->VarScope->LocalsAlwaysEnabled &&
3294 !this->emitEnableLocal(*LocalIndex, E))
3297 if (!this->emitGetPtrLocal(*LocalIndex, E))
3304template <
class Emitter>
3315 if (!this->
visit(SubExpr))
3319 return this->emitPopPtr(E);
3323template <
class Emitter>
3344 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3349 if (
P.isGlobalInitialized(*GlobalIndex))
3355 return this->emitInitGlobal(*T, *GlobalIndex, E);
3367 unsigned LocalIndex;
3371 LocalIndex = *MaybeIndex;
3375 if (!this->emitGetPtrLocal(LocalIndex, E))
3379 return this->
visit(
Init) && this->emitInit(*T, E);
3383template <
class Emitter>
3396template <
class Emitter>
3400 return this->emitConst(E->
getValue(), E);
3403template <
class Emitter>
3416 for (
const Record::Field &F : R->fields()) {
3418 if (!
Init ||
Init->containsErrors())
3426 if (!this->emitInitField(*T, F.Offset, E))
3429 if (!this->emitGetPtrField(F.Offset, E))
3435 if (!this->emitPopPtr(E))
3443template <
class Emitter>
3450 return this->emitGetPtrGlobal(StringIndex, E);
3456template <
class Emitter>
3461 return this->emitInvalid(E);
3464template <
class Emitter>
3490 if (PointeeToT && PointeeFromT) {
3509 bool Fatal = (ToT != FromT);
3516template <
class Emitter>
3519 if (!
Ctx.getLangOpts().CPlusPlus20) {
3527template <
class Emitter>
3533 return this->emitConstBool(E->
getValue(), E);
3536template <
class Emitter>
3541 if (T->isRecordType()) {
3555 if (!this->emitGetPtrLocal(*LocalIndex, E))
3563 T->getAsCXXRecordDecl()))
3573 if (!this->visitZeroRecordInitializer(R, E))
3585 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3587 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3588 if (!this->emitCheckFunctionDecl(Ctor, E))
3599 assert(
Func->hasThisPointer());
3600 assert(!
Func->hasRVO());
3604 if (!this->emitDupPtr(E))
3608 for (
const auto *Arg : E->
arguments()) {
3609 if (!this->
visit(Arg))
3613 if (
Func->isVariadic()) {
3614 uint32_t VarArgSize = 0;
3615 unsigned NumParams =
Func->getNumWrittenParams();
3616 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3620 if (!this->emitCallVar(
Func, VarArgSize, E))
3623 if (!this->emitCall(
Func, 0, E)) {
3628 (void)this->emitPopPtr(E);
3634 return this->emitPopPtr(E);
3635 return this->emitFinishInit(E);
3638 if (T->isArrayType()) {
3643 if (!this->emitDupPtr(E))
3647 initArrayDimension = [&](
QualType T) ->
bool {
3648 if (!T->isArrayType()) {
3650 for (
const auto *Arg : E->
arguments()) {
3651 if (!this->
visit(Arg))
3655 return this->emitCall(
Func, 0, E);
3659 Ctx.getASTContext().getAsConstantArrayType(T);
3664 for (
size_t I = 0; I != NumElems; ++I) {
3665 if (!this->emitConstUint64(I, E))
3667 if (!this->emitArrayElemPtrUint64(E))
3669 if (!initArrayDimension(ElemTy))
3672 return this->emitPopPtr(E);
3675 return initArrayDimension(E->
getType());
3681template <
class Emitter>
3691 assert(Val.
isInt());
3693 return this->emitConst(I, E);
3700 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3701 return this->
visit(LValueExpr);
3716 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3720 const APValue &
V = UGCD->getValue();
3721 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3722 const Record::Field *F = R->getField(I);
3723 const APValue &FieldValue =
V.getStructField(I);
3729 if (!this->emitInitField(FieldT, F->Offset, E))
3737template <
class Emitter>
3743 for (
unsigned I = 0; I != N; ++I) {
3750 if (!this->
discard(ArrayIndexExpr))
3755 if (!this->
visit(ArrayIndexExpr))
3759 if (!this->emitCast(IndexT,
PT_Sint64, E))
3769 return this->emitOffsetOf(T, E, E);
3772template <
class Emitter>
3781 return this->visitZeroInitializer(*T, Ty, E);
3788 if (!this->emitGetPtrLocal(*LocalIndex, E))
3793 QualType ElemQT = CT->getElementType();
3796 for (
unsigned I = 0; I != 2; ++I) {
3797 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3799 if (!this->emitInitElem(ElemT, I, E))
3811 if (!this->emitGetPtrLocal(*LocalIndex, E))
3816 QualType ElemQT = VT->getElementType();
3819 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3820 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3822 if (!this->emitInitElem(ElemT, I, E))
3831template <
class Emitter>
3836template <
class Emitter>
3842template <
class Emitter>
3847template <
class Emitter>
3852 return this->emitConst(E->
getValue(), E);
3855template <
class Emitter>
3860 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3874 unsigned ParamIndex = 0;
3878 if (!this->emitGetParam(PT, ParamIndex, E))
3883 return this->emitCall(F, 0, E);
3888template <
class Emitter>
3896 const Expr *PlacementDest =
nullptr;
3897 bool IsNoThrow =
false;
3902 if (PlacementArgs != 0) {
3911 if (PlacementArgs == 1) {
3919 if (!this->emitInvalidNewDeleteExpr(E, E))
3924 if (OperatorNew->isReservedGlobalPlacementOperator())
3925 PlacementDest = Arg1;
3929 return this->emitInvalid(E);
3931 }
else if (!OperatorNew
3932 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3933 return this->emitInvalidNewDeleteExpr(E, E);
3936 if (!PlacementDest) {
3941 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3944 Desc =
P.createDescriptor(
3947 false,
false,
false,
3953 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3957 const Expr *Stripped = *ArraySizeExpr;
3958 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3959 Stripped = ICE->getSubExpr())
3960 if (ICE->getCastKind() != CK_NoOp &&
3961 ICE->getCastKind() != CK_IntegralCast)
3969 if (!this->
visit(Stripped))
3971 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3974 if (PlacementDest) {
3975 if (!this->
visit(PlacementDest))
3977 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3979 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3982 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3987 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3991 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3998 size_t StaticInitElems = 0;
3999 const Expr *DynamicInit =
nullptr;
4003 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4004 StaticInitElems = CAT->getZExtSize();
4009 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4010 if (ILE->hasArrayFiller())
4011 DynamicInit = ILE->getArrayFiller();
4030 const Function *CtorFunc =
nullptr;
4031 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4035 }
else if (!DynamicInit && !ElemT)
4038 LabelTy EndLabel = this->getLabel();
4039 LabelTy StartLabel = this->getLabel();
4044 if (!this->emitDupPtr(E))
4046 if (!this->emitNullPtr(0,
nullptr, E))
4048 if (!this->emitEQPtr(E))
4050 if (!this->jumpTrue(EndLabel, E))
4057 if (!this->emitConst(StaticInitElems,
SizeT, E))
4059 if (!this->emitSetLocal(
SizeT, Iter, E))
4062 this->fallthrough(StartLabel);
4063 this->emitLabel(StartLabel);
4065 if (!this->emitGetLocal(
SizeT, Iter, E))
4067 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4069 if (!this->emitLT(
SizeT, E))
4071 if (!this->jumpFalse(EndLabel, E))
4075 if (!this->emitGetLocal(
SizeT, Iter, E))
4077 if (!this->emitArrayElemPtr(
SizeT, E))
4080 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4085 if (!this->visitZeroInitializer(InitT, ElemType, E))
4087 if (!this->emitStorePop(InitT, E))
4089 }
else if (DynamicInit) {
4091 if (!this->
visit(DynamicInit))
4093 if (!this->emitStorePop(*InitT, E))
4098 if (!this->emitPopPtr(E))
4102 if (!this->visitZeroInitializer(
4106 if (!this->emitStorePop(*ElemT, E))
4110 if (!this->emitCall(CtorFunc, 0, E))
4115 if (!this->emitGetPtrLocal(Iter, E))
4117 if (!this->emitIncPop(
SizeT,
false, E))
4120 if (!this->jump(StartLabel, E))
4123 this->fallthrough(EndLabel);
4124 this->emitLabel(EndLabel);
4128 if (PlacementDest) {
4129 if (!this->
visit(PlacementDest))
4131 if (!this->emitCheckNewTypeMismatch(E, E))
4136 if (!this->emitAlloc(Desc, E))
4145 if (!this->emitInit(*ElemT, E))
4156 return this->emitPopPtr(E);
4161template <
class Emitter>
4167 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4168 return this->emitInvalidNewDeleteExpr(E, E);
4177template <
class Emitter>
4183 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4188 return this->emitGetFnPtr(
Func, E);
4191template <
class Emitter>
4195 auto canonType = [](
const Type *T) {
4196 return T->getCanonicalTypeUnqualified().getTypePtr();
4204 return this->emitGetTypeid(
4208 return this->emitGetTypeid(
4217 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4223 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4226 return this->emitPopPtr(E);
4230template <
class Emitter>
4234 return this->emitDummyPtr(E, E);
4235 return this->emitError(E);
4238template <
class Emitter>
4241 return this->emitDummyPtr(E, E);
4242 return this->emitError(E);
4245template <
class Emitter>
4247 assert(
Ctx.getLangOpts().CPlusPlus);
4248 return this->emitConstBool(E->
getValue(), E);
4251template <
class Emitter>
4263 return this->emitDummyPtr(GuidDecl, E);
4268 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4277 assert(
V.isStruct());
4278 assert(
V.getStructNumBases() == 0);
4282 return this->emitFinishInit(E);
4285template <
class Emitter>
4295template <
class Emitter>
4304template <
class Emitter>
4310template <
class Emitter>
4314 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4318 if (OVE->isUnique())
4334template <
class Emitter>
4339template <
class Emitter>
4341 return this->emitError(E);
4344template <
class Emitter>
4350 return this->emitDummyPtr(E, E);
4353template <
class Emitter>
4357 QualType ElemType = VT->getElementType();
4361 PrimType SrcElemT = classifyVectorElementType(SrcType);
4363 unsigned SrcOffset =
4365 if (!this->
visit(Src))
4367 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4370 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4371 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4373 if (!this->emitArrayElemPop(SrcElemT, I, E))
4377 if (SrcElemT != ElemT) {
4378 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4380 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4381 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4385 if (!this->emitInitElem(ElemT, I, E))
4392template <
class Emitter>
4396 return this->emitInvalid(E);
4405 assert(NumOutputElems > 0);
4411 if (!this->emitGetPtrLocal(*LocalIndex, E))
4416 unsigned VectorOffsets[2];
4417 for (
unsigned I = 0; I != 2; ++I) {
4420 if (!this->
visit(Vecs[I]))
4422 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4425 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4427 assert(ShuffleIndex >= -1);
4428 if (ShuffleIndex == -1)
4429 return this->emitInvalidShuffleVectorIndex(I, E);
4431 assert(ShuffleIndex < (NumInputElems * 2));
4432 if (!this->emitGetLocal(
PT_Ptr,
4433 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4435 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4436 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4439 if (!this->emitInitElem(ElemT, I, E))
4444 return this->emitPopPtr(E);
4449template <
class Emitter>
4454 Base->getType()->isVectorType() ||
4460 if (Indices.size() == 1) {
4465 if (!this->emitConstUint32(Indices[0], E))
4467 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4477 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4485 if (!this->emitGetPtrLocal(*ResultIndex, E))
4493 uint32_t DstIndex = 0;
4494 for (uint32_t I : Indices) {
4495 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4497 if (!this->emitArrayElemPop(ElemT, I, E))
4499 if (!this->emitInitElem(ElemT, DstIndex, E))
4509template <
class Emitter>
4513 return this->
discard(SubExpr) && this->emitInvalid(E);
4519 return this->emitDummyPtr(E, E);
4522template <
class Emitter>
4527 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4532 if (!this->
visit(SubExpr))
4534 if (!this->emitConstUint8(0, E))
4536 if (!this->emitArrayElemPtrPopUint8(E))
4538 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4543 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4545 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4547 assert(SecondFieldT ==
PT_Ptr);
4549 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4551 if (!this->emitExpandPtr(E))
4555 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4557 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4560template <
class Emitter>
4575 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4577 return this->emitUnsupported(E);
4586 return this->
Visit(E);
4593 return this->
Visit(E);
4597 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4600 if (
const auto *CE = dyn_cast<CastExpr>(E);
4602 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4609 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4612 if (
const auto *CE = dyn_cast<CastExpr>(E);
4613 CE && (CE->getCastKind() == CK_DerivedToBase ||
4614 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4615 CE->getCastKind() == CK_NoOp))
4635 if (!this->emitGetPtrLocal(*LocalIndex, E))
4645 return this->
Visit(E);
4648template <
class Emitter>
4654 return this->
Visit(E);
4660 return this->
Visit(E);
4671 if (!this->
visit(E))
4673 return this->emitComplexBoolCast(E);
4678 if (!this->
visit(E))
4686 return this->emitIsNonNullPtr(E);
4690 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4693 return this->emitCast(*T,
PT_Bool, E);
4696template <
class Emitter>
4700 QT = AT->getValueType();
4704 return this->emitZeroBool(E);
4706 return this->emitZeroSint8(E);
4708 return this->emitZeroUint8(E);
4710 return this->emitZeroSint16(E);
4712 return this->emitZeroUint16(E);
4714 return this->emitZeroSint32(E);
4716 return this->emitZeroUint32(E);
4718 return this->emitZeroSint64(E);
4720 return this->emitZeroUint64(E);
4722 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4724 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4726 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4729 return this->emitNullMemberPtr(0,
nullptr, E);
4731 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4732 return this->emitFloat(F, E);
4735 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4739 llvm_unreachable(
"unknown primitive type");
4742template <
class Emitter>
4743bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4748 for (
const Record::Field &Field :
R->fields()) {
4749 if (Field.isUnnamedBitField())
4756 if (!this->visitZeroInitializer(T, QT, E))
4759 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4763 if (!this->emitInitField(T, Field.Offset, E))
4768 if (!this->emitGetPtrField(Field.Offset, E))
4774 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4775 if (!this->visitZeroInitializer(T, ET, E))
4777 if (!this->emitInitElem(T, I, E))
4782 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4785 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4793 if (!this->emitFinishInitActivatePop(E))
4797 if (!this->emitFinishInitPop(E))
4801 for (
const Record::Base &B :
R->bases()) {
4802 if (!this->emitGetPtrBase(B.Offset, E))
4804 if (!this->visitZeroRecordInitializer(B.R, E))
4806 if (!this->emitFinishInitPop(E))
4815template <
class Emitter>
4816bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4817 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4823 for (
size_t I = 0; I != NumElems; ++I) {
4824 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4826 if (!this->emitInitElem(*ElemT, I, E))
4832 const Record *
R = getRecord(ElemType);
4836 for (
size_t I = 0; I != NumElems; ++I) {
4837 if (!this->emitConstUint32(I, E))
4839 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4841 if (!this->visitZeroRecordInitializer(R, E))
4843 if (!this->emitPopPtr(E))
4849 for (
size_t I = 0; I != NumElems; ++I) {
4850 if (!this->emitConstUint32(I, E))
4852 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4854 if (!this->visitZeroArrayInitializer(ElemType, E))
4856 if (!this->emitPopPtr(E))
4865template <
class Emitter>
4866bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4868 if (!canClassify(E->
getType()))
4871 if (!this->visit(RHS))
4873 if (!this->visit(LHS))
4880 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4884 bool Activates = refersToUnion(LHS);
4887 if (!this->emitFlip(
PT_Ptr, RHT, E))
4890 if (DiscardResult) {
4891 if (BitField && Activates)
4892 return this->emitStoreBitFieldActivatePop(RHT, E);
4894 return this->emitStoreBitFieldPop(RHT, E);
4896 return this->emitStoreActivatePop(RHT, E);
4898 return this->emitStorePop(RHT, E);
4901 auto maybeLoad = [&](
bool Result) ->
bool {
4907 return this->emitLoadPop(RHT, E);
4911 if (BitField && Activates)
4912 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4914 return maybeLoad(this->emitStoreBitField(RHT, E));
4916 return maybeLoad(this->emitStoreActivate(RHT, E));
4918 return maybeLoad(this->emitStore(RHT, E));
4921template <
class Emitter>
4922template <
typename T>
4926 return this->emitConstSint8(
Value, E);
4928 return this->emitConstUint8(
Value, E);
4930 return this->emitConstSint16(
Value, E);
4932 return this->emitConstUint16(
Value, E);
4934 return this->emitConstSint32(
Value, E);
4936 return this->emitConstUint32(
Value, E);
4938 return this->emitConstSint64(
Value, E);
4940 return this->emitConstUint64(
Value, E);
4942 return this->emitConstBool(
Value, E);
4949 llvm_unreachable(
"Invalid integral type");
4952 llvm_unreachable(
"unknown primitive type");
4955template <
class Emitter>
4956template <
typename T>
4957bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
4958 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4961template <
class Emitter>
4965 return this->emitConstIntAPS(
Value, E);
4967 return this->emitConstIntAP(
Value, E);
4969 if (
Value.isSigned())
4970 return this->emitConst(
Value.getSExtValue(), Ty, E);
4971 return this->emitConst(
Value.getZExtValue(), Ty, E);
4974template <
class Emitter>
4978 return this->emitConstIntAPS(
Value, E);
4980 return this->emitConstIntAP(
Value, E);
4983 return this->emitConst(
Value.getSExtValue(), Ty, E);
4984 return this->emitConst(
Value.getZExtValue(), Ty, E);
4987template <
class Emitter>
4988bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4989 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4992template <
class Emitter>
5005 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5006 Locals.insert({VD, Local});
5007 VarScope->addForScopeKind(Local, SC);
5008 return Local.Offset;
5011template <
class Emitter>
5016 bool IsTemporary =
false;
5017 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5020 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5021 Init = VarD->getInit();
5023 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5034 return std::nullopt;
5039 Locals.insert({Key, Local});
5040 VarScope->addForScopeKind(Local, SC);
5041 return Local.Offset;
5044template <
class Emitter>
5054 return std::nullopt;
5064 return Local.Offset;
5067template <
class Emitter>
5069 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5070 return PT->getPointeeType()->getAsCanonical<RecordType>();
5076 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5080template <
class Emitter>
5082 return P.getOrCreateRecord(RD);
5085template <
class Emitter>
5087 return Ctx.getOrCreateFunction(FD);
5090template <
class Emitter>
5094 auto maybeDestroyLocals = [&]() ->
bool {
5095 if (DestroyToplevelScope)
5096 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5097 return this->emitCheckAllocations(E);
5104 return this->emitRetVoid(E) && maybeDestroyLocals();
5112 return this->emitRet(*T, E) && maybeDestroyLocals();
5120 if (!this->emitGetPtrLocal(*LocalOffset, E))
5126 if (!this->emitFinishInit(E))
5131 return this->emitRetValue(E) && maybeDestroyLocals();
5134 return maybeDestroyLocals() &&
false;
5137template <
class Emitter>
5149 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5150 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5164template <
class Emitter>
5166 bool ConstantContext) {
5169 if (!ConstantContext) {
5183 auto GlobalIndex =
P.getGlobal(VD);
5184 assert(GlobalIndex);
5186 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5189 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5193 auto Local =
Locals.find(VD);
5194 assert(Local !=
Locals.end());
5196 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5199 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5209 auto GlobalIndex =
P.getGlobal(VD);
5210 assert(GlobalIndex);
5211 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5220 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5223template <
class Emitter>
5233 if (!this->isActive())
5238 if (
Init &&
Init->isValueDependent())
5242 auto checkDecl = [&]() ->
bool {
5244 return !NeedsOp || this->emitCheckDecl(VD, VD);
5251 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5254 if (
P.isGlobalInitialized(*GlobalIndex))
5258 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
5272 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5275 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5281 return this->emitFinishInitGlobal(
Init);
5291 if (!
Init ||
Init->getType()->isVoidType())
5300 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5304 return this->emitSetLocal(*VarT, Offset, VD);
5312 if (!this->emitGetPtrLocal(*Offset,
Init))
5318 return this->emitFinishInitPop(
Init);
5323template <
class Emitter>
5328 return this->emitConst(Val.
getInt(), ValType, E);
5331 return this->emitFloat(F, E);
5336 return this->emitNull(ValType, 0,
nullptr, E);
5338 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5339 return this->
visit(BaseExpr);
5344 return this->emitGetMemberPtr(MemberDecl, E);
5345 return this->emitNullMemberPtr(0,
nullptr, E);
5351template <
class Emitter>
5359 const Record::Field *RF = R->getField(I);
5360 QualType FieldType = RF->Decl->getType();
5365 if (!this->emitInitField(*PT, RF->Offset, E))
5368 if (!this->emitGetPtrField(RF->Offset, E))
5372 if (!this->emitPopPtr(E))
5385 const Record::Field *RF = R->getField(UnionField);
5386 QualType FieldType = RF->Decl->getType();
5391 if (RF->isBitField())
5392 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5394 return this->emitInitFieldActivate(*PT, RF->Offset, E);
5397 if (!this->emitGetPtrField(RF->Offset, E))
5399 if (!this->emitActivate(E))
5403 return this->emitPopPtr(E);
5406 const auto *ArrType = T->getAsArrayTypeUnsafe();
5407 QualType ElemType = ArrType->getElementType();
5408 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5413 if (!this->emitInitElem(*ElemT, A, E))
5416 if (!this->emitConstUint32(A, E))
5418 if (!this->emitArrayElemPtrUint32(E))
5422 if (!this->emitPopPtr(E))
5433template <
class Emitter>
5435 unsigned BuiltinID) {
5436 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5441 return this->emitConst(0, E);
5444 if (!this->emitStartSpeculation(E))
5446 LabelTy EndLabel = this->getLabel();
5447 if (!this->speculate(E, EndLabel))
5449 if (!this->emitEndSpeculation(E))
5451 this->fallthrough(EndLabel);
5459 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5460 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5461 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5462 BuiltinID == Builtin::BI__builtin_function_start) {
5465 return this->emitDummyPtr(E, E);
5476 if (!this->emitGetPtrLocal(*LocalIndex, E))
5481 switch (BuiltinID) {
5482 case Builtin::BI__builtin_object_size:
5483 case Builtin::BI__builtin_dynamic_object_size: {
5487 if (!this->
visit(Arg0))
5498 case Builtin::BI__assume:
5499 case Builtin::BI__builtin_assume:
5502 case Builtin::BI__atomic_is_lock_free:
5503 case Builtin::BI__atomic_always_lock_free: {
5514 for (
const auto *Arg : E->
arguments()) {
5515 if (!this->
visit(Arg))
5521 if (!this->emitCallBI(E, BuiltinID, E))
5530template <
class Emitter>
5549 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5550 DD && DD->isTrivial()) {
5552 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5554 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5555 this->emitPopPtr(E);
5563 bool HasRVO = !
ReturnType->isVoidType() && !T;
5571 if (!this->emitGetPtrLocal(*LocalIndex, E))
5579 if (!this->emitGetPtrLocal(*LocalIndex, E))
5583 if (!this->emitDupPtr(E))
5590 bool IsAssignmentOperatorCall =
false;
5591 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5592 OCE && OCE->isAssignmentOp()) {
5596 assert(Args.size() == 2);
5597 IsAssignmentOperatorCall =
true;
5598 std::reverse(Args.begin(), Args.end());
5604 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5605 MD && MD->isStatic()) {
5609 Args.erase(Args.begin());
5613 bool Devirtualized =
false;
5616 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5624 if (!this->
visit(Callee))
5626 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5628 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5630 if (!this->emitGetMemberPtrBase(E))
5633 const auto *InstancePtr = MC->getImplicitObjectArgument();
5640 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5641 Devirtualized =
true;
5642 if (!this->
visit(Stripped))
5645 if (!this->
visit(InstancePtr))
5649 if (!this->
visit(InstancePtr))
5653 }
else if (
const auto *PD =
5654 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5655 if (!this->emitCheckPseudoDtor(E))
5663 return this->emitEndLifetimePop(E);
5664 }
else if (!FuncDecl) {
5668 if (!this->
visit(Callee))
5670 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5674 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5679 if (IsAssignmentOperatorCall) {
5680 assert(Args.size() == 2);
5683 if (!this->emitFlip(Arg2T, Arg1T, E))
5697 assert(HasRVO ==
Func->hasRVO());
5699 bool HasQualifier =
false;
5700 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5701 HasQualifier = ME->hasQualifier();
5703 bool IsVirtual =
false;
5704 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5705 IsVirtual = !Devirtualized && MD->isVirtual();
5710 if (IsVirtual && !HasQualifier) {
5711 uint32_t VarArgSize = 0;
5712 unsigned NumParams =
5714 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5717 if (!this->emitCallVirt(
Func, VarArgSize, E))
5719 }
else if (
Func->isVariadic()) {
5720 uint32_t VarArgSize = 0;
5721 unsigned NumParams =
5723 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5725 if (!this->emitCallVar(
Func, VarArgSize, E))
5728 if (!this->emitCall(
Func, 0, E))
5737 uint32_t ArgSize = 0;
5738 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5744 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5746 if (!this->emitGetMemberPtrDecl(E))
5749 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5752 if (!this->emitCallPtr(ArgSize, E, E))
5763template <
class Emitter>
5770template <
class Emitter>
5777template <
class Emitter>
5782 return this->emitConstBool(E->
getValue(), E);
5785template <
class Emitter>
5791 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5792 return this->emitNullPtr(Val,
nullptr, E);
5795template <
class Emitter>
5803 return this->emitZero(T, E);
5806template <
class Emitter>
5811 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
5812 if (this->LambdaThisCapture.Offset > 0) {
5813 if (this->LambdaThisCapture.IsPtr)
5814 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5815 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5824 return this->emitThis(E);
5839 unsigned StartIndex = 0;
5840 unsigned EndIndex = 0;
5842 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5844 EndIndex = StartIndex;
5851 for (; StartIndex > 0; --StartIndex) {
5861 if (StartIndex == 0 && EndIndex == 0)
5864 assert(StartIndex < EndIndex);
5867 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5879 case Stmt::CompoundStmtClass:
5881 case Stmt::DeclStmtClass:
5883 case Stmt::ReturnStmtClass:
5885 case Stmt::IfStmtClass:
5887 case Stmt::WhileStmtClass:
5889 case Stmt::DoStmtClass:
5891 case Stmt::ForStmtClass:
5893 case Stmt::CXXForRangeStmtClass:
5895 case Stmt::BreakStmtClass:
5897 case Stmt::ContinueStmtClass:
5899 case Stmt::SwitchStmtClass:
5901 case Stmt::CaseStmtClass:
5903 case Stmt::DefaultStmtClass:
5905 case Stmt::AttributedStmtClass:
5907 case Stmt::CXXTryStmtClass:
5909 case Stmt::NullStmtClass:
5912 case Stmt::GCCAsmStmtClass:
5913 case Stmt::MSAsmStmtClass:
5914 case Stmt::GotoStmtClass:
5915 return this->emitInvalid(S);
5916 case Stmt::LabelStmtClass:
5919 if (
const auto *E = dyn_cast<Expr>(S))
5926template <
class Emitter>
5929 for (
const auto *InnerStmt : S->
body())
5932 return Scope.destroyLocals();
5935template <
class Emitter>
5936bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5937 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5938 for (
auto *BD : DD->flat_bindings())
5939 if (
auto *KD = BD->getHoldingVar();
5940 KD && !this->visitVarDecl(KD, KD->getInit()))
5954template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5956 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5957 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5964 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5969 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5970 ICE && (ICE->getCastKind() == CK_NoOp ||
5971 ICE->getCastKind() == CK_DerivedToBase ||
5972 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5973 E = ICE->getSubExpr();
5977 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5978 const auto *ThisRecord =
5979 This->getType()->getPointeeType()->getAsRecordDecl();
5980 if (!ThisRecord->isUnion())
5983 if (
const auto *Ctor =
5984 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5985 return Ctor->getParent() == ThisRecord;
5994template <
class Emitter>
5996 bool EvaluateConditionDecl) {
5997 for (
const auto *D : DS->
decls()) {
6002 const auto *VD = dyn_cast<VarDecl>(D);
6009 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6016template <
class Emitter>
6019 return this->emitUnsupported(RS);
6025 if (!this->
visit(RE))
6031 if (RE->getType()->isVoidType()) {
6032 if (!this->
visit(RE))
6035 if (RE->containsErrors())
6040 if (!this->emitRVOPtr(RE))
6044 if (!this->emitPopPtr(RE))
6048 return this->emitRetVoid(RS);
6054 return this->emitRetVoid(RS);
6060 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6067 if (
auto *CondInit = IS->
getInit()) {
6083 return visitChildStmt(IS->
getThen());
6085 return visitChildStmt(Else);
6091 if (!this->emitIsConstantContext(IS))
6094 if (!this->emitIsConstantContext(IS))
6096 if (!this->emitInv(IS))
6110 LabelTy LabelElse = this->getLabel();
6111 LabelTy LabelEnd = this->getLabel();
6112 if (!this->jumpFalse(LabelElse, IS))
6114 if (!visitChildStmt(IS->
getThen()))
6116 if (!this->jump(LabelEnd, IS))
6118 this->emitLabel(LabelElse);
6119 if (!visitChildStmt(Else))
6121 this->emitLabel(LabelEnd);
6123 LabelTy LabelEnd = this->getLabel();
6124 if (!this->jumpFalse(LabelEnd, IS))
6126 if (!visitChildStmt(IS->
getThen()))
6128 this->emitLabel(LabelEnd);
6137template <
class Emitter>
6142 LabelTy CondLabel = this->getLabel();
6143 LabelTy EndLabel = this->getLabel();
6147 this->fallthrough(CondLabel);
6148 this->emitLabel(CondLabel);
6164 if (!this->jumpFalse(EndLabel, S))
6174 if (!this->jump(CondLabel, S))
6176 this->fallthrough(EndLabel);
6177 this->emitLabel(EndLabel);
6186 LabelTy StartLabel = this->getLabel();
6187 LabelTy EndLabel = this->getLabel();
6188 LabelTy CondLabel = this->getLabel();
6192 this->fallthrough(StartLabel);
6193 this->emitLabel(StartLabel);
6199 this->fallthrough(CondLabel);
6200 this->emitLabel(CondLabel);
6207 if (!this->jumpTrue(StartLabel, S))
6210 this->fallthrough(EndLabel);
6211 this->emitLabel(EndLabel);
6215template <
class Emitter>
6223 LabelTy EndLabel = this->getLabel();
6224 LabelTy CondLabel = this->getLabel();
6225 LabelTy IncLabel = this->getLabel();
6232 this->fallthrough(CondLabel);
6233 this->emitLabel(CondLabel);
6245 if (!this->jumpFalse(EndLabel, S))
6254 this->fallthrough(IncLabel);
6255 this->emitLabel(IncLabel);
6261 if (!this->jump(CondLabel, S))
6265 this->emitLabel(EndLabel);
6271template <
class Emitter>
6281 LabelTy EndLabel = this->getLabel();
6282 LabelTy CondLabel = this->getLabel();
6283 LabelTy IncLabel = this->getLabel();
6298 this->fallthrough(CondLabel);
6299 this->emitLabel(CondLabel);
6302 if (!this->jumpFalse(EndLabel, S))
6313 this->fallthrough(IncLabel);
6314 this->emitLabel(IncLabel);
6319 if (!this->jump(CondLabel, S))
6322 this->fallthrough(EndLabel);
6323 this->emitLabel(EndLabel);
6327template <
class Emitter>
6338 if (LI.BreakLabel) {
6339 TargetLabel = *LI.BreakLabel;
6340 BreakScope = LI.BreakOrContinueScope;
6346 if (LI.Name == TargetLoop) {
6347 TargetLabel = *LI.BreakLabel;
6348 BreakScope = LI.BreakOrContinueScope;
6359 C =
C->getParent()) {
6360 if (!
C->destroyLocals())
6364 return this->jump(*TargetLabel, S);
6367template <
class Emitter>
6378 if (LI.ContinueLabel) {
6379 TargetLabel = *LI.ContinueLabel;
6380 ContinueScope = LI.BreakOrContinueScope;
6386 if (LI.Name == TargetLoop) {
6387 TargetLabel = *LI.ContinueLabel;
6388 ContinueScope = LI.BreakOrContinueScope;
6393 assert(TargetLabel);
6396 C =
C->getParent()) {
6397 if (!
C->destroyLocals())
6401 return this->jump(*TargetLabel, S);
6404template <
class Emitter>
6407 if (
Cond->containsErrors())
6413 LabelTy EndLabel = this->getLabel();
6418 if (
const auto *CondInit = S->
getInit())
6429 if (!this->emitSetLocal(CondT, CondVar, S))
6439 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6442 if (CS->caseStmtIsGNURange()) {
6443 LabelTy EndOfRangeCheck = this->getLabel();
6444 const Expr *Low = CS->getLHS();
6445 const Expr *High = CS->getRHS();
6449 if (!this->emitGetLocal(CondT, CondVar, CS))
6451 if (!this->
visit(Low))
6454 if (!this->emitGE(
LT, S))
6456 if (!this->jumpFalse(EndOfRangeCheck, S))
6459 if (!this->emitGetLocal(CondT, CondVar, CS))
6461 if (!this->
visit(High))
6464 if (!this->emitLE(HT, S))
6468 this->emitLabel(EndOfRangeCheck);
6473 if (
Value->isValueDependent())
6478 if (!this->emitGetLocal(CondT, CondVar, CS))
6484 if (!this->emitEQ(ValueT, S))
6489 assert(!DefaultLabel);
6490 DefaultLabel = this->getLabel();
6497 if (!this->jump(*DefaultLabel, S))
6500 if (!this->jump(EndLabel, S))
6508 this->fallthrough(EndLabel);
6509 this->emitLabel(EndLabel);
6514template <
class Emitter>
6521template <
class Emitter>
6528 if (LI.DefaultLabel) {
6529 DefaultLabel = *LI.DefaultLabel;
6534 this->emitLabel(DefaultLabel);
6538template <
class Emitter>
6545 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6548 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6549 !this->Ctx.getLangOpts().MSVCCompat) {
6551 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6557 const Expr *Assumption = AA->getAssumption();
6568 if (!this->emitAssume(Assumption))
6577 if (IsMSVCConstexprAttr)
6578 return this->emitPopMSVCCE(S);
6582template <
class Emitter>
6588template <
class Emitter>
6589bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6596 assert(ClosureClass->
captures().empty());
6600 "A generic lambda's static-invoker function must be a "
6601 "template specialization");
6605 void *InsertPos =
nullptr;
6606 const FunctionDecl *CorrespondingCallOpSpecialization =
6608 assert(CorrespondingCallOpSpecialization);
6609 LambdaCallOp = CorrespondingCallOpSpecialization;
6613 assert(ClosureClass->
captures().empty());
6614 const Function *
Func = this->getFunction(LambdaCallOp);
6617 assert(
Func->hasThisPointer());
6620 if (
Func->hasRVO()) {
6621 if (!this->emitRVOPtr(MD))
6629 if (!this->emitNullPtr(0,
nullptr, MD))
6634 auto It = this->Params.find(PVD);
6635 assert(It != this->Params.end());
6639 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6640 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6644 if (!this->emitCall(
Func, 0, LambdaCallOp))
6649 return this->emitRet(*ReturnType, MD);
6652 return this->emitRetVoid(MD);
6655template <
class Emitter>
6656bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6657 if (Ctx.getLangOpts().CPlusPlus23)
6667 const Expr *InitExpr =
Init->getInit();
6669 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6673 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6683template <
class Emitter>
6685 assert(!ReturnType);
6687 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6688 const Expr *InitExpr,
6691 if (InitExpr->getType().isNull())
6695 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6698 if (!this->visit(InitExpr))
6701 if (F->isBitField())
6702 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
6704 return this->emitInitThisField(*T, FieldOffset, InitExpr);
6709 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6712 if (
Activate && !this->emitActivate(InitExpr))
6715 if (!this->visitInitializer(InitExpr))
6718 return this->emitFinishInitPop(InitExpr);
6722 const Record *
R = this->getRecord(RD);
6725 bool IsUnion =
R->isUnion();
6730 if (
R->getNumFields() == 0)
6731 return this->emitRetVoid(Ctor);
6734 if (!this->emitThis(Ctor))
6737 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
6740 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6741 this->emitRetVoid(Ctor);
6745 for (
const auto *
Init : Ctor->
inits()) {
6749 const Expr *InitExpr =
Init->getInit();
6751 const Record::Field *F =
R->getField(
Member);
6755 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6758 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6761 if (
Init->isBaseVirtual()) {
6762 assert(
R->getVirtualBase(BaseDecl));
6763 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6769 const Record::Base *B =
R->getBase(BaseDecl);
6771 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6775 if (IsUnion && !this->emitActivate(InitExpr))
6778 if (!this->visitInitializer(InitExpr))
6780 if (!this->emitFinishInitPop(InitExpr))
6785 assert(IFD->getChainingSize() >= 2);
6787 unsigned NestedFieldOffset = 0;
6788 const Record::Field *NestedField =
nullptr;
6789 for (
const NamedDecl *ND : IFD->chain()) {
6791 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6792 assert(FieldRecord);
6794 NestedField = FieldRecord->
getField(FD);
6795 assert(NestedField);
6796 IsUnion = IsUnion || FieldRecord->
isUnion();
6798 NestedFieldOffset += NestedField->Offset;
6800 assert(NestedField);
6802 unsigned FirstLinkOffset =
6806 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6811 unsigned InitFieldOffset = 0;
6812 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6814 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6815 assert(FieldRecord);
6816 NestedField = FieldRecord->
getField(FD);
6817 InitFieldOffset += NestedField->Offset;
6818 assert(NestedField);
6819 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6821 if (!this->emitFinishInitPop(InitExpr))
6826 assert(
Init->isDelegatingInitializer());
6827 if (!this->emitThis(InitExpr))
6829 if (!this->visitInitializer(
Init->getInit()))
6831 if (!this->emitPopPtr(InitExpr))
6835 if (!
Scope.destroyLocals())
6842 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
6843 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
6850 if (!visitStmt(Body))
6857template <
class Emitter>
6860 const Record *
R = this->getRecord(RD);
6865 if (!this->visitStmt(Dtor->
getBody()))
6869 if (!this->emitThis(Dtor))
6872 if (!this->emitCheckDestruction(Dtor))
6876 if (!
R->isUnion()) {
6880 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
6884 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6886 if (!this->emitDestructionPop(D,
SourceInfo{}))
6891 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
6892 if (
Base.R->hasTrivialDtor())
6896 if (!this->emitRecordDestructionPop(
Base.R, {}))
6901 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6904template <
class Emitter>
6905bool Compiler<Emitter>::compileUnionAssignmentOperator(
6907 if (!this->emitThis(MD))
6910 if (!this->emitGetParam(
PT_Ptr, 0, MD))
6913 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6916template <
class Emitter>
6923 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6924 return this->compileConstructor(Ctor);
6925 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6926 return this->compileDestructor(Dtor);
6929 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6934 return this->compileUnionAssignmentOperator(MD);
6937 return this->emitLambdaStaticInvokerBody(MD);
6941 if (
const auto *Body = F->
getBody())
6955 return FD->getBitWidthValue();
6958template <
class Emitter>
6971 if (!
Ctx.getLangOpts().CPlusPlus14)
6972 return this->emitInvalid(E);
6974 return this->emitError(E);
6976 if (!this->
visit(SubExpr))
6980 if (!this->emitIncPtr(E))
6987 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6988 : this->emitIncf(getFPOptions(E), E);
7000 if (!
Ctx.getLangOpts().CPlusPlus14)
7001 return this->emitInvalid(E);
7003 return this->emitError(E);
7005 if (!this->
visit(SubExpr))
7009 if (!this->emitDecPtr(E))
7016 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7017 : this->emitDecf(getFPOptions(E), E);
7030 if (!
Ctx.getLangOpts().CPlusPlus14)
7031 return this->emitInvalid(E);
7033 return this->emitError(E);
7035 if (!this->
visit(SubExpr))
7039 if (!this->emitLoadPtr(E))
7041 if (!this->emitConstUint8(1, E))
7043 if (!this->emitAddOffsetUint8(E))
7045 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7051 return this->emitIncfPop(getFPOptions(E), E);
7061 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7062 if (!this->emitLoadFloat(E))
7064 APFloat F(TargetSemantics, 1);
7065 if (!this->emitFloat(F, E))
7068 if (!this->emitAddf(getFPOptions(E), E))
7070 if (!this->emitStoreFloat(E))
7082 return E->
isGLValue() || this->emitLoadPop(*T, E);
7085 if (!
Ctx.getLangOpts().CPlusPlus14)
7086 return this->emitInvalid(E);
7088 return this->emitError(E);
7090 if (!this->
visit(SubExpr))
7094 if (!this->emitLoadPtr(E))
7096 if (!this->emitConstUint8(1, E))
7098 if (!this->emitSubOffsetUint8(E))
7100 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7106 return this->emitDecfPop(getFPOptions(E), E);
7116 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7117 if (!this->emitLoadFloat(E))
7119 APFloat F(TargetSemantics, 1);
7120 if (!this->emitFloat(F, E))
7123 if (!this->emitSubf(getFPOptions(E), E))
7125 if (!this->emitStoreFloat(E))
7137 return E->
isGLValue() || this->emitLoadPop(*T, E);
7141 return this->emitError(E);
7144 return this->
discard(SubExpr);
7149 if (!this->emitInv(E))
7153 return this->emitCast(
PT_Bool, ET, E);
7157 return this->emitError(E);
7159 if (!this->
visit(SubExpr))
7161 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7164 return this->emitError(E);
7166 if (!this->
visit(SubExpr))
7181 return this->
discard(SubExpr);
7183 if (!this->
visit(SubExpr))
7190 return this->emitNarrowPtr(E);
7195 return this->emitError(E);
7197 if (!this->
visit(SubExpr))
7199 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7211 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7216 assert(
false &&
"Unhandled opcode");
7222template <
class Emitter>
7228 return this->
discard(SubExpr);
7231 auto prepareResult = [=]() ->
bool {
7236 return this->emitGetPtrLocal(*LocalIndex, E);
7243 unsigned SubExprOffset = ~0u;
7244 auto createTemp = [=, &SubExprOffset]() ->
bool {
7247 if (!this->
visit(SubExpr))
7249 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7253 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7254 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7256 return this->emitArrayElemPop(ElemT, Index, E);
7261 if (!prepareResult())
7265 for (
unsigned I = 0; I != 2; ++I) {
7266 if (!getElem(SubExprOffset, I))
7268 if (!this->emitNeg(ElemT, E))
7270 if (!this->emitInitElem(ElemT, I, E))
7281 if (!this->
visit(SubExpr))
7283 if (!this->emitComplexBoolCast(SubExpr))
7285 if (!this->emitInv(E))
7288 return this->emitCast(
PT_Bool, ET, E);
7292 return this->emitComplexReal(SubExpr);
7295 if (!this->
visit(SubExpr))
7299 if (!this->emitConstUint8(1, E))
7301 return this->emitArrayElemPtrPopUint8(E);
7312 if (!this->emitArrayElem(ElemT, 1, E))
7314 if (!this->emitNeg(ElemT, E))
7316 if (!this->emitInitElem(ElemT, 1, E))
7324 return this->emitInvalid(E);
7330template <
class Emitter>
7336 return this->
discard(SubExpr);
7339 if (UnaryOp == UO_Extension)
7342 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7343 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7344 return this->emitInvalid(E);
7347 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7354 if (!this->emitGetPtrLocal(*LocalIndex, E))
7359 unsigned SubExprOffset =
7361 if (!this->
visit(SubExpr))
7363 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7368 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7369 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7371 return this->emitArrayElemPop(ElemT, Index, E);
7376 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7377 if (!getElem(SubExprOffset, I))
7379 if (!this->emitNeg(ElemT, E))
7381 if (!this->emitInitElem(ElemT, I, E))
7396 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7397 if (!getElem(SubExprOffset, I))
7400 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7402 if (!this->emitInv(E))
7404 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7406 if (!this->emitNeg(ElemT, E))
7408 if (ElemT != ResultVecElemT &&
7409 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7411 if (!this->emitInitElem(ResultVecElemT, I, E))
7417 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7418 if (!getElem(SubExprOffset, I))
7421 if (!this->emitInv(E))
7424 if (!this->emitComp(ElemT, E))
7427 if (!this->emitInitElem(ElemT, I, E))
7432 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7437template <
class Emitter>
7442 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7443 return this->emitConst(ECD->getInitVal(), E);
7444 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7446 return F && this->emitGetFnPtr(F, E);
7448 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7450 if (!this->emitGetPtrGlobal(*Index, E))
7455 return this->emitInitGlobal(*T, *Index, E);
7459 return this->emitFinishInit(E);
7474 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7475 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7480 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7481 if (IsReference || !It->second.IsPtr)
7482 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7484 return this->emitGetPtrParam(It->second.Index, E);
7487 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7493 const unsigned Offset = It->second.Offset;
7496 return this->emitGetRefLocal(Offset, E);
7498 return this->emitGetPtrLocal(Offset, E);
7501 if (
auto GlobalIndex =
P.getGlobal(D)) {
7503 if (!
Ctx.getLangOpts().CPlusPlus11)
7504 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7505 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7508 return this->emitGetPtrGlobal(*GlobalIndex, E);
7512 auto revisit = [&](
const VarDecl *VD,
7513 bool IsConstexprUnknown =
true) ->
bool {
7515 IsConstexprUnknown);
7520 if (!this->emitPopCC(E))
7523 if (VarState.notCreated())
7531 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7533 if (
auto It = this->LambdaCaptures.find(D);
7534 It != this->LambdaCaptures.end()) {
7535 auto [Offset, IsPtr] = It->second;
7538 return this->emitGetThisFieldPtr(Offset, E);
7539 return this->emitGetPtrThisField(Offset, E);
7543 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7544 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7545 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7549 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7550 return this->
visit(BD->getBinding());
7554 return this->emitDummyPtr(D, E);
7558 const auto *VD = dyn_cast<VarDecl>(D);
7560 return this->emitError(E);
7563 if (!
Ctx.getLangOpts().CPlusPlus) {
7566 return revisit(VD,
false);
7567 return this->emitDummyPtr(D, E);
7571 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7572 if (T.isConstant(
Ctx.getASTContext()))
7574 return T->isReferenceType();
7578 typeShouldBeVisited(DeclType)) {
7580 Init && !
Init->isValueDependent()) {
7586 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7600 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7605 return revisit(VD, IsConstexprUnknown);
7606 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7607 return revisit(VD,
true);
7614 return this->emitDummyPtr(D, E);
7617template <
class Emitter>
7625 if (!
C->destroyLocals())
7631template <
class Emitter>
7632unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7635 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7637 return Ty->getAsCXXRecordDecl();
7639 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7640 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7642 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7646template <
class Emitter>
7653 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7658 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7659 getFPOptions(E), E);
7661 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7662 getFPOptions(E), E);
7666 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7671 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7673 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7677 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7681 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7682 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7689template <
class Emitter>
7692 assert(FromT != ToT);
7695 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7697 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7699 return this->emitCast(FromT, ToT, E);
7703template <
class Emitter>
7704bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7708 return this->
discard(SubExpr);
7710 if (!this->visit(SubExpr))
7713 if (!this->emitConstUint8(0, SubExpr))
7715 return this->emitArrayElemPtrPopUint8(SubExpr);
7719 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7723template <
class Emitter>
7724bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7725 assert(!DiscardResult);
7729 if (!this->emitArrayElem(ElemT, 0, E))
7732 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7735 if (!this->emitCast(ElemT,
PT_Bool, E))
7740 LabelTy LabelTrue = this->getLabel();
7741 if (!this->jumpTrue(LabelTrue, E))
7744 if (!this->emitArrayElemPop(ElemT, 1, E))
7747 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7750 if (!this->emitCast(ElemT,
PT_Bool, E))
7754 LabelTy EndLabel = this->getLabel();
7755 this->jump(EndLabel, E);
7757 this->emitLabel(LabelTrue);
7758 if (!this->emitPopPtr(E))
7760 if (!this->emitConstBool(
true, E))
7763 this->fallthrough(EndLabel);
7764 this->emitLabel(EndLabel);
7769template <
class Emitter>
7770bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7781 LHSIsComplex =
true;
7782 ElemT = classifyComplexElementType(LHS->
getType());
7783 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7784 if (!this->visit(LHS))
7786 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7789 LHSIsComplex =
false;
7791 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7792 if (!this->visit(LHS))
7794 if (!this->emitSetLocal(LHST, LHSOffset, E))
7801 RHSIsComplex =
true;
7802 ElemT = classifyComplexElementType(RHS->
getType());
7803 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7804 if (!this->visit(RHS))
7806 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7809 RHSIsComplex =
false;
7811 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7812 if (!this->visit(RHS))
7814 if (!this->emitSetLocal(RHST, RHSOffset, E))
7818 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7819 bool IsComplex) ->
bool {
7821 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7823 return this->emitArrayElemPop(ElemT, Index, E);
7825 return this->emitGetLocal(ElemT, LocalOffset, E);
7828 for (
unsigned I = 0; I != 2; ++I) {
7830 if (!getElem(LHSOffset, I, LHSIsComplex))
7832 if (!getElem(RHSOffset, I, RHSIsComplex))
7835 if (!this->emitEQ(ElemT, E))
7838 if (!this->emitCastBoolUint8(E))
7843 if (!this->emitAddUint8(E))
7845 if (!this->emitConstUint8(2, E))
7849 if (!this->emitEQUint8(E))
7852 if (!this->emitNEUint8(E))
7859 return this->emitCast(
PT_Bool, ResT, E);
7866template <
class Emitter>
7867bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7870 assert(!
R->hasTrivialDtor());
7873 const Function *DtorFunc = getFunction(Dtor);
7876 assert(DtorFunc->hasThisPointer());
7877 assert(DtorFunc->getNumParams() == 1);
7878 return this->emitCall(DtorFunc, 0, Loc);
7883template <
class Emitter>
7884bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7896 return this->emitPopPtr(Loc);
7898 for (ssize_t I = N - 1; I >= 1; --I) {
7899 if (!this->emitConstUint64(I, Loc))
7901 if (!this->emitArrayElemPtrUint64(Loc))
7903 if (!this->emitDestructionPop(ElemDesc, Loc))
7907 if (!this->emitConstUint64(0, Loc))
7909 if (!this->emitArrayElemPtrPopUint64(Loc))
7911 return this->emitDestructionPop(ElemDesc, Loc);
7916 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7921template <
class Emitter>
7922bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7923 assert(!DiscardResult &&
"Should've been checked before");
7924 unsigned DummyID = P.getOrCreateDummy(D);
7926 if (!this->emitGetPtrGlobal(DummyID, E))
7934 return this->emitDecayPtr(
PT_Ptr, PT, E);
7940template <
class Emitter>
7941bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7943 return this->emitConstFloat(
Floating(F), E);
7945 APInt I = F.bitcastToAPInt();
7946 return this->emitConstFloat(
7947 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7948 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7959template <
class Emitter>
7960bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7973 if (!this->emitGetPtrLocal(*LocalIndex, E))
7983 if (!this->visit(SubExpr))
7985 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7986 unsigned TempOffset =
7987 allocateLocalPrimitive(SubExpr, *FromT,
true);
7988 if (!this->visit(SubExpr))
7990 if (!this->emitSetLocal(*FromT, TempOffset, E))
7992 if (!this->emitGetPtrLocal(TempOffset, E))
7999 if (!this->emitBitCast(E))
8001 return DiscardResult ? this->emitPopPtr(E) :
true;
8005 const llvm::fltSemantics *TargetSemantics =
nullptr;
8007 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8013 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8015 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8016 ResultBitWidth, TargetSemantics,
8021 return this->emitPop(*ToT, E);
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
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
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
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 ...
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
DoStmt - This represents a 'do/while' stmt.
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits()
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.
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.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
uint32_t getCodeUnit(size_t i) const
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
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
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.
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.
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
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 visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool visitAPValueInitializer(const APValue &Val, const Expr *E, QualType T)
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)
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)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E)
Visit an APValue.
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
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 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)
const ValueDecl * InitializingDecl
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 discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
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)
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 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)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const ValueDecl *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.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
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
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
Describes the statement/declaration an opcode was generated from.
StmtExprScope(Compiler< Emitter > *Ctx)
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.
Compiler< Emitter > * Ctx
Compiler instance.
virtual void addLocal(Scope::Local Local)
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
static bool Activate(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool InitScope(InterpState &S, CodePtr OpPC, uint32_t I)
constexpr bool isIntegerOrBoolType(PrimType T)
static void discard(InterpStack &Stk, PrimType T)
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
bool Init(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
U cast(CodeGen::Address addr)
int const char * function
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
static constexpr MetadataSize InlineDescMD
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
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 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()