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))
3767 if (!this->
visit(ArrayIndexExpr))
3771 if (!this->emitCast(IndexT,
PT_Sint64, E))
3781 return this->emitOffsetOf(T, E, E);
3784template <
class Emitter>
3793 return this->visitZeroInitializer(*T, Ty, E);
3800 if (!this->emitGetPtrLocal(*LocalIndex, E))
3808 ElemQT = CT->getElementType();
3811 NumElems = VT->getNumElements();
3812 ElemQT = VT->getElementType();
3818 for (
unsigned I = 0, N = NumElems; I != N; ++I) {
3819 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
3821 if (!this->emitInitElem(ElemT, I, E))
3830template <
class Emitter>
3835template <
class Emitter>
3841template <
class Emitter>
3846template <
class Emitter>
3851 return this->emitConst(E->
getValue(), E);
3854template <
class Emitter>
3859 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
3873 unsigned ParamIndex = 0;
3877 if (!this->emitGetParam(PT, ParamIndex, E))
3882 return this->emitCall(F, 0, E);
3887template <
class Emitter>
3895 const Expr *PlacementDest =
nullptr;
3896 bool IsNoThrow =
false;
3901 if (PlacementArgs != 0) {
3910 if (PlacementArgs == 1) {
3918 if (!this->emitInvalidNewDeleteExpr(E, E))
3923 if (OperatorNew->isReservedGlobalPlacementOperator())
3924 PlacementDest = Arg1;
3928 return this->emitInvalid(E);
3930 }
else if (!OperatorNew
3931 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
3932 return this->emitInvalidNewDeleteExpr(E, E);
3935 if (!PlacementDest) {
3940 Desc =
P.createDescriptor(E, *ElemT,
nullptr,
3943 Desc =
P.createDescriptor(
3946 false,
false,
false,
3952 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
3956 const Expr *Stripped = *ArraySizeExpr;
3957 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
3958 Stripped = ICE->getSubExpr())
3959 if (ICE->getCastKind() != CK_NoOp &&
3960 ICE->getCastKind() != CK_IntegralCast)
3968 if (!this->
visit(Stripped))
3970 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
3973 if (PlacementDest) {
3974 if (!this->
visit(PlacementDest))
3976 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3978 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
3981 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
3986 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
3990 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
3997 size_t StaticInitElems = 0;
3998 const Expr *DynamicInit =
nullptr;
4002 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4003 StaticInitElems = CAT->getZExtSize();
4008 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4009 if (ILE->hasArrayFiller())
4010 DynamicInit = ILE->getArrayFiller();
4029 const Function *CtorFunc =
nullptr;
4030 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4034 }
else if (!DynamicInit && !ElemT)
4037 LabelTy EndLabel = this->getLabel();
4038 LabelTy StartLabel = this->getLabel();
4043 if (!this->emitDupPtr(E))
4045 if (!this->emitNullPtr(0,
nullptr, E))
4047 if (!this->emitEQPtr(E))
4049 if (!this->jumpTrue(EndLabel, E))
4056 if (!this->emitConst(StaticInitElems,
SizeT, E))
4058 if (!this->emitSetLocal(
SizeT, Iter, E))
4061 this->fallthrough(StartLabel);
4062 this->emitLabel(StartLabel);
4064 if (!this->emitGetLocal(
SizeT, Iter, E))
4066 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4068 if (!this->emitLT(
SizeT, E))
4070 if (!this->jumpFalse(EndLabel, E))
4074 if (!this->emitGetLocal(
SizeT, Iter, E))
4076 if (!this->emitArrayElemPtr(
SizeT, E))
4079 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4084 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4086 if (!this->emitStorePop(*InitT, E))
4090 if (!this->visitZeroArrayInitializer(ElemType, E))
4093 }
else if (DynamicInit) {
4095 if (!this->
visit(DynamicInit))
4097 if (!this->emitStorePop(*InitT, E))
4104 if (!this->visitZeroInitializer(
4108 if (!this->emitStorePop(*ElemT, E))
4112 if (!this->emitCall(CtorFunc, 0, E))
4117 if (!this->emitGetPtrLocal(Iter, E))
4119 if (!this->emitIncPop(
SizeT,
false, E))
4122 if (!this->jump(StartLabel, E))
4125 this->fallthrough(EndLabel);
4126 this->emitLabel(EndLabel);
4130 if (PlacementDest) {
4131 if (!this->
visit(PlacementDest))
4133 if (!this->emitCheckNewTypeMismatch(E, E))
4138 if (!this->emitAlloc(Desc, E))
4147 if (!this->emitInit(*ElemT, E))
4158 return this->emitPopPtr(E);
4163template <
class Emitter>
4169 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4170 return this->emitInvalidNewDeleteExpr(E, E);
4179template <
class Emitter>
4185 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4190 return this->emitGetFnPtr(
Func, E);
4193template <
class Emitter>
4197 auto canonType = [](
const Type *T) {
4198 return T->getCanonicalTypeUnqualified().getTypePtr();
4206 return this->emitGetTypeid(
4210 return this->emitGetTypeid(
4219 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4225 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4228 return this->emitPopPtr(E);
4232template <
class Emitter>
4236 return this->emitDummyPtr(E, E);
4237 return this->emitError(E);
4240template <
class Emitter>
4243 return this->emitDummyPtr(E, E);
4244 return this->emitError(E);
4247template <
class Emitter>
4249 assert(
Ctx.getLangOpts().CPlusPlus);
4250 return this->emitConstBool(E->
getValue(), E);
4253template <
class Emitter>
4265 return this->emitDummyPtr(GuidDecl, E);
4270 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4279 assert(
V.isStruct());
4280 assert(
V.getStructNumBases() == 0);
4284 return this->emitFinishInit(E);
4287template <
class Emitter>
4297template <
class Emitter>
4306template <
class Emitter>
4312template <
class Emitter>
4316 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4320 if (OVE->isUnique())
4336template <
class Emitter>
4341template <
class Emitter>
4343 return this->emitError(E);
4346template <
class Emitter>
4352 return this->emitDummyPtr(E, E);
4355template <
class Emitter>
4356bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4361 QualType ElemType = VT->getElementType();
4362 PrimType ElemT = classifyPrim(ElemType);
4364 PrimType SrcElemT = classifyVectorElementType(SrcType);
4370 if (!this->emitGetPtrLocal(*LocalIndex, E))
4374 unsigned SrcOffset =
4375 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4376 if (!this->visit(Src))
4378 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4381 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4382 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4384 if (!this->emitArrayElemPop(SrcElemT, I, E))
4388 if (SrcElemT != ElemT) {
4389 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4391 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4392 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4396 if (!this->emitInitElem(ElemT, I, E))
4402template <
class Emitter>
4404 return emitVectorConversion(E->
getSrcExpr(), E);
4407template <
class Emitter>
4411 return this->emitInvalid(E);
4420 assert(NumOutputElems > 0);
4426 if (!this->emitGetPtrLocal(*LocalIndex, E))
4431 unsigned VectorOffsets[2];
4432 for (
unsigned I = 0; I != 2; ++I) {
4435 if (!this->
visit(Vecs[I]))
4437 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4440 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4442 assert(ShuffleIndex >= -1);
4443 if (ShuffleIndex == -1)
4444 return this->emitInvalidShuffleVectorIndex(I, E);
4446 assert(ShuffleIndex < (NumInputElems * 2));
4447 if (!this->emitGetLocal(
PT_Ptr,
4448 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4450 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4451 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4454 if (!this->emitInitElem(ElemT, I, E))
4459 return this->emitPopPtr(E);
4464template <
class Emitter>
4469 Base->getType()->isVectorType() ||
4475 if (Indices.size() == 1) {
4480 if (!this->emitConstUint32(Indices[0], E))
4482 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4492 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4500 if (!this->emitGetPtrLocal(*ResultIndex, E))
4508 uint32_t DstIndex = 0;
4509 for (uint32_t I : Indices) {
4510 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4512 if (!this->emitArrayElemPop(ElemT, I, E))
4514 if (!this->emitInitElem(ElemT, DstIndex, E))
4524template <
class Emitter>
4528 return this->
discard(SubExpr) && this->emitInvalid(E);
4534 return this->emitDummyPtr(E, E);
4537template <
class Emitter>
4542 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4547 if (!this->
visit(SubExpr))
4549 if (!this->emitConstUint8(0, E))
4551 if (!this->emitArrayElemPtrPopUint8(E))
4553 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4558 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4560 return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
4562 assert(SecondFieldT ==
PT_Ptr);
4564 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4566 if (!this->emitExpandPtr(E))
4570 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4572 return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
4575template <
class Emitter>
4590 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4594 return this->emitUnsupported(E);
4603 return this->
Visit(E);
4610 return this->
Visit(E);
4614 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4617 if (
const auto *CE = dyn_cast<CastExpr>(E);
4619 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
4626 if (
const auto *PE = dyn_cast<ParenExpr>(E))
4629 if (
const auto *CE = dyn_cast<CastExpr>(E);
4630 CE && (CE->getCastKind() == CK_DerivedToBase ||
4631 CE->getCastKind() == CK_UncheckedDerivedToBase ||
4632 CE->getCastKind() == CK_NoOp))
4652 if (!this->emitGetPtrLocal(*LocalIndex, E))
4662 return this->
Visit(E);
4665template <
class Emitter>
4671 return this->
Visit(E) && this->emitFinishInit(E);
4674template <
class Emitter>
4680 return this->
Visit(E) && this->emitFinishInitPop(E);
4686 return this->
Visit(E);
4697 if (!this->
visit(E))
4699 return this->emitComplexBoolCast(E);
4704 if (!this->
visit(E))
4712 return this->emitIsNonNullPtr(E);
4716 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
4719 return this->emitCast(*T,
PT_Bool, E);
4722template <
class Emitter>
4726 QT = AT->getValueType();
4730 return this->emitZeroBool(E);
4732 return this->emitZeroSint8(E);
4734 return this->emitZeroUint8(E);
4736 return this->emitZeroSint16(E);
4738 return this->emitZeroUint16(E);
4740 return this->emitZeroSint32(E);
4742 return this->emitZeroUint32(E);
4744 return this->emitZeroSint64(E);
4746 return this->emitZeroUint64(E);
4748 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
4750 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
4752 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
4755 return this->emitNullMemberPtr(0,
nullptr, E);
4757 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
4758 return this->emitFloat(F, E);
4761 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
4765 llvm_unreachable(
"unknown primitive type");
4768template <
class Emitter>
4769bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
4774 for (
const Record::Field &Field :
R->fields()) {
4775 if (Field.isUnnamedBitField())
4782 if (!this->visitZeroInitializer(T, QT, E))
4785 if (!this->emitInitFieldActivate(T, Field.Offset, E))
4789 if (!this->emitInitField(T, Field.Offset, E))
4794 if (!this->emitGetPtrField(Field.Offset, E))
4801 if (!this->visitZeroInitializer(T, ET, E))
4803 if (!this->emitInitElem(T, I, E))
4808 if (!this->visitZeroArrayInitializer(D->
getType(), E))
4811 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
4819 if (!this->emitFinishInitActivatePop(E))
4823 if (!this->emitFinishInitPop(E))
4827 for (
const Record::Base &B :
R->bases()) {
4828 if (!this->emitGetPtrBase(B.Offset, E))
4830 if (!this->visitZeroRecordInitializer(B.R, E))
4832 if (!this->emitFinishInitPop(E))
4841template <
class Emitter>
4842bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
4843 assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
4849 for (
size_t I = 0; I != NumElems; ++I) {
4850 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
4852 if (!this->emitInitElem(*ElemT, I, E))
4858 const Record *
R = getRecord(ElemType);
4862 for (
size_t I = 0; I != NumElems; ++I) {
4863 if (!this->emitConstUint32(I, E))
4865 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4867 if (!this->visitZeroRecordInitializer(R, E))
4869 if (!this->emitPopPtr(E))
4875 for (
size_t I = 0; I != NumElems; ++I) {
4876 if (!this->emitConstUint32(I, E))
4878 if (!this->emitArrayElemPtr(
PT_Uint32, E))
4880 if (!this->visitZeroArrayInitializer(ElemType, E))
4882 if (!this->emitPopPtr(E))
4891template <
class Emitter>
4892bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
4894 if (!canClassify(E->
getType()))
4897 if (!this->visit(RHS))
4899 if (!this->visit(LHS))
4906 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
4910 bool Activates = refersToUnion(LHS);
4913 if (!this->emitFlip(
PT_Ptr, RHT, E))
4916 if (DiscardResult) {
4917 if (BitField && Activates)
4918 return this->emitStoreBitFieldActivatePop(RHT, E);
4920 return this->emitStoreBitFieldPop(RHT, E);
4922 return this->emitStoreActivatePop(RHT, E);
4924 return this->emitStorePop(RHT, E);
4927 auto maybeLoad = [&](
bool Result) ->
bool {
4933 return this->emitLoadPop(RHT, E);
4937 if (BitField && Activates)
4938 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
4940 return maybeLoad(this->emitStoreBitField(RHT, E));
4942 return maybeLoad(this->emitStoreActivate(RHT, E));
4944 return maybeLoad(this->emitStore(RHT, E));
4947template <
class Emitter>
4948template <
typename T>
4952 return this->emitConstSint8(
Value, Info);
4954 return this->emitConstUint8(
Value, Info);
4956 return this->emitConstSint16(
Value, Info);
4958 return this->emitConstUint16(
Value, Info);
4960 return this->emitConstSint32(
Value, Info);
4962 return this->emitConstUint32(
Value, Info);
4964 return this->emitConstSint64(
Value, Info);
4966 return this->emitConstUint64(
Value, Info);
4968 return this->emitConstBool(
Value, Info);
4975 llvm_unreachable(
"Invalid integral type");
4978 llvm_unreachable(
"unknown primitive type");
4981template <
class Emitter>
4982template <
typename T>
4983bool Compiler<Emitter>::emitConst(T
Value,
const Expr *E) {
4984 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
4987template <
class Emitter>
4991 return this->emitConstIntAPS(
Value, Info);
4993 return this->emitConstIntAP(
Value, Info);
4995 if (
Value.isSigned())
4996 return this->emitConst(
Value.getSExtValue(), Ty, Info);
4997 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5000template <
class Emitter>
5004 return this->emitConstIntAPS(
Value, Info);
5006 return this->emitConstIntAP(
Value, Info);
5009 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5010 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5013template <
class Emitter>
5014bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5015 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5018template <
class Emitter>
5031 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>()))
5032 Locals.insert({VD, Local});
5033 VarScope->addForScopeKind(Local, SC);
5034 return Local.Offset;
5037template <
class Emitter>
5042 bool IsTemporary =
false;
5043 if (
auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<
const Decl *>())) {
5046 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5047 Init = VarD->getInit();
5049 if (
auto *E = Src.dyn_cast<
const Expr *>()) {
5060 return std::nullopt;
5065 Locals.insert({Key, Local});
5066 VarScope->addForScopeKind(Local, SC);
5067 return Local.Offset;
5070template <
class Emitter>
5080 return std::nullopt;
5090 return Local.Offset;
5093template <
class Emitter>
5095 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5096 return PT->getPointeeType()->getAsCanonical<RecordType>();
5102 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5106template <
class Emitter>
5108 return P.getOrCreateRecord(RD);
5111template <
class Emitter>
5113 return Ctx.getOrCreateFunction(FD);
5116template <
class Emitter>
5120 auto maybeDestroyLocals = [&]() ->
bool {
5121 if (DestroyToplevelScope)
5122 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5123 return this->emitCheckAllocations(E);
5130 return this->emitRetVoid(E) && maybeDestroyLocals();
5138 return this->emitRet(*T, E) && maybeDestroyLocals();
5146 if (!this->emitGetPtrLocal(*LocalOffset, E))
5154 return this->emitRetValue(E) && maybeDestroyLocals();
5157 return maybeDestroyLocals() &&
false;
5160template <
class Emitter>
5162 bool DestroyToplevelScope) {
5166 return this->
visitExpr(E, DestroyToplevelScope);
5169template <
class Emitter>
5181 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5182 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5196template <
class Emitter>
5198 bool ConstantContext) {
5201 if (!ConstantContext) {
5215 auto GlobalIndex =
P.getGlobal(VD);
5216 assert(GlobalIndex);
5218 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5221 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5225 auto Local =
Locals.find(VD);
5226 assert(Local !=
Locals.end());
5228 if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
5231 if (!this->emitGetPtrLocal(Local->second.Offset, VD))
5241 auto GlobalIndex =
P.getGlobal(VD);
5242 assert(GlobalIndex);
5243 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5252 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5255template <
class Emitter>
5266 if (!this->isActive())
5271 if (
Init &&
Init->isValueDependent())
5275 auto checkDecl = [&]() ->
bool {
5277 return !NeedsOp || this->emitCheckDecl(VD, VD);
5284 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5287 if (
P.isGlobalInitialized(*GlobalIndex))
5291 }
else if ((GlobalIndex =
5306 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5309 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5312 if (!this->emitStartInit(
Init))
5318 if (!this->emitEndInit(
Init))
5321 return this->emitFinishInitGlobal(
Init);
5331 if (!
Init ||
Init->getType()->isVoidType())
5340 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5352 if (!this->emitCheckRefInit(
Init))
5356 return this->emitSetLocal(*VarT, Offset, VD);
5364 if (!this->emitGetPtrLocal(*Offset,
Init))
5372template <
class Emitter>
5393 Locals.insert({VD, Local});
5396 if (!this->emitGetPtrLocal(Local.Offset, VD))
5402 return this->emitDestructionPop(D, VD);
5411 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5435template <
class Emitter>
5450 unsigned ParamIndex = 0;
5457 const Expr *Arg = Args[ParamIndex];
5458 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5460 unsigned ArgOffset =
5462 if (!this->
visit(Arg))
5464 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5470 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5482 if (
This->getType()->isPointerType()) {
5485 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5492 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5514template <
class Emitter>
5520 return this->emitConst(Val.
getInt(), ValType, Info);
5523 return this->emitFloat(F, Info);
5528 if (!this->emitGetMemberPtr(MemberDecl, Info))
5534 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5540 return this->emitNullMemberPtr(0,
nullptr, Info);
5545 return this->emitNull(ValType, 0,
nullptr, Info);
5550 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5551 return this->
visit(BaseExpr);
5556 QualType EntryType = VD->getType();
5557 for (
auto &Entry : Path) {
5559 uint64_t Index = Entry.getAsArrayIndex();
5562 if (!this->emitConst(Index,
PT_Uint64, Info))
5564 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5566 EntryType = ElemType;
5576 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5577 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5579 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5581 EntryType = FD->getType();
5585 if (!this->emitGetPtrBasePop(BaseOffset,
false, Info))
5587 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
5599template <
class Emitter>
5609 const Record::Field *RF = R->getField(I);
5610 QualType FieldType = RF->Decl->getType();
5616 if (!this->emitInitField(*PT, RF->Offset, Info))
5619 if (!this->emitGetPtrField(RF->Offset, Info))
5623 if (!this->emitFinishInitPop(Info))
5633 if (I >= R->getNumBases())
5638 const Record::Base *RB = R->getBase(I);
5639 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
5641 if (!this->emitGetPtrBase(RB->Offset, Info))
5645 if (!this->emitFinishInitPop(Info))
5660 const Record::Field *RF = R->getField(UnionField);
5661 QualType FieldType = RF->Decl->getType();
5666 if (RF->isBitField())
5667 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
5669 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
5672 if (!this->emitGetPtrField(RF->Offset, Info))
5674 if (!this->emitActivate(Info))
5678 return this->emitPopPtr(Info);
5682 const auto *ArrType = T->getAsArrayTypeUnsafe();
5683 QualType ElemType = ArrType->getElementType();
5686 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
5687 const APValue &Elem = A >= InitializedElems
5696 if (!this->emitInitElem(*ElemT, A, Info))
5699 if (!this->emitConstUint32(A, Info))
5701 if (!this->emitArrayElemPtrUint32(Info))
5705 if (!this->emitPopPtr(Info))
5716template <
class Emitter>
5718 unsigned BuiltinID) {
5719 if (BuiltinID == Builtin::BI__builtin_constant_p) {
5724 return this->emitConst(0, E);
5727 if (!this->emitStartSpeculation(E))
5729 LabelTy EndLabel = this->getLabel();
5730 if (!this->speculate(E, EndLabel))
5732 if (!this->emitEndSpeculation(E))
5734 this->fallthrough(EndLabel);
5742 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
5743 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
5744 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
5745 BuiltinID == Builtin::BI__builtin_function_start) {
5748 return this->emitDummyPtr(E, E);
5759 if (!this->emitGetPtrLocal(*LocalIndex, E))
5764 switch (BuiltinID) {
5765 case Builtin::BI__builtin_object_size:
5766 case Builtin::BI__builtin_dynamic_object_size: {
5770 if (!this->
visit(Arg0))
5781 case Builtin::BI__assume:
5782 case Builtin::BI__builtin_assume:
5785 case Builtin::BI__atomic_is_lock_free:
5786 case Builtin::BI__atomic_always_lock_free: {
5797 for (
const auto *Arg : E->
arguments()) {
5798 if (!this->
visit(Arg))
5804 if (!this->emitCallBI(E, BuiltinID, E))
5813template <
class Emitter>
5834 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
5835 DD && DD->isTrivial()) {
5837 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
5839 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
5840 this->emitPopPtr(E);
5848 bool HasRVO = !
ReturnType->isVoidType() && !T;
5856 if (!this->emitGetPtrLocal(*LocalIndex, E))
5864 if (!this->emitGetPtrLocal(*LocalIndex, E))
5868 if (!this->emitDupPtr(E))
5875 bool IsAssignmentOperatorCall =
false;
5876 bool ActivateLHS =
false;
5877 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
5878 OCE && OCE->isAssignmentOp()) {
5882 assert(Args.size() == 2);
5883 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
5885 IsAssignmentOperatorCall =
true;
5886 std::reverse(Args.begin(), Args.end());
5892 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
5893 MD && MD->isStatic()) {
5897 Args.erase(Args.begin());
5901 bool Devirtualized =
false;
5904 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
5912 if (!this->
visit(Callee))
5914 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
5916 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
5918 if (!this->emitGetMemberPtrBase(E))
5921 const auto *InstancePtr = MC->getImplicitObjectArgument();
5928 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
5929 Devirtualized =
true;
5930 if (!this->
visit(Stripped))
5933 if (!this->
visit(InstancePtr))
5937 if (!this->
visit(InstancePtr))
5941 }
else if (
const auto *PD =
5942 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
5943 if (!this->emitCheckPseudoDtor(E))
5951 return this->emitEndLifetimePop(E);
5952 }
else if (!FuncDecl) {
5956 if (!this->
visit(Callee))
5958 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
5967 if (IsAssignmentOperatorCall) {
5968 assert(Args.size() == 2);
5971 if (!this->emitFlip(Arg2T, Arg1T, E))
5985 assert(HasRVO ==
Func->hasRVO());
5987 bool HasQualifier =
false;
5988 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
5989 HasQualifier = ME->hasQualifier();
5991 bool IsVirtual =
false;
5992 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
5993 IsVirtual = !Devirtualized && MD->isVirtual();
5998 if (IsVirtual && !HasQualifier) {
5999 uint32_t VarArgSize = 0;
6000 unsigned NumParams =
6001 Func->getNumWrittenParams() +
6003 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6006 if (!this->emitCallVirt(
Func, VarArgSize, E))
6008 }
else if (
Func->isVariadic()) {
6009 uint32_t VarArgSize = 0;
6010 unsigned NumParams =
6011 Func->getNumWrittenParams() +
6013 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6015 if (!this->emitCallVar(
Func, VarArgSize, E))
6018 if (!this->emitCall(
Func, 0, E))
6027 uint32_t ArgSize = 0;
6028 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6034 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6036 if (!this->emitGetMemberPtrDecl(E))
6039 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6042 if (!this->emitCallPtr(ArgSize, E, E))
6053template <
class Emitter>
6060template <
class Emitter>
6067template <
class Emitter>
6072 return this->emitConstBool(E->
getValue(), E);
6075template <
class Emitter>
6081 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6082 return this->emitNullPtr(Val,
nullptr, E);
6085template <
class Emitter>
6093 return this->emitZero(T, E);
6096template <
class Emitter>
6101 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6102 if (this->LambdaThisCapture.Offset > 0) {
6103 if (this->LambdaThisCapture.IsPtr)
6104 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6105 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6114 return this->emitThis(E);
6129 unsigned StartIndex = 0;
6130 unsigned EndIndex = 0;
6132 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6134 EndIndex = StartIndex;
6141 for (; StartIndex > 0; --StartIndex) {
6151 if (StartIndex == 0 && EndIndex == 0)
6157 assert(StartIndex <= EndIndex);
6160 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6172 case Stmt::CompoundStmtClass:
6174 case Stmt::DeclStmtClass:
6176 case Stmt::ReturnStmtClass:
6178 case Stmt::IfStmtClass:
6180 case Stmt::WhileStmtClass:
6182 case Stmt::DoStmtClass:
6184 case Stmt::ForStmtClass:
6186 case Stmt::CXXForRangeStmtClass:
6188 case Stmt::BreakStmtClass:
6190 case Stmt::ContinueStmtClass:
6192 case Stmt::SwitchStmtClass:
6194 case Stmt::CaseStmtClass:
6196 case Stmt::DefaultStmtClass:
6198 case Stmt::AttributedStmtClass:
6200 case Stmt::CXXTryStmtClass:
6202 case Stmt::NullStmtClass:
6205 case Stmt::GCCAsmStmtClass:
6206 case Stmt::MSAsmStmtClass:
6207 case Stmt::GotoStmtClass:
6208 return this->emitInvalid(S);
6209 case Stmt::LabelStmtClass:
6212 if (
const auto *E = dyn_cast<Expr>(S))
6219template <
class Emitter>
6222 for (
const auto *InnerStmt : S->
body())
6225 return Scope.destroyLocals();
6228template <
class Emitter>
6229bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6230 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6231 for (
auto *BD : DD->flat_bindings())
6232 if (
auto *KD = BD->getHoldingVar();
6233 KD && !this->visitVarDecl(KD, KD->getInit()))
6247template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6249 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6250 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6257 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6262 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6263 ICE && (ICE->getCastKind() == CK_NoOp ||
6264 ICE->getCastKind() == CK_DerivedToBase ||
6265 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6266 E = ICE->getSubExpr();
6270 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6271 const auto *ThisRecord =
6272 This->getType()->getPointeeType()->getAsRecordDecl();
6273 if (!ThisRecord->isUnion())
6276 if (
const auto *Ctor =
6277 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6278 return Ctor->getParent() == ThisRecord;
6287template <
class Emitter>
6289 bool EvaluateConditionDecl) {
6290 for (
const auto *D : DS->
decls()) {
6295 const auto *VD = dyn_cast<VarDecl>(D);
6302 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6309template <
class Emitter>
6312 return this->emitUnsupported(RS);
6318 if (!this->
visit(RE))
6324 if (RE->getType()->isVoidType()) {
6325 if (!this->
visit(RE))
6328 if (RE->containsErrors())
6333 if (!this->emitRVOPtr(RE))
6339 return this->emitRetVoid(RS);
6345 return this->emitRetVoid(RS);
6351 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6358 if (
auto *CondInit = IS->
getInit()) {
6374 return visitChildStmt(IS->
getThen());
6376 return visitChildStmt(Else);
6382 if (!this->emitIsConstantContext(IS))
6385 if (!this->emitIsConstantContext(IS))
6387 if (!this->emitInv(IS))
6401 LabelTy LabelElse = this->getLabel();
6402 LabelTy LabelEnd = this->getLabel();
6403 if (!this->jumpFalse(LabelElse, IS))
6405 if (!visitChildStmt(IS->
getThen()))
6407 if (!this->jump(LabelEnd, IS))
6409 this->emitLabel(LabelElse);
6410 if (!visitChildStmt(Else))
6412 this->emitLabel(LabelEnd);
6414 LabelTy LabelEnd = this->getLabel();
6415 if (!this->jumpFalse(LabelEnd, IS))
6417 if (!visitChildStmt(IS->
getThen()))
6419 this->emitLabel(LabelEnd);
6428template <
class Emitter>
6433 LabelTy CondLabel = this->getLabel();
6434 LabelTy EndLabel = this->getLabel();
6438 this->fallthrough(CondLabel);
6439 this->emitLabel(CondLabel);
6455 if (!this->jumpFalse(EndLabel, S))
6465 if (!this->jump(CondLabel, S))
6467 this->fallthrough(EndLabel);
6468 this->emitLabel(EndLabel);
6477 LabelTy StartLabel = this->getLabel();
6478 LabelTy EndLabel = this->getLabel();
6479 LabelTy CondLabel = this->getLabel();
6483 this->fallthrough(StartLabel);
6484 this->emitLabel(StartLabel);
6490 this->fallthrough(CondLabel);
6491 this->emitLabel(CondLabel);
6498 if (!this->jumpTrue(StartLabel, S))
6501 this->fallthrough(EndLabel);
6502 this->emitLabel(EndLabel);
6506template <
class Emitter>
6514 LabelTy EndLabel = this->getLabel();
6515 LabelTy CondLabel = this->getLabel();
6516 LabelTy IncLabel = this->getLabel();
6523 this->fallthrough(CondLabel);
6524 this->emitLabel(CondLabel);
6536 if (!this->jumpFalse(EndLabel, S))
6545 this->fallthrough(IncLabel);
6546 this->emitLabel(IncLabel);
6552 if (!this->jump(CondLabel, S))
6556 this->emitLabel(EndLabel);
6562template <
class Emitter>
6572 LabelTy EndLabel = this->getLabel();
6573 LabelTy CondLabel = this->getLabel();
6574 LabelTy IncLabel = this->getLabel();
6589 this->fallthrough(CondLabel);
6590 this->emitLabel(CondLabel);
6593 if (!this->jumpFalse(EndLabel, S))
6604 this->fallthrough(IncLabel);
6605 this->emitLabel(IncLabel);
6610 if (!this->jump(CondLabel, S))
6613 this->fallthrough(EndLabel);
6614 this->emitLabel(EndLabel);
6618template <
class Emitter>
6629 if (LI.BreakLabel) {
6630 TargetLabel = *LI.BreakLabel;
6631 BreakScope = LI.BreakOrContinueScope;
6637 if (LI.Name == TargetLoop) {
6638 TargetLabel = *LI.BreakLabel;
6639 BreakScope = LI.BreakOrContinueScope;
6650 C =
C->getParent()) {
6651 if (!
C->destroyLocals())
6655 return this->jump(*TargetLabel, S);
6658template <
class Emitter>
6669 if (LI.ContinueLabel) {
6670 TargetLabel = *LI.ContinueLabel;
6671 ContinueScope = LI.BreakOrContinueScope;
6677 if (LI.Name == TargetLoop) {
6678 TargetLabel = *LI.ContinueLabel;
6679 ContinueScope = LI.BreakOrContinueScope;
6684 assert(TargetLabel);
6687 C =
C->getParent()) {
6688 if (!
C->destroyLocals())
6692 return this->jump(*TargetLabel, S);
6695template <
class Emitter>
6698 if (
Cond->containsErrors())
6705 LabelTy EndLabel = this->getLabel();
6710 if (
const auto *CondInit = S->
getInit())
6721 if (!this->emitSetLocal(CondT, CondVar, S))
6731 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
6734 if (CS->caseStmtIsGNURange()) {
6735 LabelTy EndOfRangeCheck = this->getLabel();
6736 const Expr *Low = CS->getLHS();
6737 const Expr *High = CS->getRHS();
6741 if (!this->emitGetLocal(CondT, CondVar, CS))
6743 if (!this->
visit(Low))
6746 if (!this->emitGE(
LT, S))
6748 if (!this->jumpFalse(EndOfRangeCheck, S))
6751 if (!this->emitGetLocal(CondT, CondVar, CS))
6753 if (!this->
visit(High))
6756 if (!this->emitLE(HT, S))
6760 this->emitLabel(EndOfRangeCheck);
6765 if (
Value->isValueDependent())
6770 if (!this->emitGetLocal(CondT, CondVar, CS))
6776 if (!this->emitEQ(ValueT, S))
6781 assert(!DefaultLabel);
6782 DefaultLabel = this->getLabel();
6789 if (!this->jump(*DefaultLabel, S))
6792 if (!this->jump(EndLabel, S))
6800 this->fallthrough(EndLabel);
6801 this->emitLabel(EndLabel);
6806template <
class Emitter>
6814 return this->emitUnsupported(S);
6819template <
class Emitter>
6826 if (LI.DefaultLabel) {
6827 DefaultLabel = *LI.DefaultLabel;
6832 this->emitLabel(DefaultLabel);
6836template <
class Emitter>
6843 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
6846 if (this->
Ctx.getLangOpts().CXXAssumptions &&
6847 !this->Ctx.getLangOpts().MSVCCompat) {
6849 auto *AA = dyn_cast<CXXAssumeAttr>(A);
6855 const Expr *Assumption = AA->getAssumption();
6866 if (!this->emitAssume(Assumption))
6875 if (IsMSVCConstexprAttr)
6876 return this->emitPopMSVCCE(S);
6880template <
class Emitter>
6886template <
class Emitter>
6887bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
6894 assert(ClosureClass->
captures().empty());
6898 "A generic lambda's static-invoker function must be a "
6899 "template specialization");
6903 void *InsertPos =
nullptr;
6904 const FunctionDecl *CorrespondingCallOpSpecialization =
6906 assert(CorrespondingCallOpSpecialization);
6907 LambdaCallOp = CorrespondingCallOpSpecialization;
6911 assert(ClosureClass->
captures().empty());
6912 const Function *
Func = this->getFunction(LambdaCallOp);
6915 assert(
Func->hasThisPointer());
6918 if (
Func->hasRVO()) {
6919 if (!this->emitRVOPtr(MD))
6927 if (!this->emitNullPtr(0,
nullptr, MD))
6932 auto It = this->Params.find(PVD);
6933 assert(It != this->Params.end());
6937 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
6938 if (!this->emitGetParam(ParamType, It->second.Index, MD))
6942 if (!this->emitCall(
Func, 0, LambdaCallOp))
6947 return this->emitRet(*ReturnType, MD);
6950 return this->emitRetVoid(MD);
6953template <
class Emitter>
6954bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
6955 if (Ctx.getLangOpts().CPlusPlus23)
6965 const Expr *InitExpr =
Init->getInit();
6967 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
6971 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
6981template <
class Emitter>
6983 assert(!ReturnType);
6986 if (!this->emitStartThisLifetime1(Ctor))
6989 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
6990 const Expr *InitExpr,
6993 if (InitExpr->getType().isNull())
6997 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7000 if (!this->visit(InitExpr))
7003 if (F->isBitField())
7004 return this->emitInitThisBitField(*T, FieldOffset, F->bitWidth(),
7006 return this->emitInitThisField(*T, FieldOffset, InitExpr);
7011 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7014 if (
Activate && !this->emitActivate(InitExpr))
7017 return this->visitInitializerPop(InitExpr);
7021 const Record *
R = this->getRecord(RD);
7024 bool IsUnion =
R->isUnion();
7034 if (!this->emitThis(Ctor))
7037 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7040 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7041 this->emitRetVoid(Ctor);
7044 unsigned FieldInits = 0;
7046 for (
const auto *
Init : Ctor->
inits()) {
7050 const Expr *InitExpr =
Init->getInit();
7052 const Record::Field *F =
R->getField(
Member);
7056 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7060 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7063 if (
Init->isBaseVirtual()) {
7064 assert(
R->getVirtualBase(BaseDecl));
7065 if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
7071 const Record::Base *B =
R->getBase(BaseDecl);
7073 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7077 if (!this->visitInitializerPop(InitExpr))
7082 unsigned ChainSize = IFD->getChainingSize();
7083 assert(ChainSize >= 2);
7085 unsigned NestedFieldOffset = 0;
7086 const Record::Field *NestedField =
nullptr;
7087 for (
unsigned I = 0; I != ChainSize; ++I) {
7089 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7090 assert(FieldRecord);
7092 NestedField = FieldRecord->
getField(FD);
7093 assert(NestedField);
7094 IsUnion = IsUnion || FieldRecord->
isUnion();
7096 NestedFieldOffset += NestedField->Offset;
7099 if (I != ChainSize - 1)
7102 assert(NestedField);
7105 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7110 unsigned InitFieldOffset = 0;
7111 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7113 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7114 assert(FieldRecord);
7115 NestedField = FieldRecord->
getField(FD);
7116 InitFieldOffset += NestedField->Offset;
7117 assert(NestedField);
7118 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7120 if (!this->emitFinishInitPop(InitExpr))
7124 InitStack.pop_back_n(ChainSize - 1);
7127 assert(
Init->isDelegatingInitializer());
7128 if (!this->emitThis(InitExpr))
7130 if (!this->visitInitializerPop(
Init->getInit()))
7134 if (!
Scope.destroyLocals())
7138 if (FieldInits !=
R->getNumFields()) {
7139 assert(FieldInits < R->getNumFields());
7141 if (!this->emitStartThisLifetime(Ctor))
7148 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7149 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7156 if (!visitStmt(Body))
7163template <
class Emitter>
7166 const Record *
R = this->getRecord(RD);
7170 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7171 if (!this->visitStmt(
Dtor->getBody()))
7175 if (!this->emitThis(
Dtor))
7178 if (!this->emitCheckDestruction(
Dtor))
7182 if (!
R->isUnion()) {
7186 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7190 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7192 if (!this->emitDestructionPop(D,
SourceInfo{}))
7197 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7198 if (
Base.R->hasTrivialDtor())
7202 if (!this->emitRecordDestructionPop(
Base.R, {}))
7206 if (!this->emitMarkDestroyed(
Dtor))
7210 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7213template <
class Emitter>
7214bool Compiler<Emitter>::compileUnionAssignmentOperator(
7216 if (!this->emitThis(MD))
7219 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7222 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7225template <
class Emitter>
7235 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7236 return this->compileConstructor(Ctor);
7237 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7238 return this->compileDestructor(
Dtor);
7241 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7246 return this->compileUnionAssignmentOperator(MD);
7249 return this->emitLambdaStaticInvokerBody(MD);
7253 if (
const auto *Body = F->
getBody())
7267 return FD->getBitWidthValue();
7270template <
class Emitter>
7286 if (!
Ctx.getLangOpts().CPlusPlus14)
7287 return this->emitInvalid(E);
7289 return this->emitError(E);
7291 if (!this->
visit(SubExpr))
7295 if (!this->emitIncPtr(E))
7302 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7303 : this->emitIncf(getFPOptions(E), E);
7315 if (!
Ctx.getLangOpts().CPlusPlus14)
7316 return this->emitInvalid(E);
7318 return this->emitError(E);
7320 if (!this->
visit(SubExpr))
7324 if (!this->emitDecPtr(E))
7331 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7332 : this->emitDecf(getFPOptions(E), E);
7345 if (!
Ctx.getLangOpts().CPlusPlus14)
7346 return this->emitInvalid(E);
7348 return this->emitError(E);
7350 if (!this->
visit(SubExpr))
7354 if (!this->emitLoadPtr(E))
7356 if (!this->emitConstUint8(1, E))
7358 if (!this->emitAddOffsetUint8(E))
7360 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7366 return this->emitIncfPop(getFPOptions(E), E);
7376 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7377 if (!this->emitLoadFloat(E))
7379 APFloat F(TargetSemantics, 1);
7380 if (!this->emitFloat(F, E))
7383 if (!this->emitAddf(getFPOptions(E), E))
7385 if (!this->emitStoreFloat(E))
7397 return E->
isGLValue() || this->emitLoadPop(*T, E);
7400 if (!
Ctx.getLangOpts().CPlusPlus14)
7401 return this->emitInvalid(E);
7403 return this->emitError(E);
7405 if (!this->
visit(SubExpr))
7409 if (!this->emitLoadPtr(E))
7411 if (!this->emitConstUint8(1, E))
7413 if (!this->emitSubOffsetUint8(E))
7415 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7421 return this->emitDecfPop(getFPOptions(E), E);
7431 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7432 if (!this->emitLoadFloat(E))
7434 APFloat F(TargetSemantics, 1);
7435 if (!this->emitFloat(F, E))
7438 if (!this->emitSubf(getFPOptions(E), E))
7440 if (!this->emitStoreFloat(E))
7452 return E->
isGLValue() || this->emitLoadPop(*T, E);
7456 return this->emitError(E);
7459 return this->
discard(SubExpr);
7464 if (!this->emitInv(E))
7468 return this->emitCast(
PT_Bool, ET, E);
7472 return this->emitError(E);
7474 if (!this->
visit(SubExpr))
7476 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
7479 return this->emitError(E);
7481 if (!this->
visit(SubExpr))
7497 if (!
Ctx.getLangOpts().CPlusPlus) {
7499 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
7500 Deref && Deref->getOpcode() == UO_Deref)
7501 return this->
delegate(Deref->getSubExpr());
7507 return this->
discard(SubExpr);
7509 if (!this->
visit(SubExpr))
7516 return this->emitNarrowPtr(E);
7521 return this->emitError(E);
7523 if (!this->
visit(SubExpr))
7525 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
7537 : this->visitZeroInitializer(*T, SubExpr->
getType(), SubExpr);
7542 assert(
false &&
"Unhandled opcode");
7548template <
class Emitter>
7554 return this->
discard(SubExpr);
7557 auto prepareResult = [=]() ->
bool {
7562 return this->emitGetPtrLocal(*LocalIndex, E);
7569 unsigned SubExprOffset = ~0u;
7570 auto createTemp = [=, &SubExprOffset]() ->
bool {
7573 if (!this->
visit(SubExpr))
7575 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
7579 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7580 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7582 return this->emitArrayElemPop(ElemT, Index, E);
7587 if (!prepareResult())
7591 for (
unsigned I = 0; I != 2; ++I) {
7592 if (!getElem(SubExprOffset, I))
7594 if (!this->emitNeg(ElemT, E))
7596 if (!this->emitInitElem(ElemT, I, E))
7607 if (!this->
visit(SubExpr))
7609 if (!this->emitComplexBoolCast(SubExpr))
7611 if (!this->emitInv(E))
7614 return this->emitCast(
PT_Bool, ET, E);
7618 return this->emitComplexReal(SubExpr);
7621 if (!this->
visit(SubExpr))
7625 if (!this->emitConstUint8(1, E))
7627 return this->emitArrayElemPtrPopUint8(E);
7638 if (!this->emitArrayElem(ElemT, 1, E))
7640 if (!this->emitNeg(ElemT, E))
7642 if (!this->emitInitElem(ElemT, 1, E))
7650 return this->emitInvalid(E);
7656template <
class Emitter>
7662 return this->
discard(SubExpr);
7665 if (UnaryOp == UO_Extension)
7668 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
7669 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
7670 return this->emitInvalid(E);
7673 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
7680 if (!this->emitGetPtrLocal(*LocalIndex, E))
7685 unsigned SubExprOffset =
7687 if (!this->
visit(SubExpr))
7689 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
7694 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
7695 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
7697 return this->emitArrayElemPop(ElemT, Index, E);
7702 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7703 if (!getElem(SubExprOffset, I))
7705 if (!this->emitNeg(ElemT, E))
7707 if (!this->emitInitElem(ElemT, I, E))
7722 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7723 if (!getElem(SubExprOffset, I))
7726 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
7728 if (!this->emitInv(E))
7730 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
7732 if (!this->emitNeg(ElemT, E))
7734 if (ElemT != ResultVecElemT &&
7735 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
7737 if (!this->emitInitElem(ResultVecElemT, I, E))
7743 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
7744 if (!getElem(SubExprOffset, I))
7747 if (!this->emitInv(E))
7750 if (!this->emitComp(ElemT, E))
7753 if (!this->emitInitElem(ElemT, I, E))
7758 llvm_unreachable(
"Unsupported unary operators should be handled up front");
7763template <
class Emitter>
7765 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
7768 return this->emitConst(ECD->getInitVal(), E);
7770 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
7774 return F && this->emitGetFnPtr(F, E);
7776 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
7784 return this->emitInitGlobal(*T, *Index, E);
7787 if (!this->emitGetPtrGlobal(*Index, E))
7791 return this->emitFinishInit(E);
7803 auto maybePopPtr = [&]() ->
bool {
7805 return this->emitPopPtr(E);
7812 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
7816 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
7821 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
7822 if (IsReference || !It->second.IsPtr)
7823 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
7825 return this->emitGetPtrParam(It->second.Index, E);
7828 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
7835 const unsigned Offset = It->second.Offset;
7838 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
7840 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
7843 if (
auto GlobalIndex =
P.getGlobal(D)) {
7845 if (!
Ctx.getLangOpts().CPlusPlus11)
7846 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
7847 if (!
Ctx.getLangOpts().CPlusPlus23)
7848 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
7850 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
7853 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
7857 auto revisit = [&](
const VarDecl *VD,
7858 bool IsConstexprUnknown =
true) ->
bool {
7860 IsConstexprUnknown);
7865 if (!this->emitPopCC(E))
7868 if (VarState.notCreated())
7876 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
7878 if (
auto It = this->LambdaCaptures.find(D);
7879 It != this->LambdaCaptures.end()) {
7880 auto [Offset, IsPtr] = It->second;
7883 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
7884 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
7888 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
7889 DRE && DRE->refersToEnclosingVariableOrCapture()) {
7890 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
7894 if (
const auto *BD = dyn_cast<BindingDecl>(D))
7895 return this->
delegate(BD->getBinding());
7901 return this->emitDummyPtr(D, E);
7906 const auto *VD = dyn_cast<VarDecl>(D);
7908 return this->emitError(E);
7911 if (!
Ctx.getLangOpts().CPlusPlus) {
7915 return revisit(VD,
false);
7919 return this->emitDummyPtr(D, E);
7923 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
7924 if (T.isConstant(
Ctx.getASTContext()))
7926 return T->isReferenceType();
7930 typeShouldBeVisited(DeclType)) {
7932 Init && !
Init->isValueDependent()) {
7937 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
7950 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
7955 return revisit(VD, IsConstexprUnknown);
7956 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
7957 return revisit(VD,
true);
7966 return this->emitDummyPtr(
7970template <
class Emitter>
7976template <
class Emitter>
7986 if (!
C->destroyLocals())
7992template <
class Emitter>
7993unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
7996 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
7998 return Ty->getAsCXXRecordDecl();
8000 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8001 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8003 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8007template <
class Emitter>
8014 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8019 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8020 getFPOptions(E), E);
8022 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8023 getFPOptions(E), E);
8027 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8032 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8034 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8038 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8042 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8043 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8050template <
class Emitter>
8053 assert(FromT != ToT);
8056 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8058 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8060 return this->emitCast(FromT, ToT, E);
8064template <
class Emitter>
8065bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8069 return this->
discard(SubExpr);
8071 if (!this->visit(SubExpr))
8074 if (!this->emitConstUint8(0, SubExpr))
8076 return this->emitArrayElemPtrPopUint8(SubExpr);
8080 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8084template <
class Emitter>
8085bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8086 assert(!DiscardResult);
8090 if (!this->emitArrayElem(ElemT, 0, E))
8093 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8096 if (!this->emitCast(ElemT,
PT_Bool, E))
8101 LabelTy LabelTrue = this->getLabel();
8102 if (!this->jumpTrue(LabelTrue, E))
8105 if (!this->emitArrayElemPop(ElemT, 1, E))
8108 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8111 if (!this->emitCast(ElemT,
PT_Bool, E))
8115 LabelTy EndLabel = this->getLabel();
8116 this->jump(EndLabel, E);
8118 this->emitLabel(LabelTrue);
8119 if (!this->emitPopPtr(E))
8121 if (!this->emitConstBool(
true, E))
8124 this->fallthrough(EndLabel);
8125 this->emitLabel(EndLabel);
8130template <
class Emitter>
8131bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8142 LHSIsComplex =
true;
8143 ElemT = classifyComplexElementType(LHS->
getType());
8144 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8145 if (!this->visit(LHS))
8147 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8150 LHSIsComplex =
false;
8152 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8153 if (!this->visit(LHS))
8155 if (!this->emitSetLocal(LHST, LHSOffset, E))
8162 RHSIsComplex =
true;
8163 ElemT = classifyComplexElementType(RHS->
getType());
8164 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8165 if (!this->visit(RHS))
8167 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8170 RHSIsComplex =
false;
8172 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8173 if (!this->visit(RHS))
8175 if (!this->emitSetLocal(RHST, RHSOffset, E))
8179 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8180 bool IsComplex) ->
bool {
8182 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8184 return this->emitArrayElemPop(ElemT, Index, E);
8186 return this->emitGetLocal(ElemT, LocalOffset, E);
8189 for (
unsigned I = 0; I != 2; ++I) {
8191 if (!getElem(LHSOffset, I, LHSIsComplex))
8193 if (!getElem(RHSOffset, I, RHSIsComplex))
8196 if (!this->emitEQ(ElemT, E))
8199 if (!this->emitCastBoolUint8(E))
8204 if (!this->emitAddUint8(E))
8206 if (!this->emitConstUint8(2, E))
8210 if (!this->emitEQUint8(E))
8213 if (!this->emitNEUint8(E))
8220 return this->emitCast(
PT_Bool, ResT, E);
8227template <
class Emitter>
8228bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8231 assert(!
R->hasTrivialDtor());
8234 const Function *DtorFunc = getFunction(
Dtor);
8237 assert(DtorFunc->hasThisPointer());
8238 assert(DtorFunc->getNumParams() == 1);
8239 return this->emitCall(DtorFunc, 0, Loc);
8244template <
class Emitter>
8245bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8257 return this->emitPopPtr(Loc);
8259 for (ssize_t I = N - 1; I >= 1; --I) {
8260 if (!this->emitConstUint64(I, Loc))
8262 if (!this->emitArrayElemPtrUint64(Loc))
8264 if (!this->emitDestructionPop(ElemDesc, Loc))
8268 if (!this->emitConstUint64(0, Loc))
8270 if (!this->emitArrayElemPtrPopUint64(Loc))
8272 return this->emitDestructionPop(ElemDesc, Loc);
8277 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8282template <
class Emitter>
8283bool Compiler<Emitter>::emitDummyPtr(
const DeclTy &D,
const Expr *E,
bool CU) {
8284 assert(!DiscardResult &&
"Should've been checked before");
8285 unsigned DummyID = P.getOrCreateDummy(D, CU);
8287 if (!this->emitGetPtrGlobal(DummyID, E))
8295 return this->emitDecayPtr(
PT_Ptr, PT, E);
8301template <
class Emitter>
8304 return this->emitConstFloat(
Floating(F), Info);
8306 APInt I = F.bitcastToAPInt();
8307 return this->emitConstFloat(
8308 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8309 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8320template <
class Emitter>
8321bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8334 if (!this->emitGetPtrLocal(*LocalIndex, E))
8344 if (!this->visit(SubExpr))
8346 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8347 unsigned TempOffset =
8348 allocateLocalPrimitive(SubExpr, *FromT,
true);
8349 if (!this->visit(SubExpr))
8351 if (!this->emitSetLocal(*FromT, TempOffset, E))
8353 if (!this->emitGetPtrLocal(TempOffset, E))
8360 if (!this->emitBitCast(E))
8362 return DiscardResult ? this->emitPopPtr(E) :
true;
8366 const llvm::fltSemantics *TargetSemantics =
nullptr;
8368 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8374 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8376 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8377 ResultBitWidth, TargetSemantics,
8382 return this->emitPop(*ToT, E);
8391template <
class Emitter>
8392bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
8397 unsigned NumElems = 0;
8400 NumElems = VT->getNumElements();
8401 ElemType = VT->getElementType();
8403 NumElems = MT->getNumElementsFlattened();
8404 ElemType = MT->getElementType();
8407 PrimType ElemT = classifyPrim(ElemType);
8408 for (
unsigned I = 0; I != NumElems; ++I) {
8409 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8411 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
8413 if (!this->emitInitElem(ElemT, I, E))
8423 QualType ArrElemType = CAT->getElementType();
8424 unsigned ArrSize = CAT->getZExtSize();
8427 for (
unsigned I = 0; I != ArrSize; ++I) {
8428 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8430 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
8432 if (!this->emitInitElem(*ElemT, I, E))
8436 for (
unsigned I = 0; I != ArrSize; ++I) {
8437 if (!this->emitConstUint32(I, E))
8439 if (!this->emitArrayElemPtrUint32(E))
8441 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
8443 if (!this->emitFinishInitPop(E))
8453 const Record *
R = getRecord(DestType);
8457 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8459 const Record::Base *B =
R->getBase(BS.getType());
8461 if (!this->emitGetPtrBase(B->Offset, E))
8463 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
8465 if (!this->emitFinishInitPop(E))
8470 for (
const Record::Field &F :
R->fields()) {
8471 if (F.isUnnamedBitField())
8474 QualType FieldType = F.Decl->getType();
8476 if (!this->emitGetLocal(SrcT, SrcOffset, E))
8478 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
8480 if (F.isBitField()) {
8481 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8484 if (!this->emitInitField(*FieldT, F.Offset, E))
8488 if (!this->emitGetPtrField(F.Offset, E))
8490 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
8492 if (!this->emitPopPtr(E))
8505template <
class Emitter>
8506unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
8509 return VT->getNumElements();
8511 return MT->getNumElementsFlattened();
8515 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
8519 const Record *
R = getRecord(Ty);
8523 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8525 Count += countHLSLFlatElements(BS.getType());
8527 for (
const Record::Field &F :
R->fields()) {
8528 if (F.isUnnamedBitField())
8530 Count += countHLSLFlatElements(F.Decl->getType());
8535 if (canClassify(Ty))
8544template <
class Emitter>
8545bool Compiler<Emitter>::emitHLSLFlattenAggregate(
8546 QualType SrcType,
unsigned SrcOffset,
8551 auto saveToLocal = [&](
PrimType T) ->
bool {
8552 unsigned Offset = allocateLocalPrimitive(E, T,
true);
8553 if (!this->emitSetLocal(T, Offset, E))
8555 Elements.push_back({Offset, T});
8561 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
8562 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
8563 return std::nullopt;
8568 unsigned NumElems = 0;
8571 NumElems = VT->getNumElements();
8572 ElemType = VT->getElementType();
8574 NumElems = MT->getNumElementsFlattened();
8575 ElemType = MT->getElementType();
8578 PrimType ElemT = classifyPrim(ElemType);
8579 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
8580 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8582 if (!this->emitArrayElemPop(ElemT, I, E))
8584 if (!saveToLocal(ElemT))
8594 QualType ArrElemType = CAT->getElementType();
8595 unsigned ArrSize = CAT->getZExtSize();
8598 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8599 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8601 if (!this->emitArrayElemPop(*ElemT, I, E))
8603 if (!saveToLocal(*ElemT))
8607 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
8608 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8610 if (!this->emitConstUint32(I, E))
8612 if (!this->emitArrayElemPtrPopUint32(E))
8617 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
8628 const Record *
R = getRecord(SrcType);
8632 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8634 if (Elements.size() >= MaxElements)
8636 const Record::Base *B =
R->getBase(BS.getType());
8638 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8640 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
8645 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
8651 for (
const Record::Field &F :
R->fields()) {
8652 if (Elements.size() >= MaxElements)
8654 if (F.isUnnamedBitField())
8657 QualType FieldType = F.Decl->getType();
8658 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
8660 if (!this->emitGetPtrFieldPop(F.Offset, E))
8664 if (!this->emitLoadPop(*FieldT, E))
8666 if (!saveToLocal(*FieldT))
8670 if (!FieldPtrOffset)
8672 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
8688template <
class Emitter>
8689bool Compiler<Emitter>::emitHLSLConstructAggregate(
8695 const auto &Src = Elements[ElemIdx++];
8696 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
8698 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
8702 unsigned NumElems = 0;
8705 NumElems = VT->getNumElements();
8706 ElemType = VT->getElementType();
8708 NumElems = MT->getNumElementsFlattened();
8709 ElemType = MT->getElementType();
8712 PrimType DestElemT = classifyPrim(ElemType);
8713 for (
unsigned I = 0; I != NumElems; ++I) {
8714 if (!loadAndCast(DestElemT, ElemType))
8716 if (!this->emitInitElem(DestElemT, I, E))
8726 QualType ArrElemType = CAT->getElementType();
8727 unsigned ArrSize = CAT->getZExtSize();
8730 for (
unsigned I = 0; I != ArrSize; ++I) {
8731 if (!loadAndCast(*ElemT, ArrElemType))
8733 if (!this->emitInitElem(*ElemT, I, E))
8737 for (
unsigned I = 0; I != ArrSize; ++I) {
8738 if (!this->emitConstUint32(I, E))
8740 if (!this->emitArrayElemPtrUint32(E))
8742 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
8744 if (!this->emitFinishInitPop(E))
8754 const Record *
R = getRecord(DestType);
8758 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
8760 const Record::Base *B =
R->getBase(BS.getType());
8762 if (!this->emitGetPtrBase(B->Offset, E))
8764 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
8766 if (!this->emitFinishInitPop(E))
8771 for (
const Record::Field &F :
R->fields()) {
8772 if (F.isUnnamedBitField())
8775 QualType FieldType = F.Decl->getType();
8777 if (!loadAndCast(*FieldT, FieldType))
8779 if (F.isBitField()) {
8780 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
8783 if (!this->emitInitField(*FieldT, F.Offset, E))
8787 if (!this->emitGetPtrField(F.Offset, E))
8789 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
8791 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()