20#include "llvm/Support/SaveAndRestore.h"
31 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
32 CE && CE->hasAPValueResult() &&
34 return CE->getResultAsAPSInt().getBoolValue();
45 OldInitializingDecl(
Ctx->InitializingDecl) {
46 Ctx->InitializingDecl = VD;
51 this->
Ctx->InitializingDecl = OldInitializingDecl;
52 this->
Ctx->InitStack.pop_back();
65 bool NewInitializing,
bool NewToLValue)
66 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
67 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
68 Ctx->DiscardResult = NewDiscardResult;
69 Ctx->Initializing = NewInitializing;
70 Ctx->ToLValue = NewToLValue;
74 Ctx->DiscardResult = OldDiscardResult;
75 Ctx->Initializing = OldInitializing;
76 Ctx->ToLValue = OldToLValue;
83 bool OldDiscardResult;
88template <
class Emitter>
92 return Ctx->emitThis(E);
95 return Ctx->emitGetPtrFieldPop(
Offset, E);
97 return Ctx->emitGetPtrLocal(
Offset, E);
101 if (!Ctx->emitConstUint32(
Offset, E))
103 return Ctx->emitArrayElemPtrPopUint32(E);
105 return Ctx->emitRVOPtr(E);
109 llvm_unreachable(
"Unhandled InitLink kind");
125 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
126 assert(LI.Name != Name);
129 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
150 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
152 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
153 assert(LI.Name != Name);
156 this->Ctx->CaseLabels = std::move(CaseLabels);
157 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
159 DefaultLabel, Ctx->VarScope);
163 this->Ctx->CaseLabels = std::move(OldCaseLabels);
164 this->Ctx->LabelInfoStack.pop_back();
169 CaseMap OldCaseLabels;
180 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
183 Ctx->LocOverride = NewValue;
188 Ctx->LocOverride = OldFlag;
193 std::optional<SourceInfo> OldFlag;
200template <
class Emitter>
208 case CK_LValueToRValue: {
219 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
225 if (
auto GlobalIndex =
P.getGlobal(D))
226 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
227 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
228 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
229 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
230 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
231 return this->emitGetParam(*SubExprT, It->second.Index, E);
243 if (!this->emitGetPtrLocal(*LocalIndex, E))
247 if (!this->
visit(SubExpr))
251 return this->emitLoadPop(*SubExprT, E);
256 return this->emitMemcpy(E);
259 case CK_DerivedToBaseMemberPointer: {
270 ->getMostRecentCXXRecordDecl();
272 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
273 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
275 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
283 case CK_BaseToDerivedMemberPointer: {
294 ->getMostRecentCXXRecordDecl();
298 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
300 PathI != PathE; ++PathI) {
301 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
302 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
304 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
311 assert(ToDecl != CurDecl);
312 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
314 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
320 case CK_UncheckedDerivedToBase:
321 case CK_DerivedToBase: {
326 if (
const auto *PT = dyn_cast<PointerType>(Ty))
327 return PT->getPointeeType()->getAsCXXRecordDecl();
328 return Ty->getAsCXXRecordDecl();
335 if (B->isVirtual()) {
336 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
338 CurType = B->getType();
340 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
341 if (!this->emitGetPtrBasePop(
344 CurType = B->getType();
351 case CK_BaseToDerived: {
354 unsigned DerivedOffset =
360 return this->emitGetPtrDerivedPop(DerivedOffset,
365 case CK_FloatingCast: {
368 return this->emitVectorConversion(E->
getSubExpr(), E);
372 if (!this->
visit(SubExpr))
374 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
378 case CK_IntegralToFloating: {
380 return this->emitVectorConversion(E->
getSubExpr(), E);
383 if (!this->
visit(SubExpr))
385 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
386 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
387 TargetSemantics, getFPOptions(E), E);
390 case CK_FloatingToBoolean: {
392 return this->emitVectorConversion(E->
getSubExpr(), E);
396 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
397 return this->emitConstBool(FL->getValue().isNonZero(), E);
398 if (!this->
visit(SubExpr))
400 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
403 case CK_FloatingToIntegral: {
405 return this->emitVectorConversion(E->
getSubExpr(), E);
408 if (!this->
visit(SubExpr))
412 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
415 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
418 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
421 case CK_NullToPointer:
422 case CK_NullToMemberPointer: {
425 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
430 case CK_PointerToIntegral: {
431 if (!this->
visit(SubExpr))
437 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
443 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
445 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
446 return this->emitCastPointerIntegral(T, E);
449 case CK_ArrayToPointerDecay: {
450 if (!this->
visit(SubExpr))
452 return this->emitArrayDecay(E);
455 case CK_IntegralToPointer: {
457 assert(IntType->isIntegralOrEnumerationType());
458 if (!this->
visit(SubExpr))
472 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
475 case CK_AtomicToNonAtomic:
476 case CK_ConstructorConversion:
477 case CK_FunctionToPointerDecay:
478 case CK_NonAtomicToAtomic:
480 case CK_UserDefinedConversion:
481 case CK_AddressSpaceConversion:
482 case CK_CPointerToObjCPointerCast:
499 return this->emitBuiltinBitCast(E);
514 if (!this->
visit(SubExpr))
522 return this->emitFnPtrCast(E);
529 if (!this->
visit(SubExpr))
531 return this->emitDecayPtr(*FromT, *ToT, E);
533 case CK_IntegralToBoolean:
534 case CK_FixedPointToBoolean: {
536 return this->emitVectorConversion(E->
getSubExpr(), E);
542 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
543 return this->emitConst(IL->getValue(), E);
544 if (!this->
visit(SubExpr))
549 case CK_IntegralCast:
551 return this->emitVectorConversion(E->
getSubExpr(), E);
553 case CK_BooleanToSignedIntegral: {
560 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
565 if (!this->emitConst(IL->getValue(), SubExpr))
568 if (!this->
visit(SubExpr))
576 if (!ED->isFixed()) {
577 if (!this->emitCheckEnumValue(*FromT, ED, E))
583 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
586 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
591 if (!this->emitCast(*FromT, *ToT, E))
594 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
595 return this->emitNeg(*ToT, E);
599 case CK_PointerToBoolean:
600 case CK_MemberPointerToBoolean: {
603 if (!this->
visit(SubExpr))
605 return this->emitIsNonNull(PtrT, E);
608 case CK_IntegralComplexToBoolean:
609 case CK_FloatingComplexToBoolean: {
610 if (!this->
visit(SubExpr))
612 return this->emitComplexBoolCast(SubExpr);
615 case CK_IntegralComplexToReal:
616 case CK_FloatingComplexToReal:
617 return this->emitComplexReal(SubExpr);
619 case CK_IntegralRealToComplex:
620 case CK_FloatingRealToComplex: {
627 if (!this->emitGetPtrLocal(*LocalIndex, E))
636 if (!this->visitZeroInitializer(T, SubExpr->
getType(), SubExpr))
638 return this->emitInitElem(T, 1, SubExpr);
641 case CK_IntegralComplexCast:
642 case CK_FloatingComplexCast:
643 case CK_IntegralComplexToFloatingComplex:
644 case CK_FloatingComplexToIntegralComplex: {
651 if (!this->emitGetPtrLocal(*LocalIndex, E))
658 unsigned SubExprOffset =
660 if (!this->
visit(SubExpr))
662 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
670 for (
unsigned I = 0; I != 2; ++I) {
671 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
673 if (!this->emitArrayElemPop(SourceElemT, I, E))
677 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
681 if (!this->emitInitElem(DestElemT, I, E))
687 case CK_VectorSplat: {
698 if (!this->emitGetPtrLocal(*LocalIndex, E))
704 unsigned ElemOffset =
708 if (!this->
visit(SubExpr))
713 if (!this->emitSetLocal(ElemT, ElemOffset, E))
716 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
717 if (!this->emitGetLocal(ElemT, ElemOffset, E))
719 if (!this->emitInitElem(ElemT, I, E))
726 case CK_HLSLVectorTruncation: {
731 if (!this->
visit(SubExpr))
733 return this->emitArrayElemPop(*ResultT, 0, E);
742 if (!this->emitGetPtrLocal(*LocalIndex, E))
747 if (!this->
visit(SubExpr))
749 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
753 case CK_IntegralToFixedPoint: {
754 if (!this->
visit(SubExpr))
758 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
763 return this->emitPopFixedPoint(E);
766 case CK_FloatingToFixedPoint: {
767 if (!this->
visit(SubExpr))
771 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
772 if (!this->emitCastFloatingFixedPoint(Sem, E))
775 return this->emitPopFixedPoint(E);
778 case CK_FixedPointToFloating: {
779 if (!this->
visit(SubExpr))
781 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
782 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
785 return this->emitPopFloat(E);
788 case CK_FixedPointToIntegral: {
789 if (!this->
visit(SubExpr))
792 if (!this->emitCastFixedPointIntegral(IntegralT, E))
795 return this->emitPop(IntegralT, E);
798 case CK_FixedPointCast: {
799 if (!this->
visit(SubExpr))
802 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
803 if (!this->emitCastFixedPoint(Sem, E))
806 return this->emitPopFixedPoint(E);
814 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
816 case CK_LValueBitCast:
821 case CK_HLSLArrayRValue: {
828 if (!this->emitGetPtrLocal(*LocalIndex, E))
831 if (!this->
visit(SubExpr))
833 return this->emitMemcpy(E);
836 case CK_HLSLMatrixTruncation: {
841 if (!this->
visit(SubExpr))
843 return this->emitArrayElemPop(*ResultT, 0, E);
852 if (!this->emitGetPtrLocal(*LocalIndex, E))
857 if (!this->
visit(SubExpr))
859 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
863 case CK_HLSLAggregateSplatCast: {
873 if (!this->emitGetPtrLocal(*LocalIndex, E))
883 if (!this->
visit(SubExpr))
885 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
889 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
892 case CK_HLSLElementwiseCast: {
903 unsigned SrcPtrOffset =
905 if (!this->
visit(SubExpr))
907 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
911 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
913 if (Elements.empty())
916 const HLSLFlatElement &Src = Elements[0];
917 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
919 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
926 if (!this->emitGetPtrLocal(*LocalIndex, E))
932 if (!this->
visit(SubExpr))
934 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
938 unsigned ElemCount = countHLSLFlatElements(DestType);
941 Elements.reserve(ElemCount);
942 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
947 assert(Elements.size() == ElemCount &&
948 "Source type has fewer scalar elements than the destination type");
950 return emitHLSLConstructAggregate(DestType, Elements, E);
957 const Record::Field *RF = R->getField(UnionField);
958 QualType FieldType = RF->Decl->getType();
961 if (!this->
visit(SubExpr))
963 if (RF->isBitField())
964 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
966 return this->emitInitFieldActivate(*PT, RF->Offset, E);
969 if (!this->emitGetPtrField(RF->Offset, E))
971 if (!this->emitActivate(E))
977 return this->emitInvalid(E);
979 llvm_unreachable(
"Unhandled clang::CastKind enum");
982template <
class Emitter>
984 return this->emitBuiltinBitCast(E);
987template <
class Emitter>
992 return this->emitConst(
LE->getValue(),
LE);
995template <
class Emitter>
1001 return this->emitFloat(F, E);
1004template <
class Emitter>
1014 if (!this->emitGetPtrLocal(*LocalIndex, E))
1021 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1023 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1028template <
class Emitter>
1036 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1041template <
class Emitter>
1046template <
class Emitter>
1073 return this->emitComplexComparison(LHS, RHS, E);
1081 if (!this->
visit(LHS))
1084 if (!this->
visit(RHS))
1087 if (!this->emitToMemberPtr(E))
1093 if (!this->emitCastMemberPtrPtr(E))
1110 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1116 if (!this->emitGetPtrLocal(*ResultIndex, E))
1123 return this->emitCMP3(*
LT, CmpInfo, E);
1126 if (!
LT || !RT || !T)
1136 return this->visitAssignment(LHS, RHS, E);
1143 auto MaybeCastToBool = [
this, T, E](
bool Result) {
1147 return this->emitPopBool(E);
1149 return this->emitCast(
PT_Bool, *T, E);
1153 auto Discard = [
this, T, E](
bool Result) {
1161 return MaybeCastToBool(this->emitEQ(*
LT, E));
1163 return MaybeCastToBool(this->emitNE(*
LT, E));
1165 return MaybeCastToBool(this->emitLT(*
LT, E));
1167 return MaybeCastToBool(this->emitLE(*
LT, E));
1169 return MaybeCastToBool(this->emitGT(*
LT, E));
1171 return MaybeCastToBool(this->emitGE(*
LT, E));
1174 return Discard(this->emitSubf(getFPOptions(E), E));
1175 return Discard(this->emitSub(*T, E));
1178 return Discard(this->emitAddf(getFPOptions(E), E));
1179 return Discard(this->emitAdd(*T, E));
1182 return Discard(this->emitMulf(getFPOptions(E), E));
1183 return Discard(this->emitMul(*T, E));
1185 return Discard(this->emitRem(*T, E));
1188 return Discard(this->emitDivf(getFPOptions(E), E));
1189 return Discard(this->emitDiv(*T, E));
1191 return Discard(this->emitBitAnd(*T, E));
1193 return Discard(this->emitBitOr(*T, E));
1195 return Discard(this->emitShl(*
LT, *RT, E));
1197 return Discard(this->emitShr(*
LT, *RT, E));
1199 return Discard(this->emitBitXor(*T, E));
1202 llvm_unreachable(
"Already handled earlier");
1207 llvm_unreachable(
"Unhandled binary op");
1212template <
class Emitter>
1218 if ((Op != BO_Add && Op != BO_Sub) ||
1229 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1230 if (!this->
visit(E))
1233 return this->emitDecayPtr(T,
PT_Ptr, E);
1242 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1250 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1253 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1260 if (!visitAsPointer(RHS, *RT))
1262 if (!this->
visit(LHS))
1266 if (!visitAsPointer(LHS, *
LT))
1268 if (!this->
visit(RHS))
1279 if (!this->emitAddOffset(OffsetType, E))
1283 if (!this->emitSubOffset(OffsetType, E))
1300template <
class Emitter>
1310 LabelTy LabelTrue = this->getLabel();
1311 LabelTy LabelEnd = this->getLabel();
1315 if (!this->jumpTrue(LabelTrue, E))
1320 if (!this->jump(LabelEnd, E))
1323 this->emitLabel(LabelTrue);
1324 this->emitConstBool(
true, E);
1325 this->fallthrough(LabelEnd);
1326 this->emitLabel(LabelEnd);
1329 assert(Op == BO_LAnd);
1332 LabelTy LabelFalse = this->getLabel();
1333 LabelTy LabelEnd = this->getLabel();
1337 if (!this->jumpFalse(LabelFalse, E))
1342 if (!this->jump(LabelEnd, E))
1345 this->emitLabel(LabelFalse);
1346 this->emitConstBool(
false, E);
1347 this->fallthrough(LabelEnd);
1348 this->emitLabel(LabelEnd);
1352 return this->emitPopBool(E);
1357 return this->emitCast(
PT_Bool, *T, E);
1361template <
class Emitter>
1368 if (!this->emitGetPtrLocal(*LocalIndex, E))
1377 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1378 unsigned ResultOffset = ~0u;
1384 if (!this->emitDupPtr(E))
1386 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1391 LHSType = AT->getValueType();
1394 RHSType = AT->getValueType();
1403 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1408 if (!this->
visit(LHS))
1410 if (!this->
visit(RHS))
1412 if (!this->emitMulc(ElemT, E))
1415 return this->emitPopPtr(E);
1419 if (Op == BO_Div && RHSIsComplex) {
1426 if (!LHSIsComplex) {
1431 LHSOffset = *LocalIndex;
1433 if (!this->emitGetPtrLocal(LHSOffset, E))
1436 if (!this->
visit(LHS))
1439 if (!this->emitInitElem(ElemT, 0, E))
1442 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1444 if (!this->emitInitElem(ElemT, 1, E))
1447 if (!this->
visit(LHS))
1451 if (!this->
visit(RHS))
1453 if (!this->emitDivc(ElemT, E))
1456 return this->emitPopPtr(E);
1463 if (!this->
visit(LHS))
1465 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1470 if (!this->
visit(LHS))
1472 if (!this->emitSetLocal(LHST, LHSOffset, E))
1480 if (!this->
visit(RHS))
1482 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1487 if (!this->
visit(RHS))
1489 if (!this->emitSetLocal(RHST, RHSOffset, E))
1496 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1497 unsigned ElemIndex,
unsigned Offset,
1498 const Expr *E) ->
bool {
1500 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1502 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1505 if (ElemIndex == 0 || !LoadZero)
1512 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1515 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1522 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1525 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1528 if (!this->emitAddf(getFPOptions(E), E))
1531 if (!this->emitAdd(ResultElemT, E))
1536 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1539 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1542 if (!this->emitSubf(getFPOptions(E), E))
1545 if (!this->emitSub(ResultElemT, E))
1550 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1553 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1557 if (!this->emitMulf(getFPOptions(E), E))
1560 if (!this->emitMul(ResultElemT, E))
1565 assert(!RHSIsComplex);
1566 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1569 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1573 if (!this->emitDivf(getFPOptions(E), E))
1576 if (!this->emitDiv(ResultElemT, E))
1587 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1590 if (!this->emitPop(ResultElemT, E))
1595 return this->emitPopPtr(E);
1601template <
class Emitter>
1606 "Comma op should be handled in VisitBinaryOperator");
1620 if (!this->emitGetPtrLocal(*LocalIndex, E))
1634 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1637 if (!this->
visit(LHS))
1639 if (!this->
visit(RHS))
1641 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1644 return this->emitPopPtr(E);
1649 unsigned LHSOffset =
1651 if (!this->
visit(LHS))
1653 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1657 unsigned RHSOffset =
1659 if (!this->
visit(RHS))
1661 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1673 if (NeedIntPromot) {
1675 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1680 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1681 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1683 if (!this->emitArrayElemPop(ElemT, Index, E))
1686 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1688 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1690 }
else if (NeedIntPromot) {
1691 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1697#define EMIT_ARITH_OP(OP) \
1699 if (ElemT == PT_Float) { \
1700 if (!this->emit##OP##f(getFPOptions(E), E)) \
1703 if (!this->emit##OP(ElemT, E)) \
1709 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1710 if (!getElem(LHSOffset, ElemT, I))
1712 if (!getElem(RHSOffset, RHSElemT, I))
1724 if (!this->emitRem(ElemT, E))
1728 if (!this->emitBitAnd(OpT, E))
1732 if (!this->emitBitOr(OpT, E))
1736 if (!this->emitBitXor(OpT, E))
1740 if (!this->emitShl(OpT, RHSElemT, E))
1744 if (!this->emitShr(OpT, RHSElemT, E))
1748 if (!this->emitEQ(ElemT, E))
1752 if (!this->emitNE(ElemT, E))
1756 if (!this->emitLE(ElemT, E))
1760 if (!this->emitLT(ElemT, E))
1764 if (!this->emitGE(ElemT, E))
1768 if (!this->emitGT(ElemT, E))
1773 if (!this->emitBitAnd(ResultElemT, E))
1778 if (!this->emitBitOr(ResultElemT, E))
1782 return this->emitInvalid(E);
1791 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1793 if (!this->emitNeg(ResultElemT, E))
1799 if (NeedIntPromot &&
1800 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
1804 if (!this->emitInitElem(ResultElemT, I, E))
1813template <
class Emitter>
1823 auto LHSSemaInt = LHSSema.toOpaqueInt();
1825 auto RHSSemaInt = RHSSema.toOpaqueInt();
1827 if (!this->
visit(LHS))
1835 if (!this->
visit(RHS))
1844 auto ConvertResult = [&](
bool R) ->
bool {
1848 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
1849 if (ResultSema != CommonSema)
1850 return this->emitCastFixedPoint(ResultSema, E);
1854 auto MaybeCastToBool = [&](
bool Result) {
1859 return this->emitPop(T, E);
1861 return this->emitCast(
PT_Bool, T, E);
1867 return MaybeCastToBool(this->emitEQFixedPoint(E));
1869 return MaybeCastToBool(this->emitNEFixedPoint(E));
1871 return MaybeCastToBool(this->emitLTFixedPoint(E));
1873 return MaybeCastToBool(this->emitLEFixedPoint(E));
1875 return MaybeCastToBool(this->emitGTFixedPoint(E));
1877 return MaybeCastToBool(this->emitGEFixedPoint(E));
1879 return ConvertResult(this->emitAddFixedPoint(E));
1881 return ConvertResult(this->emitSubFixedPoint(E));
1883 return ConvertResult(this->emitMulFixedPoint(E));
1885 return ConvertResult(this->emitDivFixedPoint(E));
1887 return ConvertResult(this->emitShiftFixedPoint(
true, E));
1889 return ConvertResult(this->emitShiftFixedPoint(
false, E));
1892 return this->emitInvalid(E);
1895 llvm_unreachable(
"unhandled binop opcode");
1898template <
class Emitter>
1907 if (!this->
visit(SubExpr))
1909 if (!this->emitNegFixedPoint(E))
1912 return this->emitPopFixedPoint(E);
1918 llvm_unreachable(
"Unhandled unary opcode");
1921template <
class Emitter>
1930 return this->visitZeroInitializer(*T, QT, E);
1938 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1939 CXXRD && CXXRD->getNumVBases() > 0) {
1949 return this->visitZeroRecordInitializer(R, E);
1956 return this->visitZeroArrayInitializer(QT, E);
1960 QualType ElemQT = ComplexTy->getElementType();
1962 for (
unsigned I = 0; I < 2; ++I) {
1963 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1965 if (!this->emitInitElem(ElemT, I, E))
1972 unsigned NumVecElements = VecT->getNumElements();
1973 QualType ElemQT = VecT->getElementType();
1976 for (
unsigned I = 0; I < NumVecElements; ++I) {
1977 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1979 if (!this->emitInitElem(ElemT, I, E))
1986 unsigned NumElems = MT->getNumElementsFlattened();
1987 QualType ElemQT = MT->getElementType();
1990 for (
unsigned I = 0; I != NumElems; ++I) {
1991 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1993 if (!this->emitInitElem(ElemT, I, E))
2002template <
class Emitter>
2015 for (
const Expr *SubExpr : {LHS, RHS}) {
2016 if (!this->
visit(SubExpr)) {
2023 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2024 if (!this->emitExpandPtr(E))
2035 return this->emitError(E);
2038 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2042 if (!this->emitArrayElemPtrPop(*IndexT, E))
2045 return this->emitPopPtr(E);
2051 return this->emitLoadPop(*T, E);
2054template <
class Emitter>
2056 const Expr *ArrayFiller,
const Expr *E) {
2061 QT = AT->getValueType();
2064 if (
Inits.size() == 0)
2066 return this->emitInvalid(E);
2081 if (
Inits.size() == 0)
2082 return this->visitZeroInitializer(*T, QT, E);
2083 assert(
Inits.size() == 1);
2096 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2103 bool BitField = FieldToInit->isBitField();
2105 return this->emitInitBitFieldActivate(T, FieldToInit->Offset,
2106 FieldToInit->bitWidth(), E);
2108 return this->emitInitBitField(T, FieldToInit->Offset,
2109 FieldToInit->bitWidth(), E);
2111 return this->emitInitFieldActivate(T, FieldToInit->Offset, E);
2112 return this->emitInitField(T, FieldToInit->Offset, E);
2115 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2123 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2126 if (
Activate && !this->emitActivate(E))
2133 if (
Inits.size() == 0) {
2134 if (!this->visitZeroRecordInitializer(R, E))
2139 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2140 FToInit = ILE->getInitializedFieldInUnion();
2144 const Record::Field *FieldToInit = R->getField(FToInit);
2146 if (!initPrimitiveField(FieldToInit,
Init, *T,
true))
2149 if (!initCompositeField(FieldToInit,
Init,
true))
2153 return this->emitFinishInit(E);
2156 assert(!R->isUnion());
2157 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2159 const Record::Base *B = R->getBase(BI);
2160 if (!this->emitGetPtrBase(B->Offset,
Init))
2166 unsigned FieldIndex = 0;
2167 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2168 const Record::Field *FieldToInit = R->getField(FieldIndex);
2169 if (FieldToInit->isUnnamedBitField()) {
2184 if (!initPrimitiveField(FieldToInit,
Init, *T))
2186 }
else if (!initCompositeField(FieldToInit,
Init)) {
2194 assert(R->getNumVirtualBases() == 0);
2196 return this->emitFinishInit(E);
2201 Ctx.getASTContext().getAsConstantArrayType(QT);
2204 if (
Initializing && !this->emitCheckArrayDestSize(NumElems, E))
2207 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2211 unsigned ElementIndex = 0;
2213 if (
const auto *EmbedS =
2214 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2222 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2223 getFPOptions(E), E))
2229 return this->emitInitElem(TargetT, ElemIndex, IL);
2231 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2247 for (; ElementIndex != NumElems; ++ElementIndex) {
2253 return this->emitFinishInit(E);
2257 unsigned NumInits =
Inits.size();
2262 QualType ElemQT = ComplexTy->getElementType();
2264 if (NumInits == 0) {
2266 for (
unsigned I = 0; I < 2; ++I) {
2267 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2269 if (!this->emitInitElem(ElemT, I, E))
2272 }
else if (NumInits == 2) {
2273 unsigned InitIndex = 0;
2278 if (!this->emitInitElem(ElemT, InitIndex, E))
2287 unsigned NumVecElements = VecT->getNumElements();
2288 assert(NumVecElements >=
Inits.size());
2290 QualType ElemQT = VecT->getElementType();
2294 unsigned InitIndex = 0;
2301 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2302 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2303 InitVecT->getNumElements(), E))
2305 InitIndex += InitVecT->getNumElements();
2307 if (!this->emitInitElem(ElemT, InitIndex, E))
2313 assert(InitIndex <= NumVecElements);
2316 for (; InitIndex != NumVecElements; ++InitIndex) {
2317 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2319 if (!this->emitInitElem(ElemT, InitIndex, E))
2326 unsigned NumElems = MT->getNumElementsFlattened();
2327 assert(
Inits.size() == NumElems);
2329 QualType ElemQT = MT->getElementType();
2335 for (
unsigned I = 0; I != NumElems; ++I) {
2338 if (!this->emitInitElem(ElemT, I, E))
2349template <
class Emitter>
2356 return this->emitInitElem(*InitT, ElemIndex,
Init);
2362 if (!this->emitConstUint32(ElemIndex,
Init))
2364 if (!this->emitArrayElemPtrUint32(
Init))
2369template <
class Emitter>
2372 bool Activate,
bool IsOperatorCall) {
2374 llvm::BitVector NonNullArgs;
2375 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2378 bool ExplicitMemberFn =
false;
2379 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2380 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2382 unsigned ArgIndex = 0;
2383 for (
const Expr *Arg : Args) {
2385 if (!this->
visit(Arg))
2393 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2394 if (DeclIndex < FuncDecl->getNumParams())
2395 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2404 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2412 if (!this->emitActivate(Arg))
2416 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2419 if (!this->emitCheckNonNullArg(ArgT, Arg))
2430template <
class Emitter>
2435template <
class Emitter>
2441template <
class Emitter>
2447template <
class Emitter>
2465template <
class Emitter>
2467 auto It = E->
begin();
2468 return this->
visit(*It);
2473 bool AlignOfReturnsPreferred =
2480 T = Ref->getPointeeType();
2482 if (T.getQualifiers().hasUnaligned())
2488 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2494template <
class Emitter>
2501 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2507 ArgType = Ref->getPointeeType();
2513 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2514 return this->emitInvalid(E);
2516 if (Kind == UETT_SizeOf)
2525 return this->emitConst(Size.getQuantity(), E);
2528 if (Kind == UETT_CountOf) {
2534 if (
const auto *CAT =
2538 return this->emitConst(CAT->getSize(), E);
2548 if (VAT->getElementType()->isArrayType()) {
2549 std::optional<APSInt> Res =
2551 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2556 return this->emitConst(*Res, E);
2561 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2581 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2584 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2594 return this->emitConst(Size.getQuantity(), E);
2597 if (Kind == UETT_VectorElements) {
2602 return this->emitConst(VT->getNumElements(), E);
2604 return this->emitSizelessVectorElementSize(E);
2607 if (Kind == UETT_VecStep) {
2609 unsigned N = VT->getNumElements();
2616 return this->emitConst(N, E);
2618 return this->emitConst(1, E);
2621 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2630 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2632 return this->emitInvalid(E);
2634 return this->emitConst(
2635 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2643template <
class Emitter>
2652 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2655 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2656 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2658 if (
Member->getType()->isReferenceType())
2659 return this->emitLoadPopPtr(E);
2668 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2669 MD && !MD->isStatic()) {
2673 if (!this->
discard(Base) && !this->emitSideEffect(E))
2688 const Record::Field *F = R->getField(FD);
2692 const auto maybeLoadValue = [&]() ->
bool {
2696 return this->emitLoadPop(*T, E);
2701 if (F->Decl->getType()->isReferenceType())
2702 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
2703 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
2706template <
class Emitter>
2716template <
class Emitter>
2730 if (!this->
visit(Common))
2732 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
2746 for (
size_t I = 0; I != Size; ++I) {
2758template <
class Emitter>
2773 return this->emitGetLocal(SubExprT, It->second, E);
2776 if (!this->
visit(SourceExpr))
2783 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
2792 return this->emitGetLocal(SubExprT, LocalIndex, E);
2796template <
class Emitter>
2809 bool IsBcpCall =
false;
2810 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
2811 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
2815 LabelTy LabelEnd = this->getLabel();
2816 LabelTy LabelFalse = this->getLabel();
2819 if (!this->emitPushIgnoreDiags(E))
2827 if (this->checkingForUndefinedBehavior()) {
2830 if (!this->
discard(FalseExpr))
2847 if (!this->jumpFalse(LabelFalse, E))
2852 if (!this->jump(LabelEnd, E))
2854 this->emitLabel(LabelFalse);
2858 this->fallthrough(LabelEnd);
2859 this->emitLabel(LabelEnd);
2862 return this->emitPopIgnoreDiags(E);
2866template <
class Emitter>
2872 unsigned StringIndex =
P.createGlobalString(E);
2873 return this->emitGetPtrGlobal(StringIndex, E);
2878 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
2879 assert(CAT &&
"a string literal that's not a constant array?");
2884 unsigned N = std::min(ArraySize, E->
getLength());
2887 for (
unsigned I = 0; I != N; ++I) {
2890 if (CharWidth == 1) {
2891 this->emitConstSint8(CodeUnit, E);
2892 this->emitInitElemSint8(I, E);
2893 }
else if (CharWidth == 2) {
2894 this->emitConstUint16(CodeUnit, E);
2895 this->emitInitElemUint16(I, E);
2896 }
else if (CharWidth == 4) {
2897 this->emitConstUint32(CodeUnit, E);
2898 this->emitInitElemUint32(I, E);
2900 llvm_unreachable(
"unsupported character width");
2905 for (
unsigned I = N; I != ArraySize; ++I) {
2906 if (CharWidth == 1) {
2907 this->emitConstSint8(0, E);
2908 this->emitInitElemSint8(I, E);
2909 }
else if (CharWidth == 2) {
2910 this->emitConstUint16(0, E);
2911 this->emitInitElemUint16(I, E);
2912 }
else if (CharWidth == 4) {
2913 this->emitConstUint32(0, E);
2914 this->emitInitElemUint32(I, E);
2916 llvm_unreachable(
"unsupported character width");
2923template <
class Emitter>
2927 return this->emitDummyPtr(E, E);
2930template <
class Emitter>
2932 auto &A =
Ctx.getASTContext();
2941template <
class Emitter>
2949 auto &A =
Ctx.getASTContext();
2953 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
2954 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
2961 unsigned StringIndex =
P.createGlobalString(SL);
2962 return this->emitGetPtrGlobal(StringIndex, E);
2965template <
class Emitter>
2969 return this->emitConst(E->
getValue(), E);
2972template <
class Emitter>
2998 if (!this->emitSetLocal(*RT, TempOffset, E))
3004 if (!this->emitLoad(LHST, E))
3008 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3009 LHSComputationType, E))
3013 if (!this->emitGetLocal(*RT, TempOffset, E))
3018 if (!this->emitAddf(getFPOptions(E), E))
3022 if (!this->emitSubf(getFPOptions(E), E))
3026 if (!this->emitMulf(getFPOptions(E), E))
3030 if (!this->emitDivf(getFPOptions(E), E))
3041 return this->emitStorePop(LHST, E);
3042 return this->emitStore(LHST, E);
3045template <
class Emitter>
3054 if (Op != BO_AddAssign && Op != BO_SubAssign)
3063 if (!this->emitLoad(*
LT, LHS))
3069 if (Op == BO_AddAssign) {
3070 if (!this->emitAddOffset(*RT, E))
3073 if (!this->emitSubOffset(*RT, E))
3078 return this->emitStorePopPtr(E);
3079 return this->emitStorePtr(E);
3082template <
class Emitter>
3095 if (!
Ctx.getLangOpts().CPlusPlus14)
3096 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3098 if (!
LT || !RT || !ResultT || !LHSComputationT)
3123 if (!this->emitSetLocal(*RT, TempOffset, E))
3130 if (!this->emitLoad(*
LT, E))
3132 if (
LT != LHSComputationT &&
3138 if (!this->emitGetLocal(*RT, TempOffset, E))
3144 if (!this->emitAdd(*LHSComputationT, E))
3148 if (!this->emitSub(*LHSComputationT, E))
3152 if (!this->emitMul(*LHSComputationT, E))
3156 if (!this->emitDiv(*LHSComputationT, E))
3160 if (!this->emitRem(*LHSComputationT, E))
3164 if (!this->emitShl(*LHSComputationT, *RT, E))
3168 if (!this->emitShr(*LHSComputationT, *RT, E))
3172 if (!this->emitBitAnd(*LHSComputationT, E))
3176 if (!this->emitBitXor(*LHSComputationT, E))
3180 if (!this->emitBitOr(*LHSComputationT, E))
3184 llvm_unreachable(
"Unimplemented compound assign operator");
3188 if (ResultT != LHSComputationT &&
3189 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3195 return this->emitStoreBitFieldPop(*ResultT, E);
3196 return this->emitStorePop(*ResultT, E);
3199 return this->emitStoreBitField(*ResultT, E);
3200 return this->emitStore(*ResultT, E);
3203template <
class Emitter>
3211template <
class Emitter>
3226 if (!
Ctx.getLangOpts().CPlusPlus11)
3233 for (
const Expr *LHS : CommaLHSs) {
3255 if (!this->
visit(Inner))
3260 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3263 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3266 return this->emitGetPtrGlobal(*GlobalIndex, E);
3269 if (!this->checkLiteralType(Inner))
3272 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3278 return this->emitInitGlobalTempComp(TempDecl, E);
3291 unsigned LocalIndex =
3293 if (!this->VarScope->LocalsAlwaysEnabled &&
3294 !this->emitEnableLocal(LocalIndex, E))
3297 if (!this->
visit(Inner))
3299 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3302 return this->emitGetPtrLocal(LocalIndex, E);
3305 if (!this->checkLiteralType(Inner))
3312 if (!this->VarScope->LocalsAlwaysEnabled &&
3313 !this->emitEnableLocal(*LocalIndex, E))
3316 if (!this->emitGetPtrLocal(*LocalIndex, E))
3323template <
class Emitter>
3334 if (!this->
visit(SubExpr))
3338 return this->emitPopPtr(E);
3342template <
class Emitter>
3363 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3368 if (
P.isGlobalInitialized(*GlobalIndex))
3374 return this->emitInitGlobal(*T, *GlobalIndex, E);
3386 unsigned LocalIndex;
3390 LocalIndex = *MaybeIndex;
3394 if (!this->emitGetPtrLocal(LocalIndex, E))
3398 return this->
visit(
Init) && this->emitInit(*T, E);
3402template <
class Emitter>
3415template <
class Emitter>
3419 return this->emitConst(E->
getValue(), E);
3422template <
class Emitter>
3435 for (
const Record::Field &F : R->fields()) {
3437 if (!
Init ||
Init->containsErrors())
3445 if (!this->emitInitField(*T, F.Offset, E))
3448 if (!this->emitGetPtrField(F.Offset, E))
3459template <
class Emitter>
3466 return this->emitGetPtrGlobal(StringIndex, E);
3472template <
class Emitter>
3477 return this->emitInvalid(E);
3480template <
class Emitter>
3500 bool Fatal = (ToT != FromT);
3507template <
class Emitter>
3509 if (!
Ctx.getLangOpts().CPlusPlus20) {
3530 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3535 return this->emitPopPtr(E);
3539template <
class Emitter>
3545 return this->emitConstBool(E->
getValue(), E);
3548template <
class Emitter>
3553 if (T->isRecordType()) {
3567 if (!this->emitGetPtrLocal(*LocalIndex, E))
3575 T->getAsCXXRecordDecl()))
3585 if (!this->visitZeroRecordInitializer(R, E))
3597 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3599 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3600 if (!this->emitCheckFunctionDecl(Ctor, E))
3611 assert(
Func->hasThisPointer());
3612 assert(!
Func->hasRVO());
3616 if (!this->emitDupPtr(E))
3620 for (
const auto *Arg : E->
arguments()) {
3621 if (!this->
visit(Arg))
3625 if (
Func->isVariadic()) {
3626 uint32_t VarArgSize = 0;
3627 unsigned NumParams =
Func->getNumWrittenParams();
3628 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
3632 if (!this->emitCallVar(
Func, VarArgSize, E))
3635 if (!this->emitCall(
Func, 0, E)) {
3640 (void)this->emitPopPtr(E);
3646 return this->emitPopPtr(E);
3650 if (T->isArrayType()) {
3655 if (!this->emitDupPtr(E))
3659 initArrayDimension = [&](
QualType T) ->
bool {
3660 if (!T->isArrayType()) {
3662 for (
const auto *Arg : E->
arguments()) {
3663 if (!this->
visit(Arg))
3667 return this->emitCall(
Func, 0, E);
3671 Ctx.getASTContext().getAsConstantArrayType(T);
3676 for (
size_t I = 0; I != NumElems; ++I) {
3677 if (!this->emitConstUint64(I, E))
3679 if (!this->emitArrayElemPtrUint64(E))
3681 if (!initArrayDimension(ElemTy))
3684 return this->emitPopPtr(E);
3687 return initArrayDimension(E->
getType());
3693template <
class Emitter>
3703 assert(Val.
isInt());
3705 return this->emitConst(I, E);
3712 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
3713 return this->
visit(LValueExpr);
3728 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3732 const APValue &
V = UGCD->getValue();
3733 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
3734 const Record::Field *F = R->getField(I);
3735 const APValue &FieldValue =
V.getStructField(I);
3741 if (!this->emitInitField(FieldT, F->Offset, E))
3749template <
class Emitter>
3755 for (
unsigned I = 0; I != N; ++I) {
3762 if (!this->
discard(ArrayIndexExpr))
3768 if (!this->
visit(ArrayIndexExpr))
3770 if (!this->emitCastNoOverflow(IndexT, E))
3774 if (!this->
visit(ArrayIndexExpr))
3778 if (!this->emitCast(IndexT,
PT_Sint64, E))
3788 return this->emitOffsetOf(T, E, E);
3791template <
class Emitter>
3800 return this->visitZeroInitializer(*T, Ty, E);
3807 if (!this->emitGetPtrLocal(*LocalIndex, E))
3815 ElemQT = CT->getElementType();
3818 NumElems = VT->getNumElements();
3819 ElemQT = VT->getElementType();
3825 for (
unsigned I = 0, N = NumElems; I != N; ++I) {
3826 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3828 if (!this->emitInitElem(ElemT, I, E))
3837template <
class Emitter>
3842template <
class Emitter>
3848template <
class Emitter>
3853template <
class Emitter>
3858 return this->emitConst(E->
getValue(), E);
3861template <
class Emitter>
3866 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3880 unsigned ParamIndex = 0;
3884 if (!this->emitGetParam(PT, ParamIndex, E))
3889 return this->emitCall(F, 0, E);
3894template <
class Emitter>
3902 const Expr *PlacementDest =
nullptr;
3903 bool IsNoThrow =
false;
3908 if (PlacementArgs != 0) {
3917 if (PlacementArgs == 1) {
3925 if (!this->emitInvalidNewDeleteExpr(E, E))
3930 if (OperatorNew->isReservedGlobalPlacementOperator())
3931 PlacementDest = Arg1;
3935 return this->emitInvalid(E);
3937 }
else if (!OperatorNew
3938 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3939 return this->emitInvalidNewDeleteExpr(E, E);
3942 if (!PlacementDest) {
3947 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3950 Desc =
P.createDescriptor(
3953 false,
false,
false,
3959 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3963 const Expr *Stripped = *ArraySizeExpr;
3964 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3965 Stripped = ICE->getSubExpr())
3966 if (ICE->getCastKind() != CK_NoOp &&
3967 ICE->getCastKind() != CK_IntegralCast)
3975 if (!this->
visit(Stripped))
3977 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3980 if (PlacementDest) {
3981 if (!this->
visit(PlacementDest))
3983 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3985 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3988 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3993 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3997 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4004 size_t StaticInitElems = 0;
4005 const Expr *DynamicInit =
nullptr;
4009 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4010 StaticInitElems = CAT->getZExtSize();
4015 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4016 if (ILE->hasArrayFiller())
4017 DynamicInit = ILE->getArrayFiller();
4036 const Function *CtorFunc =
nullptr;
4037 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4041 }
else if (!DynamicInit && !ElemT)
4044 LabelTy EndLabel = this->getLabel();
4045 LabelTy StartLabel = this->getLabel();
4050 if (!this->emitDupPtr(E))
4052 if (!this->emitNullPtr(0,
nullptr, E))
4054 if (!this->emitEQPtr(E))
4056 if (!this->jumpTrue(EndLabel, E))
4063 if (!this->emitConst(StaticInitElems,
SizeT, E))
4065 if (!this->emitSetLocal(
SizeT, Iter, E))
4068 this->fallthrough(StartLabel);
4069 this->emitLabel(StartLabel);
4071 if (!this->emitGetLocal(
SizeT, Iter, E))
4073 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4075 if (!this->emitLT(
SizeT, E))
4077 if (!this->jumpFalse(EndLabel, E))
4081 if (!this->emitGetLocal(
SizeT, Iter, E))
4083 if (!this->emitArrayElemPtr(
SizeT, E))
4086 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4091 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4093 if (!this->emitStorePop(*InitT, E))
4097 if (!this->visitZeroArrayInitializer(ElemType, E))
4100 }
else if (DynamicInit) {
4102 if (!this->
visit(DynamicInit))
4104 if (!this->emitStorePop(*InitT, E))
4111 if (!this->visitZeroInitializer(
4115 if (!this->emitStorePop(*ElemT, E))
4119 if (!this->emitCall(CtorFunc, 0, E))
4124 if (!this->emitGetPtrLocal(Iter, E))
4126 if (!this->emitIncPop(
SizeT,
false, E))
4129 if (!this->jump(StartLabel, E))
4132 this->fallthrough(EndLabel);
4133 this->emitLabel(EndLabel);
4137 if (PlacementDest) {
4138 if (!this->
visit(PlacementDest))
4140 if (!this->emitCheckNewTypeMismatch(E, E))
4145 if (!this->emitAlloc(Desc, E))
4154 if (!this->emitInit(*ElemT, E))
4165 return this->emitPopPtr(E);
4170template <
class Emitter>
4176 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4177 return this->emitInvalidNewDeleteExpr(E, E);
4186template <
class Emitter>
4192 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4197 return this->emitGetFnPtr(
Func, E);
4200template <
class Emitter>
4204 auto canonType = [](
const Type *T) {
4205 return T->getCanonicalTypeUnqualified().getTypePtr();
4213 return this->emitGetTypeid(
4217 return this->emitGetTypeid(
4226 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4232 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4235 return this->emitPopPtr(E);
4239template <
class Emitter>
4243 return this->emitDummyPtr(E, E);
4244 return this->emitError(E);
4247template <
class Emitter>
4250 return this->emitDummyPtr(E, E);
4251 return this->emitError(E);
4254template <
class Emitter>
4256 assert(
Ctx.getLangOpts().CPlusPlus);
4257 return this->emitConstBool(E->
getValue(), E);
4260template <
class Emitter>
4272 return this->emitDummyPtr(GuidDecl, E);
4277 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4286 assert(
V.isStruct());
4287 assert(
V.getStructNumBases() == 0);
4291 return this->emitFinishInit(E);
4294template <
class Emitter>
4304template <
class Emitter>
4313template <
class Emitter>
4319template <
class Emitter>
4323 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4327 if (OVE->isUnique())
4343template <
class Emitter>
4348template <
class Emitter>
4350 return this->emitError(E);
4353template <
class Emitter>
4359 return this->emitDummyPtr(E, E);
4362template <
class Emitter>
4363bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4368 QualType ElemType = VT->getElementType();
4369 PrimType ElemT = classifyPrim(ElemType);
4371 PrimType SrcElemT = classifyVectorElementType(SrcType);
4377 if (!this->emitGetPtrLocal(*LocalIndex, E))
4381 unsigned SrcOffset =
4382 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4383 if (!this->visit(Src))
4385 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4388 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4389 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4391 if (!this->emitArrayElemPop(SrcElemT, I, E))
4395 if (SrcElemT != ElemT) {
4396 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4398 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4399 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4403 if (!this->emitInitElem(ElemT, I, E))
4409template <
class Emitter>
4411 return emitVectorConversion(E->
getSrcExpr(), E);
4414template <
class Emitter>
4418 return this->emitInvalid(E);
4427 assert(NumOutputElems > 0);
4433 if (!this->emitGetPtrLocal(*LocalIndex, E))
4438 unsigned VectorOffsets[2];
4439 for (
unsigned I = 0; I != 2; ++I) {
4442 if (!this->
visit(Vecs[I]))
4444 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4447 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4449 assert(ShuffleIndex >= -1);
4450 if (ShuffleIndex == -1)
4451 return this->emitInvalidShuffleVectorIndex(I, E);
4453 assert(ShuffleIndex < (NumInputElems * 2));
4454 if (!this->emitGetLocal(
PT_Ptr,
4455 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4457 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4458 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4461 if (!this->emitInitElem(ElemT, I, E))
4466 return this->emitPopPtr(E);
4471template <
class Emitter>
4476 Base->getType()->isVectorType() ||
4482 if (Indices.size() == 1) {
4487 if (!this->emitConstUint32(Indices[0], E))
4489 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4499 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4507 if (!this->emitGetPtrLocal(*ResultIndex, E))
4515 uint32_t DstIndex = 0;
4516 for (uint32_t I : Indices) {
4517 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4519 if (!this->emitArrayElemPop(ElemT, I, E))
4521 if (!this->emitInitElem(ElemT, DstIndex, E))
4531template <
class Emitter>
4535 return this->
discard(SubExpr) && this->emitInvalid(E);
4541 return this->emitDummyPtr(E, E);
4544template <
class Emitter>
4549 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4554 if (!this->
visit(SubExpr))
4556 if (!this->emitConstUint8(0, E))
4558 if (!this->emitArrayElemPtrPopUint8(E))
4560 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4565 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4567 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4569 assert(SecondFieldT ==
PT_Ptr);
4571 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4573 if (!this->emitExpandPtr(E))
4577 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4579 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4582template <
class Emitter>
4597 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4601 return this->emitUnsupported(E);
4610 return this->
Visit(E);
4617 return this->
Visit(E);
4621 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4624 if (
const auto *CE = dyn_cast<CastExpr>(E);
4626 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4633 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4636 if (
const auto *CE = dyn_cast<CastExpr>(E);
4637 CE && (CE->getCastKind() == CK_DerivedToBase ||
4638 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4639 CE->getCastKind() == CK_NoOp))
4659 if (!this->emitGetPtrLocal(*LocalIndex, E))
4669 return this->
Visit(E);
4672template <
class Emitter>
4678 return this->
Visit(E) && this->emitFinishInit(E);
4681template <
class Emitter>
4687 return this->
Visit(E) && this->emitFinishInitPop(E);
4693 return this->
Visit(E);
4704 if (!this->
visit(E))
4706 return this->emitComplexBoolCast(E);
4711 if (!this->
visit(E))
4719 return this->emitIsNonNullPtr(E);
4723 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4726 return this->emitCast(*T,
PT_Bool, E);
4729template <
class Emitter>
4733 QT = AT->getValueType();
4737 return this->emitZeroBool(E);
4739 return this->emitZeroSint8(E);
4741 return this->emitZeroUint8(E);
4743 return this->emitZeroSint16(E);
4745 return this->emitZeroUint16(E);
4747 return this->emitZeroSint32(E);
4749 return this->emitZeroUint32(E);
4751 return this->emitZeroSint64(E);
4753 return this->emitZeroUint64(E);
4755 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4757 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4759 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4762 return this->emitNullMemberPtr(0,
nullptr, E);
4764 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4765 return this->emitFloat(F, E);
4768 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
4772 llvm_unreachable(
"unknown primitive type");
4775template <
class Emitter>
4776bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4781 for (
const Record::Field &Field :
R->fields()) {
4782 if (Field.isUnnamedBitField())
4789 if (!this->visitZeroInitializer(T, QT, E))
4792 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4796 if (!this->emitInitField(T, Field.Offset, E))
4801 if (!this->emitGetPtrField(Field.Offset, E))
4808 if (!this->visitZeroInitializer(T, ET, E))
4810 if (!this->emitInitElem(T, I, E))
4815 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4818 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4826 if (!this->emitFinishInitActivatePop(E))
4830 if (!this->emitFinishInitPop(E))
4834 for (
const Record::Base &B :
R->bases()) {
4835 if (!this->emitGetPtrBase(B.Offset, E))
4837 if (!this->visitZeroRecordInitializer(B.R, E))
4839 if (!this->emitFinishInitPop(E))
4848template <
class Emitter>
4849bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4850 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4856 for (
size_t I = 0; I != NumElems; ++I) {
4857 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4859 if (!this->emitInitElem(*ElemT, I, E))
4865 const Record *
R = getRecord(ElemType);
4869 for (
size_t I = 0; I != NumElems; ++I) {
4870 if (!this->emitConstUint32(I, E))
4872 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4874 if (!this->visitZeroRecordInitializer(R, E))
4876 if (!this->emitPopPtr(E))
4882 for (
size_t I = 0; I != NumElems; ++I) {
4883 if (!this->emitConstUint32(I, E))
4885 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4887 if (!this->visitZeroArrayInitializer(ElemType, E))
4889 if (!this->emitPopPtr(E))
4898template <
class Emitter>
4899bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4901 if (!canClassify(E->
getType()))
4904 if (!this->visit(RHS))
4906 if (!this->visit(LHS))
4913 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4917 bool Activates = refersToUnion(LHS);
4920 if (!this->emitFlip(
PT_Ptr, RHT, E))
4923 if (DiscardResult) {
4924 if (BitField && Activates)
4925 return this->emitStoreBitFieldActivatePop(RHT, E);
4927 return this->emitStoreBitFieldPop(RHT, E);
4929 return this->emitStoreActivatePop(RHT, E);
4931 return this->emitStorePop(RHT, E);
4934 auto maybeLoad = [&](
bool Result) ->
bool {
4940 return this->emitLoadPop(RHT, E);
4944 if (BitField && Activates)
4945 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4947 return maybeLoad(this->emitStoreBitField(RHT, E));
4949 return maybeLoad(this->emitStoreActivate(RHT, E));
4951 return maybeLoad(this->emitStore(RHT, E));
4954template <
class Emitter>
4955template <
typename T>
4959 return this->emitConstSint8(
Value, Info);
4961 return this->emitConstUint8(
Value, Info);
4963 return this->emitConstSint16(
Value, Info);
4965 return this->emitConstUint16(
Value, Info);
4967 return this->emitConstSint32(
Value, Info);
4969 return this->emitConstUint32(
Value, Info);
4971 return this->emitConstSint64(
Value, Info);
4973 return this->emitConstUint64(
Value, Info);
4975 return this->emitConstBool(
Value, Info);
4982 llvm_unreachable(
"Invalid integral type");
4985 llvm_unreachable(
"unknown primitive type");
4988template <
class Emitter>
4989template <
typename T>
4990bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
4991 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4994template <
class Emitter>
4998 return this->emitConstIntAPS(
Value, Info);
5000 return this->emitConstIntAP(
Value, Info);
5002 if (
Value.isSigned())
5003 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5004 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5007template <
class Emitter>
5011 return this->emitConstIntAPS(
Value, Info);
5013 return this->emitConstIntAP(
Value, Info);
5016 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5017 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5020template <
class Emitter>
5021bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5022 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5025template <
class Emitter>
5038 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5039 Locals.insert({VD, Local});
5040 VarScope->addForScopeKind(Local, SC);
5041 return Local.Offset;
5044template <
class Emitter>
5049 bool IsTemporary =
false;
5050 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5053 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5054 Init = VarD->getInit();
5056 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5067 return std::nullopt;
5072 Locals.insert({Key, Local});
5073 VarScope->addForScopeKind(Local, SC);
5074 return Local.Offset;
5077template <
class Emitter>
5087 return std::nullopt;
5097 return Local.Offset;
5100template <
class Emitter>
5102 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5103 return PT->getPointeeType()->getAsCanonical<RecordType>();
5109 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5113template <
class Emitter>
5115 return P.getOrCreateRecord(RD);
5118template <
class Emitter>
5120 return Ctx.getOrCreateFunction(FD);
5123template <
class Emitter>
5127 auto maybeDestroyLocals = [&]() ->
bool {
5128 if (DestroyToplevelScope)
5129 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5130 return this->emitCheckAllocations(E);
5137 return this->emitRetVoid(E) && maybeDestroyLocals();
5145 return this->emitRet(*T, E) && maybeDestroyLocals();
5153 if (!this->emitGetPtrLocal(*LocalOffset, E))
5161 return this->emitRetValue(E) && maybeDestroyLocals();
5164 return maybeDestroyLocals() &&
false;
5167template <
class Emitter>
5169 bool DestroyToplevelScope) {
5173 return this->
visitExpr(E, DestroyToplevelScope);
5176template <
class Emitter>
5188 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5189 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5203template <
class Emitter>
5205 bool ConstantContext) {
5208 if (!ConstantContext) {
5222 auto GlobalIndex =
P.getGlobal(VD);
5223 assert(GlobalIndex);
5225 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5228 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5232 auto Local =
Locals.find(VD);
5233 assert(Local !=
Locals.end());
5235 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5238 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5248 auto GlobalIndex =
P.getGlobal(VD);
5249 assert(GlobalIndex);
5250 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5259 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5262template <
class Emitter>
5273 if (!this->isActive())
5278 if (
Init &&
Init->isValueDependent())
5282 auto checkDecl = [&]() ->
bool {
5284 return !NeedsOp || this->emitCheckDecl(VD, VD);
5291 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5294 if (
P.isGlobalInitialized(*GlobalIndex))
5298 }
else if ((GlobalIndex =
5313 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5316 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5319 if (!this->emitStartInit(
Init))
5325 if (!this->emitEndInit(
Init))
5328 return this->emitFinishInitGlobal(
Init);
5338 if (!
Init ||
Init->getType()->isVoidType())
5347 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5359 if (!this->emitCheckRefInit(
Init))
5363 return this->emitSetLocal(*VarT, Offset, VD);
5371 if (!this->emitGetPtrLocal(*Offset,
Init))
5379template <
class Emitter>
5400 Locals.insert({VD, Local});
5403 if (!this->emitGetPtrLocal(Local.Offset, VD))
5409 return this->emitDestructionPop(D, VD);
5418 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5442template <
class Emitter>
5457 unsigned ParamIndex = 0;
5464 const Expr *Arg = Args[ParamIndex];
5465 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5467 unsigned ArgOffset =
5469 if (!this->
visit(Arg))
5471 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5477 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5489 if (
This->getType()->isPointerType()) {
5492 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5499 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5521template <
class Emitter>
5527 return this->emitConst(Val.
getInt(), ValType, Info);
5530 return this->emitFloat(F, Info);
5535 if (!this->emitGetMemberPtr(MemberDecl, Info))
5541 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5547 return this->emitNullMemberPtr(0,
nullptr, Info);
5552 return this->emitNull(ValType, 0,
nullptr, Info);
5557 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5558 return this->
visit(BaseExpr);
5563 QualType EntryType = VD->getType();
5564 for (
auto &Entry : Path) {
5566 uint64_t Index = Entry.getAsArrayIndex();
5569 if (!this->emitConst(Index,
PT_Uint64, Info))
5571 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5573 EntryType = ElemType;
5583 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5584 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5586 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5588 EntryType = FD->getType();
5592 if (!this->emitGetPtrBasePop(BaseOffset,
false, Info))
5594 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5606template <
class Emitter>
5616 const Record::Field *RF = R->getField(I);
5617 QualType FieldType = RF->Decl->getType();
5623 if (!this->emitInitField(*PT, RF->Offset, Info))
5626 if (!this->emitGetPtrField(RF->Offset, Info))
5630 if (!this->emitFinishInitPop(Info))
5640 if (I >= R->getNumBases())
5645 const Record::Base *RB = R->getBase(I);
5646 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5648 if (!this->emitGetPtrBase(RB->Offset, Info))
5652 if (!this->emitFinishInitPop(Info))
5667 const Record::Field *RF = R->getField(UnionField);
5668 QualType FieldType = RF->Decl->getType();
5673 if (RF->isBitField())
5674 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5676 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
5679 if (!this->emitGetPtrField(RF->Offset, Info))
5681 if (!this->emitActivate(Info))
5685 return this->emitPopPtr(Info);
5689 const auto *ArrType = T->getAsArrayTypeUnsafe();
5690 QualType ElemType = ArrType->getElementType();
5693 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5694 const APValue &Elem = A >= InitializedElems
5703 if (!this->emitInitElem(*ElemT, A, Info))
5706 if (!this->emitConstUint32(A, Info))
5708 if (!this->emitArrayElemPtrUint32(Info))
5712 if (!this->emitPopPtr(Info))
5723template <
class Emitter>
5725 unsigned BuiltinID) {
5726 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5731 return this->emitConst(0, E);
5734 if (!this->emitStartSpeculation(E))
5736 LabelTy EndLabel = this->getLabel();
5737 if (!this->speculate(E, EndLabel))
5739 if (!this->emitEndSpeculation(E))
5741 this->fallthrough(EndLabel);
5749 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5750 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5751 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5752 BuiltinID == Builtin::BI__builtin_function_start) {
5755 return this->emitDummyPtr(E, E);
5766 if (!this->emitGetPtrLocal(*LocalIndex, E))
5771 switch (BuiltinID) {
5772 case Builtin::BI__builtin_object_size:
5773 case Builtin::BI__builtin_dynamic_object_size: {
5777 if (!this->
visit(Arg0))
5788 case Builtin::BI__assume:
5789 case Builtin::BI__builtin_assume:
5792 case Builtin::BI__atomic_is_lock_free:
5793 case Builtin::BI__atomic_always_lock_free: {
5804 for (
const auto *Arg : E->
arguments()) {
5805 if (!this->
visit(Arg))
5811 if (!this->emitCallBI(E, BuiltinID, E))
5820template <
class Emitter>
5841 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5842 DD && DD->isTrivial()) {
5844 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5846 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5847 this->emitPopPtr(E);
5855 bool HasRVO = !
ReturnType->isVoidType() && !T;
5863 if (!this->emitGetPtrLocal(*LocalIndex, E))
5871 if (!this->emitGetPtrLocal(*LocalIndex, E))
5875 if (!this->emitDupPtr(E))
5882 bool IsAssignmentOperatorCall =
false;
5883 bool ActivateLHS =
false;
5884 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5885 OCE && OCE->isAssignmentOp()) {
5889 assert(Args.size() == 2);
5890 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
5892 IsAssignmentOperatorCall =
true;
5893 std::reverse(Args.begin(), Args.end());
5899 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5900 MD && MD->isStatic()) {
5904 Args.erase(Args.begin());
5908 bool Devirtualized =
false;
5911 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5919 if (!this->
visit(Callee))
5921 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5923 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5925 if (!this->emitGetMemberPtrBase(E))
5928 const auto *InstancePtr = MC->getImplicitObjectArgument();
5935 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5936 Devirtualized =
true;
5937 if (!this->
visit(Stripped))
5940 if (!this->
visit(InstancePtr))
5944 if (!this->
visit(InstancePtr))
5948 }
else if (
const auto *PD =
5949 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5950 if (!this->emitCheckPseudoDtor(E))
5958 return this->emitEndLifetimePop(E);
5959 }
else if (!FuncDecl) {
5963 if (!this->
visit(Callee))
5965 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5974 if (IsAssignmentOperatorCall) {
5975 assert(Args.size() == 2);
5978 if (!this->emitFlip(Arg2T, Arg1T, E))
5992 assert(HasRVO ==
Func->hasRVO());
5994 bool HasQualifier =
false;
5995 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5996 HasQualifier = ME->hasQualifier();
5998 bool IsVirtual =
false;
5999 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6000 IsVirtual = !Devirtualized && MD->isVirtual();
6005 if (IsVirtual && !HasQualifier) {
6006 uint32_t VarArgSize = 0;
6007 unsigned NumParams =
6008 Func->getNumWrittenParams() +
6010 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6013 if (!this->emitCallVirt(
Func, VarArgSize, E))
6015 }
else if (
Func->isVariadic()) {
6016 uint32_t VarArgSize = 0;
6017 unsigned NumParams =
6018 Func->getNumWrittenParams() +
6020 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6022 if (!this->emitCallVar(
Func, VarArgSize, E))
6025 if (!this->emitCall(
Func, 0, E))
6034 uint32_t ArgSize = 0;
6035 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6041 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6043 if (!this->emitGetMemberPtrDecl(E))
6046 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6049 if (!this->emitCallPtr(ArgSize, E, E))
6060template <
class Emitter>
6067template <
class Emitter>
6074template <
class Emitter>
6079 return this->emitConstBool(E->
getValue(), E);
6082template <
class Emitter>
6088 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6089 return this->emitNullPtr(Val,
nullptr, E);
6092template <
class Emitter>
6100 return this->emitZero(T, E);
6103template <
class Emitter>
6108 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6109 if (this->LambdaThisCapture.Offset > 0) {
6110 if (this->LambdaThisCapture.IsPtr)
6111 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6112 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6121 return this->emitThis(E);
6136 unsigned StartIndex = 0;
6137 unsigned EndIndex = 0;
6139 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6141 EndIndex = StartIndex;
6148 for (; StartIndex > 0; --StartIndex) {
6158 if (StartIndex == 0 && EndIndex == 0)
6164 assert(StartIndex <= EndIndex);
6167 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6179 case Stmt::CompoundStmtClass:
6181 case Stmt::DeclStmtClass:
6183 case Stmt::ReturnStmtClass:
6185 case Stmt::IfStmtClass:
6187 case Stmt::WhileStmtClass:
6189 case Stmt::DoStmtClass:
6191 case Stmt::ForStmtClass:
6193 case Stmt::CXXForRangeStmtClass:
6195 case Stmt::BreakStmtClass:
6197 case Stmt::ContinueStmtClass:
6199 case Stmt::SwitchStmtClass:
6201 case Stmt::CaseStmtClass:
6203 case Stmt::DefaultStmtClass:
6205 case Stmt::AttributedStmtClass:
6207 case Stmt::CXXTryStmtClass:
6209 case Stmt::NullStmtClass:
6212 case Stmt::GCCAsmStmtClass:
6213 case Stmt::MSAsmStmtClass:
6214 case Stmt::GotoStmtClass:
6215 return this->emitInvalid(S);
6216 case Stmt::LabelStmtClass:
6219 if (
const auto *E = dyn_cast<Expr>(S))
6226template <
class Emitter>
6229 for (
const auto *InnerStmt : S->
body())
6232 return Scope.destroyLocals();
6235template <
class Emitter>
6236bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6237 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6238 for (
auto *BD : DD->flat_bindings())
6239 if (
auto *KD = BD->getHoldingVar();
6240 KD && !this->visitVarDecl(KD, KD->getInit()))
6254template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6256 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6257 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6264 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6269 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6270 ICE && (ICE->getCastKind() == CK_NoOp ||
6271 ICE->getCastKind() == CK_DerivedToBase ||
6272 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6273 E = ICE->getSubExpr();
6277 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6278 const auto *ThisRecord =
6279 This->getType()->getPointeeType()->getAsRecordDecl();
6280 if (!ThisRecord->isUnion())
6283 if (
const auto *Ctor =
6284 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6285 return Ctor->getParent() == ThisRecord;
6294template <
class Emitter>
6296 bool EvaluateConditionDecl) {
6297 for (
const auto *D : DS->
decls()) {
6302 const auto *VD = dyn_cast<VarDecl>(D);
6309 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6316template <
class Emitter>
6319 return this->emitUnsupported(RS);
6325 if (!this->
visit(RE))
6331 if (RE->getType()->isVoidType()) {
6332 if (!this->
visit(RE))
6335 if (RE->containsErrors())
6340 if (!this->emitRVOPtr(RE))
6346 return this->emitRetVoid(RS);
6352 return this->emitRetVoid(RS);
6358 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6365 if (
auto *CondInit = IS->
getInit()) {
6381 return visitChildStmt(IS->
getThen());
6383 return visitChildStmt(Else);
6389 if (!this->emitIsConstantContext(IS))
6392 if (!this->emitIsConstantContext(IS))
6394 if (!this->emitInv(IS))
6408 LabelTy LabelElse = this->getLabel();
6409 LabelTy LabelEnd = this->getLabel();
6410 if (!this->jumpFalse(LabelElse, IS))
6412 if (!visitChildStmt(IS->
getThen()))
6414 if (!this->jump(LabelEnd, IS))
6416 this->emitLabel(LabelElse);
6417 if (!visitChildStmt(Else))
6419 this->emitLabel(LabelEnd);
6421 LabelTy LabelEnd = this->getLabel();
6422 if (!this->jumpFalse(LabelEnd, IS))
6424 if (!visitChildStmt(IS->
getThen()))
6426 this->emitLabel(LabelEnd);
6435template <
class Emitter>
6440 LabelTy CondLabel = this->getLabel();
6441 LabelTy EndLabel = this->getLabel();
6445 this->fallthrough(CondLabel);
6446 this->emitLabel(CondLabel);
6462 if (!this->jumpFalse(EndLabel, S))
6472 if (!this->jump(CondLabel, S))
6474 this->fallthrough(EndLabel);
6475 this->emitLabel(EndLabel);
6484 LabelTy StartLabel = this->getLabel();
6485 LabelTy EndLabel = this->getLabel();
6486 LabelTy CondLabel = this->getLabel();
6490 this->fallthrough(StartLabel);
6491 this->emitLabel(StartLabel);
6497 this->fallthrough(CondLabel);
6498 this->emitLabel(CondLabel);
6505 if (!this->jumpTrue(StartLabel, S))
6508 this->fallthrough(EndLabel);
6509 this->emitLabel(EndLabel);
6513template <
class Emitter>
6521 LabelTy EndLabel = this->getLabel();
6522 LabelTy CondLabel = this->getLabel();
6523 LabelTy IncLabel = this->getLabel();
6530 this->fallthrough(CondLabel);
6531 this->emitLabel(CondLabel);
6543 if (!this->jumpFalse(EndLabel, S))
6552 this->fallthrough(IncLabel);
6553 this->emitLabel(IncLabel);
6559 if (!this->jump(CondLabel, S))
6563 this->emitLabel(EndLabel);
6569template <
class Emitter>
6579 LabelTy EndLabel = this->getLabel();
6580 LabelTy CondLabel = this->getLabel();
6581 LabelTy IncLabel = this->getLabel();
6596 this->fallthrough(CondLabel);
6597 this->emitLabel(CondLabel);
6600 if (!this->jumpFalse(EndLabel, S))
6611 this->fallthrough(IncLabel);
6612 this->emitLabel(IncLabel);
6617 if (!this->jump(CondLabel, S))
6620 this->fallthrough(EndLabel);
6621 this->emitLabel(EndLabel);
6625template <
class Emitter>
6636 if (LI.BreakLabel) {
6637 TargetLabel = *LI.BreakLabel;
6638 BreakScope = LI.BreakOrContinueScope;
6644 if (LI.Name == TargetLoop) {
6645 TargetLabel = *LI.BreakLabel;
6646 BreakScope = LI.BreakOrContinueScope;
6657 C =
C->getParent()) {
6658 if (!
C->destroyLocals())
6662 return this->jump(*TargetLabel, S);
6665template <
class Emitter>
6676 if (LI.ContinueLabel) {
6677 TargetLabel = *LI.ContinueLabel;
6678 ContinueScope = LI.BreakOrContinueScope;
6684 if (LI.Name == TargetLoop) {
6685 TargetLabel = *LI.ContinueLabel;
6686 ContinueScope = LI.BreakOrContinueScope;
6691 assert(TargetLabel);
6694 C =
C->getParent()) {
6695 if (!
C->destroyLocals())
6699 return this->jump(*TargetLabel, S);
6702template <
class Emitter>
6705 if (
Cond->containsErrors())
6712 LabelTy EndLabel = this->getLabel();
6717 if (
const auto *CondInit = S->
getInit())
6728 if (!this->emitSetLocal(CondT, CondVar, S))
6738 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6741 if (CS->caseStmtIsGNURange()) {
6742 LabelTy EndOfRangeCheck = this->getLabel();
6743 const Expr *Low = CS->getLHS();
6744 const Expr *High = CS->getRHS();
6748 if (!this->emitGetLocal(CondT, CondVar, CS))
6750 if (!this->
visit(Low))
6753 if (!this->emitGE(
LT, S))
6755 if (!this->jumpFalse(EndOfRangeCheck, S))
6758 if (!this->emitGetLocal(CondT, CondVar, CS))
6760 if (!this->
visit(High))
6763 if (!this->emitLE(HT, S))
6767 this->emitLabel(EndOfRangeCheck);
6772 if (
Value->isValueDependent())
6777 if (!this->emitGetLocal(CondT, CondVar, CS))
6783 if (!this->emitEQ(ValueT, S))
6788 assert(!DefaultLabel);
6789 DefaultLabel = this->getLabel();
6796 if (!this->jump(*DefaultLabel, S))
6799 if (!this->jump(EndLabel, S))
6807 this->fallthrough(EndLabel);
6808 this->emitLabel(EndLabel);
6813template <
class Emitter>
6821 return this->emitUnsupported(S);
6826template <
class Emitter>
6833 if (LI.DefaultLabel) {
6834 DefaultLabel = *LI.DefaultLabel;
6839 this->emitLabel(DefaultLabel);
6843template <
class Emitter>
6850 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6853 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6854 !this->Ctx.getLangOpts().MSVCCompat) {
6856 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6862 const Expr *Assumption = AA->getAssumption();
6873 if (!this->emitAssume(Assumption))
6882 if (IsMSVCConstexprAttr)
6883 return this->emitPopMSVCCE(S);
6887template <
class Emitter>
6893template <
class Emitter>
6894bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6901 assert(ClosureClass->
captures().empty());
6905 "A generic lambda's static-invoker function must be a "
6906 "template specialization");
6910 void *InsertPos =
nullptr;
6911 const FunctionDecl *CorrespondingCallOpSpecialization =
6913 assert(CorrespondingCallOpSpecialization);
6914 LambdaCallOp = CorrespondingCallOpSpecialization;
6918 assert(ClosureClass->
captures().empty());
6919 const Function *
Func = this->getFunction(LambdaCallOp);
6922 assert(
Func->hasThisPointer());
6925 if (
Func->hasRVO()) {
6926 if (!this->emitRVOPtr(MD))
6934 if (!this->emitNullPtr(0,
nullptr, MD))
6939 auto It = this->Params.find(PVD);
6940 assert(It != this->Params.end());
6944 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6945 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6949 if (!this->emitCall(
Func, 0, LambdaCallOp))
6954 return this->emitRet(*ReturnType, MD);
6957 return this->emitRetVoid(MD);
6960template <
class Emitter>
6961bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6962 if (Ctx.getLangOpts().CPlusPlus23)
6972 const Expr *InitExpr =
Init->getInit();
6974 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6978 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6988template <
class Emitter>
6990 assert(!ReturnType);
6993 if (!this->emitStartThisLifetime1(Ctor))
6996 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6997 const Expr *InitExpr,
7000 if (InitExpr->getType().isNull())
7004 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7007 if (!this->visit(InitExpr))
7010 if (F->isBitField())
7011 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
7013 return this->emitInitThisField(*T, FieldOffset, InitExpr);
7018 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7021 if (
Activate && !this->emitActivate(InitExpr))
7024 return this->visitInitializerPop(InitExpr);
7028 const Record *
R = this->getRecord(RD);
7031 bool IsUnion =
R->isUnion();
7041 if (!this->emitThis(Ctor))
7044 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7047 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7048 this->emitRetVoid(Ctor);
7051 unsigned FieldInits = 0;
7053 for (
const auto *
Init : Ctor->
inits()) {
7057 const Expr *InitExpr =
Init->getInit();
7059 const Record::Field *F =
R->getField(
Member);
7063 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7067 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7070 if (
Init->isBaseVirtual()) {
7071 assert(
R->getVirtualBase(BaseDecl));
7072 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
7078 const Record::Base *B =
R->getBase(BaseDecl);
7080 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7084 if (!this->visitInitializerPop(InitExpr))
7089 unsigned ChainSize = IFD->getChainingSize();
7090 assert(ChainSize >= 2);
7092 unsigned NestedFieldOffset = 0;
7093 const Record::Field *NestedField =
nullptr;
7094 for (
unsigned I = 0; I != ChainSize; ++I) {
7096 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7097 assert(FieldRecord);
7099 NestedField = FieldRecord->
getField(FD);
7100 assert(NestedField);
7101 IsUnion = IsUnion || FieldRecord->
isUnion();
7103 NestedFieldOffset += NestedField->Offset;
7106 if (I != ChainSize - 1)
7109 assert(NestedField);
7112 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7117 unsigned InitFieldOffset = 0;
7118 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7120 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7121 assert(FieldRecord);
7122 NestedField = FieldRecord->
getField(FD);
7123 InitFieldOffset += NestedField->Offset;
7124 assert(NestedField);
7125 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7127 if (!this->emitFinishInitPop(InitExpr))
7131 InitStack.pop_back_n(ChainSize - 1);
7134 assert(
Init->isDelegatingInitializer());
7135 if (!this->emitThis(InitExpr))
7137 if (!this->visitInitializerPop(
Init->getInit()))
7141 if (!
Scope.destroyLocals())
7145 if (FieldInits !=
R->getNumFields()) {
7146 assert(FieldInits < R->getNumFields());
7148 if (!this->emitStartThisLifetime(Ctor))
7155 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7156 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7163 if (!visitStmt(Body))
7170template <
class Emitter>
7173 const Record *
R = this->getRecord(RD);
7177 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7178 if (!this->visitStmt(
Dtor->getBody()))
7182 if (!this->emitThis(
Dtor))
7185 if (!this->emitCheckDestruction(
Dtor))
7189 if (!
R->isUnion()) {
7193 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7197 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7199 if (!this->emitDestructionPop(D,
SourceInfo{}))
7204 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7205 if (
Base.R->hasTrivialDtor())
7209 if (!this->emitRecordDestructionPop(
Base.R, {}))
7213 if (!this->emitMarkDestroyed(
Dtor))
7217 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7220template <
class Emitter>
7221bool Compiler<Emitter>::compileUnionAssignmentOperator(
7223 if (!this->emitThis(MD))
7226 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7229 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7232template <
class Emitter>
7242 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7243 return this->compileConstructor(Ctor);
7244 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7245 return this->compileDestructor(
Dtor);
7248 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7253 return this->compileUnionAssignmentOperator(MD);
7256 return this->emitLambdaStaticInvokerBody(MD);
7260 if (
const auto *Body = F->
getBody())
7274 return FD->getBitWidthValue();
7277template <
class Emitter>
7293 if (!
Ctx.getLangOpts().CPlusPlus14)
7294 return this->emitInvalid(E);
7296 return this->emitError(E);
7298 if (!this->
visit(SubExpr))
7302 if (!this->emitIncPtr(E))
7309 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7310 : this->emitIncf(getFPOptions(E), E);
7322 if (!
Ctx.getLangOpts().CPlusPlus14)
7323 return this->emitInvalid(E);
7325 return this->emitError(E);
7327 if (!this->
visit(SubExpr))
7331 if (!this->emitDecPtr(E))
7338 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7339 : this->emitDecf(getFPOptions(E), E);
7352 if (!
Ctx.getLangOpts().CPlusPlus14)
7353 return this->emitInvalid(E);
7355 return this->emitError(E);
7357 if (!this->
visit(SubExpr))
7361 if (!this->emitLoadPtr(E))
7363 if (!this->emitConstUint8(1, E))
7365 if (!this->emitAddOffsetUint8(E))
7367 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7373 return this->emitIncfPop(getFPOptions(E), E);
7383 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7384 if (!this->emitLoadFloat(E))
7386 APFloat F(TargetSemantics, 1);
7387 if (!this->emitFloat(F, E))
7390 if (!this->emitAddf(getFPOptions(E), E))
7392 if (!this->emitStoreFloat(E))
7404 return E->
isGLValue() || this->emitLoadPop(*T, E);
7407 if (!
Ctx.getLangOpts().CPlusPlus14)
7408 return this->emitInvalid(E);
7410 return this->emitError(E);
7412 if (!this->
visit(SubExpr))
7416 if (!this->emitLoadPtr(E))
7418 if (!this->emitConstUint8(1, E))
7420 if (!this->emitSubOffsetUint8(E))
7422 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7428 return this->emitDecfPop(getFPOptions(E), E);
7438 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7439 if (!this->emitLoadFloat(E))
7441 APFloat F(TargetSemantics, 1);
7442 if (!this->emitFloat(F, E))
7445 if (!this->emitSubf(getFPOptions(E), E))
7447 if (!this->emitStoreFloat(E))
7459 return E->
isGLValue() || this->emitLoadPop(*T, E);
7463 return this->emitError(E);
7466 return this->
discard(SubExpr);
7471 if (!this->emitInv(E))
7475 return this->emitCast(
PT_Bool, ET, E);
7479 return this->emitError(E);
7481 if (!this->
visit(SubExpr))
7483 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7486 return this->emitError(E);
7488 if (!this->
visit(SubExpr))
7504 if (!
Ctx.getLangOpts().CPlusPlus) {
7506 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7507 Deref && Deref->getOpcode() == UO_Deref)
7508 return this->
delegate(Deref->getSubExpr());
7514 return this->
discard(SubExpr);
7516 if (!this->
visit(SubExpr))
7523 return this->emitNarrowPtr(E);
7528 return this->emitError(E);
7530 if (!this->
visit(SubExpr))
7532 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7544 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7549 assert(
false &&
"Unhandled opcode");
7555template <
class Emitter>
7561 return this->
discard(SubExpr);
7564 auto prepareResult = [=]() ->
bool {
7569 return this->emitGetPtrLocal(*LocalIndex, E);
7576 unsigned SubExprOffset = ~0u;
7577 auto createTemp = [=, &SubExprOffset]() ->
bool {
7580 if (!this->
visit(SubExpr))
7582 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7586 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7587 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7589 return this->emitArrayElemPop(ElemT, Index, E);
7594 if (!prepareResult())
7598 for (
unsigned I = 0; I != 2; ++I) {
7599 if (!getElem(SubExprOffset, I))
7601 if (!this->emitNeg(ElemT, E))
7603 if (!this->emitInitElem(ElemT, I, E))
7614 if (!this->
visit(SubExpr))
7616 if (!this->emitComplexBoolCast(SubExpr))
7618 if (!this->emitInv(E))
7621 return this->emitCast(
PT_Bool, ET, E);
7625 return this->emitComplexReal(SubExpr);
7628 if (!this->
visit(SubExpr))
7632 if (!this->emitConstUint8(1, E))
7634 return this->emitArrayElemPtrPopUint8(E);
7645 if (!this->emitArrayElem(ElemT, 1, E))
7647 if (!this->emitNeg(ElemT, E))
7649 if (!this->emitInitElem(ElemT, 1, E))
7657 return this->emitInvalid(E);
7663template <
class Emitter>
7669 return this->
discard(SubExpr);
7672 if (UnaryOp == UO_Extension)
7675 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7676 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7677 return this->emitInvalid(E);
7680 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7687 if (!this->emitGetPtrLocal(*LocalIndex, E))
7692 unsigned SubExprOffset =
7694 if (!this->
visit(SubExpr))
7696 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7701 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7702 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7704 return this->emitArrayElemPop(ElemT, Index, E);
7709 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7710 if (!getElem(SubExprOffset, I))
7712 if (!this->emitNeg(ElemT, E))
7714 if (!this->emitInitElem(ElemT, I, E))
7729 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7730 if (!getElem(SubExprOffset, I))
7733 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7735 if (!this->emitInv(E))
7737 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7739 if (!this->emitNeg(ElemT, E))
7741 if (ElemT != ResultVecElemT &&
7742 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7744 if (!this->emitInitElem(ResultVecElemT, I, E))
7750 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7751 if (!getElem(SubExprOffset, I))
7754 if (!this->emitInv(E))
7757 if (!this->emitComp(ElemT, E))
7760 if (!this->emitInitElem(ElemT, I, E))
7765 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7770template <
class Emitter>
7772 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
7775 return this->emitConst(ECD->getInitVal(), E);
7777 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7781 return F && this->emitGetFnPtr(F, E);
7783 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7791 return this->emitInitGlobal(*T, *Index, E);
7794 if (!this->emitGetPtrGlobal(*Index, E))
7798 return this->emitFinishInit(E);
7810 auto maybePopPtr = [&]() ->
bool {
7812 return this->emitPopPtr(E);
7819 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7823 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7828 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7829 if (IsReference || !It->second.IsPtr)
7830 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7832 return this->emitGetPtrParam(It->second.Index, E);
7835 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
7842 const unsigned Offset = It->second.Offset;
7845 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
7847 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
7850 if (
auto GlobalIndex =
P.getGlobal(D)) {
7852 if (!
Ctx.getLangOpts().CPlusPlus11)
7853 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7854 if (!
Ctx.getLangOpts().CPlusPlus23)
7855 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7857 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
7860 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
7864 auto revisit = [&](
const VarDecl *VD,
7865 bool IsConstexprUnknown =
true) ->
bool {
7867 IsConstexprUnknown);
7872 if (!this->emitPopCC(E))
7875 if (VarState.notCreated())
7883 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7885 if (
auto It = this->LambdaCaptures.find(D);
7886 It != this->LambdaCaptures.end()) {
7887 auto [Offset, IsPtr] = It->second;
7890 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
7891 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
7895 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7896 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7897 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7901 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7902 return this->
delegate(BD->getBinding());
7908 return this->emitDummyPtr(D, E);
7913 const auto *VD = dyn_cast<VarDecl>(D);
7915 return this->emitError(E);
7918 if (!
Ctx.getLangOpts().CPlusPlus) {
7922 return revisit(VD,
false);
7926 return this->emitDummyPtr(D, E);
7930 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7931 if (T.isConstant(
Ctx.getASTContext()))
7933 return T->isReferenceType();
7937 typeShouldBeVisited(DeclType)) {
7939 Init && !
Init->isValueDependent()) {
7944 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
7957 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7962 return revisit(VD, IsConstexprUnknown);
7963 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7964 return revisit(VD,
true);
7973 return this->emitDummyPtr(
7977template <
class Emitter>
7983template <
class Emitter>
7993 if (!
C->destroyLocals())
7999template <
class Emitter>
8000unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8003 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8005 return Ty->getAsCXXRecordDecl();
8007 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8008 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8010 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8014template <
class Emitter>
8021 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8026 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8027 getFPOptions(E), E);
8029 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8030 getFPOptions(E), E);
8034 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8039 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8041 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8045 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8049 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8050 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8057template <
class Emitter>
8060 assert(FromT != ToT);
8063 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8065 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8067 return this->emitCast(FromT, ToT, E);
8071template <
class Emitter>
8072bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8076 return this->
discard(SubExpr);
8078 if (!this->visit(SubExpr))
8081 if (!this->emitConstUint8(0, SubExpr))
8083 return this->emitArrayElemPtrPopUint8(SubExpr);
8087 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8091template <
class Emitter>
8092bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8093 assert(!DiscardResult);
8097 if (!this->emitArrayElem(ElemT, 0, E))
8100 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8103 if (!this->emitCast(ElemT,
PT_Bool, E))
8108 LabelTy LabelTrue = this->getLabel();
8109 if (!this->jumpTrue(LabelTrue, E))
8112 if (!this->emitArrayElemPop(ElemT, 1, E))
8115 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8118 if (!this->emitCast(ElemT,
PT_Bool, E))
8122 LabelTy EndLabel = this->getLabel();
8123 this->jump(EndLabel, E);
8125 this->emitLabel(LabelTrue);
8126 if (!this->emitPopPtr(E))
8128 if (!this->emitConstBool(
true, E))
8131 this->fallthrough(EndLabel);
8132 this->emitLabel(EndLabel);
8137template <
class Emitter>
8138bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8149 LHSIsComplex =
true;
8150 ElemT = classifyComplexElementType(LHS->
getType());
8151 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8152 if (!this->visit(LHS))
8154 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8157 LHSIsComplex =
false;
8159 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8160 if (!this->visit(LHS))
8162 if (!this->emitSetLocal(LHST, LHSOffset, E))
8169 RHSIsComplex =
true;
8170 ElemT = classifyComplexElementType(RHS->
getType());
8171 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8172 if (!this->visit(RHS))
8174 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8177 RHSIsComplex =
false;
8179 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8180 if (!this->visit(RHS))
8182 if (!this->emitSetLocal(RHST, RHSOffset, E))
8186 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8187 bool IsComplex) ->
bool {
8189 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8191 return this->emitArrayElemPop(ElemT, Index, E);
8193 return this->emitGetLocal(ElemT, LocalOffset, E);
8196 for (
unsigned I = 0; I != 2; ++I) {
8198 if (!getElem(LHSOffset, I, LHSIsComplex))
8200 if (!getElem(RHSOffset, I, RHSIsComplex))
8203 if (!this->emitEQ(ElemT, E))
8206 if (!this->emitCastBoolUint8(E))
8211 if (!this->emitAddUint8(E))
8213 if (!this->emitConstUint8(2, E))
8217 if (!this->emitEQUint8(E))
8220 if (!this->emitNEUint8(E))
8227 return this->emitCast(
PT_Bool, ResT, E);
8234template <
class Emitter>
8235bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8238 assert(!
R->hasTrivialDtor());
8241 const Function *DtorFunc = getFunction(
Dtor);
8244 assert(DtorFunc->hasThisPointer());
8245 assert(DtorFunc->getNumParams() == 1);
8246 return this->emitCall(DtorFunc, 0, Loc);
8251template <
class Emitter>
8252bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8264 return this->emitPopPtr(Loc);
8266 for (ssize_t I = N - 1; I >= 1; --I) {
8267 if (!this->emitConstUint64(I, Loc))
8269 if (!this->emitArrayElemPtrUint64(Loc))
8271 if (!this->emitDestructionPop(ElemDesc, Loc))
8275 if (!this->emitConstUint64(0, Loc))
8277 if (!this->emitArrayElemPtrPopUint64(Loc))
8279 return this->emitDestructionPop(ElemDesc, Loc);
8284 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8289template <
class Emitter>
8290bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E,
bool CU) {
8291 assert(!DiscardResult &&
"Should've been checked before");
8292 unsigned DummyID = P.getOrCreateDummy(D, CU);
8294 if (!this->emitGetPtrGlobal(DummyID, E))
8302 return this->emitDecayPtr(
PT_Ptr, PT, E);
8308template <
class Emitter>
8311 return this->emitConstFloat(
Floating(F), Info);
8313 APInt I = F.bitcastToAPInt();
8314 return this->emitConstFloat(
8315 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8316 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8327template <
class Emitter>
8328bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8341 if (!this->emitGetPtrLocal(*LocalIndex, E))
8351 if (!this->visit(SubExpr))
8353 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8354 unsigned TempOffset =
8355 allocateLocalPrimitive(SubExpr, *FromT,
true);
8356 if (!this->visit(SubExpr))
8358 if (!this->emitSetLocal(*FromT, TempOffset, E))
8360 if (!this->emitGetPtrLocal(TempOffset, E))
8367 if (!this->emitBitCast(E))
8369 return DiscardResult ? this->emitPopPtr(E) :
true;
8373 const llvm::fltSemantics *TargetSemantics =
nullptr;
8375 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8381 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8383 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8384 ResultBitWidth, TargetSemantics,
8389 return this->emitPop(*ToT, E);
8398template <
class Emitter>
8399bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8404 unsigned NumElems = 0;
8407 NumElems = VT->getNumElements();
8408 ElemType = VT->getElementType();
8410 NumElems = MT->getNumElementsFlattened();
8411 ElemType = MT->getElementType();
8414 PrimType ElemT = classifyPrim(ElemType);
8415 for (
unsigned I = 0; I != NumElems; ++I) {
8416 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8418 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8420 if (!this->emitInitElem(ElemT, I, E))
8430 QualType ArrElemType = CAT->getElementType();
8431 unsigned ArrSize = CAT->getZExtSize();
8434 for (
unsigned I = 0; I != ArrSize; ++I) {
8435 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8437 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8439 if (!this->emitInitElem(*ElemT, I, E))
8443 for (
unsigned I = 0; I != ArrSize; ++I) {
8444 if (!this->emitConstUint32(I, E))
8446 if (!this->emitArrayElemPtrUint32(E))
8448 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8450 if (!this->emitFinishInitPop(E))
8460 const Record *
R = getRecord(DestType);
8464 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8466 const Record::Base *B =
R->getBase(BS.getType());
8468 if (!this->emitGetPtrBase(B->Offset, E))
8470 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8472 if (!this->emitFinishInitPop(E))
8477 for (
const Record::Field &F :
R->fields()) {
8478 if (F.isUnnamedBitField())
8481 QualType FieldType = F.Decl->getType();
8483 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8485 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8487 if (F.isBitField()) {
8488 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8491 if (!this->emitInitField(*FieldT, F.Offset, E))
8495 if (!this->emitGetPtrField(F.Offset, E))
8497 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8499 if (!this->emitPopPtr(E))
8512template <
class Emitter>
8513unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8516 return VT->getNumElements();
8518 return MT->getNumElementsFlattened();
8522 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8526 const Record *
R = getRecord(Ty);
8530 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8532 Count += countHLSLFlatElements(BS.getType());
8534 for (
const Record::Field &F :
R->fields()) {
8535 if (F.isUnnamedBitField())
8537 Count += countHLSLFlatElements(F.Decl->getType());
8542 if (canClassify(Ty))
8551template <
class Emitter>
8552bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8553 QualType SrcType,
unsigned SrcOffset,
8558 auto saveToLocal = [&](
PrimType T) ->
bool {
8559 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8560 if (!this->emitSetLocal(T, Offset, E))
8562 Elements.push_back({Offset, T});
8568 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8569 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8570 return std::nullopt;
8575 unsigned NumElems = 0;
8578 NumElems = VT->getNumElements();
8579 ElemType = VT->getElementType();
8581 NumElems = MT->getNumElementsFlattened();
8582 ElemType = MT->getElementType();
8585 PrimType ElemT = classifyPrim(ElemType);
8586 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8587 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8589 if (!this->emitArrayElemPop(ElemT, I, E))
8591 if (!saveToLocal(ElemT))
8601 QualType ArrElemType = CAT->getElementType();
8602 unsigned ArrSize = CAT->getZExtSize();
8605 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8606 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8608 if (!this->emitArrayElemPop(*ElemT, I, E))
8610 if (!saveToLocal(*ElemT))
8614 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8615 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8617 if (!this->emitConstUint32(I, E))
8619 if (!this->emitArrayElemPtrPopUint32(E))
8624 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8635 const Record *
R = getRecord(SrcType);
8639 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8641 if (Elements.size() >= MaxElements)
8643 const Record::Base *B =
R->getBase(BS.getType());
8645 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8647 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8652 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8658 for (
const Record::Field &F :
R->fields()) {
8659 if (Elements.size() >= MaxElements)
8661 if (F.isUnnamedBitField())
8664 QualType FieldType = F.Decl->getType();
8665 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8667 if (!this->emitGetPtrFieldPop(F.Offset, E))
8671 if (!this->emitLoadPop(*FieldT, E))
8673 if (!saveToLocal(*FieldT))
8677 if (!FieldPtrOffset)
8679 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8695template <
class Emitter>
8696bool Compiler<Emitter>::emitHLSLConstructAggregate(
8702 const auto &Src = Elements[ElemIdx++];
8703 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8705 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8709 unsigned NumElems = 0;
8712 NumElems = VT->getNumElements();
8713 ElemType = VT->getElementType();
8715 NumElems = MT->getNumElementsFlattened();
8716 ElemType = MT->getElementType();
8719 PrimType DestElemT = classifyPrim(ElemType);
8720 for (
unsigned I = 0; I != NumElems; ++I) {
8721 if (!loadAndCast(DestElemT, ElemType))
8723 if (!this->emitInitElem(DestElemT, I, E))
8733 QualType ArrElemType = CAT->getElementType();
8734 unsigned ArrSize = CAT->getZExtSize();
8737 for (
unsigned I = 0; I != ArrSize; ++I) {
8738 if (!loadAndCast(*ElemT, ArrElemType))
8740 if (!this->emitInitElem(*ElemT, I, E))
8744 for (
unsigned I = 0; I != ArrSize; ++I) {
8745 if (!this->emitConstUint32(I, E))
8747 if (!this->emitArrayElemPtrUint32(E))
8749 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8751 if (!this->emitFinishInitPop(E))
8761 const Record *
R = getRecord(DestType);
8765 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8767 const Record::Base *B =
R->getBase(BS.getType());
8769 if (!this->emitGetPtrBase(B->Offset, E))
8771 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
8773 if (!this->emitFinishInitPop(E))
8778 for (
const Record::Field &F :
R->fields()) {
8779 if (F.isUnnamedBitField())
8782 QualType FieldType = F.Decl->getType();
8784 if (!loadAndCast(*FieldT, FieldType))
8786 if (F.isBitField()) {
8787 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8790 if (!this->emitInitField(*FieldT, F.Offset, E))
8794 if (!this->emitGetPtrField(F.Offset, E))
8796 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
8798 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.
llvm::SmallPtrSet< const ParmVarDecl *, 1 > FoundParams
bool VisitDeclRefExpr(const DeclRefExpr *E) override
a trap message and trap category.
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
ArrayRef< LValuePathEntry > getLValuePath() const
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
unsigned getStructNumFields() const
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
const ValueDecl * getMemberPointerDecl() const
APValue & getUnionValue()
APValue & getArrayFiller()
bool isIndeterminate() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
bool isMemberPointer() const
unsigned getArraySize() const
@ None
There is no such object (it's outside its lifetime).
bool isNullPointer() const
APValue & getStructBase(unsigned i)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
const LangOptions & getLangOpts() const
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
AddrLabelExpr - The GNU address of label extension, representing &&label.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
uint64_t getValue() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Represents a C++ declaration that introduces decls from somewhere else.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isLogicalOp(Opcode Opc)
static bool isComparisonOp(Opcode Opc)
static bool isShiftOp(Opcode Opc)
static bool isCommaOp(Opcode Opc)
static Opcode getOpForCompoundAssignment(Opcode Opc)
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BreakStmt - This represents a break.
Represents a C++2a __builtin_bit_cast(T, v) expression.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Expr * getArg(unsigned Arg)
Return the specified argument.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
bool 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.
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.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
const Expr * getBase() const
Represents a reference to emded data.
ChildElementIter< false > begin()
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
bool isValueDependent() const
Determines whether the value of this expression depends on.
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
An expression trait intrinsic.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
llvm::APFloat getValue() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
const Expr * getSubExpr() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, 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.
bool isCompatibleWith(ClangABI Version) const
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
SourceLocation getAtLoc() const
bool isExpressibleAsConstantInitializer() const
ObjCStringLiteral, used for Objective-C string literals i.e.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Expr * getIndexExpr(unsigned Idx)
const OffsetOfNode & getComponent(unsigned Idx) const
unsigned getNumComponents() const
Helper class for OffsetOfExpr.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
@ Array
An index into an array.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
ParenExpr - This represents a parenthesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringLiteral * getFunctionName()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withConst() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstant(const ASTContext &Ctx) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Base for LValueReferenceType and RValueReferenceType.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
bool isSatisfied() const
Whether or not the requires clause is satisfied.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getLocation() const
std::string ComputeName(ASTContext &Context) const
Scope - A scope is a transient data structure that is used while parsing the program.
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
llvm::APSInt getShuffleMaskIdx(unsigned N) const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Represents an expression that computes the length of a parameter pack.
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Represents a C++11 static_assert declaration.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
bool Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
StmtClass getStmtClass() const
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
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.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
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 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 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 visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
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.
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T)
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)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType ReturnType
Type of the expression returned by the function.
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitEmbedExpr(const EmbedExpr *E)
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.
const Expr * asExpr() const
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 This(InterpState &S, CodePtr OpPC)
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.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
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
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
EvalResult is a struct with detailed info about an evaluated expression.
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()