32#include "llvm/IR/DataLayout.h"
33#include "llvm/IR/GlobalValue.h"
34#include "llvm/IR/Instructions.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/Value.h"
37#include "llvm/Support/ScopedPrinter.h"
42using namespace CodeGen;
47 llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
54 bool UseARMMethodPtrABI;
55 bool UseARMGuardVarABI;
56 bool Use32BitVTableOffsetABI;
64 bool UseARMMethodPtrABI =
false,
65 bool UseARMGuardVarABI =
false) :
66 CGCXXABI(CGM), UseARMMethodPtrABI(UseARMMethodPtrABI),
67 UseARMGuardVarABI(UseARMGuardVarABI),
68 Use32BitVTableOffsetABI(
false) { }
82 if (isa<CXXDestructorDecl>(GD.
getDecl())) {
92 llvm_unreachable(
"emitting dtor comdat as function?");
94 llvm_unreachable(
"bad dtor kind");
96 if (isa<CXXConstructorDecl>(GD.
getDecl())) {
106 llvm_unreachable(
"closure ctors in Itanium ABI?");
109 llvm_unreachable(
"emitting ctor comdat as function?");
111 llvm_unreachable(
"bad dtor kind");
126 llvm::Value *&ThisPtrForCall,
127 llvm::Value *MemFnPtr,
138 llvm::Value *Src)
override;
140 llvm::Constant *Src)
override;
152 llvm::Value *L, llvm::Value *R,
154 bool Inequality)
override;
171 llvm::Value *Exn)
override;
173 void EmitFundamentalRTTIDescriptors(
const CXXRecordDecl *RD);
177 QualType CatchHandlerType)
override {
185 llvm::Type *StdTypeInfoPtrTy)
override;
194 bool hasUniqueVTablePointer(
QualType RecordTy) {
199 if (!CGM.getCodeGenOpts().AssumeUniqueVTables ||
200 getContext().getLangOpts().AppleKext)
205 if (!CGM.shouldEmitRTTI())
210 if (!llvm::GlobalValue::isWeakForLinker(CGM.getVTableLinkage(RD)))
219 llvm::GlobalValue::DefaultVisibility)
226 return hasUniqueVTablePointer(DestRecordTy);
232 llvm::BasicBlock *CastEnd)
override;
237 llvm::BasicBlock *CastSuccess,
238 llvm::BasicBlock *CastFail)
override;
252 AddedStructorArgCounts
292 CodeGenFunction::VPtr Vptr)
override;
306 llvm::Value *getVTableAddressPointInStructorWithVTT(
324 DeleteOrMemberCallExpr E)
override;
329 bool canSpeculativelyEmitVTableAsBaseClass(
const CXXRecordDecl *RD)
const;
335 if (ForVTable && !Thunk->hasLocalLinkage())
336 Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
337 CGM.setGVProperties(Thunk, GD);
350 assert(!Args.empty() &&
"expected the arglist to not be empty!");
351 return Args.size() - 1;
356 {
return "__cxa_deleted_virtual"; }
361 llvm::Value *NumElements,
369 llvm::GlobalVariable *DeclPtr,
370 bool PerformInit)
override;
372 llvm::FunctionCallee dtor,
373 llvm::Constant *addr)
override;
375 llvm::Function *getOrCreateThreadLocalWrapper(
const VarDecl *VD,
397 virtual bool shouldRTTIBeUnique()
const {
return true; }
401 enum RTTIUniquenessKind {
419 classifyRTTIUniqueness(
QualType CanTy,
420 llvm::GlobalValue::LinkageTypes
Linkage)
const;
421 friend class ItaniumRTTIBuilder;
425 std::pair<llvm::Value *, const CXXRecordDecl *>
430 bool hasAnyUnusedVirtualInlineFunction(
const CXXRecordDecl *RD)
const {
431 const auto &VtableLayout =
432 CGM.getItaniumVTableContext().getVTableLayout(RD);
434 for (
const auto &VtableComponent : VtableLayout.vtable_components()) {
436 if (!VtableComponent.isUsedFunctionPointerKind())
439 const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
443 StringRef Name = CGM.getMangledName(VtableComponent.getGlobalDecl());
444 auto *Entry = CGM.GetGlobalValue(Name);
450 if (!Entry || Entry->isDeclaration())
457 const auto &VtableLayout =
458 CGM.getItaniumVTableContext().getVTableLayout(RD);
460 for (
const auto &VtableComponent : VtableLayout.vtable_components()) {
461 if (VtableComponent.isRTTIKind()) {
462 const CXXRecordDecl *RTTIDecl = VtableComponent.getRTTIDecl();
463 if (RTTIDecl->
getVisibility() == Visibility::HiddenVisibility)
465 }
else if (VtableComponent.isUsedFunctionPointerKind()) {
466 const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
467 if (Method->
getVisibility() == Visibility::HiddenVisibility &&
476class ARMCXXABI :
public ItaniumCXXABI {
479 ItaniumCXXABI(CGM,
true,
482 bool constructorsAndDestructorsReturnThis()
const override {
return true; }
490 llvm::Value *NumElements,
497class AppleARM64CXXABI :
public ARMCXXABI {
500 Use32BitVTableOffsetABI =
true;
504 bool shouldRTTIBeUnique()
const override {
return false; }
507class FuchsiaCXXABI final :
public ItaniumCXXABI {
510 : ItaniumCXXABI(CGM) {}
513 bool constructorsAndDestructorsReturnThis()
const override {
return true; }
516class WebAssemblyCXXABI final :
public ItaniumCXXABI {
519 : ItaniumCXXABI(CGM,
true,
524 llvm::Value *Exn)
override;
527 bool constructorsAndDestructorsReturnThis()
const override {
return true; }
528 bool canCallMismatchedFunctionType()
const override {
return false; }
531class XLCXXABI final :
public ItaniumCXXABI {
534 : ItaniumCXXABI(CGM) {}
537 llvm::FunctionCallee dtor,
538 llvm::Constant *addr)
override;
540 bool useSinitAndSterm()
const override {
return true; }
543 void emitCXXStermFinalizer(
const VarDecl &D, llvm::Function *dtorStub,
544 llvm::Constant *addr);
552 case TargetCXXABI::GenericARM:
553 case TargetCXXABI::iOS:
554 case TargetCXXABI::WatchOS:
555 return new ARMCXXABI(CGM);
557 case TargetCXXABI::AppleARM64:
558 return new AppleARM64CXXABI(CGM);
560 case TargetCXXABI::Fuchsia:
561 return new FuchsiaCXXABI(CGM);
566 case TargetCXXABI::GenericAArch64:
567 return new ItaniumCXXABI(CGM,
true,
570 case TargetCXXABI::GenericMIPS:
571 return new ItaniumCXXABI(CGM,
true);
573 case TargetCXXABI::WebAssembly:
574 return new WebAssemblyCXXABI(CGM);
576 case TargetCXXABI::XL:
577 return new XLCXXABI(CGM);
579 case TargetCXXABI::GenericItanium:
581 == llvm::Triple::le32) {
585 return new ItaniumCXXABI(CGM,
true);
587 return new ItaniumCXXABI(CGM);
589 case TargetCXXABI::Microsoft:
590 llvm_unreachable(
"Microsoft ABI is not Itanium-based");
592 llvm_unreachable(
"bad ABI kind");
598 return CGM.PtrDiffTy;
599 return llvm::StructType::get(CGM.PtrDiffTy, CGM.PtrDiffTy);
622CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
624 llvm::Value *&ThisPtrForCall,
633 llvm::Constant *ptrdiff_1 = llvm::ConstantInt::get(CGM.PtrDiffTy, 1);
640 llvm::Value *RawAdj = Builder.CreateExtractValue(MemFnPtr, 1,
"memptr.adj");
643 llvm::Value *Adj = RawAdj;
644 if (UseARMMethodPtrABI)
645 Adj = Builder.CreateAShr(Adj, ptrdiff_1,
"memptr.adj.shifted");
650 This = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), This, Adj);
651 ThisPtrForCall = This;
654 llvm::Value *FnAsInt = Builder.CreateExtractValue(MemFnPtr, 0,
"memptr.ptr");
658 llvm::Value *IsVirtual;
659 if (UseARMMethodPtrABI)
660 IsVirtual = Builder.CreateAnd(RawAdj, ptrdiff_1);
662 IsVirtual = Builder.CreateAnd(FnAsInt, ptrdiff_1);
663 IsVirtual = Builder.CreateIsNotNull(IsVirtual,
"memptr.isvirtual");
664 Builder.CreateCondBr(IsVirtual, FnVirtual, FnNonVirtual);
682 llvm::Value *VTableOffset = FnAsInt;
683 if (!UseARMMethodPtrABI)
684 VTableOffset = Builder.CreateSub(VTableOffset, ptrdiff_1);
685 if (Use32BitVTableOffsetABI) {
686 VTableOffset = Builder.CreateTrunc(VTableOffset, CGF.
Int32Ty);
687 VTableOffset = Builder.CreateZExt(VTableOffset, CGM.PtrDiffTy);
692 llvm::Constant *CheckSourceLocation;
693 llvm::Constant *CheckTypeDesc;
694 bool ShouldEmitCFICheck = CGF.
SanOpts.
has(SanitizerKind::CFIMFCall) &&
695 CGM.HasHiddenLTOVisibility(RD);
696 bool ShouldEmitVFEInfo = CGM.getCodeGenOpts().VirtualFunctionElimination &&
697 CGM.HasHiddenLTOVisibility(RD);
698 bool ShouldEmitWPDInfo =
699 CGM.getCodeGenOpts().WholeProgramVTables &&
701 !CGM.AlwaysHasLTOVisibilityPublic(RD);
702 llvm::Value *VirtualFn =
nullptr;
705 CodeGenFunction::SanitizerScope SanScope(&CGF);
706 llvm::Value *TypeId =
nullptr;
707 llvm::Value *CheckResult =
nullptr;
709 if (ShouldEmitCFICheck || ShouldEmitVFEInfo || ShouldEmitWPDInfo) {
713 CGM.CreateMetadataIdentifierForVirtualMemPtrType(
QualType(MPT, 0));
717 if (ShouldEmitVFEInfo) {
718 llvm::Value *VFPAddr =
719 Builder.CreateGEP(CGF.
Int8Ty, VTable, VTableOffset);
726 llvm::Value *CheckedLoad = Builder.CreateCall(
727 CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
728 {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId});
729 CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
730 VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0);
734 if (ShouldEmitCFICheck || ShouldEmitWPDInfo) {
735 llvm::Value *VFPAddr =
736 Builder.CreateGEP(CGF.
Int8Ty, VTable, VTableOffset);
737 llvm::Intrinsic::ID IID = CGM.HasHiddenLTOVisibility(RD)
738 ? llvm::Intrinsic::type_test
739 : llvm::Intrinsic::public_type_test;
742 Builder.CreateCall(CGM.getIntrinsic(IID), {VFPAddr, TypeId});
745 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
746 VirtualFn = CGF.
Builder.CreateCall(
747 CGM.getIntrinsic(llvm::Intrinsic::load_relative,
748 {VTableOffset->getType()}),
749 {VTable, VTableOffset});
751 llvm::Value *VFPAddr =
758 assert(VirtualFn &&
"Virtual fuction pointer not created!");
759 assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || !ShouldEmitWPDInfo ||
761 "Check result required but not created!");
763 if (ShouldEmitCFICheck) {
767 llvm::Constant *StaticData[] = {
768 llvm::ConstantInt::get(CGF.
Int8Ty, CodeGenFunction::CFITCK_VMFCall),
773 if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) {
774 CGF.
EmitTrapCheck(CheckResult, SanitizerHandler::CFICheckFail);
776 llvm::Value *AllVtables = llvm::MetadataAsValue::get(
777 CGM.getLLVMContext(),
778 llvm::MDString::get(CGM.getLLVMContext(),
"all-vtables"));
779 llvm::Value *ValidVtable = Builder.CreateCall(
780 CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables});
781 CGF.
EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIMFCall),
782 SanitizerHandler::CFICheckFail, StaticData,
783 {VTable, ValidVtable});
786 FnVirtual = Builder.GetInsertBlock();
795 llvm::Value *NonVirtualFn =
796 Builder.CreateIntToPtr(FnAsInt, CGF.
UnqualPtrTy,
"memptr.nonvirtualfn");
799 if (ShouldEmitCFICheck) {
802 CodeGenFunction::SanitizerScope SanScope(&CGF);
804 llvm::Constant *StaticData[] = {
805 llvm::ConstantInt::get(CGF.
Int8Ty, CodeGenFunction::CFITCK_NVMFCall),
810 llvm::Value *Bit = Builder.getFalse();
812 llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(
813 getContext().getMemberPointerType(
816 llvm::Value *TypeId =
819 llvm::Value *TypeTest =
820 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::type_test),
821 {NonVirtualFn, TypeId});
822 Bit = Builder.CreateOr(Bit, TypeTest);
825 CGF.
EmitCheck(std::make_pair(Bit, SanitizerKind::CFIMFCall),
826 SanitizerHandler::CFICheckFail, StaticData,
827 {NonVirtualFn, llvm::UndefValue::get(CGF.
IntPtrTy)});
829 FnNonVirtual = Builder.GetInsertBlock();
835 llvm::PHINode *CalleePtr = Builder.CreatePHI(CGF.
UnqualPtrTy, 2);
836 CalleePtr->addIncoming(VirtualFn, FnVirtual);
837 CalleePtr->addIncoming(NonVirtualFn, FnNonVirtual);
845llvm::Value *ItaniumCXXABI::EmitMemberDataPointerAddress(
848 assert(MemPtr->getType() == CGM.PtrDiffTy);
853 return Builder.CreateInBoundsGEP(CGF.
Int8Ty,
Base.getPointer(), MemPtr,
884 assert(E->
getCastKind() == CK_DerivedToBaseMemberPointer ||
885 E->
getCastKind() == CK_BaseToDerivedMemberPointer ||
889 if (E->
getCastKind() == CK_ReinterpretMemberPointer)
return src;
892 if (isa<llvm::Constant>(src))
893 return EmitMemberPointerConversion(E, cast<llvm::Constant>(src));
895 llvm::Constant *adj = getMemberPointerAdjustment(E);
896 if (!adj)
return src;
899 bool isDerivedToBase = (E->
getCastKind() == CK_DerivedToBaseMemberPointer);
909 dst = Builder.CreateNSWSub(src, adj,
"adj");
911 dst = Builder.CreateNSWAdd(src, adj,
"adj");
914 llvm::Value *null = llvm::Constant::getAllOnesValue(src->getType());
915 llvm::Value *isNull = Builder.CreateICmpEQ(src, null,
"memptr.isnull");
916 return Builder.CreateSelect(isNull, src, dst);
920 if (UseARMMethodPtrABI) {
921 uint64_t offset = cast<llvm::ConstantInt>(adj)->getZExtValue();
923 adj = llvm::ConstantInt::get(adj->getType(), offset);
926 llvm::Value *srcAdj = Builder.CreateExtractValue(src, 1,
"src.adj");
929 dstAdj = Builder.CreateNSWSub(srcAdj, adj,
"adj");
931 dstAdj = Builder.CreateNSWAdd(srcAdj, adj,
"adj");
933 return Builder.CreateInsertValue(src, dstAdj, 1);
937ItaniumCXXABI::EmitMemberPointerConversion(
const CastExpr *E,
938 llvm::Constant *src) {
939 assert(E->
getCastKind() == CK_DerivedToBaseMemberPointer ||
940 E->
getCastKind() == CK_BaseToDerivedMemberPointer ||
944 if (E->
getCastKind() == CK_ReinterpretMemberPointer)
return src;
947 llvm::Constant *adj = getMemberPointerAdjustment(E);
948 if (!adj)
return src;
950 bool isDerivedToBase = (E->
getCastKind() == CK_DerivedToBaseMemberPointer);
959 if (src->isAllOnesValue())
return src;
962 return llvm::ConstantExpr::getNSWSub(src, adj);
964 return llvm::ConstantExpr::getNSWAdd(src, adj);
968 if (UseARMMethodPtrABI) {
969 uint64_t offset = cast<llvm::ConstantInt>(adj)->getZExtValue();
971 adj = llvm::ConstantInt::get(adj->getType(), offset);
974 llvm::Constant *srcAdj = src->getAggregateElement(1);
975 llvm::Constant *dstAdj;
977 dstAdj = llvm::ConstantExpr::getNSWSub(srcAdj, adj);
979 dstAdj = llvm::ConstantExpr::getNSWAdd(srcAdj, adj);
981 llvm::Constant *res = ConstantFoldInsertValueInstruction(src, dstAdj, 1);
982 assert(res !=
nullptr &&
"Folding must succeed");
991 return llvm::ConstantInt::get(CGM.PtrDiffTy, -1ULL,
true);
993 llvm::Constant *
Zero = llvm::ConstantInt::get(CGM.PtrDiffTy, 0);
994 llvm::Constant *Values[2] = {
Zero,
Zero };
995 return llvm::ConstantStruct::getAnon(Values);
1004 return llvm::ConstantInt::get(CGM.PtrDiffTy, offset.
getQuantity());
1008ItaniumCXXABI::EmitMemberFunctionPointer(
const CXXMethodDecl *MD) {
1012llvm::Constant *ItaniumCXXABI::BuildMemberPointer(
const CXXMethodDecl *MD,
1014 assert(MD->
isInstance() &&
"Member function must not be static!");
1019 llvm::Constant *MemPtr[2];
1021 uint64_t Index = CGM.getItaniumVTableContext().getMethodVTableIndex(MD);
1023 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
1025 VTableOffset = Index * 4;
1030 VTableOffset = Index * PointerWidth.
getQuantity();
1033 if (UseARMMethodPtrABI) {
1040 MemPtr[0] = llvm::ConstantInt::get(CGM.PtrDiffTy, VTableOffset);
1041 MemPtr[1] = llvm::ConstantInt::get(CGM.PtrDiffTy,
1048 MemPtr[0] = llvm::ConstantInt::get(CGM.PtrDiffTy, VTableOffset + 1);
1049 MemPtr[1] = llvm::ConstantInt::get(CGM.PtrDiffTy,
1056 if (Types.isFuncTypeConvertible(FPT)) {
1058 Ty = Types.GetFunctionType(Types.arrangeCXXMethodDeclaration(MD));
1064 llvm::Constant *addr = CGM.GetAddrOfFunction(MD, Ty);
1066 MemPtr[0] = llvm::ConstantExpr::getPtrToInt(addr, CGM.PtrDiffTy);
1067 MemPtr[1] = llvm::ConstantInt::get(CGM.PtrDiffTy,
1068 (UseARMMethodPtrABI ? 2 : 1) *
1072 return llvm::ConstantStruct::getAnon(MemPtr);
1075llvm::Constant *ItaniumCXXABI::EmitMemberPointer(
const APValue &MP,
1080 return EmitNullMemberPointer(MPT);
1088 getContext().toCharUnitsFromBits(getContext().
getFieldOffset(MPD));
1104 llvm::ICmpInst::Predicate
Eq;
1105 llvm::Instruction::BinaryOps
And,
Or;
1107 Eq = llvm::ICmpInst::ICMP_NE;
1108 And = llvm::Instruction::Or;
1109 Or = llvm::Instruction::And;
1111 Eq = llvm::ICmpInst::ICMP_EQ;
1112 And = llvm::Instruction::And;
1113 Or = llvm::Instruction::Or;
1119 return Builder.CreateICmp(
Eq, L, R);
1131 llvm::Value *LPtr = Builder.CreateExtractValue(L, 0,
"lhs.memptr.ptr");
1132 llvm::Value *RPtr = Builder.CreateExtractValue(R, 0,
"rhs.memptr.ptr");
1136 llvm::Value *PtrEq = Builder.CreateICmp(
Eq, LPtr, RPtr,
"cmp.ptr");
1141 llvm::Value *
Zero = llvm::Constant::getNullValue(LPtr->getType());
1142 llvm::Value *EqZero = Builder.CreateICmp(
Eq, LPtr, Zero,
"cmp.ptr.null");
1146 llvm::Value *LAdj = Builder.CreateExtractValue(L, 1,
"lhs.memptr.adj");
1147 llvm::Value *RAdj = Builder.CreateExtractValue(R, 1,
"rhs.memptr.adj");
1148 llvm::Value *AdjEq = Builder.CreateICmp(
Eq, LAdj, RAdj,
"cmp.adj");
1152 if (UseARMMethodPtrABI) {
1153 llvm::Value *One = llvm::ConstantInt::get(LPtr->getType(), 1);
1156 llvm::Value *OrAdj = Builder.CreateOr(LAdj, RAdj,
"or.adj");
1157 llvm::Value *OrAdjAnd1 = Builder.CreateAnd(OrAdj, One);
1158 llvm::Value *OrAdjAnd1EqZero = Builder.CreateICmp(
Eq, OrAdjAnd1, Zero,
1160 EqZero = Builder.CreateBinOp(
And, EqZero, OrAdjAnd1EqZero);
1164 llvm::Value *Result = Builder.CreateBinOp(
Or, EqZero, AdjEq);
1165 Result = Builder.CreateBinOp(
And, PtrEq, Result,
1166 Inequality ?
"memptr.ne" :
"memptr.eq");
1172 llvm::Value *MemPtr,
1178 assert(MemPtr->getType() == CGM.PtrDiffTy);
1179 llvm::Value *NegativeOne =
1180 llvm::Constant::getAllOnesValue(MemPtr->getType());
1181 return Builder.CreateICmpNE(MemPtr, NegativeOne,
"memptr.tobool");
1185 llvm::Value *Ptr = Builder.CreateExtractValue(MemPtr, 0,
"memptr.ptr");
1187 llvm::Constant *
Zero = llvm::ConstantInt::get(Ptr->getType(), 0);
1188 llvm::Value *Result = Builder.CreateICmpNE(Ptr, Zero,
"memptr.tobool");
1192 if (UseARMMethodPtrABI) {
1193 llvm::Constant *One = llvm::ConstantInt::get(Ptr->getType(), 1);
1194 llvm::Value *Adj = Builder.CreateExtractValue(MemPtr, 1,
"memptr.adj");
1195 llvm::Value *VirtualBit = Builder.CreateAnd(Adj, One,
"memptr.virtualbit");
1196 llvm::Value *IsVirtual = Builder.CreateICmpNE(VirtualBit, Zero,
1197 "memptr.isvirtual");
1198 Result = Builder.CreateOr(Result, IsVirtual);
1204bool ItaniumCXXABI::classifyReturnType(
CGFunctionInfo &FI)
const {
1211 auto Align = CGM.getContext().getTypeAlignInChars(FI.
getReturnType());
1232 if (UseGlobalDelete) {
1242 llvm::Value *OffsetPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
1243 CGF.
IntPtrTy, VTable, -2,
"complete-offset.ptr");
1250 CGF.
Builder.CreateInBoundsGEP(CGF.
Int8Ty, CompletePtr, Offset);
1261 EmitVirtualDestructorCall(CGF, Dtor, DtorType, Ptr, DE);
1263 if (UseGlobalDelete)
1267void ItaniumCXXABI::emitRethrow(
CodeGenFunction &CGF,
bool isNoReturn) {
1270 llvm::FunctionType *FTy =
1271 llvm::FunctionType::get(CGM.VoidTy,
false);
1273 llvm::FunctionCallee Fn = CGM.CreateRuntimeFunction(FTy,
"__cxa_rethrow");
1284 llvm::FunctionType *FTy =
1295 llvm::FunctionType *FTy =
1296 llvm::FunctionType::get(CGM.
VoidTy, Args,
false);
1304 llvm::Type *SizeTy = CGF.
ConvertType(getContext().getSizeType());
1305 uint64_t TypeSize = getContext().getTypeSizeInChars(ThrowType).getQuantity();
1309 AllocExceptionFn, llvm::ConstantInt::get(SizeTy, TypeSize),
"exception");
1316 llvm::Constant *
TypeInfo = CGM.GetAddrOfRTTIDescriptor(ThrowType,
1321 llvm::Constant *Dtor =
nullptr;
1324 if (!
Record->hasTrivialDestructor()) {
1329 if (!Dtor) Dtor = llvm::Constant::getNullValue(CGM.Int8PtrTy);
1331 llvm::Value *args[] = { ExceptionPtr,
TypeInfo, Dtor };
1343 llvm::Type *PtrDiffTy =
1346 llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
1348 llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args,
false);
1352 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1353 FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
1354 FuncAttrs.addMemoryAttr(llvm::MemoryEffects::readOnly());
1355 llvm::AttributeList Attrs = llvm::AttributeList::get(
1356 CGF.
getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);
1363 llvm::FunctionType *FTy = llvm::FunctionType::get(CGF.
VoidTy,
false);
1380 unsigned NumPublicPaths = 0;
1393 if (PathElement.Base->isVirtual())
1396 if (NumPublicPaths > 1)
1402 PathElement.Base->getType()->getAsCXXRecordDecl());
1407 if (NumPublicPaths == 0)
1411 if (NumPublicPaths > 1)
1421 llvm::FunctionType *FTy = llvm::FunctionType::get(CGF.
VoidTy,
false);
1426bool ItaniumCXXABI::shouldTypeidBeNullChecked(
bool IsDeref,
1434 Call->setDoesNotReturn();
1435 CGF.
Builder.CreateUnreachable();
1441 llvm::Type *StdTypeInfoPtrTy) {
1447 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
1450 CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
1451 {Value, llvm::ConstantInt::get(CGM.Int32Ty, -4)});
1455 CGF.
Builder.CreateConstInBoundsGEP1_64(StdTypeInfoPtrTy,
Value, -1ULL);
1461bool ItaniumCXXABI::shouldDynamicCastCallBeNullChecked(
bool SrcIsPtr,
1466llvm::Value *ItaniumCXXABI::emitDynamicCastCall(
1469 llvm::Type *PtrDiffLTy =
1472 llvm::Value *SrcRTTI =
1474 llvm::Value *DestRTTI =
1480 llvm::Value *OffsetHint = llvm::ConstantInt::get(
1485 llvm::Value *Args[] = {ThisAddr.
getPointer(), SrcRTTI, DestRTTI, OffsetHint};
1486 llvm::Value *
Value =
1492 llvm::BasicBlock *BadCastBlock =
1499 EmitBadCastCall(CGF);
1505llvm::Value *ItaniumCXXABI::emitExactDynamicCast(
1508 llvm::BasicBlock *CastFail) {
1520 std::optional<CharUnits> Offset;
1530 PathElement.Base->getType()->getAsCXXRecordDecl();
1531 if (PathElement.Base->isVirtual()) {
1544 Offset = PathOffset;
1545 else if (Offset != PathOffset) {
1550 ThisAddr =
Address(emitDynamicCastToVoid(CGF, ThisAddr, SrcRecordTy),
1561 return llvm::PoisonValue::get(CGF.
VoidPtrTy);
1570 CGM.DecorateInstructionWithTBAA(
1571 VPtr, CGM.getTBAAVTablePtrAccessInfo(CGF.
VoidPtrPtrTy));
1573 VPtr, getVTableAddressPoint(
BaseSubobject(SrcDecl, *Offset), DestDecl));
1575 if (!Offset->isZero())
1576 Result = CGF.
Builder.CreateInBoundsGEP(
1578 {llvm::ConstantInt::get(CGF.PtrDiffTy, -Offset->getQuantity())});
1583llvm::Value *ItaniumCXXABI::emitDynamicCastToVoid(
CodeGenFunction &CGF,
1588 llvm::Value *OffsetToTop;
1589 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
1591 llvm::Value *VTable =
1596 CGF.
Builder.CreateConstInBoundsGEP1_32(CGM.Int32Ty, VTable, -2U);
1600 llvm::Type *PtrDiffLTy =
1604 llvm::Value *VTable =
1609 CGF.
Builder.CreateConstInBoundsGEP1_64(PtrDiffLTy, VTable, -2ULL);
1621 Call->setDoesNotReturn();
1622 CGF.
Builder.CreateUnreachable();
1631 llvm::Value *VTablePtr = CGF.
GetVTablePtr(This, CGM.Int8PtrTy, ClassDecl);
1633 CGM.getItaniumVTableContext().getVirtualBaseOffsetOffset(ClassDecl,
1635 llvm::Value *VBaseOffsetPtr =
1636 CGF.
Builder.CreateConstGEP1_64(
1638 "vbase.offset.ptr");
1640 llvm::Value *VBaseOffset;
1641 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
1647 CGM.PtrDiffTy, VBaseOffsetPtr, CGF.
getPointerAlign(),
"vbase.offset");
1654 assert(CGM.getTarget().getCXXABI().hasConstructorVariants());
1669ItaniumCXXABI::buildStructorSignature(
GlobalDecl GD,
1679 cast<CXXMethodDecl>(GD.
getDecl())->getParent()->getNumVBases() != 0) {
1680 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1682 ArgTys.insert(ArgTys.begin() + 1,
1684 return AddedStructorArgCounts::prefix(1);
1686 return AddedStructorArgCounts{};
1709 assert(isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD));
1712 if (NeedsVTTParameter(CGF.
CurGD)) {
1716 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1721 T, ImplicitParamKind::CXXVTT);
1722 Params.insert(Params.begin() + 1, VTTDecl);
1723 getStructorImplicitParamDecl(CGF) = VTTDecl;
1734 setCXXABIThisValue(CGF, loadIncomingCXXThis(CGF));
1737 if (getStructorImplicitParamDecl(CGF)) {
1750 if (HasThisReturn(CGF.
CurGD))
1758 return AddedStructorArgs{};
1765 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1766 QualType Q = getContext().getAddrSpaceQualType(getContext().VoidPtrTy, AS);
1767 QualType VTTTy = getContext().getPointerType(Q);
1768 return AddedStructorArgs::prefix({{VTT, VTTTy}});
1771llvm::Value *ItaniumCXXABI::getCXXDestructorImplicitParam(
1786 QualType VTTTy = getContext().getPointerType(getContext().VoidPtrTy);
1789 if (getContext().getLangOpts().AppleKext &&
1801 llvm::GlobalVariable *VTable = getAddrOfVTable(RD,
CharUnits());
1802 if (VTable->hasInitializer())
1807 llvm::GlobalVariable::LinkageTypes
Linkage = CGM.getVTableLinkage(RD);
1808 llvm::Constant *RTTI =
1809 CGM.GetAddrOfRTTIDescriptor(CGM.getContext().getTagDeclType(RD));
1813 auto components = builder.beginStruct();
1815 llvm::GlobalValue::isLocalLinkage(
Linkage));
1816 components.finishAndSetAsInitializer(VTable);
1821 if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
1822 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
1825 CGM.setGVProperties(VTable, RD);
1833 isa<NamespaceDecl>(DC) && cast<NamespaceDecl>(DC)->getIdentifier() &&
1834 cast<NamespaceDecl>(DC)->getIdentifier()->isStr(
"__cxxabiv1") &&
1836 EmitFundamentalRTTIDescriptors(RD);
1843 if (!VTable->isDeclarationForLinker() ||
1844 CGM.getCodeGenOpts().WholeProgramVTables) {
1845 CGM.EmitVTableTypeMetadata(RD, VTable, VTLayout);
1849 if (VTable->isDeclarationForLinker()) {
1850 assert(CGM.getCodeGenOpts().WholeProgramVTables);
1851 CGM.addCompilerUsedGlobal(VTable);
1857 if (!VTable->isDSOLocal())
1862bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField(
1864 if (Vptr.NearestVBase ==
nullptr)
1866 return NeedsVTTParameter(CGF.
CurGD);
1869llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructor(
1873 if ((
Base.getBase()->getNumVBases() || NearestVBase !=
nullptr) &&
1874 NeedsVTTParameter(CGF.
CurGD)) {
1875 return getVTableAddressPointInStructorWithVTT(CGF, VTableClass,
Base,
1878 return getVTableAddressPoint(
Base, VTableClass);
1884 llvm::GlobalValue *VTable = getAddrOfVTable(VTableClass,
CharUnits());
1889 CGM.getItaniumVTableContext()
1890 .getVTableLayout(VTableClass)
1891 .getAddressPoint(
Base);
1892 llvm::Value *Indices[] = {
1893 llvm::ConstantInt::get(CGM.Int32Ty, 0),
1894 llvm::ConstantInt::get(CGM.Int32Ty, AddressPoint.
VTableIndex),
1898 return llvm::ConstantExpr::getGetElementPtr(VTable->getValueType(), VTable,
1905template <
typename T>
1907 bool FoundNonInlineVirtualMethodWithAttr =
false;
1909 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1910 if (!FD->isVirtualAsWritten() || FD->isInlineSpecified() ||
1911 FD->doesThisDeclarationHaveABody())
1915 FoundNonInlineVirtualMethodWithAttr =
true;
1923 return FoundNonInlineVirtualMethodWithAttr;
1926llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
1929 assert((
Base.getBase()->getNumVBases() || NearestVBase !=
nullptr) &&
1930 NeedsVTTParameter(CGF.
CurGD) &&
"This class doesn't have VTT");
1934 CGM.getVTables().getSecondaryVirtualPointerIndex(VTableClass,
Base);
1938 if (VirtualPointerIndex)
1940 VirtualPointerIndex);
1947llvm::Constant *ItaniumCXXABI::getVTableAddressPointForConstExpr(
1949 return getVTableAddressPoint(
Base, VTableClass);
1952llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(
const CXXRecordDecl *RD,
1954 assert(VPtrOffset.
isZero() &&
"Itanium ABI only supports zero vptr offsets");
1956 llvm::GlobalVariable *&VTable = VTables[RD];
1961 CGM.addDeferredVTable(RD);
1964 llvm::raw_svector_ostream Out(Name);
1965 getMangleContext().mangleCXXVTable(RD, Out);
1968 CGM.getItaniumVTableContext().getVTableLayout(RD);
1969 llvm::Type *VTableType = CGM.getVTables().getVTableType(VTLayout);
1974 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1975 unsigned PAlign = CGM.getItaniumVTableContext().isRelativeLayout()
1977 : CGM.getTarget().getPointerAlign(AS);
1979 VTable = CGM.CreateOrReplaceCXXRuntimeVariable(
1980 Name, VTableType, llvm::GlobalValue::ExternalLinkage,
1981 getContext().toCharUnitsFromBits(PAlign).getAsAlign());
1982 VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1991 if (CGM.getTarget().hasPS4DLLImportExport()) {
1992 if ((!RD->
hasAttr<DLLImportAttr>()) && (!RD->
hasAttr<DLLExportAttr>())) {
1993 if (CGM.getVTables().isVTableExternal(RD)) {
1994 if (CXXRecordAllNonInlineVirtualsHaveAttr<DLLImportAttr>(RD))
1995 VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
1997 if (CXXRecordAllNonInlineVirtualsHaveAttr<DLLExportAttr>(RD))
1998 VTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
2002 CGM.setGVProperties(VTable, RD);
2012 llvm::Type *PtrTy = CGM.GlobalsInt8PtrTy;
2013 auto *MethodDecl = cast<CXXMethodDecl>(GD.
getDecl());
2014 llvm::Value *VTable = CGF.
GetVTablePtr(This, PtrTy, MethodDecl->getParent());
2016 uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
2020 MethodDecl->getParent(), VTable, PtrTy,
2022 CGM.getContext().getTargetInfo().getPointerWidth(LangAS::Default) /
2027 llvm::Value *VFuncLoad;
2028 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
2029 VFuncLoad = CGF.
Builder.CreateCall(
2030 CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
2031 {VTable, llvm::ConstantInt::get(CGM.Int32Ty, 4 * VTableIndex)});
2033 llvm::Value *VTableSlotPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
2034 PtrTy, VTable, VTableIndex,
"vfn");
2045 if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2046 CGM.getCodeGenOpts().StrictVTablePointers) {
2047 if (
auto *VFuncLoadInstr = dyn_cast<llvm::Instruction>(VFuncLoad)) {
2048 VFuncLoadInstr->setMetadata(
2049 llvm::LLVMContext::MD_invariant_load,
2050 llvm::MDNode::get(CGM.getLLVMContext(),
2061llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
2063 Address This, DeleteOrMemberCallExpr E) {
2066 assert((CE !=
nullptr) ^ (D !=
nullptr));
2067 assert(CE ==
nullptr || CE->arg_begin() == CE->arg_end());
2072 &CGM.getTypes().arrangeCXXStructorDeclaration(GD);
2078 ThisTy = CE->getObjectType();
2080 ThisTy = D->getDestroyedType();
2088void ItaniumCXXABI::emitVirtualInheritanceTables(
const CXXRecordDecl *RD) {
2094bool ItaniumCXXABI::canSpeculativelyEmitVTableAsBaseClass(
2098 if (CGM.getLangOpts().AppleKext)
2103 if (isVTableHidden(RD))
2106 if (CGM.getCodeGenOpts().ForceEmitVTables)
2113 if (hasAnyUnusedVirtualInlineFunction(RD))
2121 for (
const auto &B : RD->
bases()) {
2122 auto *BRD = B.getType()->getAsCXXRecordDecl();
2123 assert(BRD &&
"no class for base specifier");
2124 if (B.isVirtual() || !BRD->isDynamicClass())
2126 if (!canSpeculativelyEmitVTableAsBaseClass(BRD))
2134bool ItaniumCXXABI::canSpeculativelyEmitVTable(
const CXXRecordDecl *RD)
const {
2135 if (!canSpeculativelyEmitVTableAsBaseClass(RD))
2140 for (
const auto &B : RD->
vbases()) {
2141 auto *BRD = B.getType()->getAsCXXRecordDecl();
2142 assert(BRD &&
"no class for base specifier");
2143 if (!BRD->isDynamicClass())
2145 if (!canSpeculativelyEmitVTableAsBaseClass(BRD))
2153 int64_t NonVirtualAdjustment,
2154 int64_t VirtualAdjustment,
2155 bool IsReturnAdjustment) {
2156 if (!NonVirtualAdjustment && !VirtualAdjustment)
2162 if (NonVirtualAdjustment && !IsReturnAdjustment) {
2168 llvm::Value *ResultPtr;
2169 if (VirtualAdjustment) {
2173 llvm::Value *Offset;
2174 llvm::Value *OffsetPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
2175 CGF.
Int8Ty, VTablePtr, VirtualAdjustment);
2182 llvm::Type *PtrDiffTy =
2190 ResultPtr = CGF.
Builder.CreateInBoundsGEP(
2191 V.getElementType(),
V.getPointer(), Offset);
2193 ResultPtr =
V.getPointer();
2198 if (NonVirtualAdjustment && IsReturnAdjustment) {
2199 ResultPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(CGF.
Int8Ty, ResultPtr,
2200 NonVirtualAdjustment);
2206llvm::Value *ItaniumCXXABI::performThisAdjustment(
CodeGenFunction &CGF,
2225 return ItaniumCXXABI::EmitReturnFromThunk(CGF, RV, ResultType);
2230 return ItaniumCXXABI::EmitReturnFromThunk(CGF, Undef, ResultType);
2239 CGM.getContext().getPreferredTypeAlignInChars(elementType));
2244 llvm::Value *NumElements,
2247 assert(requiresArrayCookie(
expr));
2257 assert(CookieSize == getArrayCookieSizeImpl(ElementType));
2261 CharUnits CookieOffset = CookieSize - SizeSize;
2262 if (!CookieOffset.
isZero())
2270 if (CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) && AS == 0 &&
2271 (
expr->getOperatorNew()->isReplaceableGlobalAllocationFunction() ||
2272 CGM.getCodeGenOpts().SanitizeAddressPoisonCustomArrayCookie)) {
2274 SI->setNoSanitizeMetadata();
2275 llvm::FunctionType *FTy =
2276 llvm::FunctionType::get(CGM.VoidTy, NumElementsPtr.
getType(),
false);
2277 llvm::FunctionCallee F =
2278 CGM.CreateRuntimeFunction(FTy,
"__asan_poison_cxx_array_cookie");
2291 Address numElementsPtr = allocPtr;
2293 if (!numElementsOffset.
isZero())
2299 if (!CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) || AS != 0)
2306 llvm::FunctionType *FTy =
2308 llvm::FunctionCallee F =
2309 CGM.CreateRuntimeFunction(FTy,
"__asan_load_cxx_array_cookie");
2323 CGM.getContext().getTypeAlignInChars(elementType));
2328 llvm::Value *numElements,
2331 assert(requiresArrayCookie(
expr));
2338 llvm::Value *elementSize = llvm::ConstantInt::get(CGF.
SizeTy,
2339 getContext().getTypeSizeInChars(elementType).getQuantity());
2348 CharUnits cookieSize = ARMCXXABI::getArrayCookieSizeImpl(elementType);
2367 llvm::PointerType *GuardPtrTy) {
2369 llvm::FunctionType *FTy =
2373 FTy,
"__cxa_guard_acquire",
2375 llvm::AttributeList::FunctionIndex,
2376 llvm::Attribute::NoUnwind));
2380 llvm::PointerType *GuardPtrTy) {
2382 llvm::FunctionType *FTy =
2383 llvm::FunctionType::get(CGM.
VoidTy, GuardPtrTy,
false);
2385 FTy,
"__cxa_guard_release",
2387 llvm::AttributeList::FunctionIndex,
2388 llvm::Attribute::NoUnwind));
2392 llvm::PointerType *GuardPtrTy) {
2394 llvm::FunctionType *FTy =
2395 llvm::FunctionType::get(CGM.
VoidTy, GuardPtrTy,
false);
2397 FTy,
"__cxa_guard_abort",
2399 llvm::AttributeList::FunctionIndex,
2400 llvm::Attribute::NoUnwind));
2405 llvm::GlobalVariable *Guard;
2406 CallGuardAbort(llvm::GlobalVariable *Guard) : Guard(Guard) {}
2419 llvm::GlobalVariable *var,
2420 bool shouldPerformInit) {
2425 bool NonTemplateInline =
2432 bool threadsafe = getContext().getLangOpts().ThreadsafeStatics &&
2438 bool useInt8GuardVariable = !threadsafe && var->hasInternalLinkage();
2440 llvm::IntegerType *guardTy;
2442 if (useInt8GuardVariable) {
2448 if (UseARMGuardVarABI) {
2457 llvm::PointerType *guardPtrTy = llvm::PointerType::get(
2463 llvm::GlobalVariable *guard = CGM.getStaticLocalDeclGuardAddress(&D);
2468 llvm::raw_svector_ostream out(guardName);
2469 getMangleContext().mangleStaticGuardVariable(&D, out);
2475 guard =
new llvm::GlobalVariable(CGM.getModule(), guardTy,
2476 false, var->getLinkage(),
2477 llvm::ConstantInt::get(guardTy, 0),
2479 guard->setDSOLocal(var->isDSOLocal());
2480 guard->setVisibility(var->getVisibility());
2481 guard->setDLLStorageClass(var->getDLLStorageClass());
2483 guard->setThreadLocalMode(var->getThreadLocalMode());
2484 guard->setAlignment(guardAlignment.
getAsAlign());
2489 llvm::Comdat *
C = var->getComdat();
2491 (CGM.getTarget().getTriple().isOSBinFormatELF() ||
2492 CGM.getTarget().getTriple().isOSBinFormatWasm())) {
2493 guard->setComdat(
C);
2494 }
else if (CGM.supportsCOMDAT() && guard->isWeakForLinker()) {
2495 guard->setComdat(CGM.getModule().getOrInsertComdat(guard->getName()));
2498 CGM.setStaticLocalDeclGuardAddress(&D, guard);
2501 Address guardAddr =
Address(guard, guard->getValueType(), guardAlignment);
2526 if (!threadsafe || MaxInlineWidthInBits) {
2528 llvm::LoadInst *LI =
2538 LI->setAtomic(llvm::AtomicOrdering::Acquire);
2561 (UseARMGuardVarABI && !useInt8GuardVariable)
2562 ? Builder.CreateAnd(LI, llvm::ConstantInt::get(CGM.Int8Ty, 1))
2564 llvm::Value *NeedsInit = Builder.CreateIsNull(
V,
"guard.uninitialized");
2570 CodeGenFunction::GuardKind::VariableGuard, &D);
2598 Builder.CreateCondBr(Builder.CreateIsNotNull(
V,
"tobool"),
2599 InitBlock, EndBlock);
2609 Builder.CreateStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),
2627 Builder.CreateStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),
2636 llvm::FunctionCallee dtor,
2637 llvm::Constant *addr,
bool TLS) {
2639 "unexpected call to emitGlobalDtorWithCXAAtExit");
2641 "__cxa_atexit is disabled");
2642 const char *Name =
"__cxa_atexit";
2645 Name = T.isOSDarwin() ?
"_tlv_atexit" :
"__cxa_thread_atexit";
2653 auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
2654 auto AddrPtrTy = AddrAS ? llvm::PointerType::get(CGF.
getLLVMContext(), AddrAS)
2658 llvm::Constant *handle =
2660 auto *GV = cast<llvm::GlobalValue>(handle->stripPointerCasts());
2661 GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
2664 llvm::Type *paramTys[] = {
dtorTy, AddrPtrTy, handle->getType()};
2665 llvm::FunctionType *atexitTy =
2666 llvm::FunctionType::get(CGF.
IntTy, paramTys,
false);
2670 if (llvm::Function *fn = dyn_cast<llvm::Function>(atexit.getCallee()))
2671 fn->setDoesNotThrow();
2678 addr = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
2680 llvm::Value *args[] = {dtor.getCallee(), addr, handle};
2688 llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.
VoidTy,
false);
2692 return GlobalInitOrCleanupFn;
2695void CodeGenModule::unregisterGlobalDtorsWithUnAtExit() {
2696 for (
const auto &I : DtorsUsingAtExit) {
2698 std::string GlobalCleanupFnName =
2699 std::string(
"__GLOBAL_cleanup_") + llvm::to_string(Priority);
2701 llvm::Function *GlobalCleanupFn =
2711 llvm::FunctionType *dtorFuncTy = llvm::FunctionType::get(CGF.
VoidTy,
false);
2715 const llvm::TinyPtrVector<llvm::Function *> &Dtors = I.second;
2716 auto itv = Dtors.rbegin();
2717 while (itv != Dtors.rend()) {
2718 llvm::Function *Dtor = *itv;
2723 llvm::Value *NeedsDestruct =
2724 CGF.
Builder.CreateIsNull(
V,
"needs_destruct");
2726 llvm::BasicBlock *DestructCallBlock =
2729 (itv + 1) != Dtors.rend() ?
"unatexit.call" :
"destruct.end");
2732 CGF.
Builder.CreateCondBr(NeedsDestruct, DestructCallBlock, EndBlock);
2737 llvm::CallInst *CI = CGF.
Builder.CreateCall(dtorFuncTy, Dtor);
2739 CI->setCallingConv(Dtor->getCallingConv());
2751void CodeGenModule::registerGlobalDtorsWithAtExit() {
2752 for (
const auto &I : DtorsUsingAtExit) {
2754 std::string GlobalInitFnName =
2755 std::string(
"__GLOBAL_init_") + llvm::to_string(Priority);
2756 llvm::Function *GlobalInitFn =
2770 const llvm::TinyPtrVector<llvm::Function *> &Dtors = I.second;
2771 for (
auto *Dtor : Dtors) {
2788 unregisterGlobalDtorsWithUnAtExit();
2793 llvm::FunctionCallee dtor,
2794 llvm::Constant *addr) {
2810 if (CGM.getCodeGenOpts().CXAAtExit || D.
getTLSKind())
2815 if (CGM.getLangOpts().AppleKext) {
2817 return CGM.AddCXXDtorEntry(dtor, addr);
2825 assert(!VD->
isStaticLocal() &&
"static local VarDecls don't need wrappers!");
2835static llvm::GlobalValue::LinkageTypes
2837 llvm::GlobalValue::LinkageTypes VarLinkage =
2841 if (llvm::GlobalValue::isLocalLinkage(VarLinkage))
2846 if (!llvm::GlobalVariable::isLinkOnceLinkage(VarLinkage) &&
2847 !llvm::GlobalVariable::isWeakODRLinkage(VarLinkage))
2849 return llvm::GlobalValue::WeakODRLinkage;
2853ItaniumCXXABI::getOrCreateThreadLocalWrapper(
const VarDecl *VD,
2858 llvm::raw_svector_ostream Out(WrapperName);
2859 getMangleContext().mangleItaniumThreadLocalWrapper(VD, Out);
2864 if (llvm::Value *
V = CGM.getModule().getNamedValue(WrapperName))
2865 return cast<llvm::Function>(
V);
2871 const CGFunctionInfo &FI = CGM.getTypes().arrangeBuiltinFunctionDeclaration(
2874 llvm::FunctionType *FnTy = CGM.getTypes().GetFunctionType(FI);
2875 llvm::Function *Wrapper =
2877 WrapperName.str(), &CGM.getModule());
2879 if (CGM.supportsCOMDAT() && Wrapper->isWeakForLinker())
2880 Wrapper->setComdat(CGM.getModule().getOrInsertComdat(Wrapper->getName()));
2882 CGM.SetLLVMFunctionAttributes(
GlobalDecl(), FI, Wrapper,
false);
2885 if (!Wrapper->hasLocalLinkage())
2887 llvm::GlobalVariable::isLinkOnceLinkage(Wrapper->getLinkage()) ||
2888 llvm::GlobalVariable::isWeakODRLinkage(Wrapper->getLinkage()) ||
2890 Wrapper->setVisibility(llvm::GlobalValue::HiddenVisibility);
2893 Wrapper->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
2894 Wrapper->addFnAttr(llvm::Attribute::NoUnwind);
2897 ThreadWrappers.push_back({VD, Wrapper});
2901void ItaniumCXXABI::EmitThreadLocalInitFuncs(
2905 llvm::Function *InitFunc =
nullptr;
2910 llvm::SmallDenseMap<const VarDecl *, llvm::Function *> UnorderedInits;
2911 for (
unsigned I = 0; I != CXXThreadLocalInits.size(); ++I) {
2914 UnorderedInits[CXXThreadLocalInitVars[I]->getCanonicalDecl()] =
2915 CXXThreadLocalInits[I];
2917 OrderedInits.push_back(CXXThreadLocalInits[I]);
2920 if (!OrderedInits.empty()) {
2922 llvm::FunctionType *FTy =
2923 llvm::FunctionType::get(CGM.
VoidTy,
false);
2928 llvm::GlobalVariable *Guard =
new llvm::GlobalVariable(
2930 llvm::GlobalVariable::InternalLinkage,
2931 llvm::ConstantInt::get(CGM.
Int8Ty, 0),
"__tls_guard");
2932 Guard->setThreadLocal(
true);
2936 Guard->setAlignment(GuardAlign.
getAsAlign());
2942 InitFunc->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
2943 InitFunc->addFnAttr(llvm::Attribute::NoUnwind);
2949 for (
const VarDecl *VD : CXXThreadLocals) {
2953 getOrCreateThreadLocalWrapper(VD, GV);
2958 for (
auto VDAndWrapper : ThreadWrappers) {
2959 const VarDecl *VD = VDAndWrapper.first;
2960 llvm::GlobalVariable *Var =
2962 llvm::Function *Wrapper = VDAndWrapper.second;
2969 Wrapper->setLinkage(llvm::Function::ExternalLinkage);
2975 if (Wrapper->getLinkage() == llvm::Function::WeakODRLinkage)
2976 Wrapper->setLinkage(llvm::Function::LinkOnceODRLinkage);
2984 llvm::raw_svector_ostream Out(InitFnName);
2985 getMangleContext().mangleItaniumThreadLocalInit(VD, Out);
2988 llvm::FunctionType *InitFnTy = llvm::FunctionType::get(CGM.
VoidTy,
false);
2993 llvm::GlobalValue *
Init =
nullptr;
2994 bool InitIsInitFunc =
false;
2995 bool HasConstantInitialization =
false;
2996 if (!usesThreadWrapperFunction(VD)) {
2997 HasConstantInitialization =
true;
2999 InitIsInitFunc =
true;
3000 llvm::Function *InitFuncToUse = InitFunc;
3004 Init = llvm::GlobalAlias::create(Var->getLinkage(), InitFnName.str(),
3011 Init = llvm::Function::Create(InitFnTy,
3012 llvm::GlobalVariable::ExternalWeakLinkage,
3020 Init->setVisibility(Var->getVisibility());
3022 if (!CGM.
getTriple().isOSWindows() || !
Init->hasExternalWeakLinkage())
3023 Init->setDSOLocal(Var->isDSOLocal());
3026 llvm::LLVMContext &Context = CGM.
getModule().getContext();
3034 isEmittedWithConstantInitializer(VD,
true) &&
3035 !mayNeedDestruction(VD)) {
3040 assert(
Init ==
nullptr &&
"Expected Init to be null.");
3042 llvm::Function *
Func = llvm::Function::Create(
3043 InitFnTy, Var->getLinkage(), InitFnName.str(), &CGM.
getModule());
3046 cast<llvm::Function>(
Func),
3049 llvm::BasicBlock *Entry = llvm::BasicBlock::Create(Context,
"",
Func);
3051 Builder.CreateRetVoid();
3054 llvm::BasicBlock *Entry = llvm::BasicBlock::Create(Context,
"", Wrapper);
3056 if (HasConstantInitialization) {
3058 }
else if (InitIsInitFunc) {
3060 llvm::CallInst *CallVal = Builder.CreateCall(InitFnTy,
Init);
3062 CallVal->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
3063 llvm::Function *Fn =
3064 cast<llvm::Function>(cast<llvm::GlobalAlias>(
Init)->getAliasee());
3065 Fn->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
3076 Builder.CreateCall(InitFnTy,
Init);
3079 llvm::Value *Have = Builder.CreateIsNotNull(
Init);
3080 llvm::BasicBlock *InitBB = llvm::BasicBlock::Create(Context,
"", Wrapper);
3081 llvm::BasicBlock *ExitBB = llvm::BasicBlock::Create(Context,
"", Wrapper);
3082 Builder.CreateCondBr(Have, InitBB, ExitBB);
3084 Builder.SetInsertPoint(InitBB);
3085 Builder.CreateCall(InitFnTy,
Init);
3086 Builder.CreateBr(ExitBB);
3088 Builder.SetInsertPoint(ExitBB);
3093 llvm::Value *Val = Builder.CreateThreadLocalAddress(Var);
3097 Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
3100 Builder.CreateRet(Val);
3108 llvm::Function *Wrapper = getOrCreateThreadLocalWrapper(VD, Val);
3110 llvm::CallInst *CallVal = CGF.
Builder.CreateCall(Wrapper);
3111 CallVal->setCallingConv(Wrapper->getCallingConv());
3125bool ItaniumCXXABI::NeedsVTTParameter(
GlobalDecl GD) {
3144class ItaniumRTTIBuilder {
3146 llvm::LLVMContext &VMContext;
3147 const ItaniumCXXABI &
CXXABI;
3153 llvm::GlobalVariable *
3154 GetAddrOfTypeName(
QualType Ty, llvm::GlobalVariable::LinkageTypes
Linkage);
3158 llvm::Constant *GetAddrOfExternalRTTIDescriptor(
QualType Ty);
3161 void BuildVTablePointer(
const Type *Ty);
3174 void BuildPointerTypeInfo(
QualType PointeeTy);
3185 ItaniumRTTIBuilder(
const ItaniumCXXABI &ABI)
3186 : CGM(ABI.CGM), VMContext(CGM.getModule().getContext()),
CXXABI(ABI) {}
3200 PTI_Incomplete = 0x8,
3204 PTI_ContainingClassIncomplete = 0x10,
3210 PTI_Noexcept = 0x40,
3216 VMI_NonDiamondRepeat = 0x1,
3219 VMI_DiamondShaped = 0x2
3233 llvm::Constant *BuildTypeInfo(
QualType Ty);
3236 llvm::Constant *BuildTypeInfo(
3238 llvm::GlobalVariable::LinkageTypes
Linkage,
3239 llvm::GlobalValue::VisibilityTypes
Visibility,
3240 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass);
3244llvm::GlobalVariable *ItaniumRTTIBuilder::GetAddrOfTypeName(
3247 llvm::raw_svector_ostream Out(Name);
3253 llvm::Constant *
Init = llvm::ConstantDataArray::getString(VMContext,
3260 GV->setInitializer(
Init);
3266ItaniumRTTIBuilder::GetAddrOfExternalRTTIDescriptor(
QualType Ty) {
3269 llvm::raw_svector_ostream Out(Name);
3273 llvm::GlobalVariable *GV = CGM.
getModule().getNamedGlobal(Name);
3280 GV =
new llvm::GlobalVariable(
3282 true, llvm::GlobalValue::ExternalLinkage,
nullptr, Name);
3288 if (RD && CXXRecordAllNonInlineVirtualsHaveAttr<DLLImportAttr>(RD)) {
3289 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
3316 case BuiltinType::Void:
3317 case BuiltinType::NullPtr:
3318 case BuiltinType::Bool:
3319 case BuiltinType::WChar_S:
3320 case BuiltinType::WChar_U:
3321 case BuiltinType::Char_U:
3322 case BuiltinType::Char_S:
3323 case BuiltinType::UChar:
3324 case BuiltinType::SChar:
3325 case BuiltinType::Short:
3326 case BuiltinType::UShort:
3327 case BuiltinType::Int:
3328 case BuiltinType::UInt:
3329 case BuiltinType::Long:
3330 case BuiltinType::ULong:
3331 case BuiltinType::LongLong:
3332 case BuiltinType::ULongLong:
3333 case BuiltinType::Half:
3334 case BuiltinType::Float:
3335 case BuiltinType::Double:
3336 case BuiltinType::LongDouble:
3337 case BuiltinType::Float16:
3338 case BuiltinType::Float128:
3339 case BuiltinType::Ibm128:
3340 case BuiltinType::Char8:
3341 case BuiltinType::Char16:
3342 case BuiltinType::Char32:
3343 case BuiltinType::Int128:
3344 case BuiltinType::UInt128:
3347#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3348 case BuiltinType::Id:
3349#include "clang/Basic/OpenCLImageTypes.def"
3350#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3351 case BuiltinType::Id:
3352#include "clang/Basic/OpenCLExtensionTypes.def"
3353 case BuiltinType::OCLSampler:
3354 case BuiltinType::OCLEvent:
3355 case BuiltinType::OCLClkEvent:
3356 case BuiltinType::OCLQueue:
3357 case BuiltinType::OCLReserveID:
3358#define SVE_TYPE(Name, Id, SingletonId) \
3359 case BuiltinType::Id:
3360#include "clang/Basic/AArch64SVEACLETypes.def"
3361#define PPC_VECTOR_TYPE(Name, Id, Size) \
3362 case BuiltinType::Id:
3363#include "clang/Basic/PPCTypes.def"
3364#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
3365#include "clang/Basic/RISCVVTypes.def"
3366#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
3367#include "clang/Basic/WebAssemblyReferenceTypes.def"
3368 case BuiltinType::ShortAccum:
3369 case BuiltinType::Accum:
3370 case BuiltinType::LongAccum:
3371 case BuiltinType::UShortAccum:
3372 case BuiltinType::UAccum:
3373 case BuiltinType::ULongAccum:
3374 case BuiltinType::ShortFract:
3375 case BuiltinType::Fract:
3376 case BuiltinType::LongFract:
3377 case BuiltinType::UShortFract:
3378 case BuiltinType::UFract:
3379 case BuiltinType::ULongFract:
3380 case BuiltinType::SatShortAccum:
3381 case BuiltinType::SatAccum:
3382 case BuiltinType::SatLongAccum:
3383 case BuiltinType::SatUShortAccum:
3384 case BuiltinType::SatUAccum:
3385 case BuiltinType::SatULongAccum:
3386 case BuiltinType::SatShortFract:
3387 case BuiltinType::SatFract:
3388 case BuiltinType::SatLongFract:
3389 case BuiltinType::SatUShortFract:
3390 case BuiltinType::SatUFract:
3391 case BuiltinType::SatULongFract:
3392 case BuiltinType::BFloat16:
3395 case BuiltinType::Dependent:
3396#define BUILTIN_TYPE(Id, SingletonId)
3397#define PLACEHOLDER_TYPE(Id, SingletonId) \
3398 case BuiltinType::Id:
3399#include "clang/AST/BuiltinTypes.def"
3400 llvm_unreachable(
"asking for RRTI for a placeholder type!");
3402 case BuiltinType::ObjCId:
3403 case BuiltinType::ObjCClass:
3404 case BuiltinType::ObjCSel:
3405 llvm_unreachable(
"FIXME: Objective-C types are unsupported!");
3408 llvm_unreachable(
"Invalid BuiltinType Kind!");
3413 const BuiltinType *BuiltinTy = dyn_cast<BuiltinType>(PointeeTy);
3431 if (
const BuiltinType *BuiltinTy = dyn_cast<BuiltinType>(Ty))
3436 if (
const PointerType *PointerTy = dyn_cast<PointerType>(Ty))
3454 if (
const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
3455 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
3466 bool IsDLLImport = RD->
hasAttr<DLLImportAttr>();
3469 if (CGM.
getTriple().isWindowsGNUEnvironment())
3476 return IsDLLImport && !CGM.
getTriple().isWindowsItaniumEnvironment()
3504 if (
const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
3509 if (
const PointerType *PointerTy = dyn_cast<PointerType>(Ty))
3513 dyn_cast<MemberPointerType>(Ty)) {
3515 const RecordType *ClassType = cast<RecordType>(MemberPointerTy->getClass());
3537 if (
Base->isVirtual())
3547 if (!BaseDecl->isEmpty() &&
3554void ItaniumRTTIBuilder::BuildVTablePointer(
const Type *Ty) {
3556 static const char *
const ClassTypeInfo =
3557 "_ZTVN10__cxxabiv117__class_type_infoE";
3559 static const char *
const SIClassTypeInfo =
3560 "_ZTVN10__cxxabiv120__si_class_type_infoE";
3562 static const char *
const VMIClassTypeInfo =
3563 "_ZTVN10__cxxabiv121__vmi_class_type_infoE";
3565 const char *VTableName =
nullptr;
3568#define TYPE(Class, Base)
3569#define ABSTRACT_TYPE(Class, Base)
3570#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3571#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3572#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3573#include "clang/AST/TypeNodes.inc"
3574 llvm_unreachable(
"Non-canonical and dependent types shouldn't get here");
3576 case Type::LValueReference:
3577 case Type::RValueReference:
3578 llvm_unreachable(
"References shouldn't get here");
3581 case Type::DeducedTemplateSpecialization:
3582 llvm_unreachable(
"Undeduced type shouldn't get here");
3585 llvm_unreachable(
"Pipe types shouldn't get here");
3591 case Type::ExtVector:
3592 case Type::ConstantMatrix:
3596 case Type::BlockPointer:
3598 VTableName =
"_ZTVN10__cxxabiv123__fundamental_type_infoE";
3601 case Type::ConstantArray:
3602 case Type::IncompleteArray:
3603 case Type::VariableArray:
3605 VTableName =
"_ZTVN10__cxxabiv117__array_type_infoE";
3608 case Type::FunctionNoProto:
3609 case Type::FunctionProto:
3611 VTableName =
"_ZTVN10__cxxabiv120__function_type_infoE";
3616 VTableName =
"_ZTVN10__cxxabiv116__enum_type_infoE";
3619 case Type::Record: {
3621 cast<CXXRecordDecl>(cast<RecordType>(Ty)->getDecl());
3624 VTableName = ClassTypeInfo;
3626 VTableName = SIClassTypeInfo;
3628 VTableName = VMIClassTypeInfo;
3634 case Type::ObjCObject:
3636 Ty = cast<ObjCObjectType>(Ty)->getBaseType().getTypePtr();
3639 if (isa<BuiltinType>(Ty)) {
3640 VTableName = ClassTypeInfo;
3644 assert(isa<ObjCInterfaceType>(Ty));
3647 case Type::ObjCInterface:
3648 if (cast<ObjCInterfaceType>(Ty)->getDecl()->getSuperClass()) {
3649 VTableName = SIClassTypeInfo;
3651 VTableName = ClassTypeInfo;
3655 case Type::ObjCObjectPointer:
3658 VTableName =
"_ZTVN10__cxxabiv119__pointer_type_infoE";
3661 case Type::MemberPointer:
3663 VTableName =
"_ZTVN10__cxxabiv129__pointer_to_member_type_infoE";
3667 llvm::Constant *VTable =
nullptr;
3671 VTable = CGM.
getModule().getNamedAlias(VTableName);
3674 VTable = CGM.
getModule().getOrInsertGlobal(VTableName, Ty);
3677 CGM.
setDSOLocal(cast<llvm::GlobalValue>(VTable->stripPointerCasts()));
3679 llvm::Type *PtrDiffTy =
3686 llvm::Constant *Eight = llvm::ConstantInt::get(CGM.
Int32Ty, 8);
3688 llvm::ConstantExpr::getInBoundsGetElementPtr(CGM.
Int8Ty, VTable, Eight);
3690 llvm::Constant *Two = llvm::ConstantInt::get(PtrDiffTy, 2);
3691 VTable = llvm::ConstantExpr::getInBoundsGetElementPtr(CGM.
GlobalsInt8PtrTy,
3695 Fields.push_back(VTable);
3712 return llvm::GlobalValue::InternalLinkage;
3716 llvm_unreachable(
"Linkage hasn't been computed!");
3721 return llvm::GlobalValue::InternalLinkage;
3729 return llvm::GlobalValue::LinkOnceODRLinkage;
3734 return llvm::GlobalValue::WeakODRLinkage;
3735 if (CGM.
getTriple().isWindowsItaniumEnvironment())
3736 if (RD->
hasAttr<DLLImportAttr>() &&
3738 return llvm::GlobalValue::ExternalLinkage;
3744 .isWindowsGNUEnvironment())
3748 return llvm::GlobalValue::LinkOnceODRLinkage;
3751 llvm_unreachable(
"Invalid linkage!");
3754llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
QualType Ty) {
3760 llvm::raw_svector_ostream Out(Name);
3763 llvm::GlobalVariable *OldGV = CGM.
getModule().getNamedGlobal(Name);
3764 if (OldGV && !OldGV->isDeclaration()) {
3765 assert(!OldGV->hasAvailableExternallyLinkage() &&
3766 "available_externally typeinfos not yet implemented");
3774 return GetAddrOfExternalRTTIDescriptor(Ty);
3781 llvm::GlobalValue::VisibilityTypes llvmVisibility;
3782 if (llvm::GlobalValue::isLocalLinkage(
Linkage))
3784 llvmVisibility = llvm::GlobalValue::DefaultVisibility;
3786 ItaniumCXXABI::RUK_NonUniqueHidden)
3787 llvmVisibility = llvm::GlobalValue::HiddenVisibility;
3791 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass =
3792 llvm::GlobalValue::DefaultStorageClass;
3794 if ((CGM.
getTriple().isWindowsItaniumEnvironment() &&
3795 RD->
hasAttr<DLLExportAttr>()) ||
3797 !llvm::GlobalValue::isLocalLinkage(
Linkage) &&
3798 llvmVisibility == llvm::GlobalValue::DefaultVisibility))
3799 DLLStorageClass = llvm::GlobalValue::DLLExportStorageClass;
3801 return BuildTypeInfo(Ty,
Linkage, llvmVisibility, DLLStorageClass);
3804llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
3806 llvm::GlobalVariable::LinkageTypes
Linkage,
3807 llvm::GlobalValue::VisibilityTypes
Visibility,
3808 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass) {
3810 BuildVTablePointer(cast<Type>(Ty));
3814 llvm::Constant *TypeNameField;
3818 ItaniumCXXABI::RTTIUniquenessKind RTTIUniqueness =
3820 if (RTTIUniqueness != ItaniumCXXABI::RUK_Unique) {
3823 TypeNameField = llvm::ConstantExpr::getPtrToInt(TypeName, CGM.
Int64Ty);
3824 llvm::Constant *flag =
3825 llvm::ConstantInt::get(CGM.
Int64Ty, ((uint64_t)1) << 63);
3826 TypeNameField = llvm::ConstantExpr::getAdd(TypeNameField, flag);
3832 Fields.push_back(TypeNameField);
3835#define TYPE(Class, Base)
3836#define ABSTRACT_TYPE(Class, Base)
3837#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3838#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3839#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3840#include "clang/AST/TypeNodes.inc"
3841 llvm_unreachable(
"Non-canonical and dependent types shouldn't get here");
3846 case Type::ExtVector:
3847 case Type::ConstantMatrix:
3849 case Type::BlockPointer:
3854 case Type::LValueReference:
3855 case Type::RValueReference:
3856 llvm_unreachable(
"References shouldn't get here");
3859 case Type::DeducedTemplateSpecialization:
3860 llvm_unreachable(
"Undeduced type shouldn't get here");
3868 case Type::ConstantArray:
3869 case Type::IncompleteArray:
3870 case Type::VariableArray:
3875 case Type::FunctionNoProto:
3876 case Type::FunctionProto:
3886 case Type::Record: {
3888 cast<CXXRecordDecl>(cast<RecordType>(Ty)->getDecl());
3895 BuildSIClassTypeInfo(RD);
3897 BuildVMIClassTypeInfo(RD);
3902 case Type::ObjCObject:
3903 case Type::ObjCInterface:
3904 BuildObjCObjectTypeInfo(cast<ObjCObjectType>(Ty));
3907 case Type::ObjCObjectPointer:
3908 BuildPointerTypeInfo(cast<ObjCObjectPointerType>(Ty)->getPointeeType());
3912 BuildPointerTypeInfo(cast<PointerType>(Ty)->getPointeeType());
3915 case Type::MemberPointer:
3916 BuildPointerToMemberTypeInfo(cast<MemberPointerType>(Ty));
3924 llvm::Constant *
Init = llvm::ConstantStruct::getAnon(Fields);
3927 llvm::raw_svector_ostream Out(Name);
3930 llvm::GlobalVariable *OldGV = M.getNamedGlobal(Name);
3931 llvm::GlobalVariable *GV =
3932 new llvm::GlobalVariable(M,
Init->getType(),
3936 auto GVDLLStorageClass = DLLStorageClass;
3938 if (
const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
3939 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
3940 if (RD->
hasAttr<DLLExportAttr>() ||
3941 CXXRecordAllNonInlineVirtualsHaveAttr<DLLExportAttr>(RD)) {
3942 GVDLLStorageClass = llvm::GlobalVariable::DLLExportStorageClass;
3949 GV->takeName(OldGV);
3950 OldGV->replaceAllUsesWith(GV);
3951 OldGV->eraseFromParent();
3955 GV->setComdat(M.getOrInsertComdat(GV->getName()));
3982 TypeName->setDLLStorageClass(DLLStorageClass);
3995void ItaniumRTTIBuilder::BuildObjCObjectTypeInfo(
const ObjCObjectType *OT) {
3998 assert(isa<BuiltinType>(T) || isa<ObjCInterfaceType>(T));
4002 if (isa<BuiltinType>(T))
return;
4013 llvm::Constant *BaseTypeInfo =
4014 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(SuperTy);
4015 Fields.push_back(BaseTypeInfo);
4020void ItaniumRTTIBuilder::BuildSIClassTypeInfo(
const CXXRecordDecl *RD) {
4024 llvm::Constant *BaseTypeInfo =
4026 Fields.push_back(BaseTypeInfo);
4049 if (
Base->isVirtual()) {
4051 if (!Bases.VirtualBases.insert(BaseDecl).second) {
4054 Flags |= ItaniumRTTIBuilder::VMI_DiamondShaped;
4056 if (Bases.NonVirtualBases.count(BaseDecl))
4057 Flags |= ItaniumRTTIBuilder::VMI_NonDiamondRepeat;
4061 if (!Bases.NonVirtualBases.insert(BaseDecl).second) {
4064 Flags |= ItaniumRTTIBuilder::VMI_NonDiamondRepeat;
4066 if (Bases.VirtualBases.count(BaseDecl))
4067 Flags |= ItaniumRTTIBuilder::VMI_NonDiamondRepeat;
4072 for (
const auto &I : BaseDecl->bases())
4083 for (
const auto &I : RD->
bases())
4092void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(
const CXXRecordDecl *RD) {
4093 llvm::Type *UnsignedIntLTy =
4101 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
4106 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, RD->
getNumBases()));
4139 llvm::Type *OffsetFlagsLTy =
4144 Fields.push_back(ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(
Base.getType()));
4156 if (
Base.isVirtual())
4164 OffsetFlags =
uint64_t(Offset.getQuantity()) << 8;
4168 if (
Base.isVirtual())
4169 OffsetFlags |= BCTI_Virtual;
4171 OffsetFlags |= BCTI_Public;
4173 Fields.push_back(llvm::ConstantInt::get(OffsetFlagsLTy, OffsetFlags));
4182 if (
Type.isConstQualified())
4183 Flags |= ItaniumRTTIBuilder::PTI_Const;
4184 if (
Type.isVolatileQualified())
4185 Flags |= ItaniumRTTIBuilder::PTI_Volatile;
4186 if (
Type.isRestrictQualified())
4187 Flags |= ItaniumRTTIBuilder::PTI_Restrict;
4194 Flags |= ItaniumRTTIBuilder::PTI_Incomplete;
4197 if (Proto->isNothrow()) {
4198 Flags |= ItaniumRTTIBuilder::PTI_Noexcept;
4208void ItaniumRTTIBuilder::BuildPointerTypeInfo(
QualType PointeeTy) {
4214 llvm::Type *UnsignedIntLTy =
4216 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
4221 llvm::Constant *PointeeTypeInfo =
4222 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(PointeeTy);
4223 Fields.push_back(PointeeTypeInfo);
4239 Flags |= PTI_ContainingClassIncomplete;
4241 llvm::Type *UnsignedIntLTy =
4243 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
4248 llvm::Constant *PointeeTypeInfo =
4249 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(PointeeTy);
4250 Fields.push_back(PointeeTypeInfo);
4257 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(
QualType(ClassType, 0)));
4260llvm::Constant *ItaniumCXXABI::getAddrOfRTTIDescriptor(
QualType Ty) {
4261 return ItaniumRTTIBuilder(*this).BuildTypeInfo(Ty);
4264void ItaniumCXXABI::EmitFundamentalRTTIDescriptors(
const CXXRecordDecl *RD) {
4267 getContext().VoidTy, getContext().NullPtrTy,
4268 getContext().BoolTy, getContext().WCharTy,
4269 getContext().CharTy, getContext().UnsignedCharTy,
4270 getContext().SignedCharTy, getContext().ShortTy,
4271 getContext().UnsignedShortTy, getContext().IntTy,
4272 getContext().UnsignedIntTy, getContext().LongTy,
4273 getContext().UnsignedLongTy, getContext().LongLongTy,
4274 getContext().UnsignedLongLongTy, getContext().Int128Ty,
4275 getContext().UnsignedInt128Ty, getContext().HalfTy,
4276 getContext().FloatTy, getContext().DoubleTy,
4277 getContext().LongDoubleTy, getContext().Float128Ty,
4278 getContext().Char8Ty, getContext().Char16Ty,
4279 getContext().Char32Ty
4281 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass =
4283 ? llvm::GlobalValue::DLLExportStorageClass
4284 : llvm::GlobalValue::DefaultStorageClass;
4285 llvm::GlobalValue::VisibilityTypes
Visibility =
4287 for (
const QualType &FundamentalType : FundamentalTypes) {
4289 QualType PointerTypeConst = getContext().getPointerType(
4290 FundamentalType.withConst());
4292 ItaniumRTTIBuilder(*this).BuildTypeInfo(
4293 Type, llvm::GlobalValue::ExternalLinkage,
4300ItaniumCXXABI::RTTIUniquenessKind ItaniumCXXABI::classifyRTTIUniqueness(
4302 if (shouldRTTIBeUnique())
4306 if (
Linkage != llvm::GlobalValue::LinkOnceODRLinkage &&
4307 Linkage != llvm::GlobalValue::WeakODRLinkage)
4315 if (
Linkage == llvm::GlobalValue::LinkOnceODRLinkage)
4316 return RUK_NonUniqueHidden;
4321 assert(
Linkage == llvm::GlobalValue::WeakODRLinkage);
4322 return RUK_NonUniqueVisible;
4327enum class StructorCodegen { Emit, RAUW, Alias, COMDAT };
4332 return StructorCodegen::Emit;
4337 return StructorCodegen::Emit;
4340 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
4343 const auto *CD = cast<CXXConstructorDecl>(MD);
4348 if (llvm::GlobalValue::isDiscardableIfUnused(
Linkage))
4349 return StructorCodegen::RAUW;
4352 if (!llvm::GlobalAlias::isValidLinkage(
Linkage))
4353 return StructorCodegen::RAUW;
4355 if (llvm::GlobalValue::isWeakForLinker(
Linkage)) {
4359 return StructorCodegen::COMDAT;
4360 return StructorCodegen::Emit;
4363 return StructorCodegen::Alias;
4373 if (Entry && !Entry->isDeclaration())
4376 auto *Aliasee = cast<llvm::GlobalValue>(CGM.
GetAddrOfGlobal(TargetDecl));
4379 auto *Alias = llvm::GlobalAlias::create(
Linkage,
"", Aliasee);
4382 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4386 assert(Entry->getType() == Aliasee->getType() &&
4387 "declaration exists with different type");
4388 Alias->takeName(Entry);
4389 Entry->replaceAllUsesWith(Alias);
4390 Entry->eraseFromParent();
4392 Alias->setName(MangledName);
4399void ItaniumCXXABI::emitCXXStructor(
GlobalDecl GD) {
4400 auto *MD = cast<CXXMethodDecl>(GD.
getDecl());
4401 auto *CD = dyn_cast<CXXConstructorDecl>(MD);
4414 if (CGType == StructorCodegen::Alias || CGType == StructorCodegen::COMDAT) {
4419 if (CGType == StructorCodegen::RAUW) {
4432 CGType != StructorCodegen::COMDAT &&
4450 if (CGType == StructorCodegen::COMDAT) {
4452 llvm::raw_svector_ostream Out(Buffer);
4454 getMangleContext().mangleCXXDtorComdat(DD, Out);
4456 getMangleContext().mangleCXXCtorComdat(CD, Out);
4457 llvm::Comdat *
C = CGM.
getModule().getOrInsertComdat(Out.str());
4466 llvm::FunctionType *FTy = llvm::FunctionType::get(
4474 llvm::FunctionType *FTy =
4475 llvm::FunctionType::get(CGM.
VoidTy,
false);
4482 llvm::FunctionType *FTy = llvm::FunctionType::get(
4502 CallEndCatch(
bool MightThrow) : MightThrow(MightThrow) {}
4524 bool EndMightThrow) {
4525 llvm::CallInst *call =
4528 CGF.
EHStack.pushCleanup<CallEndCatch>(
4530 EndMightThrow && !CGF.
CGM.
getLangOpts().AssumeNothrowExceptionDtor);
4550 if (isa<ReferenceType>(CatchType)) {
4555 llvm::Value *AdjustedExn =
CallBeginCatch(CGF, Exn, EndCatchMightThrow);
4560 if (
const PointerType *PT = dyn_cast<PointerType>(CaughtType)) {
4569 unsigned HeaderSize =
4572 CGF.
Builder.CreateConstGEP1_32(CGF.
Int8Ty, Exn, HeaderSize);
4595 llvm::Value *Casted = CGF.
Builder.CreateBitCast(AdjustedExn, PtrTy);
4603 llvm::Value *ExnCast =
4604 CGF.
Builder.CreateBitCast(AdjustedExn, LLVMCatchTy,
"exn.byref");
4616 if (CatchType->hasPointerRepresentation()) {
4617 llvm::Value *CastExn =
4618 CGF.
Builder.CreateBitCast(AdjustedExn, LLVMCatchTy,
"exn.casted");
4635 llvm_unreachable(
"bad ownership qualifier!");
4653 llvm_unreachable(
"evaluation kind filtered out!");
4655 llvm_unreachable(
"bad evaluation kind");
4658 assert(isa<RecordType>(CatchType) &&
"unexpected catch type!");
4659 auto catchRD = CatchType->getAsCXXRecordDecl();
4669 Address adjustedExn(CGF.
Builder.CreateBitCast(rawAdjustedExn, PtrTy),
4670 LLVMCatchTy, caughtExnAlignment);
4679 llvm::CallInst *rawAdjustedExn =
4683 Address adjustedExn(CGF.
Builder.CreateBitCast(rawAdjustedExn, PtrTy),
4684 LLVMCatchTy, caughtExnAlignment);
4688 CodeGenFunction::OpaqueValueMapping
4740 VarDecl *CatchParam = S->getExceptionDecl();
4749 InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF), S->getBeginLoc());
4759 C.VoidTy, {C.getPointerType(C.CharTy)});
4762 fnTy,
"__clang_call_terminate", llvm::AttributeList(),
true);
4763 llvm::Function *fn =
4764 cast<llvm::Function>(fnRef.getCallee()->stripPointerCasts());
4768 fn->setDoesNotThrow();
4769 fn->setDoesNotReturn();
4774 fn->addFnAttr(llvm::Attribute::NoInline);
4778 fn->setLinkage(llvm::Function::LinkOnceODRLinkage);
4779 fn->setVisibility(llvm::Function::HiddenVisibility);
4781 fn->setComdat(CGM.
getModule().getOrInsertComdat(fn->getName()));
4784 llvm::BasicBlock *entry =
4789 llvm::Value *exn = &*fn->arg_begin();
4792 llvm::CallInst *catchCall = builder.CreateCall(
getBeginCatchFn(CGM), exn);
4793 catchCall->setDoesNotThrow();
4797 llvm::CallInst *termCall = builder.CreateCall(CGM.
getTerminateFn());
4798 termCall->setDoesNotThrow();
4799 termCall->setDoesNotReturn();
4803 builder.CreateUnreachable();
4809ItaniumCXXABI::emitTerminateForUnexpectedException(
CodeGenFunction &CGF,
4819std::pair<llvm::Value *, const CXXRecordDecl *>
4830 ItaniumCXXABI::emitBeginCatch(CGF,
C);
4834WebAssemblyCXXABI::emitTerminateForUnexpectedException(
CodeGenFunction &CGF,
4847 llvm::FunctionCallee Dtor,
4848 llvm::Constant *Addr) {
4853 llvm::FunctionType *AtExitTy =
4854 llvm::FunctionType::get(CGM.
IntTy, {CGM.IntTy, PtrTy},
true);
4857 llvm::FunctionCallee
AtExit =
4865 llvm::Value *NV = llvm::Constant::getNullValue(CGM.
IntTy);
4880 emitCXXStermFinalizer(D, DtorStub, Addr);
4883void XLCXXABI::emitCXXStermFinalizer(
const VarDecl &D, llvm::Function *dtorStub,
4884 llvm::Constant *addr) {
4885 llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.
VoidTy,
false);
4888 llvm::raw_svector_ostream Out(FnName);
4889 getMangleContext().mangleDynamicStermFinalizer(&D, Out);
4909 llvm::Value *NeedsDestruct = CGF.
Builder.CreateIsNull(
V,
"needs_destruct");
4911 llvm::BasicBlock *DestructCallBlock = CGF.
createBasicBlock(
"destruct.call");
4916 CGF.
Builder.CreateCondBr(NeedsDestruct, DestructCallBlock, EndBlock);
4921 llvm::CallInst *CI = CGF.
Builder.CreateCall(dtorStub);
4924 CI->setCallingConv(dtorStub->getCallingConv());
4930 if (
auto *IPA = D.
getAttr<InitPriorityAttr>()) {
4932 IPA->getPriority());
static StructorCodegen getCodegenToUse(CodeGenModule &CGM, const CXXMethodDecl *MD)
static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction &CGF)
static llvm::FunctionCallee getClangCallTerminateFn(CodeGenModule &CGM)
Get or define the following function: void @__clang_call_terminate(i8* exn) nounwind noreturn This co...
static llvm::Value * performTypeAdjustment(CodeGenFunction &CGF, Address InitialPtr, int64_t NonVirtualAdjustment, int64_t VirtualAdjustment, bool IsReturnAdjustment)
static unsigned extractPBaseFlags(ASTContext &Ctx, QualType &Type)
Compute the flags for a __pbase_type_info, and remove the corresponding pieces from Type.
static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM, QualType Ty)
ShouldUseExternalRTTIDescriptor - Returns whether the type information for the given type exists some...
static bool IsIncompleteClassType(const RecordType *RecordTy)
IsIncompleteClassType - Returns whether the given record type is incomplete.
static unsigned ComputeVMIClassTypeInfoFlags(const CXXBaseSpecifier *Base, SeenBases &Bases)
ComputeVMIClassTypeInfoFlags - Compute the value of the flags member in abi::__vmi_class_type_info.
static llvm::FunctionCallee getBadTypeidFn(CodeGenFunction &CGF)
static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF, llvm::FunctionCallee dtor, llvm::Constant *addr, bool TLS)
Register a global destructor using __cxa_atexit.
static llvm::FunctionCallee getBadCastFn(CodeGenFunction &CGF)
static llvm::FunctionCallee getBeginCatchFn(CodeGenModule &CGM)
static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty)
Return the linkage that the type info and type info name constants should have for the given type.
static llvm::FunctionCallee getGuardReleaseFn(CodeGenModule &CGM, llvm::PointerType *GuardPtrTy)
static llvm::Function * createGlobalInitOrCleanupFn(CodeGen::CodeGenModule &CGM, StringRef FnName)
static llvm::FunctionCallee getAllocateExceptionFn(CodeGenModule &CGM)
static bool IsStandardLibraryRTTIDescriptor(QualType Ty)
IsStandardLibraryRTTIDescriptor - Returns whether the type information for the given type exists in t...
static llvm::Value * CallBeginCatch(CodeGenFunction &CGF, llvm::Value *Exn, bool EndMightThrow)
Emits a call to __cxa_begin_catch and enters a cleanup to call __cxa_end_catch.
static llvm::FunctionCallee getGuardAbortFn(CodeGenModule &CGM, llvm::PointerType *GuardPtrTy)
static CharUnits computeOffsetHint(ASTContext &Context, const CXXRecordDecl *Src, const CXXRecordDecl *Dst)
Compute the src2dst_offset hint as described in the Itanium C++ ABI [2.9.7].
static bool isThreadWrapperReplaceable(const VarDecl *VD, CodeGen::CodeGenModule &CGM)
static bool CXXRecordAllNonInlineVirtualsHaveAttr(const CXXRecordDecl *RD)
static void InitCatchParam(CodeGenFunction &CGF, const VarDecl &CatchParam, Address ParamAddr, SourceLocation Loc)
A "special initializer" callback for initializing a catch parameter during catch initialization.
static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty)
TypeInfoIsInStandardLibrary - Given a builtin type, returns whether the type info for that type is de...
static bool CanUseSingleInheritance(const CXXRecordDecl *RD)
static llvm::FunctionCallee getEndCatchFn(CodeGenModule &CGM)
static llvm::GlobalValue::LinkageTypes getThreadLocalWrapperLinkage(const VarDecl *VD, CodeGen::CodeGenModule &CGM)
Get the appropriate linkage for the wrapper function.
static llvm::FunctionCallee getThrowFn(CodeGenModule &CGM)
static llvm::FunctionCallee getGuardAcquireFn(CodeGenModule &CGM, llvm::PointerType *GuardPtrTy)
static bool ContainsIncompleteClassType(QualType Ty)
ContainsIncompleteClassType - Returns whether the given type contains an incomplete class type.
static void emitConstructorDestructorAlias(CodeGenModule &CGM, GlobalDecl AliasDecl, GlobalDecl TargetDecl)
static llvm::FunctionCallee getGetExceptionPtrFn(CodeGenModule &CGM)
static void dtorTy(Block *, std::byte *Ptr, const Descriptor *)
llvm::MachO::Record Record
static uint64_t getFieldOffset(const ASTContext &C, const FieldDecl *FD)
static const RecordType * getRecordType(QualType QT)
Checks that the passed in QualType either is of RecordType or points to RecordType.
static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D)
Determine what kind of template specialization the given declaration is.
#define CXXABI(Name, Str)
C Language Family Type Representation.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const ValueDecl * getMemberPointerDecl() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
QualType getFunctionTypeWithExceptionSpec(QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) const
Get a function type and produce the equivalent function type with the specified exception specificati...
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
CharUnits getExnObjectAlignment() const
Return the alignment (in bytes) of the thrown exception object.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
CharUnits getPreferredTypeAlignInChars(QualType T) const
Return the PreferredAlignment of a (complete) type T, in characters.
CanQualType UnsignedIntTy
const TargetInfo & getTargetInfo() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
TargetCXXABI::Kind getCXXABIKind() const
Return the C++ ABI kind that should be used.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
This class is used for builtin types like 'int'.
Implements C++ ABI-specific semantic analysis functions.
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a base class of a C++ class.
QualType getType() const
Retrieves the type of the base class.
CXXCatchStmt - This represents a C++ catch block.
Represents a C++ constructor within a class.
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.
Represents a call to a member function that may be written either with member call syntax (e....
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.
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Represents a C++ struct/union/class.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_iterator bases_begin()
base_class_range vbases()
bool isAbstract() const
Determine whether this class has a pure virtual function.
bool isDynamicClass() const
bool hasDefinition() const
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
static CanQual< Type > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
Qualifiers getQualifiers() const
Retrieve all qualifiers.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
std::string SymbolPartition
The name of the partition that symbols are assigned to, specified with -fsymbol-partition (see https:...
static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
unsigned getAddressSpace() const
Return the address space that this address resides in.
llvm::Value * getPointer() const
llvm::PointerType * getType() const
Return the type of the pointer value.
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
Address CreateGEP(Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
Implements C++ ABI-specific code generation functions.
virtual bool shouldEmitExactDynamicCast(QualType DestRecordTy)=0
virtual void EmitCXXConstructors(const CXXConstructorDecl *D)=0
Emit constructor variants required by this ABI.
virtual llvm::Constant * getAddrOfRTTIDescriptor(QualType Ty)=0
virtual llvm::Value * performReturnAdjustment(CodeGenFunction &CGF, Address Ret, const ReturnAdjustment &RA)=0
virtual llvm::Value * getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base, const CXXRecordDecl *NearestVBase)=0
Get the address point of the vtable for the given base subobject while building a constructor or a de...
virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C)=0
virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn)=0
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, FunctionArgList &Args) const =0
virtual bool isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF, CodeGenFunction::VPtr Vptr)=0
Checks if ABI requires extra virtual offset for vtable field.
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)=0
Emits the guarded initializer and destructor setup for the given variable, given that it couldn't be ...
virtual void EmitCXXDestructors(const CXXDestructorDecl *D)=0
Emit destructor variants required by this ABI.
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor, CXXDtorType DT) const =0
Returns true if the given destructor type should be emitted as a linkonce delegating thunk,...
virtual bool NeedsVTTParameter(GlobalDecl GD)
Return whether the given global decl needs a VTT parameter.
virtual llvm::CallInst * emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn)
@ RAA_Default
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
@ RAA_Indirect
Pass it as a pointer to temporary memory.
virtual llvm::Type * ConvertMemberPointerType(const MemberPointerType *MPT)
Find the LLVM type used to represent the given member pointer type.
virtual llvm::Constant * EmitNullMemberPointer(const MemberPointerType *MPT)
Create a null member pointer of the given type.
virtual StringRef GetPureVirtualCallName()=0
Gets the pure virtual member call function.
virtual CharUnits getArrayCookieSizeImpl(QualType elementType)
Returns the extra size required in order to store the array cookie for the given type.
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const =0
Determine whether it's possible to emit a vtable for RD, even though we do not know that the vtable h...
virtual StringRef GetDeletedVirtualCallName()=0
Gets the deleted virtual member call name.
virtual llvm::Value * EmitMemberPointerIsNotNull(CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)
Determine if a member pointer is non-null. Returns an i1.
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType)=0
Emit a reference to a non-local thread_local variable (including triggering the initialization of all...
bool isEmittedWithConstantInitializer(const VarDecl *VD, bool InspectInitForWeakDef=false) const
Determine whether we will definitely emit this variable with a constant initializer,...
virtual llvm::Value * EmitMemberPointerComparison(CodeGenFunction &CGF, llvm::Value *L, llvm::Value *R, const MemberPointerType *MPT, bool Inequality)
Emit a comparison between two member pointers. Returns an i1.
virtual llvm::Constant * EmitMemberPointer(const APValue &MP, QualType MPT)
Create a member pointer for the given member pointer constant.
virtual llvm::Constant * getVTableAddressPoint(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Get the address point of the vtable for the given base subobject.
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
virtual llvm::Value * readArrayCookieImpl(CodeGenFunction &IGF, Address ptr, CharUnits cookieSize)
Reads the array cookie for an allocation which is known to have one.
virtual llvm::Value * EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, Address Base, llvm::Value *MemPtr, const MemberPointerType *MPT)
Calculate an l-value from an object and a data member pointer.
virtual llvm::Value * getCXXDestructorImplicitParam(CodeGenFunction &CGF, const CXXDestructorDecl *DD, CXXDtorType Type, bool ForVirtualBase, bool Delegating)=0
Get the implicit (second) parameter that comes after the "this" pointer, or nullptr if there is isn't...
virtual std::pair< llvm::Value *, const CXXRecordDecl * > LoadVTablePtr(CodeGenFunction &CGF, Address This, const CXXRecordDecl *RD)=0
Load a vtable from This, an object of polymorphic type RD, or from one of its virtual bases if it doe...
virtual llvm::Constant * getVTableAddressPointForConstExpr(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Get the address point of the vtable for the given base subobject while building a constexpr.
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD, bool ReturnAdjustment)=0
virtual llvm::Value * EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, Address This, DeleteOrMemberCallExpr E)=0
Emit the ABI-specific virtual destructor call.
bool mayNeedDestruction(const VarDecl *VD) const
virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass)=0
Checks if ABI requires to initialize vptrs for given dynamic class.
virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E)=0
virtual llvm::Value * GetVirtualBaseClassOffset(CodeGenFunction &CGF, Address This, const CXXRecordDecl *ClassDecl, const CXXRecordDecl *BaseClassDecl)=0
virtual bool isThisCompleteObject(GlobalDecl GD) const =0
Determine whether there's something special about the rules of the ABI tell us that 'this' is a compl...
virtual CGCallee getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD, Address This, llvm::Type *Ty, SourceLocation Loc)=0
Build a virtual function pointer in the ABI-specific way.
virtual bool classifyReturnType(CGFunctionInfo &FI) const =0
If the C++ ABI requires the given type be returned in a particular way, this method sets RetAI and re...
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
virtual CatchTypeInfo getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)=0
virtual void EmitThreadLocalInitFuncs(CodeGenModule &CGM, ArrayRef< const VarDecl * > CXXThreadLocals, ArrayRef< llvm::Function * > CXXThreadLocalInits, ArrayRef< const VarDecl * > CXXThreadLocalInitVars)=0
Emits ABI-required functions necessary to initialize thread_local variables in this translation unit.
virtual bool usesThreadWrapperFunction(const VarDecl *VD) const =0
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
virtual llvm::Value * emitExactDynamicCast(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastSuccess, llvm::BasicBlock *CastFail)=0
Emit a dynamic_cast from SrcRecordTy to DestRecordTy.
virtual void EmitDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *DD, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)=0
Emit the destructor call.
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)
Create a member pointer for the given field.
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, Address ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD)=0
Emit any tables needed to implement virtual inheritance.
virtual void emitVTableDefinitions(CodeGenVTables &CGVT, const CXXRecordDecl *RD)=0
Emits the VTable definitions required for the given record type.
virtual CGCallee EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, const Expr *E, Address This, llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, const MemberPointerType *MPT)
Load a member function from an object and a member function pointer.
virtual void emitCXXStructor(GlobalDecl GD)=0
Emit a single constructor/destructor with the given type from a C++ constructor Decl.
virtual bool exportThunk()=0
virtual void EmitBadTypeidCall(CodeGenFunction &CGF)=0
virtual llvm::Value * emitDynamicCastToVoid(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy)=0
virtual bool isZeroInitializable(const MemberPointerType *MPT)
Return true if the given member pointer can be zero-initialized (in the C++ sense) with an LLVM zeroi...
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
virtual llvm::Value * EmitMemberPointerConversion(CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)
Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion.
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
virtual llvm::Value * emitDynamicCastCall(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd)=0
virtual Address InitializeArrayCookie(CodeGenFunction &CGF, Address NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
Initialize the array cookie for the given allocation.
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, QualType SrcRecordTy)=0
virtual AddedStructorArgCounts buildStructorSignature(GlobalDecl GD, SmallVectorImpl< CanQualType > &ArgTys)=0
Build the signature of the given constructor or destructor variant by adding any required parameters.
virtual llvm::Value * performThisAdjustment(CodeGenFunction &CGF, Address This, const ThisAdjustment &TA)=0
MangleContext & getMangleContext()
Gets the mangle context.
virtual AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating)=0
All available information about a concrete callee.
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
CGFunctionInfo - Class to encapsulate the information about a function definition.
ABIArgInfo & getReturnInfo()
CanQualType getReturnType() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void GenerateCXXGlobalInitFunc(llvm::Function *Fn, ArrayRef< llvm::Function * > CXXThreadLocals, ConstantAddress Guard=ConstantAddress::invalid())
GenerateCXXGlobalInitFunc - Generates code for initializing global variables.
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
SanitizerSet SanOpts
Sanitizers enabled for this function.
void EmitAnyExprToExn(const Expr *E, Address Addr)
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
llvm::Value * EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy, uint64_t VTableByteOffset)
Emit a type checked load from the given vtable.
llvm::Value * GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, bool Delegating)
GetVTTParameter - Return the VTT parameter that should be passed to a base constructor/destructor wit...
llvm::Type * ConvertTypeForMem(QualType T)
llvm::Function * createTLSAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr, llvm::FunctionCallee &AtExit)
void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Registers the dtor using 'llvm.global_dtors' for platforms that do not support an 'atexit()' function...
const TargetInfo & getTarget() const
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
llvm::Function * createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Call atexit() with a function that passes the given argument to the given function.
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
llvm::Value * unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub)
Call unatexit() with function dtorStub.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
ASTContext & getContext() const
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
llvm::Value * LoadCXXVTT()
LoadCXXVTT - Load the VTT parameter to base constructors/destructors have virtual bases.
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
void EmitAutoVarCleanups(const AutoVarEmission &emission)
void EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, llvm::Value *VTable, SourceLocation Loc)
If whole-program virtual table optimization is enabled, emit an assumption that VTable is a member of...
llvm::Type * ConvertType(QualType T)
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args)
CodeGenTypes & getTypes() const
void EmitARCInitWeak(Address addr, llvm::Value *value)
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass)
GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.
llvm::Instruction * CurrentFuncletPad
llvm::LLVMContext & getLLVMContext()
llvm::Value * getExceptionFromSlot()
Returns the contents of the function's exception object and selector slots.
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, llvm::BasicBlock *InitBlock, llvm::BasicBlock *NoInitBlock, GuardKind Kind, const VarDecl *D)
Emit a branch to select whether or not to perform guarded initialization.
This class organizes the cross-function state that is used while generating LLVM code.
void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer, int Priority)
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer, int Priority)
Add an sterm finalizer to its own llvm.global_dtors entry.
llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const
Get LLVM TLS mode from CodeGenOptions.
void setDSOLocal(llvm::GlobalValue *GV) const
llvm::Module & getModule() const
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
CodeGenVTables & getVTables()
void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn)
Add an sterm finalizer to the C++ global cleanup function.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
bool shouldMapVisibilityToDLLExport(const NamedDecl *D) const
const TargetInfo & getTarget() const
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
const llvm::DataLayout & getDataLayout() const
CGCXXABI & getCXXABI() const
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V)
llvm::Function * codegenCXXStructor(GlobalDecl GD)
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
const llvm::Triple & getTriple() const
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535, bool IsDtorAttrFunc=false)
AddGlobalDtor - Add a function to the list that will be called when the module is unloaded.
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, const CXXRecordDecl *Class, CharUnits ExpectedTargetAlign)
Given a class pointer with an actual known alignment, and the expected alignment of an object at a dy...
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
ItaniumVTableContext & getItaniumVTableContext()
ASTContext & getContext() const
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
bool supportsCOMDAT() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, llvm::Align Alignment)
Will return a global variable of the given type.
llvm::FunctionCallee getTerminateFn()
Get the declaration of std::terminate for the platform.
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
LangAS GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
void addReplacement(StringRef Name, llvm::Constant *C)
void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535, unsigned LexOrder=~0U, llvm::Constant *AssociatedData=nullptr)
AddGlobalCtor - Add a function to the list that will be called before main() runs.
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::Function * CreateGlobalInitOrCleanUpFunction(llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, SourceLocation Loc=SourceLocation(), bool TLS=false, llvm::GlobalVariable::LinkageTypes Linkage=llvm::GlobalVariable::InternalLinkage)
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
const CodeGenOptions & getCodeGenOpts() const
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
void createVTableInitializer(ConstantStructBuilder &builder, const VTableLayout &layout, llvm::Constant *rtti, bool vtableHasLocalLinkage)
Add vtable components for the given vtable layout to the given global initializer.
void GenerateRelativeVTableAlias(llvm::GlobalVariable *VTable, llvm::StringRef AliasNameRef)
Generate a public facing alias for the vtable and make the vtable either hidden or private.
bool isVTableExternal(const CXXRecordDecl *RD)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
void RemoveHwasanMetadata(llvm::GlobalValue *GV) const
Specify a global should not be instrumented with hwasan.
void EmitVTTDefinition(llvm::GlobalVariable *VTT, llvm::GlobalVariable::LinkageTypes Linkage, const CXXRecordDecl *RD)
EmitVTTDefinition - Emit the definition of the given vtable.
A specialization of Address that requires the address to be an LLVM Constant.
The standard implementation of ConstantInitBuilder used in Clang.
Information for lazily generating a cleanup.
void popTerminate()
Pops a terminate handler off the stack.
void pushTerminate()
Push a terminate handler on the stack.
FunctionArgList - Type for representing both the decl and type of parameters to a function.
LValue - This represents an lvalue references.
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
virtual unsigned getSizeOfUnwindException() const
Determines the size of struct _Unwind_Exception on this platform, in 8-bit units.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isTranslationUnit() const
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
SourceLocation getLocation() const
DeclContext * getDeclContext()
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Represents a prototype with parameter type info, e.g.
GlobalDecl - represents a global declaration.
GlobalDecl getWithCtorType(CXXCtorType Type)
CXXCtorType getCtorType() const
GlobalDecl getWithDtorType(CXXDtorType Type)
CXXDtorType getDtorType() const
const Decl * getDecl() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
bool isRelativeLayout() const
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
virtual void mangleCXXRTTI(QualType T, raw_ostream &)=0
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
A pointer to member type per C++ 8.3.3 - Pointers to members.
QualType getPointeeType() const
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
bool isMemberDataPointer() const
Returns true if the member type (i.e.
const Type * getClass() const
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Visibility getVisibility() const
Determines the visibility of this entity.
Represents an ObjC class declaration.
Represents a class type in Objective C.
QualType getBaseType() const
Gets the base type of this object type.
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
The collection of all-type qualifiers we support.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
ObjCLifetime getObjCLifetime() const
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
Encodes a location in the source.
SourceLocation getBeginLoc() const LLVM_READONLY
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Exposes information about the current target.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
unsigned getMaxAtomicInlineWidth() const
Return the maximum width lock-free atomic operation which can be inlined given the supported features...
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool hasPS4DLLImportExport() const
uint64_t getPointerAlign(LangAS AddrSpace) const
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Visibility getVisibility() const
Determine the visibility of this type.
Linkage getLinkage() const
Determine the linkage of this type.
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
TLSKind getTLSKind() const
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed? If so, the variable need not have a usable destr...
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
bool isInline() const
Whether this variable is (C++1z) inline.
const Expr * getInit() const
@ TLS_Dynamic
TLS with a dynamic initializer.
@ TLS_None
Not a TLS variable.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
CGCXXABI * CreateItaniumCXXABI(CodeGenModule &CGM)
Creates an Itanium-family ABI.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
bool This(InterpState &S, CodePtr OpPC)
bool Zero(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_DefaultClosure
Default closure variant of a ctor.
@ Ctor_CopyingClosure
Copying closure variant of a ctor.
@ Ctor_Complete
Complete object ctor.
@ Ctor_Comdat
The COMDAT used for ctors.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ VisibleNone
No linkage according to the standard, but is visible from other translation units because of types de...
@ None
No linkage, which means that the entity is unique and can only be referred to from within its scope.
@ UniqueExternal
External linkage within a unique namespace.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
CXXDtorType
C++ destructor types.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
bool isDiscardableGVALinkage(GVALinkage L)
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ Success
Template argument deduction was successful.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ EST_None
no exception specification
Visibility
Describes the different kinds of visibility that a declaration may have.
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
Represents an element in a path from a derived class to a base class.
Similar to AddedStructorArgs, but only notes the number of additional arguments.
Additional implicit arguments to add to the beginning (Prefix) and end (Suffix) of a constructor / de...
The MS C++ ABI needs a pointer to RTTI data plus some flags to describe the type of a catch handler,...
llvm::PointerType * VoidPtrTy
llvm::IntegerType * Int64Ty
llvm::PointerType * GlobalsVoidPtrTy
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * CharTy
char
llvm::CallingConv::ID getRuntimeCC() const
llvm::IntegerType * SizeTy
llvm::PointerType * VoidPtrPtrTy
llvm::PointerType * GlobalsInt8PtrTy
llvm::IntegerType * Int32Ty
llvm::IntegerType * IntPtrTy
llvm::IntegerType * IntTy
int
CharUnits getSizeSize() const
CharUnits getSizeAlign() const
llvm::PointerType * Int8PtrTy
llvm::PointerType * UnqualPtrTy
CharUnits getPointerAlign() const
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
A this pointer adjustment.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
unsigned AddressPointIndex
struct clang::ReturnAdjustment::VirtualAdjustment::@183 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@185 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.