32#include "llvm/ADT/StringExtras.h"
33#include "llvm/ADT/StringSet.h"
34#include "llvm/IR/Intrinsics.h"
42struct VBTableGlobals {
44 SmallVector<llvm::GlobalVariable *, 2> Globals;
47class MicrosoftCXXABI :
public CGCXXABI {
49 MicrosoftCXXABI(CodeGenModule &CGM)
50 : CGCXXABI(CGM), BaseClassDescriptorType(
nullptr),
51 ClassHierarchyDescriptorType(
nullptr),
56 "visibility export mapping option unimplemented in this ABI");
59 bool HasThisReturn(GlobalDecl GD)
const override;
60 bool hasMostDerivedReturn(GlobalDecl GD)
const override;
66 bool isSRetParameterAfterThis()
const override {
return true; }
68 bool isThisCompleteObject(GlobalDecl GD)
const override {
80 case Dtor_Comdat: llvm_unreachable(
"emitting dtor comdat as function?");
82 llvm_unreachable(
"unexpected unified dtor type");
84 llvm_unreachable(
"bad dtor kind");
91 size_t getSrcArgforCopyCtor(
const CXXConstructorDecl *CD,
92 FunctionArgList &Args)
const override {
93 assert(Args.size() >= 2 &&
94 "expected the arglist to have at least two args!");
103 std::vector<CharUnits> getVBPtrOffsets(
const CXXRecordDecl *RD)
override {
104 std::vector<CharUnits> VBPtrOffsets;
105 const ASTContext &Context = getContext();
106 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
108 const VBTableGlobals &VBGlobals = enumerateVBTables(RD);
109 for (
const std::unique_ptr<VPtrInfo> &VBT : *VBGlobals.VBTables) {
110 const ASTRecordLayout &SubobjectLayout =
111 Context.getASTRecordLayout(VBT->IntroducingObject);
112 CharUnits Offs = VBT->NonVirtualOffset;
114 if (VBT->getVBaseWithVPtr())
116 VBPtrOffsets.push_back(Offs);
118 llvm::array_pod_sort(VBPtrOffsets.begin(), VBPtrOffsets.end());
122 StringRef GetPureVirtualCallName()
override {
return "_purecall"; }
123 StringRef GetDeletedVirtualCallName()
override {
return "_purecall"; }
125 void emitVirtualObjectDelete(CodeGenFunction &CGF,
const CXXDeleteExpr *DE,
126 Address Ptr, QualType ElementType,
127 const CXXDestructorDecl *Dtor)
override;
129 void emitRethrow(CodeGenFunction &CGF,
bool isNoReturn)
override;
130 void emitThrow(CodeGenFunction &CGF,
const CXXThrowExpr *E)
override;
132 void emitBeginCatch(CodeGenFunction &CGF,
const CXXCatchStmt *
C)
override;
134 llvm::GlobalVariable *getMSCompleteObjectLocator(
const CXXRecordDecl *RD,
135 const VPtrInfo &Info);
137 llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty)
override;
139 getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)
override;
142 CatchTypeInfo getCatchAllTypeInfo()
override {
145 if (getContext().getLangOpts().EHAsynch)
146 return CatchTypeInfo{
nullptr, 0};
148 return CatchTypeInfo{
nullptr, 0x40};
151 bool shouldTypeidBeNullChecked(QualType SrcRecordTy)
override;
152 void EmitBadTypeidCall(CodeGenFunction &CGF)
override;
153 llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
155 llvm::Type *StdTypeInfoPtrTy)
override;
157 bool shouldDynamicCastCallBeNullChecked(
bool SrcIsPtr,
158 QualType SrcRecordTy)
override;
160 bool shouldEmitExactDynamicCast(QualType DestRecordTy)
override {
164 std::optional<ExactDynamicCastInfo>
165 getExactDynamicCastInfo(QualType SrcRecordTy, QualType DestTy,
166 QualType DestRecordTy)
override {
167 llvm_unreachable(
"unsupported");
170 QualType SrcRecordTy, QualType DestTy,
171 QualType DestRecordTy,
172 const ExactDynamicCastInfo &CastInfo,
173 llvm::BasicBlock *CastSuccess,
174 llvm::BasicBlock *CastFail)
override {
175 llvm_unreachable(
"unsupported");
178 llvm::Value *emitDynamicCastCall(CodeGenFunction &CGF, Address
Value,
179 QualType SrcRecordTy, QualType DestTy,
180 QualType DestRecordTy,
181 llvm::BasicBlock *CastEnd)
override;
184 QualType SrcRecordTy)
override;
186 bool EmitBadCastCall(CodeGenFunction &CGF)
override;
187 bool canSpeculativelyEmitVTable(
const CXXRecordDecl *RD)
const override {
192 GetVirtualBaseClassOffset(CodeGenFunction &CGF, Address This,
193 const CXXRecordDecl *ClassDecl,
194 const CXXRecordDecl *BaseClassDecl)
override;
197 EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
198 const CXXRecordDecl *RD)
override;
201 EmitDtorCompleteObjectHandler(CodeGenFunction &CGF);
203 void initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
204 const CXXRecordDecl *RD)
override;
206 void EmitCXXConstructors(
const CXXConstructorDecl *D)
override;
240 AddedStructorArgCounts
241 buildStructorSignature(GlobalDecl GD,
242 SmallVectorImpl<CanQualType> &ArgTys)
override;
245 bool useThunkForDtorVariant(
const CXXDestructorDecl *Dtor,
250 void setCXXDestructorDLLStorage(llvm::GlobalValue *GV,
251 const CXXDestructorDecl *Dtor,
254 llvm::GlobalValue::LinkageTypes
258 void EmitCXXDestructors(
const CXXDestructorDecl *D)
override;
260 const CXXRecordDecl *getThisArgumentTypeForMethod(GlobalDecl GD)
override {
263 if (MD->isVirtual()) {
264 GlobalDecl LookupGD = GD;
265 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
269 return MD->getParent();
273 LookupGD = GlobalDecl(
279 MethodVFTableLocation ML =
291 return MD->getParent();
295 adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD,
297 bool VirtualCall)
override;
299 void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
300 FunctionArgList &Params)
override;
302 void EmitInstanceFunctionProlog(CodeGenFunction &CGF)
override;
304 AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF,
305 const CXXConstructorDecl *D,
311 const CXXDestructorDecl *DD,
316 void EmitDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *DD,
319 QualType ThisTy)
override;
321 void emitVTableTypeMetadata(
const VPtrInfo &Info,
const CXXRecordDecl *RD,
322 llvm::GlobalVariable *VTable);
324 void emitVTableDefinitions(CodeGenVTables &CGVT,
325 const CXXRecordDecl *RD)
override;
327 bool isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
328 CodeGenFunction::VPtr Vptr)
override;
332 bool doStructorsInitializeVPtrs(
const CXXRecordDecl *VTableClass)
override {
333 return !VTableClass->
hasAttr<MSNoVTableAttr>();
337 getVTableAddressPoint(BaseSubobject Base,
338 const CXXRecordDecl *VTableClass)
override;
340 llvm::Value *getVTableAddressPointInStructor(
341 CodeGenFunction &CGF,
const CXXRecordDecl *VTableClass,
342 BaseSubobject Base,
const CXXRecordDecl *NearestVBase)
override;
344 llvm::GlobalVariable *getAddrOfVTable(
const CXXRecordDecl *RD,
345 CharUnits VPtrOffset)
override;
347 CGCallee getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD,
348 Address This, llvm::Type *Ty,
349 SourceLocation Loc)
override;
352 EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
354 DeleteOrMemberCallExpr E,
355 llvm::CallBase **CallOrInvoke)
override;
357 void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD,
358 CallArgList &CallArgs)
override {
361 "Only vector deleting destructor thunks are available in this ABI");
366 void emitVirtualInheritanceTables(
const CXXRecordDecl *RD)
override;
368 llvm::GlobalVariable *
369 getAddrOfVBTable(
const VPtrInfo &VBT,
const CXXRecordDecl *RD,
370 llvm::GlobalVariable::LinkageTypes
Linkage);
372 llvm::GlobalVariable *
373 getAddrOfVirtualDisplacementMap(
const CXXRecordDecl *SrcRD,
374 const CXXRecordDecl *DstRD) {
375 SmallString<256> OutName;
376 llvm::raw_svector_ostream
Out(OutName);
377 getMangleContext().mangleCXXVirtualDisplacementMap(SrcRD, DstRD, Out);
378 StringRef MangledName = OutName.str();
380 if (
auto *VDispMap = CGM.
getModule().getNamedGlobal(MangledName))
385 SmallVector<llvm::Constant *, 4> Map(NumEntries,
386 llvm::PoisonValue::get(CGM.
IntTy));
387 Map[0] = llvm::ConstantInt::get(CGM.
IntTy, 0);
388 bool AnyDifferent =
false;
389 for (
const auto &I : SrcRD->
vbases()) {
390 const CXXRecordDecl *VBase = I.getType()->getAsCXXRecordDecl();
396 Map[SrcVBIndex] = llvm::ConstantInt::get(CGM.
IntTy, DstVBIndex * 4);
397 AnyDifferent |= SrcVBIndex != DstVBIndex;
403 llvm::ArrayType *VDispMapTy = llvm::ArrayType::get(CGM.
IntTy, Map.size());
404 llvm::Constant *
Init = llvm::ConstantArray::get(VDispMapTy, Map);
405 llvm::GlobalValue::LinkageTypes
Linkage =
407 ? llvm::GlobalValue::LinkOnceODRLinkage
408 : llvm::GlobalValue::InternalLinkage;
409 auto *VDispMap =
new llvm::GlobalVariable(
415 void emitVBTableDefinition(
const VPtrInfo &VBT,
const CXXRecordDecl *RD,
416 llvm::GlobalVariable *GV)
const;
418 void setThunkLinkage(llvm::Function *Thunk,
bool ForVTable,
419 GlobalDecl GD,
bool ReturnAdjustment)
override {
424 Thunk->setLinkage(llvm::GlobalValue::InternalLinkage);
425 else if (ReturnAdjustment)
426 Thunk->setLinkage(llvm::GlobalValue::WeakODRLinkage);
428 Thunk->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage);
431 bool exportThunk()
override {
return false; }
433 llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This,
434 const CXXRecordDecl * ,
435 const ThunkInfo &TI)
override;
438 const CXXRecordDecl * ,
439 const ReturnAdjustment &RA)
override;
441 void EmitThreadLocalInitFuncs(
442 CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals,
443 ArrayRef<llvm::Function *> CXXThreadLocalInits,
444 ArrayRef<const VarDecl *> CXXThreadLocalInitVars)
override;
446 bool usesThreadWrapperFunction(
const VarDecl *VD)
const override {
447 return getContext().getLangOpts().isCompatibleWithMSVC(
448 LangOptions::MSVC2019_5) &&
450 (!isEmittedWithConstantInitializer(VD) || mayNeedDestruction(VD));
452 LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
const VarDecl *VD,
453 QualType LValType)
override;
455 void EmitGuardedInit(CodeGenFunction &CGF,
const VarDecl &D,
456 llvm::GlobalVariable *DeclPtr,
457 bool PerformInit)
override;
458 void registerGlobalDtor(CodeGenFunction &CGF,
const VarDecl &D,
459 llvm::FunctionCallee Dtor,
460 llvm::Constant *
Addr)
override;
485 bool requiresArrayCookie(
const CXXDeleteExpr *
expr,
486 QualType elementType)
override;
487 bool requiresArrayCookie(
const CXXNewExpr *
expr)
override;
488 CharUnits getArrayCookieSizeImpl(QualType
type)
override;
489 Address InitializeArrayCookie(CodeGenFunction &CGF,
491 llvm::Value *NumElements,
492 const CXXNewExpr *
expr,
493 QualType ElementType)
override;
494 llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF,
496 CharUnits cookieSize)
override;
498 friend struct MSRTTIBuilder;
500 bool isRTTIImageRelative()
const {
507 bool isThrowInfoImageRelative()
const {
509 return isRTTIImageRelative() ||
T.isARM() ||
T.isThumb();
513 llvm::StructType *getTypeDescriptorType(StringRef TypeInfoString) {
514 llvm::SmallString<32> TDTypeName(
"rtti.TypeDescriptor");
515 TDTypeName += llvm::utostr(TypeInfoString.size());
516 llvm::StructType *&TypeDescriptorType =
517 TypeDescriptorTypeMap[TypeInfoString.size()];
518 if (TypeDescriptorType)
519 return TypeDescriptorType;
520 llvm::Type *FieldTypes[] = {
523 llvm::ArrayType::get(CGM.
Int8Ty, TypeInfoString.size() + 1)};
525 llvm::StructType::create(CGM.
getLLVMContext(), FieldTypes, TDTypeName);
526 return TypeDescriptorType;
529 llvm::Type *getImageRelativeType(llvm::Type *PtrType) {
530 if (!isRTTIImageRelative())
535 llvm::StructType *getBaseClassDescriptorType() {
536 if (BaseClassDescriptorType)
537 return BaseClassDescriptorType;
538 llvm::Type *FieldTypes[] = {
547 BaseClassDescriptorType = llvm::StructType::create(
549 return BaseClassDescriptorType;
552 llvm::StructType *getClassHierarchyDescriptorType() {
553 if (ClassHierarchyDescriptorType)
554 return ClassHierarchyDescriptorType;
558 ClassHierarchyDescriptorType =
559 llvm::StructType::create(FieldTypes,
"rtti.ClassHierarchyDescriptor");
560 return ClassHierarchyDescriptorType;
563 llvm::StructType *getCompleteObjectLocatorType() {
564 if (CompleteObjectLocatorType)
565 return CompleteObjectLocatorType;
566 llvm::Type *FieldTypes[] = {
572 getImageRelativeType(CGM.
VoidTy),
574 llvm::ArrayRef<llvm::Type *> FieldTypesRef(FieldTypes);
575 if (!isRTTIImageRelative())
576 FieldTypesRef = FieldTypesRef.drop_back();
577 CompleteObjectLocatorType =
578 llvm::StructType::create(FieldTypesRef,
"rtti.CompleteObjectLocator");
579 return CompleteObjectLocatorType;
582 llvm::GlobalVariable *getImageBase() {
583 StringRef Name =
"__ImageBase";
584 if (llvm::GlobalVariable *GV = CGM.
getModule().getNamedGlobal(Name))
589 llvm::GlobalValue::ExternalLinkage,
595 llvm::Constant *getImageRelativeConstant(llvm::Constant *PtrVal) {
596 if (!isRTTIImageRelative())
598 return getImageRelativeOffset(PtrVal);
601 llvm::Type *getThrowInfoRelativeType(llvm::Type *PtrType) {
602 if (!isThrowInfoImageRelative())
607 llvm::Constant *getThrowInfoRelativeConstant(llvm::Constant *PtrVal) {
608 if (!isThrowInfoImageRelative())
610 return getImageRelativeOffset(PtrVal);
613 llvm::Constant *getImageRelativeOffset(llvm::Constant *PtrVal) {
614 llvm::Constant *ImageBaseAsInt =
615 llvm::ConstantExpr::getPtrToInt(getImageBase(), CGM.
IntPtrTy);
616 llvm::Constant *PtrValAsInt =
617 llvm::ConstantExpr::getPtrToInt(PtrVal, CGM.
IntPtrTy);
618 llvm::Constant *Diff =
619 llvm::ConstantExpr::getSub(PtrValAsInt, ImageBaseAsInt,
622 if (Diff->getType() == CGM.
IntTy)
624 return llvm::ConstantExpr::getTrunc(Diff, CGM.
IntTy);
628 MicrosoftMangleContext &getMangleContext() {
632 llvm::Constant *getZeroInt() {
633 return llvm::ConstantInt::get(CGM.
IntTy, 0);
636 llvm::Constant *getAllOnesInt() {
637 return llvm::Constant::getAllOnesValue(CGM.
IntTy);
640 CharUnits getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD)
override;
643 GetNullMemberPointerFields(
const MemberPointerType *MPT,
644 llvm::SmallVectorImpl<llvm::Constant *> &fields);
649 llvm::Value *GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
651 llvm::Value *VBPtrOffset,
652 llvm::Value *VBTableOffset,
653 llvm::Value **VBPtr =
nullptr);
655 llvm::Value *GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
659 llvm::Value **VBPtr =
nullptr) {
660 assert(VBTableOffset % 4 == 0 &&
"should be byte offset into table of i32s");
661 llvm::Value *VBPOffset =
662 llvm::ConstantInt::getSigned(CGM.
IntTy, VBPtrOffset);
663 llvm::Value *VBTOffset = llvm::ConstantInt::get(CGM.
IntTy, VBTableOffset);
664 return GetVBaseOffsetFromVBPtr(CGF, Base, VBPOffset, VBTOffset, VBPtr);
667 std::tuple<Address, llvm::Value *, const CXXRecordDecl *>
668 performBaseAdjustment(CodeGenFunction &CGF, Address
Value,
669 QualType SrcRecordTy);
673 llvm::Value *AdjustVirtualBase(CodeGenFunction &CGF,
const Expr *E,
674 const CXXRecordDecl *RD, Address Base,
675 llvm::Value *VirtualBaseAdjustmentOffset,
676 llvm::Value *VBPtrOffset );
680 llvm::Constant *EmitFullMemberPointer(llvm::Constant *FirstField,
681 bool IsMemberFunction,
682 const CXXRecordDecl *RD,
683 CharUnits NonVirtualBaseAdjustment,
684 unsigned VBTableIndex);
686 bool MemberPointerConstantIsNull(
const MemberPointerType *MPT,
690 void EmitVBPtrStores(CodeGenFunction &CGF,
const CXXRecordDecl *RD);
693 const VBTableGlobals &enumerateVBTables(
const CXXRecordDecl *RD);
696 llvm::Function *EmitVirtualMemPtrThunk(
const CXXMethodDecl *MD,
697 const MethodVFTableLocation &ML);
699 llvm::Constant *EmitMemberDataPointer(
const CXXRecordDecl *RD,
703 llvm::Type *ConvertMemberPointerType(
const MemberPointerType *MPT)
override;
705 bool isZeroInitializable(
const MemberPointerType *MPT)
override;
707 bool isMemberPointerConvertible(
const MemberPointerType *MPT)
const override {
709 return RD->
hasAttr<MSInheritanceAttr>();
712 llvm::Constant *EmitNullMemberPointer(
const MemberPointerType *MPT)
override;
714 llvm::Constant *EmitMemberDataPointer(
const MemberPointerType *MPT,
715 CharUnits offset)
override;
716 llvm::Constant *EmitMemberFunctionPointer(
const CXXMethodDecl *MD)
override;
717 llvm::Constant *EmitMemberPointer(
const APValue &MP, QualType MPT)
override;
719 llvm::Value *EmitMemberPointerComparison(CodeGenFunction &CGF,
722 const MemberPointerType *MPT,
723 bool Inequality)
override;
725 llvm::Value *EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
727 const MemberPointerType *MPT)
override;
729 llvm::Value *EmitMemberDataPointerAddress(CodeGenFunction &CGF,
const Expr *E,
730 Address Base, llvm::Value *MemPtr,
731 const MemberPointerType *MPT,
732 bool IsInBounds)
override;
734 llvm::Value *EmitNonNullMemberPointerConversion(
735 const MemberPointerType *SrcTy,
const MemberPointerType *DstTy,
738 CGBuilderTy &Builder);
740 llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
742 llvm::Value *Src)
override;
744 llvm::Constant *EmitMemberPointerConversion(
const CastExpr *E,
745 llvm::Constant *Src)
override;
747 llvm::Constant *EmitMemberPointerConversion(
748 const MemberPointerType *SrcTy,
const MemberPointerType *DstTy,
753 EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
const Expr *E,
754 Address This, llvm::Value *&ThisPtrForCall,
756 const MemberPointerType *MPT)
override;
758 void emitCXXStructor(GlobalDecl GD)
override;
760 llvm::StructType *getCatchableTypeType() {
761 if (CatchableTypeType)
762 return CatchableTypeType;
763 llvm::Type *FieldTypes[] = {
772 CatchableTypeType = llvm::StructType::create(
774 return CatchableTypeType;
777 llvm::StructType *getCatchableTypeArrayType(
uint32_t NumEntries) {
778 llvm::StructType *&CatchableTypeArrayType =
779 CatchableTypeArrayTypeMap[NumEntries];
780 if (CatchableTypeArrayType)
781 return CatchableTypeArrayType;
783 llvm::SmallString<23> CTATypeName(
"eh.CatchableTypeArray.");
784 CTATypeName += llvm::utostr(NumEntries);
785 llvm::Type *CTType = getThrowInfoRelativeType(CGM.
DefaultPtrTy);
786 llvm::Type *FieldTypes[] = {
788 llvm::ArrayType::get(CTType, NumEntries)
790 CatchableTypeArrayType =
791 llvm::StructType::create(CGM.
getLLVMContext(), FieldTypes, CTATypeName);
792 return CatchableTypeArrayType;
795 llvm::StructType *getThrowInfoType() {
797 return ThrowInfoType;
798 llvm::Type *FieldTypes[] = {
804 ThrowInfoType = llvm::StructType::create(CGM.
getLLVMContext(), FieldTypes,
806 return ThrowInfoType;
813 llvm::FunctionType *FTy =
814 llvm::FunctionType::get(CGM.
VoidTy, Args,
false);
815 llvm::FunctionCallee Throw =
819 if (
auto *Fn = dyn_cast<llvm::Function>(Throw.getCallee()))
820 Fn->setCallingConv(llvm::CallingConv::X86_StdCall);
825 llvm::Function *getAddrOfCXXCtorClosure(
const CXXConstructorDecl *CD,
828 llvm::Constant *getCatchableType(QualType
T,
833 llvm::GlobalVariable *getCatchableTypeArray(QualType
T);
835 llvm::GlobalVariable *getThrowInfo(QualType
T)
override;
837 std::pair<llvm::Value *, const CXXRecordDecl *>
838 LoadVTablePtr(CodeGenFunction &CGF, Address This,
839 const CXXRecordDecl *RD)
override;
842 isPermittedToBeHomogeneousAggregate(
const CXXRecordDecl *RD)
const override;
845 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
846 typedef llvm::DenseMap<VFTableIdTy, llvm::GlobalVariable *> VTablesMapTy;
847 typedef llvm::DenseMap<VFTableIdTy, llvm::GlobalValue *> VFTablesMapTy;
849 VFTablesMapTy VFTablesMap;
850 VTablesMapTy VTablesMap;
853 llvm::SmallPtrSet<const CXXRecordDecl *, 4> DeferredVFTables;
857 llvm::DenseMap<const CXXRecordDecl *, VBTableGlobals> VBTablesMap;
862 GuardInfo() =
default;
863 llvm::GlobalVariable *Guard =
nullptr;
864 unsigned BitIndex = 0;
869 llvm::DenseMap<const DeclContext *, GuardInfo> GuardVariableMap;
870 llvm::DenseMap<const DeclContext *, GuardInfo> ThreadLocalGuardVariableMap;
871 llvm::DenseMap<const DeclContext *, unsigned> ThreadSafeGuardNumMap;
873 llvm::DenseMap<size_t, llvm::StructType *> TypeDescriptorTypeMap;
874 llvm::StructType *BaseClassDescriptorType;
875 llvm::StructType *ClassHierarchyDescriptorType;
876 llvm::StructType *CompleteObjectLocatorType;
878 llvm::DenseMap<QualType, llvm::GlobalVariable *> CatchableTypeArrays;
880 llvm::StructType *CatchableTypeType;
881 llvm::DenseMap<uint32_t, llvm::StructType *> CatchableTypeArrayTypeMap;
882 llvm::StructType *ThrowInfoType;
888MicrosoftCXXABI::getRecordArgABI(
const CXXRecordDecl *RD)
const {
900 case llvm::Triple::thumb:
906 case llvm::Triple::x86: {
912 getContext().getTypeInfo(getContext().getCanonicalTagType(RD));
918 return RAA_DirectInMemory;
921 case llvm::Triple::x86_64:
922 case llvm::Triple::aarch64:
926 llvm_unreachable(
"invalid enum");
929void MicrosoftCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
930 const CXXDeleteExpr *DE,
932 QualType ElementType,
933 const CXXDestructorDecl *Dtor) {
936 if (!getContext().getTargetInfo().callGlobalDeleteInDeletingDtor(
937 getContext().getLangOpts())) {
940 llvm::Value *MDThis =
941 EmitVirtualDestructorCall(CGF, Dtor, DtorType, Ptr, DE,
951void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF,
bool isNoReturn) {
952 llvm::Value *Args[] = {llvm::ConstantPointerNull::get(CGM.
Int8PtrTy),
961void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
962 const CXXCatchStmt *S) {
966 llvm::BasicBlock *CatchPadBB = CGF.
Builder.GetInsertBlock();
967 llvm::CatchPadInst *CPI =
979 CPI->setArgOperand(2,
var.getObjectAddress(CGF).emitRawPointer(CGF));
987std::tuple<Address, llvm::Value *, const CXXRecordDecl *>
988MicrosoftCXXABI::performBaseAdjustment(CodeGenFunction &CGF, Address
Value,
989 QualType SrcRecordTy) {
992 const ASTContext &Context = getContext();
998 return std::make_tuple(
Value, llvm::ConstantInt::get(CGF.
Int32Ty, 0),
1003 const CXXRecordDecl *PolymorphicBase =
nullptr;
1004 for (
auto &Base : SrcDecl->
vbases()) {
1005 const CXXRecordDecl *BaseDecl =
Base.getType()->getAsCXXRecordDecl();
1007 PolymorphicBase = BaseDecl;
1011 assert(PolymorphicBase &&
"polymorphic class has no apparent vfptr?");
1013 llvm::Value *Offset =
1014 GetVirtualBaseClassOffset(CGF,
Value, SrcDecl, PolymorphicBase);
1016 Value.getElementType(),
Value.emitRawPointer(CGF), Offset);
1017 CharUnits VBaseAlign =
1019 return std::make_tuple(
Address(Ptr, CGF.
Int8Ty, VBaseAlign), Offset,
1023bool MicrosoftCXXABI::shouldTypeidBeNullChecked(QualType SrcRecordTy) {
1025 return !getContext().getASTRecordLayout(SrcDecl).hasExtendableVFPtr();
1029 llvm::Value *Argument) {
1030 llvm::Type *ArgTypes[] = {CGF.
Int8PtrTy};
1031 llvm::FunctionType *FTy =
1032 llvm::FunctionType::get(CGF.
Int8PtrTy, ArgTypes,
false);
1033 llvm::Value *Args[] = {Argument};
1038void MicrosoftCXXABI::EmitBadTypeidCall(CodeGenFunction &CGF) {
1039 llvm::CallBase *
Call =
1041 Call->setDoesNotReturn();
1042 CGF.
Builder.CreateUnreachable();
1045llvm::Value *MicrosoftCXXABI::EmitTypeid(CodeGenFunction &CGF,
1046 QualType SrcRecordTy,
1048 llvm::Type *StdTypeInfoPtrTy) {
1049 std::tie(ThisPtr, std::ignore, std::ignore) =
1050 performBaseAdjustment(CGF, ThisPtr, SrcRecordTy);
1052 return CGF.
Builder.CreateBitCast(Typeid, StdTypeInfoPtrTy);
1055bool MicrosoftCXXABI::shouldDynamicCastCallBeNullChecked(
bool SrcIsPtr,
1056 QualType SrcRecordTy) {
1059 !getContext().getASTRecordLayout(SrcDecl).hasExtendableVFPtr();
1062llvm::Value *MicrosoftCXXABI::emitDynamicCastCall(
1063 CodeGenFunction &CGF, Address This, QualType SrcRecordTy, QualType DestTy,
1064 QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
1065 llvm::Value *SrcRTTI =
1067 llvm::Value *DestRTTI =
1070 llvm::Value *Offset;
1071 std::tie(This, Offset, std::ignore) =
1072 performBaseAdjustment(CGF, This, SrcRecordTy);
1073 llvm::Value *ThisPtr =
This.emitRawPointer(CGF);
1085 llvm::FunctionType::get(CGF.
Int8PtrTy, ArgTypes,
false),
1087 llvm::Value *Args[] = {
1088 ThisPtr, Offset, SrcRTTI, DestRTTI,
1093llvm::Value *MicrosoftCXXABI::emitDynamicCastToVoid(CodeGenFunction &CGF,
1095 QualType SrcRecordTy) {
1096 std::tie(
Value, std::ignore, std::ignore) =
1097 performBaseAdjustment(CGF,
Value, SrcRecordTy);
1101 llvm::Type *ArgTypes[] = {CGF.
Int8PtrTy};
1103 llvm::FunctionType::get(CGF.
Int8PtrTy, ArgTypes,
false),
1105 llvm::Value *Args[] = {
Value.emitRawPointer(CGF)};
1109bool MicrosoftCXXABI::EmitBadCastCall(CodeGenFunction &CGF) {
1113llvm::Value *MicrosoftCXXABI::GetVirtualBaseClassOffset(
1114 CodeGenFunction &CGF, Address This,
const CXXRecordDecl *ClassDecl,
1115 const CXXRecordDecl *BaseClassDecl) {
1116 const ASTContext &Context = getContext();
1119 llvm::Value *VBPtrOffset = llvm::ConstantInt::get(CGM.
PtrDiffTy, VBPtrChars);
1121 CharUnits VBTableChars =
1124 llvm::Value *VBTableOffset =
1127 llvm::Value *VBPtrToNewBase =
1128 GetVBaseOffsetFromVBPtr(CGF, This, VBPtrOffset, VBTableOffset);
1131 return CGF.
Builder.CreateNSWAdd(VBPtrOffset, VBPtrToNewBase);
1134bool MicrosoftCXXABI::HasThisReturn(GlobalDecl GD)
const {
1144bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl GD)
const {
1194 auto *Ctor = dyn_cast<CXXConstructorDecl>(D);
1196 if (
auto *
Template = dyn_cast<FunctionTemplateDecl>(D))
1197 Ctor = dyn_cast<CXXConstructorDecl>(
Template->getTemplatedDecl());
1199 if (Ctor && Ctor->isUserProvided()) {
1201 }
else if (
auto *MethodDecl = dyn_cast<CXXMethodDecl>(D)) {
1202 if (MethodDecl->isCopyAssignmentOperator() && MethodDecl->isDeleted())
1211bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo &FI)
const {
1212 const CXXRecordDecl *RD = FI.
getReturnType()->getAsCXXRecordDecl();
1222 if (isIndirectReturn) {
1244MicrosoftCXXABI::EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
1245 const CXXRecordDecl *RD) {
1246 llvm::Value *IsMostDerivedClass = getStructorImplicitParamValue(CGF);
1247 assert(IsMostDerivedClass &&
1248 "ctor for a class with virtual bases must have an implicit parameter");
1249 llvm::Value *IsCompleteObject =
1250 CGF.
Builder.CreateIsNotNull(IsMostDerivedClass,
"is_complete_object");
1252 llvm::BasicBlock *CallVbaseCtorsBB = CGF.
createBasicBlock(
"ctor.init_vbases");
1253 llvm::BasicBlock *SkipVbaseCtorsBB = CGF.
createBasicBlock(
"ctor.skip_vbases");
1254 CGF.
Builder.CreateCondBr(IsCompleteObject,
1255 CallVbaseCtorsBB, SkipVbaseCtorsBB);
1260 EmitVBPtrStores(CGF, RD);
1264 return SkipVbaseCtorsBB;
1268MicrosoftCXXABI::EmitDtorCompleteObjectHandler(CodeGenFunction &CGF) {
1269 llvm::Value *IsMostDerivedClass = getStructorImplicitParamValue(CGF);
1270 assert(IsMostDerivedClass &&
1271 "ctor for a class with virtual bases must have an implicit parameter");
1272 llvm::Value *IsCompleteObject =
1273 CGF.
Builder.CreateIsNotNull(IsMostDerivedClass,
"is_complete_object");
1275 llvm::BasicBlock *CallVbaseDtorsBB = CGF.
createBasicBlock(
"Dtor.dtor_vbases");
1276 llvm::BasicBlock *SkipVbaseDtorsBB = CGF.
createBasicBlock(
"Dtor.skip_vbases");
1277 CGF.
Builder.CreateCondBr(IsCompleteObject,
1278 CallVbaseDtorsBB, SkipVbaseDtorsBB);
1283 return SkipVbaseDtorsBB;
1286void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers(
1287 CodeGenFunction &CGF,
const CXXRecordDecl *RD) {
1301 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
1304 CGBuilderTy &Builder = CGF.
Builder;
1306 llvm::Value *Int8This =
nullptr;
1308 for (
const CXXBaseSpecifier &S : RD->
vbases()) {
1309 const CXXRecordDecl *VBase = S.getType()->getAsCXXRecordDecl();
1310 auto I = VBaseMap.find(VBase);
1311 assert(I != VBaseMap.end());
1312 if (!I->second.hasVtorDisp())
1315 llvm::Value *VBaseOffset =
1316 GetVirtualBaseClassOffset(CGF, getThisAddress(CGF), RD, VBase);
1317 uint64_t ConstantVBaseOffset = I->second.VBaseOffset.getQuantity();
1320 llvm::Value *VtorDispValue = Builder.CreateSub(
1321 VBaseOffset, llvm::ConstantInt::get(CGM.
PtrDiffTy, ConstantVBaseOffset),
1323 VtorDispValue = Builder.CreateTruncOrBitCast(VtorDispValue, CGF.
Int32Ty);
1326 Int8This = getThisValue(CGF);
1328 llvm::Value *VtorDispPtr =
1329 Builder.CreateInBoundsGEP(CGF.
Int8Ty, Int8This, VBaseOffset);
1331 VtorDispPtr = Builder.CreateConstGEP1_32(CGF.
Int8Ty, VtorDispPtr, -4);
1333 Builder.CreateAlignedStore(VtorDispValue, VtorDispPtr,
1340 CallingConv ExpectedCallingConv = Context.getDefaultCallingConvention(
1344 return ExpectedCallingConv == ActualCallingConv;
1347void MicrosoftCXXABI::EmitCXXConstructors(
const CXXConstructorDecl *D) {
1359 Fn->setLinkage(llvm::GlobalValue::WeakODRLinkage);
1365void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction &CGF,
1366 const CXXRecordDecl *RD) {
1369 const ASTContext &Context = getContext();
1372 const VBTableGlobals &VBGlobals = enumerateVBTables(RD);
1373 for (
unsigned I = 0, E = VBGlobals.VBTables->size(); I != E; ++I) {
1374 const std::unique_ptr<VPtrInfo> &VBT = (*VBGlobals.VBTables)[I];
1375 llvm::GlobalVariable *GV = VBGlobals.Globals[I];
1376 const ASTRecordLayout &SubobjectLayout =
1378 CharUnits Offs = VBT->NonVirtualOffset;
1380 if (VBT->getVBaseWithVPtr())
1383 llvm::Value *GVPtr =
1390CGCXXABI::AddedStructorArgCounts
1391MicrosoftCXXABI::buildStructorSignature(GlobalDecl GD,
1392 SmallVectorImpl<CanQualType> &ArgTys) {
1393 AddedStructorArgCounts Added;
1399 ArgTys.push_back(getContext().IntTy);
1402 auto *CD = dyn_cast<CXXConstructorDecl>(GD.
getDecl());
1410 const FunctionProtoType *FPT = CD->
getType()->
castAs<FunctionProtoType>();
1411 if (
Class->getNumVBases()) {
1413 ArgTys.insert(ArgTys.begin() + 1, getContext().IntTy);
1416 ArgTys.push_back(getContext().IntTy);
1424void MicrosoftCXXABI::setCXXDestructorDLLStorage(llvm::GlobalValue *GV,
1425 const CXXDestructorDecl *Dtor,
1430 GV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
1432 const NamedDecl *ND =
Dtor;
1437llvm::GlobalValue::LinkageTypes MicrosoftCXXABI::getCXXDestructorLinkage(
1442 return llvm::GlobalValue::InternalLinkage;
1453 if (
Dtor->hasAttr<DLLExportAttr>())
1454 return llvm::GlobalValue::WeakODRLinkage;
1455 if (
Dtor->hasAttr<DLLImportAttr>())
1456 return llvm::GlobalValue::AvailableExternallyLinkage;
1457 return llvm::GlobalValue::LinkOnceODRLinkage;
1462 return llvm::GlobalValue::LinkOnceODRLinkage;
1464 llvm_unreachable(
"MS C++ ABI does not support unified dtors");
1470 return llvm::GlobalValue::WeakAnyLinkage;
1472 llvm_unreachable(
"MS C++ ABI does not support comdat dtors");
1474 llvm_unreachable(
"invalid dtor type");
1477void MicrosoftCXXABI::EmitCXXDestructors(
const CXXDestructorDecl *D) {
1491MicrosoftCXXABI::getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) {
1494 if (
const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
1509 MethodVFTableLocation ML =
1521 const ASTRecordLayout &DerivedLayout =
1522 getContext().getASTRecordLayout(MD->
getParent());
1529Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
1530 CodeGenFunction &CGF, GlobalDecl GD, Address This,
1535 CharUnits Adjustment = getVirtualFunctionPrologueThisAdjustment(GD);
1546 GlobalDecl LookupGD = GD;
1547 if (
const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
1561 MethodVFTableLocation ML =
1576 const CXXRecordDecl *Derived = MD->
getParent();
1577 const CXXRecordDecl *VBase = ML.
VBase;
1578 llvm::Value *VBaseOffset =
1579 GetVirtualBaseClassOffset(CGF,
Result, Derived, VBase);
1581 Result.getElementType(),
Result.emitRawPointer(CGF), VBaseOffset);
1582 CharUnits VBaseAlign =
1586 if (!StaticOffset.
isZero()) {
1602void MicrosoftCXXABI::addImplicitStructorParams(CodeGenFunction &CGF,
1604 FunctionArgList &Params) {
1605 ASTContext &Context = getContext();
1612 ImplicitParamKind::Other);
1615 const FunctionProtoType *FPT = MD->
getType()->
castAs<FunctionProtoType>();
1617 Params.insert(Params.begin() + 1, IsMostDerived);
1619 Params.push_back(IsMostDerived);
1620 getStructorImplicitParamDecl(CGF) = IsMostDerived;
1625 ImplicitParamKind::Other);
1626 Params.push_back(ShouldDelete);
1627 getStructorImplicitParamDecl(CGF) = ShouldDelete;
1631void MicrosoftCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
1648 llvm::Value *
This = loadIncomingCXXThis(CGF);
1651 CharUnits Adjustment = getVirtualFunctionPrologueThisAdjustment(CGF.
CurGD);
1652 if (!Adjustment.
isZero()) {
1658 setCXXABIThisValue(CGF, This);
1668 if (HasThisReturn(CGF.
CurGD) || hasMostDerivedReturn(CGF.
CurGD))
1672 assert(getStructorImplicitParamDecl(CGF) &&
1673 "no implicit parameter for a constructor with virtual bases?");
1674 getStructorImplicitParamValue(CGF)
1681 assert(getStructorImplicitParamDecl(CGF) &&
1682 "no implicit parameter for a deleting destructor?");
1683 getStructorImplicitParamValue(CGF)
1686 "should_call_delete");
1690CGCXXABI::AddedStructorArgs MicrosoftCXXABI::getImplicitConstructorArgs(
1697 return AddedStructorArgs{};
1700 const FunctionProtoType *FPT = D->
getType()->
castAs<FunctionProtoType>();
1701 llvm::Value *MostDerivedArg;
1703 MostDerivedArg = getStructorImplicitParamValue(CGF);
1708 return AddedStructorArgs::prefix({{MostDerivedArg, getContext().IntTy}});
1710 return AddedStructorArgs::suffix({{MostDerivedArg, getContext().IntTy}});
1713llvm::Value *MicrosoftCXXABI::getCXXDestructorImplicitParam(
1719void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
1720 const CXXDestructorDecl *DD,
1730 GlobalDecl GD(DD,
Type);
1734 assert(
Type != CXXDtorType::Dtor_Deleting &&
1735 "The deleting destructor should only be called via a virtual call");
1736 This = adjustThisArgumentForVirtualFunctionCall(CGF, GlobalDecl(DD,
Type),
1740 llvm::BasicBlock *BaseDtorEndBB =
nullptr;
1742 BaseDtorEndBB = EmitDtorCompleteObjectHandler(CGF);
1751 QualType(),
nullptr);
1752 if (BaseDtorEndBB) {
1754 CGF.
Builder.CreateBr(BaseDtorEndBB);
1759void MicrosoftCXXABI::emitVTableTypeMetadata(
const VPtrInfo &Info,
1760 const CXXRecordDecl *RD,
1761 llvm::GlobalVariable *VTable) {
1772 llvm::DenseSet<const CXXRecordDecl *> Visited;
1773 llvm::GlobalObject::VCallVisibility TypeVis =
1775 if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
1776 VTable->setVCallVisibilityMetadata(TypeVis);
1782 CharUnits AddressPoint =
1783 getContext().getLangOpts().RTTIData
1784 ? getContext().toCharUnitsFromBits(
1785 getContext().getTargetInfo().getPointerWidth(LangAS::Default))
1803 const ASTRecordLayout &Layout =
1804 getContext().getASTRecordLayout(DerivedRD);
1810 Offset = VBI->second.VBaseOffset;
1821void MicrosoftCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
1822 const CXXRecordDecl *RD) {
1826 for (
const std::unique_ptr<VPtrInfo>& Info : VFPtrs) {
1827 llvm::GlobalVariable *VTable = getAddrOfVTable(RD, Info->
FullOffsetInMDC);
1828 if (VTable->hasInitializer())
1831 const VTableLayout &VTLayout =
1834 llvm::Constant *RTTI =
nullptr;
1836 [](
const VTableComponent &VTC) { return VTC.isRTTIKind(); }))
1837 RTTI = getMSCompleteObjectLocator(RD, *Info);
1839 ConstantInitBuilder builder(CGM);
1840 auto components = builder.beginStruct();
1842 VTable->hasLocalLinkage());
1843 components.finishAndSetAsInitializer(VTable);
1845 emitVTableTypeMetadata(*Info, RD, VTable);
1849bool MicrosoftCXXABI::isVirtualOffsetNeededForVTableField(
1850 CodeGenFunction &CGF, CodeGenFunction::VPtr Vptr) {
1854llvm::Value *MicrosoftCXXABI::getVTableAddressPointInStructor(
1855 CodeGenFunction &CGF,
const CXXRecordDecl *VTableClass, BaseSubobject Base,
1856 const CXXRecordDecl *NearestVBase) {
1857 llvm::Constant *VTableAddressPoint = getVTableAddressPoint(Base, VTableClass);
1858 if (!VTableAddressPoint) {
1859 assert(
Base.getBase()->getNumVBases() &&
1860 !getContext().getASTRecordLayout(
Base.getBase()).hasOwnVFPtr());
1862 return VTableAddressPoint;
1868 llvm::raw_svector_ostream Out(Name);
1873MicrosoftCXXABI::getVTableAddressPoint(BaseSubobject Base,
1874 const CXXRecordDecl *VTableClass) {
1875 (void)getAddrOfVTable(VTableClass,
Base.getBaseOffset());
1876 VFTableIdTy
ID(VTableClass,
Base.getBaseOffset());
1877 return VFTablesMap[
ID];
1880llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(
const CXXRecordDecl *RD,
1881 CharUnits VPtrOffset) {
1886 VFTableIdTy
ID(RD, VPtrOffset);
1887 auto [I, Inserted] = VTablesMap.try_emplace(ID);
1891 llvm::GlobalVariable *&VTable = I->second;
1896 if (DeferredVFTables.insert(RD).second) {
1904 llvm::StringSet<> ObservedMangledNames;
1905 for (
const auto &VFPtr : VFPtrs) {
1906 SmallString<256> Name;
1908 if (!ObservedMangledNames.insert(Name.str()).second)
1909 llvm_unreachable(
"Already saw this mangling before?");
1914 const std::unique_ptr<VPtrInfo> *VFPtrI =
1915 llvm::find_if(VFPtrs, [&](
const std::unique_ptr<VPtrInfo> &VPI) {
1916 return VPI->FullOffsetInMDC == VPtrOffset;
1918 if (VFPtrI == VFPtrs.end()) {
1919 VFTablesMap[
ID] =
nullptr;
1922 const std::unique_ptr<VPtrInfo> &VFPtr = *VFPtrI;
1924 SmallString<256> VFTableName;
1934 llvm::GlobalValue::LinkageTypes VFTableLinkage =
1935 RD->
hasAttr<DLLImportAttr>() ? llvm::GlobalValue::LinkOnceODRLinkage
1936 : CGM.getVTableLinkage(RD);
1937 bool VFTableComesFromAnotherTU =
1938 llvm::GlobalValue::isAvailableExternallyLinkage(VFTableLinkage) ||
1939 llvm::GlobalValue::isExternalLinkage(VFTableLinkage);
1940 bool VTableAliasIsRequred =
1941 !VFTableComesFromAnotherTU && getContext().getLangOpts().RTTIData;
1943 if (llvm::GlobalValue *VFTable =
1944 CGM.
getModule().getNamedGlobal(VFTableName)) {
1945 VFTablesMap[
ID] = VFTable;
1946 VTable = VTableAliasIsRequred
1949 :
cast<llvm::GlobalVariable>(VFTable);
1953 const VTableLayout &VTLayout =
1955 llvm::GlobalValue::LinkageTypes VTableLinkage =
1956 VTableAliasIsRequred ? llvm::GlobalValue::PrivateLinkage : VFTableLinkage;
1958 StringRef VTableName = VTableAliasIsRequred ? StringRef() : VFTableName.str();
1960 llvm::Type *VTableType = CGM.
getVTables().getVTableType(VTLayout);
1964 llvm::GlobalValue *VFTable;
1965 VTable =
new llvm::GlobalVariable(CGM.
getModule(), VTableType,
1966 true, VTableLinkage,
1967 nullptr, VTableName);
1969 VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1971 llvm::Comdat *
C =
nullptr;
1972 if (!VFTableComesFromAnotherTU &&
1973 llvm::GlobalValue::isWeakForLinker(VFTableLinkage))
1974 C = CGM.
getModule().getOrInsertComdat(VFTableName.str());
1979 if (VTableAliasIsRequred) {
1980 llvm::Constant *GEPIndices[] = {llvm::ConstantInt::get(CGM.
Int32Ty, 0),
1981 llvm::ConstantInt::get(CGM.
Int32Ty, 0),
1982 llvm::ConstantInt::get(CGM.
Int32Ty, 1)};
1985 llvm::Constant *VTableGEP = llvm::ConstantExpr::getGetElementPtr(
1986 CGM.
getDataLayout(), VTable->getValueType(), VTable, GEPIndices,
1987 llvm::GEPNoWrapFlags::inBounds());
1988 if (llvm::GlobalValue::isWeakForLinker(VFTableLinkage)) {
1989 VFTableLinkage = llvm::GlobalValue::ExternalLinkage;
1991 C->setSelectionKind(llvm::Comdat::Largest);
1993 VFTable = llvm::GlobalAlias::create(CGM.
Int8PtrTy,
1995 VFTableName.str(), VTableGEP,
1998 VFTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2007 VTable->setComdat(
C);
2009 if (RD->
hasAttr<DLLExportAttr>())
2010 VFTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
2012 VFTablesMap[
ID] = VFTable;
2016CGCallee MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
2020 SourceLocation Loc) {
2021 CGBuilderTy &Builder = CGF.
Builder;
2025 adjustThisArgumentForVirtualFunctionCall(CGF, GD, This,
true);
2028 llvm::Value *VTable =
2037 const CXXRecordDecl *ObjectWithVPtr =
2040 [&](
const std::unique_ptr<VPtrInfo> &Info) {
2041 return Info->FullOffsetInMDC == ML.VFPtrOffset;
2047 ObjectWithVPtr, VTable, Ty,
2053 return CGCallee(GD, VFunc);
2059 llvm::Value *VFuncPtr =
2060 Builder.CreateConstInBoundsGEP1_64(Ty, VTable, ML.
Index,
"vfn");
2061 llvm::Value *VFunc =
2063 return CGCallee(GD, VFunc);
2066llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall(
2067 CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
2068 Address This, DeleteOrMemberCallExpr E, llvm::CallBase **CallOrInvoke) {
2069 auto *CE = dyn_cast<const CXXMemberCallExpr *>(E);
2070 auto *D = dyn_cast<const CXXDeleteExpr *>(E);
2071 assert((CE !=
nullptr) ^ (D !=
nullptr));
2072 assert(CE ==
nullptr || CE->arg_begin() == CE->arg_end());
2078 ASTContext &Context = getContext();
2079 bool VectorDeletingDtorsEnabled =
2083 const CGFunctionInfo *FInfo =
2089 bool IsArrayDelete = D && D->isArrayForm() && VectorDeletingDtorsEnabled;
2090 bool IsGlobalDelete = D && D->isGlobalDelete() &&
2093 llvm::Value *ImplicitParam =
2094 CGF.
Builder.getInt32((IsDeleting ? 1 : 0) | (IsGlobalDelete ? 4 : 0) |
2095 (IsArrayDelete ? 2 : 0));
2099 ThisTy = CE->getObjectType();
2101 ThisTy = D->getDestroyedType();
2105 ThisTy = ATy->getElementType();
2107 This = adjustThisArgumentForVirtualFunctionCall(CGF, GD, This,
true);
2110 ImplicitParam, Context.
IntTy, CE, CallOrInvoke);
2114const VBTableGlobals &
2115MicrosoftCXXABI::enumerateVBTables(
const CXXRecordDecl *RD) {
2118 auto [Entry, Added] = VBTablesMap.try_emplace(RD);
2119 VBTableGlobals &VBGlobals = Entry->second;
2124 VBGlobals.VBTables = &Context.enumerateVBTables(RD);
2129 for (VPtrInfoVector::const_iterator I = VBGlobals.VBTables->begin(),
2130 E = VBGlobals.VBTables->end();
2132 VBGlobals.Globals.push_back(getAddrOfVBTable(**I, RD,
Linkage));
2139MicrosoftCXXABI::EmitVirtualMemPtrThunk(
const CXXMethodDecl *MD,
2140 const MethodVFTableLocation &ML) {
2142 "can't form pointers to ctors or virtual dtors");
2145 SmallString<256> ThunkName;
2146 llvm::raw_svector_ostream
Out(ThunkName);
2147 getMangleContext().mangleVirtualMemPtrThunk(MD, ML, Out);
2150 if (llvm::GlobalValue *GV = CGM.
getModule().getNamedValue(ThunkName))
2154 const CGFunctionInfo &FnInfo =
2157 llvm::Function *ThunkFn =
2158 llvm::Function::Create(ThunkTy, llvm::Function::ExternalLinkage,
2160 assert(ThunkFn->getName() == ThunkName &&
"name was uniqued!");
2163 ? llvm::GlobalValue::LinkOnceODRLinkage
2164 : llvm::GlobalValue::InternalLinkage);
2166 ThunkFn->setComdat(CGM.
getModule().getOrInsertComdat(ThunkFn->getName()));
2175 ThunkFn->addFnAttr(
"thunk");
2178 ThunkFn->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
2181 CodeGenFunction CGF(CGM);
2182 CGF.
CurGD = GlobalDecl(MD);
2187 FunctionArgList FunctionArgs;
2188 buildThisParam(CGF, FunctionArgs);
2192 FunctionArgs, MD->
getLocation(), SourceLocation());
2195 setCXXABIThisValue(CGF, loadIncomingCXXThis(CGF));
2200 llvm::Value *VTable =
2203 llvm::Value *VFuncPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
2204 ThunkPtrTy, VTable, ML.
Index,
"vfn");
2213void MicrosoftCXXABI::emitVirtualInheritanceTables(
const CXXRecordDecl *RD) {
2214 const VBTableGlobals &VBGlobals = enumerateVBTables(RD);
2215 for (
unsigned I = 0, E = VBGlobals.VBTables->size(); I != E; ++I) {
2216 const std::unique_ptr<VPtrInfo>& VBT = (*VBGlobals.VBTables)[I];
2217 llvm::GlobalVariable *GV = VBGlobals.Globals[I];
2218 if (GV->isDeclaration())
2219 emitVBTableDefinition(*VBT, RD, GV);
2223llvm::GlobalVariable *
2224MicrosoftCXXABI::getAddrOfVBTable(
const VPtrInfo &VBT,
const CXXRecordDecl *RD,
2225 llvm::GlobalVariable::LinkageTypes
Linkage) {
2226 SmallString<256> OutName;
2227 llvm::raw_svector_ostream
Out(OutName);
2228 getMangleContext().mangleCXXVBTable(RD, VBT.
MangledPath, Out);
2229 StringRef Name = OutName.str();
2231 llvm::ArrayType *VBTableType =
2234 assert(!CGM.
getModule().getNamedGlobal(Name) &&
2235 "vbtable with this name already exists: mangling bug?");
2236 CharUnits Alignment =
2240 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2242 if (RD->
hasAttr<DLLImportAttr>())
2243 GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
2244 else if (RD->
hasAttr<DLLExportAttr>())
2245 GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
2247 if (!GV->hasExternalLinkage())
2248 emitVBTableDefinition(VBT, RD, GV);
2253void MicrosoftCXXABI::emitVBTableDefinition(
const VPtrInfo &VBT,
2254 const CXXRecordDecl *RD,
2255 llvm::GlobalVariable *GV)
const {
2259 "should only emit vbtables for classes with vbtables");
2261 const ASTRecordLayout &BaseLayout =
2263 const ASTRecordLayout &DerivedLayout = getContext().getASTRecordLayout(RD);
2265 SmallVector<llvm::Constant *, 4> Offsets(1 + ObjectWithVPtr->
getNumVBases(),
2274 for (
const auto &I : ObjectWithVPtr->
vbases()) {
2275 const CXXRecordDecl *VBase = I.getType()->getAsCXXRecordDecl();
2282 CompleteVBPtrOffset +=
2284 Offset -= CompleteVBPtrOffset;
2286 unsigned VBIndex = Context.getVBTableIndex(ObjectWithVPtr, VBase);
2287 assert(Offsets[VBIndex] ==
nullptr &&
"The same vbindex seen twice?");
2292 assert(Offsets.size() ==
2294 llvm::ArrayType *VBTableType =
2295 llvm::ArrayType::get(CGM.
IntTy, Offsets.size());
2296 llvm::Constant *
Init = llvm::ConstantArray::get(VBTableType, Offsets);
2297 GV->setInitializer(
Init);
2299 if (RD->
hasAttr<DLLImportAttr>())
2300 GV->setLinkage(llvm::GlobalVariable::AvailableExternallyLinkage);
2303llvm::Value *MicrosoftCXXABI::performThisAdjustment(
2304 CodeGenFunction &CGF, Address This,
2305 const CXXRecordDecl * ,
const ThunkInfo &TI) {
2306 const ThisAdjustment &TA = TI.
This;
2308 return This.emitRawPointer(CGF);
2314 V =
This.emitRawPointer(CGF);
2324 CGF.
Builder.CreateNeg(VtorDisp));
2337 llvm::Value *VBaseOffset = GetVBaseOffsetFromVBPtr(
2356llvm::Value *MicrosoftCXXABI::performReturnAdjustment(
2357 CodeGenFunction &CGF, Address Ret,
2358 const CXXRecordDecl * ,
const ReturnAdjustment &RA) {
2361 return Ret.emitRawPointer(CGF);
2365 llvm::Value *
V =
Ret.emitRawPointer(CGF);
2370 llvm::Value *VBaseOffset =
2382bool MicrosoftCXXABI::requiresArrayCookie(
const CXXDeleteExpr *
expr,
2383 QualType elementType) {
2389bool MicrosoftCXXABI::requiresArrayCookie(
const CXXNewExpr *
expr) {
2392 return expr->getAllocatedType().isDestructedType();
2395CharUnits MicrosoftCXXABI::getArrayCookieSizeImpl(QualType
type) {
2398 ASTContext &Ctx = getContext();
2403llvm::Value *MicrosoftCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
2405 CharUnits cookieSize) {
2410Address MicrosoftCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
2412 llvm::Value *numElements,
2413 const CXXNewExpr *
expr,
2414 QualType elementType) {
2415 assert(requiresArrayCookie(
expr));
2418 CharUnits cookieSize = getArrayCookieSizeImpl(elementType);
2433 llvm::FunctionCallee Dtor,
2434 llvm::Constant *
Addr) {
2439 llvm::FunctionType *TLRegDtorTy = llvm::FunctionType::get(
2440 CGF.
IntTy, DtorStub->getType(),
false);
2443 TLRegDtorTy,
"__tlregdtor", llvm::AttributeList(),
true);
2444 if (llvm::Function *TLRegDtorFn =
2445 dyn_cast<llvm::Function>(TLRegDtor.getCallee()))
2446 TLRegDtorFn->setDoesNotThrow();
2451void MicrosoftCXXABI::registerGlobalDtor(CodeGenFunction &CGF,
const VarDecl &D,
2452 llvm::FunctionCallee Dtor,
2453 llvm::Constant *
Addr) {
2465 if (
auto *ISA = D.
getAttr<InitSegAttr>()) {
2466 if (
const FunctionDecl *FD = ISA->getFunc()) {
2468 llvm::FunctionType *ExitFnTy =
2469 llvm::FunctionType::get(CGM.
IntTy, dtorStub->getType(),
false);
2481void MicrosoftCXXABI::EmitThreadLocalInitFuncs(
2482 CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals,
2483 ArrayRef<llvm::Function *> CXXThreadLocalInits,
2484 ArrayRef<const VarDecl *> CXXThreadLocalInitVars) {
2485 if (CXXThreadLocalInits.empty())
2490 ?
"/include:___dyn_tls_init@12"
2491 :
"/include:__dyn_tls_init");
2496 auto AddToXDU = [&CGM](llvm::Function *InitFunc) {
2497 llvm::GlobalVariable *InitFuncPtr =
new llvm::GlobalVariable(
2498 CGM.
getModule(), InitFunc->getType(),
true,
2499 llvm::GlobalVariable::InternalLinkage, InitFunc,
2500 Twine(InitFunc->getName(),
"$initializer$"));
2501 InitFuncPtr->setSection(
".CRT$XDU");
2508 std::vector<llvm::Function *> NonComdatInits;
2509 for (
size_t I = 0, E = CXXThreadLocalInitVars.size(); I != E; ++I) {
2512 llvm::Function *F = CXXThreadLocalInits[I];
2515 if (llvm::Comdat *
C = GV->getComdat())
2516 AddToXDU(F)->setComdat(
C);
2518 NonComdatInits.push_back(F);
2521 if (!NonComdatInits.empty()) {
2522 llvm::FunctionType *FTy =
2523 llvm::FunctionType::get(CGM.
VoidTy,
false);
2526 SourceLocation(),
true);
2527 CodeGenFunction(CGM).GenerateCXXGlobalInitFunc(InitFunc, NonComdatInits);
2539 llvm::Constant *TlsGuardConstant =
2543 TlsGuard->setThreadLocal(
true);
2551 llvm::FunctionType *FTy =
2552 llvm::FunctionType::get(llvm::Type::getVoidTy(CGM.
getLLVMContext()), {},
2555 FTy,
"__dyn_tls_on_demand_init",
2557 llvm::AttributeList::FunctionIndex,
2558 llvm::Attribute::NoUnwind),
2563 llvm::BasicBlock *DynInitBB,
2564 llvm::BasicBlock *ContinueBB) {
2565 llvm::LoadInst *TlsGuardValue =
2567 llvm::Value *CmpResult =
2569 CGF.
Builder.CreateCondBr(CmpResult, DynInitBB, ContinueBB);
2573 llvm::GlobalValue *TlsGuard,
2574 llvm::BasicBlock *ContinueBB) {
2576 llvm::Function *InitializerFunction =
2578 llvm::CallInst *CallVal = CGF.
Builder.CreateCall(InitializerFunction);
2579 CallVal->setCallingConv(InitializerFunction->getCallingConv());
2581 CGF.
Builder.CreateBr(ContinueBB);
2585 llvm::BasicBlock *DynInitBB =
2587 llvm::BasicBlock *ContinueBB =
2593 CGF.
Builder.SetInsertPoint(DynInitBB);
2595 CGF.
Builder.SetInsertPoint(ContinueBB);
2598LValue MicrosoftCXXABI::EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
2600 QualType LValType) {
2618 AlignmentSource::Decl)
2624 StringRef VarName(
"_Init_thread_epoch");
2626 if (
auto *GV = CGM.
getModule().getNamedGlobal(VarName))
2628 auto *GV =
new llvm::GlobalVariable(
2630 false, llvm::GlobalVariable::ExternalLinkage,
2632 nullptr, llvm::GlobalVariable::GeneralDynamicTLSModel);
2638 llvm::FunctionType *FTy =
2639 llvm::FunctionType::get(llvm::Type::getVoidTy(CGM.
getLLVMContext()),
2642 FTy,
"_Init_thread_header",
2644 llvm::AttributeList::FunctionIndex,
2645 llvm::Attribute::NoUnwind),
2650 llvm::FunctionType *FTy =
2651 llvm::FunctionType::get(llvm::Type::getVoidTy(CGM.
getLLVMContext()),
2654 FTy,
"_Init_thread_footer",
2656 llvm::AttributeList::FunctionIndex,
2657 llvm::Attribute::NoUnwind),
2662 llvm::FunctionType *FTy =
2663 llvm::FunctionType::get(llvm::Type::getVoidTy(CGM.
getLLVMContext()),
2666 FTy,
"_Init_thread_abort",
2668 llvm::AttributeList::FunctionIndex,
2669 llvm::Attribute::NoUnwind),
2674struct ResetGuardBit final : EHScopeStack::Cleanup {
2677 ResetGuardBit(Address Guard,
unsigned GuardNum)
2678 : Guard(Guard), GuardNum(GuardNum) {}
2680 void Emit(CodeGenFunction &CGF, Flags flags)
override {
2683 CGBuilderTy &Builder = CGF.
Builder;
2684 llvm::LoadInst *LI = Builder.CreateLoad(Guard);
2685 llvm::ConstantInt *Mask =
2686 llvm::ConstantInt::getSigned(CGF.
IntTy, ~(1ULL << GuardNum));
2687 Builder.CreateStore(Builder.CreateAnd(LI, Mask), Guard);
2691struct CallInitThreadAbort final : EHScopeStack::Cleanup {
2693 CallInitThreadAbort(RawAddress Guard) : Guard(Guard.getPointer()) {}
2695 void Emit(CodeGenFunction &CGF, Flags flags)
override {
2702void MicrosoftCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
const VarDecl &D,
2703 llvm::GlobalVariable *GV,
2707 assert(GV->hasWeakLinkage() || GV->hasLinkOnceLinkage());
2709 llvm::Function *F = CGF.
CurFn;
2710 F->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage);
2711 F->setComdat(CGM.
getModule().getOrInsertComdat(F->getName()));
2717 bool ThreadsafeStatic = getContext().getLangOpts().ThreadsafeStatics;
2721 bool HasPerVariableGuard = ThreadsafeStatic && !ThreadlocalStatic;
2723 CGBuilderTy &Builder = CGF.
Builder;
2724 llvm::IntegerType *GuardTy = CGF.
Int32Ty;
2725 llvm::ConstantInt *
Zero = llvm::ConstantInt::get(GuardTy, 0);
2729 GuardInfo *GI =
nullptr;
2730 if (ThreadlocalStatic)
2732 else if (!ThreadsafeStatic)
2735 llvm::GlobalVariable *GuardVar = GI ? GI->Guard :
nullptr;
2740 GuardNum = getContext().getStaticLocalNumber(&D);
2741 assert(GuardNum > 0);
2743 }
else if (HasPerVariableGuard) {
2747 GuardNum = GI->BitIndex++;
2750 if (!HasPerVariableGuard && GuardNum >= 32) {
2752 ErrorUnsupportedABI(CGF,
"more than 32 guarded initializations");
2759 SmallString<256> GuardName;
2761 llvm::raw_svector_ostream
Out(GuardName);
2762 if (HasPerVariableGuard)
2763 getMangleContext().mangleThreadSafeStaticGuardVariable(&D, GuardNum,
2766 getMangleContext().mangleStaticGuardVariable(&D, Out);
2772 new llvm::GlobalVariable(CGM.
getModule(), GuardTy,
false,
2773 GV->getLinkage(),
Zero, GuardName.str());
2774 GuardVar->setVisibility(GV->getVisibility());
2775 GuardVar->setDLLStorageClass(GV->getDLLStorageClass());
2776 GuardVar->setAlignment(GuardAlign.
getAsAlign());
2777 if (GuardVar->isWeakForLinker())
2778 GuardVar->setComdat(
2779 CGM.
getModule().getOrInsertComdat(GuardVar->getName()));
2782 if (GI && !HasPerVariableGuard)
2783 GI->Guard = GuardVar;
2786 ConstantAddress GuardAddr(GuardVar, GuardTy, GuardAlign);
2788 assert(GuardVar->getLinkage() == GV->getLinkage() &&
2789 "static local from the same function had different linkage");
2791 if (!HasPerVariableGuard) {
2799 llvm::ConstantInt *Bit = llvm::ConstantInt::get(GuardTy, 1ULL << GuardNum);
2800 llvm::LoadInst *LI = Builder.CreateLoad(GuardAddr);
2801 llvm::Value *NeedsInit =
2802 Builder.CreateICmpEQ(Builder.CreateAnd(LI, Bit),
Zero);
2806 CodeGenFunction::GuardKind::VariableGuard, &D);
2811 Builder.CreateStore(Builder.CreateOr(LI, Bit), GuardAddr);
2815 Builder.CreateBr(EndBlock);
2833 llvm::LoadInst *FirstGuardLoad = Builder.CreateLoad(GuardAddr);
2834 FirstGuardLoad->setOrdering(llvm::AtomicOrdering::Unordered);
2835 llvm::LoadInst *InitThreadEpoch =
2837 llvm::Value *IsUninitialized =
2838 Builder.CreateICmpSGT(FirstGuardLoad, InitThreadEpoch);
2842 CodeGenFunction::GuardKind::VariableGuard, &D);
2848 GuardAddr.getPointer());
2849 llvm::LoadInst *SecondGuardLoad = Builder.CreateLoad(GuardAddr);
2850 SecondGuardLoad->setOrdering(llvm::AtomicOrdering::Unordered);
2851 llvm::Value *ShouldDoInit =
2852 Builder.CreateICmpEQ(SecondGuardLoad, getAllOnesInt());
2854 Builder.CreateCondBr(ShouldDoInit, InitBlock, EndBlock);
2862 GuardAddr.getPointer());
2863 Builder.CreateBr(EndBlock);
2869bool MicrosoftCXXABI::isZeroInitializable(
const MemberPointerType *MPT) {
2885MicrosoftCXXABI::ConvertMemberPointerType(
const MemberPointerType *MPT) {
2888 llvm::SmallVector<llvm::Type *, 4> fields;
2892 fields.push_back(CGM.
IntTy);
2896 fields.push_back(CGM.
IntTy);
2898 fields.push_back(CGM.
IntTy);
2900 fields.push_back(CGM.
IntTy);
2902 if (fields.size() == 1)
2907void MicrosoftCXXABI::
2908GetNullMemberPointerFields(
const MemberPointerType *MPT,
2909 llvm::SmallVectorImpl<llvm::Constant *> &fields) {
2910 assert(fields.empty());
2915 fields.push_back(llvm::Constant::getNullValue(CGM.
VoidPtrTy));
2918 fields.push_back(getZeroInt());
2920 fields.push_back(getAllOnesInt());
2925 fields.push_back(getZeroInt());
2927 fields.push_back(getZeroInt());
2929 fields.push_back(getAllOnesInt());
2933MicrosoftCXXABI::EmitNullMemberPointer(
const MemberPointerType *MPT) {
2934 llvm::SmallVector<llvm::Constant *, 4> fields;
2935 GetNullMemberPointerFields(MPT, fields);
2936 if (fields.size() == 1)
2938 llvm::Constant *Res = llvm::ConstantStruct::getAnon(fields);
2939 assert(Res->getType() == ConvertMemberPointerType(MPT));
2944MicrosoftCXXABI::EmitFullMemberPointer(llvm::Constant *FirstField,
2945 bool IsMemberFunction,
2946 const CXXRecordDecl *RD,
2947 CharUnits NonVirtualBaseAdjustment,
2948 unsigned VBTableIndex) {
2956 llvm::SmallVector<llvm::Constant *, 4> fields;
2957 fields.push_back(FirstField);
2960 fields.push_back(llvm::ConstantInt::getSigned(
2966 Offs = getContext().getASTRecordLayout(RD).getVBPtrOffset();
2972 fields.push_back(llvm::ConstantInt::get(CGM.
IntTy, VBTableIndex));
2974 return llvm::ConstantStruct::getAnon(fields);
2978MicrosoftCXXABI::EmitMemberDataPointer(
const MemberPointerType *MPT,
2983llvm::Constant *MicrosoftCXXABI::EmitMemberDataPointer(
const CXXRecordDecl *RD,
2986 MSInheritanceModel::Virtual)
2987 offset -= getContext().getOffsetOfBaseWithVBPtr(RD);
2988 llvm::Constant *FirstField =
2990 return EmitFullMemberPointer(FirstField,
false, RD,
2994llvm::Constant *MicrosoftCXXABI::EmitMemberPointer(
const APValue &MP,
2996 const MemberPointerType *DstTy = MPType->
castAs<MemberPointerType>();
2999 return EmitNullMemberPointer(DstTy);
3001 ASTContext &Ctx = getContext();
3005 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MPD)) {
3006 C = EmitMemberFunctionPointer(MD);
3014 const FieldDecl *FD = dyn_cast<FieldDecl>(MPD);
3019 C = EmitMemberDataPointer(RD, FieldOffset);
3022 if (!MemberPointerPath.empty()) {
3024 const MemberPointerType *SrcTy =
3026 std::nullopt, SrcRD)
3027 ->
castAs<MemberPointerType>();
3030 SmallVector<const CXXBaseSpecifier *, 4> DerivedToBasePath;
3031 const CXXRecordDecl *PrevRD = SrcRD;
3032 for (
const CXXRecordDecl *PathElem : MemberPointerPath) {
3033 const CXXRecordDecl *
Base =
nullptr;
3034 const CXXRecordDecl *Derived =
nullptr;
3035 if (DerivedMember) {
3042 for (
const CXXBaseSpecifier &BS : Derived->
bases())
3043 if (BS.getType()->getAsCXXRecordDecl()->getCanonicalDecl() ==
3044 Base->getCanonicalDecl())
3045 DerivedToBasePath.push_back(&BS);
3048 assert(DerivedToBasePath.size() == MemberPointerPath.size());
3050 CastKind CK = DerivedMember ? CK_DerivedToBaseMemberPointer
3051 : CK_BaseToDerivedMemberPointer;
3052 C = EmitMemberPointerConversion(SrcTy, DstTy, CK, DerivedToBasePath.begin(),
3053 DerivedToBasePath.end(),
C);
3059MicrosoftCXXABI::EmitMemberFunctionPointer(
const CXXMethodDecl *MD) {
3060 assert(MD->
isInstance() &&
"Member function must not be static!");
3064 CodeGenTypes &Types = CGM.
getTypes();
3066 unsigned VBTableIndex = 0;
3067 llvm::Constant *FirstField;
3068 const FunctionProtoType *FPT = MD->
getType()->
castAs<FunctionProtoType>();
3083 MethodVFTableLocation ML = VTableContext.getMethodVFTableLocation(MD);
3084 FirstField = EmitVirtualMemPtrThunk(MD, ML);
3088 VBTableIndex = VTableContext.getVBTableIndex(RD, ML.
VBase) * 4;
3091 if (VBTableIndex == 0 &&
3093 MSInheritanceModel::Virtual)
3094 NonVirtualBaseAdjustment -= getContext().getOffsetOfBaseWithVBPtr(RD);
3097 return EmitFullMemberPointer(FirstField,
true, RD,
3098 NonVirtualBaseAdjustment, VBTableIndex);
3105MicrosoftCXXABI::EmitMemberPointerComparison(CodeGenFunction &CGF,
3108 const MemberPointerType *MPT,
3110 CGBuilderTy &Builder = CGF.
Builder;
3113 llvm::ICmpInst::Predicate Eq;
3114 llvm::Instruction::BinaryOps
And,
Or;
3116 Eq = llvm::ICmpInst::ICMP_NE;
3117 And = llvm::Instruction::Or;
3118 Or = llvm::Instruction::And;
3120 Eq = llvm::ICmpInst::ICMP_EQ;
3121 And = llvm::Instruction::And;
3122 Or = llvm::Instruction::Or;
3131 return Builder.CreateICmp(Eq, L, R);
3134 llvm::Value *L0 = Builder.CreateExtractValue(L, 0,
"lhs.0");
3135 llvm::Value *R0 = Builder.CreateExtractValue(R, 0,
"rhs.0");
3136 llvm::Value *Cmp0 = Builder.CreateICmp(Eq, L0, R0,
"memptr.cmp.first");
3139 llvm::Value *Res =
nullptr;
3141 for (
unsigned I = 1, E = LType->getNumElements(); I != E; ++I) {
3142 llvm::Value *LF = Builder.CreateExtractValue(L, I);
3143 llvm::Value *RF = Builder.CreateExtractValue(R, I);
3144 llvm::Value *
Cmp = Builder.CreateICmp(Eq, LF, RF,
"memptr.cmp.rest");
3146 Res = Builder.CreateBinOp(
And, Res,
Cmp);
3154 llvm::Value *
Zero = llvm::Constant::getNullValue(L0->getType());
3155 llvm::Value *IsZero = Builder.CreateICmp(Eq, L0,
Zero,
"memptr.cmp.iszero");
3156 Res = Builder.CreateBinOp(
Or, Res, IsZero);
3161 return Builder.CreateBinOp(
And, Res, Cmp0,
"memptr.cmp");
3165MicrosoftCXXABI::EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
3166 llvm::Value *MemPtr,
3167 const MemberPointerType *MPT) {
3168 CGBuilderTy &Builder = CGF.
Builder;
3169 llvm::SmallVector<llvm::Constant *, 4> fields;
3172 fields.push_back(llvm::Constant::getNullValue(CGM.
VoidPtrTy));
3174 GetNullMemberPointerFields(MPT, fields);
3175 assert(!fields.empty());
3176 llvm::Value *FirstField = MemPtr;
3177 if (MemPtr->getType()->isStructTy())
3178 FirstField = Builder.CreateExtractValue(MemPtr, 0);
3179 llvm::Value *Res = Builder.CreateICmpNE(FirstField, fields[0],
"memptr.cmp0");
3187 for (
int I = 1, E = fields.size(); I < E; ++I) {
3188 llvm::Value *
Field = Builder.CreateExtractValue(MemPtr, I);
3189 llvm::Value *
Next = Builder.CreateICmpNE(Field, fields[I],
"memptr.cmp");
3190 Res = Builder.CreateOr(Res,
Next,
"memptr.tobool");
3195bool MicrosoftCXXABI::MemberPointerConstantIsNull(
const MemberPointerType *MPT,
3196 llvm::Constant *Val) {
3199 llvm::Constant *FirstField = Val->getType()->isStructTy() ?
3200 Val->getAggregateElement(0U) : Val;
3201 return FirstField->isNullValue();
3206 if (isZeroInitializable(MPT) && Val->isNullValue())
3211 llvm::SmallVector<llvm::Constant *, 4> Fields;
3212 GetNullMemberPointerFields(MPT, Fields);
3213 if (Fields.size() == 1) {
3214 assert(Val->getType()->isIntegerTy());
3215 return Val == Fields[0];
3219 for (I = 0, E = Fields.size(); I != E; ++I) {
3220 if (Val->getAggregateElement(I) != Fields[I])
3227MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
3229 llvm::Value *VBPtrOffset,
3230 llvm::Value *VBTableOffset,
3231 llvm::Value **VBPtrOut) {
3232 CGBuilderTy &Builder = CGF.
Builder;
3234 llvm::Value *VBPtr = Builder.CreateInBoundsGEP(
3235 CGM.
Int8Ty,
This.emitRawPointer(CGF), VBPtrOffset,
"vbptr");
3239 CharUnits VBPtrAlign;
3240 if (
auto CI = dyn_cast<llvm::ConstantInt>(VBPtrOffset)) {
3241 VBPtrAlign =
This.getAlignment().alignmentAtOffset(
3247 llvm::Value *VBTable =
3248 Builder.CreateAlignedLoad(CGM.
DefaultPtrTy, VBPtr, VBPtrAlign,
"vbtable");
3251 llvm::Value *VBTableIndex = Builder.CreateAShr(
3252 VBTableOffset, llvm::ConstantInt::get(VBTableOffset->getType(), 2),
3256 llvm::Value *VBaseOffs =
3257 Builder.CreateInBoundsGEP(CGM.
Int32Ty, VBTable, VBTableIndex);
3258 return Builder.CreateAlignedLoad(CGM.
Int32Ty, VBaseOffs,
3264llvm::Value *MicrosoftCXXABI::AdjustVirtualBase(
3265 CodeGenFunction &CGF,
const Expr *E,
const CXXRecordDecl *RD,
3266 Address Base, llvm::Value *VBTableOffset, llvm::Value *VBPtrOffset) {
3267 CGBuilderTy &Builder = CGF.
Builder;
3269 llvm::BasicBlock *OriginalBB =
nullptr;
3270 llvm::BasicBlock *SkipAdjustBB =
nullptr;
3271 llvm::BasicBlock *VBaseAdjustBB =
nullptr;
3278 OriginalBB = Builder.GetInsertBlock();
3281 llvm::Value *IsVirtual =
3282 Builder.CreateICmpNE(VBTableOffset, getZeroInt(),
3284 Builder.CreateCondBr(IsVirtual, VBaseAdjustBB, SkipAdjustBB);
3297 offs = getContext().getASTRecordLayout(RD).getVBPtrOffset();
3300 llvm::Value *VBPtr =
nullptr;
3301 llvm::Value *VBaseOffs =
3302 GetVBaseOffsetFromVBPtr(CGF, Base, VBPtrOffset, VBTableOffset, &VBPtr);
3303 llvm::Value *AdjustedBase =
3304 Builder.CreateInBoundsGEP(CGM.
Int8Ty, VBPtr, VBaseOffs);
3307 if (VBaseAdjustBB) {
3308 Builder.CreateBr(SkipAdjustBB);
3310 llvm::PHINode *Phi = Builder.CreatePHI(CGM.
Int8PtrTy, 2,
"memptr.base");
3311 Phi->addIncoming(
Base.emitRawPointer(CGF), OriginalBB);
3312 Phi->addIncoming(AdjustedBase, VBaseAdjustBB);
3315 return AdjustedBase;
3318llvm::Value *MicrosoftCXXABI::EmitMemberDataPointerAddress(
3319 CodeGenFunction &CGF,
const Expr *E, Address Base, llvm::Value *MemPtr,
3320 const MemberPointerType *MPT,
bool IsInBounds) {
3322 CGBuilderTy &Builder = CGF.
Builder;
3328 llvm::Value *FieldOffset = MemPtr;
3329 llvm::Value *VirtualBaseAdjustmentOffset =
nullptr;
3330 llvm::Value *VBPtrOffset =
nullptr;
3331 if (MemPtr->getType()->isStructTy()) {
3334 FieldOffset = Builder.CreateExtractValue(MemPtr, I++);
3336 VBPtrOffset = Builder.CreateExtractValue(MemPtr, I++);
3338 VirtualBaseAdjustmentOffset = Builder.CreateExtractValue(MemPtr, I++);
3342 if (VirtualBaseAdjustmentOffset) {
3343 Addr = AdjustVirtualBase(CGF, E, RD, Base, VirtualBaseAdjustmentOffset,
3350 return Builder.CreateGEP(CGF.
Int8Ty,
Addr, FieldOffset,
"memptr.offset",
3351 IsInBounds ? llvm::GEPNoWrapFlags::inBounds()
3352 : llvm::GEPNoWrapFlags::none());
3356MicrosoftCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
3359 assert(E->
getCastKind() == CK_DerivedToBaseMemberPointer ||
3360 E->
getCastKind() == CK_BaseToDerivedMemberPointer ||
3369 const MemberPointerType *SrcTy =
3371 const MemberPointerType *DstTy = E->
getType()->
castAs<MemberPointerType>();
3375 bool IsReinterpret = E->
getCastKind() == CK_ReinterpretMemberPointer;
3376 if (IsReinterpret && IsFunc)
3380 CXXRecordDecl *DstRD = DstTy->getMostRecentCXXRecordDecl();
3381 if (IsReinterpret &&
3385 CGBuilderTy &Builder = CGF.
Builder;
3388 llvm::Value *
IsNotNull = EmitMemberPointerIsNotNull(CGF, Src, SrcTy);
3389 llvm::Constant *DstNull = EmitNullMemberPointer(DstTy);
3393 if (IsReinterpret) {
3396 assert(Src->getType() == DstNull->getType());
3397 return Builder.CreateSelect(
IsNotNull, Src, DstNull);
3400 llvm::BasicBlock *OriginalBB = Builder.GetInsertBlock();
3403 Builder.CreateCondBr(
IsNotNull, ConvertBB, ContinueBB);
3406 llvm::Value *Dst = EmitNonNullMemberPointerConversion(
3410 Builder.CreateBr(ContinueBB);
3414 llvm::PHINode *Phi = Builder.CreatePHI(DstNull->getType(), 2,
"memptr.converted");
3415 Phi->addIncoming(DstNull, OriginalBB);
3416 Phi->addIncoming(Dst, ConvertBB);
3420llvm::Value *MicrosoftCXXABI::EmitNonNullMemberPointerConversion(
3421 const MemberPointerType *SrcTy,
const MemberPointerType *DstTy,
CastKind CK,
3424 CGBuilderTy &Builder) {
3433 llvm::Value *FirstField = Src;
3434 llvm::Value *NonVirtualBaseAdjustment = getZeroInt();
3435 llvm::Value *VirtualBaseAdjustmentOffset = getZeroInt();
3436 llvm::Value *VBPtrOffset = getZeroInt();
3440 FirstField = Builder.CreateExtractValue(Src, I++);
3442 NonVirtualBaseAdjustment = Builder.CreateExtractValue(Src, I++);
3444 VBPtrOffset = Builder.CreateExtractValue(Src, I++);
3446 VirtualBaseAdjustmentOffset = Builder.CreateExtractValue(Src, I++);
3449 bool IsDerivedToBase = (CK == CK_DerivedToBaseMemberPointer);
3450 const MemberPointerType *DerivedTy = IsDerivedToBase ? SrcTy : DstTy;
3455 llvm::Value *&NVAdjustField = IsFunc ? NonVirtualBaseAdjustment : FirstField;
3462 llvm::Value *SrcVBIndexEqZero =
3463 Builder.CreateICmpEQ(VirtualBaseAdjustmentOffset, getZeroInt());
3464 if (SrcInheritance == MSInheritanceModel::Virtual) {
3465 if (
int64_t SrcOffsetToFirstVBase =
3466 getContext().getOffsetOfBaseWithVBPtr(SrcRD).getQuantity()) {
3467 llvm::Value *UndoSrcAdjustment = Builder.CreateSelect(
3469 llvm::ConstantInt::get(CGM.
IntTy, SrcOffsetToFirstVBase),
3471 NVAdjustField = Builder.CreateNSWAdd(NVAdjustField, UndoSrcAdjustment);
3482 llvm::Constant *BaseClassOffset = llvm::ConstantInt::get(
3487 llvm::Value *NVDisp;
3488 if (IsDerivedToBase)
3489 NVDisp = Builder.CreateNSWSub(NVAdjustField, BaseClassOffset,
"adj");
3491 NVDisp = Builder.CreateNSWAdd(NVAdjustField, BaseClassOffset,
"adj");
3493 NVAdjustField = Builder.CreateSelect(SrcVBIndexEqZero, NVDisp, getZeroInt());
3497 llvm::Value *DstVBIndexEqZero = SrcVBIndexEqZero;
3500 if (llvm::GlobalVariable *VDispMap =
3501 getAddrOfVirtualDisplacementMap(SrcRD, DstRD)) {
3502 llvm::Value *VBIndex = Builder.CreateExactUDiv(
3503 VirtualBaseAdjustmentOffset, llvm::ConstantInt::get(CGM.
IntTy, 4));
3505 llvm::Constant *Mapping = VDispMap->getInitializer();
3506 VirtualBaseAdjustmentOffset =
3509 llvm::Value *Idxs[] = {getZeroInt(), VBIndex};
3510 VirtualBaseAdjustmentOffset = Builder.CreateAlignedLoad(
3511 CGM.
IntTy, Builder.CreateInBoundsGEP(VDispMap->getValueType(),
3517 Builder.CreateICmpEQ(VirtualBaseAdjustmentOffset, getZeroInt());
3524 llvm::Value *DstVBPtrOffset = llvm::ConstantInt::getSigned(
3526 getContext().getASTRecordLayout(DstRD).getVBPtrOffset().getQuantity());
3528 Builder.CreateSelect(DstVBIndexEqZero, getZeroInt(), DstVBPtrOffset);
3534 if (DstInheritance == MSInheritanceModel::Virtual) {
3535 if (
int64_t DstOffsetToFirstVBase =
3536 getContext().getOffsetOfBaseWithVBPtr(DstRD).getQuantity()) {
3537 llvm::Value *DoDstAdjustment = Builder.CreateSelect(
3539 llvm::ConstantInt::get(CGM.
IntTy, DstOffsetToFirstVBase),
3541 NVAdjustField = Builder.CreateNSWSub(NVAdjustField, DoDstAdjustment);
3550 Dst = llvm::PoisonValue::get(ConvertMemberPointerType(DstTy));
3552 Dst = Builder.CreateInsertValue(Dst, FirstField, Idx++);
3554 Dst = Builder.CreateInsertValue(Dst, NonVirtualBaseAdjustment, Idx++);
3556 Dst = Builder.CreateInsertValue(Dst, VBPtrOffset, Idx++);
3558 Dst = Builder.CreateInsertValue(Dst, VirtualBaseAdjustmentOffset, Idx++);
3564MicrosoftCXXABI::EmitMemberPointerConversion(
const CastExpr *E,
3565 llvm::Constant *Src) {
3566 const MemberPointerType *SrcTy =
3568 const MemberPointerType *DstTy = E->
getType()->
castAs<MemberPointerType>();
3572 return EmitMemberPointerConversion(SrcTy, DstTy, CK, E->
path_begin(),
3576llvm::Constant *MicrosoftCXXABI::EmitMemberPointerConversion(
3577 const MemberPointerType *SrcTy,
const MemberPointerType *DstTy,
CastKind CK,
3580 assert(CK == CK_DerivedToBaseMemberPointer ||
3581 CK == CK_BaseToDerivedMemberPointer ||
3582 CK == CK_ReinterpretMemberPointer);
3585 if (MemberPointerConstantIsNull(SrcTy, Src))
3586 return EmitNullMemberPointer(DstTy);
3591 if (CK == CK_ReinterpretMemberPointer)
3596 SrcTy, DstTy, CK, PathBegin, PathEnd, Src, Builder));
3601CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer(
3602 CodeGenFunction &CGF,
const Expr *E, Address This,
3603 llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr,
3604 const MemberPointerType *MPT) {
3606 const FunctionProtoType *FPT =
3609 CGBuilderTy &Builder = CGF.
Builder;
3615 llvm::Value *FunctionPointer = MemPtr;
3616 llvm::Value *NonVirtualBaseAdjustment =
nullptr;
3617 llvm::Value *VirtualBaseAdjustmentOffset =
nullptr;
3618 llvm::Value *VBPtrOffset =
nullptr;
3619 if (MemPtr->getType()->isStructTy()) {
3622 FunctionPointer = Builder.CreateExtractValue(MemPtr, I++);
3624 NonVirtualBaseAdjustment = Builder.CreateExtractValue(MemPtr, I++);
3626 VBPtrOffset = Builder.CreateExtractValue(MemPtr, I++);
3628 VirtualBaseAdjustmentOffset = Builder.CreateExtractValue(MemPtr, I++);
3631 if (VirtualBaseAdjustmentOffset) {
3632 ThisPtrForCall = AdjustVirtualBase(CGF, E, RD, This,
3633 VirtualBaseAdjustmentOffset, VBPtrOffset);
3635 ThisPtrForCall =
This.emitRawPointer(CGF);
3638 if (NonVirtualBaseAdjustment)
3639 ThisPtrForCall = Builder.CreateInBoundsGEP(CGF.
Int8Ty, ThisPtrForCall,
3640 NonVirtualBaseAdjustment);
3642 CGCallee
Callee(FPT, FunctionPointer);
3647 return new MicrosoftCXXABI(CGM);
3681 StringRef MangledName(
"??_7type_info@@6B@");
3682 if (
auto VTable = CGM.
getModule().getNamedGlobal(MangledName))
3686 llvm::GlobalVariable::ExternalLinkage,
3687 nullptr, MangledName);
3700 IsPrivateOnPath = 1 | 8,
3704 HasHierarchyDescriptor = 64
3706 MSRTTIClass(
const CXXRecordDecl *RD) : RD(RD) {}
3707 uint32_t initialize(
const MSRTTIClass *Parent,
3708 const CXXBaseSpecifier *Specifier);
3710 MSRTTIClass *getFirstChild() {
return this + 1; }
3711 static MSRTTIClass *getNextChild(MSRTTIClass *Child) {
3712 return Child + 1 + Child->NumBases;
3715 const CXXRecordDecl *RD, *VirtualRoot;
3716 uint32_t Flags, NumBases, OffsetInVBase;
3720uint32_t MSRTTIClass::initialize(
const MSRTTIClass *Parent,
3721 const CXXBaseSpecifier *Specifier) {
3722 Flags = HasHierarchyDescriptor;
3724 VirtualRoot =
nullptr;
3728 Flags |= IsPrivate | IsPrivateOnPath;
3734 if (Parent->Flags & IsPrivateOnPath)
3735 Flags |= IsPrivateOnPath;
3736 VirtualRoot = Parent->VirtualRoot;
3737 OffsetInVBase = Parent->OffsetInVBase + RD->getASTContext()
3738 .getASTRecordLayout(Parent->RD).getBaseClassOffset(RD).getQuantity();
3742 MSRTTIClass *Child = getFirstChild();
3743 for (
const CXXBaseSpecifier &Base : RD->bases()) {
3744 NumBases += Child->initialize(
this, &Base) + 1;
3745 Child = getNextChild(Child);
3750static llvm::GlobalValue::LinkageTypes getLinkageForRTTI(QualType Ty) {
3752 case Linkage::Invalid:
3753 llvm_unreachable(
"Linkage hasn't been computed!");
3756 case Linkage::Internal:
3757 case Linkage::UniqueExternal:
3758 return llvm::GlobalValue::InternalLinkage;
3760 case Linkage::VisibleNone:
3761 case Linkage::Module:
3762 case Linkage::External:
3763 return llvm::GlobalValue::LinkOnceODRLinkage;
3765 llvm_unreachable(
"Invalid linkage!");
3771struct MSRTTIBuilder {
3773 HasBranchingHierarchy = 1,
3774 HasVirtualBranchingHierarchy = 2,
3775 HasAmbiguousBases = 4
3778 MSRTTIBuilder(MicrosoftCXXABI &ABI,
const CXXRecordDecl *RD)
3779 : CGM(ABI.CGM), Context(CGM.getContext()),
3780 VMContext(CGM.getLLVMContext()),
Module(CGM.getModule()), RD(RD),
3781 Linkage(getLinkageForRTTI(CGM.getContext().getCanonicalTagType(RD))),
3784 llvm::GlobalVariable *getBaseClassDescriptor(
const MSRTTIClass &Classes);
3785 llvm::GlobalVariable *
3786 getBaseClassArray(SmallVectorImpl<MSRTTIClass> &Classes);
3787 llvm::GlobalVariable *getClassHierarchyDescriptor();
3788 llvm::GlobalVariable *getCompleteObjectLocator(
const VPtrInfo &Info);
3791 ASTContext &Context;
3792 llvm::LLVMContext &VMContext;
3794 const CXXRecordDecl *RD;
3795 llvm::GlobalVariable::LinkageTypes
Linkage;
3796 MicrosoftCXXABI &ABI;
3805 Classes.push_back(MSRTTIClass(RD));
3816 for (MSRTTIClass *Class = &Classes.front(); Class <= &Classes.back();) {
3817 if ((Class->Flags & MSRTTIClass::IsVirtual) &&
3818 !VirtualBases.insert(Class->RD).second) {
3819 Class = MSRTTIClass::getNextChild(Class);
3822 if (!UniqueBases.insert(Class->RD).second)
3823 AmbiguousBases.insert(Class->RD);
3826 if (AmbiguousBases.empty())
3828 for (MSRTTIClass &Class : Classes)
3829 if (AmbiguousBases.count(Class.RD))
3830 Class.Flags |= MSRTTIClass::IsAmbiguous;
3833llvm::GlobalVariable *MSRTTIBuilder::getClassHierarchyDescriptor() {
3834 SmallString<256> MangledName;
3836 llvm::raw_svector_ostream
Out(MangledName);
3837 ABI.getMangleContext().mangleCXXRTTIClassHierarchyDescriptor(RD, Out);
3841 if (
auto CHD =
Module.getNamedGlobal(MangledName))
3845 SmallVector<MSRTTIClass, 8> Classes;
3847 Classes.front().initialize(
nullptr,
nullptr);
3850 for (
const MSRTTIClass &
Class : Classes) {
3851 if (
Class.RD->getNumBases() > 1)
3852 Flags |= HasBranchingHierarchy;
3855 if (
Class.Flags & MSRTTIClass::IsAmbiguous)
3856 Flags |= HasAmbiguousBases;
3858 if ((Flags & HasBranchingHierarchy) && RD->getNumVBases() != 0)
3859 Flags |= HasVirtualBranchingHierarchy;
3862 auto Type = ABI.getClassHierarchyDescriptorType();
3866 if (CHD->isWeakForLinker())
3867 CHD->setComdat(CGM.
getModule().getOrInsertComdat(CHD->getName()));
3869 auto *Bases = getBaseClassArray(Classes);
3872 llvm::Constant *Fields[] = {
3873 llvm::ConstantInt::get(CGM.
IntTy, 0),
3874 llvm::ConstantInt::get(CGM.
IntTy, Flags),
3875 llvm::ConstantInt::get(CGM.
IntTy, Classes.size()),
3876 ABI.getImageRelativeConstant(Bases)
3878 CHD->setInitializer(llvm::ConstantStruct::get(
Type, Fields));
3882llvm::GlobalVariable *
3883MSRTTIBuilder::getBaseClassArray(SmallVectorImpl<MSRTTIClass> &Classes) {
3884 SmallString<256> MangledName;
3886 llvm::raw_svector_ostream
Out(MangledName);
3887 ABI.getMangleContext().mangleCXXRTTIBaseClassArray(RD, Out);
3895 llvm::Type *PtrType = ABI.getImageRelativeType(CGM.
DefaultPtrTy);
3896 auto *ArrType = llvm::ArrayType::get(PtrType, Classes.size() + 1);
3898 new llvm::GlobalVariable(
Module, ArrType,
3900 nullptr, MangledName);
3901 if (BCA->isWeakForLinker())
3902 BCA->setComdat(CGM.
getModule().getOrInsertComdat(BCA->getName()));
3905 SmallVector<llvm::Constant *, 8> BaseClassArrayData;
3906 for (MSRTTIClass &
Class : Classes)
3907 BaseClassArrayData.push_back(
3908 ABI.getImageRelativeConstant(getBaseClassDescriptor(
Class)));
3909 BaseClassArrayData.push_back(llvm::Constant::getNullValue(PtrType));
3910 BCA->setInitializer(llvm::ConstantArray::get(ArrType, BaseClassArrayData));
3914llvm::GlobalVariable *
3915MSRTTIBuilder::getBaseClassDescriptor(
const MSRTTIClass &
Class) {
3920 if (
Class.VirtualRoot) {
3922 OffsetInVBTable = VTableContext.getVBTableIndex(RD,
Class.VirtualRoot) * 4;
3926 SmallString<256> MangledName;
3928 llvm::raw_svector_ostream
Out(MangledName);
3929 ABI.getMangleContext().mangleCXXRTTIBaseClassDescriptor(
3930 Class.RD,
Class.OffsetInVBase, VBPtrOffset, OffsetInVBTable,
3935 if (
auto BCD =
Module.getNamedGlobal(MangledName))
3939 auto Type = ABI.getBaseClassDescriptorType();
3942 nullptr, MangledName);
3943 if (BCD->isWeakForLinker())
3944 BCD->setComdat(CGM.
getModule().getOrInsertComdat(BCD->getName()));
3947 llvm::Constant *Fields[] = {
3948 ABI.getImageRelativeConstant(
3950 llvm::ConstantInt::get(CGM.
IntTy,
Class.NumBases),
3951 llvm::ConstantInt::get(CGM.
IntTy,
Class.OffsetInVBase),
3952 llvm::ConstantInt::getSigned(CGM.
IntTy, VBPtrOffset),
3953 llvm::ConstantInt::get(CGM.
IntTy, OffsetInVBTable),
3954 llvm::ConstantInt::get(CGM.
IntTy,
Class.Flags),
3955 ABI.getImageRelativeConstant(
3956 MSRTTIBuilder(ABI,
Class.RD).getClassHierarchyDescriptor()),
3958 BCD->setInitializer(llvm::ConstantStruct::get(
Type, Fields));
3962llvm::GlobalVariable *
3963MSRTTIBuilder::getCompleteObjectLocator(
const VPtrInfo &Info) {
3964 SmallString<256> MangledName;
3966 llvm::raw_svector_ostream
Out(MangledName);
3967 ABI.getMangleContext().mangleCXXRTTICompleteObjectLocator(RD, Info.
MangledPath, Out);
3971 if (
auto COL =
Module.getNamedGlobal(MangledName))
3976 int VFPtrOffset = 0;
3982 ->second.hasVtorDisp())
3986 llvm::StructType *
Type = ABI.getCompleteObjectLocatorType();
3988 nullptr, MangledName);
3991 llvm::Constant *Fields[] = {
3992 llvm::ConstantInt::get(CGM.
IntTy, ABI.isRTTIImageRelative()),
3993 llvm::ConstantInt::get(CGM.
IntTy, OffsetToTop),
3994 llvm::ConstantInt::get(CGM.
IntTy, VFPtrOffset),
3995 ABI.getImageRelativeConstant(
3997 ABI.getImageRelativeConstant(getClassHierarchyDescriptor()),
3998 ABI.getImageRelativeConstant(COL),
4000 llvm::ArrayRef<llvm::Constant *> FieldsRef(Fields);
4001 if (!ABI.isRTTIImageRelative())
4002 FieldsRef = FieldsRef.drop_back();
4003 COL->setInitializer(llvm::ConstantStruct::get(
Type, FieldsRef));
4004 if (COL->isWeakForLinker())
4005 COL->setComdat(CGM.
getModule().getOrInsertComdat(COL->getName()));
4010 bool &IsConst,
bool &IsVolatile,
4011 bool &IsUnaligned) {
4012 T = Context.getExceptionObjectType(
T);
4021 IsUnaligned =
false;
4022 QualType PointeeType =
T->getPointeeType();
4023 if (!PointeeType.
isNull()) {
4033 MPTy->getQualifier(),
4034 MPTy->getMostRecentCXXRecordDecl());
4038 if (
T->isPointerType())
4045MicrosoftCXXABI::getAddrOfCXXCatchHandlerType(QualType
Type,
4046 QualType CatchHandlerType) {
4050 bool IsConst, IsVolatile, IsUnaligned;
4066 return CatchTypeInfo{getAddrOfRTTIDescriptor(
Type)->stripPointerCasts(),
4074llvm::Constant *MicrosoftCXXABI::getAddrOfRTTIDescriptor(QualType
Type) {
4075 SmallString<256> MangledName;
4077 llvm::raw_svector_ostream
Out(MangledName);
4078 getMangleContext().mangleCXXRTTI(
Type, Out);
4082 if (llvm::GlobalVariable *GV = CGM.
getModule().getNamedGlobal(MangledName))
4089 SmallString<256> TypeInfoString;
4091 llvm::raw_svector_ostream
Out(TypeInfoString);
4092 getMangleContext().mangleCXXRTTIName(
Type, Out);
4096 llvm::Constant *Fields[] = {
4098 llvm::ConstantPointerNull::get(CGM.
Int8PtrTy),
4099 llvm::ConstantDataArray::getString(CGM.
getLLVMContext(), TypeInfoString)};
4100 llvm::StructType *TypeDescriptorType =
4101 getTypeDescriptorType(TypeInfoString);
4102 auto *Var =
new llvm::GlobalVariable(
4103 CGM.
getModule(), TypeDescriptorType,
false,
4104 getLinkageForRTTI(
Type),
4105 llvm::ConstantStruct::get(TypeDescriptorType, Fields),
4107 if (Var->isWeakForLinker())
4108 Var->setComdat(CGM.
getModule().getOrInsertComdat(Var->getName()));
4113llvm::GlobalVariable *
4114MicrosoftCXXABI::getMSCompleteObjectLocator(
const CXXRecordDecl *RD,
4115 const VPtrInfo &Info) {
4116 return MSRTTIBuilder(*
this, RD).getCompleteObjectLocator(Info);
4119void MicrosoftCXXABI::emitCXXStructor(GlobalDecl GD) {
4120 if (
auto *ctor = dyn_cast<CXXConstructorDecl>(GD.
getDecl())) {
4122 llvm::Function *
Fn =
4134 dtor->getParent()->getNumVBases() == 0)
4157 if (
Fn->isWeakForLinker())
4158 Fn->setComdat(CGM.
getModule().getOrInsertComdat(
Fn->getName()));
4162MicrosoftCXXABI::getAddrOfCXXCtorClosure(
const CXXConstructorDecl *CD,
4167 SmallString<256> ThunkName;
4168 llvm::raw_svector_ostream
Out(ThunkName);
4169 getMangleContext().mangleName(GlobalDecl(CD, CT), Out);
4172 if (llvm::GlobalValue *GV = CGM.
getModule().getNamedValue(ThunkName))
4178 const CXXRecordDecl *RD = CD->
getParent();
4179 CanQualType RecordTy = getContext().getCanonicalTagType(RD);
4180 llvm::Function *ThunkFn = llvm::Function::Create(
4181 ThunkTy, getLinkageForRTTI(RecordTy), ThunkName.str(), &CGM.
getModule());
4182 ThunkFn->setCallingConv(
static_cast<llvm::CallingConv::ID
>(
4184 if (ThunkFn->isWeakForLinker())
4185 ThunkFn->setComdat(CGM.
getModule().getOrInsertComdat(ThunkFn->getName()));
4189 CodeGenFunction CGF(CGM);
4193 FunctionArgList FunctionArgs;
4196 buildThisParam(CGF, FunctionArgs);
4201 getContext(),
nullptr, SourceLocation(),
4202 &getContext().Idents.get(
"src"),
4203 getContext().getLValueReferenceType(RecordTy,
4205 ImplicitParamKind::Other);
4207 FunctionArgs.push_back(SrcParam);
4212 auto *IsMostDerived =
4214 &getContext().Idents.get(
"is_most_derived"),
4215 getContext().IntTy, ImplicitParamKind::Other);
4218 FunctionArgs.push_back(IsMostDerived);
4223 FunctionArgs, CD->
getLocation(), SourceLocation());
4226 setCXXABIThisValue(CGF, loadIncomingCXXThis(CGF));
4227 llvm::Value *
This = getThisValue(CGF);
4229 llvm::Value *SrcVal =
4243 SmallVector<const Stmt *, 4> ArgVec;
4244 for (
const CXXDefaultArgExpr *Expr :
4246 ArgVec.push_back(Expr);
4249 CodeGenFunction::RunCleanupsScope Cleanups(CGF);
4251 const auto *FPT = CD->
getType()->
castAs<FunctionProtoType>();
4252 CGF.
EmitCallArgs(Args, FPT, ArrayRef(ArgVec), CD, IsCopy ? 1 : 0);
4255 AddedStructorArgCounts ExtraArgs =
4260 llvm::Constant *CalleePtr =
4268 Args, CD,
Ctor_Complete, ExtraArgs.Prefix, ExtraArgs.Suffix,
4270 CGF.
EmitCall(CalleeInfo, Callee, ReturnValueSlot(), Args);
4272 Cleanups.ForceCleanup();
4281llvm::Constant *MicrosoftCXXABI::getCatchableType(QualType
T,
4288 const CXXConstructorDecl *CD =
4295 uint32_t Size = getContext().getTypeSizeInChars(
T).getQuantity();
4296 SmallString<256> MangledName;
4298 llvm::raw_svector_ostream
Out(MangledName);
4299 getMangleContext().mangleCXXCatchableType(
T, CD, CT, Size, NVOffset,
4300 VBPtrOffset, VBIndex, Out);
4302 if (llvm::GlobalVariable *GV = CGM.
getModule().getNamedGlobal(MangledName))
4303 return getThrowInfoRelativeConstant(GV);
4307 llvm::Constant *TD = getThrowInfoRelativeConstant(getAddrOfRTTIDescriptor(
T));
4311 llvm::Constant *CopyCtor;
4317 CopyCtor = getThrowInfoRelativeConstant(CopyCtor);
4320 llvm::Constant::getNullValue(getThrowInfoRelativeType(CGM.
Int8PtrTy));
4323 bool IsScalar = !RD;
4324 bool HasVirtualBases =
false;
4325 bool IsStdBadAlloc =
false;
4326 QualType PointeeType =
T;
4340 if (HasVirtualBases)
4345 llvm::Constant *Fields[] = {
4346 llvm::ConstantInt::get(CGM.
IntTy, Flags),
4348 llvm::ConstantInt::get(CGM.
IntTy, NVOffset),
4349 llvm::ConstantInt::getSigned(CGM.
IntTy, VBPtrOffset),
4350 llvm::ConstantInt::get(CGM.
IntTy, VBIndex),
4351 llvm::ConstantInt::get(CGM.
IntTy, Size),
4354 llvm::StructType *CTType = getCatchableTypeType();
4355 auto *GV =
new llvm::GlobalVariable(
4356 CGM.
getModule(), CTType,
true, getLinkageForRTTI(
T),
4357 llvm::ConstantStruct::get(CTType, Fields), MangledName);
4358 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4359 GV->setSection(
".xdata");
4360 if (GV->isWeakForLinker())
4361 GV->setComdat(CGM.
getModule().getOrInsertComdat(GV->getName()));
4362 return getThrowInfoRelativeConstant(GV);
4365llvm::GlobalVariable *MicrosoftCXXABI::getCatchableTypeArray(QualType
T) {
4369 llvm::GlobalVariable *&CTA = CatchableTypeArrays[
T];
4376 llvm::SmallSetVector<llvm::Constant *, 2> CatchableTypes;
4386 const CXXRecordDecl *MostDerivedClass =
nullptr;
4394 if (MostDerivedClass) {
4395 const ASTContext &Context = getContext();
4396 const ASTRecordLayout &MostDerivedLayout =
4399 SmallVector<MSRTTIClass, 8> Classes;
4401 Classes.front().initialize(
nullptr,
nullptr);
4403 for (
const MSRTTIClass &
Class : Classes) {
4406 (MSRTTIClass::IsPrivateOnPath | MSRTTIClass::IsAmbiguous))
4411 if (
Class.VirtualRoot) {
4422 CatchableTypes.insert(getCatchableType(RTTITy,
Class.OffsetInVBase,
4423 VBPtrOffset, OffsetInVBTable));
4431 CatchableTypes.insert(getCatchableType(
T));
4444 CatchableTypes.insert(getCatchableType(getContext().VoidPtrTy));
4455 CatchableTypes.insert(getCatchableType(getContext().VoidPtrTy));
4457 uint32_t NumEntries = CatchableTypes.size();
4458 llvm::Type *CTType = getThrowInfoRelativeType(CGM.
DefaultPtrTy);
4459 llvm::ArrayType *AT = llvm::ArrayType::get(CTType, NumEntries);
4460 llvm::StructType *CTAType = getCatchableTypeArrayType(NumEntries);
4461 llvm::Constant *Fields[] = {
4462 llvm::ConstantInt::get(CGM.
IntTy, NumEntries),
4463 llvm::ConstantArray::get(
4464 AT, llvm::ArrayRef(CatchableTypes.begin(),
4465 CatchableTypes.end()))
4467 SmallString<256> MangledName;
4469 llvm::raw_svector_ostream
Out(MangledName);
4470 getMangleContext().mangleCXXCatchableTypeArray(
T, NumEntries, Out);
4472 CTA =
new llvm::GlobalVariable(
4473 CGM.
getModule(), CTAType,
true, getLinkageForRTTI(
T),
4474 llvm::ConstantStruct::get(CTAType, Fields), MangledName);
4475 CTA->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4476 CTA->setSection(
".xdata");
4477 if (CTA->isWeakForLinker())
4478 CTA->setComdat(CGM.
getModule().getOrInsertComdat(CTA->getName()));
4482llvm::GlobalVariable *MicrosoftCXXABI::getThrowInfo(QualType
T) {
4483 bool IsConst, IsVolatile, IsUnaligned;
4488 llvm::GlobalVariable *CTA = getCatchableTypeArray(
T);
4495 ->getLimitedValue();
4497 SmallString<256> MangledName;
4499 llvm::raw_svector_ostream
Out(MangledName);
4500 getMangleContext().mangleCXXThrowInfo(
T, IsConst, IsVolatile, IsUnaligned,
4506 if (llvm::GlobalVariable *GV = CGM.
getModule().getNamedGlobal(MangledName))
4522 llvm::Constant *CleanupFn =
4523 llvm::Constant::getNullValue(getThrowInfoRelativeType(CGM.
Int8PtrTy));
4526 if (!DtorD->isTrivial())
4527 CleanupFn = getThrowInfoRelativeConstant(
4530 llvm::Constant *ForwardCompat =
4531 llvm::Constant::getNullValue(getThrowInfoRelativeType(CGM.
Int8PtrTy));
4532 llvm::Constant *PointerToCatchableTypes = getThrowInfoRelativeConstant(CTA);
4533 llvm::StructType *TIType = getThrowInfoType();
4534 llvm::Constant *Fields[] = {
4535 llvm::ConstantInt::get(CGM.
IntTy, Flags),
4538 PointerToCatchableTypes
4540 auto *GV =
new llvm::GlobalVariable(
4541 CGM.
getModule(), TIType,
true, getLinkageForRTTI(
T),
4542 llvm::ConstantStruct::get(TIType, Fields), MangledName.str());
4543 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4544 GV->setSection(
".xdata");
4545 if (GV->isWeakForLinker())
4546 GV->setComdat(CGM.
getModule().getOrInsertComdat(GV->getName()));
4550void MicrosoftCXXABI::emitThrow(CodeGenFunction &CGF,
const CXXThrowExpr *E) {
4552 assert(SubExpr &&
"SubExpr cannot be null");
4553 QualType ThrowType = SubExpr->
getType();
4562 llvm::GlobalVariable *TI = getThrowInfo(ThrowType);
4569std::pair<llvm::Value *, const CXXRecordDecl *>
4570MicrosoftCXXABI::LoadVTablePtr(CodeGenFunction &CGF, Address This,
4571 const CXXRecordDecl *RD) {
4573 std::tie(This, std::ignore, RD) = performBaseAdjustment(CGF, This,
T);
4577bool MicrosoftCXXABI::isPermittedToBeHomogeneousAggregate(
4578 const CXXRecordDecl *RD)
const {
4608 for (
const CXXBaseSpecifier &B : RD->
bases()) {
4609 if (
const CXXRecordDecl *FRD = B.getType()->getAsCXXRecordDecl()) {
4610 if (!isPermittedToBeHomogeneousAggregate(FRD))
static Address emitDynamicCastToVoid(CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, Address src)
static mlir::Value emitExactDynamicCast(CIRGenItaniumCXXABI &abi, CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, QualType destRecordTy, cir::PointerType destCIRTy, bool isRefCast, Address src)
static RValue performReturnAdjustment(CIRGenFunction &cgf, QualType resultType, RValue rv, const ThunkInfo &thunk)
static llvm::FunctionCallee getThrowFn(CodeGenModule &CGM)
static void emitTlsGuardCheck(CodeGenFunction &CGF, llvm::GlobalValue *TlsGuard, llvm::BasicBlock *DynInitBB, llvm::BasicBlock *ContinueBB)
static llvm::GlobalVariable * getTypeInfoVTable(CodeGenModule &CGM)
static bool hasDefaultCXXMethodCC(ASTContext &Context, const CXXMethodDecl *MD)
static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty, CodeGenModule &CGM)
static llvm::FunctionCallee getInitThreadAbortFn(CodeGenModule &CGM)
static llvm::FunctionCallee getInitThreadHeaderFn(CodeGenModule &CGM)
static llvm::GlobalValue * getTlsGuardVar(CodeGenModule &CGM)
static QualType decomposeTypeForEH(ASTContext &Context, QualType T, bool &IsConst, bool &IsVolatile, bool &IsUnaligned)
static llvm::CallBase * emitRTtypeidCall(CodeGenFunction &CGF, llvm::Value *Argument)
static llvm::FunctionCallee getDynTlsOnDemandInitFn(CodeGenModule &CGM)
static void emitDynamicTlsInitializationCall(CodeGenFunction &CGF, llvm::GlobalValue *TlsGuard, llvm::BasicBlock *ContinueBB)
static void detectAmbiguousBases(SmallVectorImpl< MSRTTIClass > &Classes)
Find ambiguity among base classes.
static void emitDynamicTlsInitialization(CodeGenFunction &CGF)
static void serializeClassHierarchy(SmallVectorImpl< MSRTTIClass > &Classes, const CXXRecordDecl *RD)
Recursively serializes a class hierarchy in pre-order depth first order.
static llvm::FunctionCallee getInitThreadFooterFn(CodeGenModule &CGM)
static bool isDeletingDtor(GlobalDecl GD)
static void emitGlobalDtorWithTLRegDtor(CodeGenFunction &CGF, const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
static ConstantAddress getInitThreadEpochPtr(CodeGenModule &CGM)
static void mangleVFTableName(MicrosoftMangleContext &MangleContext, const CXXRecordDecl *RD, const VPtrInfo &VFPtr, SmallString< 256 > &Name)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Result
Implement __builtin_bit_cast and related operations.
bool isMemberPointerToDerivedMember() const
const ValueDecl * getMemberPointerDecl() const
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() 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.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
QualType getMemberPointerType(QualType T, NestedNameSpecifier Qualifier, const CXXRecordDecl *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
const CXXConstructorDecl * getCopyConstructorForExceptionObject(CXXRecordDecl *RD)
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
const TargetInfo & getTargetInfo() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType getCanonicalTagType(const TagDecl *TD) const
unsigned getTargetAddressSpace(LangAS AS) const
void recordMemberDataPointerEvaluation(const ValueDecl *VD)
llvm::DenseMap< const CXXRecordDecl *, VBaseInfo > VBaseOffsetsMapTy
CharUnits getVBPtrOffset() const
getVBPtrOffset - Get the offset for virtual base table pointer.
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.
const VBaseOffsetsMapTy & getVBaseOffsetsMap() const
bool hasExtendableVFPtr() const
hasVFPtr - Does this class have a virtual function table pointer that can be extended by a derived cl...
Represents a base class of a C++ class.
VarDecl * getExceptionDecl() const
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
ArrayRef< CXXDefaultArgExpr * > getCtorClosureDefaultArgs() const
FunctionDecl * getOperatorDelete() const
bool isGlobalDelete() const
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.
QualType getThisType() const
Return the type of the this pointer.
Represents a C++ struct/union/class.
bool hasNonTrivialCopyAssignment() const
Determine whether this class has a non-trivial copy assignment operator (C++ [class....
CXXRecordDecl * getMostRecentDecl()
bool hasPrivateFields() const
bool hasProtectedFields() const
bool hasNonTrivialDestructor() const
Determine whether this class has a non-trivial destructor (C++ [class.dtor]p3)
bool isPolymorphic() const
Whether this class is polymorphic (C++ [class.virtual]), which means that the class contains or inher...
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_range vbases()
MSInheritanceModel getMSInheritanceModel() const
Returns the inheritance model used for this record.
bool nullFieldOffsetIsZero() const
In the Microsoft C++ ABI, use zero for the field offset of a null data member pointer if we can guara...
bool hasDefinition() const
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
bool hasNonTrivialDefaultConstructor() const
Determine whether this class has a non-trivial default constructor (C++11 [class.ctor]p5).
bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is virtually derived from the class Base.
bool needsImplicitCopyAssignment() const
Determine whether this class needs an implicit copy assignment operator to be lazily declared.
bool hasSimpleCopyAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous copy assignment operat...
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
const Expr * getSubExpr() const
path_iterator path_begin()
CastKind getCastKind() const
const CXXBaseSpecifier *const * path_const_iterator
This is an opaque type for sizes expressed in character units.
bool isNegative() const
Test whether the quantity is less than zero.
bool isPositive() const
Test whether the quantity is greater than zero.
bool isZero() const
Test whether the quantity equals zero.
llvm::Align getAsAlign() const
Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits One()
Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
static ABIArgInfo getIndirect(CharUnits Alignment, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
void setSRetAfterThis(bool AfterThis)
bool isHomogeneousAggregate(QualType Ty, const Type *&Base, uint64_t &Members) const
isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous aggregate.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
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.
Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::Twine &Name="")
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Address CreateConstByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="")
Implements C++ ABI-specific code generation functions.
RecordArgABI
Specify how one should pass an argument of a record type.
MangleContext & getMangleContext()
Gets the mangle context.
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
bool isInstanceMethod() const
ABIArgInfo & getReturnInfo()
CanQualType getReturnType() const
unsigned getEffectiveCallingConvention() const
getEffectiveCallingConvention - Return the actual calling convention to use, which may depend on the ...
void add(RValue rvalue, QualType type)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass, VTableAuthMode AuthMode=VTableAuthMode::Authenticate)
GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
llvm::Constant * createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
Create a stub function, suitable for being passed to atexit, which passes the given address to the gi...
void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, llvm::FunctionCallee Callee)
Emit a musttail call for a thunk with a potentially adjusted this pointer.
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args)
Emits a call or invoke to the given noreturn runtime function.
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
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.
llvm::Value * getAsNaturalPointerTo(Address Addr, QualType PointeeType)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
EmitAutoVarAlloca - Emit the alloca and debug information for a local variable.
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
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.
llvm::Value * EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy, uint64_t VTableByteOffset, SourceLocation Loc)
Emit a type checked load from the given vtable.
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.
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result type,...
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
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::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
ASTContext & getContext() const
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
void EmitAutoVarCleanups(const AutoVarEmission &emission)
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
CodeGenTypes & getTypes() const
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits(), llvm::Constant *CalleeOverride=nullptr)
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
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::Instruction * CurrentFuncletPad
bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
void PopCleanupBlock(bool FallThroughIsBranchThrough=false, bool ForDeactivation=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
This class organizes the cross-function state that is used while generating LLVM code.
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object)
Add a destructor and object to add to the C++ global destructor function.
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create and attach type metadata for the given vtable.
void setDSOLocal(llvm::GlobalValue *GV) const
llvm::GlobalObject::VCallVisibility GetVCallVisibilityLevel(const CXXRecordDecl *RD, llvm::DenseSet< const CXXRecordDecl * > &Visited)
Returns the vcall visibility of the given type.
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()
bool classNeedsVectorDestructor(const CXXRecordDecl *RD)
Check that class need vector deleting destructor body.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
const ABIInfo & getABIInfo()
DiagnosticsEngine & getDiags() const
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage)
Returns LLVM linkage for a declarator.
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
bool shouldEmitRTTI(bool ForEH=false)
void EmitGlobal(GlobalDecl D)
Emit code for a single global function or var decl.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
void AppendLinkerOptions(StringRef Opts)
Appends Opts to the "llvm.linker.options" metadata value.
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
const llvm::DataLayout & getDataLayout() const
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End)
CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the assumed alignment of a virtual base of a class.
void EmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target)
Emit a definition as a global alias for another definition, unconditionally.
llvm::Function * codegenCXXStructor(GlobalDecl GD)
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
Set the TLS mode for the given LLVM GlobalValue for the thread-local variable declaration D.
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.
MicrosoftVTableContext & getMicrosoftVTableContext()
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
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::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const
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 addDeferredVTable(const CXXRecordDecl *RD)
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)
const CGFunctionInfo & arrangeCXXConstructorCall(const CallArgList &Args, const CXXConstructorDecl *D, CXXCtorType CtorKind, unsigned ExtraPrefixArgs, unsigned ExtraSuffixArgs, const FunctionDecl *ABIInfoFD, bool PassProtoArgs=true)
Arrange a call to a C++ method, passing the given arguments.
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i....
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
const CGFunctionInfo & arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes 'this' as the first parameter followed by varargs.
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
const CGFunctionInfo & arrangeMSCtorClosure(const CXXConstructorDecl *CD, CXXCtorType CT)
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
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.
A specialization of Address that requires the address to be an LLVM Constant.
static RValue get(llvm::Value *V)
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
virtual LangAS getSRetAddrSpace(const CXXRecordDecl *RD) const
Get the address space for an indirect (sret) return of the given type.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
bool isInStdNamespace() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
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.
bool isVariadic() const
Whether this function prototype is variadic.
GlobalDecl - represents a global declaration.
GlobalDecl getWithCtorType(CXXCtorType Type)
GlobalDecl getWithDtorType(CXXDtorType Type)
CXXDtorType getDtorType() const
const Decl * getDecl() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
bool isExplicitDefaultVisibilityExportMapping() const
bool isAllDefaultVisibilityExportMapping() const
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
A pointer to member type per C++ 8.3.3 - Pointers to members.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
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.
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived.
MethodVFTableLocation getMethodVFTableLocation(GlobalDecl GD)
const VPtrInfoVector & getVFPtrOffsets(const CXXRecordDecl *RD)
const VTableLayout & getVFTableLayout(const CXXRecordDecl *RD, CharUnits VFPtrOffset)
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool isExternallyVisible() const
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isConstQualified() const
Determine whether this type is const-qualified.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
bool hasUnaligned() const
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool emitVectorDeletingDtors(const LangOptions &) const
Controls whether to emit MSVC vector deleting destructors.
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool callGlobalDeleteInDeletingDtor(const LangOptions &) const
Controls whether global operator delete is called by the deleting destructor or at the point where de...
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...
bool isPointerType() const
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.
bool isObjectType() const
Determine whether this type is an object type.
Linkage getLinkage() const
Determine the linkage of this type.
bool isNullPtrType() const
ArrayRef< VTableComponent > vtable_components() const
Represents a variable declaration or definition.
TLSKind getTLSKind() const
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
@ 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 * CreateMicrosoftCXXABI(CodeGenModule &CGM)
Creates a Microsoft-family ABI.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
constexpr Variable var(Literal L)
Returns the variable of L.
PRESERVE_NONE bool Ret(InterpState &S)
bool This(InterpState &S, CodePtr OpPC)
@ Address
A pointer to a ValueDecl.
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
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.
bool isa(CodeGen::Address addr)
GVALinkage
A more specific kind of linkage than enum Linkage.
bool inheritanceModelHasNVOffsetField(bool IsMemberFunction, MSInheritanceModel Inheritance)
bool inheritanceModelHasOnlyOneField(bool IsMemberFunction, MSInheritanceModel Inheritance)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool inheritanceModelHasVBPtrOffsetField(MSInheritanceModel Inheritance)
bool inheritanceModelHasVBTableOffsetField(MSInheritanceModel Inheritance)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
SmallVector< std::unique_ptr< VPtrInfo >, 2 > VPtrInfoVector
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
CastKind
CastKind - The kind of operation required for a conversion.
MSInheritanceModel
Assigned inheritance model for a class in the MS C++ ABI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Implicit
An implicit conversion.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t int64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t
const CXXRecordDecl * NearestVBase
llvm::PointerType * VoidPtrTy
llvm::PointerType * Int8PtrPtrTy
CharUnits getIntAlign() const
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
CharUnits getIntSize() const
llvm::IntegerType * SizeTy
llvm::IntegerType * Int32Ty
llvm::IntegerType * IntPtrTy
llvm::IntegerType * IntTy
int
llvm::PointerType * Int8PtrTy
llvm::IntegerType * PtrDiffTy
CharUnits getPointerAlign() const
llvm::PointerType * DefaultPtrTy
const CXXRecordDecl * VBase
If nonnull, holds the last vbase which contains the vfptr that the method definition is adjusted to.
CharUnits VFPtrOffset
This is the offset of the vfptr from the start of the last vbase, or the complete type if there are n...
uint64_t Index
Method's index in the vftable.
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
ThisAdjustment This
The this pointer adjustment.
Holds information about the inheritance path to a virtual base or function table pointer.
CharUnits NonVirtualOffset
IntroducingObject is at this offset from its containing complete object or virtual base.
CharUnits FullOffsetInMDC
Static offset from the top of the most derived class to this vfptr, including any virtual base offset...
const CXXRecordDecl * getVBaseWithVPtr() const
The vptr is stored inside the non-virtual component of this virtual base.
const CXXRecordDecl * IntroducingObject
This is the class that introduced the vptr by declaring new virtual methods or virtual bases.
BasePath MangledPath
The bases from the inheritance path that got used to mangle the vbtable name.
BasePath PathToIntroducingObject
This holds the base classes path from the complete type to the first base with the given vfptr offset...
const CXXRecordDecl * ObjectWithVPtr
This is the most derived class that has this vptr at offset zero.
uint32_t VBPtrOffset
The offset (in bytes) of the vbptr, relative to the beginning of the derived class.
struct clang::ReturnAdjustment::VirtualAdjustment::@167242364125115315334113104006210160165266060257 Microsoft
uint32_t VBIndex
Index of the virtual base in the vbtable.
int32_t VtordispOffset
The offset of the vtordisp (in bytes), relative to the ECX.
struct clang::ThisAdjustment::VirtualAdjustment::@312251255113040203233347230177110330127151157305 Microsoft
int32_t VBOffsetOffset
The offset (in bytes) of the vbase offset in the vbtable.
int32_t VBPtrOffset
The offset of the vbptr of the derived class (in bytes), relative to the ECX after vtordisp adjustmen...