19#include "llvm/Support/SaveAndRestore.h"
30 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
31 CE && CE->hasAPValueResult() &&
33 return CE->getResultAsAPSInt().getBoolValue();
44 OldInitializingDecl(
Ctx->InitializingDecl) {
45 Ctx->InitializingDecl = VD;
50 this->
Ctx->InitializingDecl = OldInitializingDecl;
51 this->
Ctx->InitStack.pop_back();
64 bool NewInitializing,
bool NewToLValue)
65 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
66 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
67 Ctx->DiscardResult = NewDiscardResult;
68 Ctx->Initializing = NewInitializing;
69 Ctx->ToLValue = NewToLValue;
73 Ctx->DiscardResult = OldDiscardResult;
74 Ctx->Initializing = OldInitializing;
75 Ctx->ToLValue = OldToLValue;
82 bool OldDiscardResult;
87template <
class Emitter>
91 return Ctx->emitThis(E);
94 return Ctx->emitGetPtrFieldPop(
Offset, E);
96 return Ctx->emitGetPtrLocal(
Offset, E);
100 if (!Ctx->emitConstUint32(
Offset, E))
102 return Ctx->emitArrayElemPtrPopUint32(E);
104 return Ctx->emitRVOPtr(E);
108 llvm_unreachable(
"Unhandled InitLink kind");
124 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
125 assert(LI.Name != Name);
128 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
149 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
151 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
152 assert(LI.Name != Name);
155 this->Ctx->CaseLabels = std::move(CaseLabels);
156 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
158 DefaultLabel, Ctx->VarScope);
162 this->Ctx->CaseLabels = std::move(OldCaseLabels);
163 this->Ctx->LabelInfoStack.pop_back();
168 CaseMap OldCaseLabels;
174 Ctx->InStmtExpr =
true;
192 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
195 Ctx->LocOverride = NewValue;
200 Ctx->LocOverride = OldFlag;
205 std::optional<SourceInfo> OldFlag;
212template <
class Emitter>
220 case CK_LValueToRValue: {
231 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
237 if (
auto GlobalIndex =
P.getGlobal(D))
238 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
239 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
240 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
241 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
242 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
243 return this->emitGetParam(*SubExprT, It->second.Index, E);
255 if (!this->emitGetPtrLocal(*LocalIndex, E))
259 if (!this->
visit(SubExpr))
263 return this->emitLoadPop(*SubExprT, E);
268 return this->emitMemcpy(E);
271 case CK_DerivedToBaseMemberPointer: {
282 ->getMostRecentCXXRecordDecl();
284 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
285 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
287 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
295 case CK_BaseToDerivedMemberPointer: {
306 ->getMostRecentCXXRecordDecl();
310 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
312 PathI != PathE; ++PathI) {
313 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
314 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
316 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
323 assert(ToDecl != CurDecl);
324 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
326 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
332 case CK_UncheckedDerivedToBase:
333 case CK_DerivedToBase: {
338 if (
const auto *PT = dyn_cast<PointerType>(Ty))
339 return PT->getPointeeType()->getAsCXXRecordDecl();
340 return Ty->getAsCXXRecordDecl();
347 if (B->isVirtual()) {
348 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
350 CurType = B->getType();
352 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
353 if (!this->emitGetPtrBasePop(
356 CurType = B->getType();
363 case CK_BaseToDerived: {
366 unsigned DerivedOffset =
372 return this->emitGetPtrDerivedPop(DerivedOffset,
377 case CK_FloatingCast: {
380 return this->emitVectorConversion(E->
getSubExpr(), E);
384 if (!this->
visit(SubExpr))
386 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
390 case CK_IntegralToFloating: {
392 return this->emitVectorConversion(E->
getSubExpr(), E);
395 if (!this->
visit(SubExpr))
397 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
398 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
399 TargetSemantics, getFPOptions(E), E);
402 case CK_FloatingToBoolean: {
404 return this->emitVectorConversion(E->
getSubExpr(), E);
408 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
409 return this->emitConstBool(FL->getValue().isNonZero(), E);
410 if (!this->
visit(SubExpr))
412 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
415 case CK_FloatingToIntegral: {
417 return this->emitVectorConversion(E->
getSubExpr(), E);
420 if (!this->
visit(SubExpr))
424 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
427 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
430 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
433 case CK_NullToPointer:
434 case CK_NullToMemberPointer: {
439 if (!PointeeType.
isNull()) {
441 Desc =
P.createDescriptor(SubExpr, *T);
443 Desc =
P.createDescriptor(SubExpr, PointeeType.
getTypePtr(),
447 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
451 case CK_PointerToIntegral: {
452 if (!this->
visit(SubExpr))
458 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
464 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
466 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
467 return this->emitCastPointerIntegral(T, E);
470 case CK_ArrayToPointerDecay: {
471 if (!this->
visit(SubExpr))
473 return this->emitArrayDecay(E);
476 case CK_IntegralToPointer: {
478 assert(IntType->isIntegralOrEnumerationType());
479 if (!this->
visit(SubExpr))
487 Desc =
P.createDescriptor(SubExpr, *T);
494 if (!this->emitGetIntPtr(T, Desc, E))
502 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
505 case CK_AtomicToNonAtomic:
506 case CK_ConstructorConversion:
507 case CK_FunctionToPointerDecay:
508 case CK_NonAtomicToAtomic:
510 case CK_UserDefinedConversion:
511 case CK_AddressSpaceConversion:
512 case CK_CPointerToObjCPointerCast:
529 return this->emitBuiltinBitCast(E);
544 if (!this->
visit(SubExpr))
552 return this->emitFnPtrCast(E);
559 if (!this->
visit(SubExpr))
561 return this->emitDecayPtr(*FromT, *ToT, E);
563 case CK_IntegralToBoolean:
564 case CK_FixedPointToBoolean: {
566 return this->emitVectorConversion(E->
getSubExpr(), E);
572 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
573 return this->emitConst(IL->getValue(), E);
574 if (!this->
visit(SubExpr))
579 case CK_IntegralCast:
581 return this->emitVectorConversion(E->
getSubExpr(), E);
583 case CK_BooleanToSignedIntegral: {
590 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
595 if (!this->emitConst(IL->getValue(), SubExpr))
598 if (!this->
visit(SubExpr))
606 if (!ED->isFixed()) {
607 if (!this->emitCheckEnumValue(*FromT, ED, E))
613 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
616 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
621 if (!this->emitCast(*FromT, *ToT, E))
624 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
625 return this->emitNeg(*ToT, E);
629 case CK_PointerToBoolean:
630 case CK_MemberPointerToBoolean: {
633 if (!this->
visit(SubExpr))
635 return this->emitIsNonNull(PtrT, E);
638 case CK_IntegralComplexToBoolean:
639 case CK_FloatingComplexToBoolean: {
640 if (!this->
visit(SubExpr))
642 return this->emitComplexBoolCast(SubExpr);
645 case CK_IntegralComplexToReal:
646 case CK_FloatingComplexToReal:
647 return this->emitComplexReal(SubExpr);
649 case CK_IntegralRealToComplex:
650 case CK_FloatingRealToComplex: {
657 if (!this->emitGetPtrLocal(*LocalIndex, E))
666 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
668 return this->emitInitElem(T, 1, SubExpr);
671 case CK_IntegralComplexCast:
672 case CK_FloatingComplexCast:
673 case CK_IntegralComplexToFloatingComplex:
674 case CK_FloatingComplexToIntegralComplex: {
681 if (!this->emitGetPtrLocal(*LocalIndex, E))
688 unsigned SubExprOffset =
690 if (!this->
visit(SubExpr))
692 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
700 for (
unsigned I = 0; I != 2; ++I) {
701 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
703 if (!this->emitArrayElemPop(SourceElemT, I, E))
707 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
711 if (!this->emitInitElem(DestElemT, I, E))
717 case CK_VectorSplat: {
728 if (!this->emitGetPtrLocal(*LocalIndex, E))
734 unsigned ElemOffset =
738 if (!this->
visit(SubExpr))
743 if (!this->emitSetLocal(ElemT, ElemOffset, E))
746 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
747 if (!this->emitGetLocal(ElemT, ElemOffset, E))
749 if (!this->emitInitElem(ElemT, I, E))
756 case CK_HLSLVectorTruncation: {
761 if (!this->
visit(SubExpr))
763 return this->emitArrayElemPop(*ResultT, 0, E);
772 if (!this->emitGetPtrLocal(*LocalIndex, E))
777 if (!this->
visit(SubExpr))
779 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
783 case CK_IntegralToFixedPoint: {
784 if (!this->
visit(SubExpr))
788 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
793 return this->emitPopFixedPoint(E);
796 case CK_FloatingToFixedPoint: {
797 if (!this->
visit(SubExpr))
801 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
802 if (!this->emitCastFloatingFixedPoint(Sem, E))
805 return this->emitPopFixedPoint(E);
808 case CK_FixedPointToFloating: {
809 if (!this->
visit(SubExpr))
811 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
812 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
815 return this->emitPopFloat(E);
818 case CK_FixedPointToIntegral: {
819 if (!this->
visit(SubExpr))
822 if (!this->emitCastFixedPointIntegral(IntegralT, E))
825 return this->emitPop(IntegralT, E);
828 case CK_FixedPointCast: {
829 if (!this->
visit(SubExpr))
832 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
833 if (!this->emitCastFixedPoint(Sem, E))
836 return this->emitPopFixedPoint(E);
848 case CK_LValueBitCast:
853 case CK_HLSLArrayRValue: {
860 if (!this->emitGetPtrLocal(*LocalIndex, E))
863 if (!this->
visit(SubExpr))
865 return this->emitMemcpy(E);
868 case CK_HLSLMatrixTruncation: {
873 if (!this->
visit(SubExpr))
875 return this->emitArrayElemPop(*ResultT, 0, E);
884 if (!this->emitGetPtrLocal(*LocalIndex, E))
889 if (!this->
visit(SubExpr))
891 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
895 case CK_HLSLAggregateSplatCast: {
905 if (!this->emitGetPtrLocal(*LocalIndex, E))
915 if (!this->
visit(SubExpr))
917 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
921 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
924 case CK_HLSLElementwiseCast: {
935 unsigned SrcPtrOffset =
937 if (!this->
visit(SubExpr))
939 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
943 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
945 if (Elements.empty())
948 const HLSLFlatElement &Src = Elements[0];
949 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
951 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
958 if (!this->emitGetPtrLocal(*LocalIndex, E))
964 if (!this->
visit(SubExpr))
966 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
970 unsigned ElemCount = countHLSLFlatElements(DestType);
973 Elements.reserve(ElemCount);
974 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
979 assert(Elements.size() == ElemCount &&
980 "Source type has fewer scalar elements than the destination type");
982 return emitHLSLConstructAggregate(DestType, Elements, E);
989 const Record::Field *RF = R->getField(UnionField);
990 QualType FieldType = RF->Decl->getType();
993 if (!this->
visit(SubExpr))
995 if (RF->isBitField())
996 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
998 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1001 if (!this->emitGetPtrField(RF->Offset, E))
1003 if (!this->emitActivate(E))
1009 return this->emitInvalid(E);
1011 llvm_unreachable(
"Unhandled clang::CastKind enum");
1014template <
class Emitter>
1016 return this->emitBuiltinBitCast(E);
1019template <
class Emitter>
1024 return this->emitConst(
LE->getValue(),
LE);
1027template <
class Emitter>
1033 return this->emitFloat(F, E);
1036template <
class Emitter>
1046 if (!this->emitGetPtrLocal(*LocalIndex, E))
1053 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1055 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1060template <
class Emitter>
1068 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1073template <
class Emitter>
1078template <
class Emitter>
1105 return this->emitComplexComparison(LHS, RHS, E);
1113 if (!this->
visit(LHS))
1116 if (!this->
visit(RHS))
1119 if (!this->emitToMemberPtr(E))
1125 if (!this->emitCastMemberPtrPtr(E))
1142 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1148 if (!this->emitGetPtrLocal(*ResultIndex, E))
1155 return this->emitCMP3(*
LT, CmpInfo, E);
1158 if (!
LT || !RT || !T)
1168 return this->visitAssignment(LHS, RHS, E);
1175 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1179 return this->emitPopBool(E);
1181 return this->emitCast(
PT_Bool, *T, E);
1185 auto Discard = [
this, T, E](
bool Result) {
1193 return MaybeCastToBool(this->emitEQ(*
LT, E));
1195 return MaybeCastToBool(this->emitNE(*
LT, E));
1197 return MaybeCastToBool(this->emitLT(*
LT, E));
1199 return MaybeCastToBool(this->emitLE(*
LT, E));
1201 return MaybeCastToBool(this->emitGT(*
LT, E));
1203 return MaybeCastToBool(this->emitGE(*
LT, E));
1206 return Discard(this->emitSubf(getFPOptions(E), E));
1207 return Discard(this->emitSub(*T, E));
1210 return Discard(this->emitAddf(getFPOptions(E), E));
1211 return Discard(this->emitAdd(*T, E));
1214 return Discard(this->emitMulf(getFPOptions(E), E));
1215 return Discard(this->emitMul(*T, E));
1217 return Discard(this->emitRem(*T, E));
1220 return Discard(this->emitDivf(getFPOptions(E), E));
1221 return Discard(this->emitDiv(*T, E));
1223 return Discard(this->emitBitAnd(*T, E));
1225 return Discard(this->emitBitOr(*T, E));
1227 return Discard(this->emitShl(*
LT, *RT, E));
1229 return Discard(this->emitShr(*
LT, *RT, E));
1231 return Discard(this->emitBitXor(*T, E));
1234 llvm_unreachable(
"Already handled earlier");
1239 llvm_unreachable(
"Unhandled binary op");
1244template <
class Emitter>
1250 if ((Op != BO_Add && Op != BO_Sub) ||
1261 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1262 if (!this->
visit(E))
1265 return this->emitDecayPtr(T,
PT_Ptr, E);
1274 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1282 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1285 if (!this->emitSubPtr(IntT, ElemTypeSize.
isZero(), E))
1292 if (!visitAsPointer(RHS, *RT))
1294 if (!this->
visit(LHS))
1298 if (!visitAsPointer(LHS, *
LT))
1300 if (!this->
visit(RHS))
1311 if (!this->emitAddOffset(OffsetType, E))
1315 if (!this->emitSubOffset(OffsetType, E))
1332template <
class Emitter>
1342 LabelTy LabelTrue = this->getLabel();
1343 LabelTy LabelEnd = this->getLabel();
1347 if (!this->jumpTrue(LabelTrue, E))
1352 if (!this->jump(LabelEnd, E))
1355 this->emitLabel(LabelTrue);
1356 this->emitConstBool(
true, E);
1357 this->fallthrough(LabelEnd);
1358 this->emitLabel(LabelEnd);
1361 assert(Op == BO_LAnd);
1364 LabelTy LabelFalse = this->getLabel();
1365 LabelTy LabelEnd = this->getLabel();
1369 if (!this->jumpFalse(LabelFalse, E))
1374 if (!this->jump(LabelEnd, E))
1377 this->emitLabel(LabelFalse);
1378 this->emitConstBool(
false, E);
1379 this->fallthrough(LabelEnd);
1380 this->emitLabel(LabelEnd);
1384 return this->emitPopBool(E);
1389 return this->emitCast(
PT_Bool, *T, E);
1393template <
class Emitter>
1400 if (!this->emitGetPtrLocal(*LocalIndex, E))
1409 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1410 unsigned ResultOffset = ~0u;
1416 if (!this->emitDupPtr(E))
1418 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1423 LHSType = AT->getValueType();
1426 RHSType = AT->getValueType();
1435 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1440 if (!this->
visit(LHS))
1442 if (!this->
visit(RHS))
1444 if (!this->emitMulc(ElemT, E))
1447 return this->emitPopPtr(E);
1451 if (Op == BO_Div && RHSIsComplex) {
1458 if (!LHSIsComplex) {
1463 LHSOffset = *LocalIndex;
1465 if (!this->emitGetPtrLocal(LHSOffset, E))
1468 if (!this->
visit(LHS))
1471 if (!this->emitInitElem(ElemT, 0, E))
1474 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1476 if (!this->emitInitElem(ElemT, 1, E))
1479 if (!this->
visit(LHS))
1483 if (!this->
visit(RHS))
1485 if (!this->emitDivc(ElemT, E))
1488 return this->emitPopPtr(E);
1495 if (!this->
visit(LHS))
1497 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1502 if (!this->
visit(LHS))
1504 if (!this->emitSetLocal(LHST, LHSOffset, E))
1512 if (!this->
visit(RHS))
1514 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1519 if (!this->
visit(RHS))
1521 if (!this->emitSetLocal(RHST, RHSOffset, E))
1528 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1529 unsigned ElemIndex,
unsigned Offset,
1530 const Expr *E) ->
bool {
1532 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1534 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1537 if (ElemIndex == 0 || !LoadZero)
1544 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1547 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1554 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1557 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1560 if (!this->emitAddf(getFPOptions(E), E))
1563 if (!this->emitAdd(ResultElemT, E))
1568 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1571 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1574 if (!this->emitSubf(getFPOptions(E), E))
1577 if (!this->emitSub(ResultElemT, E))
1582 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1585 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1589 if (!this->emitMulf(getFPOptions(E), E))
1592 if (!this->emitMul(ResultElemT, E))
1597 assert(!RHSIsComplex);
1598 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1601 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1605 if (!this->emitDivf(getFPOptions(E), E))
1608 if (!this->emitDiv(ResultElemT, E))
1619 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1622 if (!this->emitPop(ResultElemT, E))
1627 return this->emitPopPtr(E);
1633template <
class Emitter>
1638 "Comma op should be handled in VisitBinaryOperator");
1652 if (!this->emitGetPtrLocal(*LocalIndex, E))
1666 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1669 if (!this->
visit(LHS))
1671 if (!this->
visit(RHS))
1673 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1676 return this->emitPopPtr(E);
1681 unsigned LHSOffset =
1683 if (!this->
visit(LHS))
1685 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1689 unsigned RHSOffset =
1691 if (!this->
visit(RHS))
1693 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1705 if (NeedIntPromot) {
1707 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1712 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1713 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1715 if (!this->emitArrayElemPop(ElemT, Index, E))
1718 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1720 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1722 }
else if (NeedIntPromot) {
1723 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1729#define EMIT_ARITH_OP(OP) \
1731 if (ElemT == PT_Float) { \
1732 if (!this->emit##OP##f(getFPOptions(E), E)) \
1735 if (!this->emit##OP(ElemT, E)) \
1741 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1742 if (!getElem(LHSOffset, ElemT, I))
1744 if (!getElem(RHSOffset, RHSElemT, I))
1756 if (!this->emitRem(ElemT, E))
1760 if (!this->emitBitAnd(OpT, E))
1764 if (!this->emitBitOr(OpT, E))
1768 if (!this->emitBitXor(OpT, E))
1772 if (!this->emitShl(OpT, RHSElemT, E))
1776 if (!this->emitShr(OpT, RHSElemT, E))
1780 if (!this->emitEQ(ElemT, E))
1784 if (!this->emitNE(ElemT, E))
1788 if (!this->emitLE(ElemT, E))
1792 if (!this->emitLT(ElemT, E))
1796 if (!this->emitGE(ElemT, E))
1800 if (!this->emitGT(ElemT, E))
1805 if (!this->emitBitAnd(ResultElemT, E))
1810 if (!this->emitBitOr(ResultElemT, E))
1814 return this->emitInvalid(E);
1823 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1825 if (!this->emitNeg(ResultElemT, E))
1831 if (NeedIntPromot &&
1832 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1836 if (!this->emitInitElem(ResultElemT, I, E))
1845template <
class Emitter>
1855 auto LHSSemaInt = LHSSema.toOpaqueInt();
1857 auto RHSSemaInt = RHSSema.toOpaqueInt();
1859 if (!this->
visit(LHS))
1867 if (!this->
visit(RHS))
1876 auto ConvertResult = [&](
bool R) ->
bool {
1880 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1881 if (ResultSema != CommonSema)
1882 return this->emitCastFixedPoint(ResultSema, E);
1886 auto MaybeCastToBool = [&](
bool Result) {
1891 return this->emitPop(T, E);
1893 return this->emitCast(
PT_Bool, T, E);
1899 return MaybeCastToBool(this->emitEQFixedPoint(E));
1901 return MaybeCastToBool(this->emitNEFixedPoint(E));
1903 return MaybeCastToBool(this->emitLTFixedPoint(E));
1905 return MaybeCastToBool(this->emitLEFixedPoint(E));
1907 return MaybeCastToBool(this->emitGTFixedPoint(E));
1909 return MaybeCastToBool(this->emitGEFixedPoint(E));
1911 return ConvertResult(this->emitAddFixedPoint(E));
1913 return ConvertResult(this->emitSubFixedPoint(E));
1915 return ConvertResult(this->emitMulFixedPoint(E));
1917 return ConvertResult(this->emitDivFixedPoint(E));
1919 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1921 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1924 return this->emitInvalid(E);
1927 llvm_unreachable(
"unhandled binop opcode");
1930template <
class Emitter>
1939 if (!this->
visit(SubExpr))
1941 if (!this->emitNegFixedPoint(E))
1944 return this->emitPopFixedPoint(E);
1950 llvm_unreachable(
"Unhandled unary opcode");
1953template <
class Emitter>
1962 return this->visitZeroInitializer(*T, QT, E);
1970 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1971 CXXRD && CXXRD->getNumVBases() > 0) {
1981 return this->visitZeroRecordInitializer(R, E);
1988 return this->visitZeroArrayInitializer(QT, E);
1992 QualType ElemQT = ComplexTy->getElementType();
1994 for (
unsigned I = 0; I < 2; ++I) {
1995 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1997 if (!this->emitInitElem(ElemT, I, E))
2004 unsigned NumVecElements = VecT->getNumElements();
2005 QualType ElemQT = VecT->getElementType();
2008 for (
unsigned I = 0; I < NumVecElements; ++I) {
2009 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2011 if (!this->emitInitElem(ElemT, I, E))
2018 unsigned NumElems = MT->getNumElementsFlattened();
2019 QualType ElemQT = MT->getElementType();
2022 for (
unsigned I = 0; I != NumElems; ++I) {
2023 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2025 if (!this->emitInitElem(ElemT, I, E))
2034template <
class Emitter>
2047 for (
const Expr *SubExpr : {LHS, RHS}) {
2048 if (!this->
visit(SubExpr)) {
2055 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2056 if (!this->emitExpandPtr(E))
2067 return this->emitError(E);
2070 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2074 if (!this->emitArrayElemPtrPop(*IndexT, E))
2077 return this->emitPopPtr(E);
2083 return this->emitLoadPop(*T, E);
2086template <
class Emitter>
2088 const Expr *ArrayFiller,
const Expr *E) {
2093 QT = AT->getValueType();
2096 if (
Inits.size() == 0)
2098 return this->emitInvalid(E);
2113 if (
Inits.size() == 0)
2114 return this->visitZeroInitializer(*T, QT, E);
2115 assert(
Inits.size() == 1);
2128 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2135 bool BitField = FieldToInit->isBitField();
2137 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2138 FieldToInit->bitWidth(), E);
2140 return this->emitInitBitField(T, FieldToInit->Offset,
2141 FieldToInit->bitWidth(), E);
2143 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2144 return this->emitInitField(T, FieldToInit->Offset, E);
2147 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2155 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2158 if (
Activate && !this->emitActivate(E))
2165 if (
Inits.size() == 0) {
2166 if (!this->visitZeroRecordInitializer(R, E))
2171 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2172 FToInit = ILE->getInitializedFieldInUnion();
2176 const Record::Field *FieldToInit = R->getField(FToInit);
2178 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2181 if (!initCompositeField(FieldToInit,
Init,
true))
2185 return this->emitFinishInit(E);
2188 assert(!R->isUnion());
2189 unsigned InitIndex = 0;
2192 while (InitIndex < R->getNumFields() &&
2193 R->getField(InitIndex)->isUnnamedBitField())
2204 const Record::Field *FieldToInit = R->getField(InitIndex);
2205 if (!initPrimitiveField(FieldToInit,
Init, *T))
2210 if (
const Record::Base *B = R->getBase(
Init->getType())) {
2211 if (!this->emitGetPtrBase(B->Offset,
Init))
2219 const Record::Field *FieldToInit = R->getField(InitIndex);
2220 if (!initCompositeField(FieldToInit,
Init))
2226 return this->emitFinishInit(E);
2231 Ctx.getASTContext().getAsConstantArrayType(QT);
2234 if (
Initializing && !this->emitCheckArrayDestSize(NumElems, E))
2237 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2241 unsigned ElementIndex = 0;
2243 if (
const auto *EmbedS =
2244 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2252 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2253 getFPOptions(E), E))
2259 return this->emitInitElem(TargetT, ElemIndex, IL);
2261 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2277 for (; ElementIndex != NumElems; ++ElementIndex) {
2283 return this->emitFinishInit(E);
2287 unsigned NumInits =
Inits.size();
2292 QualType ElemQT = ComplexTy->getElementType();
2294 if (NumInits == 0) {
2296 for (
unsigned I = 0; I < 2; ++I) {
2297 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2299 if (!this->emitInitElem(ElemT, I, E))
2302 }
else if (NumInits == 2) {
2303 unsigned InitIndex = 0;
2308 if (!this->emitInitElem(ElemT, InitIndex, E))
2317 unsigned NumVecElements = VecT->getNumElements();
2318 assert(NumVecElements >=
Inits.size());
2320 QualType ElemQT = VecT->getElementType();
2324 unsigned InitIndex = 0;
2331 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2332 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2333 InitVecT->getNumElements(), E))
2335 InitIndex += InitVecT->getNumElements();
2337 if (!this->emitInitElem(ElemT, InitIndex, E))
2343 assert(InitIndex <= NumVecElements);
2346 for (; InitIndex != NumVecElements; ++InitIndex) {
2347 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2349 if (!this->emitInitElem(ElemT, InitIndex, E))
2356 unsigned NumElems = MT->getNumElementsFlattened();
2357 assert(
Inits.size() == NumElems);
2359 QualType ElemQT = MT->getElementType();
2365 for (
unsigned I = 0; I != NumElems; ++I) {
2368 if (!this->emitInitElem(ElemT, I, E))
2379template <
class Emitter>
2386 return this->emitInitElem(*InitT, ElemIndex,
Init);
2392 if (!this->emitConstUint32(ElemIndex,
Init))
2394 if (!this->emitArrayElemPtrUint32(
Init))
2399template <
class Emitter>
2402 bool Activate,
bool IsOperatorCall) {
2404 llvm::BitVector NonNullArgs;
2405 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2408 bool ExplicitMemberFn =
false;
2409 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2410 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2412 unsigned ArgIndex = 0;
2413 for (
const Expr *Arg : Args) {
2415 if (!this->
visit(Arg))
2423 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2424 if (DeclIndex < FuncDecl->getNumParams())
2425 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2434 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2442 if (!this->emitActivate(Arg))
2446 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2449 if (!this->emitCheckNonNullArg(ArgT, Arg))
2460template <
class Emitter>
2465template <
class Emitter>
2471template <
class Emitter>
2477template <
class Emitter>
2495template <
class Emitter>
2497 auto It = E->
begin();
2498 return this->
visit(*It);
2503 bool AlignOfReturnsPreferred =
2504 ASTCtx.
getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver7;
2510 T = Ref->getPointeeType();
2512 if (T.getQualifiers().hasUnaligned())
2518 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2524template <
class Emitter>
2531 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2537 ArgType = Ref->getPointeeType();
2543 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2544 return this->emitInvalid(E);
2546 if (Kind == UETT_SizeOf)
2555 return this->emitConst(Size.getQuantity(), E);
2558 if (Kind == UETT_CountOf) {
2564 if (
const auto *CAT =
2568 return this->emitConst(CAT->getSize(), E);
2578 if (VAT->getElementType()->isArrayType()) {
2579 std::optional<APSInt> Res =
2581 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2586 return this->emitConst(*Res, E);
2591 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2611 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2614 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2624 return this->emitConst(Size.getQuantity(), E);
2627 if (Kind == UETT_VectorElements) {
2632 return this->emitConst(VT->getNumElements(), E);
2634 return this->emitSizelessVectorElementSize(E);
2637 if (Kind == UETT_VecStep) {
2639 unsigned N = VT->getNumElements();
2646 return this->emitConst(N, E);
2648 return this->emitConst(1, E);
2651 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2658 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2660 return this->emitInvalid(E);
2662 return this->emitConst(
2663 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2671template <
class Emitter>
2680 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2683 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2684 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2686 if (
Member->getType()->isReferenceType())
2687 return this->emitLoadPopPtr(E);
2696 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2697 MD && !MD->isStatic()) {
2701 if (!this->
discard(Base) && !this->emitSideEffect(E))
2716 const Record::Field *F = R->getField(FD);
2720 const auto maybeLoadValue = [&]() ->
bool {
2724 return this->emitLoadPop(*T, E);
2729 if (F->Decl->getType()->isReferenceType())
2730 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2731 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2734template <
class Emitter>
2744template <
class Emitter>
2758 if (!this->
visit(Common))
2760 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2774 for (
size_t I = 0; I != Size; ++I) {
2786template <
class Emitter>
2801 return this->emitGetLocal(SubExprT, It->second, E);
2804 if (!this->
visit(SourceExpr))
2811 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2820 return this->emitGetLocal(SubExprT, LocalIndex, E);
2824template <
class Emitter>
2847 bool IsBcpCall =
false;
2848 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2849 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2853 LabelTy LabelEnd = this->getLabel();
2854 LabelTy LabelFalse = this->getLabel();
2857 if (!this->emitPushIgnoreDiags(E))
2865 if (this->checkingForUndefinedBehavior()) {
2868 if (!this->
discard(FalseExpr))
2874 if (!this->jumpFalse(LabelFalse, E))
2879 if (!this->jump(LabelEnd, E))
2881 this->emitLabel(LabelFalse);
2885 this->fallthrough(LabelEnd);
2886 this->emitLabel(LabelEnd);
2889 return this->emitPopIgnoreDiags(E);
2893template <
class Emitter>
2899 unsigned StringIndex =
P.createGlobalString(E);
2900 return this->emitGetPtrGlobal(StringIndex, E);
2905 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2906 assert(CAT &&
"a string literal that's not a constant array?");
2911 unsigned N = std::min(ArraySize, E->
getLength());
2914 for (
unsigned I = 0; I != N; ++I) {
2917 if (CharWidth == 1) {
2918 this->emitConstSint8(CodeUnit, E);
2919 this->emitInitElemSint8(I, E);
2920 }
else if (CharWidth == 2) {
2921 this->emitConstUint16(CodeUnit, E);
2922 this->emitInitElemUint16(I, E);
2923 }
else if (CharWidth == 4) {
2924 this->emitConstUint32(CodeUnit, E);
2925 this->emitInitElemUint32(I, E);
2927 llvm_unreachable(
"unsupported character width");
2932 for (
unsigned I = N; I != ArraySize; ++I) {
2933 if (CharWidth == 1) {
2934 this->emitConstSint8(0, E);
2935 this->emitInitElemSint8(I, E);
2936 }
else if (CharWidth == 2) {
2937 this->emitConstUint16(0, E);
2938 this->emitInitElemUint16(I, E);
2939 }
else if (CharWidth == 4) {
2940 this->emitConstUint32(0, E);
2941 this->emitInitElemUint32(I, E);
2943 llvm_unreachable(
"unsupported character width");
2950template <
class Emitter>
2954 return this->emitDummyPtr(E, E);
2957template <
class Emitter>
2959 auto &A =
Ctx.getASTContext();
2968template <
class Emitter>
2976 auto &A =
Ctx.getASTContext();
2980 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2981 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2988 unsigned StringIndex =
P.createGlobalString(SL);
2989 return this->emitGetPtrGlobal(StringIndex, E);
2992template <
class Emitter>
2996 return this->emitConst(E->
getValue(), E);
2999template <
class Emitter>
3025 if (!this->emitSetLocal(*RT, TempOffset, E))
3031 if (!this->emitLoad(LHST, E))
3035 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3036 LHSComputationType, E))
3040 if (!this->emitGetLocal(*RT, TempOffset, E))
3045 if (!this->emitAddf(getFPOptions(E), E))
3049 if (!this->emitSubf(getFPOptions(E), E))
3053 if (!this->emitMulf(getFPOptions(E), E))
3057 if (!this->emitDivf(getFPOptions(E), E))
3068 return this->emitStorePop(LHST, E);
3069 return this->emitStore(LHST, E);
3072template <
class Emitter>
3081 if (Op != BO_AddAssign && Op != BO_SubAssign)
3090 if (!this->emitLoad(*
LT, LHS))
3096 if (Op == BO_AddAssign) {
3097 if (!this->emitAddOffset(*RT, E))
3100 if (!this->emitSubOffset(*RT, E))
3105 return this->emitStorePopPtr(E);
3106 return this->emitStorePtr(E);
3109template <
class Emitter>
3122 if (!
Ctx.getLangOpts().CPlusPlus14)
3123 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3125 if (!
LT || !RT || !ResultT || !LHSComputationT)
3150 if (!this->emitSetLocal(*RT, TempOffset, E))
3157 if (!this->emitLoad(*
LT, E))
3159 if (
LT != LHSComputationT &&
3165 if (!this->emitGetLocal(*RT, TempOffset, E))
3171 if (!this->emitAdd(*LHSComputationT, E))
3175 if (!this->emitSub(*LHSComputationT, E))
3179 if (!this->emitMul(*LHSComputationT, E))
3183 if (!this->emitDiv(*LHSComputationT, E))
3187 if (!this->emitRem(*LHSComputationT, E))
3191 if (!this->emitShl(*LHSComputationT, *RT, E))
3195 if (!this->emitShr(*LHSComputationT, *RT, E))
3199 if (!this->emitBitAnd(*LHSComputationT, E))
3203 if (!this->emitBitXor(*LHSComputationT, E))
3207 if (!this->emitBitOr(*LHSComputationT, E))
3211 llvm_unreachable(
"Unimplemented compound assign operator");
3215 if (ResultT != LHSComputationT &&
3216 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3222 return this->emitStoreBitFieldPop(*ResultT, E);
3223 return this->emitStorePop(*ResultT, E);
3226 return this->emitStoreBitField(*ResultT, E);
3227 return this->emitStore(*ResultT, E);
3230template <
class Emitter>
3238template <
class Emitter>
3253 if (!
Ctx.getLangOpts().CPlusPlus11)
3260 for (
const Expr *LHS : CommaLHSs) {
3282 if (!this->
visit(Inner))
3287 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3290 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3293 return this->emitGetPtrGlobal(*GlobalIndex, E);
3296 if (!this->checkLiteralType(Inner))
3299 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3305 return this->emitInitGlobalTempComp(TempDecl, E);
3318 unsigned LocalIndex =
3320 if (!this->VarScope->LocalsAlwaysEnabled &&
3321 !this->emitEnableLocal(LocalIndex, E))
3324 if (!this->
visit(Inner))
3326 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3329 return this->emitGetPtrLocal(LocalIndex, E);
3332 if (!this->checkLiteralType(Inner))
3339 if (!this->VarScope->LocalsAlwaysEnabled &&
3340 !this->emitEnableLocal(*LocalIndex, E))
3343 if (!this->emitGetPtrLocal(*LocalIndex, E))
3350template <
class Emitter>
3361 if (!this->
visit(SubExpr))
3365 return this->emitPopPtr(E);
3369template <
class Emitter>
3390 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3395 if (
P.isGlobalInitialized(*GlobalIndex))
3401 return this->emitInitGlobal(*T, *GlobalIndex, E);
3413 unsigned LocalIndex;
3417 LocalIndex = *MaybeIndex;
3421 if (!this->emitGetPtrLocal(LocalIndex, E))
3425 return this->
visit(
Init) && this->emitInit(*T, E);
3429template <
class Emitter>
3442template <
class Emitter>
3446 return this->emitConst(E->
getValue(), E);
3449template <
class Emitter>
3462 for (
const Record::Field &F : R->fields()) {
3464 if (!
Init ||
Init->containsErrors())
3472 if (!this->emitInitField(*T, F.Offset, E))
3475 if (!this->emitGetPtrField(F.Offset, E))
3486template <
class Emitter>
3493 return this->emitGetPtrGlobal(StringIndex, E);
3499template <
class Emitter>
3504 return this->emitInvalid(E);
3507template <
class Emitter>
3533 if (PointeeToT && PointeeFromT) {
3552 bool Fatal = (ToT != FromT);
3559template <
class Emitter>
3562 if (!
Ctx.getLangOpts().CPlusPlus20) {
3570 if (!this->emitCheckDynamicCast(E))
3576template <
class Emitter>
3582 return this->emitConstBool(E->
getValue(), E);
3585template <
class Emitter>
3590 if (T->isRecordType()) {
3604 if (!this->emitGetPtrLocal(*LocalIndex, E))
3612 T->getAsCXXRecordDecl()))
3622 if (!this->visitZeroRecordInitializer(R, E))
3634 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3636 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3637 if (!this->emitCheckFunctionDecl(Ctor, E))
3648 assert(
Func->hasThisPointer());
3649 assert(!
Func->hasRVO());
3653 if (!this->emitDupPtr(E))
3657 for (
const auto *Arg : E->
arguments()) {
3658 if (!this->
visit(Arg))
3662 if (
Func->isVariadic()) {
3663 uint32_t VarArgSize = 0;
3664 unsigned NumParams =
Func->getNumWrittenParams();
3665 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3669 if (!this->emitCallVar(
Func, VarArgSize, E))
3672 if (!this->emitCall(
Func, 0, E)) {
3677 (void)this->emitPopPtr(E);
3683 return this->emitPopPtr(E);
3687 if (T->isArrayType()) {
3692 if (!this->emitDupPtr(E))
3696 initArrayDimension = [&](
QualType T) ->
bool {
3697 if (!T->isArrayType()) {
3699 for (
const auto *Arg : E->
arguments()) {
3700 if (!this->
visit(Arg))
3704 return this->emitCall(
Func, 0, E);
3708 Ctx.getASTContext().getAsConstantArrayType(T);
3713 for (
size_t I = 0; I != NumElems; ++I) {
3714 if (!this->emitConstUint64(I, E))
3716 if (!this->emitArrayElemPtrUint64(E))
3718 if (!initArrayDimension(ElemTy))
3721 return this->emitPopPtr(E);
3724 return initArrayDimension(E->
getType());
3730template <
class Emitter>
3740 assert(Val.
isInt());
3742 return this->emitConst(I, E);
3749 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3750 return this->
visit(LValueExpr);
3765 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3769 const APValue &
V = UGCD->getValue();
3770 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3771 const Record::Field *F = R->getField(I);
3772 const APValue &FieldValue =
V.getStructField(I);
3778 if (!this->emitInitField(FieldT, F->Offset, E))
3786template <
class Emitter>
3792 for (
unsigned I = 0; I != N; ++I) {
3799 if (!this->
discard(ArrayIndexExpr))
3804 if (!this->
visit(ArrayIndexExpr))
3808 if (!this->emitCast(IndexT,
PT_Sint64, E))
3818 return this->emitOffsetOf(T, E, E);
3821template <
class Emitter>
3830 return this->visitZeroInitializer(*T, Ty, E);
3837 if (!this->emitGetPtrLocal(*LocalIndex, E))
3842 QualType ElemQT = CT->getElementType();
3845 for (
unsigned I = 0; I != 2; ++I) {
3846 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3848 if (!this->emitInitElem(ElemT, I, E))
3860 if (!this->emitGetPtrLocal(*LocalIndex, E))
3865 QualType ElemQT = VT->getElementType();
3868 for (
unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
3869 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3871 if (!this->emitInitElem(ElemT, I, E))
3880template <
class Emitter>
3885template <
class Emitter>
3891template <
class Emitter>
3896template <
class Emitter>
3901 return this->emitConst(E->
getValue(), E);
3904template <
class Emitter>
3909 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3923 unsigned ParamIndex = 0;
3927 if (!this->emitGetParam(PT, ParamIndex, E))
3932 return this->emitCall(F, 0, E);
3937template <
class Emitter>
3945 const Expr *PlacementDest =
nullptr;
3946 bool IsNoThrow =
false;
3951 if (PlacementArgs != 0) {
3960 if (PlacementArgs == 1) {
3968 if (!this->emitInvalidNewDeleteExpr(E, E))
3973 if (OperatorNew->isReservedGlobalPlacementOperator())
3974 PlacementDest = Arg1;
3978 return this->emitInvalid(E);
3980 }
else if (!OperatorNew
3981 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3982 return this->emitInvalidNewDeleteExpr(E, E);
3985 if (!PlacementDest) {
3990 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3993 Desc =
P.createDescriptor(
3996 false,
false,
false,
4002 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4006 const Expr *Stripped = *ArraySizeExpr;
4007 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4008 Stripped = ICE->getSubExpr())
4009 if (ICE->getCastKind() != CK_NoOp &&
4010 ICE->getCastKind() != CK_IntegralCast)
4018 if (!this->
visit(Stripped))
4020 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4023 if (PlacementDest) {
4024 if (!this->
visit(PlacementDest))
4026 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4028 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4031 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4036 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4040 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4047 size_t StaticInitElems = 0;
4048 const Expr *DynamicInit =
nullptr;
4052 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4053 StaticInitElems = CAT->getZExtSize();
4058 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4059 if (ILE->hasArrayFiller())
4060 DynamicInit = ILE->getArrayFiller();
4079 const Function *CtorFunc =
nullptr;
4080 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4084 }
else if (!DynamicInit && !ElemT)
4087 LabelTy EndLabel = this->getLabel();
4088 LabelTy StartLabel = this->getLabel();
4093 if (!this->emitDupPtr(E))
4095 if (!this->emitNullPtr(0,
nullptr, E))
4097 if (!this->emitEQPtr(E))
4099 if (!this->jumpTrue(EndLabel, E))
4106 if (!this->emitConst(StaticInitElems,
SizeT, E))
4108 if (!this->emitSetLocal(
SizeT, Iter, E))
4111 this->fallthrough(StartLabel);
4112 this->emitLabel(StartLabel);
4114 if (!this->emitGetLocal(
SizeT, Iter, E))
4116 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4118 if (!this->emitLT(
SizeT, E))
4120 if (!this->jumpFalse(EndLabel, E))
4124 if (!this->emitGetLocal(
SizeT, Iter, E))
4126 if (!this->emitArrayElemPtr(
SizeT, E))
4129 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4134 if (!this->visitZeroInitializer(InitT, ElemType, E))
4136 if (!this->emitStorePop(InitT, E))
4138 }
else if (DynamicInit) {
4140 if (!this->
visit(DynamicInit))
4142 if (!this->emitStorePop(*InitT, E))
4149 if (!this->visitZeroInitializer(
4153 if (!this->emitStorePop(*ElemT, E))
4157 if (!this->emitCall(CtorFunc, 0, E))
4162 if (!this->emitGetPtrLocal(Iter, E))
4164 if (!this->emitIncPop(
SizeT,
false, E))
4167 if (!this->jump(StartLabel, E))
4170 this->fallthrough(EndLabel);
4171 this->emitLabel(EndLabel);
4175 if (PlacementDest) {
4176 if (!this->
visit(PlacementDest))
4178 if (!this->emitCheckNewTypeMismatch(E, E))
4183 if (!this->emitAlloc(Desc, E))
4192 if (!this->emitInit(*ElemT, E))
4203 return this->emitPopPtr(E);
4208template <
class Emitter>
4214 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4215 return this->emitInvalidNewDeleteExpr(E, E);
4224template <
class Emitter>
4230 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4235 return this->emitGetFnPtr(
Func, E);
4238template <
class Emitter>
4242 auto canonType = [](
const Type *T) {
4243 return T->getCanonicalTypeUnqualified().getTypePtr();
4251 return this->emitGetTypeid(
4255 return this->emitGetTypeid(
4264 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4270 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4273 return this->emitPopPtr(E);
4277template <
class Emitter>
4281 return this->emitDummyPtr(E, E);
4282 return this->emitError(E);
4285template <
class Emitter>
4288 return this->emitDummyPtr(E, E);
4289 return this->emitError(E);
4292template <
class Emitter>
4294 assert(
Ctx.getLangOpts().CPlusPlus);
4295 return this->emitConstBool(E->
getValue(), E);
4298template <
class Emitter>
4310 return this->emitDummyPtr(GuidDecl, E);
4315 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4324 assert(
V.isStruct());
4325 assert(
V.getStructNumBases() == 0);
4329 return this->emitFinishInit(E);
4332template <
class Emitter>
4342template <
class Emitter>
4351template <
class Emitter>
4357template <
class Emitter>
4361 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4365 if (OVE->isUnique())
4381template <
class Emitter>
4386template <
class Emitter>
4388 return this->emitError(E);
4391template <
class Emitter>
4397 return this->emitDummyPtr(E, E);
4400template <
class Emitter>
4401bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4403 QualType ElemType = VT->getElementType();
4404 PrimType ElemT = classifyPrim(ElemType);
4406 PrimType SrcElemT = classifyVectorElementType(SrcType);
4412 if (!this->emitGetPtrLocal(*LocalIndex, E))
4416 unsigned SrcOffset =
4417 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4418 if (!this->visit(Src))
4420 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4423 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4424 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4426 if (!this->emitArrayElemPop(SrcElemT, I, E))
4430 if (SrcElemT != ElemT) {
4431 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4433 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4434 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4438 if (!this->emitInitElem(ElemT, I, E))
4444template <
class Emitter>
4446 return emitVectorConversion(E->
getSrcExpr(), E);
4449template <
class Emitter>
4453 return this->emitInvalid(E);
4462 assert(NumOutputElems > 0);
4468 if (!this->emitGetPtrLocal(*LocalIndex, E))
4473 unsigned VectorOffsets[2];
4474 for (
unsigned I = 0; I != 2; ++I) {
4477 if (!this->
visit(Vecs[I]))
4479 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4482 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4484 assert(ShuffleIndex >= -1);
4485 if (ShuffleIndex == -1)
4486 return this->emitInvalidShuffleVectorIndex(I, E);
4488 assert(ShuffleIndex < (NumInputElems * 2));
4489 if (!this->emitGetLocal(
PT_Ptr,
4490 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4492 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4493 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4496 if (!this->emitInitElem(ElemT, I, E))
4501 return this->emitPopPtr(E);
4506template <
class Emitter>
4511 Base->getType()->isVectorType() ||
4517 if (Indices.size() == 1) {
4522 if (!this->emitConstUint32(Indices[0], E))
4524 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4534 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4542 if (!this->emitGetPtrLocal(*ResultIndex, E))
4550 uint32_t DstIndex = 0;
4551 for (uint32_t I : Indices) {
4552 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4554 if (!this->emitArrayElemPop(ElemT, I, E))
4556 if (!this->emitInitElem(ElemT, DstIndex, E))
4566template <
class Emitter>
4570 return this->
discard(SubExpr) && this->emitInvalid(E);
4576 return this->emitDummyPtr(E, E);
4579template <
class Emitter>
4584 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4589 if (!this->
visit(SubExpr))
4591 if (!this->emitConstUint8(0, E))
4593 if (!this->emitArrayElemPtrPopUint8(E))
4595 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4600 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4602 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4604 assert(SecondFieldT ==
PT_Ptr);
4606 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4608 if (!this->emitExpandPtr(E))
4612 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4614 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4617template <
class Emitter>
4632 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4634 return this->emitUnsupported(E);
4643 return this->
Visit(E);
4650 return this->
Visit(E);
4654 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4657 if (
const auto *CE = dyn_cast<CastExpr>(E);
4659 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4666 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4669 if (
const auto *CE = dyn_cast<CastExpr>(E);
4670 CE && (CE->getCastKind() == CK_DerivedToBase ||
4671 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4672 CE->getCastKind() == CK_NoOp))
4692 if (!this->emitGetPtrLocal(*LocalIndex, E))
4702 return this->
Visit(E);
4705template <
class Emitter>
4711 return this->
Visit(E) && this->emitFinishInit(E);
4714template <
class Emitter>
4720 return this->
Visit(E) && this->emitFinishInitPop(E);
4726 return this->
Visit(E);
4737 if (!this->
visit(E))
4739 return this->emitComplexBoolCast(E);
4744 if (!this->
visit(E))
4752 return this->emitIsNonNullPtr(E);
4756 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4759 return this->emitCast(*T,
PT_Bool, E);
4762template <
class Emitter>
4766 QT = AT->getValueType();
4770 return this->emitZeroBool(E);
4772 return this->emitZeroSint8(E);
4774 return this->emitZeroUint8(E);
4776 return this->emitZeroSint16(E);
4778 return this->emitZeroUint16(E);
4780 return this->emitZeroSint32(E);
4782 return this->emitZeroUint32(E);
4784 return this->emitZeroSint64(E);
4786 return this->emitZeroUint64(E);
4788 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4790 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4792 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4795 return this->emitNullMemberPtr(0,
nullptr, E);
4797 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4798 return this->emitFloat(F, E);
4801 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
4805 llvm_unreachable(
"unknown primitive type");
4808template <
class Emitter>
4809bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4814 for (
const Record::Field &Field :
R->fields()) {
4815 if (Field.isUnnamedBitField())
4822 if (!this->visitZeroInitializer(T, QT, E))
4825 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4829 if (!this->emitInitField(T, Field.Offset, E))
4834 if (!this->emitGetPtrField(Field.Offset, E))
4840 for (uint32_t I = 0, N = D->
getNumElems(); I != N; ++I) {
4841 if (!this->visitZeroInitializer(T, ET, E))
4843 if (!this->emitInitElem(T, I, E))
4848 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4851 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4859 if (!this->emitFinishInitActivatePop(E))
4863 if (!this->emitFinishInitPop(E))
4867 for (
const Record::Base &B :
R->bases()) {
4868 if (!this->emitGetPtrBase(B.Offset, E))
4870 if (!this->visitZeroRecordInitializer(B.R, E))
4872 if (!this->emitFinishInitPop(E))
4881template <
class Emitter>
4882bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4883 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4889 for (
size_t I = 0; I != NumElems; ++I) {
4890 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4892 if (!this->emitInitElem(*ElemT, I, E))
4898 const Record *
R = getRecord(ElemType);
4902 for (
size_t I = 0; I != NumElems; ++I) {
4903 if (!this->emitConstUint32(I, E))
4905 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4907 if (!this->visitZeroRecordInitializer(R, E))
4909 if (!this->emitPopPtr(E))
4915 for (
size_t I = 0; I != NumElems; ++I) {
4916 if (!this->emitConstUint32(I, E))
4918 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4920 if (!this->visitZeroArrayInitializer(ElemType, E))
4922 if (!this->emitPopPtr(E))
4931template <
class Emitter>
4932bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4934 if (!canClassify(E->
getType()))
4937 if (!this->visit(RHS))
4939 if (!this->visit(LHS))
4946 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4950 bool Activates = refersToUnion(LHS);
4953 if (!this->emitFlip(
PT_Ptr, RHT, E))
4956 if (DiscardResult) {
4957 if (BitField && Activates)
4958 return this->emitStoreBitFieldActivatePop(RHT, E);
4960 return this->emitStoreBitFieldPop(RHT, E);
4962 return this->emitStoreActivatePop(RHT, E);
4964 return this->emitStorePop(RHT, E);
4967 auto maybeLoad = [&](
bool Result) ->
bool {
4973 return this->emitLoadPop(RHT, E);
4977 if (BitField && Activates)
4978 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4980 return maybeLoad(this->emitStoreBitField(RHT, E));
4982 return maybeLoad(this->emitStoreActivate(RHT, E));
4984 return maybeLoad(this->emitStore(RHT, E));
4987template <
class Emitter>
4988template <
typename T>
4992 return this->emitConstSint8(
Value, E);
4994 return this->emitConstUint8(
Value, E);
4996 return this->emitConstSint16(
Value, E);
4998 return this->emitConstUint16(
Value, E);
5000 return this->emitConstSint32(
Value, E);
5002 return this->emitConstUint32(
Value, E);
5004 return this->emitConstSint64(
Value, E);
5006 return this->emitConstUint64(
Value, E);
5008 return this->emitConstBool(
Value, E);
5015 llvm_unreachable(
"Invalid integral type");
5018 llvm_unreachable(
"unknown primitive type");
5021template <
class Emitter>
5022template <
typename T>
5023bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
5024 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5027template <
class Emitter>
5031 return this->emitConstIntAPS(
Value, E);
5033 return this->emitConstIntAP(
Value, E);
5035 if (
Value.isSigned())
5036 return this->emitConst(
Value.getSExtValue(), Ty, E);
5037 return this->emitConst(
Value.getZExtValue(), Ty, E);
5040template <
class Emitter>
5044 return this->emitConstIntAPS(
Value, E);
5046 return this->emitConstIntAP(
Value, E);
5049 return this->emitConst(
Value.getSExtValue(), Ty, E);
5050 return this->emitConst(
Value.getZExtValue(), Ty, E);
5053template <
class Emitter>
5054bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5055 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5058template <
class Emitter>
5071 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5072 Locals.insert({VD, Local});
5073 VarScope->addForScopeKind(Local, SC);
5074 return Local.Offset;
5077template <
class Emitter>
5082 bool IsTemporary =
false;
5083 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5086 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5087 Init = VarD->getInit();
5089 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5100 return std::nullopt;
5105 Locals.insert({Key, Local});
5106 VarScope->addForScopeKind(Local, SC);
5107 return Local.Offset;
5110template <
class Emitter>
5120 return std::nullopt;
5130 return Local.Offset;
5133template <
class Emitter>
5135 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5136 return PT->getPointeeType()->getAsCanonical<RecordType>();
5142 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5146template <
class Emitter>
5148 return P.getOrCreateRecord(RD);
5151template <
class Emitter>
5153 return Ctx.getOrCreateFunction(FD);
5156template <
class Emitter>
5160 auto maybeDestroyLocals = [&]() ->
bool {
5161 if (DestroyToplevelScope)
5162 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5163 return this->emitCheckAllocations(E);
5170 return this->emitRetVoid(E) && maybeDestroyLocals();
5178 return this->emitRet(*T, E) && maybeDestroyLocals();
5186 if (!this->emitGetPtrLocal(*LocalOffset, E))
5194 return this->emitRetValue(E) && maybeDestroyLocals();
5197 return maybeDestroyLocals() &&
false;
5200template <
class Emitter>
5202 bool DestroyToplevelScope) {
5206 return this->
visitExpr(E, DestroyToplevelScope);
5209template <
class Emitter>
5221 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5222 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5236template <
class Emitter>
5238 bool ConstantContext) {
5241 if (!ConstantContext) {
5255 auto GlobalIndex =
P.getGlobal(VD);
5256 assert(GlobalIndex);
5258 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5261 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5265 auto Local =
Locals.find(VD);
5266 assert(Local !=
Locals.end());
5268 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5271 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5281 auto GlobalIndex =
P.getGlobal(VD);
5282 assert(GlobalIndex);
5283 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5292 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5295template <
class Emitter>
5306 if (!this->isActive())
5311 if (
Init &&
Init->isValueDependent())
5315 auto checkDecl = [&]() ->
bool {
5317 return !NeedsOp || this->emitCheckDecl(VD, VD);
5324 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5327 if (
P.isGlobalInitialized(*GlobalIndex))
5331 }
else if ((GlobalIndex =
5346 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5349 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5352 if (!this->emitStartInit(
Init))
5358 if (!this->emitEndInit(
Init))
5361 return this->emitFinishInitGlobal(
Init);
5371 if (!
Init ||
Init->getType()->isVoidType())
5380 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5392 if (!this->emitCheckRefInit(
Init))
5396 return this->emitSetLocal(*VarT, Offset, VD);
5404 if (!this->emitGetPtrLocal(*Offset,
Init))
5412template <
class Emitter>
5427 Locals.insert({VD, Local});
5430 if (!this->emitGetPtrLocal(Local.Offset, VD))
5434 return this->emitDestructionPop(D, VD);
5437template <
class Emitter>
5442 return this->emitConst(Val.
getInt(), ValType, E);
5445 return this->emitFloat(F, E);
5450 if (!this->emitGetMemberPtr(MemberDecl, E))
5456 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, E))
5462 return this->emitNullMemberPtr(0,
nullptr, E);
5467 return this->emitNull(ValType, 0,
nullptr, E);
5472 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5473 return this->
visit(BaseExpr);
5478 QualType EntryType = VD->getType();
5479 for (
auto &Entry : Path) {
5481 uint64_t Index = Entry.getAsArrayIndex();
5484 if (!this->emitConst(Index,
PT_Uint64, E))
5486 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
5488 EntryType = ElemType;
5498 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5499 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5501 if (!this->emitGetPtrFieldPop(EntryOffset, E))
5503 EntryType = FD->getType();
5507 if (!this->emitGetPtrBasePop(BaseOffset,
false, E))
5509 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5521template <
class Emitter>
5529 const Record::Field *RF = R->getField(I);
5530 QualType FieldType = RF->Decl->getType();
5536 if (!this->emitInitField(*PT, RF->Offset, E))
5539 if (!this->emitGetPtrField(RF->Offset, E))
5543 if (!this->emitFinishInitPop(E))
5551 const Record::Base *RB = R->getBase(I);
5552 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5554 if (!this->emitGetPtrBase(RB->Offset, E))
5558 if (!this->emitFinishInitPop(E))
5571 const Record::Field *RF = R->getField(UnionField);
5572 QualType FieldType = RF->Decl->getType();
5577 if (RF->isBitField())
5578 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5580 return this->emitInitFieldActivate(*PT, RF->Offset, E);
5583 if (!this->emitGetPtrField(RF->Offset, E))
5585 if (!this->emitActivate(E))
5589 return this->emitPopPtr(E);
5593 const auto *ArrType = T->getAsArrayTypeUnsafe();
5594 QualType ElemType = ArrType->getElementType();
5597 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5598 const APValue &Elem = A >= InitializedElems
5605 if (!this->emitInitElem(*ElemT, A, E))
5608 if (!this->emitConstUint32(A, E))
5610 if (!this->emitArrayElemPtrUint32(E))
5614 if (!this->emitPopPtr(E))
5625template <
class Emitter>
5627 unsigned BuiltinID) {
5628 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5633 return this->emitConst(0, E);
5636 if (!this->emitStartSpeculation(E))
5638 LabelTy EndLabel = this->getLabel();
5639 if (!this->speculate(E, EndLabel))
5641 if (!this->emitEndSpeculation(E))
5643 this->fallthrough(EndLabel);
5651 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5652 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5653 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5654 BuiltinID == Builtin::BI__builtin_function_start) {
5657 return this->emitDummyPtr(E, E);
5668 if (!this->emitGetPtrLocal(*LocalIndex, E))
5673 switch (BuiltinID) {
5674 case Builtin::BI__builtin_object_size:
5675 case Builtin::BI__builtin_dynamic_object_size: {
5679 if (!this->
visit(Arg0))
5690 case Builtin::BI__assume:
5691 case Builtin::BI__builtin_assume:
5694 case Builtin::BI__atomic_is_lock_free:
5695 case Builtin::BI__atomic_always_lock_free: {
5706 for (
const auto *Arg : E->
arguments()) {
5707 if (!this->
visit(Arg))
5713 if (!this->emitCallBI(E, BuiltinID, E))
5722template <
class Emitter>
5741 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5742 DD && DD->isTrivial()) {
5744 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5746 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5747 this->emitPopPtr(E);
5755 bool HasRVO = !
ReturnType->isVoidType() && !T;
5763 if (!this->emitGetPtrLocal(*LocalIndex, E))
5771 if (!this->emitGetPtrLocal(*LocalIndex, E))
5775 if (!this->emitDupPtr(E))
5782 bool IsAssignmentOperatorCall =
false;
5783 bool ActivateLHS =
false;
5784 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5785 OCE && OCE->isAssignmentOp()) {
5789 assert(Args.size() == 2);
5790 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
5792 IsAssignmentOperatorCall =
true;
5793 std::reverse(Args.begin(), Args.end());
5799 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5800 MD && MD->isStatic()) {
5804 Args.erase(Args.begin());
5808 bool Devirtualized =
false;
5811 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5819 if (!this->
visit(Callee))
5821 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5823 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5825 if (!this->emitGetMemberPtrBase(E))
5828 const auto *InstancePtr = MC->getImplicitObjectArgument();
5835 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5836 Devirtualized =
true;
5837 if (!this->
visit(Stripped))
5840 if (!this->
visit(InstancePtr))
5844 if (!this->
visit(InstancePtr))
5848 }
else if (
const auto *PD =
5849 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5850 if (!this->emitCheckPseudoDtor(E))
5858 return this->emitEndLifetimePop(E);
5859 }
else if (!FuncDecl) {
5863 if (!this->
visit(Callee))
5865 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5874 if (IsAssignmentOperatorCall) {
5875 assert(Args.size() == 2);
5878 if (!this->emitFlip(Arg2T, Arg1T, E))
5892 assert(HasRVO ==
Func->hasRVO());
5894 bool HasQualifier =
false;
5895 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5896 HasQualifier = ME->hasQualifier();
5898 bool IsVirtual =
false;
5899 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5900 IsVirtual = !Devirtualized && MD->isVirtual();
5905 if (IsVirtual && !HasQualifier) {
5906 uint32_t VarArgSize = 0;
5907 unsigned NumParams =
5908 Func->getNumWrittenParams() +
5910 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5913 if (!this->emitCallVirt(
Func, VarArgSize, E))
5915 }
else if (
Func->isVariadic()) {
5916 uint32_t VarArgSize = 0;
5917 unsigned NumParams =
5918 Func->getNumWrittenParams() +
5920 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
5922 if (!this->emitCallVar(
Func, VarArgSize, E))
5925 if (!this->emitCall(
Func, 0, E))
5934 uint32_t ArgSize = 0;
5935 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
5941 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5943 if (!this->emitGetMemberPtrDecl(E))
5946 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
5949 if (!this->emitCallPtr(ArgSize, E, E))
5960template <
class Emitter>
5967template <
class Emitter>
5974template <
class Emitter>
5979 return this->emitConstBool(E->
getValue(), E);
5982template <
class Emitter>
5988 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
5989 return this->emitNullPtr(Val,
nullptr, E);
5992template <
class Emitter>
6000 return this->emitZero(T, E);
6003template <
class Emitter>
6008 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6009 if (this->LambdaThisCapture.Offset > 0) {
6010 if (this->LambdaThisCapture.IsPtr)
6011 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6012 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6021 return this->emitThis(E);
6036 unsigned StartIndex = 0;
6037 unsigned EndIndex = 0;
6039 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6041 EndIndex = StartIndex;
6048 for (; StartIndex > 0; --StartIndex) {
6058 if (StartIndex == 0 && EndIndex == 0)
6061 assert(StartIndex < EndIndex);
6064 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6076 case Stmt::CompoundStmtClass:
6078 case Stmt::DeclStmtClass:
6080 case Stmt::ReturnStmtClass:
6082 case Stmt::IfStmtClass:
6084 case Stmt::WhileStmtClass:
6086 case Stmt::DoStmtClass:
6088 case Stmt::ForStmtClass:
6090 case Stmt::CXXForRangeStmtClass:
6092 case Stmt::BreakStmtClass:
6094 case Stmt::ContinueStmtClass:
6096 case Stmt::SwitchStmtClass:
6098 case Stmt::CaseStmtClass:
6100 case Stmt::DefaultStmtClass:
6102 case Stmt::AttributedStmtClass:
6104 case Stmt::CXXTryStmtClass:
6106 case Stmt::NullStmtClass:
6109 case Stmt::GCCAsmStmtClass:
6110 case Stmt::MSAsmStmtClass:
6111 case Stmt::GotoStmtClass:
6112 return this->emitInvalid(S);
6113 case Stmt::LabelStmtClass:
6116 if (
const auto *E = dyn_cast<Expr>(S))
6123template <
class Emitter>
6126 for (
const auto *InnerStmt : S->
body())
6129 return Scope.destroyLocals();
6132template <
class Emitter>
6133bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6134 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6135 for (
auto *BD : DD->flat_bindings())
6136 if (
auto *KD = BD->getHoldingVar();
6137 KD && !this->visitVarDecl(KD, KD->getInit()))
6151template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6153 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6154 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6161 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6166 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6167 ICE && (ICE->getCastKind() == CK_NoOp ||
6168 ICE->getCastKind() == CK_DerivedToBase ||
6169 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6170 E = ICE->getSubExpr();
6174 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6175 const auto *ThisRecord =
6176 This->getType()->getPointeeType()->getAsRecordDecl();
6177 if (!ThisRecord->isUnion())
6180 if (
const auto *Ctor =
6181 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6182 return Ctor->getParent() == ThisRecord;
6191template <
class Emitter>
6193 bool EvaluateConditionDecl) {
6194 for (
const auto *D : DS->
decls()) {
6199 const auto *VD = dyn_cast<VarDecl>(D);
6206 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6213template <
class Emitter>
6216 return this->emitUnsupported(RS);
6222 if (!this->
visit(RE))
6228 if (RE->getType()->isVoidType()) {
6229 if (!this->
visit(RE))
6232 if (RE->containsErrors())
6237 if (!this->emitRVOPtr(RE))
6243 return this->emitRetVoid(RS);
6249 return this->emitRetVoid(RS);
6255 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6262 if (
auto *CondInit = IS->
getInit()) {
6278 return visitChildStmt(IS->
getThen());
6280 return visitChildStmt(Else);
6286 if (!this->emitIsConstantContext(IS))
6289 if (!this->emitIsConstantContext(IS))
6291 if (!this->emitInv(IS))
6305 LabelTy LabelElse = this->getLabel();
6306 LabelTy LabelEnd = this->getLabel();
6307 if (!this->jumpFalse(LabelElse, IS))
6309 if (!visitChildStmt(IS->
getThen()))
6311 if (!this->jump(LabelEnd, IS))
6313 this->emitLabel(LabelElse);
6314 if (!visitChildStmt(Else))
6316 this->emitLabel(LabelEnd);
6318 LabelTy LabelEnd = this->getLabel();
6319 if (!this->jumpFalse(LabelEnd, IS))
6321 if (!visitChildStmt(IS->
getThen()))
6323 this->emitLabel(LabelEnd);
6332template <
class Emitter>
6337 LabelTy CondLabel = this->getLabel();
6338 LabelTy EndLabel = this->getLabel();
6342 this->fallthrough(CondLabel);
6343 this->emitLabel(CondLabel);
6359 if (!this->jumpFalse(EndLabel, S))
6369 if (!this->jump(CondLabel, S))
6371 this->fallthrough(EndLabel);
6372 this->emitLabel(EndLabel);
6381 LabelTy StartLabel = this->getLabel();
6382 LabelTy EndLabel = this->getLabel();
6383 LabelTy CondLabel = this->getLabel();
6387 this->fallthrough(StartLabel);
6388 this->emitLabel(StartLabel);
6394 this->fallthrough(CondLabel);
6395 this->emitLabel(CondLabel);
6402 if (!this->jumpTrue(StartLabel, S))
6405 this->fallthrough(EndLabel);
6406 this->emitLabel(EndLabel);
6410template <
class Emitter>
6418 LabelTy EndLabel = this->getLabel();
6419 LabelTy CondLabel = this->getLabel();
6420 LabelTy IncLabel = this->getLabel();
6427 this->fallthrough(CondLabel);
6428 this->emitLabel(CondLabel);
6440 if (!this->jumpFalse(EndLabel, S))
6449 this->fallthrough(IncLabel);
6450 this->emitLabel(IncLabel);
6456 if (!this->jump(CondLabel, S))
6460 this->emitLabel(EndLabel);
6466template <
class Emitter>
6476 LabelTy EndLabel = this->getLabel();
6477 LabelTy CondLabel = this->getLabel();
6478 LabelTy IncLabel = this->getLabel();
6493 this->fallthrough(CondLabel);
6494 this->emitLabel(CondLabel);
6497 if (!this->jumpFalse(EndLabel, S))
6508 this->fallthrough(IncLabel);
6509 this->emitLabel(IncLabel);
6514 if (!this->jump(CondLabel, S))
6517 this->fallthrough(EndLabel);
6518 this->emitLabel(EndLabel);
6522template <
class Emitter>
6533 if (LI.BreakLabel) {
6534 TargetLabel = *LI.BreakLabel;
6535 BreakScope = LI.BreakOrContinueScope;
6541 if (LI.Name == TargetLoop) {
6542 TargetLabel = *LI.BreakLabel;
6543 BreakScope = LI.BreakOrContinueScope;
6554 C =
C->getParent()) {
6555 if (!
C->destroyLocals())
6559 return this->jump(*TargetLabel, S);
6562template <
class Emitter>
6573 if (LI.ContinueLabel) {
6574 TargetLabel = *LI.ContinueLabel;
6575 ContinueScope = LI.BreakOrContinueScope;
6581 if (LI.Name == TargetLoop) {
6582 TargetLabel = *LI.ContinueLabel;
6583 ContinueScope = LI.BreakOrContinueScope;
6588 assert(TargetLabel);
6591 C =
C->getParent()) {
6592 if (!
C->destroyLocals())
6596 return this->jump(*TargetLabel, S);
6599template <
class Emitter>
6602 if (
Cond->containsErrors())
6608 LabelTy EndLabel = this->getLabel();
6613 if (
const auto *CondInit = S->
getInit())
6624 if (!this->emitSetLocal(CondT, CondVar, S))
6634 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6637 if (CS->caseStmtIsGNURange()) {
6638 LabelTy EndOfRangeCheck = this->getLabel();
6639 const Expr *Low = CS->getLHS();
6640 const Expr *High = CS->getRHS();
6644 if (!this->emitGetLocal(CondT, CondVar, CS))
6646 if (!this->
visit(Low))
6649 if (!this->emitGE(
LT, S))
6651 if (!this->jumpFalse(EndOfRangeCheck, S))
6654 if (!this->emitGetLocal(CondT, CondVar, CS))
6656 if (!this->
visit(High))
6659 if (!this->emitLE(HT, S))
6663 this->emitLabel(EndOfRangeCheck);
6668 if (
Value->isValueDependent())
6673 if (!this->emitGetLocal(CondT, CondVar, CS))
6679 if (!this->emitEQ(ValueT, S))
6684 assert(!DefaultLabel);
6685 DefaultLabel = this->getLabel();
6692 if (!this->jump(*DefaultLabel, S))
6695 if (!this->jump(EndLabel, S))
6703 this->fallthrough(EndLabel);
6704 this->emitLabel(EndLabel);
6709template <
class Emitter>
6716template <
class Emitter>
6723 if (LI.DefaultLabel) {
6724 DefaultLabel = *LI.DefaultLabel;
6729 this->emitLabel(DefaultLabel);
6733template <
class Emitter>
6740 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6743 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6744 !this->Ctx.getLangOpts().MSVCCompat) {
6746 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6752 const Expr *Assumption = AA->getAssumption();
6763 if (!this->emitAssume(Assumption))
6772 if (IsMSVCConstexprAttr)
6773 return this->emitPopMSVCCE(S);
6777template <
class Emitter>
6783template <
class Emitter>
6784bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6791 assert(ClosureClass->
captures().empty());
6795 "A generic lambda's static-invoker function must be a "
6796 "template specialization");
6800 void *InsertPos =
nullptr;
6801 const FunctionDecl *CorrespondingCallOpSpecialization =
6803 assert(CorrespondingCallOpSpecialization);
6804 LambdaCallOp = CorrespondingCallOpSpecialization;
6808 assert(ClosureClass->
captures().empty());
6809 const Function *
Func = this->getFunction(LambdaCallOp);
6812 assert(
Func->hasThisPointer());
6815 if (
Func->hasRVO()) {
6816 if (!this->emitRVOPtr(MD))
6824 if (!this->emitNullPtr(0,
nullptr, MD))
6829 auto It = this->Params.find(PVD);
6830 assert(It != this->Params.end());
6834 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6835 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6839 if (!this->emitCall(
Func, 0, LambdaCallOp))
6844 return this->emitRet(*ReturnType, MD);
6847 return this->emitRetVoid(MD);
6850template <
class Emitter>
6851bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6852 if (Ctx.getLangOpts().CPlusPlus23)
6862 const Expr *InitExpr =
Init->getInit();
6864 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6868 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6878template <
class Emitter>
6880 assert(!ReturnType);
6883 if (!this->emitStartThisLifetime1(Ctor))
6886 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6887 const Expr *InitExpr,
6890 if (InitExpr->getType().isNull())
6894 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
6897 if (!this->visit(InitExpr))
6900 if (F->isBitField())
6901 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
6903 return this->emitInitThisField(*T, FieldOffset, InitExpr);
6908 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
6911 if (
Activate && !this->emitActivate(InitExpr))
6914 return this->visitInitializerPop(InitExpr);
6918 const Record *
R = this->getRecord(RD);
6921 bool IsUnion =
R->isUnion();
6931 if (!this->emitThis(Ctor))
6934 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
6937 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
6938 this->emitRetVoid(Ctor);
6941 unsigned FieldInits = 0;
6943 for (
const auto *
Init : Ctor->
inits()) {
6947 const Expr *InitExpr =
Init->getInit();
6949 const Record::Field *F =
R->getField(
Member);
6953 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
6957 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
6960 if (
Init->isBaseVirtual()) {
6961 assert(
R->getVirtualBase(BaseDecl));
6962 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
6968 const Record::Base *B =
R->getBase(BaseDecl);
6970 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
6974 if (IsUnion && !this->emitActivate(InitExpr))
6977 if (!this->visitInitializerPop(InitExpr))
6982 unsigned ChainSize = IFD->getChainingSize();
6983 assert(ChainSize >= 2);
6985 unsigned NestedFieldOffset = 0;
6986 const Record::Field *NestedField =
nullptr;
6987 for (
unsigned I = 0; I != ChainSize; ++I) {
6989 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
6990 assert(FieldRecord);
6992 NestedField = FieldRecord->
getField(FD);
6993 assert(NestedField);
6994 IsUnion = IsUnion || FieldRecord->
isUnion();
6996 NestedFieldOffset += NestedField->Offset;
6999 if (I != ChainSize - 1)
7002 assert(NestedField);
7005 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7010 unsigned InitFieldOffset = 0;
7011 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7013 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7014 assert(FieldRecord);
7015 NestedField = FieldRecord->
getField(FD);
7016 InitFieldOffset += NestedField->Offset;
7017 assert(NestedField);
7018 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7020 if (!this->emitFinishInitPop(InitExpr))
7024 InitStack.pop_back_n(ChainSize - 1);
7027 assert(
Init->isDelegatingInitializer());
7028 if (!this->emitThis(InitExpr))
7030 if (!this->visitInitializerPop(
Init->getInit()))
7034 if (!
Scope.destroyLocals())
7038 if (FieldInits !=
R->getNumFields()) {
7039 assert(FieldInits < R->getNumFields());
7041 if (!this->emitStartThisLifetime(Ctor))
7048 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7049 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7056 if (!visitStmt(Body))
7063template <
class Emitter>
7066 const Record *
R = this->getRecord(RD);
7071 if (!this->visitStmt(Dtor->
getBody()))
7075 if (!this->emitThis(Dtor))
7078 if (!this->emitCheckDestruction(Dtor))
7082 if (!
R->isUnion()) {
7086 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7090 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7092 if (!this->emitDestructionPop(D,
SourceInfo{}))
7097 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7098 if (
Base.R->hasTrivialDtor())
7102 if (!this->emitRecordDestructionPop(
Base.R, {}))
7106 if (!this->emitMarkDestroyed(Dtor))
7110 return this->emitPopPtr(Dtor) && this->emitRetVoid(Dtor);
7113template <
class Emitter>
7114bool Compiler<Emitter>::compileUnionAssignmentOperator(
7116 if (!this->emitThis(MD))
7119 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7122 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7125template <
class Emitter>
7135 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7136 return this->compileConstructor(Ctor);
7137 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(F))
7138 return this->compileDestructor(Dtor);
7141 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7146 return this->compileUnionAssignmentOperator(MD);
7149 return this->emitLambdaStaticInvokerBody(MD);
7153 if (
const auto *Body = F->
getBody())
7167 return FD->getBitWidthValue();
7170template <
class Emitter>
7183 if (!
Ctx.getLangOpts().CPlusPlus14)
7184 return this->emitInvalid(E);
7186 return this->emitError(E);
7188 if (!this->
visit(SubExpr))
7192 if (!this->emitIncPtr(E))
7199 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7200 : this->emitIncf(getFPOptions(E), E);
7212 if (!
Ctx.getLangOpts().CPlusPlus14)
7213 return this->emitInvalid(E);
7215 return this->emitError(E);
7217 if (!this->
visit(SubExpr))
7221 if (!this->emitDecPtr(E))
7228 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7229 : this->emitDecf(getFPOptions(E), E);
7242 if (!
Ctx.getLangOpts().CPlusPlus14)
7243 return this->emitInvalid(E);
7245 return this->emitError(E);
7247 if (!this->
visit(SubExpr))
7251 if (!this->emitLoadPtr(E))
7253 if (!this->emitConstUint8(1, E))
7255 if (!this->emitAddOffsetUint8(E))
7257 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7263 return this->emitIncfPop(getFPOptions(E), E);
7273 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7274 if (!this->emitLoadFloat(E))
7276 APFloat F(TargetSemantics, 1);
7277 if (!this->emitFloat(F, E))
7280 if (!this->emitAddf(getFPOptions(E), E))
7282 if (!this->emitStoreFloat(E))
7294 return E->
isGLValue() || this->emitLoadPop(*T, E);
7297 if (!
Ctx.getLangOpts().CPlusPlus14)
7298 return this->emitInvalid(E);
7300 return this->emitError(E);
7302 if (!this->
visit(SubExpr))
7306 if (!this->emitLoadPtr(E))
7308 if (!this->emitConstUint8(1, E))
7310 if (!this->emitSubOffsetUint8(E))
7312 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7318 return this->emitDecfPop(getFPOptions(E), E);
7328 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7329 if (!this->emitLoadFloat(E))
7331 APFloat F(TargetSemantics, 1);
7332 if (!this->emitFloat(F, E))
7335 if (!this->emitSubf(getFPOptions(E), E))
7337 if (!this->emitStoreFloat(E))
7349 return E->
isGLValue() || this->emitLoadPop(*T, E);
7353 return this->emitError(E);
7356 return this->
discard(SubExpr);
7361 if (!this->emitInv(E))
7365 return this->emitCast(
PT_Bool, ET, E);
7369 return this->emitError(E);
7371 if (!this->
visit(SubExpr))
7373 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7376 return this->emitError(E);
7378 if (!this->
visit(SubExpr))
7393 return this->
discard(SubExpr);
7395 if (!this->
visit(SubExpr))
7402 return this->emitNarrowPtr(E);
7407 return this->emitError(E);
7409 if (!this->
visit(SubExpr))
7411 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7423 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7428 assert(
false &&
"Unhandled opcode");
7434template <
class Emitter>
7440 return this->
discard(SubExpr);
7443 auto prepareResult = [=]() ->
bool {
7448 return this->emitGetPtrLocal(*LocalIndex, E);
7455 unsigned SubExprOffset = ~0u;
7456 auto createTemp = [=, &SubExprOffset]() ->
bool {
7459 if (!this->
visit(SubExpr))
7461 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7465 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7466 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7468 return this->emitArrayElemPop(ElemT, Index, E);
7473 if (!prepareResult())
7477 for (
unsigned I = 0; I != 2; ++I) {
7478 if (!getElem(SubExprOffset, I))
7480 if (!this->emitNeg(ElemT, E))
7482 if (!this->emitInitElem(ElemT, I, E))
7493 if (!this->
visit(SubExpr))
7495 if (!this->emitComplexBoolCast(SubExpr))
7497 if (!this->emitInv(E))
7500 return this->emitCast(
PT_Bool, ET, E);
7504 return this->emitComplexReal(SubExpr);
7507 if (!this->
visit(SubExpr))
7511 if (!this->emitConstUint8(1, E))
7513 return this->emitArrayElemPtrPopUint8(E);
7524 if (!this->emitArrayElem(ElemT, 1, E))
7526 if (!this->emitNeg(ElemT, E))
7528 if (!this->emitInitElem(ElemT, 1, E))
7536 return this->emitInvalid(E);
7542template <
class Emitter>
7548 return this->
discard(SubExpr);
7551 if (UnaryOp == UO_Extension)
7554 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7555 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7556 return this->emitInvalid(E);
7559 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7566 if (!this->emitGetPtrLocal(*LocalIndex, E))
7571 unsigned SubExprOffset =
7573 if (!this->
visit(SubExpr))
7575 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7580 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7581 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7583 return this->emitArrayElemPop(ElemT, Index, E);
7588 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7589 if (!getElem(SubExprOffset, I))
7591 if (!this->emitNeg(ElemT, E))
7593 if (!this->emitInitElem(ElemT, I, E))
7608 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7609 if (!getElem(SubExprOffset, I))
7612 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7614 if (!this->emitInv(E))
7616 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7618 if (!this->emitNeg(ElemT, E))
7620 if (ElemT != ResultVecElemT &&
7621 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7623 if (!this->emitInitElem(ResultVecElemT, I, E))
7629 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7630 if (!getElem(SubExprOffset, I))
7633 if (!this->emitInv(E))
7636 if (!this->emitComp(ElemT, E))
7639 if (!this->emitInitElem(ElemT, I, E))
7644 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7649template <
class Emitter>
7654 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7655 return this->emitConst(ECD->getInitVal(), E);
7656 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7658 return F && this->emitGetFnPtr(F, E);
7660 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7665 return this->emitInitGlobal(*T, *Index, E);
7668 if (!this->emitGetPtrGlobal(*Index, E))
7672 return this->emitFinishInit(E);
7687 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7688 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7693 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7694 if (IsReference || !It->second.IsPtr)
7695 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7697 return this->emitGetPtrParam(It->second.Index, E);
7700 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7706 const unsigned Offset = It->second.Offset;
7709 return this->emitGetRefLocal(Offset, E);
7711 return this->emitGetPtrLocal(Offset, E);
7714 if (
auto GlobalIndex =
P.getGlobal(D)) {
7716 if (!
Ctx.getLangOpts().CPlusPlus11)
7717 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7718 if (!
Ctx.getLangOpts().CPlusPlus23)
7719 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7720 return this->emitGetRefGlobal(*GlobalIndex, E);
7723 return this->emitGetPtrGlobal(*GlobalIndex, E);
7727 auto revisit = [&](
const VarDecl *VD,
7728 bool IsConstexprUnknown =
true) ->
bool {
7730 IsConstexprUnknown);
7735 if (!this->emitPopCC(E))
7738 if (VarState.notCreated())
7746 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7748 if (
auto It = this->LambdaCaptures.find(D);
7749 It != this->LambdaCaptures.end()) {
7750 auto [Offset, IsPtr] = It->second;
7753 return this->emitGetThisFieldPtr(Offset, E);
7754 return this->emitGetPtrThisField(Offset, E);
7758 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7759 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7760 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7764 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7765 return this->
visit(BD->getBinding());
7769 return this->emitDummyPtr(D, E);
7773 const auto *VD = dyn_cast<VarDecl>(D);
7775 return this->emitError(E);
7778 if (!
Ctx.getLangOpts().CPlusPlus) {
7782 return revisit(VD,
false);
7783 return this->emitDummyPtr(D, E);
7787 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7788 if (T.isConstant(
Ctx.getASTContext()))
7790 return T->isReferenceType();
7794 typeShouldBeVisited(DeclType)) {
7796 Init && !
Init->isValueDependent()) {
7802 (void)
Init->EvaluateAsInitializer(
V,
Ctx.getASTContext(), VD, Notes,
7816 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7821 return revisit(VD, IsConstexprUnknown);
7822 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7823 return revisit(VD,
true);
7830 return this->emitDummyPtr(
7834template <
class Emitter>
7840template <
class Emitter>
7851 if (!
C->destroyLocals())
7857template <
class Emitter>
7858unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7861 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7863 return Ty->getAsCXXRecordDecl();
7865 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
7866 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
7868 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
7872template <
class Emitter>
7879 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7884 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
7885 getFPOptions(E), E);
7887 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
7888 getFPOptions(E), E);
7892 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
7897 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7899 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7903 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
7907 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
7908 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
7915template <
class Emitter>
7918 assert(FromT != ToT);
7921 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
7923 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
7925 return this->emitCast(FromT, ToT, E);
7929template <
class Emitter>
7930bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
7934 return this->
discard(SubExpr);
7936 if (!this->visit(SubExpr))
7939 if (!this->emitConstUint8(0, SubExpr))
7941 return this->emitArrayElemPtrPopUint8(SubExpr);
7945 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
7949template <
class Emitter>
7950bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
7951 assert(!DiscardResult);
7955 if (!this->emitArrayElem(ElemT, 0, E))
7958 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7961 if (!this->emitCast(ElemT,
PT_Bool, E))
7966 LabelTy LabelTrue = this->getLabel();
7967 if (!this->jumpTrue(LabelTrue, E))
7970 if (!this->emitArrayElemPop(ElemT, 1, E))
7973 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
7976 if (!this->emitCast(ElemT,
PT_Bool, E))
7980 LabelTy EndLabel = this->getLabel();
7981 this->jump(EndLabel, E);
7983 this->emitLabel(LabelTrue);
7984 if (!this->emitPopPtr(E))
7986 if (!this->emitConstBool(
true, E))
7989 this->fallthrough(EndLabel);
7990 this->emitLabel(EndLabel);
7995template <
class Emitter>
7996bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8007 LHSIsComplex =
true;
8008 ElemT = classifyComplexElementType(LHS->
getType());
8009 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8010 if (!this->visit(LHS))
8012 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8015 LHSIsComplex =
false;
8017 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8018 if (!this->visit(LHS))
8020 if (!this->emitSetLocal(LHST, LHSOffset, E))
8027 RHSIsComplex =
true;
8028 ElemT = classifyComplexElementType(RHS->
getType());
8029 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8030 if (!this->visit(RHS))
8032 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8035 RHSIsComplex =
false;
8037 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8038 if (!this->visit(RHS))
8040 if (!this->emitSetLocal(RHST, RHSOffset, E))
8044 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8045 bool IsComplex) ->
bool {
8047 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8049 return this->emitArrayElemPop(ElemT, Index, E);
8051 return this->emitGetLocal(ElemT, LocalOffset, E);
8054 for (
unsigned I = 0; I != 2; ++I) {
8056 if (!getElem(LHSOffset, I, LHSIsComplex))
8058 if (!getElem(RHSOffset, I, RHSIsComplex))
8061 if (!this->emitEQ(ElemT, E))
8064 if (!this->emitCastBoolUint8(E))
8069 if (!this->emitAddUint8(E))
8071 if (!this->emitConstUint8(2, E))
8075 if (!this->emitEQUint8(E))
8078 if (!this->emitNEUint8(E))
8085 return this->emitCast(
PT_Bool, ResT, E);
8092template <
class Emitter>
8093bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8096 assert(!
R->hasTrivialDtor());
8099 const Function *DtorFunc = getFunction(Dtor);
8102 assert(DtorFunc->hasThisPointer());
8103 assert(DtorFunc->getNumParams() == 1);
8104 return this->emitCall(DtorFunc, 0, Loc);
8109template <
class Emitter>
8110bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8122 return this->emitPopPtr(Loc);
8124 for (ssize_t I = N - 1; I >= 1; --I) {
8125 if (!this->emitConstUint64(I, Loc))
8127 if (!this->emitArrayElemPtrUint64(Loc))
8129 if (!this->emitDestructionPop(ElemDesc, Loc))
8133 if (!this->emitConstUint64(0, Loc))
8135 if (!this->emitArrayElemPtrPopUint64(Loc))
8137 return this->emitDestructionPop(ElemDesc, Loc);
8142 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8147template <
class Emitter>
8148bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E,
bool CU) {
8149 assert(!DiscardResult &&
"Should've been checked before");
8150 unsigned DummyID = P.getOrCreateDummy(D, CU);
8152 if (!this->emitGetPtrGlobal(DummyID, E))
8160 return this->emitDecayPtr(
PT_Ptr, PT, E);
8166template <
class Emitter>
8167bool Compiler<Emitter>::emitFloat(
const APFloat &F,
const Expr *E) {
8169 return this->emitConstFloat(
Floating(F), E);
8171 APInt I = F.bitcastToAPInt();
8172 return this->emitConstFloat(
8173 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8174 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8185template <
class Emitter>
8186bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8199 if (!this->emitGetPtrLocal(*LocalIndex, E))
8209 if (!this->visit(SubExpr))
8211 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8212 unsigned TempOffset =
8213 allocateLocalPrimitive(SubExpr, *FromT,
true);
8214 if (!this->visit(SubExpr))
8216 if (!this->emitSetLocal(*FromT, TempOffset, E))
8218 if (!this->emitGetPtrLocal(TempOffset, E))
8225 if (!this->emitBitCast(E))
8227 return DiscardResult ? this->emitPopPtr(E) :
true;
8231 const llvm::fltSemantics *TargetSemantics =
nullptr;
8233 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8239 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8241 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8242 ResultBitWidth, TargetSemantics,
8247 return this->emitPop(*ToT, E);
8256template <
class Emitter>
8257bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8262 unsigned NumElems = 0;
8265 NumElems = VT->getNumElements();
8266 ElemType = VT->getElementType();
8268 NumElems = MT->getNumElementsFlattened();
8269 ElemType = MT->getElementType();
8272 PrimType ElemT = classifyPrim(ElemType);
8273 for (
unsigned I = 0; I != NumElems; ++I) {
8274 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8276 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8278 if (!this->emitInitElem(ElemT, I, E))
8288 QualType ArrElemType = CAT->getElementType();
8289 unsigned ArrSize = CAT->getZExtSize();
8292 for (
unsigned I = 0; I != ArrSize; ++I) {
8293 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8295 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8297 if (!this->emitInitElem(*ElemT, I, E))
8301 for (
unsigned I = 0; I != ArrSize; ++I) {
8302 if (!this->emitConstUint32(I, E))
8304 if (!this->emitArrayElemPtrUint32(E))
8306 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8308 if (!this->emitFinishInitPop(E))
8318 const Record *
R = getRecord(DestType);
8322 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8324 const Record::Base *B =
R->getBase(BS.getType());
8326 if (!this->emitGetPtrBase(B->Offset, E))
8328 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8330 if (!this->emitFinishInitPop(E))
8335 for (
const Record::Field &F :
R->fields()) {
8336 if (F.isUnnamedBitField())
8339 QualType FieldType = F.Decl->getType();
8341 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8343 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8345 if (F.isBitField()) {
8346 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8349 if (!this->emitInitField(*FieldT, F.Offset, E))
8353 if (!this->emitGetPtrField(F.Offset, E))
8355 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8357 if (!this->emitPopPtr(E))
8370template <
class Emitter>
8371unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8374 return VT->getNumElements();
8376 return MT->getNumElementsFlattened();
8380 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8384 const Record *
R = getRecord(Ty);
8388 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8390 Count += countHLSLFlatElements(BS.getType());
8392 for (
const Record::Field &F :
R->fields()) {
8393 if (F.isUnnamedBitField())
8395 Count += countHLSLFlatElements(F.Decl->getType());
8400 if (canClassify(Ty))
8409template <
class Emitter>
8410bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8411 QualType SrcType,
unsigned SrcOffset,
8416 auto saveToLocal = [&](
PrimType T) ->
bool {
8417 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8418 if (!this->emitSetLocal(T, Offset, E))
8420 Elements.push_back({Offset, T});
8426 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8427 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8428 return std::nullopt;
8433 unsigned NumElems = 0;
8436 NumElems = VT->getNumElements();
8437 ElemType = VT->getElementType();
8439 NumElems = MT->getNumElementsFlattened();
8440 ElemType = MT->getElementType();
8443 PrimType ElemT = classifyPrim(ElemType);
8444 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8445 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8447 if (!this->emitArrayElemPop(ElemT, I, E))
8449 if (!saveToLocal(ElemT))
8459 QualType ArrElemType = CAT->getElementType();
8460 unsigned ArrSize = CAT->getZExtSize();
8463 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8464 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8466 if (!this->emitArrayElemPop(*ElemT, I, E))
8468 if (!saveToLocal(*ElemT))
8472 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8473 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8475 if (!this->emitConstUint32(I, E))
8477 if (!this->emitArrayElemPtrPopUint32(E))
8482 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8493 const Record *
R = getRecord(SrcType);
8497 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8499 if (Elements.size() >= MaxElements)
8501 const Record::Base *B =
R->getBase(BS.getType());
8503 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8505 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8510 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8516 for (
const Record::Field &F :
R->fields()) {
8517 if (Elements.size() >= MaxElements)
8519 if (F.isUnnamedBitField())
8522 QualType FieldType = F.Decl->getType();
8523 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8525 if (!this->emitGetPtrFieldPop(F.Offset, E))
8529 if (!this->emitLoadPop(*FieldT, E))
8531 if (!saveToLocal(*FieldT))
8535 if (!FieldPtrOffset)
8537 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8553template <
class Emitter>
8554bool Compiler<Emitter>::emitHLSLConstructAggregate(
8560 const auto &Src = Elements[ElemIdx++];
8561 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8563 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8567 unsigned NumElems = 0;
8570 NumElems = VT->getNumElements();
8571 ElemType = VT->getElementType();
8573 NumElems = MT->getNumElementsFlattened();
8574 ElemType = MT->getElementType();
8577 PrimType DestElemT = classifyPrim(ElemType);
8578 for (
unsigned I = 0; I != NumElems; ++I) {
8579 if (!loadAndCast(DestElemT, ElemType))
8581 if (!this->emitInitElem(DestElemT, I, E))
8591 QualType ArrElemType = CAT->getElementType();
8592 unsigned ArrSize = CAT->getZExtSize();
8595 for (
unsigned I = 0; I != ArrSize; ++I) {
8596 if (!loadAndCast(*ElemT, ArrElemType))
8598 if (!this->emitInitElem(*ElemT, I, E))
8602 for (
unsigned I = 0; I != ArrSize; ++I) {
8603 if (!this->emitConstUint32(I, E))
8605 if (!this->emitArrayElemPtrUint32(E))
8607 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8609 if (!this->emitFinishInitPop(E))
8619 const Record *
R = getRecord(DestType);
8623 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8625 const Record::Base *B =
R->getBase(BS.getType());
8627 if (!this->emitGetPtrBase(B->Offset, E))
8629 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
8631 if (!this->emitFinishInitPop(E))
8636 for (
const Record::Field &F :
R->fields()) {
8637 if (F.isUnnamedBitField())
8640 QualType FieldType = F.Decl->getType();
8642 if (!loadAndCast(*FieldT, FieldType))
8644 if (F.isBitField()) {
8645 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8648 if (!this->emitInitField(*FieldT, F.Offset, E))
8652 if (!this->emitGetPtrField(F.Offset, E))
8654 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
8656 if (!this->emitPopPtr(E))
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static uint32_t getBitWidth(const Expr *E)
#define EMIT_ARITH_OP(OP)
static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx, UnaryExprOrTypeTrait Kind)
static const Expr * stripDerivedToBaseCasts(const Expr *E)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
Result
Implement __builtin_bit_cast and related operations.
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
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
APValue & getArrayFiller()
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
Represents a call to an inherited base class constructor from an inheriting constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Expr * getPlacementArg(unsigned I)
unsigned getNumPlacementArgs() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
The null pointer literal (C++11 [lex.nullptr])
Represents a list-initialization with parenthesis.
MutableArrayRef< Expr * > getInitExprs()
Represents a C++ struct/union/class.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_range captures() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
A rewritten comparison expression that was originally written using operator syntax.
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Represents the this expression in C++.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
CXXTryStmt - A C++ try block, including all handlers.
CompoundStmt * getTryBlock()
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
const FieldDecl * getTargetUnionField() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
bool hasAPValueResult() const
Represents a concrete matrix type with constant number of rows and columns.
ContinueStmt - This represents a continue.
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isInvalidDecl() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isAnyOperatorNew() const
InitListExpr * getUpdater() const
DoStmt - This represents a 'do/while' stmt.
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Represents a C11 generic selection.
Expr * getResultExpr()
Return the result expression of this controlling expression.
IfStmt - This represents an if/then/else.
bool isNonNegatedConsteval() const
bool isNegatedConsteval() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents an implicitly-generated value initialization of an object of a given type.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ArrayRef< Expr * > inits() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
uint32_t getCodeUnit(size_t i) const
unsigned getCharByteWidth() const
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Expr * getReplacement() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
bool getBoolValue() const
const APValue & getAPValue() const
bool isStoredAsBoolean() const
The base class of the type hierarchy.
bool isBooleanType() const
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isFunctionPointerType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isAtomicType() const
EnumDecl * castAsEnumDecl() const
bool isStdByteType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Represents C++ using-directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool visitAPValueInitializer(const APValue &Val, const Expr *E, QualType T)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E)
Visit an APValue.
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
const ValueDecl * InitializingDecl
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VariablesAreConstexprUnknown
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Scope used to handle temporaries in toplevel variable declarations.
DeclScope(Compiler< Emitter > *Ctx, const ValueDecl *VD)
Wrapper around fixed point types.
static FixedPoint zero(llvm::FixedPointSemantics Sem)
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
bool hasThisPointer() const
bool hasRVO() const
Checks if the first argument is a RVO pointer.
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
LocalScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
Sets the context for break/continue statements.
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
LoopScope(Compiler< Emitter > *Ctx, const Stmt *Name, LabelTy BreakLabel, LabelTy ContinueLabel)
PrimType value_or(PrimType PT) const
Scope used to handle initialization methods.
OptionScope(Compiler< Emitter > *Ctx, bool NewDiscardResult, bool NewInitializing, bool NewToLValue)
Root constructor, compiling or discarding primitives.
Context to manage declaration lifetimes.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
const Field * getField(unsigned I) const
const Base * getBase(unsigned I) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
Describes the statement/declaration an opcode was generated from.
StmtExprScope(Compiler< Emitter > *Ctx)
typename Compiler< Emitter >::LabelTy LabelTy
typename Compiler< Emitter >::OptLabelTy OptLabelTy
typename Compiler< Emitter >::LabelInfo LabelInfo
typename Compiler< Emitter >::CaseMap CaseMap
SwitchScope(Compiler< Emitter > *Ctx, const Stmt *Name, CaseMap &&CaseLabels, LabelTy BreakLabel, OptLabelTy DefaultLabel)
Scope chain managing the variable lifetimes.
Compiler< Emitter > * Ctx
Compiler instance.
virtual void addLocal(Scope::Local Local)
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
static bool Activate(InterpState &S, CodePtr OpPC)
constexpr bool isPtrType(PrimType T)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool InitScope(InterpState &S, CodePtr OpPC, uint32_t I)
constexpr bool isIntegerOrBoolType(PrimType T)
static void discard(InterpStack &Stk, PrimType T)
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
bool Init(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
U cast(CodeGen::Address addr)
int const char * function
Describes a memory block created by an allocation site.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Descriptor *const ElemDesc
Descriptor of the array element.
static constexpr MetadataSize InlineDescMD
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
static InitLink InitList()
static InitLink Elem(unsigned Index)
bool emit(Compiler< Emitter > *Ctx, const Expr *E) const
static InitLink Field(unsigned Offset)
static InitLink Decl(const ValueDecl *D)
static InitLink Temp(unsigned Offset)
Information about a local's storage.
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
static VarCreationState NotCreated()