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, CE);
239 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
240 return this->emitGetLocal(*SubExprT, It->second.Offset, CE);
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.Offset, CE);
255 if (!this->emitGetPtrLocal(*LocalIndex, CE))
259 if (!this->
visit(SubExpr))
263 return this->emitLoadPop(*SubExprT, CE);
268 return this->emitMemcpy(CE);
271 case CK_DerivedToBaseMemberPointer: {
277 unsigned DerivedOffset =
279 FromMP->getMostRecentCXXRecordDecl());
284 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
287 case CK_BaseToDerivedMemberPointer: {
293 unsigned DerivedOffset =
294 Ctx.collectBaseOffset(FromMP->getMostRecentCXXRecordDecl(),
299 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
302 case CK_UncheckedDerivedToBase:
303 case CK_DerivedToBase: {
308 if (
const auto *PT = dyn_cast<PointerType>(Ty))
309 return PT->getPointeeType()->getAsCXXRecordDecl();
310 return Ty->getAsCXXRecordDecl();
317 if (B->isVirtual()) {
318 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), CE))
320 CurType = B->getType();
322 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
323 if (!this->emitGetPtrBasePop(
326 CurType = B->getType();
333 case CK_BaseToDerived: {
336 unsigned DerivedOffset =
342 return this->emitGetPtrDerivedPop(DerivedOffset,
347 case CK_FloatingCast: {
352 if (!this->
visit(SubExpr))
354 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
358 case CK_IntegralToFloating: {
361 if (!this->
visit(SubExpr))
363 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
364 return this->emitCastIntegralFloating(
365 classifyPrim(SubExpr), TargetSemantics, getFPOptions(CE), CE);
368 case CK_FloatingToBoolean: {
372 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
373 return this->emitConstBool(FL->getValue().isNonZero(), CE);
374 if (!this->
visit(SubExpr))
376 return this->emitCastFloatingIntegralBool(getFPOptions(CE), CE);
379 case CK_FloatingToIntegral: {
382 if (!this->
visit(SubExpr))
386 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(CE->
getType()),
387 getFPOptions(CE), CE);
389 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
390 getFPOptions(CE), CE);
392 return this->emitCastFloatingIntegral(ToT, getFPOptions(CE), CE);
395 case CK_NullToPointer:
396 case CK_NullToMemberPointer: {
401 if (!PointeeType.
isNull()) {
403 Desc =
P.createDescriptor(SubExpr, *
T);
405 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
409 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(CE->
getType());
413 case CK_PointerToIntegral: {
414 if (!this->
visit(SubExpr))
420 if (!this->emitDecayPtr(FromT,
PT_Ptr, CE))
426 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(CE->
getType()),
429 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
431 return this->emitCastPointerIntegral(
T, CE);
434 case CK_ArrayToPointerDecay: {
435 if (!this->
visit(SubExpr))
437 return this->emitArrayDecay(CE);
440 case CK_IntegralToPointer: {
442 assert(IntType->isIntegralOrEnumerationType());
443 if (!this->
visit(SubExpr))
451 Desc =
P.createDescriptor(SubExpr, *
T);
458 if (!this->emitGetIntPtr(
T, Desc, CE))
466 return this->emitDecayPtr(
PT_Ptr, DestPtrT, CE);
469 case CK_AtomicToNonAtomic:
470 case CK_ConstructorConversion:
471 case CK_FunctionToPointerDecay:
472 case CK_NonAtomicToAtomic:
474 case CK_UserDefinedConversion:
475 case CK_AddressSpaceConversion:
476 case CK_CPointerToObjCPointerCast:
491 return this->emitBuiltinBitCast(CE);
506 if (!this->
visit(SubExpr))
514 return this->emitFnPtrCast(CE);
521 if (!this->
visit(SubExpr))
523 return this->emitDecayPtr(*FromT, *ToT, CE);
525 case CK_IntegralToBoolean:
526 case CK_FixedPointToBoolean: {
532 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
533 return this->emitConst(IL->getValue(), CE);
534 if (!this->
visit(SubExpr))
539 case CK_BooleanToSignedIntegral:
540 case CK_IntegralCast: {
547 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
552 if (!this->emitConst(IL->getValue(), SubExpr))
555 if (!this->
visit(SubExpr))
563 if (!ED->isFixed()) {
564 if (!this->emitCheckEnumValue(*FromT, ED, CE))
570 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
573 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
578 if (!this->emitCast(*FromT, *ToT, CE))
581 if (CE->
getCastKind() == CK_BooleanToSignedIntegral)
582 return this->emitNeg(*ToT, CE);
586 case CK_PointerToBoolean:
587 case CK_MemberPointerToBoolean: {
590 if (!this->
visit(SubExpr))
592 return this->emitIsNonNull(PtrT, CE);
595 case CK_IntegralComplexToBoolean:
596 case CK_FloatingComplexToBoolean: {
597 if (!this->
visit(SubExpr))
599 return this->emitComplexBoolCast(SubExpr);
602 case CK_IntegralComplexToReal:
603 case CK_FloatingComplexToReal:
604 return this->emitComplexReal(SubExpr);
606 case CK_IntegralRealToComplex:
607 case CK_FloatingRealToComplex: {
614 if (!this->emitGetPtrLocal(*LocalIndex, CE))
623 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
625 return this->emitInitElem(
T, 1, SubExpr);
628 case CK_IntegralComplexCast:
629 case CK_FloatingComplexCast:
630 case CK_IntegralComplexToFloatingComplex:
631 case CK_FloatingComplexToIntegralComplex: {
638 if (!this->emitGetPtrLocal(*LocalIndex, CE))
645 unsigned SubExprOffset =
647 if (!this->
visit(SubExpr))
649 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, CE))
657 for (
unsigned I = 0; I != 2; ++I) {
658 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, CE))
660 if (!this->emitArrayElemPop(SourceElemT, I, CE))
664 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, CE))
668 if (!this->emitInitElem(DestElemT, I, CE))
674 case CK_VectorSplat: {
683 if (!this->emitGetPtrLocal(*LocalIndex, CE))
689 unsigned ElemOffset =
693 if (!this->
visit(SubExpr))
698 if (!this->emitSetLocal(ElemT, ElemOffset, CE))
701 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
702 if (!this->emitGetLocal(ElemT, ElemOffset, CE))
704 if (!this->emitInitElem(ElemT, I, CE))
711 case CK_HLSLVectorTruncation: {
716 if (!this->
visit(SubExpr))
718 return this->emitArrayElemPop(*ResultT, 0, CE);
727 if (!this->emitGetPtrLocal(*LocalIndex, CE))
732 if (!this->
visit(SubExpr))
734 return this->emitCopyArray(classifyVectorElementType(CE->
getType()), 0, 0,
738 case CK_IntegralToFixedPoint: {
739 if (!this->
visit(SubExpr))
743 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
747 case CK_FloatingToFixedPoint: {
748 if (!this->
visit(SubExpr))
752 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
753 return this->emitCastFloatingFixedPoint(Sem, CE);
755 case CK_FixedPointToFloating: {
756 if (!this->
visit(SubExpr))
758 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
759 return this->emitCastFixedPointFloating(TargetSemantics, CE);
761 case CK_FixedPointToIntegral: {
762 if (!this->
visit(SubExpr))
766 case CK_FixedPointCast: {
767 if (!this->
visit(SubExpr))
770 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
771 return this->emitCastFixedPoint(Sem, CE);
782 case CK_LValueBitCast:
786 return this->emitInvalid(CE);
788 llvm_unreachable(
"Unhandled clang::CastKind enum");
791template <
class Emitter>
793 return this->emitBuiltinBitCast(E);
796template <
class Emitter>
801 return this->emitConst(
LE->getValue(),
LE);
804template <
class Emitter>
810 return this->emitFloat(F, E);
813template <
class Emitter>
823 if (!this->emitGetPtrLocal(*LocalIndex, E))
830 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
832 if (!this->emitInitElem(SubExprT, 0, SubExpr))
837template <
class Emitter>
845 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
850template <
class Emitter>
855template <
class Emitter>
882 return this->emitComplexComparison(LHS, RHS, BO);
887 if (!this->
visit(LHS))
890 if (!this->
visit(RHS))
893 if (!this->emitToMemberPtr(BO))
899 if (!this->emitCastMemberPtrPtr(BO))
916 Ctx.getASTContext().CompCategories.lookupInfoForType(BO->
getType());
922 if (!this->emitGetPtrLocal(*ResultIndex, BO))
929 return this->emitCMP3(*
LT, CmpInfo, BO);
932 if (!
LT || !RT || !
T)
942 return this->visitAssignment(LHS, RHS, BO);
949 auto MaybeCastToBool = [
this,
T, BO](
bool Result) {
953 return this->emitPopBool(BO);
955 return this->emitCast(
PT_Bool, *
T, BO);
959 auto Discard = [
this,
T, BO](
bool Result) {
967 return MaybeCastToBool(this->emitEQ(*
LT, BO));
969 return MaybeCastToBool(this->emitNE(*
LT, BO));
971 return MaybeCastToBool(this->emitLT(*
LT, BO));
973 return MaybeCastToBool(this->emitLE(*
LT, BO));
975 return MaybeCastToBool(this->emitGT(*
LT, BO));
977 return MaybeCastToBool(this->emitGE(*
LT, BO));
980 return Discard(this->emitSubf(getFPOptions(BO), BO));
981 return Discard(this->emitSub(*
T, BO));
984 return Discard(this->emitAddf(getFPOptions(BO), BO));
985 return Discard(this->emitAdd(*
T, BO));
988 return Discard(this->emitMulf(getFPOptions(BO), BO));
989 return Discard(this->emitMul(*
T, BO));
991 return Discard(this->emitRem(*
T, BO));
994 return Discard(this->emitDivf(getFPOptions(BO), BO));
995 return Discard(this->emitDiv(*
T, BO));
997 return Discard(this->emitBitAnd(*
T, BO));
999 return Discard(this->emitBitOr(*
T, BO));
1001 return Discard(this->emitShl(*
LT, *RT, BO));
1003 return Discard(this->emitShr(*
LT, *RT, BO));
1005 return Discard(this->emitBitXor(*
T, BO));
1008 llvm_unreachable(
"Already handled earlier");
1013 llvm_unreachable(
"Unhandled binary op");
1018template <
class Emitter>
1024 if ((Op != BO_Add && Op != BO_Sub) ||
1035 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1036 if (!this->
visit(E))
1039 return this->emitDecayPtr(
T,
PT_Ptr, E);
1048 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1056 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1059 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1066 if (!visitAsPointer(RHS, *RT))
1068 if (!this->
visit(LHS))
1072 if (!visitAsPointer(LHS, *
LT))
1074 if (!this->
visit(RHS))
1084 if (!this->emitAddOffset(OffsetType, E))
1092 if (!this->emitSubOffset(OffsetType, E))
1103template <
class Emitter>
1113 LabelTy LabelTrue = this->getLabel();
1114 LabelTy LabelEnd = this->getLabel();
1118 if (!this->jumpTrue(LabelTrue))
1123 if (!this->jump(LabelEnd))
1126 this->emitLabel(LabelTrue);
1127 this->emitConstBool(
true, E);
1128 this->fallthrough(LabelEnd);
1129 this->emitLabel(LabelEnd);
1132 assert(Op == BO_LAnd);
1135 LabelTy LabelFalse = this->getLabel();
1136 LabelTy LabelEnd = this->getLabel();
1140 if (!this->jumpFalse(LabelFalse))
1145 if (!this->jump(LabelEnd))
1148 this->emitLabel(LabelFalse);
1149 this->emitConstBool(
false, E);
1150 this->fallthrough(LabelEnd);
1151 this->emitLabel(LabelEnd);
1155 return this->emitPopBool(E);
1160 return this->emitCast(
PT_Bool, *
T, E);
1164template <
class Emitter>
1171 if (!this->emitGetPtrLocal(*LocalIndex, E))
1180 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1181 unsigned ResultOffset = ~0u;
1187 if (!this->emitDupPtr(E))
1189 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1194 LHSType = AT->getValueType();
1197 RHSType = AT->getValueType();
1206 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1211 if (!this->
visit(LHS))
1213 if (!this->
visit(RHS))
1215 return this->emitMulc(ElemT, E);
1218 if (Op == BO_Div && RHSIsComplex) {
1225 if (!LHSIsComplex) {
1230 LHSOffset = *LocalIndex;
1232 if (!this->emitGetPtrLocal(LHSOffset, E))
1235 if (!this->
visit(LHS))
1238 if (!this->emitInitElem(ElemT, 0, E))
1241 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1243 if (!this->emitInitElem(ElemT, 1, E))
1246 if (!this->
visit(LHS))
1250 if (!this->
visit(RHS))
1252 return this->emitDivc(ElemT, E);
1258 if (!this->
visit(LHS))
1260 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1265 if (!this->
visit(LHS))
1267 if (!this->emitSetLocal(LHST, LHSOffset, E))
1275 if (!this->
visit(RHS))
1277 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1282 if (!this->
visit(RHS))
1284 if (!this->emitSetLocal(RHST, RHSOffset, E))
1291 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1292 unsigned ElemIndex,
unsigned Offset,
1293 const Expr *E) ->
bool {
1295 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1297 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1300 if (ElemIndex == 0 || !LoadZero)
1307 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1310 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1317 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1320 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1323 if (!this->emitAddf(getFPOptions(E), E))
1326 if (!this->emitAdd(ResultElemT, E))
1331 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1334 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1337 if (!this->emitSubf(getFPOptions(E), E))
1340 if (!this->emitSub(ResultElemT, E))
1345 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1348 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1352 if (!this->emitMulf(getFPOptions(E), E))
1355 if (!this->emitMul(ResultElemT, E))
1360 assert(!RHSIsComplex);
1361 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1364 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1368 if (!this->emitDivf(getFPOptions(E), E))
1371 if (!this->emitDiv(ResultElemT, E))
1382 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1385 if (!this->emitPop(ResultElemT, E))
1390 return this->emitPopPtr(E);
1396template <
class Emitter>
1401 "Comma op should be handled in VisitBinaryOperator");
1415 if (!this->emitGetPtrLocal(*LocalIndex, E))
1429 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1432 if (!this->
visit(LHS))
1434 if (!this->
visit(RHS))
1436 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1439 return this->emitPopPtr(E);
1444 unsigned LHSOffset =
1446 if (!this->
visit(LHS))
1448 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1452 unsigned RHSOffset =
1454 if (!this->
visit(RHS))
1456 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1468 if (NeedIntPromot) {
1470 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1475 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1476 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1478 if (!this->emitArrayElemPop(ElemT, Index, E))
1481 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1483 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1485 }
else if (NeedIntPromot) {
1486 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1492#define EMIT_ARITH_OP(OP) \
1494 if (ElemT == PT_Float) { \
1495 if (!this->emit##OP##f(getFPOptions(E), E)) \
1498 if (!this->emit##OP(ElemT, E)) \
1504 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1505 if (!getElem(LHSOffset, ElemT, I))
1507 if (!getElem(RHSOffset, RHSElemT, I))
1519 if (!this->emitRem(ElemT, E))
1523 if (!this->emitBitAnd(OpT, E))
1527 if (!this->emitBitOr(OpT, E))
1531 if (!this->emitBitXor(OpT, E))
1535 if (!this->emitShl(OpT, RHSElemT, E))
1539 if (!this->emitShr(OpT, RHSElemT, E))
1543 if (!this->emitEQ(ElemT, E))
1547 if (!this->emitNE(ElemT, E))
1551 if (!this->emitLE(ElemT, E))
1555 if (!this->emitLT(ElemT, E))
1559 if (!this->emitGE(ElemT, E))
1563 if (!this->emitGT(ElemT, E))
1568 if (!this->emitBitAnd(ResultElemT, E))
1573 if (!this->emitBitOr(ResultElemT, E))
1577 return this->emitInvalid(E);
1586 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1588 if (!this->emitNeg(ResultElemT, E))
1594 if (NeedIntPromot &&
1595 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1599 if (!this->emitInitElem(ResultElemT, I, E))
1608template <
class Emitter>
1618 auto LHSSemaInt = LHSSema.toOpaqueInt();
1620 auto RHSSemaInt = RHSSema.toOpaqueInt();
1622 if (!this->
visit(LHS))
1630 if (!this->
visit(RHS))
1639 auto ConvertResult = [&](
bool R) ->
bool {
1643 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1644 if (ResultSema != CommonSema)
1645 return this->emitCastFixedPoint(ResultSema, E);
1649 auto MaybeCastToBool = [&](
bool Result) {
1654 return this->emitPop(
T, E);
1656 return this->emitCast(
PT_Bool,
T, E);
1662 return MaybeCastToBool(this->emitEQFixedPoint(E));
1664 return MaybeCastToBool(this->emitNEFixedPoint(E));
1666 return MaybeCastToBool(this->emitLTFixedPoint(E));
1668 return MaybeCastToBool(this->emitLEFixedPoint(E));
1670 return MaybeCastToBool(this->emitGTFixedPoint(E));
1672 return MaybeCastToBool(this->emitGEFixedPoint(E));
1674 return ConvertResult(this->emitAddFixedPoint(E));
1676 return ConvertResult(this->emitSubFixedPoint(E));
1678 return ConvertResult(this->emitMulFixedPoint(E));
1680 return ConvertResult(this->emitDivFixedPoint(E));
1682 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1684 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1687 return this->emitInvalid(E);
1690 llvm_unreachable(
"unhandled binop opcode");
1693template <
class Emitter>
1702 if (!this->
visit(SubExpr))
1704 return this->emitNegFixedPoint(E);
1709 llvm_unreachable(
"Unhandled unary opcode");
1712template <
class Emitter>
1721 return this->visitZeroInitializer(*
T, QT, E);
1729 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1730 CXXRD && CXXRD->getNumVBases() > 0) {
1740 return this->visitZeroRecordInitializer(R, E);
1747 return this->visitZeroArrayInitializer(QT, E);
1751 QualType ElemQT = ComplexTy->getElementType();
1753 for (
unsigned I = 0; I < 2; ++I) {
1754 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1756 if (!this->emitInitElem(ElemT, I, E))
1763 unsigned NumVecElements = VecT->getNumElements();
1764 QualType ElemQT = VecT->getElementType();
1767 for (
unsigned I = 0; I < NumVecElements; ++I) {
1768 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1770 if (!this->emitInitElem(ElemT, I, E))
1779template <
class Emitter>
1789 for (
const Expr *SubExpr : {LHS, RHS}) {
1790 if (!this->
visit(SubExpr)) {
1797 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
1798 if (!this->emitExpandPtr(E))
1809 return this->emitError(E);
1812 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
1816 if (!this->emitArrayElemPtrPop(*IndexT, E))
1819 return this->emitPopPtr(E);
1825 return this->emitLoadPop(*
T, E);
1828template <
class Emitter>
1830 const Expr *ArrayFiller,
const Expr *E) {
1835 QT = AT->getValueType();
1838 if (Inits.size() == 0)
1840 return this->emitInvalid(E);
1855 if (Inits.size() == 0)
1856 return this->visitZeroInitializer(*
T, QT, E);
1857 assert(Inits.size() == 1);
1864 if (Inits.size() == 1 && E->
getType() == Inits[0]->getType())
1870 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
1877 bool BitField = FieldToInit->isBitField();
1879 return this->emitInitBitFieldActivate(
T, FieldToInit, E);
1881 return this->emitInitBitField(
T, FieldToInit, E);
1883 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
1884 return this->emitInitField(
T, FieldToInit->Offset, E);
1887 auto initCompositeField = [=](
const Record::Field *FieldToInit,
1895 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
1898 if (
Activate && !this->emitActivate(E))
1903 return this->emitPopPtr(E);
1907 if (Inits.size() == 0) {
1908 if (!this->visitZeroRecordInitializer(R, E))
1913 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
1914 FToInit = ILE->getInitializedFieldInUnion();
1918 const Record::Field *FieldToInit = R->
getField(FToInit);
1920 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
1923 if (!initCompositeField(FieldToInit,
Init,
true))
1927 return this->emitFinishInit(E);
1931 unsigned InitIndex = 0;
1934 while (InitIndex < R->getNumFields() &&
1939 const Record::Field *FieldToInit = R->
getField(InitIndex);
1940 if (!initPrimitiveField(FieldToInit,
Init, *
T))
1945 if (
const Record::Base *B = R->
getBase(
Init->getType())) {
1946 if (!this->emitGetPtrBase(B->Offset,
Init))
1952 if (!this->emitFinishInitPop(E))
1957 const Record::Field *FieldToInit = R->
getField(InitIndex);
1958 if (!initCompositeField(FieldToInit,
Init))
1964 return this->emitFinishInit(E);
1968 if (Inits.size() == 1 && QT == Inits[0]->getType())
1972 Ctx.getASTContext().getAsConstantArrayType(QT);
1975 if (!this->emitCheckArraySize(NumElems, E))
1979 unsigned ElementIndex = 0;
1981 if (
const auto *EmbedS =
1982 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
1990 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
1991 getFPOptions(E), E))
1997 return this->emitInitElem(TargetT, ElemIndex, IL);
1999 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2011 for (; ElementIndex != NumElems; ++ElementIndex) {
2017 return this->emitFinishInit(E);
2021 unsigned NumInits = Inits.size();
2026 QualType ElemQT = ComplexTy->getElementType();
2028 if (NumInits == 0) {
2030 for (
unsigned I = 0; I < 2; ++I) {
2031 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2033 if (!this->emitInitElem(ElemT, I, E))
2036 }
else if (NumInits == 2) {
2037 unsigned InitIndex = 0;
2042 if (!this->emitInitElem(ElemT, InitIndex, E))
2051 unsigned NumVecElements = VecT->getNumElements();
2052 assert(NumVecElements >= Inits.size());
2054 QualType ElemQT = VecT->getElementType();
2058 unsigned InitIndex = 0;
2065 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2066 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2067 InitVecT->getNumElements(), E))
2069 InitIndex += InitVecT->getNumElements();
2071 if (!this->emitInitElem(ElemT, InitIndex, E))
2077 assert(InitIndex <= NumVecElements);
2080 for (; InitIndex != NumVecElements; ++InitIndex) {
2081 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2083 if (!this->emitInitElem(ElemT, InitIndex, E))
2094template <
class Emitter>
2101 return this->emitInitElem(*InitT, ElemIndex,
Init);
2107 if (!this->emitConstUint32(ElemIndex,
Init))
2109 if (!this->emitArrayElemPtrUint32(
Init))
2113 return this->emitFinishInitPop(
Init);
2116template <
class Emitter>
2119 bool Activate,
bool IsOperatorCall) {
2121 llvm::BitVector NonNullArgs;
2122 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2125 bool ExplicitMemberFn =
false;
2126 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2127 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2129 unsigned ArgIndex = 0;
2130 for (
const Expr *Arg : Args) {
2132 if (!this->
visit(Arg))
2140 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2141 if (DeclIndex < FuncDecl->getNumParams())
2142 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2151 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2159 if (!this->emitActivate(Arg))
2163 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2166 if (!this->emitCheckNonNullArg(ArgT, Arg))
2177template <
class Emitter>
2182template <
class Emitter>
2188template <
class Emitter>
2194template <
class Emitter>
2210template <
class Emitter>
2212 auto It = E->
begin();
2213 return this->
visit(*It);
2218 bool AlignOfReturnsPreferred =
2219 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2225 T = Ref->getPointeeType();
2227 if (
T.getQualifiers().hasUnaligned())
2233 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2239template <
class Emitter>
2245 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2251 ArgType = Ref->getPointeeType();
2257 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2258 return this->emitInvalid(E);
2260 if (Kind == UETT_SizeOf)
2269 return this->emitConst(Size.getQuantity(), E);
2272 if (Kind == UETT_CountOf) {
2278 if (
const auto *CAT =
2282 return this->emitConst(CAT->getSize(), E);
2292 if (VAT->getElementType()->isArrayType()) {
2293 std::optional<APSInt> Res =
2295 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2300 return this->emitConst(*Res, E);
2305 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2322 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2325 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2335 return this->emitConst(Size.getQuantity(), E);
2338 if (Kind == UETT_VectorElements) {
2340 return this->emitConst(VT->getNumElements(), E);
2342 return this->emitSizelessVectorElementSize(E);
2345 if (Kind == UETT_VecStep) {
2347 unsigned N = VT->getNumElements();
2354 return this->emitConst(N, E);
2356 return this->emitConst(1, E);
2359 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2366 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2368 return this->emitInvalid(E);
2370 return this->emitConst(
2371 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2379template <
class Emitter>
2390 const auto maybeLoadValue = [&]() ->
bool {
2394 return this->emitLoadPop(*
T, E);
2398 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2402 if (
auto GlobalIndex =
P.getGlobal(VD))
2403 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2408 if (!this->
discard(Base) && !this->emitSideEffect(E))
2423 const Record::Field *F = R->
getField(FD);
2425 if (F->Decl->getType()->isReferenceType())
2426 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2427 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2430template <
class Emitter>
2439template <
class Emitter>
2458 for (
size_t I = 0; I != Size; ++I) {
2470template <
class Emitter>
2481 return this->emitGetLocal(SubExprT, It->second, E);
2483 if (!this->
visit(SourceExpr))
2490 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2496 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2506template <
class Emitter>
2529 bool IsBcpCall =
false;
2530 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2531 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2535 LabelTy LabelEnd = this->getLabel();
2536 LabelTy LabelFalse = this->getLabel();
2539 if (!this->emitStartSpeculation(E))
2547 if (this->checkingForUndefinedBehavior()) {
2550 if (!this->
discard(FalseExpr))
2556 if (!this->jumpFalse(LabelFalse))
2561 if (!this->jump(LabelEnd))
2563 this->emitLabel(LabelFalse);
2567 this->fallthrough(LabelEnd);
2568 this->emitLabel(LabelEnd);
2571 return this->emitEndSpeculation(E);
2575template <
class Emitter>
2581 unsigned StringIndex =
P.createGlobalString(E);
2582 return this->emitGetPtrGlobal(StringIndex, E);
2587 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2588 assert(CAT &&
"a string literal that's not a constant array?");
2593 unsigned N = std::min(ArraySize, E->
getLength());
2596 for (
unsigned I = 0; I != N; ++I) {
2599 if (CharWidth == 1) {
2600 this->emitConstSint8(CodeUnit, E);
2601 this->emitInitElemSint8(I, E);
2602 }
else if (CharWidth == 2) {
2603 this->emitConstUint16(CodeUnit, E);
2604 this->emitInitElemUint16(I, E);
2605 }
else if (CharWidth == 4) {
2606 this->emitConstUint32(CodeUnit, E);
2607 this->emitInitElemUint32(I, E);
2609 llvm_unreachable(
"unsupported character width");
2614 for (
unsigned I = N; I != ArraySize; ++I) {
2615 if (CharWidth == 1) {
2616 this->emitConstSint8(0, E);
2617 this->emitInitElemSint8(I, E);
2618 }
else if (CharWidth == 2) {
2619 this->emitConstUint16(0, E);
2620 this->emitInitElemUint16(I, E);
2621 }
else if (CharWidth == 4) {
2622 this->emitConstUint32(0, E);
2623 this->emitInitElemUint32(I, E);
2625 llvm_unreachable(
"unsupported character width");
2632template <
class Emitter>
2636 return this->emitDummyPtr(E, E);
2639template <
class Emitter>
2641 auto &A =
Ctx.getASTContext();
2650template <
class Emitter>
2658 auto &A =
Ctx.getASTContext();
2662 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2663 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2670 unsigned StringIndex =
P.createGlobalString(SL);
2671 return this->emitGetPtrGlobal(StringIndex, E);
2674template <
class Emitter>
2678 return this->emitConst(E->
getValue(), E);
2681template <
class Emitter>
2707 if (!this->emitSetLocal(*RT, TempOffset, E))
2713 if (!this->emitLoad(LHST, E))
2717 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2718 LHSComputationType, E))
2722 if (!this->emitGetLocal(*RT, TempOffset, E))
2727 if (!this->emitAddf(getFPOptions(E), E))
2731 if (!this->emitSubf(getFPOptions(E), E))
2735 if (!this->emitMulf(getFPOptions(E), E))
2739 if (!this->emitDivf(getFPOptions(E), E))
2750 return this->emitStorePop(LHST, E);
2751 return this->emitStore(LHST, E);
2754template <
class Emitter>
2763 if (Op != BO_AddAssign && Op != BO_SubAssign)
2772 if (!this->emitLoad(*
LT, LHS))
2778 if (Op == BO_AddAssign) {
2779 if (!this->emitAddOffset(*RT, E))
2782 if (!this->emitSubOffset(*RT, E))
2787 return this->emitStorePopPtr(E);
2788 return this->emitStorePtr(E);
2791template <
class Emitter>
2804 if (!
Ctx.getLangOpts().CPlusPlus14)
2805 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2807 if (!
LT || !RT || !ResultT || !LHSComputationT)
2832 if (!this->emitSetLocal(*RT, TempOffset, E))
2839 if (!this->emitLoad(*
LT, E))
2841 if (
LT != LHSComputationT &&
2847 if (!this->emitGetLocal(*RT, TempOffset, E))
2853 if (!this->emitAdd(*LHSComputationT, E))
2857 if (!this->emitSub(*LHSComputationT, E))
2861 if (!this->emitMul(*LHSComputationT, E))
2865 if (!this->emitDiv(*LHSComputationT, E))
2869 if (!this->emitRem(*LHSComputationT, E))
2873 if (!this->emitShl(*LHSComputationT, *RT, E))
2877 if (!this->emitShr(*LHSComputationT, *RT, E))
2881 if (!this->emitBitAnd(*LHSComputationT, E))
2885 if (!this->emitBitXor(*LHSComputationT, E))
2889 if (!this->emitBitOr(*LHSComputationT, E))
2893 llvm_unreachable(
"Unimplemented compound assign operator");
2897 if (ResultT != LHSComputationT &&
2898 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
2904 return this->emitStoreBitFieldPop(*ResultT, E);
2905 return this->emitStorePop(*ResultT, E);
2908 return this->emitStoreBitField(*ResultT, E);
2909 return this->emitStore(*ResultT, E);
2912template <
class Emitter>
2920template <
class Emitter>
2932 return this->
discard(SubExpr);
2947 if (!this->
visit(SubExpr))
2949 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2951 return this->emitGetPtrGlobal(*GlobalIndex, E);
2954 if (!this->checkLiteralType(SubExpr))
2957 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2961 return this->emitInitGlobalTempComp(TempDecl, E);
2972 unsigned LocalIndex =
2974 if (!this->VarScope->LocalsAlwaysEnabled &&
2975 !this->emitEnableLocal(LocalIndex, E))
2978 if (!this->
visit(SubExpr))
2980 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2983 return this->emitGetPtrLocal(LocalIndex, E);
2986 if (!this->checkLiteralType(SubExpr))
2994 if (!this->VarScope->LocalsAlwaysEnabled &&
2995 !this->emitEnableLocal(*LocalIndex, E))
2998 if (!this->emitGetPtrLocal(*LocalIndex, E))
3005template <
class Emitter>
3016 if (!this->
visit(SubExpr))
3020 return this->emitPopPtr(E);
3024template <
class Emitter>
3045 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3050 if (
P.isGlobalInitialized(*GlobalIndex))
3056 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3068 unsigned LocalIndex;
3072 LocalIndex = *MaybeIndex;
3076 if (!this->emitGetPtrLocal(LocalIndex, E))
3080 return this->
visit(
Init) && this->emitInit(*
T, E);
3084template <
class Emitter>
3097template <
class Emitter>
3101 return this->emitConst(E->
getValue(), E);
3104template <
class Emitter>
3117 for (
const Record::Field &F : R->
fields()) {
3119 if (!
Init ||
Init->containsErrors())
3127 if (!this->emitInitField(*
T, F.Offset, E))
3130 if (!this->emitGetPtrField(F.Offset, E))
3136 if (!this->emitPopPtr(E))
3144template <
class Emitter>
3151 return this->emitGetPtrGlobal(StringIndex, E);
3157template <
class Emitter>
3162 return this->emitInvalid(E);
3165template <
class Emitter>
3191 if (PointeeToT && PointeeFromT) {
3207 bool Fatal = (ToT != FromT);
3214template <
class Emitter>
3217 if (!
Ctx.getLangOpts().CPlusPlus20) {
3225template <
class Emitter>
3231 return this->emitConstBool(E->
getValue(), E);
3234template <
class Emitter>
3239 if (
T->isRecordType()) {
3253 if (!this->emitGetPtrLocal(*LocalIndex, E))
3261 T->getAsCXXRecordDecl()))
3271 if (!this->visitZeroRecordInitializer(R, E))
3283 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3285 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3286 if (!this->emitCheckFunctionDecl(Ctor, E))
3297 assert(
Func->hasThisPointer());
3298 assert(!
Func->hasRVO());
3302 if (!this->emitDupPtr(E))
3306 for (
const auto *Arg : E->
arguments()) {
3307 if (!this->
visit(Arg))
3311 if (
Func->isVariadic()) {
3312 uint32_t VarArgSize = 0;
3313 unsigned NumParams =
Func->getNumWrittenParams();
3314 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3318 if (!this->emitCallVar(
Func, VarArgSize, E))
3321 if (!this->emitCall(
Func, 0, E)) {
3326 (void)this->emitPopPtr(E);
3332 return this->emitPopPtr(E);
3333 return this->emitFinishInit(E);
3336 if (
T->isArrayType()) {
3341 if (!this->emitDupPtr(E))
3345 initArrayDimension = [&](
QualType T) ->
bool {
3346 if (!
T->isArrayType()) {
3348 for (
const auto *Arg : E->
arguments()) {
3349 if (!this->
visit(Arg))
3353 return this->emitCall(
Func, 0, E);
3357 Ctx.getASTContext().getAsConstantArrayType(
T);
3362 for (
size_t I = 0; I != NumElems; ++I) {
3363 if (!this->emitConstUint64(I, E))
3365 if (!this->emitArrayElemPtrUint64(E))
3367 if (!initArrayDimension(ElemTy))
3370 return this->emitPopPtr(E);
3373 return initArrayDimension(E->
getType());
3379template <
class Emitter>
3389 assert(Val.
isInt());
3391 return this->emitConst(I, E);
3398 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3399 return this->
visit(LValueExpr);
3414 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3418 const APValue &
V = UGCD->getValue();
3419 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3420 const Record::Field *F = R->
getField(I);
3421 const APValue &FieldValue =
V.getStructField(I);
3427 if (!this->emitInitField(FieldT, F->Offset, E))
3435template <
class Emitter>
3441 for (
unsigned I = 0; I != N; ++I) {
3448 if (!this->
discard(ArrayIndexExpr))
3453 if (!this->
visit(ArrayIndexExpr))
3457 if (!this->emitCast(IndexT,
PT_Sint64, E))
3467 return this->emitOffsetOf(
T, E, E);
3470template <
class Emitter>
3479 return this->visitZeroInitializer(*
T, Ty, E);
3486 if (!this->emitGetPtrLocal(*LocalIndex, E))
3491 QualType ElemQT = CT->getElementType();
3494 for (
unsigned I = 0; I != 2; ++I) {
3495 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3497 if (!this->emitInitElem(ElemT, I, E))
3509 if (!this->emitGetPtrLocal(*LocalIndex, E))
3514 QualType ElemQT = VT->getElementType();
3517 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3518 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3520 if (!this->emitInitElem(ElemT, I, E))
3529template <
class Emitter>
3534template <
class Emitter>
3540template <
class Emitter>
3545template <
class Emitter>
3550 return this->emitConst(E->
getValue(), E);
3553template <
class Emitter>
3558 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3576 if (!this->emitGetParam(PT, Offset, E))
3581 return this->emitCall(F, 0, E);
3586template <
class Emitter>
3594 const Expr *PlacementDest =
nullptr;
3595 bool IsNoThrow =
false;
3597 if (PlacementArgs != 0) {
3606 if (PlacementArgs == 1) {
3614 if (!this->emitInvalidNewDeleteExpr(E, E))
3619 if (OperatorNew->isReservedGlobalPlacementOperator())
3620 PlacementDest = Arg1;
3624 return this->emitInvalid(E);
3626 }
else if (!OperatorNew
3627 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3628 return this->emitInvalidNewDeleteExpr(E, E);
3631 if (!PlacementDest) {
3636 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3639 Desc =
P.createDescriptor(
3642 false,
false,
false,
3648 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3652 const Expr *Stripped = *ArraySizeExpr;
3653 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3654 Stripped = ICE->getSubExpr())
3655 if (ICE->getCastKind() != CK_NoOp &&
3656 ICE->getCastKind() != CK_IntegralCast)
3664 if (!this->
visit(Stripped))
3666 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3669 if (PlacementDest) {
3670 if (!this->
visit(PlacementDest))
3672 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3674 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3677 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3682 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3686 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3693 size_t StaticInitElems = 0;
3694 const Expr *DynamicInit =
nullptr;
3698 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3699 StaticInitElems = CAT->getZExtSize();
3704 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
3705 if (ILE->hasArrayFiller())
3706 DynamicInit = ILE->getArrayFiller();
3725 const Function *CtorFunc =
nullptr;
3726 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3730 }
else if (!DynamicInit && !ElemT)
3733 LabelTy EndLabel = this->getLabel();
3734 LabelTy StartLabel = this->getLabel();
3739 if (!this->emitDupPtr(E))
3741 if (!this->emitNullPtr(0,
nullptr, E))
3743 if (!this->emitEQPtr(E))
3745 if (!this->jumpTrue(EndLabel))
3752 if (!this->emitConst(StaticInitElems,
SizeT, E))
3754 if (!this->emitSetLocal(
SizeT, Iter, E))
3757 this->fallthrough(StartLabel);
3758 this->emitLabel(StartLabel);
3760 if (!this->emitGetLocal(
SizeT, Iter, E))
3762 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3764 if (!this->emitLT(
SizeT, E))
3766 if (!this->jumpFalse(EndLabel))
3770 if (!this->emitGetLocal(
SizeT, Iter, E))
3772 if (!this->emitArrayElemPtr(
SizeT, E))
3775 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3780 if (!this->visitZeroInitializer(InitT, ElemType, E))
3782 if (!this->emitStorePop(InitT, E))
3784 }
else if (DynamicInit) {
3786 if (!this->
visit(DynamicInit))
3788 if (!this->emitStorePop(*InitT, E))
3793 if (!this->emitPopPtr(E))
3797 if (!this->visitZeroInitializer(
3801 if (!this->emitStorePop(*ElemT, E))
3805 if (!this->emitCall(CtorFunc, 0, E))
3810 if (!this->emitGetPtrLocal(Iter, E))
3812 if (!this->emitIncPop(
SizeT,
false, E))
3815 if (!this->jump(StartLabel))
3818 this->fallthrough(EndLabel);
3819 this->emitLabel(EndLabel);
3823 if (PlacementDest) {
3824 if (!this->
visit(PlacementDest))
3826 if (!this->emitCheckNewTypeMismatch(E, E))
3831 if (!this->emitAlloc(Desc, E))
3840 if (!this->emitInit(*ElemT, E))
3851 return this->emitPopPtr(E);
3856template <
class Emitter>
3862 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3863 return this->emitInvalidNewDeleteExpr(E, E);
3866 if (!this->
visit(Arg))
3872template <
class Emitter>
3878 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3883 return this->emitGetFnPtr(
Func, E);
3886template <
class Emitter>
3890 auto canonType = [](
const Type *
T) {
3891 return T->getCanonicalTypeUnqualified().getTypePtr();
3899 return this->emitGetTypeid(
3903 return this->emitGetTypeid(
3912 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3918 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3921 return this->emitPopPtr(E);
3925template <
class Emitter>
3927 assert(
Ctx.getLangOpts().CPlusPlus);
3928 return this->emitConstBool(E->
getValue(), E);
3931template <
class Emitter>
3943 return this->emitDummyPtr(GuidDecl, E);
3948 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3957 assert(
V.isStruct());
3958 assert(
V.getStructNumBases() == 0);
3962 return this->emitFinishInit(E);
3965template <
class Emitter>
3975template <
class Emitter>
3984template <
class Emitter>
3990template <
class Emitter>
3994 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
3998 if (OVE->isUnique())
4014template <
class Emitter>
4019template <
class Emitter>
4021 return this->emitError(E);
4024template <
class Emitter>
4030 return this->emitDummyPtr(E, E);
4033template <
class Emitter>
4037 QualType ElemType = VT->getElementType();
4041 PrimType SrcElemT = classifyVectorElementType(SrcType);
4043 unsigned SrcOffset =
4045 if (!this->
visit(Src))
4047 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4050 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4051 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4053 if (!this->emitArrayElemPop(SrcElemT, I, E))
4057 if (SrcElemT != ElemT) {
4058 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4060 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4061 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
4065 if (!this->emitInitElem(ElemT, I, E))
4072template <
class Emitter>
4076 return this->emitInvalid(E);
4086 assert(NumOutputElems > 0);
4089 unsigned VectorOffsets[2];
4090 for (
unsigned I = 0; I != 2; ++I) {
4093 if (!this->
visit(Vecs[I]))
4095 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4098 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4100 assert(ShuffleIndex >= -1);
4101 if (ShuffleIndex == -1)
4102 return this->emitInvalidShuffleVectorIndex(I, E);
4104 assert(ShuffleIndex < (NumInputElems * 2));
4105 if (!this->emitGetLocal(
PT_Ptr,
4106 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4108 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4109 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4112 if (!this->emitInitElem(ElemT, I, E))
4119template <
class Emitter>
4124 Base->getType()->isVectorType() ||
4130 if (Indices.size() == 1) {
4135 if (!this->emitConstUint32(Indices[0], E))
4137 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4147 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4155 if (!this->emitGetPtrLocal(*ResultIndex, E))
4163 uint32_t DstIndex = 0;
4164 for (uint32_t I : Indices) {
4165 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4167 if (!this->emitArrayElemPop(ElemT, I, E))
4169 if (!this->emitInitElem(ElemT, DstIndex, E))
4179template <
class Emitter>
4183 return this->
discard(SubExpr) && this->emitInvalid(E);
4189 return this->emitDummyPtr(E, E);
4192template <
class Emitter>
4197 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4202 if (!this->
visit(SubExpr))
4204 if (!this->emitConstUint8(0, E))
4206 if (!this->emitArrayElemPtrPopUint8(E))
4213 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4215 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4217 assert(SecondFieldT ==
PT_Ptr);
4221 if (!this->emitExpandPtr(E))
4225 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4230template <
class Emitter>
4245 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4247 return this->emitUnsupported(E);
4256 return this->
Visit(E);
4263 return this->
Visit(E);
4267 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4270 if (
const auto *CE = dyn_cast<CastExpr>(E);
4272 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4279 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4282 if (
const auto *CE = dyn_cast<CastExpr>(E);
4283 CE && (CE->getCastKind() == CK_DerivedToBase ||
4284 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4285 CE->getCastKind() == CK_NoOp))
4305 if (!this->emitGetPtrLocal(*LocalIndex, E))
4315 return this->
Visit(E);
4318template <
class Emitter>
4324 return this->
Visit(E);
4330 return this->
Visit(E);
4338 if (!this->
visit(E))
4340 return this->emitComplexBoolCast(E);
4345 if (!this->
visit(E))
4353 return this->emitIsNonNullPtr(E);
4357 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4360 return this->emitCast(*
T,
PT_Bool, E);
4363template <
class Emitter>
4367 QT = AT->getValueType();
4371 return this->emitZeroBool(E);
4373 return this->emitZeroSint8(E);
4375 return this->emitZeroUint8(E);
4377 return this->emitZeroSint16(E);
4379 return this->emitZeroUint16(E);
4381 return this->emitZeroSint32(E);
4383 return this->emitZeroUint32(E);
4385 return this->emitZeroSint64(E);
4387 return this->emitZeroUint64(E);
4389 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4391 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4393 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4396 return this->emitNullMemberPtr(0,
nullptr, E);
4398 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4399 return this->emitFloat(F, E);
4402 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4406 llvm_unreachable(
"unknown primitive type");
4409template <
class Emitter>
4410bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4415 for (
const Record::Field &Field : R->
fields()) {
4416 if (Field.isUnnamedBitField())
4423 if (!this->visitZeroInitializer(
T, QT, E))
4426 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4430 if (!this->emitInitField(
T, Field.Offset, E))
4435 if (!this->emitGetPtrField(Field.Offset, E))
4441 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4442 if (!this->visitZeroInitializer(
T, ET, E))
4444 if (!this->emitInitElem(
T, I, E))
4449 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4452 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4460 if (!this->emitFinishInitActivatePop(E))
4464 if (!this->emitFinishInitPop(E))
4468 for (
const Record::Base &B : R->
bases()) {
4469 if (!this->emitGetPtrBase(B.Offset, E))
4471 if (!this->visitZeroRecordInitializer(B.R, E))
4473 if (!this->emitFinishInitPop(E))
4482template <
class Emitter>
4483bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4484 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4485 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4490 for (
size_t I = 0; I != NumElems; ++I) {
4491 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4493 if (!this->emitInitElem(*ElemT, I, E))
4499 const Record *R = getRecord(ElemType);
4501 for (
size_t I = 0; I != NumElems; ++I) {
4502 if (!this->emitConstUint32(I, E))
4504 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4506 if (!this->visitZeroRecordInitializer(R, E))
4508 if (!this->emitPopPtr(E))
4514 for (
size_t I = 0; I != NumElems; ++I) {
4515 if (!this->emitConstUint32(I, E))
4517 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4519 if (!this->visitZeroArrayInitializer(ElemType, E))
4521 if (!this->emitPopPtr(E))
4530template <
class Emitter>
4531bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4533 if (!canClassify(E->
getType()))
4536 if (!this->visit(RHS))
4538 if (!this->visit(LHS))
4545 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4549 bool Activates = refersToUnion(LHS);
4552 if (!this->emitFlip(
PT_Ptr, RHT, E))
4555 if (DiscardResult) {
4556 if (BitField && Activates)
4557 return this->emitStoreBitFieldActivatePop(RHT, E);
4559 return this->emitStoreBitFieldPop(RHT, E);
4561 return this->emitStoreActivatePop(RHT, E);
4563 return this->emitStorePop(RHT, E);
4566 auto maybeLoad = [&](
bool Result) ->
bool {
4572 return this->emitLoadPop(RHT, E);
4576 if (BitField && Activates)
4577 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4579 return maybeLoad(this->emitStoreBitField(RHT, E));
4581 return maybeLoad(this->emitStoreActivate(RHT, E));
4583 return maybeLoad(this->emitStore(RHT, E));
4586template <
class Emitter>
4587template <
typename T>
4591 return this->emitConstSint8(
Value, E);
4593 return this->emitConstUint8(
Value, E);
4595 return this->emitConstSint16(
Value, E);
4597 return this->emitConstUint16(
Value, E);
4599 return this->emitConstSint32(
Value, E);
4601 return this->emitConstUint32(
Value, E);
4603 return this->emitConstSint64(
Value, E);
4605 return this->emitConstUint64(
Value, E);
4607 return this->emitConstBool(
Value, E);
4614 llvm_unreachable(
"Invalid integral type");
4617 llvm_unreachable(
"unknown primitive type");
4620template <
class Emitter>
4621template <
typename T>
4622bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4623 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4626template <
class Emitter>
4630 return this->emitConstIntAPS(
Value, E);
4632 return this->emitConstIntAP(
Value, E);
4634 if (
Value.isSigned())
4635 return this->emitConst(
Value.getSExtValue(), Ty, E);
4636 return this->emitConst(
Value.getZExtValue(), Ty, E);
4639template <
class Emitter>
4643 return this->emitConstIntAPS(
Value, E);
4645 return this->emitConstIntAP(
Value, E);
4648 return this->emitConst(
Value.getSExtValue(), Ty, E);
4649 return this->emitConst(
Value.getZExtValue(), Ty, E);
4652template <
class Emitter>
4653bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4654 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4657template <
class Emitter>
4662 bool IsConstexprUnknown) {
4671 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4672 Locals.insert({VD, Local});
4673 VarScope->addForScopeKind(Local, SC);
4674 return Local.Offset;
4677template <
class Emitter>
4680 bool IsConstexprUnknown) {
4683 bool IsTemporary =
false;
4684 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4687 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4688 Init = VarD->getInit();
4690 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4701 return std::nullopt;
4706 Locals.insert({Key, Local});
4707 VarScope->addForScopeKind(Local, SC);
4708 return Local.Offset;
4711template <
class Emitter>
4721 return std::nullopt;
4731 return Local.Offset;
4734template <
class Emitter>
4736 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
4737 return PT->getPointeeType()->getAsCanonical<RecordType>();
4743 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
4747template <
class Emitter>
4749 return P.getOrCreateRecord(RD);
4752template <
class Emitter>
4754 return Ctx.getOrCreateFunction(FD);
4757template <
class Emitter>
4762 if (!DestroyToplevelScope) {
4763 if (!this->emitCheckAllocations(E))
4767 auto maybeDestroyLocals = [&]() ->
bool {
4768 if (DestroyToplevelScope)
4769 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
4770 return this->emitCheckAllocations(E);
4777 return this->emitRetVoid(E) && maybeDestroyLocals();
4785 return this->emitRet(*
T, E) && maybeDestroyLocals();
4793 if (!this->emitGetPtrLocal(*LocalOffset, E))
4799 if (!this->emitFinishInit(E))
4804 return this->emitRetValue(E) && maybeDestroyLocals();
4807 return maybeDestroyLocals() && this->emitCheckAllocations(E) &&
false;
4810template <
class Emitter>
4812 bool IsConstexprUnknown) {
4815 IsConstexprUnknown);
4824 if (
auto GlobalIndex =
P.getGlobal(VD)) {
4825 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4839template <
class Emitter>
4841 bool ConstantContext) {
4844 if (!ConstantContext) {
4858 auto GlobalIndex =
P.getGlobal(VD);
4859 assert(GlobalIndex);
4861 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
4864 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
4868 auto Local =
Locals.find(VD);
4869 assert(Local !=
Locals.end());
4871 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
4874 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
4884 auto GlobalIndex =
P.getGlobal(VD);
4885 assert(GlobalIndex);
4886 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4895 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
4898template <
class Emitter>
4901 bool Toplevel,
bool IsConstexprUnknown) {
4908 if (!this->isActive())
4913 if (
Init &&
Init->isValueDependent())
4917 auto checkDecl = [&]() ->
bool {
4919 return !NeedsOp || this->emitCheckDecl(VD, VD);
4927 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
4930 if (
P.isGlobalInitialized(*GlobalIndex))
4934 }
else if ((GlobalIndex =
P.createGlobal(VD,
Init))) {
4948 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
4951 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
4957 return this->emitFinishInitGlobal(
Init);
4966 IsConstexprUnknown);
4977 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
4981 return this->emitSetLocal(*VarT, Offset, VD);
4989 if (!this->emitGetPtrLocal(*Offset,
Init))
4995 return this->emitFinishInitPop(
Init);
5000template <
class Emitter>
5005 return this->emitConst(Val.
getInt(), ValType, E);
5008 return this->emitFloat(F, E);
5013 return this->emitNull(ValType, 0,
nullptr, E);
5015 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5016 return this->
visit(BaseExpr);
5021 return this->emitGetMemberPtr(MemberDecl, E);
5022 return this->emitNullMemberPtr(0,
nullptr, E);
5028template <
class Emitter>
5036 const Record::Field *RF = R->
getField(I);
5037 QualType FieldType = RF->Decl->getType();
5042 if (!this->emitInitField(*PT, RF->Offset, E))
5045 if (!this->emitGetPtrField(RF->Offset, E))
5049 if (!this->emitPopPtr(E))
5060 const Record::Field *RF = R->
getField(UnionField);
5064 return this->emitInitField(
T, RF->Offset, E);
5067 const auto *ArrType =
T->getAsArrayTypeUnsafe();
5068 QualType ElemType = ArrType->getElementType();
5069 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5074 if (!this->emitInitElem(*ElemT, A, E))
5077 if (!this->emitConstUint32(A, E))
5079 if (!this->emitArrayElemPtrUint32(E))
5083 if (!this->emitPopPtr(E))
5094template <
class Emitter>
5096 unsigned BuiltinID) {
5097 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5102 return this->emitConst(0, E);
5105 if (!this->emitStartSpeculation(E))
5107 LabelTy EndLabel = this->getLabel();
5108 if (!this->speculate(E, EndLabel))
5110 this->fallthrough(EndLabel);
5111 if (!this->emitEndSpeculation(E))
5120 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5121 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5122 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5123 BuiltinID == Builtin::BI__builtin_function_start) {
5126 return this->emitDummyPtr(E, E);
5137 if (!this->emitGetPtrLocal(*LocalIndex, E))
5142 switch (BuiltinID) {
5143 case Builtin::BI__builtin_object_size:
5144 case Builtin::BI__builtin_dynamic_object_size: {
5148 if (!this->
visit(Arg0))
5159 case Builtin::BI__assume:
5160 case Builtin::BI__builtin_assume:
5166 for (
const auto *Arg : E->
arguments()) {
5167 if (!this->
visit(Arg))
5173 if (!this->emitCallBI(E, BuiltinID, E))
5178 return this->emitPop(*ReturnT, E);
5184template <
class Emitter>
5201 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5202 DD && DD->isTrivial()) {
5204 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5206 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5207 this->emitPopPtr(E);
5223 if (!this->emitGetPtrLocal(*LocalIndex, E))
5231 if (!this->emitGetPtrLocal(*LocalIndex, E))
5235 if (!this->emitDupPtr(E))
5242 bool IsAssignmentOperatorCall =
false;
5243 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5244 OCE && OCE->isAssignmentOp()) {
5248 assert(Args.size() == 2);
5249 IsAssignmentOperatorCall =
true;
5250 std::reverse(Args.begin(), Args.end());
5256 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5257 MD && MD->isStatic()) {
5261 Args.erase(Args.begin());
5265 bool Devirtualized =
false;
5268 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5276 if (!this->
visit(Callee))
5278 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5280 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5282 if (!this->emitGetMemberPtrBase(E))
5285 const auto *InstancePtr = MC->getImplicitObjectArgument();
5292 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5293 Devirtualized =
true;
5294 if (!this->
visit(Stripped))
5297 if (!this->
visit(InstancePtr))
5301 if (!this->
visit(InstancePtr))
5305 }
else if (
const auto *PD =
5306 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5307 if (!this->emitCheckPseudoDtor(E))
5315 return this->emitEndLifetimePop(E);
5316 }
else if (!FuncDecl) {
5320 if (!this->
visit(Callee))
5322 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5326 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5331 if (IsAssignmentOperatorCall) {
5332 assert(Args.size() == 2);
5335 if (!this->emitFlip(Arg2T, Arg1T, E))
5349 assert(HasRVO ==
Func->hasRVO());
5351 bool HasQualifier =
false;
5352 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5353 HasQualifier = ME->hasQualifier();
5355 bool IsVirtual =
false;
5356 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5357 IsVirtual = !Devirtualized && MD->isVirtual();
5362 if (IsVirtual && !HasQualifier) {
5363 uint32_t VarArgSize = 0;
5364 unsigned NumParams =
5366 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5369 if (!this->emitCallVirt(
Func, VarArgSize, E))
5371 }
else if (
Func->isVariadic()) {
5372 uint32_t VarArgSize = 0;
5373 unsigned NumParams =
5375 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5377 if (!this->emitCallVar(
Func, VarArgSize, E))
5380 if (!this->emitCall(
Func, 0, E))
5389 uint32_t ArgSize = 0;
5390 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5396 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5398 if (!this->emitGetMemberPtrDecl(E))
5401 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5404 if (!this->emitCallPtr(ArgSize, E, E))
5415template <
class Emitter>
5422template <
class Emitter>
5429template <
class Emitter>
5434 return this->emitConstBool(E->
getValue(), E);
5437template <
class Emitter>
5443 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5444 return this->emitNullPtr(Val,
nullptr, E);
5447template <
class Emitter>
5455 return this->emitZero(
T, E);
5458template <
class Emitter>
5463 if (this->LambdaThisCapture.Offset > 0) {
5464 if (this->LambdaThisCapture.IsPtr)
5465 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5466 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5474 return this->emitThis(E);
5489 unsigned StartIndex = 0;
5490 unsigned EndIndex = 0;
5492 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5494 EndIndex = StartIndex;
5501 for (; StartIndex > 0; --StartIndex) {
5511 if (StartIndex == 0 && EndIndex == 0)
5514 assert(StartIndex < EndIndex);
5517 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
5529 case Stmt::CompoundStmtClass:
5531 case Stmt::DeclStmtClass:
5533 case Stmt::ReturnStmtClass:
5535 case Stmt::IfStmtClass:
5537 case Stmt::WhileStmtClass:
5539 case Stmt::DoStmtClass:
5541 case Stmt::ForStmtClass:
5543 case Stmt::CXXForRangeStmtClass:
5545 case Stmt::BreakStmtClass:
5547 case Stmt::ContinueStmtClass:
5549 case Stmt::SwitchStmtClass:
5551 case Stmt::CaseStmtClass:
5553 case Stmt::DefaultStmtClass:
5555 case Stmt::AttributedStmtClass:
5557 case Stmt::CXXTryStmtClass:
5559 case Stmt::NullStmtClass:
5562 case Stmt::GCCAsmStmtClass:
5563 case Stmt::MSAsmStmtClass:
5564 case Stmt::GotoStmtClass:
5565 return this->emitInvalid(S);
5566 case Stmt::LabelStmtClass:
5569 if (
const auto *E = dyn_cast<Expr>(S))
5576template <
class Emitter>
5579 for (
const auto *InnerStmt : S->
body())
5582 return Scope.destroyLocals();
5585template <
class Emitter>
5586bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5587 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5588 for (
auto *BD : DD->flat_bindings())
5589 if (
auto *KD = BD->getHoldingVar();
5590 KD && !this->visitVarDecl(KD, KD->getInit()))
5604template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5606 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5607 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5614 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5619 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5620 ICE && (ICE->getCastKind() == CK_NoOp ||
5621 ICE->getCastKind() == CK_DerivedToBase ||
5622 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5623 E = ICE->getSubExpr();
5627 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5628 const auto *ThisRecord =
5629 This->getType()->getPointeeType()->getAsRecordDecl();
5630 if (!ThisRecord->isUnion())
5633 if (
const auto *Ctor =
5634 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5635 return Ctor->getParent() == ThisRecord;
5644template <
class Emitter>
5646 bool EvaluateConditionDecl) {
5647 for (
const auto *D : DS->
decls()) {
5652 const auto *VD = dyn_cast<VarDecl>(D);
5659 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5666template <
class Emitter>
5669 return this->emitUnsupported(RS);
5675 if (!this->
visit(RE))
5681 if (RE->getType()->isVoidType()) {
5682 if (!this->
visit(RE))
5687 if (!this->emitRVOPtr(RE))
5691 if (!this->emitPopPtr(RE))
5695 return this->emitRetVoid(RS);
5701 return this->emitRetVoid(RS);
5707 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5714 if (
auto *CondInit = IS->
getInit()) {
5730 return visitChildStmt(IS->
getThen());
5732 return visitChildStmt(Else);
5738 if (!this->emitIsConstantContext(IS))
5741 if (!this->emitIsConstantContext(IS))
5743 if (!this->emitInv(IS))
5757 LabelTy LabelElse = this->getLabel();
5758 LabelTy LabelEnd = this->getLabel();
5759 if (!this->jumpFalse(LabelElse))
5761 if (!visitChildStmt(IS->
getThen()))
5763 if (!this->jump(LabelEnd))
5765 this->emitLabel(LabelElse);
5766 if (!visitChildStmt(Else))
5768 this->emitLabel(LabelEnd);
5770 LabelTy LabelEnd = this->getLabel();
5771 if (!this->jumpFalse(LabelEnd))
5773 if (!visitChildStmt(IS->
getThen()))
5775 this->emitLabel(LabelEnd);
5784template <
class Emitter>
5789 LabelTy CondLabel = this->getLabel();
5790 LabelTy EndLabel = this->getLabel();
5794 this->fallthrough(CondLabel);
5795 this->emitLabel(CondLabel);
5809 if (!this->jumpFalse(EndLabel))
5818 if (!this->jump(CondLabel))
5820 this->fallthrough(EndLabel);
5821 this->emitLabel(EndLabel);
5829 LabelTy StartLabel = this->getLabel();
5830 LabelTy EndLabel = this->getLabel();
5831 LabelTy CondLabel = this->getLabel();
5835 this->fallthrough(StartLabel);
5836 this->emitLabel(StartLabel);
5842 this->fallthrough(CondLabel);
5843 this->emitLabel(CondLabel);
5850 if (!this->jumpTrue(StartLabel))
5853 this->fallthrough(EndLabel);
5854 this->emitLabel(EndLabel);
5858template <
class Emitter>
5866 LabelTy EndLabel = this->getLabel();
5867 LabelTy CondLabel = this->getLabel();
5868 LabelTy IncLabel = this->getLabel();
5875 this->fallthrough(CondLabel);
5876 this->emitLabel(CondLabel);
5888 if (!this->jumpFalse(EndLabel))
5897 this->fallthrough(IncLabel);
5898 this->emitLabel(IncLabel);
5904 if (!this->jump(CondLabel))
5908 this->emitLabel(EndLabel);
5914template <
class Emitter>
5924 LabelTy EndLabel = this->getLabel();
5925 LabelTy CondLabel = this->getLabel();
5926 LabelTy IncLabel = this->getLabel();
5941 this->fallthrough(CondLabel);
5942 this->emitLabel(CondLabel);
5945 if (!this->jumpFalse(EndLabel))
5956 this->fallthrough(IncLabel);
5957 this->emitLabel(IncLabel);
5962 if (!this->jump(CondLabel))
5965 this->fallthrough(EndLabel);
5966 this->emitLabel(EndLabel);
5970template <
class Emitter>
5981 if (LI.BreakLabel) {
5982 TargetLabel = *LI.BreakLabel;
5983 BreakScope = LI.BreakOrContinueScope;
5989 if (LI.Name == TargetLoop) {
5990 TargetLabel = *LI.BreakLabel;
5991 BreakScope = LI.BreakOrContinueScope;
5997 assert(TargetLabel);
6000 C =
C->getParent()) {
6001 if (!
C->destroyLocals())
6005 return this->jump(*TargetLabel);
6008template <
class Emitter>
6019 if (LI.ContinueLabel) {
6020 TargetLabel = *LI.ContinueLabel;
6021 ContinueScope = LI.BreakOrContinueScope;
6027 if (LI.Name == TargetLoop) {
6028 TargetLabel = *LI.ContinueLabel;
6029 ContinueScope = LI.BreakOrContinueScope;
6034 assert(TargetLabel);
6037 C =
C->getParent()) {
6038 if (!
C->destroyLocals())
6042 return this->jump(*TargetLabel);
6045template <
class Emitter>
6048 if (
Cond->containsErrors())
6054 LabelTy EndLabel = this->getLabel();
6059 if (
const auto *CondInit = S->
getInit())
6070 if (!this->emitSetLocal(CondT, CondVar, S))
6080 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6083 if (CS->caseStmtIsGNURange()) {
6084 LabelTy EndOfRangeCheck = this->getLabel();
6085 const Expr *Low = CS->getLHS();
6086 const Expr *High = CS->getRHS();
6090 if (!this->emitGetLocal(CondT, CondVar, CS))
6092 if (!this->
visit(Low))
6095 if (!this->emitGE(
LT, S))
6097 if (!this->jumpFalse(EndOfRangeCheck))
6100 if (!this->emitGetLocal(CondT, CondVar, CS))
6102 if (!this->
visit(High))
6105 if (!this->emitLE(HT, S))
6109 this->emitLabel(EndOfRangeCheck);
6114 if (
Value->isValueDependent())
6119 if (!this->emitGetLocal(CondT, CondVar, CS))
6125 if (!this->emitEQ(ValueT, S))
6130 assert(!DefaultLabel);
6131 DefaultLabel = this->getLabel();
6138 if (!this->jump(*DefaultLabel))
6141 if (!this->jump(EndLabel))
6149 this->fallthrough(EndLabel);
6150 this->emitLabel(EndLabel);
6155template <
class Emitter>
6162template <
class Emitter>
6169 if (LI.DefaultLabel) {
6170 DefaultLabel = *LI.DefaultLabel;
6175 this->emitLabel(DefaultLabel);
6179template <
class Emitter>
6181 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6182 !this->Ctx.getLangOpts().MSVCCompat) {
6184 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6190 const Expr *Assumption = AA->getAssumption();
6201 if (!this->emitAssume(Assumption))
6210template <
class Emitter>
6216template <
class Emitter>
6217bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6224 assert(ClosureClass->
captures().empty());
6228 "A generic lambda's static-invoker function must be a "
6229 "template specialization");
6233 void *InsertPos =
nullptr;
6234 const FunctionDecl *CorrespondingCallOpSpecialization =
6236 assert(CorrespondingCallOpSpecialization);
6237 LambdaCallOp = CorrespondingCallOpSpecialization;
6241 assert(ClosureClass->
captures().empty());
6242 const Function *
Func = this->getFunction(LambdaCallOp);
6245 assert(
Func->hasThisPointer());
6248 if (
Func->hasRVO()) {
6249 if (!this->emitRVOPtr(MD))
6257 if (!this->emitNullPtr(0,
nullptr, MD))
6262 auto It = this->Params.find(PVD);
6263 assert(It != this->Params.end());
6267 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6268 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6272 if (!this->emitCall(
Func, 0, LambdaCallOp))
6277 return this->emitRet(*ReturnType, MD);
6280 return this->emitRetVoid(MD);
6283template <
class Emitter>
6284bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6285 if (Ctx.getLangOpts().CPlusPlus23)
6295 const Expr *InitExpr =
Init->getInit();
6297 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6301 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6311template <
class Emitter>
6313 assert(!ReturnType);
6315 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6316 const Expr *InitExpr,
6319 if (InitExpr->getType().isNull())
6323 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6326 if (!this->visit(InitExpr))
6329 bool BitField = F->isBitField();
6331 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6332 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6337 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6340 if (
Activate && !this->emitActivate(InitExpr))
6343 if (!this->visitInitializer(InitExpr))
6346 return this->emitFinishInitPop(InitExpr);
6350 const Record *R = this->getRecord(RD);
6359 return this->emitRetVoid(Ctor);
6362 if (!this->emitThis(Ctor))
6371 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6372 this->emitRetVoid(Ctor);
6376 for (
const auto *
Init : Ctor->
inits()) {
6380 const Expr *InitExpr =
Init->getInit();
6386 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6389 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6392 if (
Init->isBaseVirtual()) {
6394 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6400 const Record::Base *B = R->
getBase(BaseDecl);
6402 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6406 if (IsUnion && !this->emitActivate(InitExpr))
6409 if (!this->visitInitializer(InitExpr))
6411 if (!this->emitFinishInitPop(InitExpr))
6416 assert(IFD->getChainingSize() >= 2);
6418 unsigned NestedFieldOffset = 0;
6419 const Record::Field *NestedField =
nullptr;
6420 for (
const NamedDecl *ND : IFD->chain()) {
6422 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6423 assert(FieldRecord);
6425 NestedField = FieldRecord->
getField(FD);
6426 assert(NestedField);
6427 IsUnion = IsUnion || FieldRecord->
isUnion();
6429 NestedFieldOffset += NestedField->Offset;
6431 assert(NestedField);
6433 unsigned FirstLinkOffset =
6437 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6442 unsigned InitFieldOffset = 0;
6443 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6445 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6446 assert(FieldRecord);
6447 NestedField = FieldRecord->
getField(FD);
6448 InitFieldOffset += NestedField->Offset;
6449 assert(NestedField);
6450 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6452 if (!this->emitFinishInitPop(InitExpr))
6457 assert(
Init->isDelegatingInitializer());
6458 if (!this->emitThis(InitExpr))
6460 if (!this->visitInitializer(
Init->getInit()))
6462 if (!this->emitPopPtr(InitExpr))
6466 if (!
Scope.destroyLocals())
6470 if (
const auto *Body = Ctor->
getBody())
6471 if (!visitStmt(Body))
6477template <
class Emitter>
6480 const Record *R = this->getRecord(RD);
6485 if (!this->visitStmt(Dtor->
getBody()))
6489 if (!this->emitThis(Dtor))
6492 if (!this->emitCheckDestruction(Dtor))
6500 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6504 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6506 if (!this->emitDestructionPop(D,
SourceInfo{}))
6511 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6512 if (
Base.R->hasTrivialDtor())
6516 if (!this->emitRecordDestructionPop(
Base.R, {}))
6521 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6524template <
class Emitter>
6525bool Compiler<Emitter>::compileUnionAssignmentOperator(
6527 if (!this->emitThis(MD))
6536 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6539template <
class Emitter>
6546 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6547 return this->compileConstructor(Ctor);
6548 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6549 return this->compileDestructor(Dtor);
6552 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6557 return this->compileUnionAssignmentOperator(MD);
6560 return this->emitLambdaStaticInvokerBody(MD);
6564 if (
const auto *Body = F->
getBody())
6578 return FD->getBitWidthValue();
6581template <
class Emitter>
6594 if (!
Ctx.getLangOpts().CPlusPlus14)
6595 return this->emitInvalid(E);
6597 return this->emitError(E);
6599 if (!this->
visit(SubExpr))
6603 if (!this->emitIncPtr(E))
6610 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6611 : this->emitIncf(getFPOptions(E), E);
6623 if (!
Ctx.getLangOpts().CPlusPlus14)
6624 return this->emitInvalid(E);
6626 return this->emitError(E);
6628 if (!this->
visit(SubExpr))
6632 if (!this->emitDecPtr(E))
6639 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6640 : this->emitDecf(getFPOptions(E), E);
6653 if (!
Ctx.getLangOpts().CPlusPlus14)
6654 return this->emitInvalid(E);
6656 return this->emitError(E);
6658 if (!this->
visit(SubExpr))
6662 if (!this->emitLoadPtr(E))
6664 if (!this->emitConstUint8(1, E))
6666 if (!this->emitAddOffsetUint8(E))
6668 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6674 return this->emitIncfPop(getFPOptions(E), E);
6684 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6685 if (!this->emitLoadFloat(E))
6687 APFloat F(TargetSemantics, 1);
6688 if (!this->emitFloat(F, E))
6691 if (!this->emitAddf(getFPOptions(E), E))
6693 if (!this->emitStoreFloat(E))
6705 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6708 if (!
Ctx.getLangOpts().CPlusPlus14)
6709 return this->emitInvalid(E);
6711 return this->emitError(E);
6713 if (!this->
visit(SubExpr))
6717 if (!this->emitLoadPtr(E))
6719 if (!this->emitConstUint8(1, E))
6721 if (!this->emitSubOffsetUint8(E))
6723 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6729 return this->emitDecfPop(getFPOptions(E), E);
6739 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6740 if (!this->emitLoadFloat(E))
6742 APFloat F(TargetSemantics, 1);
6743 if (!this->emitFloat(F, E))
6746 if (!this->emitSubf(getFPOptions(E), E))
6748 if (!this->emitStoreFloat(E))
6760 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6764 return this->emitError(E);
6767 return this->
discard(SubExpr);
6772 if (!this->emitInv(E))
6776 return this->emitCast(
PT_Bool, ET, E);
6780 return this->emitError(E);
6782 if (!this->
visit(SubExpr))
6787 return this->emitError(E);
6789 if (!this->
visit(SubExpr))
6802 return this->
discard(SubExpr);
6804 if (!this->
visit(SubExpr))
6811 return this->emitNarrowPtr(E);
6816 return this->emitError(E);
6818 if (!this->
visit(SubExpr))
6832 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6837 assert(
false &&
"Unhandled opcode");
6843template <
class Emitter>
6849 return this->
discard(SubExpr);
6852 auto prepareResult = [=]() ->
bool {
6857 return this->emitGetPtrLocal(*LocalIndex, E);
6864 unsigned SubExprOffset = ~0u;
6865 auto createTemp = [=, &SubExprOffset]() ->
bool {
6868 if (!this->
visit(SubExpr))
6870 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6874 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6875 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6877 return this->emitArrayElemPop(ElemT, Index, E);
6882 if (!prepareResult())
6886 for (
unsigned I = 0; I != 2; ++I) {
6887 if (!getElem(SubExprOffset, I))
6889 if (!this->emitNeg(ElemT, E))
6891 if (!this->emitInitElem(ElemT, I, E))
6902 if (!this->
visit(SubExpr))
6904 if (!this->emitComplexBoolCast(SubExpr))
6906 if (!this->emitInv(E))
6909 return this->emitCast(
PT_Bool, ET, E);
6913 return this->emitComplexReal(SubExpr);
6916 if (!this->
visit(SubExpr))
6920 if (!this->emitConstUint8(1, E))
6922 return this->emitArrayElemPtrPopUint8(E);
6930 if (!this->
visit(SubExpr))
6933 if (!this->emitArrayElem(ElemT, 1, E))
6935 if (!this->emitNeg(ElemT, E))
6937 if (!this->emitInitElem(ElemT, 1, E))
6945 return this->emitInvalid(E);
6951template <
class Emitter>
6957 return this->
discard(SubExpr);
6960 if (UnaryOp == UO_Extension)
6963 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6964 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6965 return this->emitInvalid(E);
6968 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
6975 if (!this->emitGetPtrLocal(*LocalIndex, E))
6980 unsigned SubExprOffset =
6982 if (!this->
visit(SubExpr))
6984 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
6989 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6990 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6992 return this->emitArrayElemPop(ElemT, Index, E);
6997 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6998 if (!getElem(SubExprOffset, I))
7000 if (!this->emitNeg(ElemT, E))
7002 if (!this->emitInitElem(ElemT, I, E))
7017 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7018 if (!getElem(SubExprOffset, I))
7021 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7023 if (!this->emitInv(E))
7025 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7027 if (!this->emitNeg(ElemT, E))
7029 if (ElemT != ResultVecElemT &&
7030 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7032 if (!this->emitInitElem(ResultVecElemT, I, E))
7038 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7039 if (!getElem(SubExprOffset, I))
7042 if (!this->emitInv(E))
7045 if (!this->emitComp(ElemT, E))
7048 if (!this->emitInitElem(ElemT, I, E))
7053 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7058template <
class Emitter>
7063 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7064 return this->emitConst(ECD->getInitVal(), E);
7065 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7067 return F && this->emitGetFnPtr(F, E);
7069 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7071 if (!this->emitGetPtrGlobal(*Index, E))
7076 return this->emitInitGlobal(*
T, *Index, E);
7093 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7094 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7099 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7100 if (IsReference || !It->second.IsPtr)
7101 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
7103 return this->emitGetPtrParam(It->second.Offset, E);
7106 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7112 const unsigned Offset = It->second.Offset;
7115 return this->emitGetPtrLocal(Offset, E);
7118 if (
auto GlobalIndex =
P.getGlobal(D)) {
7120 if (!
Ctx.getLangOpts().CPlusPlus11)
7121 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7122 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7125 return this->emitGetPtrGlobal(*GlobalIndex, E);
7129 auto revisit = [&](
const VarDecl *VD) ->
bool {
7132 auto VarState = this->
visitDecl(VD,
true);
7134 if (!this->emitPopCC(E))
7137 if (VarState.notCreated())
7146 if (
auto It = this->LambdaCaptures.find(D);
7147 It != this->LambdaCaptures.end()) {
7148 auto [Offset, IsPtr] = It->second;
7151 return this->emitGetThisFieldPtr(Offset, E);
7152 return this->emitGetPtrThisField(Offset, E);
7155 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7156 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7157 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7161 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7162 return this->
visit(BD->getBinding());
7166 return this->emitDummyPtr(D, E);
7171 if (!
Ctx.getLangOpts().CPlusPlus) {
7172 if (
const auto *VD = dyn_cast<VarDecl>(D);
7176 return this->emitDummyPtr(D, E);
7180 const auto *VD = dyn_cast<VarDecl>(D);
7182 return this->emitDummyPtr(D, E);
7184 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7185 if (
T.isConstant(
Ctx.getASTContext()))
7187 return T->isReferenceType();
7191 typeShouldBeVisited(VD->
getType())) {
7193 Init && !
Init->isValueDependent()) {
7199 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7217 return this->emitDummyPtr(D, E);
7223 return this->emitDummyPtr(D, E);
7226template <
class Emitter>
7234 if (!
C->destroyLocals())
7240template <
class Emitter>
7241unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7244 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7246 return Ty->getAsCXXRecordDecl();
7248 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7249 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7251 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7255template <
class Emitter>
7262 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7267 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7268 getFPOptions(E), E);
7270 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7271 getFPOptions(E), E);
7275 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7280 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7282 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7286 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7290 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7291 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7298template <
class Emitter>
7301 assert(FromT != ToT);
7304 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7306 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7308 return this->emitCast(FromT, ToT, E);
7312template <
class Emitter>
7313bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7317 return this->
discard(SubExpr);
7319 if (!this->visit(SubExpr))
7322 if (!this->emitConstUint8(0, SubExpr))
7324 return this->emitArrayElemPtrPopUint8(SubExpr);
7328 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7332template <
class Emitter>
7333bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7334 assert(!DiscardResult);
7338 if (!this->emitArrayElem(ElemT, 0, E))
7341 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7344 if (!this->emitCast(ElemT,
PT_Bool, E))
7349 LabelTy LabelTrue = this->getLabel();
7350 if (!this->jumpTrue(LabelTrue))
7353 if (!this->emitArrayElemPop(ElemT, 1, E))
7356 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7359 if (!this->emitCast(ElemT,
PT_Bool, E))
7363 LabelTy EndLabel = this->getLabel();
7364 this->jump(EndLabel);
7366 this->emitLabel(LabelTrue);
7367 if (!this->emitPopPtr(E))
7369 if (!this->emitConstBool(
true, E))
7372 this->fallthrough(EndLabel);
7373 this->emitLabel(EndLabel);
7378template <
class Emitter>
7379bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7383 assert(!DiscardResult);
7389 LHSIsComplex =
true;
7390 ElemT = classifyComplexElementType(LHS->
getType());
7391 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7392 if (!this->visit(LHS))
7394 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7397 LHSIsComplex =
false;
7399 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7400 if (!this->visit(LHS))
7402 if (!this->emitSetLocal(LHST, LHSOffset, E))
7409 RHSIsComplex =
true;
7410 ElemT = classifyComplexElementType(RHS->
getType());
7411 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7412 if (!this->visit(RHS))
7414 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7417 RHSIsComplex =
false;
7419 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7420 if (!this->visit(RHS))
7422 if (!this->emitSetLocal(RHST, RHSOffset, E))
7426 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7427 bool IsComplex) ->
bool {
7429 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7431 return this->emitArrayElemPop(ElemT, Index, E);
7433 return this->emitGetLocal(ElemT, LocalOffset, E);
7436 for (
unsigned I = 0; I != 2; ++I) {
7438 if (!getElem(LHSOffset, I, LHSIsComplex))
7440 if (!getElem(RHSOffset, I, RHSIsComplex))
7443 if (!this->emitEQ(ElemT, E))
7446 if (!this->emitCastBoolUint8(E))
7451 if (!this->emitAddUint8(E))
7453 if (!this->emitConstUint8(2, E))
7457 if (!this->emitEQUint8(E))
7460 if (!this->emitNEUint8(E))
7467 return this->emitCast(
PT_Bool, ResT, E);
7474template <
class Emitter>
7475bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7481 const Function *DtorFunc = getFunction(Dtor);
7484 assert(DtorFunc->hasThisPointer());
7485 assert(DtorFunc->getNumParams() == 1);
7486 return this->emitCall(DtorFunc, 0, Loc);
7491template <
class Emitter>
7492bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7504 return this->emitPopPtr(Loc);
7506 for (ssize_t I = N - 1; I >= 1; --I) {
7507 if (!this->emitConstUint64(I, Loc))
7509 if (!this->emitArrayElemPtrUint64(Loc))
7511 if (!this->emitDestructionPop(ElemDesc, Loc))
7515 if (!this->emitConstUint64(0, Loc))
7517 if (!this->emitArrayElemPtrPopUint64(Loc))
7519 return this->emitDestructionPop(ElemDesc, Loc);
7524 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7529template <
class Emitter>
7530bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7531 assert(!DiscardResult &&
"Should've been checked before");
7533 unsigned DummyID = P.getOrCreateDummy(D);
7535 if (!this->emitGetPtrGlobal(DummyID, E))
7543 return this->emitDecayPtr(
PT_Ptr, PT, E);
7549template <
class Emitter>
7550bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7551 assert(!DiscardResult &&
"Should've been checked before");
7554 return this->emitConstFloat(
Floating(F), E);
7556 APInt I = F.bitcastToAPInt();
7557 return this->emitConstFloat(
7558 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7559 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7570template <
class Emitter>
7571bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7584 if (!this->emitGetPtrLocal(*LocalIndex, E))
7594 if (!this->visit(SubExpr))
7596 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7597 unsigned TempOffset =
7598 allocateLocalPrimitive(SubExpr, *FromT,
true);
7599 if (!this->visit(SubExpr))
7601 if (!this->emitSetLocal(*FromT, TempOffset, E))
7603 if (!this->emitGetPtrLocal(TempOffset, E))
7610 if (!this->emitBitCast(E))
7612 return DiscardResult ? this->emitPopPtr(E) :
true;
7616 const llvm::fltSemantics *TargetSemantics =
nullptr;
7618 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7624 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7626 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7627 ResultBitWidth, TargetSemantics,
7632 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, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags)
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...
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
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.
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.
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...
const Expr * getBase() const
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.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
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.
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
bool isExpressibleAsConstantInitializer() const
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() 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 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.
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)
VarCreationState visitDecl(const VarDecl *VD, bool IsConstexprUnknown=false)
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)
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)
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.
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block, bool IsConstexprUnknown=false)
Creates a local primitive value.
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.
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)
typename Emitter::LabelTy LabelTy
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)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false, bool IsConstexprUnknown=false)
Creates and initializes a variable from the given decl.
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 VisitGNUNullExpr(const GNUNullExpr *E)
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block, bool IsConstexprUnknown=false)
Allocates a space storing a local given its type.
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
const CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
const Base * getBase(unsigned I) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * getVirtualBase(unsigned I) const
llvm::iterator_range< const_base_iter > bases() const
unsigned getNumFields() const
llvm::iterator_range< const_field_iter > fields() const
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)
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)
constexpr bool isIntegralType(PrimType T)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ 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.
const FunctionProtoType * T
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)
bool isUnnamedBitField() const
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()