29 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
30 CE && CE->hasAPValueResult() &&
32 return CE->getResultAsAPSInt().getBoolValue();
43 OldInitializingDecl(
Ctx->InitializingDecl) {
44 Ctx->InitializingDecl = VD;
49 this->
Ctx->InitializingDecl = OldInitializingDecl;
50 this->
Ctx->InitStack.pop_back();
63 bool NewInitializing,
bool NewToLValue)
64 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
65 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
66 Ctx->DiscardResult = NewDiscardResult;
67 Ctx->Initializing = NewInitializing;
68 Ctx->ToLValue = NewToLValue;
72 Ctx->DiscardResult = OldDiscardResult;
73 Ctx->Initializing = OldInitializing;
74 Ctx->ToLValue = OldToLValue;
81 bool OldDiscardResult;
86template <
class Emitter>
90 return Ctx->emitThis(E);
93 return Ctx->emitGetPtrFieldPop(
Offset, E);
95 return Ctx->emitGetPtrLocal(
Offset, E);
99 if (!Ctx->emitConstUint32(
Offset, E))
101 return Ctx->emitArrayElemPtrPopUint32(E);
103 return Ctx->emitRVOPtr(E);
107 llvm_unreachable(
"Unhandled InitLink kind");
123 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
124 assert(LI.Name != Name);
127 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
148 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
150 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
151 assert(LI.Name != Name);
154 this->Ctx->CaseLabels = std::move(CaseLabels);
155 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
157 DefaultLabel, Ctx->VarScope);
161 this->Ctx->CaseLabels = std::move(OldCaseLabels);
162 this->Ctx->LabelInfoStack.pop_back();
167 CaseMap OldCaseLabels;
173 Ctx->InStmtExpr =
true;
191 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
194 Ctx->LocOverride = NewValue;
199 Ctx->LocOverride = OldFlag;
204 std::optional<SourceInfo> OldFlag;
211template <
class Emitter>
219 case CK_LValueToRValue: {
230 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
236 if (
auto GlobalIndex =
P.getGlobal(D))
237 return this->emitGetGlobal(*SubExprT, *GlobalIndex, CE);
238 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
239 return this->emitGetLocal(*SubExprT, It->second.Offset, CE);
240 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
241 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
242 return this->emitGetParam(*SubExprT, It->second.Offset, CE);
254 if (!this->emitGetPtrLocal(*LocalIndex, CE))
258 if (!this->
visit(SubExpr))
262 return this->emitLoadPop(*SubExprT, CE);
267 return this->emitMemcpy(CE);
270 case CK_DerivedToBaseMemberPointer: {
276 unsigned DerivedOffset =
278 FromMP->getMostRecentCXXRecordDecl());
283 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
286 case CK_BaseToDerivedMemberPointer: {
292 unsigned DerivedOffset =
293 Ctx.collectBaseOffset(FromMP->getMostRecentCXXRecordDecl(),
298 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
301 case CK_UncheckedDerivedToBase:
302 case CK_DerivedToBase: {
307 if (
const auto *PT = dyn_cast<PointerType>(Ty))
308 return PT->getPointeeType()->getAsCXXRecordDecl();
309 return Ty->getAsCXXRecordDecl();
316 if (B->isVirtual()) {
317 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), CE))
319 CurType = B->getType();
321 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
322 if (!this->emitGetPtrBasePop(
325 CurType = B->getType();
332 case CK_BaseToDerived: {
335 unsigned DerivedOffset =
341 return this->emitGetPtrDerivedPop(DerivedOffset,
346 case CK_FloatingCast: {
351 if (!this->
visit(SubExpr))
353 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
357 case CK_IntegralToFloating: {
360 if (!this->
visit(SubExpr))
362 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
363 return this->emitCastIntegralFloating(
364 classifyPrim(SubExpr), TargetSemantics, getFPOptions(CE), CE);
367 case CK_FloatingToBoolean: {
371 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
372 return this->emitConstBool(FL->getValue().isNonZero(), CE);
373 if (!this->
visit(SubExpr))
375 return this->emitCastFloatingIntegralBool(getFPOptions(CE), CE);
378 case CK_FloatingToIntegral: {
381 if (!this->
visit(SubExpr))
385 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(CE->
getType()),
386 getFPOptions(CE), CE);
388 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
389 getFPOptions(CE), CE);
391 return this->emitCastFloatingIntegral(ToT, getFPOptions(CE), CE);
394 case CK_NullToPointer:
395 case CK_NullToMemberPointer: {
400 if (!PointeeType.
isNull()) {
402 Desc =
P.createDescriptor(SubExpr, *
T);
404 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
408 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(CE->
getType());
412 case CK_PointerToIntegral: {
413 if (!this->
visit(SubExpr))
419 if (!this->emitDecayPtr(FromT,
PT_Ptr, CE))
425 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(CE->
getType()),
428 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(CE->
getType()),
430 return this->emitCastPointerIntegral(
T, CE);
433 case CK_ArrayToPointerDecay: {
434 if (!this->
visit(SubExpr))
436 return this->emitArrayDecay(CE);
439 case CK_IntegralToPointer: {
441 assert(IntType->isIntegralOrEnumerationType());
442 if (!this->
visit(SubExpr))
450 Desc =
P.createDescriptor(SubExpr, *
T);
457 if (!this->emitGetIntPtr(
T, Desc, CE))
465 return this->emitDecayPtr(
PT_Ptr, DestPtrT, CE);
468 case CK_AtomicToNonAtomic:
469 case CK_ConstructorConversion:
470 case CK_FunctionToPointerDecay:
471 case CK_NonAtomicToAtomic:
473 case CK_UserDefinedConversion:
474 case CK_AddressSpaceConversion:
475 case CK_CPointerToObjCPointerCast:
489 return this->emitBuiltinBitCast(CE);
503 if (!this->
visit(SubExpr))
507 return this->emitFnPtrCast(CE);
514 if (!this->
visit(SubExpr))
516 return this->emitDecayPtr(*FromT, *ToT, CE);
518 case CK_IntegralToBoolean:
519 case CK_FixedPointToBoolean: {
525 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
526 return this->emitConst(IL->getValue(), CE);
527 if (!this->
visit(SubExpr))
532 case CK_BooleanToSignedIntegral:
533 case CK_IntegralCast: {
540 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
543 return this->emitConst(IL->getValue(), CE);
544 if (!this->emitConst(IL->getValue(), SubExpr))
547 if (!this->
visit(SubExpr))
555 if (!ED->isFixed()) {
556 if (!this->emitCheckEnumValue(*FromT, ED, CE))
562 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
565 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(CE->
getType()), CE))
570 if (!this->emitCast(*FromT, *ToT, CE))
573 if (CE->
getCastKind() == CK_BooleanToSignedIntegral)
574 return this->emitNeg(*ToT, CE);
578 case CK_PointerToBoolean:
579 case CK_MemberPointerToBoolean: {
582 if (!this->
visit(SubExpr))
584 return this->emitIsNonNull(PtrT, CE);
587 case CK_IntegralComplexToBoolean:
588 case CK_FloatingComplexToBoolean: {
589 if (!this->
visit(SubExpr))
591 return this->emitComplexBoolCast(SubExpr);
594 case CK_IntegralComplexToReal:
595 case CK_FloatingComplexToReal:
596 return this->emitComplexReal(SubExpr);
598 case CK_IntegralRealToComplex:
599 case CK_FloatingRealToComplex: {
606 if (!this->emitGetPtrLocal(*LocalIndex, CE))
615 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
617 return this->emitInitElem(
T, 1, SubExpr);
620 case CK_IntegralComplexCast:
621 case CK_FloatingComplexCast:
622 case CK_IntegralComplexToFloatingComplex:
623 case CK_FloatingComplexToIntegralComplex: {
630 if (!this->emitGetPtrLocal(*LocalIndex, CE))
637 unsigned SubExprOffset =
639 if (!this->
visit(SubExpr))
641 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, CE))
649 for (
unsigned I = 0; I != 2; ++I) {
650 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, CE))
652 if (!this->emitArrayElemPop(SourceElemT, I, CE))
656 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, CE))
660 if (!this->emitInitElem(DestElemT, I, CE))
666 case CK_VectorSplat: {
675 if (!this->emitGetPtrLocal(*LocalIndex, CE))
681 unsigned ElemOffset =
685 if (!this->
visit(SubExpr))
690 if (!this->emitSetLocal(ElemT, ElemOffset, CE))
693 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
694 if (!this->emitGetLocal(ElemT, ElemOffset, CE))
696 if (!this->emitInitElem(ElemT, I, CE))
703 case CK_HLSLVectorTruncation: {
708 if (!this->
visit(SubExpr))
710 return this->emitArrayElemPop(*ResultT, 0, CE);
719 if (!this->emitGetPtrLocal(*LocalIndex, CE))
724 if (!this->
visit(SubExpr))
726 return this->emitCopyArray(classifyVectorElementType(CE->
getType()), 0, 0,
730 case CK_IntegralToFixedPoint: {
731 if (!this->
visit(SubExpr))
735 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
739 case CK_FloatingToFixedPoint: {
740 if (!this->
visit(SubExpr))
744 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
745 return this->emitCastFloatingFixedPoint(Sem, CE);
747 case CK_FixedPointToFloating: {
748 if (!this->
visit(SubExpr))
750 const auto *TargetSemantics = &
Ctx.getFloatSemantics(CE->
getType());
751 return this->emitCastFixedPointFloating(TargetSemantics, CE);
753 case CK_FixedPointToIntegral: {
754 if (!this->
visit(SubExpr))
758 case CK_FixedPointCast: {
759 if (!this->
visit(SubExpr))
762 Ctx.getASTContext().getFixedPointSemantics(CE->
getType()).toOpaqueInt();
763 return this->emitCastFixedPoint(Sem, CE);
770 return this->emitInvalid(CE);
772 llvm_unreachable(
"Unhandled clang::CastKind enum");
775template <
class Emitter>
777 return this->emitBuiltinBitCast(E);
780template <
class Emitter>
785 return this->emitConst(
LE->getValue(),
LE);
788template <
class Emitter>
794 return this->emitFloat(F, E);
797template <
class Emitter>
807 if (!this->emitGetPtrLocal(*LocalIndex, E))
814 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
816 if (!this->emitInitElem(SubExprT, 0, SubExpr))
821template <
class Emitter>
829 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
834template <
class Emitter>
839template <
class Emitter>
866 return this->emitComplexComparison(LHS, RHS, BO);
871 if (!this->
visit(LHS))
874 if (!this->
visit(RHS))
877 if (!this->emitToMemberPtr(BO))
883 if (!this->emitCastMemberPtrPtr(BO))
900 Ctx.getASTContext().CompCategories.lookupInfoForType(BO->
getType());
906 if (!this->emitGetPtrLocal(*ResultIndex, BO))
913 return this->emitCMP3(*
LT, CmpInfo, BO);
916 if (!
LT || !RT || !
T)
926 return this->visitAssignment(LHS, RHS, BO);
933 auto MaybeCastToBool = [
this,
T, BO](
bool Result) {
937 return this->emitPopBool(BO);
939 return this->emitCast(
PT_Bool, *
T, BO);
943 auto Discard = [
this,
T, BO](
bool Result) {
951 return MaybeCastToBool(this->emitEQ(*
LT, BO));
953 return MaybeCastToBool(this->emitNE(*
LT, BO));
955 return MaybeCastToBool(this->emitLT(*
LT, BO));
957 return MaybeCastToBool(this->emitLE(*
LT, BO));
959 return MaybeCastToBool(this->emitGT(*
LT, BO));
961 return MaybeCastToBool(this->emitGE(*
LT, BO));
964 return Discard(this->emitSubf(getFPOptions(BO), BO));
965 return Discard(this->emitSub(*
T, BO));
968 return Discard(this->emitAddf(getFPOptions(BO), BO));
969 return Discard(this->emitAdd(*
T, BO));
972 return Discard(this->emitMulf(getFPOptions(BO), BO));
973 return Discard(this->emitMul(*
T, BO));
975 return Discard(this->emitRem(*
T, BO));
978 return Discard(this->emitDivf(getFPOptions(BO), BO));
979 return Discard(this->emitDiv(*
T, BO));
981 return Discard(this->emitBitAnd(*
T, BO));
983 return Discard(this->emitBitOr(*
T, BO));
985 return Discard(this->emitShl(*
LT, *RT, BO));
987 return Discard(this->emitShr(*
LT, *RT, BO));
989 return Discard(this->emitBitXor(*
T, BO));
992 llvm_unreachable(
"Already handled earlier");
997 llvm_unreachable(
"Unhandled binary op");
1002template <
class Emitter>
1008 if ((Op != BO_Add && Op != BO_Sub) ||
1019 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1020 if (!this->
visit(E))
1023 return this->emitDecayPtr(
T,
PT_Ptr, E);
1032 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1036 if (!this->emitSubPtr(IntT, E))
1043 if (!visitAsPointer(RHS, *RT))
1045 if (!this->
visit(LHS))
1049 if (!visitAsPointer(LHS, *
LT))
1051 if (!this->
visit(RHS))
1061 if (!this->emitAddOffset(OffsetType, E))
1069 if (!this->emitSubOffset(OffsetType, E))
1080template <
class Emitter>
1090 LabelTy LabelTrue = this->getLabel();
1091 LabelTy LabelEnd = this->getLabel();
1095 if (!this->jumpTrue(LabelTrue))
1100 if (!this->jump(LabelEnd))
1103 this->emitLabel(LabelTrue);
1104 this->emitConstBool(
true, E);
1105 this->fallthrough(LabelEnd);
1106 this->emitLabel(LabelEnd);
1109 assert(Op == BO_LAnd);
1112 LabelTy LabelFalse = this->getLabel();
1113 LabelTy LabelEnd = this->getLabel();
1117 if (!this->jumpFalse(LabelFalse))
1122 if (!this->jump(LabelEnd))
1125 this->emitLabel(LabelFalse);
1126 this->emitConstBool(
false, E);
1127 this->fallthrough(LabelEnd);
1128 this->emitLabel(LabelEnd);
1132 return this->emitPopBool(E);
1137 return this->emitCast(
PT_Bool, *
T, E);
1141template <
class Emitter>
1148 if (!this->emitGetPtrLocal(*LocalIndex, E))
1157 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1158 unsigned ResultOffset = ~0u;
1164 if (!this->emitDupPtr(E))
1166 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1171 LHSType = AT->getValueType();
1174 RHSType = AT->getValueType();
1183 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1188 if (!this->
visit(LHS))
1190 if (!this->
visit(RHS))
1192 return this->emitMulc(ElemT, E);
1195 if (Op == BO_Div && RHSIsComplex) {
1202 if (!LHSIsComplex) {
1207 LHSOffset = *LocalIndex;
1209 if (!this->emitGetPtrLocal(LHSOffset, E))
1212 if (!this->
visit(LHS))
1215 if (!this->emitInitElem(ElemT, 0, E))
1218 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1220 if (!this->emitInitElem(ElemT, 1, E))
1223 if (!this->
visit(LHS))
1227 if (!this->
visit(RHS))
1229 return this->emitDivc(ElemT, E);
1235 if (!this->
visit(LHS))
1237 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1242 if (!this->
visit(LHS))
1244 if (!this->emitSetLocal(LHST, LHSOffset, E))
1252 if (!this->
visit(RHS))
1254 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1259 if (!this->
visit(RHS))
1261 if (!this->emitSetLocal(RHST, RHSOffset, E))
1268 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1269 unsigned ElemIndex,
unsigned Offset,
1270 const Expr *E) ->
bool {
1272 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1274 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1277 if (ElemIndex == 0 || !LoadZero)
1284 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1287 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1294 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1297 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1300 if (!this->emitAddf(getFPOptions(E), E))
1303 if (!this->emitAdd(ResultElemT, E))
1308 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1311 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1314 if (!this->emitSubf(getFPOptions(E), E))
1317 if (!this->emitSub(ResultElemT, E))
1322 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1325 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1329 if (!this->emitMulf(getFPOptions(E), E))
1332 if (!this->emitMul(ResultElemT, E))
1337 assert(!RHSIsComplex);
1338 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1341 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1345 if (!this->emitDivf(getFPOptions(E), E))
1348 if (!this->emitDiv(ResultElemT, E))
1359 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1362 if (!this->emitPop(ResultElemT, E))
1369template <
class Emitter>
1374 "Comma op should be handled in VisitBinaryOperator");
1388 if (!this->emitGetPtrLocal(*LocalIndex, E))
1402 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1405 if (!this->
visit(LHS))
1407 if (!this->
visit(RHS))
1409 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1412 return this->emitPopPtr(E);
1417 unsigned LHSOffset =
1419 if (!this->
visit(LHS))
1421 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1425 unsigned RHSOffset =
1427 if (!this->
visit(RHS))
1429 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1441 if (NeedIntPromot) {
1443 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1448 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1449 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1451 if (!this->emitArrayElemPop(ElemT, Index, E))
1454 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1456 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1458 }
else if (NeedIntPromot) {
1459 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1465#define EMIT_ARITH_OP(OP) \
1467 if (ElemT == PT_Float) { \
1468 if (!this->emit##OP##f(getFPOptions(E), E)) \
1471 if (!this->emit##OP(ElemT, E)) \
1477 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1478 if (!getElem(LHSOffset, ElemT, I))
1480 if (!getElem(RHSOffset, RHSElemT, I))
1492 if (!this->emitRem(ElemT, E))
1496 if (!this->emitBitAnd(OpT, E))
1500 if (!this->emitBitOr(OpT, E))
1504 if (!this->emitBitXor(OpT, E))
1508 if (!this->emitShl(OpT, RHSElemT, E))
1512 if (!this->emitShr(OpT, RHSElemT, E))
1516 if (!this->emitEQ(ElemT, E))
1520 if (!this->emitNE(ElemT, E))
1524 if (!this->emitLE(ElemT, E))
1528 if (!this->emitLT(ElemT, E))
1532 if (!this->emitGE(ElemT, E))
1536 if (!this->emitGT(ElemT, E))
1541 if (!this->emitBitAnd(ResultElemT, E))
1546 if (!this->emitBitOr(ResultElemT, E))
1550 return this->emitInvalid(E);
1559 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1561 if (!this->emitNeg(ResultElemT, E))
1567 if (NeedIntPromot &&
1568 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1572 if (!this->emitInitElem(ResultElemT, I, E))
1581template <
class Emitter>
1591 auto LHSSemaInt = LHSSema.toOpaqueInt();
1593 auto RHSSemaInt = RHSSema.toOpaqueInt();
1595 if (!this->
visit(LHS))
1603 if (!this->
visit(RHS))
1612 auto ConvertResult = [&](
bool R) ->
bool {
1616 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1617 if (ResultSema != CommonSema)
1618 return this->emitCastFixedPoint(ResultSema, E);
1622 auto MaybeCastToBool = [&](
bool Result) {
1627 return this->emitPop(
T, E);
1629 return this->emitCast(
PT_Bool,
T, E);
1635 return MaybeCastToBool(this->emitEQFixedPoint(E));
1637 return MaybeCastToBool(this->emitNEFixedPoint(E));
1639 return MaybeCastToBool(this->emitLTFixedPoint(E));
1641 return MaybeCastToBool(this->emitLEFixedPoint(E));
1643 return MaybeCastToBool(this->emitGTFixedPoint(E));
1645 return MaybeCastToBool(this->emitGEFixedPoint(E));
1647 return ConvertResult(this->emitAddFixedPoint(E));
1649 return ConvertResult(this->emitSubFixedPoint(E));
1651 return ConvertResult(this->emitMulFixedPoint(E));
1653 return ConvertResult(this->emitDivFixedPoint(E));
1655 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1657 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1660 return this->emitInvalid(E);
1663 llvm_unreachable(
"unhandled binop opcode");
1666template <
class Emitter>
1675 if (!this->
visit(SubExpr))
1677 return this->emitNegFixedPoint(E);
1682 llvm_unreachable(
"Unhandled unary opcode");
1685template <
class Emitter>
1691 return this->visitZeroInitializer(*
T, QT, E);
1699 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1700 CXXRD && CXXRD->getNumVBases() > 0) {
1710 return this->visitZeroRecordInitializer(R, E);
1717 return this->visitZeroArrayInitializer(QT, E);
1721 QualType ElemQT = ComplexTy->getElementType();
1723 for (
unsigned I = 0; I < 2; ++I) {
1724 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1726 if (!this->emitInitElem(ElemT, I, E))
1733 unsigned NumVecElements = VecT->getNumElements();
1734 QualType ElemQT = VecT->getElementType();
1737 for (
unsigned I = 0; I < NumVecElements; ++I) {
1738 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1740 if (!this->emitInitElem(ElemT, I, E))
1749template <
class Emitter>
1759 for (
const Expr *SubExpr : {LHS, RHS}) {
1760 if (!this->
visit(SubExpr)) {
1767 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
1768 if (!this->emitExpandPtr(E))
1779 return this->emitError(E);
1782 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
1786 if (!this->emitArrayElemPtrPop(*IndexT, E))
1789 return this->emitPopPtr(E);
1793template <
class Emitter>
1795 const Expr *ArrayFiller,
const Expr *E) {
1800 QT = AT->getValueType();
1803 if (Inits.size() == 0)
1805 return this->emitInvalid(E);
1820 if (Inits.size() == 0)
1821 return this->visitZeroInitializer(*
T, QT, E);
1822 assert(Inits.size() == 1);
1829 if (Inits.size() == 1 && E->
getType() == Inits[0]->getType())
1835 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
1843 bool BitField = FieldToInit->isBitField();
1845 return this->emitInitBitFieldActivate(
T, FieldToInit, E);
1847 return this->emitInitBitField(
T, FieldToInit, E);
1849 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
1850 return this->emitInitField(
T, FieldToInit->Offset, E);
1853 auto initCompositeField = [=](
const Record::Field *FieldToInit,
1861 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
1864 if (
Activate && !this->emitActivate(E))
1869 return this->emitPopPtr(E);
1873 if (Inits.size() == 0) {
1874 if (!this->visitZeroRecordInitializer(R, E))
1879 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
1880 FToInit = ILE->getInitializedFieldInUnion();
1884 const Record::Field *FieldToInit = R->
getField(FToInit);
1886 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
1889 if (!initCompositeField(FieldToInit,
Init,
true))
1893 return this->emitFinishInit(E);
1897 unsigned InitIndex = 0;
1900 while (InitIndex < R->getNumFields() &&
1905 const Record::Field *FieldToInit = R->
getField(InitIndex);
1906 if (!initPrimitiveField(FieldToInit,
Init, *
T))
1911 if (
const Record::Base *B = R->
getBase(
Init->getType())) {
1912 if (!this->emitGetPtrBase(B->Offset,
Init))
1918 if (!this->emitFinishInitPop(E))
1923 const Record::Field *FieldToInit = R->
getField(InitIndex);
1924 if (!initCompositeField(FieldToInit,
Init))
1930 return this->emitFinishInit(E);
1934 if (Inits.size() == 1 && QT == Inits[0]->getType())
1938 Ctx.getASTContext().getAsConstantArrayType(QT);
1941 if (!this->emitCheckArraySize(NumElems, E))
1945 unsigned ElementIndex = 0;
1947 if (
const auto *EmbedS =
1948 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
1956 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
1957 getFPOptions(E), E))
1963 return this->emitInitElem(TargetT, ElemIndex, IL);
1965 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
1977 for (; ElementIndex != NumElems; ++ElementIndex) {
1983 return this->emitFinishInit(E);
1987 unsigned NumInits = Inits.size();
1992 QualType ElemQT = ComplexTy->getElementType();
1994 if (NumInits == 0) {
1996 for (
unsigned I = 0; I < 2; ++I) {
1997 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1999 if (!this->emitInitElem(ElemT, I, E))
2002 }
else if (NumInits == 2) {
2003 unsigned InitIndex = 0;
2008 if (!this->emitInitElem(ElemT, InitIndex, E))
2017 unsigned NumVecElements = VecT->getNumElements();
2018 assert(NumVecElements >= Inits.size());
2020 QualType ElemQT = VecT->getElementType();
2024 unsigned InitIndex = 0;
2031 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2032 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2033 InitVecT->getNumElements(), E))
2035 InitIndex += InitVecT->getNumElements();
2037 if (!this->emitInitElem(ElemT, InitIndex, E))
2043 assert(InitIndex <= NumVecElements);
2046 for (; InitIndex != NumVecElements; ++InitIndex) {
2047 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2049 if (!this->emitInitElem(ElemT, InitIndex, E))
2060template <
class Emitter>
2067 return this->emitInitElem(*InitT, ElemIndex,
Init);
2073 if (!this->emitConstUint32(ElemIndex,
Init))
2075 if (!this->emitArrayElemPtrUint32(
Init))
2079 return this->emitFinishInitPop(
Init);
2082template <
class Emitter>
2085 bool Activate,
bool IsOperatorCall) {
2087 llvm::BitVector NonNullArgs;
2088 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2091 bool ExplicitMemberFn =
false;
2092 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2093 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2095 unsigned ArgIndex = 0;
2096 for (
const Expr *Arg : Args) {
2098 if (!this->
visit(Arg))
2106 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2107 if (DeclIndex < FuncDecl->getNumParams())
2108 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2118 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2126 if (!this->emitActivate(Arg))
2130 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2133 if (!this->emitCheckNonNullArg(ArgT, Arg))
2144template <
class Emitter>
2149template <
class Emitter>
2155template <
class Emitter>
2161template <
class Emitter>
2177template <
class Emitter>
2179 auto It = E->
begin();
2180 return this->
visit(*It);
2185 bool AlignOfReturnsPreferred =
2186 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2192 T = Ref->getPointeeType();
2194 if (
T.getQualifiers().hasUnaligned())
2200 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2206template <
class Emitter>
2212 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2218 ArgType = Ref->getPointeeType();
2224 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2225 return this->emitInvalid(E);
2227 if (Kind == UETT_SizeOf)
2236 return this->emitConst(Size.getQuantity(), E);
2239 if (Kind == UETT_CountOf) {
2245 if (
const auto *CAT =
2249 return this->emitConst(CAT->getSize(), E);
2259 if (VAT->getElementType()->isArrayType()) {
2260 std::optional<APSInt> Res =
2262 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2267 return this->emitConst(*Res, E);
2272 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2289 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2292 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2302 return this->emitConst(Size.getQuantity(), E);
2305 if (Kind == UETT_VectorElements) {
2307 return this->emitConst(VT->getNumElements(), E);
2309 return this->emitSizelessVectorElementSize(E);
2312 if (Kind == UETT_VecStep) {
2314 unsigned N = VT->getNumElements();
2321 return this->emitConst(N, E);
2323 return this->emitConst(1, E);
2326 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2333 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2335 return this->emitInvalid(E);
2337 return this->emitConst(
2338 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2346template <
class Emitter>
2357 const auto maybeLoadValue = [&]() ->
bool {
2361 return this->emitLoadPop(*
T, E);
2365 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2369 if (
auto GlobalIndex =
P.getGlobal(VD))
2370 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybeLoadValue();
2375 if (!this->
discard(Base) && !this->emitSideEffect(E))
2395 const Record::Field *F = R->
getField(FD);
2397 if (F->Decl->getType()->isReferenceType())
2398 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2399 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2402template <
class Emitter>
2411template <
class Emitter>
2430 for (
size_t I = 0; I != Size; ++I) {
2442template <
class Emitter>
2453 return this->emitGetLocal(SubExprT, It->second, E);
2455 if (!this->
visit(SourceExpr))
2462 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2468 if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2478template <
class Emitter>
2485 auto visitChildExpr = [&](
const Expr *E) ->
bool {
2494 return visitChildExpr(TrueExpr);
2495 return visitChildExpr(FalseExpr);
2498 bool IsBcpCall =
false;
2499 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2500 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2504 LabelTy LabelEnd = this->getLabel();
2505 LabelTy LabelFalse = this->getLabel();
2508 if (!this->emitStartSpeculation(E))
2516 if (this->checkingForUndefinedBehavior()) {
2519 if (!this->
discard(FalseExpr))
2525 if (!this->jumpFalse(LabelFalse))
2527 if (!visitChildExpr(TrueExpr))
2529 if (!this->jump(LabelEnd))
2531 this->emitLabel(LabelFalse);
2532 if (!visitChildExpr(FalseExpr))
2534 this->fallthrough(LabelEnd);
2535 this->emitLabel(LabelEnd);
2538 return this->emitEndSpeculation(E);
2542template <
class Emitter>
2548 unsigned StringIndex =
P.createGlobalString(E);
2549 return this->emitGetPtrGlobal(StringIndex, E);
2554 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2555 assert(CAT &&
"a string literal that's not a constant array?");
2560 unsigned N = std::min(ArraySize, E->
getLength());
2563 for (
unsigned I = 0; I != N; ++I) {
2566 if (CharWidth == 1) {
2567 this->emitConstSint8(CodeUnit, E);
2568 this->emitInitElemSint8(I, E);
2569 }
else if (CharWidth == 2) {
2570 this->emitConstUint16(CodeUnit, E);
2571 this->emitInitElemUint16(I, E);
2572 }
else if (CharWidth == 4) {
2573 this->emitConstUint32(CodeUnit, E);
2574 this->emitInitElemUint32(I, E);
2576 llvm_unreachable(
"unsupported character width");
2581 for (
unsigned I = N; I != ArraySize; ++I) {
2582 if (CharWidth == 1) {
2583 this->emitConstSint8(0, E);
2584 this->emitInitElemSint8(I, E);
2585 }
else if (CharWidth == 2) {
2586 this->emitConstUint16(0, E);
2587 this->emitInitElemUint16(I, E);
2588 }
else if (CharWidth == 4) {
2589 this->emitConstUint32(0, E);
2590 this->emitInitElemUint32(I, E);
2592 llvm_unreachable(
"unsupported character width");
2599template <
class Emitter>
2603 return this->emitDummyPtr(E, E);
2606template <
class Emitter>
2608 auto &A =
Ctx.getASTContext();
2617template <
class Emitter>
2625 auto &A =
Ctx.getASTContext();
2629 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2630 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2637 unsigned StringIndex =
P.createGlobalString(SL);
2638 return this->emitGetPtrGlobal(StringIndex, E);
2641template <
class Emitter>
2645 return this->emitConst(E->
getValue(), E);
2648template <
class Emitter>
2674 if (!this->emitSetLocal(*RT, TempOffset, E))
2680 if (!this->emitLoad(LHST, E))
2684 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
2685 LHSComputationType, E))
2689 if (!this->emitGetLocal(*RT, TempOffset, E))
2694 if (!this->emitAddf(getFPOptions(E), E))
2698 if (!this->emitSubf(getFPOptions(E), E))
2702 if (!this->emitMulf(getFPOptions(E), E))
2706 if (!this->emitDivf(getFPOptions(E), E))
2717 return this->emitStorePop(LHST, E);
2718 return this->emitStore(LHST, E);
2721template <
class Emitter>
2730 if (Op != BO_AddAssign && Op != BO_SubAssign)
2739 if (!this->emitLoad(*
LT, LHS))
2745 if (Op == BO_AddAssign) {
2746 if (!this->emitAddOffset(*RT, E))
2749 if (!this->emitSubOffset(*RT, E))
2754 return this->emitStorePopPtr(E);
2755 return this->emitStorePtr(E);
2758template <
class Emitter>
2771 if (!
Ctx.getLangOpts().CPlusPlus14)
2772 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
2774 if (!
LT || !RT || !ResultT || !LHSComputationT)
2799 if (!this->emitSetLocal(*RT, TempOffset, E))
2806 if (!this->emitLoad(*
LT, E))
2808 if (
LT != LHSComputationT) {
2809 if (!this->emitCast(*
LT, *LHSComputationT, E))
2814 if (!this->emitGetLocal(*RT, TempOffset, E))
2820 if (!this->emitAdd(*LHSComputationT, E))
2824 if (!this->emitSub(*LHSComputationT, E))
2828 if (!this->emitMul(*LHSComputationT, E))
2832 if (!this->emitDiv(*LHSComputationT, E))
2836 if (!this->emitRem(*LHSComputationT, E))
2840 if (!this->emitShl(*LHSComputationT, *RT, E))
2844 if (!this->emitShr(*LHSComputationT, *RT, E))
2848 if (!this->emitBitAnd(*LHSComputationT, E))
2852 if (!this->emitBitXor(*LHSComputationT, E))
2856 if (!this->emitBitOr(*LHSComputationT, E))
2860 llvm_unreachable(
"Unimplemented compound assign operator");
2864 if (ResultT != LHSComputationT) {
2865 if (!this->emitCast(*LHSComputationT, *ResultT, E))
2872 return this->emitStoreBitFieldPop(*ResultT, E);
2873 return this->emitStorePop(*ResultT, E);
2876 return this->emitStoreBitField(*ResultT, E);
2877 return this->emitStore(*ResultT, E);
2880template <
class Emitter>
2888template <
class Emitter>
2900 return this->
discard(SubExpr);
2917 if (!this->
visit(SubExpr))
2919 if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
2921 return this->emitGetPtrGlobal(*GlobalIndex, E);
2924 if (!this->checkLiteralType(SubExpr))
2927 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2931 return this->emitInitGlobalTempComp(TempDecl, E);
2937 unsigned LocalIndex =
2939 if (!this->
visit(SubExpr))
2941 if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
2943 return this->emitGetPtrLocal(LocalIndex, E);
2946 if (!this->checkLiteralType(SubExpr))
2952 if (!this->emitGetPtrLocal(*LocalIndex, E))
2959template <
class Emitter>
2970 if (!this->
visit(SubExpr))
2974 return this->emitPopPtr(E);
2978template <
class Emitter>
2999 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3004 if (
P.isGlobalInitialized(*GlobalIndex))
3010 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3022 unsigned LocalIndex;
3026 LocalIndex = *MaybeIndex;
3030 if (!this->emitGetPtrLocal(LocalIndex, E))
3034 return this->
visit(
Init) && this->emitInit(*
T, E);
3038template <
class Emitter>
3051template <
class Emitter>
3055 return this->emitConst(E->
getValue(), E);
3058template <
class Emitter>
3071 for (
const Record::Field &F : R->
fields()) {
3073 if (!
Init ||
Init->containsErrors())
3081 if (!this->emitInitField(*
T, F.Offset, E))
3084 if (!this->emitGetPtrField(F.Offset, E))
3090 if (!this->emitPopPtr(E))
3098template <
class Emitter>
3105 return this->emitGetPtrGlobal(StringIndex, E);
3111template <
class Emitter>
3116 return this->emitInvalid(E);
3119template <
class Emitter>
3145 if (PointeeToT && PointeeFromT) {
3161 bool Fatal = (ToT != FromT);
3168template <
class Emitter>
3171 if (!
Ctx.getLangOpts().CPlusPlus20) {
3179template <
class Emitter>
3185 return this->emitConstBool(E->
getValue(), E);
3188template <
class Emitter>
3193 if (
T->isRecordType()) {
3207 if (!this->emitGetPtrLocal(*LocalIndex, E))
3215 T->getAsCXXRecordDecl()))
3222 if (!this->visitZeroRecordInitializer(R, E))
3235 assert(
Func->hasThisPointer());
3236 assert(!
Func->hasRVO());
3240 if (!this->emitDupPtr(E))
3244 for (
const auto *Arg : E->
arguments()) {
3245 if (!this->
visit(Arg))
3249 if (
Func->isVariadic()) {
3250 uint32_t VarArgSize = 0;
3251 unsigned NumParams =
Func->getNumWrittenParams();
3252 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3256 if (!this->emitCallVar(
Func, VarArgSize, E))
3259 if (!this->emitCall(
Func, 0, E)) {
3264 (void)this->emitPopPtr(E);
3270 return this->emitPopPtr(E);
3271 return this->emitFinishInit(E);
3274 if (
T->isArrayType()) {
3276 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3287 for (
size_t I = 0; I != NumElems; ++I) {
3288 if (!this->emitConstUint64(I, E))
3290 if (!this->emitArrayElemPtrUint64(E))
3294 for (
const auto *Arg : E->
arguments()) {
3295 if (!this->
visit(Arg))
3299 if (!this->emitCall(
Func, 0, E))
3308template <
class Emitter>
3318 assert(Val.
isInt());
3320 return this->emitConst(I, E);
3327 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3328 return this->
visit(LValueExpr);
3343 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3347 const APValue &
V = UGCD->getValue();
3348 for (
unsigned I = 0, N = R->
getNumFields(); I != N; ++I) {
3349 const Record::Field *F = R->
getField(I);
3350 const APValue &FieldValue =
V.getStructField(I);
3356 if (!this->emitInitField(FieldT, F->Offset, E))
3364template <
class Emitter>
3370 for (
unsigned I = 0; I != N; ++I) {
3377 if (!this->
discard(ArrayIndexExpr))
3382 if (!this->
visit(ArrayIndexExpr))
3386 if (!this->emitCast(IndexT,
PT_Sint64, E))
3396 return this->emitOffsetOf(
T, E, E);
3399template <
class Emitter>
3408 return this->visitZeroInitializer(*
T, Ty, E);
3415 if (!this->emitGetPtrLocal(*LocalIndex, E))
3420 QualType ElemQT = CT->getElementType();
3423 for (
unsigned I = 0; I != 2; ++I) {
3424 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3426 if (!this->emitInitElem(ElemT, I, E))
3438 if (!this->emitGetPtrLocal(*LocalIndex, E))
3443 QualType ElemQT = VT->getElementType();
3446 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3447 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3449 if (!this->emitInitElem(ElemT, I, E))
3458template <
class Emitter>
3463template <
class Emitter>
3469template <
class Emitter>
3474template <
class Emitter>
3479 return this->emitConst(E->
getValue(), E);
3482template <
class Emitter>
3487 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3505 if (!this->emitGetParam(PT, Offset, E))
3510 return this->emitCall(F, 0, E);
3515template <
class Emitter>
3523 const Expr *PlacementDest =
nullptr;
3524 bool IsNoThrow =
false;
3526 if (PlacementArgs != 0) {
3535 if (PlacementArgs == 1) {
3543 if (!this->emitInvalidNewDeleteExpr(E, E))
3548 if (OperatorNew->isReservedGlobalPlacementOperator())
3549 PlacementDest = Arg1;
3553 return this->emitInvalid(E);
3555 }
else if (!OperatorNew
3556 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3557 return this->emitInvalidNewDeleteExpr(E, E);
3560 if (!PlacementDest) {
3565 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3568 Desc =
P.createDescriptor(
3571 false,
false,
false,
3577 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3581 const Expr *Stripped = *ArraySizeExpr;
3582 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3583 Stripped = ICE->getSubExpr())
3584 if (ICE->getCastKind() != CK_NoOp &&
3585 ICE->getCastKind() != CK_IntegralCast)
3593 if (!this->
visit(Stripped))
3595 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3598 if (PlacementDest) {
3599 if (!this->
visit(PlacementDest))
3601 if (!this->emitStartLifetime(E))
3603 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3605 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3608 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3613 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3617 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3624 size_t StaticInitElems = 0;
3625 const Expr *DynamicInit =
nullptr;
3627 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3628 StaticInitElems = CAT->getZExtSize();
3632 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init);
3633 ILE && ILE->hasArrayFiller())
3634 DynamicInit = ILE->getArrayFiller();
3648 const Function *CtorFunc =
nullptr;
3649 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
3653 }
else if (!DynamicInit)
3656 LabelTy EndLabel = this->getLabel();
3657 LabelTy StartLabel = this->getLabel();
3662 if (!this->emitDupPtr(E))
3664 if (!this->emitNullPtr(0,
nullptr, E))
3666 if (!this->emitEQPtr(E))
3668 if (!this->jumpTrue(EndLabel))
3675 if (!this->emitConst(StaticInitElems,
SizeT, E))
3677 if (!this->emitSetLocal(
SizeT, Iter, E))
3680 this->fallthrough(StartLabel);
3681 this->emitLabel(StartLabel);
3683 if (!this->emitGetLocal(
SizeT, Iter, E))
3685 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3687 if (!this->emitLT(
SizeT, E))
3689 if (!this->jumpFalse(EndLabel))
3693 if (!this->emitGetLocal(
SizeT, Iter, E))
3695 if (!this->emitArrayElemPtr(
SizeT, E))
3698 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3703 if (!this->visitZeroInitializer(InitT, ElemType, E))
3705 if (!this->emitStorePop(InitT, E))
3707 }
else if (DynamicInit) {
3709 if (!this->
visit(DynamicInit))
3711 if (!this->emitStorePop(*InitT, E))
3716 if (!this->emitPopPtr(E))
3721 if (!this->emitCall(CtorFunc, 0, E))
3726 if (!this->emitGetPtrLocal(Iter, E))
3728 if (!this->emitIncPop(
SizeT,
false, E))
3731 if (!this->jump(StartLabel))
3734 this->fallthrough(EndLabel);
3735 this->emitLabel(EndLabel);
3739 if (PlacementDest) {
3740 if (!this->
visit(PlacementDest))
3742 if (!this->emitStartLifetime(E))
3744 if (!this->emitCheckNewTypeMismatch(E, E))
3748 if (!this->emitAlloc(Desc, E))
3757 if (!this->emitInit(*ElemT, E))
3768 return this->emitPopPtr(E);
3773template <
class Emitter>
3779 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3780 return this->emitInvalidNewDeleteExpr(E, E);
3783 if (!this->
visit(Arg))
3789template <
class Emitter>
3795 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
3800 return this->emitGetFnPtr(
Func, E);
3803template <
class Emitter>
3807 auto canonType = [](
const Type *
T) {
3808 return T->getCanonicalTypeUnqualified().getTypePtr();
3816 return this->emitGetTypeid(
3820 return this->emitGetTypeid(
3829 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
3835 if (!this->emitGetTypeidPtr(TypeInfoType, E))
3838 return this->emitPopPtr(E);
3842template <
class Emitter>
3844 assert(
Ctx.getLangOpts().CPlusPlus);
3845 return this->emitConstBool(E->
getValue(), E);
3848template <
class Emitter>
3860 return this->emitDummyPtr(GuidDecl, E);
3865 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3874 assert(
V.isStruct());
3875 assert(
V.getStructNumBases() == 0);
3879 return this->emitFinishInit(E);
3882template <
class Emitter>
3892template <
class Emitter>
3901template <
class Emitter>
3907template <
class Emitter>
3911 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
3915 if (OVE->isUnique())
3931template <
class Emitter>
3936template <
class Emitter>
3938 return this->emitError(E);
3941template <
class Emitter>
3945 return this->emitDummyPtr(E, E);
3948template <
class Emitter>
3952 QualType ElemType = VT->getElementType();
3956 PrimType SrcElemT = classifyVectorElementType(SrcType);
3958 unsigned SrcOffset =
3960 if (!this->
visit(Src))
3962 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
3965 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
3966 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
3968 if (!this->emitArrayElemPop(SrcElemT, I, E))
3972 if (SrcElemT != ElemT) {
3973 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
3975 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
3976 const auto *TargetSemantics = &
Ctx.getFloatSemantics(ElemType);
3980 if (!this->emitInitElem(ElemT, I, E))
3987template <
class Emitter>
3997 assert(NumOutputElems > 0);
4000 unsigned VectorOffsets[2];
4001 for (
unsigned I = 0; I != 2; ++I) {
4004 if (!this->
visit(Vecs[I]))
4006 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4009 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4011 assert(ShuffleIndex >= -1);
4012 if (ShuffleIndex == -1)
4013 return this->emitInvalidShuffleVectorIndex(I, E);
4015 assert(ShuffleIndex < (NumInputElems * 2));
4016 if (!this->emitGetLocal(
PT_Ptr,
4017 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4019 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4020 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4023 if (!this->emitInitElem(ElemT, I, E))
4030template <
class Emitter>
4035 Base->getType()->isVectorType() ||
4041 if (Indices.size() == 1) {
4046 if (!this->emitConstUint32(Indices[0], E))
4048 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4058 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4066 if (!this->emitGetPtrLocal(*ResultIndex, E))
4074 uint32_t DstIndex = 0;
4075 for (uint32_t I : Indices) {
4076 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4078 if (!this->emitArrayElemPop(ElemT, I, E))
4080 if (!this->emitInitElem(ElemT, DstIndex, E))
4090template <
class Emitter>
4094 return this->
discard(SubExpr) && this->emitInvalid(E);
4100 return this->emitDummyPtr(E, E);
4103template <
class Emitter>
4108 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4113 if (!this->
visit(SubExpr))
4115 if (!this->emitConstUint8(0, E))
4117 if (!this->emitArrayElemPtrPopUint8(E))
4124 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4126 return this->emitInitField(SecondFieldT, R->
getField(1u)->
Offset, E);
4128 assert(SecondFieldT ==
PT_Ptr);
4132 if (!this->emitExpandPtr(E))
4136 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4141template <
class Emitter>
4156 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4158 return this->emitUnsupported(E);
4167 return this->
Visit(E);
4174 return this->
Visit(E);
4178 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4181 if (
const auto *CE = dyn_cast<CastExpr>(E);
4183 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4190 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4193 if (
const auto *CE = dyn_cast<CastExpr>(E);
4194 CE && (CE->getCastKind() == CK_DerivedToBase ||
4195 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4196 CE->getCastKind() == CK_NoOp))
4215 if (!this->emitGetPtrLocal(*LocalIndex, E))
4225 return this->
Visit(E);
4228template <
class Emitter>
4234 return this->
Visit(E);
4240 return this->
Visit(E);
4248 if (!this->
visit(E))
4250 return this->emitComplexBoolCast(E);
4255 if (!this->
visit(E))
4263 return this->emitIsNonNullPtr(E);
4267 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4270 return this->emitCast(*
T,
PT_Bool, E);
4273template <
class Emitter>
4277 QT = AT->getValueType();
4281 return this->emitZeroBool(E);
4283 return this->emitZeroSint8(E);
4285 return this->emitZeroUint8(E);
4287 return this->emitZeroSint16(E);
4289 return this->emitZeroUint16(E);
4291 return this->emitZeroSint32(E);
4293 return this->emitZeroUint32(E);
4295 return this->emitZeroSint64(E);
4297 return this->emitZeroUint64(E);
4299 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4301 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4303 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4306 return this->emitNullMemberPtr(0,
nullptr, E);
4308 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4309 return this->emitFloat(F, E);
4312 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->
getType());
4316 llvm_unreachable(
"unknown primitive type");
4319template <
class Emitter>
4320bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4325 for (
const Record::Field &Field : R->
fields()) {
4326 if (Field.isUnnamedBitField())
4333 if (!this->visitZeroInitializer(
T, QT, E))
4336 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
4340 if (!this->emitInitField(
T, Field.Offset, E))
4345 if (!this->emitGetPtrField(Field.Offset, E))
4351 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4352 if (!this->visitZeroInitializer(
T, ET, E))
4354 if (!this->emitInitElem(
T, I, E))
4359 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4362 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4370 if (!this->emitFinishInitActivatePop(E))
4374 if (!this->emitFinishInitPop(E))
4378 for (
const Record::Base &B : R->
bases()) {
4379 if (!this->emitGetPtrBase(B.Offset, E))
4381 if (!this->visitZeroRecordInitializer(B.R, E))
4383 if (!this->emitFinishInitPop(E))
4392template <
class Emitter>
4393bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4394 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
4395 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
4400 for (
size_t I = 0; I != NumElems; ++I) {
4401 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4403 if (!this->emitInitElem(*ElemT, I, E))
4409 const Record *R = getRecord(ElemType);
4411 for (
size_t I = 0; I != NumElems; ++I) {
4412 if (!this->emitConstUint32(I, E))
4414 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4416 if (!this->visitZeroRecordInitializer(R, E))
4418 if (!this->emitPopPtr(E))
4424 for (
size_t I = 0; I != NumElems; ++I) {
4425 if (!this->emitConstUint32(I, E))
4427 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4429 if (!this->visitZeroArrayInitializer(ElemType, E))
4431 if (!this->emitPopPtr(E))
4440template <
class Emitter>
4441bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4443 if (!canClassify(E->
getType()))
4446 if (!this->visit(RHS))
4448 if (!this->visit(LHS))
4452 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4456 bool Activates = refersToUnion(LHS);
4459 if (!this->emitFlip(
PT_Ptr, RHT, E))
4462 if (DiscardResult) {
4463 if (BitField && Activates)
4464 return this->emitStoreBitFieldActivatePop(RHT, E);
4466 return this->emitStoreBitFieldPop(RHT, E);
4468 return this->emitStoreActivatePop(RHT, E);
4470 return this->emitStorePop(RHT, E);
4473 auto maybeLoad = [&](
bool Result) ->
bool {
4479 return this->emitLoadPop(RHT, E);
4483 if (BitField && Activates)
4484 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4486 return maybeLoad(this->emitStoreBitField(RHT, E));
4488 return maybeLoad(this->emitStoreActivate(RHT, E));
4490 return maybeLoad(this->emitStore(RHT, E));
4493template <
class Emitter>
4494template <
typename T>
4498 return this->emitConstSint8(
Value, E);
4500 return this->emitConstUint8(
Value, E);
4502 return this->emitConstSint16(
Value, E);
4504 return this->emitConstUint16(
Value, E);
4506 return this->emitConstSint32(
Value, E);
4508 return this->emitConstUint32(
Value, E);
4510 return this->emitConstSint64(
Value, E);
4512 return this->emitConstUint64(
Value, E);
4514 return this->emitConstBool(
Value, E);
4521 llvm_unreachable(
"Invalid integral type");
4524 llvm_unreachable(
"unknown primitive type");
4527template <
class Emitter>
4528template <
typename T>
4529bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
4530 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4533template <
class Emitter>
4536 return this->emitConst(
static_cast<const APInt &
>(
Value), Ty, E);
4539template <
class Emitter>
4543 return this->emitConstIntAPS(
Value, E);
4545 return this->emitConstIntAP(
Value, E);
4548 return this->emitConst(
Value.getSExtValue(), Ty, E);
4549 return this->emitConst(
Value.getZExtValue(), Ty, E);
4552template <
class Emitter>
4553bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
4554 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4557template <
class Emitter>
4560 ScopeKind SC,
bool IsConstexprUnknown) {
4568 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
4569 Locals.insert({VD, Local});
4571 VarScope->addExtended(Local, ExtendingDecl);
4573 VarScope->addForScopeKind(Local, SC);
4574 return Local.Offset;
4577template <
class Emitter>
4581 bool IsConstexprUnknown) {
4584 bool IsTemporary =
false;
4585 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
4588 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
4589 Init = VarD->getInit();
4591 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
4599 IsTemporary,
false,
false,
Init);
4601 return std::nullopt;
4606 Locals.insert({Key, Local});
4608 VarScope->addExtended(Local, ExtendingDecl);
4610 VarScope->addForScopeKind(Local, SC);
4611 return Local.Offset;
4614template <
class Emitter>
4624 return std::nullopt;
4634 return Local.Offset;
4637template <
class Emitter>
4639 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
4640 return PT->getPointeeType()->getAsCanonical<RecordType>();
4646 return getRecord(RecordTy->getOriginalDecl()->getDefinitionOrSelf());
4650template <
class Emitter>
4652 return P.getOrCreateRecord(RD);
4655template <
class Emitter>
4657 return Ctx.getOrCreateFunction(FD);
4660template <
class Emitter>
4665 if (!DestroyToplevelScope) {
4666 if (!this->emitCheckAllocations(E))
4670 auto maybeDestroyLocals = [&]() ->
bool {
4671 if (DestroyToplevelScope)
4672 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
4673 return this->emitCheckAllocations(E);
4680 return this->emitRetVoid(E) && maybeDestroyLocals();
4688 return this->emitRet(*
T, E) && maybeDestroyLocals();
4696 if (!this->emitGetPtrLocal(*LocalOffset, E))
4702 if (!this->emitFinishInit(E))
4707 return this->emitRetValue(E) && maybeDestroyLocals();
4710 return maybeDestroyLocals() && this->emitCheckAllocations(E) &&
false;
4713template <
class Emitter>
4715 bool IsConstexprUnknown) {
4717 auto R = this->
visitVarDecl(VD,
true, IsConstexprUnknown);
4726 if (
auto GlobalIndex =
P.getGlobal(VD)) {
4727 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4742template <
class Emitter>
4744 bool ConstantContext) {
4748 if (!ConstantContext) {
4763 auto GlobalIndex =
P.getGlobal(VD);
4764 assert(GlobalIndex);
4766 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
4769 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
4773 auto Local =
Locals.find(VD);
4774 assert(Local !=
Locals.end());
4776 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
4779 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
4789 auto GlobalIndex =
P.getGlobal(VD);
4790 assert(GlobalIndex);
4791 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
4801 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
4804template <
class Emitter>
4807 bool IsConstexprUnknown) {
4814 if (!this->isActive())
4820 if (
Init &&
Init->isValueDependent())
4824 auto checkDecl = [&]() ->
bool {
4826 return !NeedsOp || this->emitCheckDecl(VD, VD);
4829 auto initGlobal = [&](
unsigned GlobalIndex) ->
bool {
4834 return checkDecl() &&
false;
4836 return checkDecl() && this->emitInitGlobal(*VarT, GlobalIndex, VD);
4842 if (!this->emitGetPtrGlobal(GlobalIndex,
Init))
4848 return this->emitFinishInitGlobal(
Init);
4855 if (
P.getPtrGlobal(*GlobalIndex).isInitialized())
4860 return Init && checkDecl() && initGlobal(*GlobalIndex);
4868 return !
Init || (checkDecl() && initGlobal(*GlobalIndex));
4876 IsConstexprUnknown);
4884 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
4888 return this->emitSetLocal(*VarT, Offset, VD);
4896 if (!this->emitGetPtrLocal(*Offset,
Init))
4902 return this->emitFinishInitPop(
Init);
4909template <
class Emitter>
4914 return this->emitConst(Val.
getInt(), ValType, E);
4917 return this->emitFloat(F, E);
4922 return this->emitNull(ValType, 0,
nullptr, E);
4924 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
4925 return this->
visit(BaseExpr);
4930 return this->emitGetMemberPtr(MemberDecl, E);
4931 return this->emitNullMemberPtr(0,
nullptr, E);
4937template <
class Emitter>
4945 const Record::Field *RF = R->
getField(I);
4946 QualType FieldType = RF->Decl->getType();
4951 if (!this->emitInitField(*PT, RF->Offset, E))
4954 if (!this->emitGetPtrField(RF->Offset, E))
4958 if (!this->emitPopPtr(E))
4969 const Record::Field *RF = R->
getField(UnionField);
4973 return this->emitInitField(
T, RF->Offset, E);
4976 const auto *ArrType =
T->getAsArrayTypeUnsafe();
4977 QualType ElemType = ArrType->getElementType();
4978 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
4983 if (!this->emitInitElem(*ElemT, A, E))
4986 if (!this->emitConstUint32(A, E))
4988 if (!this->emitArrayElemPtrUint32(E))
4992 if (!this->emitPopPtr(E))
5003template <
class Emitter>
5005 unsigned BuiltinID) {
5006 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5011 return this->emitConst(0, E);
5014 if (!this->emitStartSpeculation(E))
5016 LabelTy EndLabel = this->getLabel();
5017 if (!this->speculate(E, EndLabel))
5019 this->fallthrough(EndLabel);
5020 if (!this->emitEndSpeculation(E))
5029 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5030 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5031 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5032 BuiltinID == Builtin::BI__builtin_function_start) {
5035 return this->emitDummyPtr(E, E);
5046 if (!this->emitGetPtrLocal(*LocalIndex, E))
5051 switch (BuiltinID) {
5052 case Builtin::BI__builtin_object_size:
5053 case Builtin::BI__builtin_dynamic_object_size: {
5057 if (!this->
visit(Arg0))
5071 for (
const auto *Arg : E->
arguments()) {
5072 if (!this->
visit(Arg))
5078 if (!this->emitCallBI(E, BuiltinID, E))
5083 return this->emitPop(*ReturnT, E);
5089template <
class Emitter>
5106 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5107 DD && DD->isTrivial()) {
5109 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5111 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5112 this->emitPopPtr(E);
5128 if (!this->emitGetPtrLocal(*LocalIndex, E))
5136 if (!this->emitGetPtrLocal(*LocalIndex, E))
5140 if (!this->emitDupPtr(E))
5147 bool IsAssignmentOperatorCall =
false;
5148 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5149 OCE && OCE->isAssignmentOp()) {
5153 assert(Args.size() == 2);
5154 IsAssignmentOperatorCall =
true;
5155 std::reverse(Args.begin(), Args.end());
5161 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5162 MD && MD->isStatic()) {
5166 Args.erase(Args.begin());
5170 bool Devirtualized =
false;
5173 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5181 if (!this->
visit(Callee))
5183 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5185 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5187 if (!this->emitGetMemberPtrBase(E))
5190 const auto *InstancePtr = MC->getImplicitObjectArgument();
5197 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5198 Devirtualized =
true;
5199 if (!this->
visit(Stripped))
5202 if (!this->
visit(InstancePtr))
5206 if (!this->
visit(InstancePtr))
5210 }
else if (
const auto *PD =
5211 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5212 if (!this->emitCheckPseudoDtor(E))
5220 return this->emitEndLifetimePop(E);
5221 }
else if (!FuncDecl) {
5225 if (!this->
visit(Callee))
5227 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5231 if (!this->
visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5236 if (IsAssignmentOperatorCall) {
5237 assert(Args.size() == 2);
5240 if (!this->emitFlip(Arg2T, Arg1T, E))
5254 assert(HasRVO ==
Func->hasRVO());
5256 bool HasQualifier =
false;
5257 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5258 HasQualifier = ME->hasQualifier();
5260 bool IsVirtual =
false;
5261 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5262 IsVirtual = !Devirtualized && MD->isVirtual();
5267 if (IsVirtual && !HasQualifier) {
5268 uint32_t VarArgSize = 0;
5269 unsigned NumParams =
5271 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5274 if (!this->emitCallVirt(
Func, VarArgSize, E))
5276 }
else if (
Func->isVariadic()) {
5277 uint32_t VarArgSize = 0;
5278 unsigned NumParams =
5280 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5282 if (!this->emitCallVar(
Func, VarArgSize, E))
5285 if (!this->emitCall(
Func, 0, E))
5294 uint32_t ArgSize = 0;
5295 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5301 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5303 if (!this->emitGetMemberPtrDecl(E))
5306 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5309 if (!this->emitCallPtr(ArgSize, E, E))
5320template <
class Emitter>
5327template <
class Emitter>
5334template <
class Emitter>
5339 return this->emitConstBool(E->
getValue(), E);
5342template <
class Emitter>
5348 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5349 return this->emitNullPtr(Val,
nullptr, E);
5352template <
class Emitter>
5360 return this->emitZero(
T, E);
5363template <
class Emitter>
5368 if (this->LambdaThisCapture.Offset > 0) {
5369 if (this->LambdaThisCapture.IsPtr)
5370 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
5371 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
5379 return this->emitThis(E);
5395 unsigned StartIndex = 0;
5396 unsigned EndIndex = 0;
5398 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
5401 EndIndex = StartIndex;
5408 for (; StartIndex > 0; --StartIndex) {
5418 for (
unsigned I = StartIndex; I != EndIndex; ++I) {
5426 return this->emitThis(E);
5431 case Stmt::CompoundStmtClass:
5433 case Stmt::DeclStmtClass:
5435 case Stmt::ReturnStmtClass:
5437 case Stmt::IfStmtClass:
5439 case Stmt::WhileStmtClass:
5441 case Stmt::DoStmtClass:
5443 case Stmt::ForStmtClass:
5445 case Stmt::CXXForRangeStmtClass:
5447 case Stmt::BreakStmtClass:
5449 case Stmt::ContinueStmtClass:
5451 case Stmt::SwitchStmtClass:
5453 case Stmt::CaseStmtClass:
5455 case Stmt::DefaultStmtClass:
5457 case Stmt::AttributedStmtClass:
5459 case Stmt::CXXTryStmtClass:
5461 case Stmt::NullStmtClass:
5464 case Stmt::GCCAsmStmtClass:
5465 case Stmt::MSAsmStmtClass:
5466 case Stmt::GotoStmtClass:
5467 return this->emitInvalid(S);
5468 case Stmt::LabelStmtClass:
5471 if (
const auto *E = dyn_cast<Expr>(S))
5478template <
class Emitter>
5481 for (
const auto *InnerStmt : S->
body())
5484 return Scope.destroyLocals();
5487template <
class Emitter>
5488bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
5489 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5490 for (
auto *BD : DD->flat_bindings())
5491 if (
auto *KD = BD->getHoldingVar(); KD && !this->visitVarDecl(KD))
5500 const auto *CXXRD = dyn_cast<CXXRecordDecl>(FD->
getParent());
5501 return !CXXRD || CXXRD->hasTrivialDefaultConstructor();
5504template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
5506 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
5507 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
5514 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
5519 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5520 ICE && (ICE->getCastKind() == CK_NoOp ||
5521 ICE->getCastKind() == CK_DerivedToBase ||
5522 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
5523 E = ICE->getSubExpr();
5527 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
5528 const auto *ThisRecord =
5529 This->getType()->getPointeeType()->getAsRecordDecl();
5530 if (!ThisRecord->isUnion())
5533 if (
const auto *Ctor =
5534 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
5535 return Ctor->getParent() == ThisRecord;
5544template <
class Emitter>
5546 bool EvaluateConditionDecl) {
5547 for (
const auto *D : DS->
decls()) {
5552 const auto *VD = dyn_cast<VarDecl>(D);
5559 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5566template <
class Emitter>
5569 return this->emitUnsupported(RS);
5575 if (!this->
visit(RE))
5581 if (RE->getType()->isVoidType()) {
5582 if (!this->
visit(RE))
5587 if (!this->emitRVOPtr(RE))
5591 if (!this->emitPopPtr(RE))
5595 return this->emitRetVoid(RS);
5601 return this->emitRetVoid(RS);
5605 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
5611 if (
auto *CondInit = IS->
getInit())
5625 return visitChildStmt(IS->
getThen());
5627 return visitChildStmt(Else);
5633 if (!this->emitIsConstantContext(IS))
5636 if (!this->emitIsConstantContext(IS))
5638 if (!this->emitInv(IS))
5649 LabelTy LabelElse = this->getLabel();
5650 LabelTy LabelEnd = this->getLabel();
5651 if (!this->jumpFalse(LabelElse))
5653 if (!visitChildStmt(IS->
getThen()))
5655 if (!this->jump(LabelEnd))
5657 this->emitLabel(LabelElse);
5658 if (!visitChildStmt(Else))
5660 this->emitLabel(LabelEnd);
5662 LabelTy LabelEnd = this->getLabel();
5663 if (!this->jumpFalse(LabelEnd))
5665 if (!visitChildStmt(IS->
getThen()))
5667 this->emitLabel(LabelEnd);
5673template <
class Emitter>
5678 LabelTy CondLabel = this->getLabel();
5679 LabelTy EndLabel = this->getLabel();
5683 this->fallthrough(CondLabel);
5684 this->emitLabel(CondLabel);
5698 if (!this->jumpFalse(EndLabel))
5707 if (!this->jump(CondLabel))
5709 this->fallthrough(EndLabel);
5710 this->emitLabel(EndLabel);
5718 LabelTy StartLabel = this->getLabel();
5719 LabelTy EndLabel = this->getLabel();
5720 LabelTy CondLabel = this->getLabel();
5724 this->fallthrough(StartLabel);
5725 this->emitLabel(StartLabel);
5731 this->fallthrough(CondLabel);
5732 this->emitLabel(CondLabel);
5739 if (!this->jumpTrue(StartLabel))
5742 this->fallthrough(EndLabel);
5743 this->emitLabel(EndLabel);
5747template <
class Emitter>
5755 LabelTy EndLabel = this->getLabel();
5756 LabelTy CondLabel = this->getLabel();
5757 LabelTy IncLabel = this->getLabel();
5764 this->fallthrough(CondLabel);
5765 this->emitLabel(CondLabel);
5777 if (!this->jumpFalse(EndLabel))
5786 this->fallthrough(IncLabel);
5787 this->emitLabel(IncLabel);
5793 if (!this->jump(CondLabel))
5797 this->emitLabel(EndLabel);
5803template <
class Emitter>
5813 LabelTy EndLabel = this->getLabel();
5814 LabelTy CondLabel = this->getLabel();
5815 LabelTy IncLabel = this->getLabel();
5830 this->fallthrough(CondLabel);
5831 this->emitLabel(CondLabel);
5834 if (!this->jumpFalse(EndLabel))
5845 this->fallthrough(IncLabel);
5846 this->emitLabel(IncLabel);
5851 if (!this->jump(CondLabel))
5854 this->fallthrough(EndLabel);
5855 this->emitLabel(EndLabel);
5859template <
class Emitter>
5870 if (LI.BreakLabel) {
5871 TargetLabel = *LI.BreakLabel;
5872 BreakScope = LI.BreakOrContinueScope;
5878 if (LI.Name == TargetLoop) {
5879 TargetLabel = *LI.BreakLabel;
5880 BreakScope = LI.BreakOrContinueScope;
5886 assert(TargetLabel);
5890 C->emitDestruction();
5892 return this->jump(*TargetLabel);
5895template <
class Emitter>
5906 if (LI.ContinueLabel) {
5907 TargetLabel = *LI.ContinueLabel;
5908 ContinueScope = LI.BreakOrContinueScope;
5914 if (LI.Name == TargetLoop) {
5915 TargetLabel = *LI.ContinueLabel;
5916 ContinueScope = LI.BreakOrContinueScope;
5921 assert(TargetLabel);
5925 C->emitDestruction();
5927 return this->jump(*TargetLabel);
5930template <
class Emitter>
5933 if (
Cond->containsErrors())
5939 LabelTy EndLabel = this->getLabel();
5944 if (
const auto *CondInit = S->
getInit())
5955 if (!this->emitSetLocal(CondT, CondVar, S))
5965 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
5967 if (CS->caseStmtIsGNURange())
5975 if (!this->emitGetLocal(CondT, CondVar, CS))
5981 if (!this->emitEQ(ValueT, S))
5986 assert(!DefaultLabel);
5987 DefaultLabel = this->getLabel();
5994 if (!this->jump(*DefaultLabel))
5997 if (!this->jump(EndLabel))
6005 this->emitLabel(EndLabel);
6010template <
class Emitter>
6016template <
class Emitter>
6023 if (LI.DefaultLabel) {
6024 DefaultLabel = *LI.DefaultLabel;
6029 this->emitLabel(DefaultLabel);
6033template <
class Emitter>
6035 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6036 !this->Ctx.getLangOpts().MSVCCompat) {
6038 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6044 const Expr *Assumption = AA->getAssumption();
6055 if (!this->emitAssume(Assumption))
6064template <
class Emitter>
6070template <
class Emitter>
6071bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6078 assert(ClosureClass->
captures().empty());
6079 const Function *
Func = this->getFunction(LambdaCallOp);
6082 assert(
Func->hasThisPointer());
6085 if (
Func->hasRVO()) {
6086 if (!this->emitRVOPtr(MD))
6094 if (!this->emitNullPtr(0,
nullptr, MD))
6099 auto It = this->Params.find(PVD);
6100 assert(It != this->Params.end());
6104 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6105 if (!this->emitGetParam(ParamType, It->second.Offset, MD))
6109 if (!this->emitCall(
Func, 0, LambdaCallOp))
6114 return this->emitRet(*ReturnType, MD);
6117 return this->emitRetVoid(MD);
6120template <
class Emitter>
6121bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6122 if (Ctx.getLangOpts().CPlusPlus23)
6132 const Expr *InitExpr =
Init->getInit();
6134 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6138 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6148template <
class Emitter>
6150 assert(!ReturnType);
6152 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6153 const Expr *InitExpr,
6156 if (InitExpr->getType().isNull())
6160 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6163 if (!this->visit(InitExpr))
6166 bool BitField = F->isBitField();
6168 return this->emitInitThisBitField(*
T, F, FieldOffset, InitExpr);
6169 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
6174 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6177 if (
Activate && !this->emitActivate(InitExpr))
6180 if (!this->visitInitializer(InitExpr))
6183 return this->emitFinishInitPop(InitExpr);
6187 const Record *R = this->getRecord(RD);
6196 return this->emitRetVoid(Ctor);
6199 if (!this->emitThis(Ctor))
6208 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6209 this->emitRetVoid(Ctor);
6213 for (
const auto *
Init : Ctor->
inits()) {
6217 const Expr *InitExpr =
Init->getInit();
6223 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6226 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6229 if (
Init->isBaseVirtual()) {
6231 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6237 const Record::Base *B = R->
getBase(BaseDecl);
6239 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6243 if (IsUnion && !this->emitActivate(InitExpr))
6246 if (!this->visitInitializer(InitExpr))
6248 if (!this->emitFinishInitPop(InitExpr))
6253 assert(IFD->getChainingSize() >= 2);
6255 unsigned NestedFieldOffset = 0;
6256 const Record::Field *NestedField =
nullptr;
6257 for (
const NamedDecl *ND : IFD->chain()) {
6259 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6260 assert(FieldRecord);
6262 NestedField = FieldRecord->
getField(FD);
6263 assert(NestedField);
6264 IsUnion = IsUnion || FieldRecord->
isUnion();
6266 NestedFieldOffset += NestedField->Offset;
6268 assert(NestedField);
6270 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
6275 unsigned InitFieldOffset = 0;
6276 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
6278 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6279 assert(FieldRecord);
6280 NestedField = FieldRecord->
getField(FD);
6281 InitFieldOffset += NestedField->Offset;
6282 assert(NestedField);
6283 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
6285 if (!this->emitFinishInitPop(InitExpr))
6290 assert(
Init->isDelegatingInitializer());
6291 if (!this->emitThis(InitExpr))
6293 if (!this->visitInitializer(
Init->getInit()))
6295 if (!this->emitPopPtr(InitExpr))
6299 if (!
Scope.destroyLocals())
6303 if (
const auto *Body = Ctor->
getBody())
6304 if (!visitStmt(Body))
6310template <
class Emitter>
6313 const Record *R = this->getRecord(RD);
6318 if (!this->visitStmt(Dtor->
getBody()))
6322 if (!this->emitThis(Dtor))
6325 if (!this->emitCheckDestruction(Dtor))
6333 for (
const Record::Field &Field : llvm::reverse(R->
fields())) {
6337 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
6339 if (!this->emitDestructionPop(D,
SourceInfo{}))
6344 for (
const Record::Base &
Base : llvm::reverse(R->
bases())) {
6345 if (
Base.R->hasTrivialDtor())
6349 if (!this->emitRecordDestructionPop(
Base.R, {}))
6354 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
6357template <
class Emitter>
6358bool Compiler<Emitter>::compileUnionAssignmentOperator(
6360 if (!this->emitThis(MD))
6369 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
6372template <
class Emitter>
6379 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
6380 return this->compileConstructor(Ctor);
6381 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
6382 return this->compileDestructor(Dtor);
6385 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
6390 return this->compileUnionAssignmentOperator(MD);
6393 return this->emitLambdaStaticInvokerBody(MD);
6397 if (
const auto *Body = F->
getBody())
6407template <
class Emitter>
6420 if (!
Ctx.getLangOpts().CPlusPlus14)
6421 return this->emitInvalid(E);
6423 return this->emitError(E);
6425 if (!this->
visit(SubExpr))
6429 if (!this->emitIncPtr(E))
6436 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
6437 : this->emitIncf(getFPOptions(E), E);
6444 if (!
Ctx.getLangOpts().CPlusPlus14)
6445 return this->emitInvalid(E);
6447 return this->emitError(E);
6449 if (!this->
visit(SubExpr))
6453 if (!this->emitDecPtr(E))
6460 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
6461 : this->emitDecf(getFPOptions(E), E);
6468 if (!
Ctx.getLangOpts().CPlusPlus14)
6469 return this->emitInvalid(E);
6471 return this->emitError(E);
6473 if (!this->
visit(SubExpr))
6477 if (!this->emitLoadPtr(E))
6479 if (!this->emitConstUint8(1, E))
6481 if (!this->emitAddOffsetUint8(E))
6483 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6489 return this->emitIncfPop(getFPOptions(E), E);
6494 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6495 if (!this->emitLoadFloat(E))
6497 APFloat F(TargetSemantics, 1);
6498 if (!this->emitFloat(F, E))
6501 if (!this->emitAddf(getFPOptions(E), E))
6503 if (!this->emitStoreFloat(E))
6510 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6513 if (!
Ctx.getLangOpts().CPlusPlus14)
6514 return this->emitInvalid(E);
6516 return this->emitError(E);
6518 if (!this->
visit(SubExpr))
6522 if (!this->emitLoadPtr(E))
6524 if (!this->emitConstUint8(1, E))
6526 if (!this->emitSubOffsetUint8(E))
6528 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
6534 return this->emitDecfPop(getFPOptions(E), E);
6539 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
6540 if (!this->emitLoadFloat(E))
6542 APFloat F(TargetSemantics, 1);
6543 if (!this->emitFloat(F, E))
6546 if (!this->emitSubf(getFPOptions(E), E))
6548 if (!this->emitStoreFloat(E))
6555 return E->
isGLValue() || this->emitLoadPop(*
T, E);
6559 return this->emitError(E);
6562 return this->
discard(SubExpr);
6567 if (!this->emitInv(E))
6571 return this->emitCast(
PT_Bool, ET, E);
6575 return this->emitError(E);
6577 if (!this->
visit(SubExpr))
6582 return this->emitError(E);
6584 if (!this->
visit(SubExpr))
6597 return this->
discard(SubExpr);
6599 if (!this->
visit(SubExpr))
6602 if (!this->emitCheckNull(E))
6606 return this->emitNarrowPtr(E);
6611 return this->emitError(E);
6613 if (!this->
visit(SubExpr))
6623 return this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
6628 assert(
false &&
"Unhandled opcode");
6634template <
class Emitter>
6640 return this->
discard(SubExpr);
6643 auto prepareResult = [=]() ->
bool {
6648 return this->emitGetPtrLocal(*LocalIndex, E);
6655 unsigned SubExprOffset = ~0u;
6656 auto createTemp = [=, &SubExprOffset]() ->
bool {
6659 if (!this->
visit(SubExpr))
6661 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
6665 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6666 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6668 return this->emitArrayElemPop(ElemT, Index, E);
6673 if (!prepareResult())
6677 for (
unsigned I = 0; I != 2; ++I) {
6678 if (!getElem(SubExprOffset, I))
6680 if (!this->emitNeg(ElemT, E))
6682 if (!this->emitInitElem(ElemT, I, E))
6693 if (!this->
visit(SubExpr))
6695 if (!this->emitComplexBoolCast(SubExpr))
6697 if (!this->emitInv(E))
6700 return this->emitCast(
PT_Bool, ET, E);
6704 return this->emitComplexReal(SubExpr);
6707 if (!this->
visit(SubExpr))
6711 if (!this->emitConstUint8(1, E))
6713 return this->emitArrayElemPtrPopUint8(E);
6721 if (!this->
visit(SubExpr))
6724 if (!this->emitArrayElem(ElemT, 1, E))
6726 if (!this->emitNeg(ElemT, E))
6728 if (!this->emitInitElem(ElemT, 1, E))
6736 return this->emitInvalid(E);
6742template <
class Emitter>
6748 return this->
discard(SubExpr);
6751 if (UnaryOp == UO_Extension)
6754 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
6755 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
6756 return this->emitInvalid(E);
6759 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
6766 if (!this->emitGetPtrLocal(*LocalIndex, E))
6771 unsigned SubExprOffset =
6773 if (!this->
visit(SubExpr))
6775 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
6780 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
6781 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
6783 return this->emitArrayElemPop(ElemT, Index, E);
6788 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6789 if (!getElem(SubExprOffset, I))
6791 if (!this->emitNeg(ElemT, E))
6793 if (!this->emitInitElem(ElemT, I, E))
6808 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6809 if (!getElem(SubExprOffset, I))
6812 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
6814 if (!this->emitInv(E))
6816 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
6818 if (!this->emitNeg(ElemT, E))
6820 if (ElemT != ResultVecElemT &&
6821 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
6823 if (!this->emitInitElem(ResultVecElemT, I, E))
6829 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
6830 if (!getElem(SubExprOffset, I))
6833 if (!this->emitInv(E))
6836 if (!this->emitComp(ElemT, E))
6839 if (!this->emitInitElem(ElemT, I, E))
6844 llvm_unreachable(
"Unsupported unary operators should be handled up front");
6849template <
class Emitter>
6854 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
6855 return this->emitConst(ECD->getInitVal(), E);
6856 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
6858 return F && this->emitGetFnPtr(F, E);
6860 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6862 if (!this->emitGetPtrGlobal(*Index, E))
6867 return this->emitInitGlobal(*
T, *Index, E);
6884 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
6885 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
6890 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
6891 if (IsReference || !It->second.IsPtr)
6892 return this->emitGetParam(
classifyPrim(E), It->second.Offset, E);
6894 return this->emitGetPtrParam(It->second.Offset, E);
6899 const unsigned Offset = It->second.Offset;
6902 return this->emitGetPtrLocal(Offset, E);
6905 if (
auto GlobalIndex =
P.getGlobal(D)) {
6907 if (!
Ctx.getLangOpts().CPlusPlus11)
6908 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
6909 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
6912 return this->emitGetPtrGlobal(*GlobalIndex, E);
6916 auto revisit = [&](
const VarDecl *VD) ->
bool {
6919 auto VarState = this->
visitDecl(VD,
true);
6921 if (!this->emitPopCC(E))
6924 if (VarState.notCreated())
6933 if (
auto It = this->LambdaCaptures.find(D);
6934 It != this->LambdaCaptures.end()) {
6935 auto [Offset, IsPtr] = It->second;
6938 return this->emitGetThisFieldPtr(Offset, E);
6939 return this->emitGetPtrThisField(Offset, E);
6942 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
6943 DRE && DRE->refersToEnclosingVariableOrCapture()) {
6944 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
6948 if (
const auto *BD = dyn_cast<BindingDecl>(D))
6949 return this->
visit(BD->getBinding());
6953 return this->emitDummyPtr(D, E);
6958 if (!
Ctx.getLangOpts().CPlusPlus) {
6959 if (
const auto *VD = dyn_cast<VarDecl>(D);
6963 return this->emitDummyPtr(D, E);
6967 const auto *VD = dyn_cast<VarDecl>(D);
6969 return this->emitDummyPtr(D, E);
6971 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
6972 if (
T.isConstant(
Ctx.getASTContext()))
6974 return T->isReferenceType();
6978 typeShouldBeVisited(VD->
getType())) {
6980 Init && !
Init->isValueDependent()) {
6986 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7004 return this->emitDummyPtr(D, E);
7010 return this->emitDummyPtr(D, E);
7013template <
class Emitter>
7021 C->emitDestruction();
7024template <
class Emitter>
7025unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7028 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7030 return Ty->getAsCXXRecordDecl();
7032 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7033 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7035 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7039template <
class Emitter>
7046 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7051 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7052 getFPOptions(E), E);
7054 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7055 getFPOptions(E), E);
7059 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7064 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7066 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7070 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7074 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7075 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7083template <
class Emitter>
7084bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7088 return this->
discard(SubExpr);
7090 if (!this->visit(SubExpr))
7093 if (!this->emitConstUint8(0, SubExpr))
7095 return this->emitArrayElemPtrPopUint8(SubExpr);
7099 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7103template <
class Emitter>
7104bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7105 assert(!DiscardResult);
7109 if (!this->emitArrayElem(ElemT, 0, E))
7112 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7115 if (!this->emitCast(ElemT,
PT_Bool, E))
7120 LabelTy LabelTrue = this->getLabel();
7121 if (!this->jumpTrue(LabelTrue))
7124 if (!this->emitArrayElemPop(ElemT, 1, E))
7127 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7130 if (!this->emitCast(ElemT,
PT_Bool, E))
7134 LabelTy EndLabel = this->getLabel();
7135 this->jump(EndLabel);
7137 this->emitLabel(LabelTrue);
7138 if (!this->emitPopPtr(E))
7140 if (!this->emitConstBool(
true, E))
7143 this->fallthrough(EndLabel);
7144 this->emitLabel(EndLabel);
7149template <
class Emitter>
7150bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
7154 assert(!DiscardResult);
7160 LHSIsComplex =
true;
7161 ElemT = classifyComplexElementType(LHS->
getType());
7162 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
7163 if (!this->visit(LHS))
7165 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
7168 LHSIsComplex =
false;
7170 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
7171 if (!this->visit(LHS))
7173 if (!this->emitSetLocal(LHST, LHSOffset, E))
7180 RHSIsComplex =
true;
7181 ElemT = classifyComplexElementType(RHS->
getType());
7182 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
7183 if (!this->visit(RHS))
7185 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
7188 RHSIsComplex =
false;
7190 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
7191 if (!this->visit(RHS))
7193 if (!this->emitSetLocal(RHST, RHSOffset, E))
7197 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
7198 bool IsComplex) ->
bool {
7200 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
7202 return this->emitArrayElemPop(ElemT, Index, E);
7204 return this->emitGetLocal(ElemT, LocalOffset, E);
7207 for (
unsigned I = 0; I != 2; ++I) {
7209 if (!getElem(LHSOffset, I, LHSIsComplex))
7211 if (!getElem(RHSOffset, I, RHSIsComplex))
7214 if (!this->emitEQ(ElemT, E))
7217 if (!this->emitCastBoolUint8(E))
7222 if (!this->emitAddUint8(E))
7224 if (!this->emitConstUint8(2, E))
7228 if (!this->emitEQUint8(E))
7231 if (!this->emitNEUint8(E))
7238 return this->emitCast(
PT_Bool, ResT, E);
7245template <
class Emitter>
7246bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
7252 const Function *DtorFunc = getFunction(Dtor);
7255 assert(DtorFunc->hasThisPointer());
7256 assert(DtorFunc->getNumParams() == 1);
7257 return this->emitCall(DtorFunc, 0, Loc);
7262template <
class Emitter>
7263bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
7275 return this->emitPopPtr(Loc);
7277 for (ssize_t I = N - 1; I >= 1; --I) {
7278 if (!this->emitConstUint64(I, Loc))
7280 if (!this->emitArrayElemPtrUint64(Loc))
7282 if (!this->emitDestructionPop(ElemDesc, Loc))
7286 if (!this->emitConstUint64(0, Loc))
7288 if (!this->emitArrayElemPtrPopUint64(Loc))
7290 return this->emitDestructionPop(ElemDesc, Loc);
7295 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
7300template <
class Emitter>
7301bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E) {
7302 assert(!DiscardResult &&
"Should've been checked before");
7304 unsigned DummyID = P.getOrCreateDummy(D);
7306 if (!this->emitGetPtrGlobal(DummyID, E))
7314 return this->emitDecayPtr(
PT_Ptr, PT, E);
7320template <
class Emitter>
7321bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
7322 assert(!DiscardResult &&
"Should've been checked before");
7325 return this->emitConstFloat(
Floating(F), E);
7327 APInt I = F.bitcastToAPInt();
7328 return this->emitConstFloat(
7329 Floating(
const_cast<uint64_t *
>(I.getRawData()),
7330 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
7341template <
class Emitter>
7342bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
7355 if (!this->emitGetPtrLocal(*LocalIndex, E))
7365 if (!this->visit(SubExpr))
7367 }
else if (
OptPrimType FromT = classify(SubExpr)) {
7368 unsigned TempOffset =
7369 allocateLocalPrimitive(SubExpr, *FromT,
true);
7370 if (!this->visit(SubExpr))
7372 if (!this->emitSetLocal(*FromT, TempOffset, E))
7374 if (!this->emitGetPtrLocal(TempOffset, E))
7381 if (!this->emitBitCast(E))
7383 return DiscardResult ? this->emitPopPtr(E) :
true;
7387 const llvm::fltSemantics *TargetSemantics =
nullptr;
7389 TargetSemantics = &Ctx.getFloatSemantics(ToType);
7395 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
7397 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
7398 ResultBitWidth, TargetSemantics, E))
7402 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)
#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.
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.
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.
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 }.
Stmt * getStmtExprResult()
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.
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.
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.
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.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
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 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
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.
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 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.
Scope for storage declared in a compound statement.
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
std::byte * rawData()
Returns a pointer to the raw data, including metadata.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
VarCreationState visitVarDecl(const VarDecl *VD, bool Toplevel=false, bool IsConstexprUnknown=false)
Creates and initializes a variable from the given decl.
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)
bool visitDeclAndReturn(const VarDecl *VD, bool ConstantContext) override
Toplevel visitDeclAndReturn().
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.
void emitCleanup()
Emits scope cleanup instructions.
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 VisitCXXNewExpr(const CXXNewExpr *E)
const ValueDecl * InitializingDecl
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool 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)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl=nullptr, ScopeKind SC=ScopeKind::Block, bool IsConstexprUnknown=false)
Creates a local primitive value.
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)
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), const ValueDecl *ExtendingDecl=nullptr, ScopeKind=ScopeKind::Block, bool IsConstexprUnknown=false)
Allocates a space storing a local given its type.
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)
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 CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
const Field * getField(const FieldDecl *FD) const
Returns a field.
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
llvm::iterator_range< const_base_iter > bases() const
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
unsigned getNumFields() const
llvm::iterator_range< const_field_iter > fields() const
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
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(const 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.
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
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()