21#include "llvm/Support/SaveAndRestore.h"
32 if (
const auto *CE = dyn_cast_if_present<ConstantExpr>(E);
33 CE && CE->hasAPValueResult() &&
35 return CE->getResultAsAPSInt().getBoolValue();
57 if (NumElems > std::numeric_limits<unsigned>::max())
59 uint64_t Limit = LangOpts.ConstexprStepLimit;
60 return Limit != 0 && NumElems > Limit;
76 llvm_unreachable(
"Shouldn't be called");
142 this->
Ctx->emitDestroy(*
Idx, E);
149 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
150 this->
Ctx->Descriptors.emplace_back();
151 this->
Ctx->emitInitScope(*
Idx, {});
165 Idx =
static_cast<unsigned>(this->
Ctx->Descriptors.size());
166 this->
Ctx->Descriptors.emplace_back();
167 this->
Ctx->emitInitScope(*
Idx, {});
178 if (
Local.Desc->hasTrivialDtor())
181 if (!
Local.EnabledByDefault) {
182 typename Emitter::LabelTy EndLabel = this->
Ctx->getLabel();
183 if (!this->
Ctx->emitGetLocalEnabled(
Local.Offset, E))
185 if (!this->
Ctx->jumpFalse(EndLabel, E))
188 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
191 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
194 this->
Ctx->fallthrough(EndLabel);
195 this->
Ctx->emitLabel(EndLabel);
197 if (!this->
Ctx->emitGetPtrLocal(
Local.Offset, E))
199 if (!this->
Ctx->emitDestructionPop(
Local.Desc,
Local.Desc->getLoc()))
218 if (
const auto *OVE =
219 llvm::dyn_cast_if_present<OpaqueValueExpr>(
Local.Desc->asExpr())) {
220 this->
Ctx->OpaqueExprs.erase(OVE);
232 OldArrayIndex = Ctx->ArrayIndex;
233 Ctx->ArrayIndex = Index;
240 std::optional<uint64_t> OldArrayIndex;
248 if (!Ctx->SourceLocDefaultExpr) {
250 Ctx->SourceLocDefaultExpr = DefaultExpr;
256 Ctx->SourceLocDefaultExpr =
nullptr;
261 bool Enabled =
false;
267 Ctx->InitStack.push_back(std::move(
Link));
279 : Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
282 Ctx->InitStackActive = OldValue || Active;
288 this->Ctx->InitStackActive = OldValue;
290 Ctx->InitStack.pop_back();
304 OldInitializingDecl(
Ctx->InitializingDecl) {
305 Ctx->InitializingDecl = VD;
310 this->
Ctx->InitializingDecl = OldInitializingDecl;
311 this->
Ctx->InitStack.pop_back();
316 const VarDecl *OldInitializingDecl;
324 bool NewInitializing,
bool NewToLValue)
325 : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
326 OldInitializing(Ctx->
Initializing), OldToLValue(Ctx->ToLValue) {
327 Ctx->DiscardResult = NewDiscardResult;
328 Ctx->Initializing = NewInitializing;
329 Ctx->ToLValue = NewToLValue;
333 Ctx->DiscardResult = OldDiscardResult;
334 Ctx->Initializing = OldInitializing;
335 Ctx->ToLValue = OldToLValue;
342 bool OldDiscardResult;
343 bool OldInitializing;
347template <
class Emitter>
351 return Ctx->emitThis(E);
354 return Ctx->emitGetPtrFieldPop(
Offset, E);
356 return Ctx->emitGetPtrBasePop(
Offset,
false, E);
358 return Ctx->emitGetPtrLocal(
Offset, E);
362 if (!Ctx->emitConstUint32(
Offset, E))
364 return Ctx->emitArrayElemPtrPopUint32(E);
366 return Ctx->emitRVOPtr(E);
370 llvm_unreachable(
"Unhandled InitLink kind");
386 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
387 assert(LI.Name != Name);
390 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel, ContinueLabel,
411 : Ctx(Ctx), OldCaseLabels(
std::move(this->Ctx->CaseLabels)) {
413 for (
const LabelInfo &LI : Ctx->LabelInfoStack)
414 assert(LI.Name != Name);
417 this->Ctx->CaseLabels = std::move(CaseLabels);
418 this->Ctx->LabelInfoStack.emplace_back(Name, BreakLabel,
420 DefaultLabel, Ctx->VarScope);
424 this->Ctx->CaseLabels = std::move(OldCaseLabels);
425 this->Ctx->LabelInfoStack.pop_back();
430 CaseMap OldCaseLabels;
441 : Ctx(Ctx), OldFlag(Ctx->LocOverride), Enabled(Enabled) {
444 Ctx->LocOverride = NewValue;
449 Ctx->LocOverride = OldFlag;
454 std::optional<SourceInfo> OldFlag;
461template <
class Emitter>
469 case CK_LValueToRValue: {
477 if (!this->
visit(SubExpr))
479 return this->emitLoadPopL(E);
489 if (
const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
495 if (
auto GlobalIndex =
P.getGlobal(D))
496 return this->emitGetGlobal(*SubExprT, *GlobalIndex, E);
497 }
else if (
auto It =
Locals.find(D); It !=
Locals.end()) {
498 return this->emitGetLocal(*SubExprT, It->second.Offset, E);
499 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
500 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
501 return this->emitGetParam(*SubExprT, It->second.Index, E);
513 if (!this->emitGetPtrLocal(*LocalIndex, E))
517 if (!this->
visit(SubExpr))
521 return this->emitLoadPop(*SubExprT, E);
526 return this->emitMemcpy(E);
529 case CK_DerivedToBaseMemberPointer: {
540 ->getMostRecentCXXRecordDecl();
542 const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl();
543 unsigned DerivedOffset =
Ctx.collectBaseOffset(ToDecl, CurDecl);
545 if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E))
553 case CK_BaseToDerivedMemberPointer: {
564 ->getMostRecentCXXRecordDecl();
568 typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter;
570 PathI != PathE; ++PathI) {
571 const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl();
572 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
574 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
581 assert(ToDecl != CurDecl);
582 unsigned DerivedOffset =
Ctx.collectBaseOffset(CurDecl, ToDecl);
584 if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E))
590 case CK_UncheckedDerivedToBase:
591 case CK_DerivedToBase: {
596 if (
const auto *PT = dyn_cast<PointerType>(Ty))
597 return PT->getPointeeType()->getAsCXXRecordDecl();
598 return Ty->getAsCXXRecordDecl();
605 if (B->isVirtual()) {
606 if (!this->emitGetPtrVirtBasePop(extractRecordDecl(B->getType()), E))
608 CurType = B->getType();
610 unsigned DerivedOffset = collectBaseOffset(B->getType(), CurType);
611 if (!this->emitGetPtrBasePop(
614 CurType = B->getType();
621 case CK_BaseToDerived: {
624 unsigned DerivedOffset =
630 return this->emitGetPtrDerivedPop(DerivedOffset,
635 case CK_FloatingCast: {
638 return this->emitVectorConversion(E->
getSubExpr(), E);
642 if (!this->
visit(SubExpr))
644 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
648 case CK_IntegralToFloating: {
650 return this->emitVectorConversion(E->
getSubExpr(), E);
653 if (!this->
visit(SubExpr))
655 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
656 return this->emitCastIntegralFloating(
classifyPrim(SubExpr),
657 TargetSemantics, getFPOptions(E), E);
660 case CK_FloatingToBoolean: {
662 return this->emitVectorConversion(E->
getSubExpr(), E);
666 if (
const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
667 return this->emitConstBool(FL->getValue().isNonZero(), E);
668 if (!this->
visit(SubExpr))
670 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
673 case CK_FloatingToIntegral: {
675 return this->emitVectorConversion(E->
getSubExpr(), E);
678 if (!this->
visit(SubExpr))
682 return this->emitCastFloatingIntegralAP(
Ctx.getBitWidth(E->
getType()),
685 return this->emitCastFloatingIntegralAPS(
Ctx.getBitWidth(E->
getType()),
688 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
691 case CK_NullToPointer:
692 case CK_NullToMemberPointer: {
695 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
700 case CK_PointerToIntegral: {
701 if (!this->
visit(SubExpr))
707 if (!this->emitDecayPtr(FromT,
PT_Ptr, E))
713 return this->emitCastPointerIntegralAP(
Ctx.getBitWidth(E->
getType()), E);
715 return this->emitCastPointerIntegralAPS(
Ctx.getBitWidth(E->
getType()), E);
716 return this->emitCastPointerIntegral(
T, E);
719 case CK_ArrayToPointerDecay: {
720 if (!this->
visit(SubExpr))
722 return this->emitArrayDecay(E);
725 case CK_IntegralToPointer: {
727 assert(IntType->isIntegralOrEnumerationType());
728 if (!this->
visit(SubExpr))
742 return this->emitDecayPtr(
PT_Ptr, DestPtrT, E);
745 case CK_AtomicToNonAtomic:
746 case CK_ConstructorConversion:
747 case CK_FunctionToPointerDecay:
748 case CK_NonAtomicToAtomic:
750 case CK_UserDefinedConversion:
751 case CK_CPointerToObjCPointerCast:
754 case CK_AddressSpaceConversion: {
758 if (!this->
visit(SubExpr))
763 Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
770 return this->emitPopPtr(E);
788 return this->emitBuiltinBitCast(E);
803 if (!this->
visit(SubExpr))
811 return this->emitFnPtrCast(E);
819 if (!this->
visit(SubExpr))
821 return this->emitDecayPtr(*FromT, *ToT, E);
823 case CK_IntegralToBoolean:
824 case CK_FixedPointToBoolean: {
826 return this->emitVectorConversion(E->
getSubExpr(), E);
832 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
833 return this->emitConst(IL->getValue(), E);
834 if (!this->
visit(SubExpr))
839 case CK_IntegralCast:
841 return this->emitVectorConversion(E->
getSubExpr(), E);
843 case CK_BooleanToSignedIntegral: {
850 if (
const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
855 if (!this->emitConst(IL->getValue(), SubExpr))
858 if (!this->
visit(SubExpr))
866 if (!ED->isFixed()) {
867 if (!this->emitCheckEnumValue(*FromT, ED, E))
873 if (!this->emitCastAP(*FromT,
Ctx.getBitWidth(E->
getType()), E))
876 if (!this->emitCastAPS(*FromT,
Ctx.getBitWidth(E->
getType()), E))
881 if (!this->emitCast(*FromT, *ToT, E))
884 if (E->
getCastKind() == CK_BooleanToSignedIntegral)
885 return this->emitNeg(*ToT, E);
889 case CK_PointerToBoolean:
890 if (!this->
visit(SubExpr))
892 return this->emitIsNonNullPtr(E);
894 case CK_MemberPointerToBoolean:
895 if (!this->
visit(SubExpr))
897 return this->emitIsNonNullMemberPtr(E);
899 case CK_IntegralComplexToBoolean:
900 case CK_FloatingComplexToBoolean: {
901 if (!this->
visit(SubExpr))
903 return this->emitComplexBoolCast(SubExpr);
906 case CK_IntegralComplexToReal:
907 case CK_FloatingComplexToReal:
908 return this->emitComplexReal(SubExpr);
910 case CK_IntegralRealToComplex:
911 case CK_FloatingRealToComplex: {
918 if (!this->emitGetPtrLocal(*LocalIndex, E))
927 if (!this->visitZeroInitializer(
T, SubExpr->
getType(), SubExpr))
929 return this->emitInitElem(
T, 1, SubExpr);
932 case CK_IntegralComplexCast:
933 case CK_FloatingComplexCast:
934 case CK_IntegralComplexToFloatingComplex:
935 case CK_FloatingComplexToIntegralComplex: {
942 if (!this->emitGetPtrLocal(*LocalIndex, E))
949 unsigned SubExprOffset =
951 if (!this->
visit(SubExpr))
953 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
961 for (
unsigned I = 0; I != 2; ++I) {
962 if (!this->emitGetLocal(
PT_Ptr, SubExprOffset, E))
964 if (!this->emitArrayElemPop(SourceElemT, I, E))
968 if (!this->emitPrimCast(SourceElemT, DestElemT, DestElemType, E))
972 if (!this->emitInitElem(DestElemT, I, E))
978 case CK_VectorSplat: {
989 if (!this->emitGetPtrLocal(*LocalIndex, E))
995 unsigned ElemOffset =
999 if (!this->
visit(SubExpr))
1004 if (!this->emitSetLocal(ElemT, ElemOffset, E))
1007 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
1008 if (!this->emitGetLocal(ElemT, ElemOffset, E))
1010 if (!this->emitInitElem(ElemT, I, E))
1017 case CK_HLSLVectorTruncation: {
1022 if (!this->
visit(SubExpr))
1024 return this->emitArrayElemPop(*ResultT, 0, E);
1033 if (!this->emitGetPtrLocal(*LocalIndex, E))
1038 if (!this->
visit(SubExpr))
1040 return this->emitCopyArray(classifyVectorElementType(E->
getType()), 0, 0,
1044 case CK_IntegralToFixedPoint: {
1045 if (!this->
visit(SubExpr))
1049 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1054 return this->emitPopFixedPoint(E);
1057 case CK_FloatingToFixedPoint: {
1058 if (!this->
visit(SubExpr))
1062 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1063 if (!this->emitCastFloatingFixedPoint(Sem, E))
1066 return this->emitPopFixedPoint(E);
1069 case CK_FixedPointToFloating: {
1070 if (!this->
visit(SubExpr))
1072 const auto *TargetSemantics = &
Ctx.getFloatSemantics(E->
getType());
1073 if (!this->emitCastFixedPointFloating(TargetSemantics, E))
1076 return this->emitPopFloat(E);
1079 case CK_FixedPointToIntegral: {
1080 if (!this->
visit(SubExpr))
1083 if (!this->emitCastFixedPointIntegral(IntegralT, E))
1086 return this->emitPop(IntegralT, E);
1089 case CK_FixedPointCast: {
1090 if (!this->
visit(SubExpr))
1093 Ctx.getASTContext().getFixedPointSemantics(E->
getType()).toOpaqueInt();
1094 if (!this->emitCastFixedPoint(Sem, E))
1097 return this->emitPopFixedPoint(E);
1105 llvm_unreachable(
"CXXDynamicCastExpr has its own function");
1107 case CK_LValueBitCast:
1112 case CK_HLSLArrayRValue: {
1119 if (!this->emitGetPtrLocal(*LocalIndex, E))
1122 if (!this->
visit(SubExpr))
1124 return this->emitMemcpy(E);
1127 case CK_HLSLMatrixTruncation: {
1132 if (!this->
visit(SubExpr))
1134 return this->emitArrayElemPop(*ResultT, 0, E);
1143 if (!this->emitGetPtrLocal(*LocalIndex, E))
1148 if (!this->
visit(SubExpr))
1150 return this->emitCopyArray(classifyMatrixElementType(SubExpr->
getType()), 0,
1154 case CK_HLSLAggregateSplatCast: {
1164 if (!this->emitGetPtrLocal(*LocalIndex, E))
1171 unsigned SrcOffset =
1174 if (!this->
visit(SubExpr))
1176 if (!this->emitSetLocal(SrcElemT, SrcOffset, E))
1180 return emitHLSLAggregateSplat(SrcElemT, SrcOffset, E->
getType(), E);
1183 case CK_HLSLElementwiseCast: {
1194 unsigned SrcPtrOffset =
1196 if (!this->
visit(SubExpr))
1198 if (!this->emitSetLocal(
PT_Ptr, SrcPtrOffset, E))
1202 if (!emitHLSLFlattenAggregate(SrcType, SrcPtrOffset, Elements, 1, E))
1204 if (Elements.empty())
1207 const HLSLFlatElement &Src = Elements[0];
1208 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
1210 return this->emitPrimCast(Src.Type, *DestT, DestType, E);
1217 if (!this->emitGetPtrLocal(*LocalIndex, E))
1221 unsigned SrcOffset =
1223 if (!this->
visit(SubExpr))
1225 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
1229 unsigned ElemCount = countHLSLFlatElements(DestType);
1232 Elements.reserve(ElemCount);
1233 if (!emitHLSLFlattenAggregate(SrcType, SrcOffset, Elements, ElemCount, E))
1238 assert(Elements.size() == ElemCount &&
1239 "Source type has fewer scalar elements than the destination type");
1241 return emitHLSLConstructAggregate(DestType, Elements, E);
1248 const Record::Field *RF = R->getField(UnionField);
1251 if (!this->
visit(SubExpr))
1253 if (RF->isBitField())
1254 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
1256 return this->emitInitFieldActivate(*PT, RF->Offset, E);
1259 if (!this->emitGetPtrField(RF->Offset, E))
1261 if (!this->emitActivate(E))
1267 return this->emitInvalid(E);
1269 llvm_unreachable(
"Unhandled clang::CastKind enum");
1272template <
class Emitter>
1274 return this->emitBuiltinBitCast(E);
1277template <
class Emitter>
1282 return this->emitConst(
LE->getValue(),
LE);
1285template <
class Emitter>
1291 return this->emitFloat(F, E);
1294template <
class Emitter>
1304 if (!this->emitGetPtrLocal(*LocalIndex, E))
1311 if (!this->visitZeroInitializer(SubExprT, SubExpr->
getType(), SubExpr))
1313 if (!this->emitInitElem(SubExprT, 0, SubExpr))
1318template <
class Emitter>
1326 auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->
getType());
1331template <
class Emitter>
1336template <
class Emitter>
1363 return this->emitComplexComparison(LHS, RHS, E);
1371 if (!this->
visit(LHS))
1374 if (!this->
visit(RHS))
1377 if (!this->emitToMemberPtr(E))
1383 if (!this->emitCastMemberPtrPtr(E))
1400 Ctx.getASTContext().CompCategories.lookupInfoForType(E->
getType());
1406 if (!this->emitGetPtrLocal(*ResultIndex, E))
1413 return this->emitCMP3(*
LT, CmpInfo, E);
1416 if (!
LT || !RT || !
T)
1426 return this->visitAssignment(LHS, RHS, E);
1433 auto MaybeCastToBool = [
this,
T, E](
bool Result) {
1437 return this->emitPopBool(E);
1439 return this->emitCast(
PT_Bool, *
T, E);
1443 auto Discard = [
this,
T, E](
bool Result) {
1451 return MaybeCastToBool(this->emitEQ(*
LT, E));
1453 return MaybeCastToBool(this->emitNE(*
LT, E));
1455 return MaybeCastToBool(this->emitLT(*
LT, E));
1457 return MaybeCastToBool(this->emitLE(*
LT, E));
1459 return MaybeCastToBool(this->emitGT(*
LT, E));
1461 return MaybeCastToBool(this->emitGE(*
LT, E));
1464 return Discard(this->emitSubf(getFPOptions(E), E));
1465 return Discard(this->emitSub(*
T, E));
1468 return Discard(this->emitAddf(getFPOptions(E), E));
1469 return Discard(this->emitAdd(*
T, E));
1472 return Discard(this->emitMulf(getFPOptions(E), E));
1473 return Discard(this->emitMul(*
T, E));
1475 return Discard(this->emitRem(*
T, E));
1478 return Discard(this->emitDivf(getFPOptions(E), E));
1479 return Discard(this->emitDiv(*
T, E));
1481 return Discard(this->emitBitAnd(*
T, E));
1483 return Discard(this->emitBitOr(*
T, E));
1485 return Discard(this->emitShl(*
LT, *RT, E));
1487 return Discard(this->emitShr(*
LT, *RT, E));
1489 return Discard(this->emitBitXor(*
T, E));
1492 llvm_unreachable(
"Already handled earlier");
1497 llvm_unreachable(
"Unhandled binary op");
1502template <
class Emitter>
1508 if ((Op != BO_Add && Op != BO_Sub) ||
1519 auto visitAsPointer = [&](
const Expr *E,
PrimType T) ->
bool {
1520 if (!this->
visit(E))
1523 return this->emitDecayPtr(
T,
PT_Ptr, E);
1532 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *
LT))
1540 ElemTypeSize =
Ctx.getASTContext().getTypeSizeInChars(ElemType);
1543 if (!this->emitSubPtr(IntT, ElemTypeSize.
getQuantity(), E))
1550 if (!visitAsPointer(RHS, *RT))
1552 if (!this->
visit(LHS))
1556 if (!visitAsPointer(LHS, *
LT))
1558 if (!this->
visit(RHS))
1569 if (!this->emitAddOffset(OffsetType, E))
1573 if (!this->emitSubOffset(OffsetType, E))
1582 if (!this->emitDecayPtr(
PT_Ptr, ExprT, E))
1587 return this->emitPop(ExprT, E);
1591template <
class Emitter>
1600 LabelTy LabelTrue = this->getLabel();
1601 LabelTy LabelEnd = this->getLabel();
1605 if (!this->jumpTrue(LabelTrue, E))
1610 if (!this->jump(LabelEnd, E))
1613 this->emitLabel(LabelTrue);
1614 this->emitConstBool(
true, E);
1615 this->fallthrough(LabelEnd);
1616 this->emitLabel(LabelEnd);
1619 assert(Op == BO_LAnd);
1622 LabelTy LabelFalse = this->getLabel();
1623 LabelTy LabelEnd = this->getLabel();
1627 if (!this->jumpFalse(LabelFalse, E))
1632 if (!this->jump(LabelEnd, E))
1635 this->emitLabel(LabelFalse);
1636 this->emitConstBool(
false, E);
1637 this->fallthrough(LabelEnd);
1638 this->emitLabel(LabelEnd);
1642 return this->emitPopBool(E);
1647 return this->emitCast(
PT_Bool,
T, E);
1652template <
class Emitter>
1659 if (!this->emitGetPtrLocal(*LocalIndex, E))
1668 PrimType ResultElemT = this->classifyComplexElementType(E->
getType());
1669 unsigned ResultOffset = ~0u;
1675 if (!this->emitDupPtr(E))
1677 if (!this->emitSetLocal(
PT_Ptr, ResultOffset, E))
1682 LHSType = AT->getValueType();
1685 RHSType = AT->getValueType();
1694 if (Op == BO_Mul && LHSIsComplex && RHSIsComplex) {
1699 if (!this->
visit(LHS))
1701 if (!this->
visit(RHS))
1703 if (!this->emitMulc(ElemT, E))
1706 return this->emitPopPtr(E);
1710 if (Op == BO_Div && RHSIsComplex) {
1717 if (!LHSIsComplex) {
1722 LHSOffset = *LocalIndex;
1724 if (!this->emitGetPtrLocal(LHSOffset, E))
1727 if (!this->
visit(LHS))
1730 if (!this->emitInitElem(ElemT, 0, E))
1733 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
1735 if (!this->emitInitElem(ElemT, 1, E))
1738 if (!this->
visit(LHS))
1742 if (!this->
visit(RHS))
1744 if (!this->emitDivc(ElemT, E))
1747 return this->emitPopPtr(E);
1754 if (!this->
visit(LHS))
1756 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1761 if (!this->
visit(LHS))
1763 if (!this->emitSetLocal(LHST, LHSOffset, E))
1771 if (!this->
visit(RHS))
1773 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1778 if (!this->
visit(RHS))
1780 if (!this->emitSetLocal(RHST, RHSOffset, E))
1787 auto loadComplexValue = [
this](
bool IsComplex,
bool LoadZero,
1788 unsigned ElemIndex,
unsigned Offset,
1789 const Expr *E) ->
bool {
1791 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1793 return this->emitArrayElemPop(classifyComplexElementType(E->
getType()),
1796 if (ElemIndex == 0 || !LoadZero)
1803 for (
unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
1806 if (!this->emitGetLocal(
PT_Ptr, ResultOffset, E))
1813 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1816 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1819 if (!this->emitAddf(getFPOptions(E), E))
1822 if (!this->emitAdd(ResultElemT, E))
1827 if (!loadComplexValue(LHSIsComplex,
true, ElemIndex, LHSOffset, LHS))
1830 if (!loadComplexValue(RHSIsComplex,
true, ElemIndex, RHSOffset, RHS))
1833 if (!this->emitSubf(getFPOptions(E), E))
1836 if (!this->emitSub(ResultElemT, E))
1841 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1844 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1848 if (!this->emitMulf(getFPOptions(E), E))
1851 if (!this->emitMul(ResultElemT, E))
1856 assert(!RHSIsComplex);
1857 if (!loadComplexValue(LHSIsComplex,
false, ElemIndex, LHSOffset, LHS))
1860 if (!loadComplexValue(RHSIsComplex,
false, ElemIndex, RHSOffset, RHS))
1864 if (!this->emitDivf(getFPOptions(E), E))
1867 if (!this->emitDiv(ResultElemT, E))
1878 if (!this->emitInitElemPop(ResultElemT, ElemIndex, E))
1881 if (!this->emitPop(ResultElemT, E))
1886 return this->emitPopPtr(E);
1892template <
class Emitter>
1897 "Comma op should be handled in VisitBinaryOperator");
1901 LHSType = AT->getValueType();
1904 RHSType = AT->getValueType();
1918 if (!this->emitGetPtrLocal(*LocalIndex, E))
1927 PrimType ElemT = this->classifyVectorElementType(LHSType);
1928 PrimType RHSElemT = this->classifyVectorElementType(RHSType);
1932 assert(
Ctx.getASTContext().hasSameUnqualifiedType(
1935 if (!this->
visit(LHS))
1937 if (!this->
visit(RHS))
1939 if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
1942 return this->emitPopPtr(E);
1947 unsigned LHSOffset =
1949 if (!this->
visit(LHS))
1951 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
1955 unsigned RHSOffset =
1957 if (!this->
visit(RHS))
1959 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
1971 if (NeedIntPromot) {
1973 Ctx.getASTContext().getPromotedIntegerType(
Ctx.getASTContext().BoolTy);
1978 auto getElem = [=](
unsigned Offset,
PrimType ElemT,
unsigned Index) {
1979 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
1981 if (!this->emitArrayElemPop(ElemT, Index, E))
1984 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
1986 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
1988 }
else if (NeedIntPromot) {
1989 if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
1995#define EMIT_ARITH_OP(OP) \
1997 if (ElemT == PT_Float) { \
1998 if (!this->emit##OP##f(getFPOptions(E), E)) \
2001 if (!this->emit##OP(ElemT, E)) \
2007 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
2008 if (!getElem(LHSOffset, ElemT, I))
2010 if (!getElem(RHSOffset, RHSElemT, I))
2022 if (!this->emitRem(ElemT, E))
2026 if (!this->emitBitAnd(OpT, E))
2030 if (!this->emitBitOr(OpT, E))
2034 if (!this->emitBitXor(OpT, E))
2038 if (!this->emitShl(OpT, RHSElemT, E))
2042 if (!this->emitShr(OpT, RHSElemT, E))
2046 if (!this->emitEQ(ElemT, E))
2050 if (!this->emitNE(ElemT, E))
2054 if (!this->emitLE(ElemT, E))
2058 if (!this->emitLT(ElemT, E))
2062 if (!this->emitGE(ElemT, E))
2066 if (!this->emitGT(ElemT, E))
2071 if (!this->emitBitAnd(ResultElemT, E))
2076 if (!this->emitBitOr(ResultElemT, E))
2080 return this->emitInvalid(E);
2089 if (!this->emitPrimCast(
PT_Bool, ResultElemT, VecTy->getElementType(), E))
2091 if (!this->emitNeg(ResultElemT, E))
2097 if (NeedIntPromot &&
2098 !this->emitPrimCast(PromotT, ResultElemT, VecTy->getElementType(), E))
2102 if (!this->emitInitElem(ResultElemT, I, E))
2111template <
class Emitter>
2121 auto LHSSemaInt = LHSSema.toOpaqueInt();
2123 auto RHSSemaInt = RHSSema.toOpaqueInt();
2125 if (!this->
visit(LHS))
2133 if (!this->
visit(RHS))
2142 auto ConvertResult = [&](
bool R) ->
bool {
2146 auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
2147 if (ResultSema != CommonSema)
2148 return this->emitCastFixedPoint(ResultSema, E);
2152 auto MaybeCastToBool = [&](
bool Result) {
2157 return this->emitPop(
T, E);
2159 return this->emitCast(
PT_Bool,
T, E);
2165 return MaybeCastToBool(this->emitEQFixedPoint(E));
2167 return MaybeCastToBool(this->emitNEFixedPoint(E));
2169 return MaybeCastToBool(this->emitLTFixedPoint(E));
2171 return MaybeCastToBool(this->emitLEFixedPoint(E));
2173 return MaybeCastToBool(this->emitGTFixedPoint(E));
2175 return MaybeCastToBool(this->emitGEFixedPoint(E));
2177 return ConvertResult(this->emitAddFixedPoint(E));
2179 return ConvertResult(this->emitSubFixedPoint(E));
2181 return ConvertResult(this->emitMulFixedPoint(E));
2183 return ConvertResult(this->emitDivFixedPoint(E));
2185 return ConvertResult(this->emitShiftFixedPoint(
true, E));
2187 return ConvertResult(this->emitShiftFixedPoint(
false, E));
2190 return this->emitInvalid(E);
2193 llvm_unreachable(
"unhandled binop opcode");
2196template <
class Emitter>
2205 if (!this->
visit(SubExpr))
2207 if (!this->emitNegFixedPoint(E))
2210 return this->emitPopFixedPoint(E);
2216 llvm_unreachable(
"Unhandled unary opcode");
2219template <
class Emitter>
2228 return this->visitZeroInitializer(*
T, QT, E);
2241 return this->visitZeroRecordInitializer(R, E);
2248 return this->visitZeroArrayInitializer(QT, E);
2252 QualType ElemQT = ComplexTy->getElementType();
2254 for (
unsigned I = 0; I < 2; ++I) {
2255 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2257 if (!this->emitInitElem(ElemT, I, E))
2264 unsigned NumVecElements = VecT->getNumElements();
2265 QualType ElemQT = VecT->getElementType();
2268 for (
unsigned I = 0; I < NumVecElements; ++I) {
2269 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2271 if (!this->emitInitElem(ElemT, I, E))
2278 unsigned NumElems = MT->getNumElementsFlattened();
2279 QualType ElemQT = MT->getElementType();
2282 for (
unsigned I = 0; I != NumElems; ++I) {
2283 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2285 if (!this->emitInitElem(ElemT, I, E))
2294template <
class Emitter>
2307 for (
const Expr *SubExpr : {LHS, RHS}) {
2308 if (!this->
visit(SubExpr)) {
2315 if (SubExpr ==
Base &&
Base->getType()->isPointerType()) {
2316 if (!this->emitExpandPtr(E))
2327 return this->emitError(E);
2330 if (!this->emitFlip(
PT_Ptr, *IndexT, E))
2334 if (!this->emitArrayElemPtrPop(*IndexT, E))
2337 return this->emitPopPtr(E);
2343 return this->emitLoadPop(*
T, E);
2346template <
class Emitter>
2348 const Expr *ArrayFiller,
const Expr *E) {
2353 QT = AT->getValueType();
2356 if (
Inits.size() == 0)
2358 return this->emitInvalid(E);
2371 if (
Inits.size() == 0)
2372 return this->visitZeroInitializer(*
T, QT, E);
2373 assert(
Inits.size() == 1);
2387 if (!this->emitGetPtrLocal(*LocalIndex, E))
2402 auto initPrimitiveField = [=](
const Record::Field *FieldToInit,
2408 if (
DefaultInit && !this->emitStartFieldInit(FieldToInit->Offset,
Init))
2417 bool BitField = FieldToInit->isBitField();
2419 return this->emitInitBitFieldActivate(
T, FieldToInit->Offset,
2420 FieldToInit->bitWidth(), E);
2422 return this->emitInitBitField(
T, FieldToInit->Offset,
2423 FieldToInit->bitWidth(), E);
2425 return this->emitInitFieldActivate(
T, FieldToInit->Offset, E);
2426 return this->emitInitField(
T, FieldToInit->Offset, E);
2429 auto initCompositeField = [=](
const Record::Field *FieldToInit,
2437 if (!this->emitGetPtrField(FieldToInit->Offset,
Init))
2440 if (
Activate && !this->emitActivate(E))
2443 if (!this->emitStartInit(
Init))
2450 if (
Inits.size() == 0) {
2451 if (!this->visitZeroRecordInitializer(R, E))
2456 if (
const auto *ILE = dyn_cast<InitListExpr>(E))
2457 FToInit = ILE->getInitializedFieldInUnion();
2461 const Record::Field *FieldToInit = R->getField(FToInit);
2463 if (!initPrimitiveField(FieldToInit,
Init, *
T,
true))
2466 if (!initCompositeField(FieldToInit,
Init,
true))
2470 return this->emitFinishInit(E);
2473 assert(!R->isUnion());
2474 for (
unsigned BI = 0; BI != R->getNumBases(); ++BI) {
2476 const Record::Base *B = R->getBase(BI);
2479 if (!this->emitGetPtrBase(B->Offset,
Init))
2485 unsigned FieldIndex = 0;
2486 for (
unsigned FI = R->getNumBases(); FI !=
Inits.size();) {
2487 const Record::Field *FieldToInit = R->getField(FieldIndex);
2488 if (FieldToInit->isUnnamedBitField()) {
2503 if (!initPrimitiveField(FieldToInit,
Init, *
T))
2505 }
else if (!initCompositeField(FieldToInit,
Init)) {
2513 assert(R->getNumVirtualBases() == 0);
2515 return this->emitFinishInit(E);
2520 Ctx.getASTContext().getAsConstantArrayType(QT);
2525 !this->emitCheckArrayDestSize(NumElems, E))
2528 if (
Inits.size() == 1 && QT ==
Inits[0]->getType())
2532 unsigned ElementIndex = 0;
2534 if (
const auto *EmbedS =
2535 dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
2543 if (!this->emitCastIntegralFloating(
classifyPrim(IL), Sem,
2544 getFPOptions(E), E))
2550 return this->emitInitElem(TargetT, ElemIndex, IL);
2552 if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
2568 for (; ElementIndex != NumElems; ++ElementIndex) {
2574 return this->emitFinishInit(E);
2578 unsigned NumInits =
Inits.size();
2583 QualType ElemQT = ComplexTy->getElementType();
2585 if (NumInits == 0) {
2587 for (
unsigned I = 0; I < 2; ++I) {
2588 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2590 if (!this->emitInitElem(ElemT, I, E))
2593 }
else if (NumInits == 2) {
2594 unsigned InitIndex = 0;
2599 if (!this->emitInitElem(ElemT, InitIndex, E))
2608 unsigned NumVecElements = VecT->getNumElements();
2609 assert(NumVecElements >=
Inits.size());
2611 QualType ElemQT = VecT->getElementType();
2615 unsigned InitIndex = 0;
2622 if (
const auto *InitVecT =
Init->getType()->getAs<
VectorType>()) {
2623 if (!this->emitCopyArray(ElemT, 0, InitIndex,
2624 InitVecT->getNumElements(), E))
2626 InitIndex += InitVecT->getNumElements();
2628 if (!this->emitInitElem(ElemT, InitIndex, E))
2634 assert(InitIndex <= NumVecElements);
2637 for (; InitIndex != NumVecElements; ++InitIndex) {
2638 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
2640 if (!this->emitInitElem(ElemT, InitIndex, E))
2647 unsigned NumElems = MT->getNumElementsFlattened();
2648 assert(
Inits.size() == NumElems);
2650 QualType ElemQT = MT->getElementType();
2656 for (
unsigned I = 0; I != NumElems; ++I) {
2659 if (!this->emitInitElem(ElemT, I, E))
2670template <
class Emitter>
2677 return this->emitInitElem(*InitT, ElemIndex,
Init);
2683 if (!this->emitConstUint32(ElemIndex,
Init))
2685 if (!this->emitArrayElemPtrUint32(
Init))
2690template <
class Emitter>
2693 bool Activate,
bool IsOperatorCall) {
2695 llvm::BitVector NonNullArgs;
2696 if (FuncDecl && FuncDecl->
hasAttr<NonNullAttr>())
2699 bool ExplicitMemberFn =
false;
2700 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2701 ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2703 unsigned ArgIndex = 0;
2704 for (
const Expr *Arg : Args) {
2706 if (!this->
visit(Arg))
2714 unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2715 if (DeclIndex < FuncDecl->getNumParams())
2716 Source = FuncDecl->
getParamDecl(ArgIndex - IsOperatorCall +
2725 if (!this->emitGetPtrLocal(*LocalIndex, Arg))
2733 if (!this->emitActivate(Arg))
2737 if (!NonNullArgs.empty() && NonNullArgs[ArgIndex]) {
2740 if (!this->emitCheckNonNullArg(ArgT, Arg))
2751template <
class Emitter>
2756template <
class Emitter>
2762template <
class Emitter>
2768template <
class Emitter>
2786template <
class Emitter>
2788 auto It = E->
begin();
2789 return this->
visit(*It);
2793 UnaryExprOrTypeTrait Kind) {
2794 bool AlignOfReturnsPreferred =
2801 T = Ref->getPointeeType();
2803 if (
T.getQualifiers().hasUnaligned())
2809 if (Kind == UETT_PreferredAlignOf || AlignOfReturnsPreferred)
2815template <
class Emitter>
2819 UnaryExprOrTypeTrait Kind = E->
getKind();
2822 if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
2828 ArgType = Ref->getPointeeType();
2834 if (
ArgType->isDependentType() || !
ArgType->isConstantSizeType())
2835 return this->emitInvalid(E);
2837 if (Kind == UETT_SizeOf)
2846 return this->emitConst(Size.getQuantity(), E);
2849 if (Kind == UETT_CountOf) {
2855 if (
const auto *CAT =
2859 return this->emitConst(CAT->getSize(), E);
2869 if (VAT->getElementType()->isArrayType()) {
2870 std::optional<APSInt> Res =
2872 ? VAT->getSizeExpr()->getIntegerConstantExpr(ASTCtx)
2877 return this->emitConst(*Res, E);
2882 if (Kind == UETT_AlignOf || Kind == UETT_PreferredAlignOf) {
2902 if (
const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
2905 else if (
const auto *ME = dyn_cast<MemberExpr>(Arg))
2915 return this->emitConst(Size.getQuantity(), E);
2918 if (Kind == UETT_VectorElements) {
2923 return this->emitConst(VT->getNumElements(), E);
2925 return this->emitSizelessVectorElementSize(E);
2928 if (Kind == UETT_VecStep) {
2930 unsigned N = VT->getNumElements();
2937 return this->emitConst(N, E);
2939 return this->emitConst(1, E);
2942 if (Kind == UETT_OpenMPRequiredSimdAlign) {
2951 if (Kind == UETT_PtrAuthTypeDiscriminator) {
2953 return this->emitInvalid(E);
2955 return this->emitConst(
2956 const_cast<ASTContext &
>(ASTCtx).getPointerAuthTypeDiscriminator(
2964template <
class Emitter>
2973 if (
const auto *VD = dyn_cast<VarDecl>(
Member)) {
2978 if (VD->getInit() && !VD->getInit()->isValueDependent())
2979 VD->evaluateValue();
2980 if (
auto GlobalIndex =
P.getGlobal(VD)) {
2981 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
2983 if (
Member->getType()->isReferenceType())
2984 return this->emitLoadPopPtr(E);
2993 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
Member);
2994 MD && !MD->isStatic()) {
2998 if (!this->
discard(Base) && !this->emitSideEffect(E))
3013 const Record::Field *F = R->getField(FD);
3017 const auto maybeLoadValue = [&]() ->
bool {
3021 return this->emitLoadPop(*
T, E);
3026 if (F->Decl->getType()->isReferenceType())
3027 return this->emitGetFieldPop(
PT_Ptr, F->Offset, E) && maybeLoadValue();
3028 return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
3031template <
class Emitter>
3041template <
class Emitter>
3051 return this->emitCheckArraySize(Size, E);
3057 if (!this->
visit(Common))
3059 return this->emitCopyArray(*SubExprT, 0, 0, Size, E);
3073 for (
size_t I = 0; I != Size; ++I) {
3085template <
class Emitter>
3100 return this->emitGetLocal(SubExprT, It->second, E);
3103 if (!this->
visit(SourceExpr))
3110 if (!this->emitSetLocal(SubExprT, LocalIndex, E))
3119 return this->emitGetLocal(SubExprT, LocalIndex, E);
3123template <
class Emitter>
3136 bool IsBcpCall =
false;
3137 if (
const auto *CE = dyn_cast<CallExpr>(
Condition->IgnoreParenCasts());
3138 CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
3142 LabelTy LabelEnd = this->getLabel();
3143 LabelTy LabelFalse = this->getLabel();
3146 if (!this->emitPushIgnoreDiags(E))
3154 if (this->checkingForUndefinedBehavior()) {
3157 if (!this->
discard(FalseExpr))
3174 if (!this->jumpFalse(LabelFalse, E))
3179 if (!this->jump(LabelEnd, E))
3181 this->emitLabel(LabelFalse);
3185 this->fallthrough(LabelEnd);
3186 this->emitLabel(LabelEnd);
3189 return this->emitPopIgnoreDiags(E);
3193template <
class Emitter>
3199 return this->emitGetStringPtr(E, E);
3203 Ctx.getASTContext().getAsConstantArrayType(E->
getType());
3204 assert(CAT &&
"a string literal that's not a constant array?");
3209 unsigned N = std::min(ArraySize, E->
getLength());
3212 for (
unsigned I = 0; I != N; ++I) {
3215 if (CharWidth == 1) {
3216 this->emitConstSint8(CodeUnit, E);
3217 this->emitInitElemSint8(I, E);
3218 }
else if (CharWidth == 2) {
3219 this->emitConstUint16(CodeUnit, E);
3220 this->emitInitElemUint16(I, E);
3221 }
else if (CharWidth == 4) {
3222 this->emitConstUint32(CodeUnit, E);
3223 this->emitInitElemUint32(I, E);
3225 llvm_unreachable(
"unsupported character width");
3230 for (
unsigned I = N; I != ArraySize; ++I) {
3231 if (CharWidth == 1) {
3232 this->emitConstSint8(0, E);
3233 this->emitInitElemSint8(I, E);
3234 }
else if (CharWidth == 2) {
3235 this->emitConstUint16(0, E);
3236 this->emitInitElemUint16(I, E);
3237 }
else if (CharWidth == 4) {
3238 this->emitConstUint32(0, E);
3239 this->emitInitElemUint32(I, E);
3241 llvm_unreachable(
"unsupported character width");
3248template <
class Emitter>
3252 return this->emitDummyPtr(E, E);
3255template <
class Emitter>
3257 auto &A =
Ctx.getASTContext();
3266template <
class Emitter>
3274 auto &A =
Ctx.getASTContext();
3278 APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
3279 QualType ArrayTy = A.getConstantArrayType(CharTy, Size,
nullptr,
3285 return this->emitGetStringPtr(SL, E);
3288template <
class Emitter>
3292 return this->emitConst(E->
getValue(), E);
3295template <
class Emitter>
3317 if (!this->emitLoad(LHST, E))
3320 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3321 LHSComputationType, E))
3333 unsigned TempOffset =
3335 if (!this->emitSetLocal(*RT, TempOffset, E))
3341 if (!this->emitLoad(LHST, E))
3345 if (!this->emitPrimCast(LHST,
classifyPrim(LHSComputationType),
3346 LHSComputationType, E))
3350 if (!this->emitGetLocal(*RT, TempOffset, E))
3356 if (!this->emitAddf(getFPOptions(E), E))
3360 if (!this->emitSubf(getFPOptions(E), E))
3364 if (!this->emitMulf(getFPOptions(E), E))
3368 if (!this->emitDivf(getFPOptions(E), E))
3379 return this->emitStorePop(LHST, E);
3380 return this->emitStore(LHST, E);
3383template <
class Emitter>
3392 if (Op != BO_AddAssign && Op != BO_SubAssign)
3401 if (!this->emitLoad(*
LT, LHS))
3407 if (Op == BO_AddAssign) {
3408 if (!this->emitAddOffset(*RT, E))
3411 if (!this->emitSubOffset(*RT, E))
3416 return this->emitStorePopPtr(E);
3417 return this->emitStorePtr(E);
3420template <
class Emitter>
3433 if (!
Ctx.getLangOpts().CPlusPlus14)
3434 return this->
visit(RHS) && this->
visit(LHS) && this->emitError(E);
3436 if (!
LT || !RT || !ResultT || !LHSComputationT)
3453 if (!this->emitLoad(*
LT, E))
3455 if (
LT != LHSComputationT &&
3456 !this->emitIntegralCast(*
LT, *LHSComputationT,
3470 unsigned TempOffset =
3473 if (!this->emitSetLocal(*RT, TempOffset, E))
3480 if (!this->emitLoad(*
LT, E))
3482 if (
LT != LHSComputationT &&
3483 !this->emitIntegralCast(*
LT, *LHSComputationT,
3488 if (!this->emitGetLocal(*RT, TempOffset, E))
3495 if (!this->emitAdd(*LHSComputationT, E))
3499 if (!this->emitSub(*LHSComputationT, E))
3503 if (!this->emitMul(*LHSComputationT, E))
3507 if (!this->emitDiv(*LHSComputationT, E))
3511 if (!this->emitRem(*LHSComputationT, E))
3515 if (!this->emitShl(*LHSComputationT, *RT, E))
3519 if (!this->emitShr(*LHSComputationT, *RT, E))
3523 if (!this->emitBitAnd(*LHSComputationT, E))
3527 if (!this->emitBitXor(*LHSComputationT, E))
3531 if (!this->emitBitOr(*LHSComputationT, E))
3535 llvm_unreachable(
"Unimplemented compound assign operator");
3539 if (ResultT != LHSComputationT &&
3540 !this->emitIntegralCast(*LHSComputationT, *ResultT, E->
getType(), E))
3546 return this->emitStoreBitFieldPop(*ResultT, E);
3547 return this->emitStorePop(*ResultT, E);
3550 return this->emitStoreBitField(*ResultT, E);
3551 return this->emitStore(*ResultT, E);
3554template <
class Emitter>
3562template <
class Emitter>
3577 if (!
Ctx.getLangOpts().CPlusPlus11)
3584 for (
const Expr *LHS : CommaLHSs) {
3599 if (this->constantFolding())
3610 if (!this->
visit(Inner))
3615 if (!this->emitInitGlobalTemp(*InnerT, *GlobalIndex, TempDecl, E))
3618 if (!this->emitInitGlobal(*InnerT, *GlobalIndex, E))
3621 return this->emitGetPtrGlobal(*GlobalIndex, E);
3624 if (!this->checkLiteralType(Inner))
3627 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3633 return this->emitInitGlobalTempComp(TempDecl, E);
3646 unsigned LocalIndex =
3648 if (!this->VarScope->LocalsAlwaysEnabled &&
3649 !this->emitEnableLocal(LocalIndex, E))
3652 if (!this->
visit(Inner))
3654 if (!this->emitSetLocal(*InnerT, LocalIndex, E))
3657 return this->emitGetPtrLocal(LocalIndex, E);
3660 if (!this->checkLiteralType(Inner))
3667 if (!this->VarScope->LocalsAlwaysEnabled &&
3668 !this->emitEnableLocal(*LocalIndex, E))
3671 if (!this->emitGetPtrLocal(*LocalIndex, E))
3678template <
class Emitter>
3689 if (!this->
visit(SubExpr))
3693 return this->emitPopPtr(E);
3697template <
class Emitter>
3718 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
3723 if (
P.isGlobalInitialized(*GlobalIndex))
3729 return this->emitInitGlobal(*
T, *GlobalIndex, E);
3741 unsigned LocalIndex;
3745 LocalIndex = *MaybeIndex;
3749 if (!this->emitGetPtrLocal(LocalIndex, E))
3753 return this->
visit(
Init) && this->emitInit(*
T, E);
3757template <
class Emitter>
3768 Ctx.getASTContext().CompCategories.getInfoForType(E->
getType());
3772 if (!R || R->getNumFields() == 0)
3774 const Record::Field *Field = R->getField(0
U);
3779 return this->emitInitField(*Field->T, Field->Offset, E);
3786template <
class Emitter>
3790 return this->emitConst(E->
getValue(), E);
3793template <
class Emitter>
3806 for (
const Record::Field &F : R->fields()) {
3808 if (!
Init ||
Init->containsErrors())
3816 if (!this->emitInitField(*
T, F.Offset, E))
3819 if (!this->emitGetPtrField(F.Offset, E))
3830template <
class Emitter>
3836 return this->emitGetStringPtr(E, E);
3840template <
class Emitter>
3845 return this->emitInvalid(E);
3848template <
class Emitter>
3862 if (!this->emitInvalidCast(
CastKind,
false, E))
3870 bool Fatal = (ToT != FromT);
3877template <
class Emitter>
3879 if (!
Ctx.getLangOpts().CPlusPlus20) {
3900 if (!this->emitDynamicCast(DestType.
getTypePtr(),
3905 return this->emitPopPtr(E);
3909template <
class Emitter>
3915 return this->emitConstBool(E->
getValue(), E);
3918template <
class Emitter>
3923 if (
T->isRecordType()) {
3937 if (!this->emitGetPtrLocal(*LocalIndex, E))
3945 T->getAsCXXRecordDecl()))
3955 if (!this->visitZeroRecordInitializer(R, E))
3966 if (!this->emitDefaultInit(Ctor, E))
3969 return this->emitPopPtr(E);
3977 assert(
Ctx.getASTContext().hasSameUnqualifiedType(E->
getType(),
3979 if (
const auto *ME = dyn_cast<MaterializeTemporaryExpr>(SrcObj)) {
3980 if (!this->emitCheckFunctionDecl(Ctor, E))
3991 assert(
Func->hasThisPointer());
3992 assert(!
Func->hasRVO());
3996 if (!this->emitDupPtr(E))
4000 for (
const auto *Arg : E->
arguments()) {
4001 if (!this->
visit(Arg))
4005 if (
Func->isVariadic()) {
4006 uint32_t VarArgSize = 0;
4007 unsigned NumParams =
Func->getNumWrittenParams();
4008 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I) {
4012 if (!this->emitCallVar(
Func, VarArgSize, E))
4015 if (!this->emitCall(
Func, 0, E)) {
4020 (void)this->emitPopPtr(E);
4026 return this->emitPopPtr(E);
4030 if (
T->isArrayType()) {
4035 if (!this->emitDupPtr(E))
4039 initArrayDimension = [&](
QualType T) ->
bool {
4040 if (!
T->isArrayType()) {
4042 for (
const auto *Arg : E->
arguments()) {
4043 if (!this->
visit(Arg))
4047 return this->emitCall(
Func, 0, E);
4051 Ctx.getASTContext().getAsConstantArrayType(
T);
4057 return this->emitCheckArraySize(NumElems, E);
4058 for (uint64_t I = 0; I != NumElems; ++I) {
4059 if (!this->emitConstUint64(I, E))
4061 if (!this->emitArrayElemPtrUint64(E))
4063 if (!initArrayDimension(ElemTy))
4066 return this->emitPopPtr(E);
4069 return initArrayDimension(E->
getType());
4075template <
class Emitter>
4085 assert(Val.
isInt());
4087 return this->emitConst(I, E);
4094 if (
const Expr *LValueExpr =
Base.dyn_cast<
const Expr *>())
4095 return this->
visit(LValueExpr);
4110 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4114 const APValue &
V = UGCD->getValue();
4115 for (
unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
4116 const Record::Field *F = R->getField(I);
4117 const APValue &FieldValue =
V.getStructField(I);
4121 if (!this->emitInitField(*F->T, F->Offset, E))
4129template <
class Emitter>
4135 for (
unsigned I = 0; I != N; ++I) {
4142 if (!this->
discard(ArrayIndexExpr))
4148 if (!this->
visit(ArrayIndexExpr))
4150 if (!this->emitCastAPToOffsetIndex(IndexT, E))
4154 if (!this->
visit(ArrayIndexExpr))
4158 if (!this->emitCast(IndexT,
PT_Sint64, E))
4168 return this->emitOffsetOf(
T, E, E);
4171template <
class Emitter>
4180 return this->visitZeroInitializer(*
T, Ty, E);
4187 if (!this->emitGetPtrLocal(*LocalIndex, E))
4195 ElemQT = CT->getElementType();
4198 NumElems = VT->getNumElements();
4199 ElemQT = VT->getElementType();
4205 for (
unsigned I = 0; I != NumElems; ++I) {
4206 if (!this->visitZeroInitializer(ElemT, ElemQT, E))
4208 if (!this->emitInitElem(ElemT, I, E))
4217template <
class Emitter>
4222template <
class Emitter>
4228template <
class Emitter>
4233template <
class Emitter>
4238 return this->emitConst(E->
getValue(), E);
4241template <
class Emitter>
4246 "Trivial CXXInheritedCtorInitExpr, implement. (possible?)");
4261 unsigned ParamIndex = 0;
4265 if (!this->emitGetParam(PT, ParamIndex, E))
4270 return this->emitCall(F, 0, E);
4275template <
class Emitter>
4283 const Expr *PlacementDest =
nullptr;
4284 bool IsNoThrow =
false;
4289 if (PlacementArgs != 0) {
4298 if (PlacementArgs == 1) {
4300 if (OperatorNew->isReservedGlobalPlacementOperator()) {
4301 if (!this->emitCheckPlacementNew(E, E))
4303 PlacementDest = Arg1;
4307 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4314 return this->emitInvalidNewDeleteExpr(E, E);
4318 return this->emitInvalid(E);
4320 }
else if (!OperatorNew
4321 ->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4322 return this->emitInvalidNewDeleteExpr(E, E);
4325 if (!PlacementDest) {
4330 Desc =
P.createDescriptor(E, *ElemT);
4332 Desc =
P.createDescriptor(E, ElementType.getTypePtr(),
false,
4339 std::optional<const Expr *> ArraySizeExpr = E->
getArraySize();
4343 const Expr *Stripped = *ArraySizeExpr;
4344 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
4345 Stripped = ICE->getSubExpr())
4346 if (ICE->getCastKind() != CK_NoOp &&
4347 ICE->getCastKind() != CK_IntegralCast)
4355 if (!this->
visit(Stripped))
4357 if (!this->emitSetLocal(
SizeT, ArrayLen, E))
4360 if (PlacementDest) {
4361 if (!this->
visit(PlacementDest))
4363 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4365 if (!this->emitCheckNewTypeMismatchArray(
SizeT, E, E))
4368 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4373 if (!this->emitAllocN(
SizeT, *ElemT, E, IsNoThrow, E))
4377 if (!this->emitAllocCN(
SizeT, Desc, IsNoThrow, E))
4384 size_t StaticInitElems = 0;
4385 const Expr *DynamicInit =
nullptr;
4389 Ctx.getASTContext().getAsConstantArrayType(InitType)) {
4390 StaticInitElems = CAT->getZExtSize();
4395 if (
const auto *ILE = dyn_cast<InitListExpr>(
Init)) {
4396 if (ILE->hasArrayFiller())
4397 DynamicInit = ILE->getArrayFiller();
4416 const Function *CtorFunc =
nullptr;
4417 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
4421 }
else if (!DynamicInit && !ElemT)
4424 LabelTy EndLabel = this->getLabel();
4425 LabelTy StartLabel = this->getLabel();
4430 if (!this->emitDupPtr(E))
4432 if (!this->emitIsNonNullPtr(E))
4434 if (!this->jumpFalse(EndLabel, E))
4441 if (!this->emitConst(StaticInitElems,
SizeT, E))
4443 if (!this->emitSetLocal(
SizeT, Iter, E))
4446 this->fallthrough(StartLabel);
4447 this->emitLabel(StartLabel);
4449 if (!this->emitGetLocal(
SizeT, Iter, E))
4451 if (!this->emitGetLocal(
SizeT, ArrayLen, E))
4453 if (!this->emitLT(
SizeT, E))
4455 if (!this->jumpFalse(EndLabel, E))
4459 if (!this->emitGetLocal(
SizeT, Iter, E))
4461 if (!this->emitArrayElemPtr(
SizeT, E))
4464 if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
4469 if (!this->visitZeroInitializer(*InitT, ElemType, E))
4471 if (!this->emitStorePop(*InitT, E))
4475 if (!this->visitZeroArrayInitializer(ElemType, E))
4478 }
else if (DynamicInit) {
4480 if (!this->
visit(DynamicInit))
4482 if (!this->emitStorePop(*InitT, E))
4489 if (!this->visitZeroInitializer(
4493 if (!this->emitStorePop(*ElemT, E))
4497 if (!this->emitCall(CtorFunc, 0, E))
4502 if (!this->emitGetPtrLocal(Iter, E))
4504 if (!this->emitIncPop(
SizeT,
false, E))
4507 if (!this->jump(StartLabel, E))
4510 this->fallthrough(EndLabel);
4511 this->emitLabel(EndLabel);
4515 if (PlacementDest) {
4516 if (!this->
visit(PlacementDest))
4518 if (!this->emitCheckNewTypeMismatch(E, E))
4523 if (!this->emitAlloc(Desc, E))
4532 if (!this->emitInit(*ElemT, E))
4543 return this->emitPopPtr(E);
4548template <
class Emitter>
4554 if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
4555 return this->emitInvalidNewDeleteExpr(E, E);
4564template <
class Emitter>
4570 if (
const Function *F =
Ctx.getOrCreateObjCBlock(E))
4575 return this->emitGetFnPtr(
Func, E);
4578template <
class Emitter>
4582 auto canonType = [](
const Type *
T) {
4583 return T->getCanonicalTypeUnqualified().getTypePtr();
4591 return this->emitGetTypeid(
4595 return this->emitGetTypeid(
4604 if (!
Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
4610 if (!this->emitGetTypeidPtr(TypeInfoType, E))
4613 return this->emitPopPtr(E);
4617template <
class Emitter>
4621 return this->emitDummyPtr(E, E);
4622 return this->emitError(E);
4625template <
class Emitter>
4628 return this->emitDummyPtr(E, E);
4629 return this->emitError(E);
4632template <
class Emitter>
4634 assert(
Ctx.getLangOpts().CPlusPlus);
4635 return this->emitConstBool(E->
getValue(), E);
4638template <
class Emitter>
4650 return this->emitDummyPtr(GuidDecl, E);
4655 if (!this->emitGetPtrGlobal(*GlobalIndex, E))
4664 assert(
V.isStruct());
4665 assert(
V.getStructNumBases() == 0);
4669 return this->emitFinishInit(E);
4672template <
class Emitter>
4682template <
class Emitter>
4691template <
class Emitter>
4697template <
class Emitter>
4701 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(SemE)) {
4705 if (OVE->isUnique())
4721template <
class Emitter>
4726template <
class Emitter>
4728 return this->emitError(E);
4731template <
class Emitter>
4737 return this->emitDummyPtr(E, E);
4740template <
class Emitter>
4741bool Compiler<Emitter>::emitVectorConversion(
const Expr *Src,
const Expr *E) {
4746 QualType ElemType = VT->getElementType();
4747 PrimType ElemT = classifyPrim(ElemType);
4749 PrimType SrcElemT = classifyVectorElementType(SrcType);
4755 if (!this->emitGetPtrLocal(*LocalIndex, E))
4759 unsigned SrcOffset =
4760 this->allocateLocalPrimitive(Src,
PT_Ptr,
true);
4761 if (!this->visit(Src))
4763 if (!this->emitSetLocal(
PT_Ptr, SrcOffset, E))
4766 for (
unsigned I = 0; I != VT->getNumElements(); ++I) {
4767 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
4769 if (!this->emitArrayElemPop(SrcElemT, I, E))
4773 if (SrcElemT != ElemT) {
4774 if (!this->emitPrimCast(SrcElemT, ElemT, ElemType, E))
4776 }
else if (ElemType->isFloatingType() && SrcType != ElemType) {
4777 const auto *TargetSemantics = &Ctx.getFloatSemantics(ElemType);
4781 if (!this->emitInitElem(ElemT, I, E))
4787template <
class Emitter>
4789 return emitVectorConversion(E->
getSrcExpr(), E);
4792template <
class Emitter>
4796 return this->emitInvalid(E);
4805 assert(NumOutputElems > 0);
4811 if (!this->emitGetPtrLocal(*LocalIndex, E))
4816 unsigned VectorOffsets[2];
4817 for (
unsigned I = 0; I != 2; ++I) {
4820 if (!this->
visit(Vecs[I]))
4822 if (!this->emitSetLocal(
PT_Ptr, VectorOffsets[I], E))
4825 for (
unsigned I = 0; I != NumOutputElems; ++I) {
4827 assert(ShuffleIndex >= -1);
4828 if (ShuffleIndex == -1)
4829 return this->emitInvalidShuffleVectorIndex(I, E);
4831 assert(ShuffleIndex < (NumInputElems * 2));
4832 if (!this->emitGetLocal(
PT_Ptr,
4833 VectorOffsets[ShuffleIndex >= NumInputElems], E))
4835 unsigned InputVectorIndex = ShuffleIndex.getZExtValue() % NumInputElems;
4836 if (!this->emitArrayElemPop(ElemT, InputVectorIndex, E))
4839 if (!this->emitInitElem(ElemT, I, E))
4844 return this->emitPopPtr(E);
4849template <
class Emitter>
4854 Base->getType()->isVectorType() ||
4860 if (Indices.size() == 1) {
4865 if (!this->emitConstUint32(Indices[0], E))
4867 return this->emitArrayElemPtrPop(
PT_Uint32, E);
4877 if (!this->emitSetLocal(
PT_Ptr, BaseOffset, E))
4885 if (!this->emitGetPtrLocal(*ResultIndex, E))
4893 uint32_t DstIndex = 0;
4894 for (uint32_t I : Indices) {
4895 if (!this->emitGetLocal(
PT_Ptr, BaseOffset, E))
4897 if (!this->emitArrayElemPop(ElemT, I, E))
4899 if (!this->emitInitElem(ElemT, DstIndex, E))
4909template <
class Emitter>
4913 return this->
discard(SubExpr) && this->emitInvalid(E);
4919 return this->emitDummyPtr(E, E);
4922template <
class Emitter>
4927 Ctx.getASTContext().getAsConstantArrayType(SubExpr->
getType());
4936 if (!this->emitGetPtrLocal(*LocalIndex, E))
4940 if (!this->
visit(SubExpr))
4942 if (!this->emitConstUint8(0, E))
4944 if (!this->emitArrayElemPtrPopUint8(E))
4946 if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
4949 PrimType SecondFieldT = *R->getField(1u)->T;
4951 if (!this->emitConst(
ArrayType->getSize(), SecondFieldT, E))
4953 if (!this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E))
4956 return this->emitPopPtr(E);
4959 assert(SecondFieldT ==
PT_Ptr);
4961 if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
4963 if (!this->emitExpandPtr(E))
4967 if (!this->emitArrayElemPtrPop(
PT_Uint64, E))
4970 if (!this->emitInitFieldPtr(R->getField(1u)->Offset, E))
4973 return this->emitPopPtr(E);
4977template <
class Emitter>
4992 if (
const Expr *ResultExpr = dyn_cast<Expr>(S))
4996 return this->emitUnsupported(E);
5005 return this->
Visit(E);
5012 return this->
Visit(E);
5016 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5019 if (
const auto *CE = dyn_cast<CastExpr>(E);
5021 (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_NoOp))
5028 if (
const auto *PE = dyn_cast<ParenExpr>(E))
5031 if (
const auto *CE = dyn_cast<CastExpr>(E);
5032 CE && (CE->getCastKind() == CK_DerivedToBase ||
5033 CE->getCastKind() == CK_UncheckedDerivedToBase ||
5034 CE->getCastKind() == CK_NoOp))
5054 if (!this->emitGetPtrLocal(*LocalIndex, E))
5064 return this->
Visit(E);
5067template <
class Emitter>
5073 return this->
Visit(E) && this->emitFinishInit(E);
5076template <
class Emitter>
5082 return this->
Visit(E) && this->emitFinishInitPop(E);
5088 return this->
Visit(E);
5099 if (!this->
visit(E))
5101 return this->emitComplexBoolCast(E);
5106 if (!this->
visit(E))
5114 return this->emitIsNonNullPtr(E);
5118 return this->emitCastFloatingIntegralBool(getFPOptions(E), E);
5121 return this->emitCast(*
T,
PT_Bool, E);
5124template <
class Emitter>
5128 QT = AT->getValueType();
5132 return this->emitZeroBool(E);
5134 return this->emitZeroSint8(E);
5136 return this->emitZeroUint8(E);
5138 return this->emitZeroSint16(E);
5140 return this->emitZeroUint16(E);
5142 return this->emitZeroSint32(E);
5144 return this->emitZeroUint32(E);
5146 return this->emitZeroSint64(E);
5148 return this->emitZeroUint64(E);
5150 return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
5152 return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
5154 return this->emitNullPtr(Ctx.getASTContext().getTargetNullPointerValue(QT),
5157 return this->emitNullMemberPtr(0,
nullptr, E);
5159 APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
5160 return this->emitFloat(F, E);
5163 auto Sem = Ctx.getASTContext().getFixedPointSemantics(QT);
5167 llvm_unreachable(
"unknown primitive type");
5170template <
class Emitter>
5171bool Compiler<Emitter>::visitZeroRecordInitializer(
const Record *R,
5173 bool IsCompleteClass) {
5177 for (
const Record::Field &Field :
R->fields()) {
5178 if (Field.isUnnamedBitField())
5185 if (!this->visitZeroInitializer(
T, QT, E))
5188 if (!this->emitInitFieldActivate(
T, Field.Offset, E))
5192 if (!this->emitInitField(
T, Field.Offset, E))
5197 if (!this->emitGetPtrField(Field.Offset, E))
5204 if (!this->visitZeroInitializer(
T, ET, E))
5206 if (!this->emitInitElem(
T, I, E))
5211 if (!this->visitZeroArrayInitializer(D->
getType(), E))
5214 if (!this->visitZeroRecordInitializer(D->
ElemRecord, E))
5222 if (!this->emitFinishInitActivatePop(E))
5226 if (!this->emitFinishInitPop(E))
5230 for (
const Record::Base &B :
R->bases()) {
5231 if (!this->emitGetPtrBase(B.Offset, E))
5233 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5235 if (!this->emitFinishInitPop(E))
5239 if (IsCompleteClass) {
5240 for (
const Record::Base &B :
R->virtual_bases()) {
5243 if (!this->visitZeroRecordInitializer(B.R, E,
false))
5245 if (!this->emitFinishInitPop(E))
5253template <
class Emitter>
5254bool Compiler<Emitter>::visitZeroArrayInitializer(
QualType T,
const Expr *E) {
5255 assert(
T->isArrayType() ||
T->isAnyComplexType() ||
T->isVectorType());
5256 const ArrayType *AT =
T->getAsArrayTypeUnsafe();
5261 for (
size_t I = 0; I != NumElems; ++I) {
5262 if (!this->visitZeroInitializer(*ElemT, ElemType, E))
5264 if (!this->emitInitElem(*ElemT, I, E))
5270 const Record *
R = getRecord(ElemType);
5274 for (
size_t I = 0; I != NumElems; ++I) {
5275 if (!this->emitConstUint32(I, E))
5277 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5279 if (!this->visitZeroRecordInitializer(R, E))
5281 if (!this->emitPopPtr(E))
5287 for (
size_t I = 0; I != NumElems; ++I) {
5288 if (!this->emitConstUint32(I, E))
5290 if (!this->emitArrayElemPtr(
PT_Uint32, E))
5292 if (!this->visitZeroArrayInitializer(ElemType, E))
5294 if (!this->emitPopPtr(E))
5303template <
class Emitter>
5304bool Compiler<Emitter>::visitAssignment(
const Expr *LHS,
const Expr *RHS,
5306 if (!canClassify(E->
getType()))
5311 if (!this->visit(LHS))
5313 if (!this->visit(RHS))
5316 if (!this->visit(RHS))
5318 if (!this->visit(LHS))
5326 if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(E))
5330 bool Activates = refersToUnion(LHS);
5333 if (NeedsFlip && !this->emitFlip(
PT_Ptr, RHT, E))
5336 if (DiscardResult) {
5337 if (BitField && Activates)
5338 return this->emitStoreBitFieldActivatePop(RHT, E);
5340 return this->emitStoreBitFieldPop(RHT, E);
5342 return this->emitStoreActivatePop(RHT, E);
5344 return this->emitStorePop(RHT, E);
5347 auto maybeLoad = [&](
bool Result) ->
bool {
5353 return this->emitLoadPop(RHT, E);
5357 if (BitField && Activates)
5358 return maybeLoad(this->emitStoreBitFieldActivate(RHT, E));
5360 return maybeLoad(this->emitStoreBitField(RHT, E));
5362 return maybeLoad(this->emitStoreActivate(RHT, E));
5364 return maybeLoad(this->emitStore(RHT, E));
5367template <
class Emitter>
5368template <
typename T>
5372 return this->emitConstSint8(
Value, Info);
5374 return this->emitConstUint8(
Value, Info);
5376 return this->emitConstSint16(
Value, Info);
5378 return this->emitConstUint16(
Value, Info);
5380 return this->emitConstSint32(
Value, Info);
5382 return this->emitConstUint32(
Value, Info);
5384 return this->emitConstSint64(
Value, Info);
5386 return this->emitConstUint64(
Value, Info);
5388 return this->emitConstBool(
Value, Info);
5395 llvm_unreachable(
"Invalid integral type");
5398 llvm_unreachable(
"unknown primitive type");
5401template <
class Emitter>
5402template <
typename T>
5403bool Compiler<Emitter>::emitConst(
T Value,
const Expr *E) {
5404 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5407template <
class Emitter>
5411 return this->emitConstIntAPS(
Value, Info);
5413 return this->emitConstIntAP(
Value, Info);
5415 if (
Value.isSigned())
5416 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5417 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5420template <
class Emitter>
5424 return this->emitConstIntAPS(
Value, Info);
5426 return this->emitConstIntAP(
Value, Info);
5429 return this->emitConst(
Value.getSExtValue(), Ty, Info);
5430 return this->emitConst(
Value.getZExtValue(), Ty, Info);
5433template <
class Emitter>
5434bool Compiler<Emitter>::emitConst(
const APSInt &
Value,
const Expr *E) {
5435 return this->emitConst(
Value, classifyPrim(E->
getType()), E);
5438template <
class Emitter>
5453 return Local.Offset;
5456template <
class Emitter>
5461 bool IsTemporary =
false;
5465 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
5466 Init = VarD->getInit();
5468 if (
const auto *E = Src.
asExpr()) {
5478 return std::nullopt;
5485 return Local.Offset;
5488template <
class Emitter>
5497 return std::nullopt;
5507 return Local.Offset;
5510template <
class Emitter>
5512 if (
const PointerType *PT = dyn_cast<PointerType>(Ty))
5513 return PT->getPointeeType()->getAsCanonical<RecordType>();
5519 return getRecord(RecordTy->getDecl()->getDefinitionOrSelf());
5523template <
class Emitter>
5525 return P.getOrCreateRecord(RD);
5528template <
class Emitter>
5530 return Ctx.getOrCreateFunction(FD);
5533template <
class Emitter>
5539 auto maybeDestroyLocals = [&]() ->
bool {
5540 if (DestroyToplevelScope)
5541 return RootScope.
destroyLocals() && this->emitCheckAllocations(E);
5542 return this->emitCheckAllocations(E);
5549 return this->emitRetVoid(E) && maybeDestroyLocals();
5557 return this->emitRet(*
T, E) && maybeDestroyLocals();
5565 if (!this->emitGetPtrLocal(*LocalOffset, E))
5573 return this->emitRetValue(E) && maybeDestroyLocals();
5576 return maybeDestroyLocals() &&
false;
5579template <
class Emitter>
5581 bool DestroyToplevelScope) {
5585 return this->
visitExpr(E, DestroyToplevelScope);
5588template <
class Emitter>
5600 if (
auto GlobalIndex =
P.getGlobal(VD)) {
5601 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5615template <
class Emitter>
5617 bool ConstantContext) {
5620 if (!ConstantContext) {
5635 auto GlobalIndex =
P.getGlobal(VD);
5636 assert(GlobalIndex);
5638 if (!this->emitGetGlobalUnchecked(*VarT, *GlobalIndex, VD))
5641 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
5649 if (!this->emitGetRefLocal(
Local->second.Offset, VD))
5651 }
else if (!this->emitGetLocal(*VarT,
Local->second.Offset, VD))
5654 if (!this->emitGetPtrLocal(
Local->second.Offset, VD))
5664 auto GlobalIndex =
P.getGlobal(VD);
5665 assert(GlobalIndex);
5666 Block *GlobalBlock =
P.getGlobal(*GlobalIndex);
5675 return VDScope.
destroyLocals() && this->emitCheckAllocations(VD);
5678template <
class Emitter>
5689 if (!this->isActive())
5694 if (
Init &&
Init->isValueDependent())
5698 auto checkDecl = [&]() ->
bool {
5700 return !NeedsOp || this->emitCheckDecl(VD, VD);
5707 if (!
P.getGlobal(*GlobalIndex)->isInitialized())
5710 if (
P.isGlobalInitialized(*GlobalIndex))
5714 }
else if ((GlobalIndex =
5729 return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
5732 if (!this->emitGetPtrGlobal(*GlobalIndex,
Init))
5735 if (!this->emitStartInit(
Init))
5741 if (!this->emitEndInit(
Init))
5744 return this->emitFinishInitGlobal(
Init);
5754 if (!
Init ||
Init->getType()->isVoidType())
5763 return this->emitSetLocal(*VarT, Offset, VD) &&
Scope.destroyLocals();
5775 if (!this->emitCheckRefInit(
Init))
5779 return this->emitSetLocal(*VarT, Offset, VD);
5787 if (!this->emitGetPtrLocal(*Offset,
Init))
5795template <
class Emitter>
5818 if (!this->emitGetPtrLocal(
Local.Offset, VD))
5824 return this->emitDestructionPop(D, VD);
5833 if (
const auto *P = dyn_cast<ParmVarDecl>(E->
getDecl()))
5857template <
class Emitter>
5872 unsigned ParamIndex = 0;
5879 const Expr *Arg = Args[ParamIndex];
5880 const ParmVarDecl *Param = Callee->getParamDecl(ParamIndex);
5882 unsigned ArgOffset =
5884 if (!this->
visit(Arg))
5886 if (!this->emitSetLocal(*ParamT, ArgOffset, Arg))
5892 if (!this->emitGetPtrLocal(*ArgOffset, Arg))
5904 if (
This->getType()->isPointerType()) {
5907 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
This)) {
5914 if (!this->emitGetPtrLocal(*ArgOffset,
This))
5936template <
class Emitter>
5942 return this->emitConst(Val.
getInt(), ValType, Info);
5944 return this->emitFloat(Val.
getFloat(), Info);
5948 if (!this->emitGetMemberPtr(MemberDecl, Info))
5954 if (!this->emitCopyMemberPtrPath(PathEntry, IsDerived, Info))
5960 return this->emitNullMemberPtr(0,
nullptr, Info);
5965 return this->emitNull(ValType, 0,
nullptr, Info);
5969 if (
const Expr *BaseExpr =
Base.dyn_cast<
const Expr *>())
5970 return this->
visit(BaseExpr);
5975 QualType EntryType = VD->getType();
5978 for (
auto &Entry : Path) {
5980 uint64_t Index = Entry.getAsArrayIndex();
5983 if (!this->emitConst(Index,
PT_Uint64, Info))
5985 if (!this->emitArrayElemPtrPop(
PT_Uint64, Info))
5987 EntryType = ElemType;
5994 const Decl *BaseOrMember = Entry.getAsBaseOrMember().getPointer();
5995 if (
const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
5997 if (!this->emitGetPtrFieldPop(EntryOffset, Info))
5999 EntryType = FD->getType();
6003 if (!this->emitGetPtrBasePop(B->Offset,
false, Info))
6008 if (!this->emitGetPtrVirtBasePop(
Base, Info))
6011 EntryType =
Ctx.getASTContext().getCanonicalTagType(
Base);
6024template <
class Emitter>
6027 bool IsCompleteClass) {
6033 if (IsCompleteClass)
6040 const Record::Base *RB = R->getBase(I);
6041 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6043 if (!this->emitGetPtrBase(RB->Offset, Info))
6048 if (!this->emitFinishInitPop(Info))
6056 const Record::Field *RF = R->getField(I);
6057 QualType FieldType = RF->Decl->getType();
6062 if (!this->emitInitField(*PT, RF->Offset, Info))
6065 if (!this->emitGetPtrField(RF->Offset, Info))
6069 if (!this->emitFinishInitPop(Info))
6075 if (IsCompleteClass) {
6080 const Record::Base *RB = R->getVirtualBase(I);
6081 QualType BaseType =
Ctx.getASTContext().getCanonicalTagType(RB->Decl);
6089 if (!this->emitFinishInitPop(Info))
6105 const Record::Field *RF = R->getField(UnionField);
6106 QualType FieldType = RF->Decl->getType();
6111 if (RF->isBitField())
6112 return this->emitInitBitFieldActivate(*PT, RF->Offset, RF->bitWidth(),
6114 return this->emitInitFieldActivate(*PT, RF->Offset, Info);
6117 if (!this->emitGetPtrField(RF->Offset, Info))
6119 if (!this->emitActivate(Info))
6123 return this->emitPopPtr(Info);
6127 const auto *ArrType =
T->getAsArrayTypeUnsafe();
6128 QualType ElemType = ArrType->getElementType();
6131 for (
unsigned A = 0, AN = Val.
getArraySize(); A != AN; ++A) {
6132 const APValue &Elem = A >= InitializedElems
6141 if (!this->emitInitElem(*ElemT, A, Info))
6144 if (!this->emitConstUint32(A, Info))
6146 if (!this->emitArrayElemPtrUint32(Info))
6150 if (!this->emitPopPtr(Info))
6161template <
class Emitter>
6163 if (
P.getGlobal(VD))
6168 llvm_unreachable(
"Why didn't that work?");
6172 "registerRedecl should only be called with primitive values");
6177 return this->emitInitGlobal(
T, *GlobalIndex, {});
6180template <
class Emitter>
6182 unsigned BuiltinID) {
6188 if (!
Ctx.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
6189 return this->emitInvalid(E);
6198 if (BuiltinID == Builtin::BI__builtin_constant_p) {
6203 return this->emitConst(0, E);
6206 if (!this->emitStartSpeculation(E))
6208 LabelTy EndLabel = this->getLabel();
6209 if (!this->speculate(E, EndLabel))
6211 if (!this->emitEndSpeculation(E))
6213 this->fallthrough(EndLabel);
6221 if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
6222 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
6223 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
6224 BuiltinID == Builtin::BI__builtin_function_start) {
6227 return this->emitDummyPtr(E, E);
6238 if (!this->emitGetPtrLocal(*LocalIndex, E))
6243 switch (BuiltinID) {
6244 case Builtin::BI__builtin_object_size:
6245 case Builtin::BI__builtin_dynamic_object_size: {
6249 if (!this->
visit(Arg0))
6260 case Builtin::BI__assume:
6261 case Builtin::BI__builtin_assume:
6264 case Builtin::BI__atomic_is_lock_free:
6265 case Builtin::BI__atomic_always_lock_free: {
6276 for (
const auto *Arg : E->
arguments()) {
6277 if (!this->
visit(Arg))
6283 if (!this->emitCallBI(E, BuiltinID, E))
6301template <
class Emitter>
6322 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FuncDecl);
6323 DD && DD->isTrivial()) {
6325 if (!this->
visit(MemberCall->getImplicitObjectArgument()))
6327 return this->emitCheckDestruction(E) && this->emitEndLifetime(E) &&
6328 this->emitPopPtr(E);
6334 bool ActivateLHS =
false;
6342 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6343 OCE && OCE->isAssignmentOp()) {
6344 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6347 if (
const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
6348 if (!this->
visit(MCE->getImplicitObjectArgument()))
6355 if (!this->emitTrivialCopy(ActivateLHS,
Func, E))
6373 if (!this->emitGetPtrLocal(*LocalIndex, E))
6381 if (!this->emitGetPtrLocal(*LocalIndex, E))
6385 if (!this->emitDupPtr(E))
6390 const Expr *ReversedArgs[2];
6391 bool IsAssignmentOperatorCall =
false;
6392 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
6393 OCE && OCE->isAssignmentOp()) {
6397 assert(Args.size() == 2);
6398 const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
6400 IsAssignmentOperatorCall =
true;
6401 ReversedArgs[0] = Args[1];
6402 ReversedArgs[1] = Args[0];
6403 Args = ReversedArgs;
6410 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
6411 MD && MD->isStatic()) {
6415 Args = Args.drop_front();
6419 bool Devirtualized =
false;
6422 if (
const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
6430 if (!this->
visit(Callee))
6432 if (!this->emitSetLocal(
PT_MemberPtr, *CalleeOffset, E))
6434 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6436 if (!this->emitGetMemberPtrBase(E))
6439 const auto *InstancePtr = MC->getImplicitObjectArgument();
6446 Stripped->getType()->getPointeeType()->getAsCXXRecordDecl());
6447 Devirtualized =
true;
6448 if (!this->
visit(Stripped))
6451 if (!this->
visit(InstancePtr))
6455 if (!this->
visit(InstancePtr))
6459 }
else if (
const auto *PD =
6460 dyn_cast<CXXPseudoDestructorExpr>(E->
getCallee())) {
6461 if (!this->emitCheckPseudoDtor(E))
6469 return this->emitPseudoDtor(E);
6470 }
else if (!FuncDecl) {
6474 if (!this->
visit(Callee))
6476 if (!this->emitSetLocal(
PT_Ptr, *CalleeOffset, E))
6485 if (IsAssignmentOperatorCall) {
6486 assert(Args.size() == 2);
6489 if (!this->emitFlip(Arg2T, Arg1T, E))
6503 assert(HasRVO ==
Func->hasRVO());
6505 bool HasQualifier =
false;
6506 if (
const auto *ME = dyn_cast<MemberExpr>(E->
getCallee()))
6507 HasQualifier = ME->hasQualifier();
6509 bool IsVirtual =
false;
6510 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
6511 IsVirtual = !Devirtualized && MD->isVirtual();
6516 if (IsVirtual && !HasQualifier) {
6517 uint32_t VarArgSize = 0;
6518 unsigned NumParams =
6519 Func->getNumWrittenParams() +
6521 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6524 if (!this->emitCallVirt(
Func, VarArgSize, E))
6526 }
else if (
Func->isVariadic()) {
6527 uint32_t VarArgSize = 0;
6528 unsigned NumParams =
6529 Func->getNumWrittenParams() +
6531 for (
unsigned I = NumParams, N = E->
getNumArgs(); I != N; ++I)
6533 if (!this->emitCallVar(
Func, VarArgSize, E))
6536 if (!this->emitCall(
Func, 0, E))
6545 uint32_t ArgSize = 0;
6546 for (
unsigned I = 0, N = E->
getNumArgs(); I != N; ++I)
6552 if (!this->emitGetLocal(
PT_MemberPtr, *CalleeOffset, E))
6554 if (!this->emitGetMemberPtrDecl(E))
6557 if (!this->emitGetLocal(
PT_Ptr, *CalleeOffset, E))
6560 if (!this->emitCallPtr(ArgSize, E, E))
6571template <
class Emitter>
6578template <
class Emitter>
6585template <
class Emitter>
6590 return this->emitConstBool(E->
getValue(), E);
6593template <
class Emitter>
6599 uint64_t Val =
Ctx.getASTContext().getTargetNullPointerValue(E->
getType());
6600 return this->emitNullPtr(Val,
nullptr, E);
6603template <
class Emitter>
6611 return this->emitZero(
T, E);
6614template <
class Emitter>
6619 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
6620 if (this->LambdaThisCapture.Offset > 0) {
6621 if (this->LambdaThisCapture.IsPtr)
6622 return this->emitGetThisFieldPtr(this->LambdaThisCapture.Offset, E);
6623 return this->emitGetPtrThisField(this->LambdaThisCapture.Offset, E);
6632 return this->emitThis(E);
6647 unsigned StartIndex = 0;
6648 unsigned EndIndex = 0;
6650 for (StartIndex =
InitStack.size() - 1; StartIndex > 0; --StartIndex) {
6652 EndIndex = StartIndex;
6659 for (; StartIndex > 0; --StartIndex) {
6670 if (StartIndex == 0 && EndIndex == 0)
6681 assert(StartIndex <= EndIndex);
6684 for (
unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
6696 case Stmt::CompoundStmtClass:
6698 case Stmt::DeclStmtClass:
6700 case Stmt::ReturnStmtClass:
6702 case Stmt::IfStmtClass:
6704 case Stmt::WhileStmtClass:
6706 case Stmt::DoStmtClass:
6708 case Stmt::ForStmtClass:
6710 case Stmt::CXXForRangeStmtClass:
6712 case Stmt::BreakStmtClass:
6714 case Stmt::ContinueStmtClass:
6716 case Stmt::SwitchStmtClass:
6718 case Stmt::CaseStmtClass:
6720 case Stmt::DefaultStmtClass:
6722 case Stmt::AttributedStmtClass:
6724 case Stmt::CXXTryStmtClass:
6726 case Stmt::NullStmtClass:
6729 case Stmt::GCCAsmStmtClass:
6730 case Stmt::MSAsmStmtClass:
6731 case Stmt::GotoStmtClass:
6732 return this->emitInvalid(S);
6733 case Stmt::LabelStmtClass:
6735 case Stmt::CXXExpansionStmtInstantiationClass:
6739 if (
const auto *E = dyn_cast<Expr>(S))
6746template <
class Emitter>
6749 for (
const auto *InnerStmt : S->
body())
6752 return Scope.destroyLocals();
6755template <
class Emitter>
6756bool Compiler<Emitter>::maybeEmitDeferredVarInit(
const VarDecl *VD) {
6757 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
6758 for (
auto *BD : DD->flat_bindings())
6759 if (
auto *KD = BD->getHoldingVar();
6760 KD && !this->visitVarDecl(KD, KD->getInit()))
6774template <
class Emitter>
bool Compiler<Emitter>::refersToUnion(
const Expr *E) {
6776 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
6777 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
6784 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
6789 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
6790 ICE && (ICE->getCastKind() == CK_NoOp ||
6791 ICE->getCastKind() == CK_DerivedToBase ||
6792 ICE->getCastKind() == CK_UncheckedDerivedToBase)) {
6793 E = ICE->getSubExpr();
6797 if (
const auto *
This = dyn_cast<CXXThisExpr>(E)) {
6798 const auto *ThisRecord =
6799 This->getType()->getPointeeType()->getAsRecordDecl();
6800 if (!ThisRecord->isUnion())
6803 if (
const auto *Ctor =
6804 dyn_cast_if_present<CXXConstructorDecl>(CompilingFunction))
6805 return Ctor->getParent() == ThisRecord;
6814template <
class Emitter>
6816 bool EvaluateConditionDecl) {
6817 for (
const auto *D : DS->
decls()) {
6822 if (
const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
6823 assert(ESD->getInstantiations() &&
"not expanded?");
6824 if (!this->
visitStmt(ESD->getInstantiations()))
6829 const auto *VD = dyn_cast<VarDecl>(D);
6836 if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
6843template <
class Emitter>
6846 return this->emitUnsupported(RS);
6852 if (!this->
visit(RE))
6858 if (RE->getType()->isVoidType()) {
6859 if (!this->
visit(RE))
6862 if (RE->containsErrors())
6867 if (!this->emitRVOPtr(RE))
6873 return this->emitRetVoid(RS);
6879 return this->emitRetVoid(RS);
6885 auto visitChildStmt = [&](
const Stmt *S) ->
bool {
6892 if (
auto *CondInit = IS->
getInit()) {
6908 return visitChildStmt(IS->
getThen());
6910 return visitChildStmt(Else);
6916 if (!this->emitIsConstantContext(IS))
6919 if (!this->emitIsConstantContext(IS))
6921 if (!this->emitInv(IS))
6935 LabelTy LabelElse = this->getLabel();
6936 LabelTy LabelEnd = this->getLabel();
6937 if (!this->jumpFalse(LabelElse, IS))
6939 if (!visitChildStmt(IS->
getThen()))
6941 if (!this->jump(LabelEnd, IS))
6943 this->emitLabel(LabelElse);
6944 if (!visitChildStmt(Else))
6946 this->emitLabel(LabelEnd);
6948 LabelTy LabelEnd = this->getLabel();
6949 if (!this->jumpFalse(LabelEnd, IS))
6951 if (!visitChildStmt(IS->
getThen()))
6953 this->emitLabel(LabelEnd);
6962template <
class Emitter>
6967 LabelTy CondLabel = this->getLabel();
6968 LabelTy EndLabel = this->getLabel();
6972 this->fallthrough(CondLabel);
6973 this->emitLabel(CondLabel);
6989 if (!this->jumpFalse(EndLabel, S))
6999 if (!this->jump(CondLabel, S))
7001 this->fallthrough(EndLabel);
7002 this->emitLabel(EndLabel);
7011 LabelTy StartLabel = this->getLabel();
7012 LabelTy EndLabel = this->getLabel();
7013 LabelTy CondLabel = this->getLabel();
7017 this->fallthrough(StartLabel);
7018 this->emitLabel(StartLabel);
7024 this->fallthrough(CondLabel);
7025 this->emitLabel(CondLabel);
7032 if (!this->jumpTrue(StartLabel, S))
7035 this->fallthrough(EndLabel);
7036 this->emitLabel(EndLabel);
7040template <
class Emitter>
7048 LabelTy EndLabel = this->getLabel();
7049 LabelTy CondLabel = this->getLabel();
7050 LabelTy IncLabel = this->getLabel();
7057 this->fallthrough(CondLabel);
7058 this->emitLabel(CondLabel);
7070 if (!this->jumpFalse(EndLabel, S))
7079 this->fallthrough(IncLabel);
7080 this->emitLabel(IncLabel);
7086 if (!this->jump(CondLabel, S))
7090 this->emitLabel(EndLabel);
7096template <
class Emitter>
7106 LabelTy EndLabel = this->getLabel();
7107 LabelTy CondLabel = this->getLabel();
7108 LabelTy IncLabel = this->getLabel();
7124 this->fallthrough(CondLabel);
7125 this->emitLabel(CondLabel);
7128 if (!this->jumpFalse(EndLabel, S))
7139 this->fallthrough(IncLabel);
7140 this->emitLabel(IncLabel);
7147 if (!this->jump(CondLabel, S))
7150 this->fallthrough(EndLabel);
7151 this->emitLabel(EndLabel);
7155template <
class Emitter>
7166 if (LI.BreakLabel) {
7167 TargetLabel = *LI.BreakLabel;
7168 BreakScope = LI.BreakOrContinueScope;
7174 if (LI.Name == TargetLoop) {
7175 TargetLabel = *LI.BreakLabel;
7176 BreakScope = LI.BreakOrContinueScope;
7187 C =
C->getParent()) {
7188 if (!
C->destroyLocals())
7192 return this->jump(*TargetLabel, S);
7195template <
class Emitter>
7206 if (LI.ContinueLabel) {
7207 TargetLabel = *LI.ContinueLabel;
7208 ContinueScope = LI.BreakOrContinueScope;
7214 if (LI.Name == TargetLoop) {
7215 TargetLabel = *LI.ContinueLabel;
7216 ContinueScope = LI.BreakOrContinueScope;
7226 C =
C->getParent()) {
7227 if (!
C->destroyLocals())
7231 return this->jump(*TargetLabel, S);
7234template <
class Emitter>
7244 LabelTy EndLabel = this->getLabel();
7249 if (
const auto *CondInit = S->
getInit())
7258 if (!this->
visit(Cond))
7260 if (!this->emitSetLocal(CondT, CondVar, S))
7270 if (
const auto *CS = dyn_cast<CaseStmt>(SC)) {
7273 if (CS->caseStmtIsGNURange()) {
7274 LabelTy EndOfRangeCheck = this->getLabel();
7275 const Expr *Low = CS->getLHS();
7276 const Expr *High = CS->getRHS();
7280 if (!this->emitGetLocal(CondT, CondVar, CS))
7282 if (!this->
visit(Low))
7285 if (!this->emitGE(
LT, S))
7287 if (!this->jumpFalse(EndOfRangeCheck, S))
7290 if (!this->emitGetLocal(CondT, CondVar, CS))
7292 if (!this->
visit(High))
7295 if (!this->emitLE(HT, S))
7299 this->emitLabel(EndOfRangeCheck);
7304 if (
Value->isValueDependent())
7309 if (!this->emitGetLocal(CondT, CondVar, CS))
7315 if (!this->emitEQ(ValueT, S))
7320 assert(!DefaultLabel);
7321 DefaultLabel = this->getLabel();
7328 if (!this->jump(*DefaultLabel, S))
7331 if (!this->jump(EndLabel, S))
7339 this->fallthrough(EndLabel);
7340 this->emitLabel(EndLabel);
7345template <
class Emitter>
7353 return this->emitUnsupported(S);
7358template <
class Emitter>
7365 if (LI.DefaultLabel) {
7366 DefaultLabel = *LI.DefaultLabel;
7371 this->emitLabel(DefaultLabel);
7375template <
class Emitter>
7382 if (IsMSVCConstexprAttr && !this->emitPushMSVCCE(S))
7385 if (this->
Ctx.getLangOpts().CXXAssumptions &&
7386 !this->Ctx.getLangOpts().MSVCCompat) {
7388 auto *AA = dyn_cast<CXXAssumeAttr>(A);
7394 const Expr *Assumption = AA->getAssumption();
7405 if (!this->emitAssume(Assumption))
7414 if (IsMSVCConstexprAttr)
7415 return this->emitPopMSVCCE(S);
7419template <
class Emitter>
7432template <
class Emitter>
7442 LabelTy EndLabel = this->getLabel();
7444 LabelTy ContinueLabel = this->getLabel();
7449 this->emitLabel(ContinueLabel);
7452 this->emitLabel(EndLabel);
7457template <
class Emitter>
7458bool Compiler<Emitter>::emitLambdaStaticInvokerBody(
const CXXMethodDecl *MD) {
7465 assert(ClosureClass->
captures().empty());
7469 "A generic lambda's static-invoker function must be a "
7470 "template specialization");
7474 llvm::FoldingSetInsertToken InsertToken;
7475 const FunctionDecl *CorrespondingCallOpSpecialization =
7477 assert(CorrespondingCallOpSpecialization);
7478 LambdaCallOp = CorrespondingCallOpSpecialization;
7482 assert(ClosureClass->
captures().empty());
7483 const Function *
Func = this->getFunction(LambdaCallOp);
7486 assert(
Func->hasThisPointer());
7489 if (
Func->hasRVO()) {
7490 if (!this->emitRVOPtr(MD))
7498 if (!this->emitNullPtr(0,
nullptr, MD))
7503 auto It = this->Params.find(PVD);
7504 assert(It != this->Params.end());
7508 PrimType ParamType = this->classify(PVD->getType()).value_or(
PT_Ptr);
7509 if (!this->emitGetParam(ParamType, It->second.Index, MD))
7513 if (!this->emitCall(
Func, 0, LambdaCallOp))
7518 return this->emitRet(*ReturnType, MD);
7521 return this->emitRetVoid(MD);
7524template <
class Emitter>
7525bool Compiler<Emitter>::checkLiteralType(
const Expr *E) {
7526 if (Ctx.getLangOpts().CPlusPlus23)
7536 const Expr *InitExpr =
Init->getInit();
7538 if (!
Init->isWritten() && !
Init->isInClassMemberInitializer() &&
7542 if (
const auto *CE = dyn_cast<CXXConstructExpr>(InitExpr)) {
7552template <
class Emitter>
7554 assert(!ReturnType);
7557 if (!this->emitStartThisLifetime1(Ctor))
7560 auto emitFieldInitializer = [&](
const Record::Field *F,
unsigned FieldOffset,
7561 const Expr *InitExpr,
7564 if (InitExpr->getType().isNull())
7568 if (
Activate && !this->emitActivateThisField(FieldOffset, InitExpr))
7571 if (!this->visit(InitExpr))
7574 if (F->isBitField())
7575 return this->emitInitThisBitField(*
T, FieldOffset, F->bitWidth(),
7577 return this->emitInitThisField(*
T, FieldOffset, InitExpr);
7582 if (!this->emitGetPtrThisField(FieldOffset, InitExpr))
7585 if (
Activate && !this->emitActivate(InitExpr))
7588 return this->visitInitializerPop(InitExpr);
7592 const Record *
R = this->getRecord(RD);
7595 bool IsUnion =
R->isUnion();
7605 if (!this->emitThis(Ctor))
7608 if (!this->emitGetParam(
PT_Ptr, 0, Ctor))
7611 return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
7612 this->emitRetVoid(Ctor);
7615 unsigned FieldInits = 0;
7618 if (
R->getNumVirtualBases() > 0) {
7619 if (!this->emitThis(Ctor))
7621 LabelTy AfterVirtBasesLabel = this->getLabel();
7624 if (!this->emitIsBaseClass({}))
7626 if (!this->jumpTrue(AfterVirtBasesLabel, {}))
7629 for (
const auto *
Init : Ctor->
inits()) {
7632 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7634 assert(
R->findVirtualBase(BaseDecl));
7635 if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor))
7637 if (!this->visitInitializerPop(
Init->getInit()))
7642 this->fallthrough(AfterVirtBasesLabel);
7643 this->emitLabel(AfterVirtBasesLabel);
7645 if (!this->emitPopPtr(Ctor))
7649 for (
const auto *
Init : Ctor->
inits()) {
7653 const Expr *InitExpr =
Init->getInit();
7655 const Record::Field *F =
R->getField(
Member);
7659 if (!emitFieldInitializer(F, F->Offset, InitExpr, IsUnion))
7663 const auto *BaseDecl =
Base->getAsCXXRecordDecl();
7666 if (
Init->isBaseVirtual()) {
7672 const Record::Base *B =
R->getBase(BaseDecl);
7674 if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
7678 if (!this->visitInitializerPop(InitExpr))
7683 unsigned ChainSize = IFD->getChainingSize();
7684 assert(ChainSize >= 2);
7686 unsigned NestedFieldOffset = 0;
7687 const Record::Field *NestedField =
nullptr;
7688 for (
unsigned I = 0; I != ChainSize; ++I) {
7690 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7691 assert(FieldRecord);
7693 NestedField = FieldRecord->
getField(FD);
7694 assert(NestedField);
7695 IsUnion = IsUnion || FieldRecord->
isUnion();
7697 NestedFieldOffset += NestedField->Offset;
7700 if (I != ChainSize - 1)
7703 assert(NestedField);
7706 if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
7711 unsigned InitFieldOffset = 0;
7712 for (
const NamedDecl *ND : IFD->chain().drop_back()) {
7714 const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
7715 assert(FieldRecord);
7716 NestedField = FieldRecord->
getField(FD);
7717 InitFieldOffset += NestedField->Offset;
7718 assert(NestedField);
7719 if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
7721 if (!this->emitFinishInitPop(InitExpr))
7725 InitStack.pop_back_n(ChainSize - 1);
7728 assert(
Init->isDelegatingInitializer());
7729 if (!this->emitThis(InitExpr))
7731 if (!this->visitInitializerPop(
Init->getInit()))
7735 if (!
Scope.destroyLocals())
7739 if (FieldInits !=
R->getNumFields()) {
7740 assert(FieldInits < R->getNumFields());
7742 if (!this->emitStartThisLifetime(Ctor))
7749 if (
const auto *CS = dyn_cast<CompoundStmt>(Body)) {
7750 if (!CS->body_empty() && !this->emitCtorCheck(
SourceInfo{}))
7757 if (!visitStmt(Body))
7764template <
class Emitter>
7767 const Record *
R = this->getRecord(RD);
7771 if (!
Dtor->isTrivial() &&
Dtor->getBody()) {
7772 if (!this->visitStmt(
Dtor->getBody()))
7776 if (!this->emitThis(
Dtor))
7779 if (!this->emitCheckDestruction(
Dtor))
7783 if (!
R->isUnion()) {
7787 for (
const Record::Field &Field : llvm::reverse(
R->fields())) {
7791 if (!this->emitGetPtrField(Field.Offset,
SourceInfo{}))
7793 if (!this->emitDestructionPop(D,
SourceInfo{}))
7798 for (
const Record::Base &
Base : llvm::reverse(
R->bases())) {
7799 if (
Base.R->hasTrivialDtor())
7803 if (!this->emitRecordDestructionPop(
Base.R, {}))
7807 if (
R->getNumVirtualBases() > 0) {
7808 LabelTy EndLabel = this->getLabel();
7810 if (!this->emitIsBaseClass({}))
7812 if (!this->jumpTrue(EndLabel, {}))
7815 for (
const Record::Base &
Base : llvm::reverse(
R->virtual_bases())) {
7816 if (
Base.R->hasTrivialDtor())
7821 if (!this->emitRecordDestructionPop(
Base.R, {}))
7825 this->fallthrough(EndLabel);
7826 this->emitLabel(EndLabel);
7829 if (!this->emitMarkDestroyed(
Dtor))
7832 return this->emitPopPtr(
Dtor) && this->emitRetVoid(
Dtor);
7835template <
class Emitter>
7836bool Compiler<Emitter>::compileUnionAssignmentOperator(
7838 if (!this->emitThis(MD))
7841 if (!this->emitGetParam(
PT_Ptr, 0, MD))
7844 return this->emitMemcpy(MD) && this->emitRet(
PT_Ptr, MD);
7847template <
class Emitter>
7857 if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
7858 return this->compileConstructor(Ctor);
7859 if (
const auto *
Dtor = dyn_cast<CXXDestructorDecl>(F))
7860 return this->compileDestructor(
Dtor);
7863 if (
const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
7868 return this->compileUnionAssignmentOperator(MD);
7871 return this->emitLambdaStaticInvokerBody(MD);
7875 if (
const auto *Body = F->
getBody())
7889 return FD->getBitWidthValue();
7892template <
class Emitter>
7908 if (!
Ctx.getLangOpts().CPlusPlus14)
7909 return this->emitInvalid(E);
7911 return this->emitError(E);
7913 if (!this->
visit(SubExpr))
7917 if (!this->emitIncPtr(E))
7924 return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
7925 : this->emitIncf(getFPOptions(E), E);
7937 if (!
Ctx.getLangOpts().CPlusPlus14)
7938 return this->emitInvalid(E);
7940 return this->emitError(E);
7942 if (!this->
visit(SubExpr))
7946 if (!this->emitDecPtr(E))
7953 return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
7954 : this->emitDecf(getFPOptions(E), E);
7967 if (!
Ctx.getLangOpts().CPlusPlus14)
7968 return this->emitInvalid(E);
7970 return this->emitError(E);
7972 if (!this->
visit(SubExpr))
7976 if (!this->emitLoadPtr(E))
7978 if (!this->emitConstUint8(1, E))
7980 if (!this->emitAddOffsetUint8(E))
7982 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
7988 return this->emitIncfPop(getFPOptions(E), E);
7998 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
7999 if (!this->emitLoadFloat(E))
8001 APFloat F(TargetSemantics, 1);
8002 if (!this->emitFloat(F, E))
8005 if (!this->emitAddf(getFPOptions(E), E))
8007 if (!this->emitStoreFloat(E))
8019 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8022 if (!
Ctx.getLangOpts().CPlusPlus14)
8023 return this->emitInvalid(E);
8025 return this->emitError(E);
8027 if (!this->
visit(SubExpr))
8031 if (!this->emitLoadPtr(E))
8033 if (!this->emitConstUint8(1, E))
8035 if (!this->emitSubOffsetUint8(E))
8037 return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
8043 return this->emitDecfPop(getFPOptions(E), E);
8053 const auto &TargetSemantics =
Ctx.getFloatSemantics(E->
getType());
8054 if (!this->emitLoadFloat(E))
8056 APFloat F(TargetSemantics, 1);
8057 if (!this->emitFloat(F, E))
8060 if (!this->emitSubf(getFPOptions(E), E))
8062 if (!this->emitStoreFloat(E))
8074 return E->
isGLValue() || this->emitLoadPop(*
T, E);
8078 return this->emitError(E);
8081 return this->
discard(SubExpr);
8086 if (!this->emitInv(E))
8090 return this->emitCast(
PT_Bool, ET, E);
8094 return this->emitError(E);
8096 if (!this->
visit(SubExpr))
8101 return this->emitError(E);
8103 if (!this->
visit(SubExpr))
8119 if (!
Ctx.getLangOpts().CPlusPlus) {
8122 if (
const auto *Deref = dyn_cast<UnaryOperator>(
Sub);
8123 Deref && Deref->getOpcode() == UO_Deref) {
8125 return this->
discard(Deref->getSubExpr());
8126 return this->
visit(Deref->getSubExpr()) && this->emitAddrOf(E);
8131 return this->
discard(SubExpr);
8132 return this->
delegate(SubExpr) && this->emitAddrOf(E);
8135 return this->
discard(SubExpr);
8137 if (!this->
visit(SubExpr))
8144 return this->emitNarrowPtr(E);
8149 return this->emitError(E);
8151 if (!this->
visit(SubExpr))
8165 : this->visitZeroInitializer(*
T, SubExpr->
getType(), SubExpr);
8170 assert(
false &&
"Unhandled opcode");
8176template <
class Emitter>
8182 return this->
discard(SubExpr);
8185 auto prepareResult = [=]() ->
bool {
8190 return this->emitGetPtrLocal(*LocalIndex, E);
8197 unsigned SubExprOffset = ~0u;
8198 auto createTemp = [=, &SubExprOffset]() ->
bool {
8201 if (!this->
visit(SubExpr))
8203 return this->emitSetLocal(
PT_Ptr, SubExprOffset, E);
8207 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8208 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8210 return this->emitArrayElemPop(ElemT, Index, E);
8215 if (!prepareResult())
8219 for (
unsigned I = 0; I != 2; ++I) {
8220 if (!getElem(SubExprOffset, I))
8222 if (!this->emitNeg(ElemT, E))
8224 if (!this->emitInitElem(ElemT, I, E))
8235 if (!this->
visit(SubExpr))
8237 if (!this->emitComplexBoolCast(SubExpr))
8239 if (!this->emitInv(E))
8242 return this->emitCast(
PT_Bool, ET, E);
8246 return this->emitComplexReal(SubExpr);
8249 if (!this->
visit(SubExpr))
8253 if (!this->emitConstUint8(1, E))
8255 return this->emitArrayElemPtrPopUint8(E);
8266 if (!this->emitArrayElem(ElemT, 1, E))
8268 if (!this->emitNeg(ElemT, E))
8270 if (!this->emitInitElem(ElemT, 1, E))
8278 return this->emitInvalid(E);
8284template <
class Emitter>
8290 return this->
discard(SubExpr);
8293 if (UnaryOp == UO_Extension)
8296 if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
8297 UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
8298 return this->emitInvalid(E);
8301 if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
8308 if (!this->emitGetPtrLocal(*LocalIndex, E))
8313 unsigned SubExprOffset =
8315 if (!this->
visit(SubExpr))
8317 if (!this->emitSetLocal(
PT_Ptr, SubExprOffset, E))
8322 auto getElem = [=](
unsigned Offset,
unsigned Index) ->
bool {
8323 if (!this->emitGetLocal(
PT_Ptr, Offset, E))
8325 return this->emitArrayElemPop(ElemT, Index, E);
8330 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8331 if (!getElem(SubExprOffset, I))
8333 if (!this->emitNeg(ElemT, E))
8335 if (!this->emitInitElem(ElemT, I, E))
8350 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8351 if (!getElem(SubExprOffset, I))
8354 if (!this->emitPrimCast(ElemT,
PT_Bool,
Ctx.getASTContext().BoolTy, E))
8356 if (!this->emitInv(E))
8358 if (!this->emitPrimCast(
PT_Bool, ElemT, VecTy->getElementType(), E))
8360 if (!this->emitNeg(ElemT, E))
8362 if (ElemT != ResultVecElemT &&
8363 !this->emitPrimCast(ElemT, ResultVecElemT, ResultVecTy, E))
8365 if (!this->emitInitElem(ResultVecElemT, I, E))
8371 for (
unsigned I = 0; I != VecTy->getNumElements(); ++I) {
8372 if (!getElem(SubExprOffset, I))
8375 if (!this->emitInv(E))
8378 if (!this->emitComp(ElemT, E))
8381 if (!this->emitInitElem(ElemT, I, E))
8386 llvm_unreachable(
"Unsupported unary operators should be handled up front");
8391template <
class Emitter>
8393 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
8396 return this->emitConst(ECD->getInitVal(), E);
8398 if (
const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
8402 return F && this->emitGetFnPtr(F, E);
8404 if (
const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
8405 TPOD = TPOD->getFirstDecl();
8409 return this->emitGetPtrGlobal(*GlobalIndex, E);
8415 return this->emitInitGlobal(*
T, *Index, E);
8418 if (!this->emitGetPtrGlobal(*Index, E))
8422 return this->emitFinishInit(E);
8434 auto maybePopPtr = [&]() ->
bool {
8436 return this->emitPopPtr(E);
8443 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
8447 if (
Ctx.getLangOpts().CPlusPlus && !
Ctx.getLangOpts().CPlusPlus11 &&
8452 if (
auto It = this->Params.find(PVD); It != this->Params.end()) {
8453 if (IsReference || !It->second.IsPtr)
8454 return this->emitGetParam(
classifyPrim(E), It->second.Index, E);
8456 return this->emitGetPtrParam(It->second.Index, E);
8459 if (!
Ctx.getLangOpts().CPlusPlus23 && IsReference && !
Locals.contains(D))
8466 const unsigned Offset = It->second.Offset;
8469 return this->emitGetRefLocal(Offset, E) && maybePopPtr();
8471 return this->emitGetPtrLocal(Offset, E) && maybePopPtr();
8474 if (
auto GlobalIndex =
P.getGlobal(D)) {
8476 if (!
Ctx.getLangOpts().CPlusPlus11)
8477 return this->emitGetGlobal(
classifyPrim(E), *GlobalIndex, E);
8478 if (!
Ctx.getLangOpts().CPlusPlus23)
8479 return this->emitGetGlobalUnchecked(
classifyPrim(E), *GlobalIndex, E);
8481 return this->emitGetRefGlobal(*GlobalIndex, E) && maybePopPtr();
8484 return this->emitGetPtrGlobal(*GlobalIndex, E) && maybePopPtr();
8488 auto revisit = [&](
const VarDecl *VD,
8489 bool IsConstexprUnknown =
true) ->
bool {
8491 IsConstexprUnknown);
8492 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8498 if constexpr (std::is_same_v<Emitter, EvalEmitter>) {
8499 if (!this->emitPopCC(E))
8503 if (VarState.notCreated())
8511 if constexpr (!std::is_same_v<Emitter, EvalEmitter>) {
8513 if (
auto It = this->LambdaCaptures.find(D);
8514 It != this->LambdaCaptures.end()) {
8515 auto [Offset, IsPtr] = It->second;
8518 return this->emitGetThisFieldPtr(Offset, E) && maybePopPtr();
8519 return this->emitGetPtrThisField(Offset, E) && maybePopPtr();
8523 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E);
8524 DRE && DRE->refersToEnclosingVariableOrCapture()) {
8525 if (
const auto *VD = dyn_cast<VarDecl>(D); VD && VD->
isInitCapture())
8529 if (
const auto *BD = dyn_cast<BindingDecl>(D))
8530 return this->
delegate(BD->getBinding());
8536 return this->emitDummyPtr(D, E);
8541 const auto *VD = dyn_cast<VarDecl>(D);
8543 return this->emitError(E);
8546 if (!
Ctx.getLangOpts().CPlusPlus) {
8550 return revisit(VD,
false);
8554 return this->emitDummyPtr(D, E);
8558 const auto typeShouldBeVisited = [&](
QualType T) ->
bool {
8559 if (
T.isConstant(
Ctx.getASTContext()))
8561 return T->isReferenceType();
8565 typeShouldBeVisited(DeclType)) {
8567 Init && !
Init->isValueDependent()) {
8572 (void)
Init->EvaluateAsInitializer(
Ctx.getASTContext(), VD,
Result,
true);
8585 bool IsConstexprUnknown = !DeclType.
isConstant(
Ctx.getASTContext()) &&
8590 return revisit(VD, IsConstexprUnknown);
8591 }
else if (
Ctx.getLangOpts().CPlusPlus23 && IsReference)
8592 return revisit(VD,
true);
8601 return this->emitDummyPtr(
8605template <
class Emitter>
8611template <
class Emitter>
8621 if (!
C->destroyLocals())
8627template <
class Emitter>
8628unsigned Compiler<Emitter>::collectBaseOffset(
const QualType BaseType,
8631 if (
const auto *R = Ty->getPointeeCXXRecordDecl())
8633 return Ty->getAsCXXRecordDecl();
8635 const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType);
8636 const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType);
8638 return Ctx.collectBaseOffset(BaseDecl, DerivedDecl);
8642template <
class Emitter>
8649 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8654 return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
8655 getFPOptions(E), E);
8657 return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
8658 getFPOptions(E), E);
8662 return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
8667 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8669 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8673 return FromT != ToT ? this->emitCast(FromT, ToT, E) :
true;
8677 const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
8678 return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
8685template <
class Emitter>
8688 assert(FromT != ToT);
8691 return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
8693 return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
8695 return this->emitCast(FromT, ToT, E);
8699template <
class Emitter>
8700bool Compiler<Emitter>::emitComplexReal(
const Expr *SubExpr) {
8704 return this->
discard(SubExpr);
8706 if (!this->visit(SubExpr))
8709 if (!this->emitConstUint8(0, SubExpr))
8711 return this->emitArrayElemPtrPopUint8(SubExpr);
8715 return this->emitArrayElemPop(classifyComplexElementType(SubExpr->
getType()),
8719template <
class Emitter>
8720bool Compiler<Emitter>::emitComplexBoolCast(
const Expr *E) {
8721 assert(!DiscardResult);
8725 if (!this->emitArrayElem(ElemT, 0, E))
8728 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8731 if (!this->emitCast(ElemT,
PT_Bool, E))
8736 LabelTy LabelTrue = this->getLabel();
8737 if (!this->jumpTrue(LabelTrue, E))
8740 if (!this->emitArrayElemPop(ElemT, 1, E))
8743 if (!this->emitCastFloatingIntegral(
PT_Bool, getFPOptions(E), E))
8746 if (!this->emitCast(ElemT,
PT_Bool, E))
8750 LabelTy EndLabel = this->getLabel();
8751 this->jump(EndLabel, E);
8753 this->emitLabel(LabelTrue);
8754 if (!this->emitPopPtr(E))
8756 if (!this->emitConstBool(
true, E))
8759 this->fallthrough(EndLabel);
8760 this->emitLabel(EndLabel);
8765template <
class Emitter>
8766bool Compiler<Emitter>::emitComplexComparison(
const Expr *LHS,
const Expr *RHS,
8777 LHSIsComplex =
true;
8778 ElemT = classifyComplexElementType(LHS->
getType());
8779 LHSOffset = allocateLocalPrimitive(LHS,
PT_Ptr,
true);
8780 if (!this->visit(LHS))
8782 if (!this->emitSetLocal(
PT_Ptr, LHSOffset, E))
8785 LHSIsComplex =
false;
8787 LHSOffset = this->allocateLocalPrimitive(LHS, LHST,
true);
8788 if (!this->visit(LHS))
8790 if (!this->emitSetLocal(LHST, LHSOffset, E))
8797 RHSIsComplex =
true;
8798 ElemT = classifyComplexElementType(RHS->
getType());
8799 RHSOffset = allocateLocalPrimitive(RHS,
PT_Ptr,
true);
8800 if (!this->visit(RHS))
8802 if (!this->emitSetLocal(
PT_Ptr, RHSOffset, E))
8805 RHSIsComplex =
false;
8807 RHSOffset = this->allocateLocalPrimitive(RHS, RHST,
true);
8808 if (!this->visit(RHS))
8810 if (!this->emitSetLocal(RHST, RHSOffset, E))
8814 auto getElem = [&](
unsigned LocalOffset,
unsigned Index,
8815 bool IsComplex) ->
bool {
8817 if (!this->emitGetLocal(
PT_Ptr, LocalOffset, E))
8819 return this->emitArrayElemPop(ElemT, Index, E);
8821 return this->emitGetLocal(ElemT, LocalOffset, E);
8824 for (
unsigned I = 0; I != 2; ++I) {
8826 if (!getElem(LHSOffset, I, LHSIsComplex))
8828 if (!getElem(RHSOffset, I, RHSIsComplex))
8831 if (!this->emitEQ(ElemT, E))
8834 if (!this->emitCastBoolUint8(E))
8839 if (!this->emitAddUint8(E))
8841 if (!this->emitConstUint8(2, E))
8845 if (!this->emitEQUint8(E))
8848 if (!this->emitNEUint8(E))
8855 return this->emitCast(
PT_Bool, ResT, E);
8862template <
class Emitter>
8863bool Compiler<Emitter>::emitRecordDestructionPop(
const Record *R,
8866 assert(!
R->hasTrivialDtor());
8869 const Function *DtorFunc = getFunction(
Dtor);
8872 assert(DtorFunc->hasThisPointer());
8873 assert(DtorFunc->getNumParams() == 1);
8874 return this->emitCall(DtorFunc, 0, Loc);
8879template <
class Emitter>
8880bool Compiler<Emitter>::emitDestructionPop(
const Descriptor *Desc,
8892 return this->emitPopPtr(Loc);
8894 for (ssize_t I = N - 1; I >= 1; --I) {
8895 if (!this->emitConstUint64(I, Loc))
8897 if (!this->emitArrayElemPtrUint64(Loc))
8899 if (!this->emitDestructionPop(ElemDesc, Loc))
8903 if (!this->emitConstUint64(0, Loc))
8905 if (!this->emitArrayElemPtrPopUint64(Loc))
8907 return this->emitDestructionPop(ElemDesc, Loc);
8912 return this->emitRecordDestructionPop(Desc->
ElemRecord, Loc);
8917template <
class Emitter>
8918bool Compiler<Emitter>::emitDummyPtr(
DeclOrExpr D,
const Expr *E,
bool CU) {
8919 assert(!DiscardResult &&
"Should've been checked before");
8920 return this->emitGetOpaquePtr(D, CU, E);
8923template <
class Emitter>
8926 return this->emitConstFloat(
Floating(F), Info);
8928 APInt I = F.bitcastToAPInt();
8929 return this->emitConstFloat(
8930 Floating(
const_cast<uint64_t *
>(I.getRawData()),
8931 llvm::APFloatBase::SemanticsToEnum(F.getSemantics())),
8942template <
class Emitter>
8943bool Compiler<Emitter>::emitBuiltinBitCast(
const CastExpr *E) {
8956 if (!this->emitGetPtrLocal(*LocalIndex, E))
8966 if (!this->visit(SubExpr))
8968 }
else if (
OptPrimType FromT = classify(SubExpr)) {
8969 unsigned TempOffset =
8970 allocateLocalPrimitive(SubExpr, *FromT,
true);
8971 if (!this->visit(SubExpr))
8973 if (!this->emitSetLocal(*FromT, TempOffset, E))
8975 if (!this->emitGetPtrLocal(TempOffset, E))
8982 if (!this->emitBitCast(E))
8984 return DiscardResult ? this->emitPopPtr(E) :
true;
8988 const llvm::fltSemantics *TargetSemantics =
nullptr;
8990 TargetSemantics = &Ctx.getFloatSemantics(ToType);
8996 uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
8998 if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->
isStdByteType(),
8999 ResultBitWidth, TargetSemantics,
9004 return this->emitPop(*ToT, E);
9013template <
class Emitter>
9014bool Compiler<Emitter>::emitHLSLAggregateSplat(
PrimType SrcT,
9019 unsigned NumElems = 0;
9022 NumElems = VT->getNumElements();
9023 ElemType = VT->getElementType();
9025 NumElems = MT->getNumElementsFlattened();
9026 ElemType = MT->getElementType();
9029 PrimType ElemT = classifyPrim(ElemType);
9030 for (
unsigned I = 0; I != NumElems; ++I) {
9031 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9033 if (!this->emitPrimCast(SrcT, ElemT, ElemType, E))
9035 if (!this->emitInitElem(ElemT, I, E))
9045 QualType ArrElemType = CAT->getElementType();
9046 unsigned ArrSize = CAT->getZExtSize();
9049 for (
unsigned I = 0; I != ArrSize; ++I) {
9050 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9052 if (!this->emitPrimCast(SrcT, *ElemT, ArrElemType, E))
9054 if (!this->emitInitElem(*ElemT, I, E))
9058 for (
unsigned I = 0; I != ArrSize; ++I) {
9059 if (!this->emitConstUint32(I, E))
9061 if (!this->emitArrayElemPtrUint32(E))
9063 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, ArrElemType, E))
9065 if (!this->emitFinishInitPop(E))
9075 const Record *
R = getRecord(DestType);
9079 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9081 const Record::Base *B =
R->getBase(BS.getType());
9083 if (!this->emitGetPtrBase(B->Offset, E))
9085 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, BS.getType(), E))
9087 if (!this->emitFinishInitPop(E))
9092 for (
const Record::Field &F :
R->fields()) {
9093 if (F.isUnnamedBitField())
9096 QualType FieldType = F.Decl->getType();
9098 if (!this->emitGetLocal(SrcT, SrcOffset, E))
9100 if (!this->emitPrimCast(SrcT, *FieldT, FieldType, E))
9102 if (F.isBitField()) {
9103 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9106 if (!this->emitInitField(*FieldT, F.Offset, E))
9110 if (!this->emitGetPtrField(F.Offset, E))
9112 if (!emitHLSLAggregateSplat(SrcT, SrcOffset, FieldType, E))
9114 if (!this->emitPopPtr(E))
9127template <
class Emitter>
9128unsigned Compiler<Emitter>::countHLSLFlatElements(
QualType Ty) {
9131 return VT->getNumElements();
9133 return MT->getNumElementsFlattened();
9137 return CAT->getZExtSize() * countHLSLFlatElements(CAT->getElementType());
9141 const Record *
R = getRecord(Ty);
9145 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9147 Count += countHLSLFlatElements(BS.getType());
9149 for (
const Record::Field &F :
R->fields()) {
9150 if (F.isUnnamedBitField())
9152 Count += countHLSLFlatElements(F.Decl->getType());
9157 if (canClassify(Ty))
9166template <
class Emitter>
9167bool Compiler<Emitter>::emitHLSLFlattenAggregate(
9168 QualType SrcType,
unsigned SrcOffset,
9173 auto saveToLocal = [&](
PrimType T) ->
bool {
9174 unsigned Offset = allocateLocalPrimitive(E,
T,
true);
9175 if (!this->emitSetLocal(
T, Offset, E))
9177 Elements.push_back({Offset,
T});
9183 unsigned Offset = allocateLocalPrimitive(E,
PT_Ptr,
true);
9184 if (!this->emitSetLocal(
PT_Ptr, Offset, E))
9185 return std::nullopt;
9190 unsigned NumElems = 0;
9193 NumElems = VT->getNumElements();
9194 ElemType = VT->getElementType();
9196 NumElems = MT->getNumElementsFlattened();
9197 ElemType = MT->getElementType();
9200 PrimType ElemT = classifyPrim(ElemType);
9201 for (
unsigned I = 0; I != NumElems && Elements.size() < MaxElements; ++I) {
9202 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9204 if (!this->emitArrayElemPop(ElemT, I, E))
9206 if (!saveToLocal(ElemT))
9216 QualType ArrElemType = CAT->getElementType();
9217 unsigned ArrSize = CAT->getZExtSize();
9220 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9221 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9223 if (!this->emitArrayElemPop(*ElemT, I, E))
9225 if (!saveToLocal(*ElemT))
9229 for (
unsigned I = 0; I != ArrSize && Elements.size() < MaxElements; ++I) {
9230 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9232 if (!this->emitConstUint32(I, E))
9234 if (!this->emitArrayElemPtrPopUint32(E))
9239 if (!emitHLSLFlattenAggregate(ArrElemType, *ElemPtrOffset, Elements,
9250 const Record *
R = getRecord(SrcType);
9254 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9256 if (Elements.size() >= MaxElements)
9258 const Record::Base *B =
R->getBase(BS.getType());
9260 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9262 if (!this->emitGetPtrBasePop(B->Offset,
false, E))
9267 if (!emitHLSLFlattenAggregate(BS.getType(), *BasePtrOffset, Elements,
9273 for (
const Record::Field &F :
R->fields()) {
9274 if (Elements.size() >= MaxElements)
9276 if (F.isUnnamedBitField())
9279 QualType FieldType = F.Decl->getType();
9280 if (!this->emitGetLocal(
PT_Ptr, SrcOffset, E))
9282 if (!this->emitGetPtrFieldPop(F.Offset, E))
9286 if (!this->emitLoadPop(*FieldT, E))
9288 if (!saveToLocal(*FieldT))
9292 if (!FieldPtrOffset)
9294 if (!emitHLSLFlattenAggregate(FieldType, *FieldPtrOffset, Elements,
9310template <
class Emitter>
9311bool Compiler<Emitter>::emitHLSLConstructAggregate(
9317 const auto &Src = Elements[ElemIdx++];
9318 if (!this->emitGetLocal(Src.Type, Src.LocalOffset, E))
9320 return this->emitPrimCast(Src.Type, DestT, DestQT, E);
9324 unsigned NumElems = 0;
9327 NumElems = VT->getNumElements();
9328 ElemType = VT->getElementType();
9330 NumElems = MT->getNumElementsFlattened();
9331 ElemType = MT->getElementType();
9334 PrimType DestElemT = classifyPrim(ElemType);
9335 for (
unsigned I = 0; I != NumElems; ++I) {
9336 if (!loadAndCast(DestElemT, ElemType))
9338 if (!this->emitInitElem(DestElemT, I, E))
9348 QualType ArrElemType = CAT->getElementType();
9349 unsigned ArrSize = CAT->getZExtSize();
9352 for (
unsigned I = 0; I != ArrSize; ++I) {
9353 if (!loadAndCast(*ElemT, ArrElemType))
9355 if (!this->emitInitElem(*ElemT, I, E))
9359 for (
unsigned I = 0; I != ArrSize; ++I) {
9360 if (!this->emitConstUint32(I, E))
9362 if (!this->emitArrayElemPtrUint32(E))
9364 if (!emitHLSLConstructAggregate(ArrElemType, Elements, ElemIdx, E))
9366 if (!this->emitFinishInitPop(E))
9376 const Record *
R = getRecord(DestType);
9380 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
R->getDecl())) {
9382 const Record::Base *B =
R->getBase(BS.getType());
9384 if (!this->emitGetPtrBase(B->Offset, E))
9386 if (!emitHLSLConstructAggregate(BS.getType(), Elements, ElemIdx, E))
9388 if (!this->emitFinishInitPop(E))
9393 for (
const Record::Field &F :
R->fields()) {
9394 if (F.isUnnamedBitField())
9397 QualType FieldType = F.Decl->getType();
9399 if (!loadAndCast(*FieldT, FieldType))
9401 if (F.isBitField()) {
9402 if (!this->emitInitBitField(*FieldT, F.Offset, F.bitWidth(), E))
9405 if (!this->emitInitField(*FieldT, F.Offset, E))
9409 if (!this->emitGetPtrField(F.Offset, E))
9411 if (!emitHLSLConstructAggregate(FieldType, Elements, ElemIdx, E))
9413 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 bool isTrivialMemoryOperation(const CXXMethodDecl *MD)
static const Expr * stripCheckedDerivedToBaseCasts(const Expr *E)
static bool hasTrivialDefaultCtorParent(const FieldDecl *FD)
static bool initNeedsOverridenLoc(const CXXCtorInitializer *Init)
const Expr * ignorePointerCastsAndParens(const Expr *E)
A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. This ignores some c...
bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD)
Determine whether a type would actually be read by an lvalue-to-rvalue conversion.
unsigned ConvertBuiltinIDToX86BuiltinID(const ASTContext &Ctx, unsigned BuiltinOp)
Convert a builtin ID to the canonical x86 builtin ID the constant evaluators dispatch on in their x86...
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
APValue & getStructVirtualBase(unsigned i)
bool isMemberPointerToDerivedMember() const
unsigned getArrayInitializedElts() const
unsigned getStructNumBases() const
unsigned getStructNumVirtualBases() const
bool hasLValuePath() 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 isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
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]).
Represents the code generated for an expanded expansion statement.
ArrayRef< Stmt * > getInstantiations() const
ArrayRef< Stmt * > getPreambleStmts() const
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
This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits 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.
const ValueInfo * getValueInfo(ComparisonCategoryResult ValueKind) const
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, llvm::FoldingSetInsertToken &InsertToken)
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.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
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...
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
bool isStoredAsComparisonResult() 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.
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
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.
ArrayIndexScope(Compiler< Emitter > *Ctx, uint64_t Index)
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
Compilation context for expressions.
llvm::SmallVector< InitLink > InitStack
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool 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 visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
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)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
bool VisitBlockExpr(const BlockExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
const VarDecl * InitializingDecl
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)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool registerRedecl(const VarDecl *VD, const APValue &V)
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)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
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)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
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 VarDecl *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.
InitLinkScope(Compiler< Emitter > *Ctx, InitLink &&Link)
Compiler< Emitter > * Ctx
InitStackScope(Compiler< Emitter > *Ctx, bool Active)
When generating code for e.g.
LocOverrideScope(Compiler< Emitter > *Ctx, SourceInfo NewValue, bool Enabled=true)
Generic scope for local variables.
UnsignedOrNone Idx
Index of the scope in the chain.
~LocalScope() override
Emit a Destroy op for this scope.
bool destroyLocals(const Expr *E=nullptr) override
Explicit destruction of local variables.
bool emitDestructors(const Expr *E=nullptr) override
void removeIfStoredOpaqueValue(const Scope::Local &Local)
void addLocal(Scope::Local Local) override
void removeStoredOpaqueValues()
void forceInit() override
Force-initialize this scope.
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 * getBaseOrNull(const RecordDecl *RD) const
bool hasTrivialDtor() const
Returns true for anonymous unions and records with no destructor or for those with a trivial destruct...
const Base * findVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Describes the statement/declaration an opcode was generated from.
const Expr * asExpr() const
SourceLocScope(Compiler< Emitter > *Ctx, const Expr *DefaultExpr)
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.
void addForScopeKind(const Scope::Local &Local, ScopeKind Kind)
Like addExtended, but adds to the nearest scope of the given kind.
bool LocalsAlwaysEnabled
Whether locals added to this scope are enabled by default.
Compiler< Emitter > * Ctx
Compiler instance.
virtual bool emitDestructors(const Expr *E=nullptr)
VariableScope(Compiler< Emitter > *Ctx, ScopeKind Kind=ScopeKind::Block)
virtual bool destroyLocals(const Expr *E=nullptr)
virtual void addLocal(Scope::Local Local)
VariableScope * Parent
Link to the parent scope.
ScopeKind getKind() const
VariableScope * getParent() const
bool Sub(InterpState &S, CodePtr OpPC)
bool LT(InterpState &S, CodePtr OpPC)
static llvm::RoundingMode getRoundingMode(FPOptions FPO)
constexpr bool isSignedType(PrimType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
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)
constexpr bool isIntegerOrBoolType(PrimType T)
bool InitScope(InterpState &S, uint32_t I)
static void discard(InterpStack &Stk, PrimType T)
static bool isSideEffectFree(const Expr *E)
Check if E has side-effects.
bool LE(InterpState &S, CodePtr OpPC)
PrimType
Enumeration of the primitive types of the VM.
static std::optional< bool > getBoolValue(const Expr *E)
static bool Activate(InterpState &S)
static bool exceedsArraySizeLimit(const LangOptions &LangOpts, uint64_t NumElems)
Whether the CheckArraySize op rejects an array with NumElems elements.
bool Init(InterpState &S, CodePtr OpPC)
bool DefaultInit(InterpState &S, CodePtr OpPC, const CXXConstructorDecl *Ctor)
bool Mul(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
bool Add(InterpState &S, CodePtr OpPC)
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, ArrayRef< const Expr * > Args)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
bool hasSpecificAttr(const Container &container)
@ Success
Annotation was successful.
@ Link
'link' clause, allowed on 'declare' construct.
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ 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
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...
EvalResult is a struct with detailed info about an evaluated expression.
const ValueDecl * asValueDecl() const
const Expr * asExpr() const
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.
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 Base(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()