35#include "llvm/IR/DataLayout.h"
36#include "llvm/IR/GlobalValue.h"
37#include "llvm/IR/Instructions.h"
38#include "llvm/IR/Intrinsics.h"
39#include "llvm/IR/Value.h"
40#include "llvm/Support/ConvertEBCDIC.h"
41#include "llvm/Support/ScopedPrinter.h"
51 llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
54 llvm::SmallVector<std::pair<const VarDecl *, llvm::Function *>, 8>
58 bool UseARMMethodPtrABI;
59 bool UseARMGuardVarABI;
60 bool Use32BitVTableOffsetABI;
62 ItaniumMangleContext &getMangleContext() {
67 ItaniumCXXABI(CodeGen::CodeGenModule &CGM,
68 bool UseARMMethodPtrABI =
false,
69 bool UseARMGuardVarABI =
false) :
70 CGCXXABI(CGM), UseARMMethodPtrABI(UseARMMethodPtrABI),
71 UseARMGuardVarABI(UseARMGuardVarABI),
72 Use32BitVTableOffsetABI(
false) { }
83 bool isThisCompleteObject(GlobalDecl GD)
const override {
96 llvm_unreachable(
"emitting dtor comdat as function?");
98 llvm_unreachable(
"emitting unified dtor as function?");
100 llvm_unreachable(
"unexpected dtor kind for this ABI");
102 llvm_unreachable(
"bad dtor kind");
114 llvm_unreachable(
"closure ctors in Itanium ABI?");
117 llvm_unreachable(
"emitting ctor comdat as function?");
120 llvm_unreachable(
"emitting unified ctor as function?");
122 llvm_unreachable(
"bad dtor kind");
129 bool isZeroInitializable(
const MemberPointerType *MPT)
override;
131 llvm::Type *ConvertMemberPointerType(
const MemberPointerType *MPT)
override;
134 EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
137 llvm::Value *&ThisPtrForCall,
138 llvm::Value *MemFnPtr,
139 const MemberPointerType *MPT)
override;
141 llvm::Value *EmitMemberDataPointerAddress(CodeGenFunction &CGF,
const Expr *E,
142 Address Base, llvm::Value *MemPtr,
143 const MemberPointerType *MPT,
144 bool IsInBounds)
override;
146 llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
148 llvm::Value *Src)
override;
149 llvm::Constant *EmitMemberPointerConversion(
const CastExpr *E,
150 llvm::Constant *Src)
override;
152 llvm::Constant *EmitNullMemberPointer(
const MemberPointerType *MPT)
override;
154 llvm::Constant *EmitMemberFunctionPointer(
const CXXMethodDecl *MD)
override;
155 llvm::Constant *EmitMemberDataPointer(
const MemberPointerType *MPT,
156 CharUnits offset)
override;
157 llvm::Constant *EmitMemberPointer(
const APValue &MP, QualType MPT)
override;
158 llvm::Constant *BuildMemberPointer(
const CXXMethodDecl *MD,
159 CharUnits ThisAdjustment);
161 llvm::Value *EmitMemberPointerComparison(CodeGenFunction &CGF,
162 llvm::Value *L, llvm::Value *R,
163 const MemberPointerType *MPT,
164 bool Inequality)
override;
166 llvm::Value *EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
168 const MemberPointerType *MPT)
override;
170 void emitVirtualObjectDelete(CodeGenFunction &CGF,
const CXXDeleteExpr *DE,
171 Address Ptr, QualType ElementType,
172 const CXXDestructorDecl *Dtor)
override;
174 void emitRethrow(CodeGenFunction &CGF,
bool isNoReturn)
override;
175 void emitThrow(CodeGenFunction &CGF,
const CXXThrowExpr *E)
override;
177 void emitBeginCatch(CodeGenFunction &CGF,
const CXXCatchStmt *
C)
override;
180 emitTerminateForUnexpectedException(CodeGenFunction &CGF,
181 llvm::Value *Exn)
override;
183 void EmitFundamentalRTTIDescriptors(
const CXXRecordDecl *RD);
184 llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty)
override;
186 getAddrOfCXXCatchHandlerType(QualType Ty,
187 QualType CatchHandlerType)
override {
188 return CatchTypeInfo{getAddrOfRTTIDescriptor(Ty), 0};
191 bool shouldTypeidBeNullChecked(QualType SrcRecordTy)
override;
192 void EmitBadTypeidCall(CodeGenFunction &CGF)
override;
193 llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
195 llvm::Type *StdTypeInfoPtrTy)
override;
197 bool shouldDynamicCastCallBeNullChecked(
bool SrcIsPtr,
198 QualType SrcRecordTy)
override;
204 bool hasUniqueVTablePointer(QualType RecordTy) {
210 if (CGM.getCodeGenOpts().DisableExactDynamicCast ||
211 getContext().getLangOpts().AppleKext)
216 if (!CGM.shouldEmitRTTI())
221 if (!llvm::GlobalValue::isWeakForLinker(CGM.getVTableLinkage(RD)))
230 llvm::GlobalValue::DefaultVisibility)
236 return !CGM.mayVTableBeDuplicated(CGM.getVTableLinkage(RD));
239 bool shouldEmitExactDynamicCast(QualType DestRecordTy)
override {
240 return hasUniqueVTablePointer(DestRecordTy);
243 std::optional<ExactDynamicCastInfo>
244 getExactDynamicCastInfo(QualType SrcRecordTy, QualType DestTy,
245 QualType DestRecordTy)
override;
247 llvm::Value *emitDynamicCastCall(CodeGenFunction &CGF, Address
Value,
248 QualType SrcRecordTy, QualType DestTy,
249 QualType DestRecordTy,
250 llvm::BasicBlock *CastEnd)
override;
253 QualType SrcRecordTy, QualType DestTy,
254 QualType DestRecordTy,
255 const ExactDynamicCastInfo &CastInfo,
256 llvm::BasicBlock *CastSuccess,
257 llvm::BasicBlock *CastFail)
override;
260 QualType SrcRecordTy)
override;
262 bool EmitBadCastCall(CodeGenFunction &CGF)
override;
265 GetVirtualBaseClassOffset(CodeGenFunction &CGF, Address This,
266 const CXXRecordDecl *ClassDecl,
267 const CXXRecordDecl *BaseClassDecl)
override;
269 void EmitCXXConstructors(
const CXXConstructorDecl *D)
override;
271 AddedStructorArgCounts
272 buildStructorSignature(GlobalDecl GD,
273 SmallVectorImpl<CanQualType> &ArgTys)
override;
275 bool useThunkForDtorVariant(
const CXXDestructorDecl *Dtor,
283 void EmitCXXDestructors(
const CXXDestructorDecl *D)
override;
285 void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
286 FunctionArgList &Params)
override;
288 void EmitInstanceFunctionProlog(CodeGenFunction &CGF)
override;
290 AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF,
291 const CXXConstructorDecl *D,
297 const CXXDestructorDecl *DD,
302 void EmitDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *DD,
305 QualType ThisTy)
override;
307 void emitVTableDefinitions(CodeGenVTables &CGVT,
308 const CXXRecordDecl *RD)
override;
310 bool isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
311 CodeGenFunction::VPtr Vptr)
override;
313 bool doStructorsInitializeVPtrs(
const CXXRecordDecl *VTableClass)
override {
318 getVTableAddressPoint(BaseSubobject Base,
319 const CXXRecordDecl *VTableClass)
override;
321 llvm::Value *getVTableAddressPointInStructor(
322 CodeGenFunction &CGF,
const CXXRecordDecl *VTableClass,
323 BaseSubobject Base,
const CXXRecordDecl *NearestVBase)
override;
325 llvm::Value *getVTableAddressPointInStructorWithVTT(
326 CodeGenFunction &CGF,
const CXXRecordDecl *VTableClass,
327 BaseSubobject Base,
const CXXRecordDecl *NearestVBase);
329 llvm::GlobalVariable *getAddrOfVTable(
const CXXRecordDecl *RD,
330 CharUnits VPtrOffset)
override;
332 CGCallee getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD,
333 Address This, llvm::Type *Ty,
334 SourceLocation Loc)
override;
337 EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
339 DeleteOrMemberCallExpr E,
340 llvm::CallBase **CallOrInvoke)
override;
342 void emitVirtualInheritanceTables(
const CXXRecordDecl *RD)
override;
344 bool canSpeculativelyEmitVTable(
const CXXRecordDecl *RD)
const override;
345 bool canSpeculativelyEmitVTableAsBaseClass(
const CXXRecordDecl *RD)
const;
347 void setThunkLinkage(llvm::Function *Thunk,
bool ForVTable, GlobalDecl GD,
348 bool ReturnAdjustment)
override {
351 if (ForVTable && !Thunk->hasLocalLinkage())
352 Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
353 CGM.setGVProperties(Thunk, GD);
356 bool exportThunk()
override {
return true; }
358 llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This,
359 const CXXRecordDecl *UnadjustedThisClass,
360 const ThunkInfo &TI)
override;
363 const CXXRecordDecl *UnadjustedRetClass,
364 const ReturnAdjustment &RA)
override;
366 size_t getSrcArgforCopyCtor(
const CXXConstructorDecl *,
367 FunctionArgList &Args)
const override {
368 assert(!Args.empty() &&
"expected the arglist to not be empty!");
369 return Args.size() - 1;
372 StringRef GetPureVirtualCallName()
override {
return "__cxa_pure_virtual"; }
373 StringRef GetDeletedVirtualCallName()
override
374 {
return "__cxa_deleted_virtual"; }
376 CharUnits getArrayCookieSizeImpl(QualType elementType)
override;
377 Address InitializeArrayCookie(CodeGenFunction &CGF,
379 llvm::Value *NumElements,
380 const CXXNewExpr *
expr,
381 QualType ElementType)
override;
382 llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF,
384 CharUnits cookieSize)
override;
386 void EmitGuardedInit(CodeGenFunction &CGF,
const VarDecl &D,
387 llvm::GlobalVariable *DeclPtr,
388 bool PerformInit)
override;
389 void registerGlobalDtor(CodeGenFunction &CGF,
const VarDecl &D,
390 llvm::FunctionCallee dtor,
391 llvm::Constant *addr)
override;
393 llvm::Function *getOrCreateThreadLocalWrapper(
const VarDecl *VD,
395 void EmitThreadLocalInitFuncs(
397 ArrayRef<const VarDecl *> CXXThreadLocals,
398 ArrayRef<llvm::Function *> CXXThreadLocalInits,
399 ArrayRef<const VarDecl *> CXXThreadLocalInitVars)
override;
401 bool usesThreadWrapperFunction(
const VarDecl *VD)
const override {
402 return !isEmittedWithConstantInitializer(VD) ||
403 mayNeedDestruction(VD);
405 LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
const VarDecl *VD,
406 QualType LValType)
override;
408 bool NeedsVTTParameter(GlobalDecl GD)
override;
411 getOrCreateVirtualFunctionPointerThunk(
const CXXMethodDecl *MD);
418 virtual bool shouldRTTIBeUnique()
const {
return true; }
422 enum RTTIUniquenessKind {
440 classifyRTTIUniqueness(QualType CanTy,
441 llvm::GlobalValue::LinkageTypes
Linkage)
const;
442 friend class ItaniumRTTIBuilder;
444 void emitCXXStructor(GlobalDecl GD)
override;
446 std::pair<llvm::Value *, const CXXRecordDecl *>
447 LoadVTablePtr(CodeGenFunction &CGF, Address This,
448 const CXXRecordDecl *RD)
override;
452 getSignedVirtualMemberFunctionPointer(
const CXXMethodDecl *MD);
454 bool hasAnyUnusedVirtualInlineFunction(
const CXXRecordDecl *RD)
const {
455 const auto &VtableLayout =
456 CGM.getItaniumVTableContext().getVTableLayout(RD);
458 for (
const auto &VtableComponent : VtableLayout.vtable_components()) {
460 if (!VtableComponent.isUsedFunctionPointerKind())
463 const CXXMethodDecl *
Method = VtableComponent.getFunctionDecl();
464 const FunctionDecl *FD =
Method->getDefinition();
465 const bool IsInlined =
470 StringRef Name = CGM.getMangledName(
471 VtableComponent.getGlobalDecl(
false));
472 auto *Entry = CGM.GetGlobalValue(Name);
478 if (!Entry || Entry->isDeclaration())
484 bool isVTableHidden(
const CXXRecordDecl *RD)
const {
485 const auto &VtableLayout =
486 CGM.getItaniumVTableContext().getVTableLayout(RD);
488 for (
const auto &VtableComponent : VtableLayout.vtable_components()) {
489 if (VtableComponent.isRTTIKind()) {
490 const CXXRecordDecl *RTTIDecl = VtableComponent.getRTTIDecl();
491 if (RTTIDecl->
getVisibility() == Visibility::HiddenVisibility)
493 }
else if (VtableComponent.isUsedFunctionPointerKind()) {
494 const CXXMethodDecl *
Method = VtableComponent.getFunctionDecl();
495 if (
Method->getVisibility() == Visibility::HiddenVisibility &&
504class ARMCXXABI :
public ItaniumCXXABI {
506 ARMCXXABI(CodeGen::CodeGenModule &CGM) :
507 ItaniumCXXABI(CGM,
true,
510 bool constructorsAndDestructorsReturnThis()
const override {
return true; }
512 void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV,
513 QualType ResTy)
override;
515 CharUnits getArrayCookieSizeImpl(QualType elementType)
override;
516 Address InitializeArrayCookie(CodeGenFunction &CGF,
518 llvm::Value *NumElements,
519 const CXXNewExpr *
expr,
520 QualType ElementType)
override;
521 llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF, Address allocPtr,
522 CharUnits cookieSize)
override;
525class AppleARM64CXXABI :
public ARMCXXABI {
527 AppleARM64CXXABI(CodeGen::CodeGenModule &CGM) : ARMCXXABI(CGM) {
528 Use32BitVTableOffsetABI =
true;
532 bool shouldRTTIBeUnique()
const override {
return false; }
535class FuchsiaCXXABI final :
public ItaniumCXXABI {
537 explicit FuchsiaCXXABI(CodeGen::CodeGenModule &CGM)
538 : ItaniumCXXABI(CGM) {}
541 bool constructorsAndDestructorsReturnThis()
const override {
return true; }
544class WebAssemblyCXXABI final :
public ItaniumCXXABI {
546 explicit WebAssemblyCXXABI(CodeGen::CodeGenModule &CGM)
547 : ItaniumCXXABI(CGM,
true,
549 void emitBeginCatch(CodeGenFunction &CGF,
const CXXCatchStmt *
C)
override;
551 emitTerminateForUnexpectedException(CodeGenFunction &CGF,
552 llvm::Value *Exn)
override;
555 bool constructorsAndDestructorsReturnThis()
const override {
return true; }
556 bool canCallMismatchedFunctionType()
const override {
return false; }
559class XLCXXABI final :
public ItaniumCXXABI {
561 explicit XLCXXABI(CodeGen::CodeGenModule &CGM)
562 : ItaniumCXXABI(CGM) {}
564 void registerGlobalDtor(CodeGenFunction &CGF,
const VarDecl &D,
565 llvm::FunctionCallee dtor,
566 llvm::Constant *addr)
override;
568 bool useSinitAndSterm()
const override {
return true; }
571 void emitCXXStermFinalizer(
const VarDecl &D, llvm::Function *dtorStub,
572 llvm::Constant *addr);
580 case TargetCXXABI::GenericARM:
581 case TargetCXXABI::iOS:
582 case TargetCXXABI::WatchOS:
583 return new ARMCXXABI(CGM);
585 case TargetCXXABI::AppleARM64:
586 return new AppleARM64CXXABI(CGM);
588 case TargetCXXABI::Fuchsia:
589 return new FuchsiaCXXABI(CGM);
594 case TargetCXXABI::GenericAArch64:
595 return new ItaniumCXXABI(CGM,
true,
598 case TargetCXXABI::GenericMIPS:
599 return new ItaniumCXXABI(CGM,
true);
601 case TargetCXXABI::WebAssembly:
602 return new WebAssemblyCXXABI(CGM);
604 case TargetCXXABI::XL:
605 return new XLCXXABI(CGM);
607 case TargetCXXABI::GenericItanium:
608 return new ItaniumCXXABI(CGM);
610 case TargetCXXABI::Microsoft:
611 llvm_unreachable(
"Microsoft ABI is not Itanium-based");
613 llvm_unreachable(
"bad ABI kind");
619 return CGM.PtrDiffTy;
620 return llvm::StructType::get(CGM.PtrDiffTy, CGM.PtrDiffTy);
643CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
645 llvm::Value *&ThisPtrForCall,
653 llvm::Constant *ptrdiff_1 = llvm::ConstantInt::get(CGM.PtrDiffTy, 1);
660 llvm::Value *RawAdj = Builder.CreateExtractValue(MemFnPtr, 1,
"memptr.adj");
663 llvm::Value *Adj = RawAdj;
664 if (UseARMMethodPtrABI)
665 Adj = Builder.CreateAShr(Adj, ptrdiff_1,
"memptr.adj.shifted");
670 This = Builder.CreateInBoundsGEP(Builder.getInt8Ty(),
This, Adj);
671 ThisPtrForCall =
This;
674 llvm::Value *FnAsInt = Builder.CreateExtractValue(MemFnPtr, 0,
"memptr.ptr");
678 llvm::Value *IsVirtual;
679 if (UseARMMethodPtrABI)
680 IsVirtual = Builder.CreateAnd(RawAdj, ptrdiff_1);
682 IsVirtual = Builder.CreateAnd(FnAsInt, ptrdiff_1);
683 IsVirtual = Builder.CreateIsNotNull(IsVirtual,
"memptr.isvirtual");
684 Builder.CreateCondBr(IsVirtual, FnVirtual, FnNonVirtual);
702 llvm::Value *VTableOffset = FnAsInt;
703 if (!UseARMMethodPtrABI)
704 VTableOffset = Builder.CreateSub(VTableOffset, ptrdiff_1);
705 if (Use32BitVTableOffsetABI) {
706 VTableOffset = Builder.CreateTrunc(VTableOffset, CGF.
Int32Ty);
707 VTableOffset = Builder.CreateZExt(VTableOffset, CGM.PtrDiffTy);
712 bool ShouldEmitCFICheck = CGF.
SanOpts.
has(SanitizerKind::CFIMFCall) &&
713 CGM.HasHiddenLTOVisibility(RD);
715 if (ShouldEmitCFICheck) {
716 if (
const auto *BinOp = dyn_cast<BinaryOperator>(E)) {
717 if (BinOp->isPtrMemOp() &&
720 ->hasPointeeToCFIUncheckedCalleeFunctionType())
721 ShouldEmitCFICheck =
false;
725 bool ShouldEmitVFEInfo = CGM.getCodeGenOpts().VirtualFunctionElimination &&
726 CGM.HasHiddenLTOVisibility(RD);
730 bool ShouldEmitWPDInfo =
731 (CGM.getCodeGenOpts().WholeProgramVTables &&
733 !CGM.AlwaysHasLTOVisibilityPublic(RD)) ||
734 CGM.getCodeGenOpts().DevirtualizeSpeculatively;
735 llvm::Value *VirtualFn =
nullptr;
738 auto CheckOrdinal = SanitizerKind::SO_CFIMFCall;
739 auto CheckHandler = SanitizerHandler::CFICheckFail;
740 SanitizerDebugLocation SanScope(&CGF, {CheckOrdinal}, CheckHandler);
742 llvm::Value *TypeId =
nullptr;
743 llvm::Value *CheckResult =
nullptr;
745 if (ShouldEmitCFICheck || ShouldEmitVFEInfo || ShouldEmitWPDInfo) {
749 CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT, 0));
753 if (ShouldEmitVFEInfo) {
754 llvm::Value *VFPAddr =
755 Builder.CreateGEP(CGF.
Int8Ty, VTable, VTableOffset);
762 llvm::Value *CheckedLoad = Builder.CreateCall(
763 CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
764 {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId});
765 CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
766 VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0);
770 if (ShouldEmitCFICheck || ShouldEmitWPDInfo) {
771 llvm::Value *VFPAddr =
772 Builder.CreateGEP(CGF.
Int8Ty, VTable, VTableOffset);
773 llvm::Intrinsic::ID IID = CGM.HasHiddenLTOVisibility(RD)
774 ? llvm::Intrinsic::type_test
775 : llvm::Intrinsic::public_type_test;
778 Builder.CreateCall(CGM.getIntrinsic(IID), {VFPAddr, TypeId});
781 if (CGM.getLangOpts().RelativeCXXABIVTables) {
782 VirtualFn = CGF.
Builder.CreateCall(
783 CGM.getIntrinsic(llvm::Intrinsic::load_relative,
784 {VTableOffset->getType()}),
785 {VTable, VTableOffset});
787 llvm::Value *VFPAddr =
794 assert(VirtualFn &&
"Virtual fuction pointer not created!");
795 assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || !ShouldEmitWPDInfo ||
797 "Check result required but not created!");
799 if (ShouldEmitCFICheck) {
804 if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) {
807 llvm::Value *AllVtables = llvm::MetadataAsValue::get(
808 CGM.getLLVMContext(),
809 llvm::MDString::get(CGM.getLLVMContext(),
"all-vtables"));
810 llvm::Value *ValidVtable = Builder.CreateCall(
811 CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables});
812 CGF.
EmitCheck(std::make_pair(CheckResult, CheckOrdinal), CheckHandler,
813 StaticData, {VTable, ValidVtable});
816 FnVirtual = Builder.GetInsertBlock();
825 llvm::Value *NonVirtualFn =
826 Builder.CreateIntToPtr(FnAsInt, CGF.
DefaultPtrTy,
"memptr.nonvirtualfn");
829 if (ShouldEmitCFICheck) {
832 auto CheckOrdinal = SanitizerKind::SO_CFIMFCall;
833 auto CheckHandler = SanitizerHandler::CFICheckFail;
834 SanitizerDebugLocation SanScope(&CGF, {CheckOrdinal}, CheckHandler);
839 llvm::Value *Bit = Builder.getFalse();
840 for (
const CXXRecordDecl *Base : CGM.getMostBaseClasses(RD)) {
841 llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(
844 Base->getCanonicalDecl()));
845 llvm::Value *TypeId =
848 llvm::Value *TypeTest =
849 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::type_test),
850 {NonVirtualFn, TypeId});
851 Bit = Builder.CreateOr(Bit, TypeTest);
854 CGF.
EmitCheck(std::make_pair(Bit, CheckOrdinal), CheckHandler, StaticData,
855 {NonVirtualFn, llvm::UndefValue::get(CGF.
IntPtrTy)});
857 FnNonVirtual = Builder.GetInsertBlock();
863 llvm::PHINode *CalleePtr = Builder.CreatePHI(CGF.
DefaultPtrTy, 2);
864 CalleePtr->addIncoming(VirtualFn, FnVirtual);
865 CalleePtr->addIncoming(NonVirtualFn, FnNonVirtual);
867 CGPointerAuthInfo PointerAuth;
869 if (
const auto &Schema =
870 CGM.getCodeGenOpts().PointerAuth.CXXMemberFunctionPointers) {
871 llvm::PHINode *DiscriminatorPHI = Builder.CreatePHI(CGF.
IntPtrTy, 2);
872 DiscriminatorPHI->addIncoming(llvm::ConstantInt::get(CGF.
IntPtrTy, 0),
874 const auto &AuthInfo =
875 CGM.getMemberFunctionPointerAuthInfo(QualType(MPT, 0));
876 assert(Schema.getKey() == AuthInfo.getKey() &&
877 "Keys for virtual and non-virtual member functions must match");
878 auto *NonVirtualDiscriminator = AuthInfo.getDiscriminator();
879 DiscriminatorPHI->addIncoming(NonVirtualDiscriminator, FnNonVirtual);
880 PointerAuth = CGPointerAuthInfo(
881 Schema.getKey(), Schema.getAuthenticationMode(), Schema.isIsaPointer(),
882 Schema.authenticatesNullValues(), DiscriminatorPHI);
885 CGCallee
Callee(FPT, CalleePtr, PointerAuth);
891llvm::Value *ItaniumCXXABI::EmitMemberDataPointerAddress(
892 CodeGenFunction &CGF,
const Expr *E, Address Base, llvm::Value *MemPtr,
893 const MemberPointerType *MPT,
bool IsInBounds) {
894 assert(MemPtr->getType() == CGM.PtrDiffTy);
896 CGBuilderTy &Builder = CGF.
Builder;
899 llvm::Value *BaseAddr =
Base.emitRawPointer(CGF);
900 return Builder.CreateGEP(CGF.
Int8Ty, BaseAddr, MemPtr,
"memptr.offset",
901 IsInBounds ? llvm::GEPNoWrapFlags::inBounds()
902 : llvm::GEPNoWrapFlags::none());
909 const auto *CPA = dyn_cast<llvm::ConstantPtrAuth>(Ptr);
914 assert(CPA->getKey()->getZExtValue() == CurAuthInfo.
getKey() &&
915 CPA->getAddrDiscriminator()->isNullValue() &&
917 "unexpected key or discriminators");
920 CPA->getPointer(), NewAuthInfo.
getKey(),
nullptr,
948ItaniumCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
955 assert(E->
getCastKind() == CK_DerivedToBaseMemberPointer ||
956 E->
getCastKind() == CK_BaseToDerivedMemberPointer ||
959 CGBuilderTy &Builder = CGF.
Builder;
960 QualType DstType = E->
getType();
963 if (
const auto &NewAuthInfo =
964 CGM.getMemberFunctionPointerAuthInfo(DstType)) {
967 const auto &CurAuthInfo = CGM.getMemberFunctionPointerAuthInfo(SrcType);
968 llvm::Value *MemFnPtr = Builder.CreateExtractValue(src, 0,
"memptr.ptr");
969 llvm::Type *OrigTy = MemFnPtr->getType();
971 llvm::BasicBlock *StartBB = Builder.GetInsertBlock();
976 assert(UseARMMethodPtrABI &&
"ARM ABI expected");
977 llvm::Value *Adj = Builder.CreateExtractValue(src, 1,
"memptr.adj");
978 llvm::Constant *Ptrdiff_1 = llvm::ConstantInt::get(CGM.PtrDiffTy, 1);
979 llvm::Value *AndVal = Builder.CreateAnd(Adj, Ptrdiff_1);
980 llvm::Value *IsVirtualOffset =
981 Builder.CreateIsNotNull(AndVal,
"is.virtual.offset");
982 Builder.CreateCondBr(IsVirtualOffset, MergeBB, ResignBB);
985 llvm::Type *PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
986 MemFnPtr = Builder.CreateIntToPtr(MemFnPtr, PtrTy);
990 MemFnPtr = Builder.CreatePtrToInt(MemFnPtr, OrigTy);
991 llvm::Value *ResignedVal = Builder.CreateInsertValue(src, MemFnPtr, 0);
992 ResignBB = Builder.GetInsertBlock();
995 llvm::PHINode *NewSrc = Builder.CreatePHI(src->getType(), 2);
996 NewSrc->addIncoming(src, StartBB);
997 NewSrc->addIncoming(ResignedVal, ResignBB);
1003 if (E->
getCastKind() == CK_ReinterpretMemberPointer)
return src;
1005 llvm::Constant *adj = getMemberPointerAdjustment(E);
1006 if (!adj)
return src;
1008 bool isDerivedToBase = (E->
getCastKind() == CK_DerivedToBaseMemberPointer);
1010 const MemberPointerType *destTy =
1017 if (isDerivedToBase)
1018 dst = Builder.CreateNSWSub(src, adj,
"adj");
1020 dst = Builder.CreateNSWAdd(src, adj,
"adj");
1023 llvm::Value *null = llvm::Constant::getAllOnesValue(src->getType());
1024 llvm::Value *isNull = Builder.CreateICmpEQ(src, null,
"memptr.isnull");
1025 return Builder.CreateSelect(isNull, src, dst);
1029 if (UseARMMethodPtrABI) {
1032 adj = llvm::ConstantInt::get(adj->getType(), offset);
1035 llvm::Value *srcAdj = Builder.CreateExtractValue(src, 1,
"src.adj");
1036 llvm::Value *dstAdj;
1037 if (isDerivedToBase)
1038 dstAdj = Builder.CreateNSWSub(srcAdj, adj,
"adj");
1040 dstAdj = Builder.CreateNSWAdd(srcAdj, adj,
"adj");
1042 return Builder.CreateInsertValue(src, dstAdj, 1);
1045static llvm::Constant *
1050 "member function pointers expected");
1051 if (DestType == SrcType)
1057 if (!NewAuthInfo && !CurAuthInfo)
1060 llvm::Constant *MemFnPtr = Src->getAggregateElement(0u);
1061 if (MemFnPtr->getNumOperands() == 0) {
1069 ConstPtr = llvm::ConstantExpr::getPtrToInt(ConstPtr, MemFnPtr->getType());
1070 return ConstantFoldInsertValueInstruction(Src, ConstPtr, 0);
1074ItaniumCXXABI::EmitMemberPointerConversion(
const CastExpr *E,
1075 llvm::Constant *src) {
1076 assert(E->
getCastKind() == CK_DerivedToBaseMemberPointer ||
1077 E->
getCastKind() == CK_BaseToDerivedMemberPointer ||
1080 QualType DstType = E->
getType();
1087 if (E->
getCastKind() == CK_ReinterpretMemberPointer)
return src;
1090 llvm::Constant *adj = getMemberPointerAdjustment(E);
1091 if (!adj)
return src;
1093 bool isDerivedToBase = (E->
getCastKind() == CK_DerivedToBaseMemberPointer);
1095 const MemberPointerType *destTy =
1102 if (src->isAllOnesValue())
return src;
1104 if (isDerivedToBase)
1105 return llvm::ConstantExpr::getNSWSub(src, adj);
1107 return llvm::ConstantExpr::getNSWAdd(src, adj);
1111 if (UseARMMethodPtrABI) {
1114 adj = llvm::ConstantInt::get(adj->getType(), offset);
1117 llvm::Constant *srcAdj = src->getAggregateElement(1);
1118 llvm::Constant *dstAdj;
1119 if (isDerivedToBase)
1120 dstAdj = llvm::ConstantExpr::getNSWSub(srcAdj, adj);
1122 dstAdj = llvm::ConstantExpr::getNSWAdd(srcAdj, adj);
1124 llvm::Constant *res = ConstantFoldInsertValueInstruction(src, dstAdj, 1);
1125 assert(res !=
nullptr &&
"Folding must succeed");
1130ItaniumCXXABI::EmitNullMemberPointer(
const MemberPointerType *MPT) {
1134 return llvm::ConstantInt::get(CGM.PtrDiffTy, -1ULL,
true);
1136 llvm::Constant *
Zero = llvm::ConstantInt::get(CGM.PtrDiffTy, 0);
1137 llvm::Constant *Values[2] = {
Zero,
Zero };
1138 return llvm::ConstantStruct::getAnon(Values);
1142ItaniumCXXABI::EmitMemberDataPointer(
const MemberPointerType *MPT,
1147 return llvm::ConstantInt::get(CGM.PtrDiffTy, offset.
getQuantity());
1151ItaniumCXXABI::EmitMemberFunctionPointer(
const CXXMethodDecl *MD) {
1155llvm::Constant *ItaniumCXXABI::BuildMemberPointer(
const CXXMethodDecl *MD,
1156 CharUnits ThisAdjustment) {
1157 assert(MD->
isInstance() &&
"Member function must not be static!");
1159 CodeGenTypes &Types = CGM.getTypes();
1162 llvm::Constant *MemPtr[2];
1164 uint64_t Index = CGM.getItaniumVTableContext().getMethodVTableIndex(MD);
1166 if (CGM.getLangOpts().RelativeCXXABIVTables) {
1168 VTableOffset = Index * 4;
1170 const ASTContext &Context = getContext();
1173 VTableOffset = Index * PointerWidth.
getQuantity();
1176 if (UseARMMethodPtrABI) {
1198 const auto &Schema =
1199 CGM.getCodeGenOpts().PointerAuth.CXXMemberFunctionPointers;
1201 MemPtr[0] = llvm::ConstantExpr::getPtrToInt(
1202 getSignedVirtualMemberFunctionPointer(MD), CGM.PtrDiffTy);
1204 MemPtr[0] = llvm::ConstantInt::get(CGM.PtrDiffTy, VTableOffset);
1207 MemPtr[1] = llvm::ConstantInt::get(
1208 CGM.PtrDiffTy, 2 * ThisAdjustment.
getQuantity() + !Schema);
1214 MemPtr[0] = llvm::ConstantInt::get(CGM.PtrDiffTy, VTableOffset + 1);
1215 MemPtr[1] = llvm::ConstantInt::get(CGM.PtrDiffTy,
1219 const FunctionProtoType *FPT = MD->
getType()->
castAs<FunctionProtoType>();
1230 llvm::Constant *addr = CGM.getMemberFunctionPointer(MD, Ty);
1232 MemPtr[0] = llvm::ConstantExpr::getPtrToInt(addr, CGM.PtrDiffTy);
1233 MemPtr[1] = llvm::ConstantInt::get(CGM.PtrDiffTy,
1234 (UseARMMethodPtrABI ? 2 : 1) *
1238 return llvm::ConstantStruct::getAnon(MemPtr);
1241llvm::Constant *ItaniumCXXABI::EmitMemberPointer(
const APValue &MP,
1243 const MemberPointerType *MPT = MPType->
castAs<MemberPointerType>();
1246 return EmitNullMemberPointer(MPT);
1248 CharUnits ThisAdjustment = getContext().getMemberPointerPathAdjustment(MP);
1250 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MPD)) {
1251 llvm::Constant *Src = BuildMemberPointer(MD, ThisAdjustment);
1252 QualType SrcType = getContext().getMemberPointerType(
1257 getContext().recordMemberDataPointerEvaluation(MPD);
1258 CharUnits FieldOffset =
1259 getContext().toCharUnitsFromBits(getContext().
getFieldOffset(MPD));
1260 return EmitMemberDataPointer(MPT, ThisAdjustment + FieldOffset);
1268ItaniumCXXABI::EmitMemberPointerComparison(CodeGenFunction &CGF,
1271 const MemberPointerType *MPT,
1273 CGBuilderTy &Builder = CGF.
Builder;
1275 llvm::ICmpInst::Predicate Eq;
1276 llvm::Instruction::BinaryOps
And,
Or;
1278 Eq = llvm::ICmpInst::ICMP_NE;
1279 And = llvm::Instruction::Or;
1280 Or = llvm::Instruction::And;
1282 Eq = llvm::ICmpInst::ICMP_EQ;
1283 And = llvm::Instruction::And;
1284 Or = llvm::Instruction::Or;
1290 return Builder.CreateICmp(Eq, L, R);
1302 llvm::Value *LPtr = Builder.CreateExtractValue(L, 0,
"lhs.memptr.ptr");
1303 llvm::Value *RPtr = Builder.CreateExtractValue(R, 0,
"rhs.memptr.ptr");
1307 llvm::Value *PtrEq = Builder.CreateICmp(Eq, LPtr, RPtr,
"cmp.ptr");
1312 llvm::Value *
Zero = llvm::Constant::getNullValue(LPtr->getType());
1313 llvm::Value *EqZero = Builder.CreateICmp(Eq, LPtr,
Zero,
"cmp.ptr.null");
1317 llvm::Value *LAdj = Builder.CreateExtractValue(L, 1,
"lhs.memptr.adj");
1318 llvm::Value *RAdj = Builder.CreateExtractValue(R, 1,
"rhs.memptr.adj");
1319 llvm::Value *AdjEq = Builder.CreateICmp(Eq, LAdj, RAdj,
"cmp.adj");
1323 if (UseARMMethodPtrABI) {
1324 llvm::Value *One = llvm::ConstantInt::get(LPtr->getType(), 1);
1327 llvm::Value *OrAdj = Builder.CreateOr(LAdj, RAdj,
"or.adj");
1328 llvm::Value *OrAdjAnd1 = Builder.CreateAnd(OrAdj, One);
1329 llvm::Value *OrAdjAnd1EqZero = Builder.CreateICmp(Eq, OrAdjAnd1,
Zero,
1331 EqZero = Builder.CreateBinOp(
And, EqZero, OrAdjAnd1EqZero);
1335 llvm::Value *
Result = Builder.CreateBinOp(
Or, EqZero, AdjEq);
1337 Inequality ?
"memptr.ne" :
"memptr.eq");
1342ItaniumCXXABI::EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
1343 llvm::Value *MemPtr,
1344 const MemberPointerType *MPT) {
1345 CGBuilderTy &Builder = CGF.
Builder;
1349 assert(MemPtr->getType() == CGM.PtrDiffTy);
1350 llvm::Value *NegativeOne =
1351 llvm::Constant::getAllOnesValue(MemPtr->getType());
1352 return Builder.CreateICmpNE(MemPtr, NegativeOne,
"memptr.tobool");
1356 llvm::Value *
Ptr = Builder.CreateExtractValue(MemPtr, 0,
"memptr.ptr");
1358 llvm::Constant *
Zero = llvm::ConstantInt::get(
Ptr->getType(), 0);
1359 llvm::Value *
Result = Builder.CreateICmpNE(Ptr,
Zero,
"memptr.tobool");
1363 if (UseARMMethodPtrABI) {
1364 llvm::Constant *One = llvm::ConstantInt::get(
Ptr->getType(), 1);
1365 llvm::Value *Adj = Builder.CreateExtractValue(MemPtr, 1,
"memptr.adj");
1366 llvm::Value *VirtualBit = Builder.CreateAnd(Adj, One,
"memptr.virtualbit");
1367 llvm::Value *IsVirtual = Builder.CreateICmpNE(VirtualBit,
Zero,
1368 "memptr.isvirtual");
1375bool ItaniumCXXABI::classifyReturnType(CGFunctionInfo &FI)
const {
1376 const CXXRecordDecl *RD = FI.
getReturnType()->getAsCXXRecordDecl();
1383 auto Align = CGM.getContext().getTypeAlignInChars(FI.
getReturnType());
1384 LangAS SRetAS = CGM.getTargetCodeGenInfo().getSRetAddrSpace(RD);
1385 unsigned AS = CGM.getContext().getTargetAddressSpace(SRetAS);
1395bool ItaniumCXXABI::isZeroInitializable(
const MemberPointerType *MPT) {
1401void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
1402 const CXXDeleteExpr *DE,
1404 QualType ElementType,
1405 const CXXDestructorDecl *Dtor) {
1407 if (UseGlobalDelete) {
1412 auto *ClassDecl = ElementType->castAsCXXRecordDecl();
1416 llvm::Value *OffsetPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
1417 CGF.
IntPtrTy, VTable, -2,
"complete-offset.ptr");
1422 llvm::Value *CompletePtr =
Ptr.emitRawPointer(CGF);
1435 EmitVirtualDestructorCall(CGF, Dtor, DtorType, Ptr, DE,
1438 if (UseGlobalDelete)
1442void ItaniumCXXABI::emitRethrow(CodeGenFunction &CGF,
bool isNoReturn) {
1445 llvm::FunctionType *FTy =
1446 llvm::FunctionType::get(CGM.VoidTy,
false);
1448 llvm::FunctionCallee
Fn = CGM.CreateRuntimeFunction(FTy,
"__cxa_rethrow");
1459 llvm::FunctionType *FTy =
1470 llvm::FunctionType *FTy =
1471 llvm::FunctionType::get(CGM.
VoidTy, Args,
false);
1476void ItaniumCXXABI::emitThrow(CodeGenFunction &CGF,
const CXXThrowExpr *E) {
1479 llvm::Type *SizeTy = CGF.
ConvertType(getContext().getSizeType());
1480 uint64_t TypeSize = getContext().getTypeSizeInChars(ThrowType).getQuantity();
1484 AllocExceptionFn, llvm::ConstantInt::get(SizeTy, TypeSize),
"exception");
1491 llvm::Constant *TypeInfo = CGM.GetAddrOfRTTIDescriptor(ThrowType,
1496 llvm::Constant *
Dtor =
nullptr;
1502 const ASTContext &Ctx = getContext();
1504 FunctionProtoType::ExtProtoInfo());
1506 CXXDestructorDecl *DtorD =
Record->getDestructor();
1508 Dtor = CGM.getFunctionPointer(Dtor, DtorTy);
1510 if (!Dtor)
Dtor = llvm::Constant::getNullValue(CGM.Int8PtrTy);
1512 llvm::Value *args[] = { ExceptionPtr, TypeInfo,
Dtor };
1524 llvm::Type *PtrDiffTy =
1527 llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
1529 llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args,
false);
1533 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1534 FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
1535 FuncAttrs.addMemoryAttr(llvm::MemoryEffects::readOnly());
1536 llvm::AttributeList Attrs = llvm::AttributeList::get(
1537 CGF.
getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);
1544 llvm::FunctionType *FTy = llvm::FunctionType::get(CGF.
VoidTy,
false);
1550 llvm::FunctionType *FTy = llvm::FunctionType::get(CGF.
VoidTy,
false);
1555bool ItaniumCXXABI::shouldTypeidBeNullChecked(QualType SrcRecordTy) {
1559void ItaniumCXXABI::EmitBadTypeidCall(CodeGenFunction &CGF) {
1562 Call->setDoesNotReturn();
1563 CGF.
Builder.CreateUnreachable();
1566llvm::Value *ItaniumCXXABI::EmitTypeid(CodeGenFunction &CGF,
1567 QualType SrcRecordTy,
1569 llvm::Type *StdTypeInfoPtrTy) {
1574 if (CGM.getLangOpts().RelativeCXXABIVTables) {
1577 CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
1578 {Value, llvm::ConstantInt::getSigned(CGM.Int32Ty, -4)});
1582 CGF.
Builder.CreateConstInBoundsGEP1_64(StdTypeInfoPtrTy,
Value, -1ULL);
1588bool ItaniumCXXABI::shouldDynamicCastCallBeNullChecked(
bool SrcIsPtr,
1589 QualType SrcRecordTy) {
1593llvm::Value *ItaniumCXXABI::emitDynamicCastCall(
1594 CodeGenFunction &CGF, Address ThisAddr, QualType SrcRecordTy,
1595 QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
1596 llvm::Type *PtrDiffLTy =
1599 llvm::Value *SrcRTTI =
1601 llvm::Value *DestRTTI =
1607 llvm::Value *OffsetHint = llvm::ConstantInt::getSigned(
1614 if (CGM.getCodeGenOpts().PointerAuth.CXXVTablePointers) {
1620 llvm::Value *Vtable =
1622 CodeGenFunction::VTableAuthMode::MustTrap);
1627 llvm::Value *args[] = {
Value, SrcRTTI, DestRTTI, OffsetHint};
1633 llvm::BasicBlock *BadCastBlock =
1640 EmitBadCastCall(CGF);
1646std::optional<CGCXXABI::ExactDynamicCastInfo>
1647ItaniumCXXABI::getExactDynamicCastInfo(QualType SrcRecordTy, QualType DestTy,
1648 QualType DestRecordTy) {
1649 assert(shouldEmitExactDynamicCast(DestRecordTy));
1651 ASTContext &Context = getContext();
1656 CXXBasePaths Paths(
true,
true,
1662 std::optional<CharUnits> Offset;
1663 for (
const CXXBasePath &Path : Paths) {
1668 CharUnits PathOffset;
1669 for (
const CXXBasePathElement &PathElement : Path) {
1671 const CXXRecordDecl *
Base =
1672 PathElement.Base->getType()->getAsCXXRecordDecl();
1673 if (PathElement.Base->isVirtual()) {
1679 const ASTRecordLayout &L =
1686 Offset = PathOffset;
1687 else if (Offset != PathOffset) {
1689 return ExactDynamicCastInfo{
true,
1694 return std::nullopt;
1695 return ExactDynamicCastInfo{
false, *Offset};
1698llvm::Value *ItaniumCXXABI::emitExactDynamicCast(
1699 CodeGenFunction &CGF, Address ThisAddr, QualType SrcRecordTy,
1700 QualType DestTy, QualType DestRecordTy,
1701 const ExactDynamicCastInfo &ExactCastInfo, llvm::BasicBlock *CastSuccess,
1702 llvm::BasicBlock *CastFail) {
1705 auto AuthenticateVTable = [&](
Address ThisAddr,
const CXXRecordDecl *
Decl) {
1709 CodeGenFunction::VTableAuthMode::MustTrap);
1712 bool PerformPostCastAuthentication =
false;
1713 llvm::Value *VTable =
nullptr;
1714 if (ExactCastInfo.RequiresCastToPrimaryBase) {
1719 llvm::Value *PrimaryBase =
1726 PerformPostCastAuthentication = CGF.
getLangOpts().PointerAuthCalls;
1727 CGPointerAuthInfo StrippingAuthInfo(0, PointerAuthenticationMode::Strip,
1728 false,
false,
nullptr);
1731 if (PerformPostCastAuthentication)
1734 VTable = CGF.
GetVTablePtr(ThisAddr, CGM.GlobalsInt8PtrTy, SrcDecl);
1738 llvm::Constant *ExpectedVTable = getVTableAddressPoint(
1739 BaseSubobject(SrcDecl, ExactCastInfo.Offset), DestDecl);
1740 llvm::Value *
Success = CGF.
Builder.CreateICmpEQ(VTable, ExpectedVTable);
1743 if (!ExactCastInfo.Offset.isZero()) {
1745 llvm::Constant *OffsetConstant =
1746 llvm::ConstantInt::get(CGF.
PtrDiffTy, -Offset);
1749 PerformPostCastAuthentication = CGF.
getLangOpts().PointerAuthCalls;
1752 if (PerformPostCastAuthentication) {
1755 llvm::BasicBlock *NonNullBlock = CGF.
Builder.GetInsertBlock();
1756 llvm::BasicBlock *PostCastAuthSuccess =
1758 llvm::BasicBlock *PostCastAuthComplete =
1761 PostCastAuthComplete);
1765 AuthenticateVTable(AdjustedThisAddr, DestDecl);
1768 llvm::PHINode *PHI = CGF.
Builder.CreatePHI(AdjustedThisPtr->getType(), 2);
1769 PHI->addIncoming(AdjustedThisPtr, PostCastAuthSuccess);
1770 llvm::Value *NullValue =
1771 llvm::Constant::getNullValue(AdjustedThisPtr->getType());
1772 PHI->addIncoming(NullValue, NonNullBlock);
1773 AdjustedThisPtr = PHI;
1776 return AdjustedThisPtr;
1779llvm::Value *ItaniumCXXABI::emitDynamicCastToVoid(CodeGenFunction &CGF,
1781 QualType SrcRecordTy) {
1783 llvm::Value *OffsetToTop;
1784 if (CGM.getLangOpts().RelativeCXXABIVTables) {
1786 llvm::Value *VTable =
1791 CGF.
Builder.CreateConstInBoundsGEP1_32(CGM.Int32Ty, VTable, -2U);
1795 llvm::Type *PtrDiffLTy =
1799 llvm::Value *VTable =
1804 CGF.
Builder.CreateConstInBoundsGEP1_64(PtrDiffLTy, VTable, -2ULL);
1813bool ItaniumCXXABI::EmitBadCastCall(CodeGenFunction &CGF) {
1816 Call->setDoesNotReturn();
1817 CGF.
Builder.CreateUnreachable();
1822ItaniumCXXABI::GetVirtualBaseClassOffset(CodeGenFunction &CGF,
1824 const CXXRecordDecl *ClassDecl,
1825 const CXXRecordDecl *BaseClassDecl) {
1826 llvm::Value *VTablePtr = CGF.
GetVTablePtr(This, CGM.Int8PtrTy, ClassDecl);
1827 CharUnits VBaseOffsetOffset =
1828 CGM.getItaniumVTableContext().getVirtualBaseOffsetOffset(ClassDecl,
1830 llvm::Value *VBaseOffsetPtr =
1831 CGF.
Builder.CreateConstGEP1_64(
1833 "vbase.offset.ptr");
1835 llvm::Value *VBaseOffset;
1836 if (CGM.getLangOpts().RelativeCXXABIVTables) {
1842 CGM.PtrDiffTy, VBaseOffsetPtr, CGF.
getPointerAlign(),
"vbase.offset");
1847void ItaniumCXXABI::EmitCXXConstructors(
const CXXConstructorDecl *D) {
1849 assert(CGM.getTarget().getCXXABI().hasConstructorVariants());
1853 CGM.EmitGlobal(GlobalDecl(D,
Ctor_Base));
1863CGCXXABI::AddedStructorArgCounts
1864ItaniumCXXABI::buildStructorSignature(GlobalDecl GD,
1865 SmallVectorImpl<CanQualType> &ArgTys) {
1866 ASTContext &Context = getContext();
1875 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1877 ArgTys.insert(ArgTys.begin() + 1,
1879 return AddedStructorArgCounts::prefix(1);
1881 return AddedStructorArgCounts{};
1884void ItaniumCXXABI::EmitCXXDestructors(
const CXXDestructorDecl *D) {
1887 CGM.EmitGlobal(GlobalDecl(D,
Dtor_Base));
1900void ItaniumCXXABI::addImplicitStructorParams(CodeGenFunction &CGF,
1902 FunctionArgList &Params) {
1907 if (NeedsVTTParameter(CGF.
CurGD)) {
1908 ASTContext &Context = getContext();
1911 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1916 T, ImplicitParamKind::CXXVTT);
1917 Params.insert(Params.begin() + 1, VTTDecl);
1918 getStructorImplicitParamDecl(CGF) = VTTDecl;
1922void ItaniumCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
1929 setCXXABIThisValue(CGF, loadIncomingCXXThis(CGF));
1932 if (getStructorImplicitParamDecl(CGF)) {
1945 if (HasThisReturn(CGF.
CurGD))
1949CGCXXABI::AddedStructorArgs ItaniumCXXABI::getImplicitConstructorArgs(
1952 if (!NeedsVTTParameter(GlobalDecl(D,
Type)))
1953 return AddedStructorArgs{};
1960 LangAS AS = CGM.GetGlobalVarAddressSpace(
nullptr);
1961 QualType Q = getContext().getAddrSpaceQualType(getContext().VoidPtrTy, AS);
1962 QualType VTTTy = getContext().getPointerType(Q);
1963 return AddedStructorArgs::prefix({{VTT, VTTTy}});
1966llvm::Value *ItaniumCXXABI::getCXXDestructorImplicitParam(
1969 GlobalDecl GD(DD,
Type);
1973void ItaniumCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
1974 const CXXDestructorDecl *DD,
1978 GlobalDecl GD(DD,
Type);
1981 QualType VTTTy = getContext().getPointerType(getContext().VoidPtrTy);
1984 if (getContext().getLangOpts().AppleKext &&
1991 ThisTy, VTT, VTTTy,
nullptr);
1995template <
typename T>
1998 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2011 llvm::GlobalVariable *VTable,
2013 if (VTable->getDLLStorageClass() !=
2014 llvm::GlobalVariable::DefaultStorageClass ||
2020 VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
2022 VTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
2025void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
2026 const CXXRecordDecl *RD) {
2027 llvm::GlobalVariable *VTable = getAddrOfVTable(RD, CharUnits());
2028 if (VTable->hasInitializer())
2031 ItaniumVTableContext &VTContext = CGM.getItaniumVTableContext();
2033 llvm::GlobalVariable::LinkageTypes
Linkage = CGM.getVTableLinkage(RD);
2034 llvm::Constant *RTTI =
2035 CGM.GetAddrOfRTTIDescriptor(CGM.getContext().getCanonicalTagType(RD));
2038 ConstantInitBuilder builder(CGM);
2039 auto components = builder.beginStruct();
2041 llvm::GlobalValue::isLocalLinkage(
Linkage));
2042 components.finishAndSetAsInitializer(VTable);
2050 if (CGM.mayVTableBeDuplicated(VTable->getLinkage()))
2051 VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2053 if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
2054 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
2056 if (CGM.getTarget().hasPS4DLLImportExport())
2060 CGM.setGVProperties(VTable, RD);
2071 EmitFundamentalRTTIDescriptors(RD);
2079 if (!VTable->isDeclarationForLinker() ||
2080 CGM.getCodeGenOpts().WholeProgramVTables ||
2081 CGM.getCodeGenOpts().DevirtualizeSpeculatively) {
2082 CGM.EmitVTableTypeMetadata(RD, VTable, VTLayout);
2086 if (VTable->isDeclarationForLinker()) {
2087 assert(CGM.getCodeGenOpts().WholeProgramVTables ||
2088 CGM.getCodeGenOpts().DevirtualizeSpeculatively);
2089 CGM.addCompilerUsedGlobal(VTable);
2093 if (CGM.getLangOpts().RelativeCXXABIVTables) {
2095 if (!VTable->isDSOLocal())
2100 if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
2101 DI->emitVTableSymbol(VTable, RD);
2104bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField(
2105 CodeGenFunction &CGF, CodeGenFunction::VPtr Vptr) {
2108 return NeedsVTTParameter(CGF.
CurGD);
2111llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructor(
2112 CodeGenFunction &CGF,
const CXXRecordDecl *VTableClass, BaseSubobject Base,
2113 const CXXRecordDecl *NearestVBase) {
2115 if ((
Base.getBase()->getNumVBases() || NearestVBase !=
nullptr) &&
2116 NeedsVTTParameter(CGF.
CurGD)) {
2117 return getVTableAddressPointInStructorWithVTT(CGF, VTableClass, Base,
2120 return getVTableAddressPoint(Base, VTableClass);
2124ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
2125 const CXXRecordDecl *VTableClass) {
2126 llvm::GlobalValue *VTable = getAddrOfVTable(VTableClass, CharUnits());
2130 const VTableLayout &Layout =
2131 CGM.getItaniumVTableContext().getVTableLayout(VTableClass);
2132 VTableLayout::AddressPointLocation AddressPoint =
2134 llvm::Constant *Indices[] = {
2135 llvm::ConstantInt::get(CGM.Int32Ty, 0),
2136 llvm::ConstantInt::get(CGM.Int32Ty, AddressPoint.
VTableIndex),
2142 unsigned ComponentSize =
2143 CGM.getDataLayout().getTypeAllocSize(CGM.getVTableComponentType());
2144 unsigned VTableSize =
2147 llvm::ConstantRange InRange(
2148 llvm::APInt(32, (
int)-Offset,
true),
2149 llvm::APInt(32, (
int)(VTableSize - Offset),
true));
2150 return llvm::ConstantExpr::getGetElementPtr(
2151 CGM.getDataLayout(), VTable->getValueType(), VTable, Indices,
2152 llvm::GEPNoWrapFlags::inBounds(), InRange);
2155llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
2156 CodeGenFunction &CGF,
const CXXRecordDecl *VTableClass, BaseSubobject Base,
2157 const CXXRecordDecl *NearestVBase) {
2158 assert((
Base.getBase()->getNumVBases() || NearestVBase !=
nullptr) &&
2159 NeedsVTTParameter(CGF.
CurGD) &&
"This class doesn't have VTT");
2163 CGM.getVTables().getSecondaryVirtualPointerIndex(VTableClass, Base);
2167 if (VirtualPointerIndex)
2169 VirtualPointerIndex);
2176 if (
auto PointerAuth = CGM.getVTablePointerAuthInfo(&CGF, VTableClass, VTT,
2183llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(
const CXXRecordDecl *RD,
2184 CharUnits VPtrOffset) {
2185 assert(VPtrOffset.
isZero() &&
"Itanium ABI only supports zero vptr offsets");
2187 llvm::GlobalVariable *&VTable = VTables[RD];
2192 CGM.addDeferredVTable(RD);
2194 SmallString<256> Name;
2195 llvm::raw_svector_ostream
Out(Name);
2196 getMangleContext().mangleCXXVTable(RD, Out);
2198 const VTableLayout &VTLayout =
2199 CGM.getItaniumVTableContext().getVTableLayout(RD);
2200 llvm::Type *VTableType = CGM.getVTables().getVTableType(VTLayout);
2205 unsigned PAlign = CGM.getVtableGlobalVarAlignment();
2207 VTable = CGM.CreateOrReplaceCXXRuntimeVariable(
2208 Name, VTableType, llvm::GlobalValue::ExternalLinkage,
2209 getContext().toCharUnitsFromBits(PAlign).getAsAlign());
2210 if (!CGM.shouldEmitRTTI())
2211 VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2213 if (CGM.getTarget().hasPS4DLLImportExport())
2216 CGM.setGVProperties(VTable, RD);
2220CGCallee ItaniumCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
2224 SourceLocation Loc) {
2225 llvm::Type *PtrTy = CGM.GlobalsInt8PtrTy;
2227 llvm::Value *VTable = CGF.
GetVTablePtr(This, PtrTy, MethodDecl->getParent());
2233 if (CGM.getLangOpts().OpenMPIsTargetDevice) {
2234 auto *NewPtrTy = CGM.VoidPtrTy;
2235 llvm::Type *RtlFnArgs[] = {NewPtrTy};
2236 llvm::FunctionCallee DeviceRtlFn = CGM.CreateRuntimeFunction(
2237 llvm::FunctionType::get(NewPtrTy, RtlFnArgs,
false),
2238 "__llvm_omp_indirect_call_lookup");
2239 auto *BackupTy = VTable->getType();
2247 uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
2248 llvm::Value *VFunc, *VTableSlotPtr =
nullptr;
2249 auto &Schema = CGM.getCodeGenOpts().PointerAuth.CXXVirtualFunctionPointers;
2251 llvm::Type *ComponentTy = CGM.getVTables().getVTableComponentType();
2253 VTableIndex * CGM.getDataLayout().getTypeSizeInBits(ComponentTy) / 8;
2257 PtrTy, ByteOffset, Loc);
2261 llvm::Value *VFuncLoad;
2262 if (CGM.getLangOpts().RelativeCXXABIVTables) {
2263 VFuncLoad = CGF.
Builder.CreateCall(
2264 CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
2265 {VTable, llvm::ConstantInt::get(CGM.Int32Ty, ByteOffset)});
2267 VTableSlotPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
2268 PtrTy, VTable, VTableIndex,
"vfn");
2279 if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2280 CGM.getCodeGenOpts().StrictVTablePointers) {
2281 if (
auto *VFuncLoadInstr = dyn_cast<llvm::Instruction>(VFuncLoad)) {
2282 VFuncLoadInstr->setMetadata(
2283 llvm::LLVMContext::MD_invariant_load,
2284 llvm::MDNode::get(CGM.getLLVMContext(),
2285 llvm::ArrayRef<llvm::Metadata *>()));
2291 CGPointerAuthInfo PointerAuth;
2293 assert(VTableSlotPtr &&
"virtual function pointer not set");
2294 GD = CGM.getItaniumVTableContext().findOriginalMethod(GD.
getCanonicalDecl());
2297 CGCallee
Callee(GD, VFunc, PointerAuth);
2301llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
2302 CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
2303 Address This, DeleteOrMemberCallExpr E, llvm::CallBase **CallOrInvoke) {
2304 auto *CE = dyn_cast<const CXXMemberCallExpr *>(E);
2305 auto *D = dyn_cast<const CXXDeleteExpr *>(E);
2306 assert((CE !=
nullptr) ^ (D !=
nullptr));
2307 assert(CE ==
nullptr || CE->arguments().empty());
2310 GlobalDecl GD(Dtor, DtorType);
2311 const CGFunctionInfo *FInfo =
2312 &CGM.getTypes().arrangeCXXStructorDeclaration(GD);
2318 ThisTy = CE->getObjectType();
2320 ThisTy = D->getDestroyedType();
2324 nullptr, QualType(),
nullptr, CallOrInvoke);
2328void ItaniumCXXABI::emitVirtualInheritanceTables(
const CXXRecordDecl *RD) {
2329 CodeGenVTables &VTables = CGM.getVTables();
2334bool ItaniumCXXABI::canSpeculativelyEmitVTableAsBaseClass(
2335 const CXXRecordDecl *RD)
const {
2338 if (CGM.getLangOpts().AppleKext)
2343 if (isVTableHidden(RD))
2346 if (CGM.getCodeGenOpts().ForceEmitVTables)
2363 if (hasAnyUnusedVirtualInlineFunction(RD))
2371 for (
const auto &B : RD->
bases()) {
2372 auto *BRD = B.getType()->getAsCXXRecordDecl();
2373 assert(BRD &&
"no class for base specifier");
2374 if (B.isVirtual() || !BRD->isDynamicClass())
2376 if (!canSpeculativelyEmitVTableAsBaseClass(BRD))
2384bool ItaniumCXXABI::canSpeculativelyEmitVTable(
const CXXRecordDecl *RD)
const {
2385 if (!canSpeculativelyEmitVTableAsBaseClass(RD))
2393 for (
const auto &B : RD->
vbases()) {
2394 auto *BRD = B.getType()->getAsCXXRecordDecl();
2395 assert(BRD &&
"no class for base specifier");
2396 if (!BRD->isDynamicClass())
2398 if (!canSpeculativelyEmitVTableAsBaseClass(BRD))
2409 bool IsReturnAdjustment) {
2410 if (!NonVirtualAdjustment && !VirtualAdjustment)
2416 if (NonVirtualAdjustment && !IsReturnAdjustment) {
2422 llvm::Value *ResultPtr;
2423 if (VirtualAdjustment) {
2424 llvm::Value *VTablePtr =
2427 llvm::Value *Offset;
2428 llvm::Value *OffsetPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(
2429 CGF.
Int8Ty, VTablePtr, VirtualAdjustment);
2436 llvm::Type *PtrDiffTy =
2445 V.emitRawPointer(CGF), Offset);
2447 ResultPtr =
V.emitRawPointer(CGF);
2452 if (NonVirtualAdjustment && IsReturnAdjustment) {
2453 ResultPtr = CGF.
Builder.CreateConstInBoundsGEP1_64(CGF.
Int8Ty, ResultPtr,
2454 NonVirtualAdjustment);
2461ItaniumCXXABI::performThisAdjustment(CodeGenFunction &CGF, Address This,
2462 const CXXRecordDecl *UnadjustedClass,
2463 const ThunkInfo &TI) {
2470ItaniumCXXABI::performReturnAdjustment(CodeGenFunction &CGF, Address Ret,
2471 const CXXRecordDecl *UnadjustedClass,
2472 const ReturnAdjustment &RA) {
2478void ARMCXXABI::EmitReturnFromThunk(CodeGenFunction &CGF,
2479 RValue RV, QualType ResultType) {
2481 return ItaniumCXXABI::EmitReturnFromThunk(CGF, RV, ResultType);
2486 return ItaniumCXXABI::EmitReturnFromThunk(CGF, Undef, ResultType);
2491CharUnits ItaniumCXXABI::getArrayCookieSizeImpl(QualType elementType) {
2495 CGM.getContext().getPreferredTypeAlignInChars(elementType));
2498Address ItaniumCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
2500 llvm::Value *NumElements,
2501 const CXXNewExpr *
expr,
2502 QualType ElementType) {
2503 assert(requiresArrayCookie(
expr));
2507 ASTContext &Ctx = getContext();
2511 CharUnits CookieSize =
2513 assert(CookieSize == getArrayCookieSizeImpl(ElementType));
2517 CharUnits CookieOffset = CookieSize - SizeSize;
2518 if (!CookieOffset.
isZero())
2526 if (CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) && AS == 0 &&
2527 (
expr->getOperatorNew()->isReplaceableGlobalAllocationFunction() ||
2528 CGM.getCodeGenOpts().SanitizeAddressPoisonCustomArrayCookie)) {
2530 SI->setNoSanitizeMetadata();
2531 llvm::FunctionType *FTy =
2532 llvm::FunctionType::get(CGM.VoidTy, NumElementsPtr.
getType(),
false);
2533 llvm::FunctionCallee F =
2534 CGM.CreateRuntimeFunction(FTy,
"__asan_poison_cxx_array_cookie");
2543llvm::Value *ItaniumCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
2545 CharUnits cookieSize) {
2547 Address numElementsPtr = allocPtr;
2548 CharUnits numElementsOffset = cookieSize - CGF.
getSizeSize();
2549 if (!numElementsOffset.
isZero())
2555 if (!CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) || AS != 0)
2562 llvm::FunctionType *FTy =
2564 llvm::FunctionCallee F =
2565 CGM.CreateRuntimeFunction(FTy,
"__asan_load_cxx_array_cookie");
2569CharUnits ARMCXXABI::getArrayCookieSizeImpl(QualType elementType) {
2579 CGM.getContext().getTypeAlignInChars(elementType));
2582Address ARMCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
2584 llvm::Value *numElements,
2585 const CXXNewExpr *
expr,
2586 QualType elementType) {
2587 assert(requiresArrayCookie(
expr));
2594 llvm::Value *elementSize = llvm::ConstantInt::get(CGF.
SizeTy,
2595 getContext().getTypeSizeInChars(elementType).getQuantity());
2604 CharUnits cookieSize = ARMCXXABI::getArrayCookieSizeImpl(elementType);
2608llvm::Value *ARMCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
2610 CharUnits cookieSize) {
2623 llvm::PointerType *GuardPtrTy) {
2625 llvm::FunctionType *FTy =
2629 FTy,
"__cxa_guard_acquire",
2631 llvm::AttributeList::FunctionIndex,
2632 llvm::Attribute::NoUnwind));
2636 llvm::PointerType *GuardPtrTy) {
2638 llvm::FunctionType *FTy =
2639 llvm::FunctionType::get(CGM.
VoidTy, GuardPtrTy,
false);
2641 FTy,
"__cxa_guard_release",
2643 llvm::AttributeList::FunctionIndex,
2644 llvm::Attribute::NoUnwind));
2648 llvm::PointerType *GuardPtrTy) {
2650 llvm::FunctionType *FTy =
2651 llvm::FunctionType::get(CGM.
VoidTy, GuardPtrTy,
false);
2653 FTy,
"__cxa_guard_abort",
2655 llvm::AttributeList::FunctionIndex,
2656 llvm::Attribute::NoUnwind));
2660 struct CallGuardAbort final : EHScopeStack::Cleanup {
2661 llvm::GlobalVariable *Guard;
2662 CallGuardAbort(llvm::GlobalVariable *Guard) : Guard(Guard) {}
2664 void Emit(CodeGenFunction &CGF, Flags flags)
override {
2673void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
2675 llvm::GlobalVariable *var,
2676 bool shouldPerformInit) {
2677 CGBuilderTy &Builder = CGF.
Builder;
2681 bool NonTemplateInline =
2688 bool threadsafe = getContext().getLangOpts().ThreadsafeStatics &&
2694 bool useInt8GuardVariable = !threadsafe &&
var->hasInternalLinkage();
2696 llvm::IntegerType *guardTy;
2697 CharUnits guardAlignment;
2698 if (useInt8GuardVariable) {
2704 if (UseARMGuardVarABI) {
2713 llvm::PointerType *guardPtrTy = llvm::PointerType::get(
2719 llvm::GlobalVariable *guard = CGM.getStaticLocalDeclGuardAddress(&D);
2722 SmallString<256> guardName;
2724 llvm::raw_svector_ostream
out(guardName);
2725 getMangleContext().mangleStaticGuardVariable(&D,
out);
2731 guard =
new llvm::GlobalVariable(CGM.getModule(), guardTy,
2732 false,
var->getLinkage(),
2733 llvm::ConstantInt::get(guardTy, 0),
2735 guard->setDSOLocal(
var->isDSOLocal());
2736 guard->setVisibility(
var->getVisibility());
2737 guard->setDLLStorageClass(
var->getDLLStorageClass());
2739 guard->setThreadLocalMode(
var->getThreadLocalMode());
2740 guard->setAlignment(guardAlignment.
getAsAlign());
2745 llvm::Comdat *
C =
var->getComdat();
2747 (CGM.getTarget().getTriple().isOSBinFormatELF() ||
2748 CGM.getTarget().getTriple().isOSBinFormatWasm())) {
2749 guard->setComdat(
C);
2750 }
else if (CGM.supportsCOMDAT() && guard->isWeakForLinker()) {
2751 guard->setComdat(CGM.getModule().getOrInsertComdat(guard->getName()));
2754 CGM.setStaticLocalDeclGuardAddress(&D, guard);
2757 Address guardAddr =
Address(guard, guard->getValueType(), guardAlignment);
2782 if (!threadsafe || MaxInlineWidthInBits) {
2784 llvm::LoadInst *LI =
2794 LI->setAtomic(llvm::AtomicOrdering::Acquire);
2817 (UseARMGuardVarABI && !useInt8GuardVariable)
2818 ? Builder.CreateAnd(LI, llvm::ConstantInt::get(CGM.Int8Ty, 1))
2820 llvm::Value *NeedsInit = Builder.CreateIsNull(
V,
"guard.uninitialized");
2826 CodeGenFunction::GuardKind::VariableGuard, &D);
2854 Builder.CreateCondBr(Builder.CreateIsNotNull(
V,
"tobool"),
2855 InitBlock, EndBlock);
2865 Builder.CreateStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),
2883 Builder.CreateStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),
2892 llvm::FunctionCallee dtor,
2893 llvm::Constant *addr,
bool TLS) {
2895 "unexpected call to emitGlobalDtorWithCXAAtExit");
2897 "__cxa_atexit is disabled");
2898 const char *Name =
"__cxa_atexit";
2901 Name =
T.isOSDarwin() ?
"_tlv_atexit" :
"__cxa_thread_atexit";
2909 auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
2910 auto AddrPtrTy = AddrAS ? llvm::PointerType::get(CGF.
getLLVMContext(), AddrAS)
2914 llvm::Constant *handle =
2917 GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
2920 llvm::Type *paramTys[] = {
dtorTy, AddrPtrTy, handle->getType()};
2921 llvm::FunctionType *atexitTy =
2922 llvm::FunctionType::get(CGF.
IntTy, paramTys,
false);
2926 if (llvm::Function *fn = dyn_cast<llvm::Function>(atexit.getCallee()))
2927 fn->setDoesNotThrow();
2933 Context.getFunctionType(Context.VoidTy, {Context.VoidPtrTy}, EPI);
2934 llvm::Value *dtorCallee = dtor.getCallee();
2938 if (dtorCallee->getType()->getPointerAddressSpace() != AddrAS)
2946 addr = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
2948 llvm::Value *args[] = {dtorCallee, addr, handle};
2956 llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.
VoidTy,
false);
2960 return GlobalInitOrCleanupFn;
2963void CodeGenModule::unregisterGlobalDtorsWithUnAtExit() {
2964 for (
const auto &I : DtorsUsingAtExit) {
2965 int Priority = I.first;
2966 std::string GlobalCleanupFnName =
2967 std::string(
"__GLOBAL_cleanup_") + llvm::to_string(Priority);
2969 llvm::Function *GlobalCleanupFn =
2972 CodeGenFunction CGF(*
this);
2973 CGF.
StartFunction(GlobalDecl(), getContext().VoidTy, GlobalCleanupFn,
2974 getTypes().arrangeNullaryFunction(), FunctionArgList(),
2975 SourceLocation(), SourceLocation());
2979 llvm::FunctionType *dtorFuncTy = llvm::FunctionType::get(CGF.
VoidTy,
false);
2983 const llvm::TinyPtrVector<llvm::Function *> &Dtors = I.second;
2984 auto itv = Dtors.rbegin();
2985 while (itv != Dtors.rend()) {
2986 llvm::Function *
Dtor = *itv;
2991 llvm::Value *NeedsDestruct =
2994 llvm::BasicBlock *DestructCallBlock =
2997 (itv + 1) != Dtors.rend() ?
"unatexit.call" :
"destruct.end");
3000 CGF.
Builder.CreateCondBr(NeedsDestruct, DestructCallBlock, EndBlock);
3005 llvm::CallInst *CI = CGF.
Builder.CreateCall(dtorFuncTy, Dtor);
3007 CI->setCallingConv(
Dtor->getCallingConv());
3015 AddGlobalDtor(GlobalCleanupFn, Priority);
3019void CodeGenModule::registerGlobalDtorsWithAtExit() {
3020 for (
const auto &I : DtorsUsingAtExit) {
3021 int Priority = I.first;
3022 std::string GlobalInitFnName =
3023 std::string(
"__GLOBAL_init_") + llvm::to_string(Priority);
3024 llvm::Function *GlobalInitFn =
3027 CodeGenFunction CGF(*
this);
3028 CGF.
StartFunction(GlobalDecl(), getContext().VoidTy, GlobalInitFn,
3029 getTypes().arrangeNullaryFunction(), FunctionArgList(),
3030 SourceLocation(), SourceLocation());
3038 const llvm::TinyPtrVector<llvm::Function *> &Dtors = I.second;
3039 for (
auto *Dtor : Dtors) {
3042 if (getCodeGenOpts().CXAAtExit) {
3052 AddGlobalCtor(GlobalInitFn, Priority);
3055 if (getCXXABI().useSinitAndSterm())
3056 unregisterGlobalDtorsWithUnAtExit();
3060void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction &CGF,
const VarDecl &D,
3061 llvm::FunctionCallee dtor,
3062 llvm::Constant *addr) {
3067 if (CGM.getLangOpts().HLSL)
3068 return CGM.AddCXXDtorEntry(dtor, addr);
3082 if (CGM.getCodeGenOpts().CXAAtExit || D.
getTLSKind())
3087 if (CGM.getLangOpts().AppleKext) {
3089 return CGM.AddCXXDtorEntry(dtor, addr);
3097 assert(!VD->
isStaticLocal() &&
"static local VarDecls don't need wrappers!");
3107static llvm::GlobalValue::LinkageTypes
3109 llvm::GlobalValue::LinkageTypes VarLinkage =
3113 if (llvm::GlobalValue::isLocalLinkage(VarLinkage))
3118 if (!llvm::GlobalVariable::isLinkOnceLinkage(VarLinkage) &&
3119 !llvm::GlobalVariable::isWeakODRLinkage(VarLinkage))
3121 return llvm::GlobalValue::WeakODRLinkage;
3125ItaniumCXXABI::getOrCreateThreadLocalWrapper(
const VarDecl *VD,
3128 SmallString<256> WrapperName;
3130 llvm::raw_svector_ostream
Out(WrapperName);
3131 getMangleContext().mangleItaniumThreadLocalWrapper(VD, Out);
3136 if (llvm::Value *
V = CGM.getModule().getNamedValue(WrapperName))
3139 QualType RetQT = VD->
getType();
3143 const CGFunctionInfo &FI = CGM.getTypes().arrangeBuiltinFunctionDeclaration(
3144 getContext().getPointerType(RetQT), FunctionArgList());
3146 llvm::FunctionType *FnTy = CGM.getTypes().GetFunctionType(FI);
3147 llvm::Function *Wrapper =
3149 WrapperName.str(), &CGM.getModule());
3151 if (CGM.supportsCOMDAT() && Wrapper->isWeakForLinker())
3152 Wrapper->setComdat(CGM.getModule().getOrInsertComdat(Wrapper->getName()));
3154 CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Wrapper,
false);
3157 if (!Wrapper->hasLocalLinkage())
3159 llvm::GlobalVariable::isLinkOnceLinkage(Wrapper->getLinkage()) ||
3160 llvm::GlobalVariable::isWeakODRLinkage(Wrapper->getLinkage()) ||
3162 Wrapper->setVisibility(llvm::GlobalValue::HiddenVisibility);
3165 Wrapper->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
3166 Wrapper->addFnAttr(llvm::Attribute::NoUnwind);
3169 ThreadWrappers.push_back({VD, Wrapper});
3173void ItaniumCXXABI::EmitThreadLocalInitFuncs(
3174 CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals,
3175 ArrayRef<llvm::Function *> CXXThreadLocalInits,
3176 ArrayRef<const VarDecl *> CXXThreadLocalInitVars) {
3177 llvm::Function *InitFunc =
nullptr;
3181 llvm::SmallVector<llvm::Function *, 8> OrderedInits;
3182 llvm::SmallDenseMap<const VarDecl *, llvm::Function *> UnorderedInits;
3183 for (
unsigned I = 0; I != CXXThreadLocalInits.size(); ++I) {
3186 UnorderedInits[CXXThreadLocalInitVars[I]->getCanonicalDecl()] =
3187 CXXThreadLocalInits[I];
3189 OrderedInits.push_back(CXXThreadLocalInits[I]);
3192 if (!OrderedInits.empty()) {
3194 llvm::FunctionType *FTy =
3195 llvm::FunctionType::get(CGM.
VoidTy,
false);
3200 llvm::GlobalVariable *Guard =
new llvm::GlobalVariable(
3202 llvm::GlobalVariable::InternalLinkage,
3203 llvm::ConstantInt::get(CGM.
Int8Ty, 0),
"__tls_guard");
3204 Guard->setThreadLocal(
true);
3208 Guard->setAlignment(GuardAlign.
getAsAlign());
3210 CodeGenFunction(CGM).GenerateCXXGlobalInitFunc(
3211 InitFunc, OrderedInits, ConstantAddress(Guard, CGM.
Int8Ty, GuardAlign));
3214 InitFunc->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
3215 InitFunc->addFnAttr(llvm::Attribute::NoUnwind);
3221 for (
const VarDecl *VD : CXXThreadLocals) {
3225 getOrCreateThreadLocalWrapper(VD, GV);
3230 for (
auto VDAndWrapper : ThreadWrappers) {
3231 const VarDecl *VD = VDAndWrapper.first;
3232 llvm::GlobalVariable *Var =
3234 llvm::Function *Wrapper = VDAndWrapper.second;
3241 Wrapper->setLinkage(llvm::Function::ExternalLinkage);
3247 if (Wrapper->getLinkage() == llvm::Function::WeakODRLinkage)
3248 Wrapper->setLinkage(llvm::Function::LinkOnceODRLinkage);
3254 SmallString<256> InitFnName;
3256 llvm::raw_svector_ostream
Out(InitFnName);
3257 getMangleContext().mangleItaniumThreadLocalInit(VD, Out);
3260 llvm::FunctionType *InitFnTy = llvm::FunctionType::get(CGM.
VoidTy,
false);
3265 llvm::GlobalValue *
Init =
nullptr;
3266 bool InitIsInitFunc =
false;
3267 bool HasConstantInitialization =
false;
3268 if (!usesThreadWrapperFunction(VD)) {
3269 HasConstantInitialization =
true;
3271 InitIsInitFunc =
true;
3272 llvm::Function *InitFuncToUse = InitFunc;
3276 Init = llvm::GlobalAlias::create(Var->getLinkage(), InitFnName.str(),
3283 Init = llvm::Function::Create(InitFnTy,
3284 llvm::GlobalVariable::ExternalWeakLinkage,
3292 Init->setVisibility(Var->getVisibility());
3294 if (!CGM.
getTriple().isOSWindows() || !
Init->hasExternalWeakLinkage())
3295 Init->setDSOLocal(Var->isDSOLocal());
3298 llvm::LLVMContext &Context = CGM.
getModule().getContext();
3306 isEmittedWithConstantInitializer(VD,
true) &&
3307 !mayNeedDestruction(VD)) {
3312 assert(
Init ==
nullptr &&
"Expected Init to be null.");
3314 llvm::Function *
Func = llvm::Function::Create(
3315 InitFnTy, Var->getLinkage(), InitFnName.str(), &CGM.
getModule());
3321 llvm::BasicBlock *Entry = llvm::BasicBlock::Create(Context,
"",
Func);
3322 CGBuilderTy Builder(CGM, Entry);
3323 Builder.CreateRetVoid();
3326 llvm::BasicBlock *Entry = llvm::BasicBlock::Create(Context,
"", Wrapper);
3327 CGBuilderTy Builder(CGM, Entry);
3328 if (HasConstantInitialization) {
3330 }
else if (InitIsInitFunc) {
3332 llvm::CallInst *CallVal = Builder.CreateCall(InitFnTy,
Init);
3334 CallVal->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
3335 llvm::Function *
Fn =
3337 Fn->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
3348 Builder.CreateCall(InitFnTy,
Init);
3351 llvm::Value *Have = Builder.CreateIsNotNull(
Init);
3352 llvm::BasicBlock *InitBB = llvm::BasicBlock::Create(Context,
"", Wrapper);
3353 llvm::BasicBlock *ExitBB = llvm::BasicBlock::Create(Context,
"", Wrapper);
3354 Builder.CreateCondBr(Have, InitBB, ExitBB);
3356 Builder.SetInsertPoint(InitBB);
3357 Builder.CreateCall(InitFnTy,
Init);
3358 Builder.CreateBr(ExitBB);
3360 Builder.SetInsertPoint(ExitBB);
3365 llvm::Value *Val = Builder.CreateThreadLocalAddress(Var);
3369 Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
3371 Val = Builder.CreateAddrSpaceCast(Val, Wrapper->getReturnType());
3373 Builder.CreateRet(Val);
3377LValue ItaniumCXXABI::EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
3379 QualType LValType) {
3381 llvm::Function *Wrapper = getOrCreateThreadLocalWrapper(VD, Val);
3383 llvm::CallInst *CallVal =
3385 CallVal->setCallingConv(Wrapper->getCallingConv());
3399bool ItaniumCXXABI::NeedsVTTParameter(GlobalDecl GD) {
3418ItaniumCXXABI::getOrCreateVirtualFunctionPointerThunk(
const CXXMethodDecl *MD) {
3419 SmallString<256> MethodName;
3420 llvm::raw_svector_ostream
Out(MethodName);
3421 getMangleContext().mangleCXXName(MD, Out);
3422 MethodName +=
"_vfpthunk_";
3423 StringRef ThunkName = MethodName.str();
3424 llvm::Function *ThunkFn;
3425 if ((ThunkFn = cast_or_null<llvm::Function>(
3426 CGM.
getModule().getNamedValue(ThunkName))))
3431 llvm::GlobalValue::LinkageTypes
Linkage =
3433 : llvm::GlobalValue::InternalLinkage;
3436 if (
Linkage == llvm::GlobalValue::LinkOnceODRLinkage)
3437 ThunkFn->setVisibility(llvm::GlobalValue::HiddenVisibility);
3438 assert(ThunkFn->getName() == ThunkName &&
"name was uniqued!");
3444 ThunkFn->removeFnAttr(llvm::Attribute::StackProtect);
3445 ThunkFn->removeFnAttr(llvm::Attribute::StackProtectStrong);
3446 ThunkFn->removeFnAttr(llvm::Attribute::StackProtectReq);
3449 CodeGenFunction CGF(CGM);
3450 CGF.
CurGD = GlobalDecl(MD);
3454 FunctionArgList FunctionArgs;
3458 FunctionArgs, MD->
getLocation(), SourceLocation());
3463 llvm::Value *ThisVal = loadIncomingCXXThis(CGF);
3464 setCXXABIThisValue(CGF, ThisVal);
3466 CallArgList CallArgs;
3467 for (
const VarDecl *VD : FunctionArgs)
3470 const FunctionProtoType *FPT = MD->
getType()->
getAs<FunctionProtoType>();
3472 const CGFunctionInfo &CallInfo =
3475 getThisAddress(CGF), ThunkTy);
3476 llvm::CallBase *CallOrInvoke;
3477 CGF.
EmitCall(CallInfo, Callee, ReturnValueSlot(), CallArgs, &CallOrInvoke,
3478 true, SourceLocation(),
true);
3480 Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
3481 if (
Call->getType()->isVoidTy())
3494class ItaniumRTTIBuilder {
3496 llvm::LLVMContext &VMContext;
3497 const ItaniumCXXABI &
CXXABI;
3500 SmallVector<llvm::Constant *, 16> Fields;
3503 llvm::GlobalVariable *
3504 GetAddrOfTypeName(QualType Ty, llvm::GlobalVariable::LinkageTypes
Linkage);
3508 llvm::Constant *GetAddrOfExternalRTTIDescriptor(QualType Ty);
3511 void BuildVTablePointer(
const Type *Ty, llvm::Constant *StorageAddress);
3515 void BuildSIClassTypeInfo(
const CXXRecordDecl *RD);
3520 void BuildVMIClassTypeInfo(
const CXXRecordDecl *RD);
3524 void BuildPointerTypeInfo(QualType PointeeTy);
3528 void BuildObjCObjectTypeInfo(
const ObjCObjectType *Ty);
3532 void BuildPointerToMemberTypeInfo(
const MemberPointerType *Ty);
3535 ItaniumRTTIBuilder(
const ItaniumCXXABI &ABI)
3536 : CGM(ABI.CGM), VMContext(CGM.getModule().getContext()),
CXXABI(ABI) {}
3540 llvm::Constant *BuildTypeInfo(QualType Ty);
3544 llvm::Constant *BuildTypeInfo(
3545 QualType Ty, llvm::GlobalVariable::LinkageTypes
Linkage,
3546 llvm::GlobalValue::VisibilityTypes
Visibility,
3547 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass,
3548 llvm::GlobalValue::VisibilityTypes TypeInfoVisibility,
3549 llvm::GlobalValue::DLLStorageClassTypes TypeInfoDLLStorageClass);
3553llvm::GlobalVariable *ItaniumRTTIBuilder::GetAddrOfTypeName(
3554 QualType Ty, llvm::GlobalVariable::LinkageTypes
Linkage) {
3555 SmallString<256> Name;
3556 llvm::raw_svector_ostream
Out(Name);
3562 llvm::Constant *
Init;
3565 SmallString<256> DualEncodedName;
3566 llvm::ConverterEBCDIC::convertToEBCDIC(Name.substr(4), DualEncodedName);
3567 DualEncodedName +=
'\0';
3568 DualEncodedName += Name.substr(4);
3569 Init = llvm::ConstantDataArray::getString(VMContext, DualEncodedName);
3571 Init = llvm::ConstantDataArray::getString(VMContext, Name.substr(4));
3578 GV->setInitializer(
Init);
3584ItaniumRTTIBuilder::GetAddrOfExternalRTTIDescriptor(QualType Ty) {
3586 SmallString<256> Name;
3587 llvm::raw_svector_ostream
Out(Name);
3591 llvm::GlobalVariable *GV = CGM.
getModule().getNamedGlobal(Name);
3598 GV =
new llvm::GlobalVariable(
3600 true, llvm::GlobalValue::ExternalLinkage,
nullptr, Name);
3607 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
3626 if (!Context.getLangOpts().RTTI)
return false;
3628 if (
const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
3641 bool IsDLLImport = RD->
hasAttr<DLLImportAttr>();
3651 return IsDLLImport && !CGM.
getTriple().isWindowsItaniumEnvironment()
3662void ItaniumRTTIBuilder::BuildVTablePointer(
const Type *Ty,
3663 llvm::Constant *StorageAddress) {
3665 static const char *
const ClassTypeInfo =
3666 "_ZTVN10__cxxabiv117__class_type_infoE";
3668 static const char *
const SIClassTypeInfo =
3669 "_ZTVN10__cxxabiv120__si_class_type_infoE";
3671 static const char *
const VMIClassTypeInfo =
3672 "_ZTVN10__cxxabiv121__vmi_class_type_infoE";
3674 const char *VTableName =
nullptr;
3677#define TYPE(Class, Base)
3678#define ABSTRACT_TYPE(Class, Base)
3679#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3680#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3681#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3682#include "clang/AST/TypeNodes.inc"
3683 llvm_unreachable(
"Non-canonical and dependent types shouldn't get here");
3685 case Type::LValueReference:
3686 case Type::RValueReference:
3687 llvm_unreachable(
"References shouldn't get here");
3690 case Type::DeducedTemplateSpecialization:
3691 llvm_unreachable(
"Undeduced type shouldn't get here");
3694 llvm_unreachable(
"Pipe types shouldn't get here");
3696 case Type::ArrayParameter:
3697 llvm_unreachable(
"Array Parameter types should not get here.");
3701 case Type::OverflowBehavior:
3704 case Type::ExtVector:
3705 case Type::ConstantMatrix:
3709 case Type::BlockPointer:
3711 VTableName =
"_ZTVN10__cxxabiv123__fundamental_type_infoE";
3714 case Type::ConstantArray:
3715 case Type::IncompleteArray:
3716 case Type::VariableArray:
3718 VTableName =
"_ZTVN10__cxxabiv117__array_type_infoE";
3721 case Type::FunctionNoProto:
3722 case Type::FunctionProto:
3724 VTableName =
"_ZTVN10__cxxabiv120__function_type_infoE";
3729 VTableName =
"_ZTVN10__cxxabiv116__enum_type_infoE";
3732 case Type::Record: {
3734 ->getDefinitionOrSelf();
3737 VTableName = ClassTypeInfo;
3739 VTableName = SIClassTypeInfo;
3741 VTableName = VMIClassTypeInfo;
3747 case Type::ObjCObject:
3753 VTableName = ClassTypeInfo;
3760 case Type::ObjCInterface:
3762 VTableName = SIClassTypeInfo;
3764 VTableName = ClassTypeInfo;
3768 case Type::ObjCObjectPointer:
3771 VTableName =
"_ZTVN10__cxxabiv119__pointer_type_infoE";
3774 case Type::MemberPointer:
3776 VTableName =
"_ZTVN10__cxxabiv129__pointer_to_member_type_infoE";
3779 case Type::HLSLAttributedResource:
3780 case Type::HLSLInlineSpirv:
3781 llvm_unreachable(
"HLSL doesn't support virtual functions");
3784 llvm::Constant *VTable =
nullptr;
3788 VTable = CGM.
getModule().getNamedAlias(VTableName);
3791 VTable = CGM.
getModule().getOrInsertGlobal(VTableName, Ty);
3796 llvm::Type *PtrDiffTy =
3803 llvm::Constant *Eight = llvm::ConstantInt::get(CGM.
Int32Ty, 8);
3804 VTable = llvm::ConstantExpr::getInBoundsPtrAdd(VTable, Eight);
3806 llvm::Constant *Two = llvm::ConstantInt::get(PtrDiffTy, 2);
3807 VTable = llvm::ConstantExpr::getGetElementPtr(
3809 llvm::GEPNoWrapFlags::inBounds());
3812 if (
const auto &Schema =
3816 Schema.isAddressDiscriminated() ? StorageAddress :
nullptr,
3817 GlobalDecl(), QualType(Ty, 0));
3819 Fields.push_back(VTable);
3836 return llvm::GlobalValue::InternalLinkage;
3840 llvm_unreachable(
"Linkage hasn't been computed!");
3845 return llvm::GlobalValue::InternalLinkage;
3853 return llvm::GlobalValue::LinkOnceODRLinkage;
3855 if (
const RecordType *
Record = dyn_cast<RecordType>(Ty)) {
3859 return llvm::GlobalValue::WeakODRLinkage;
3860 if (CGM.
getTriple().isWindowsItaniumEnvironment())
3861 if (RD->
hasAttr<DLLImportAttr>() &&
3863 return llvm::GlobalValue::ExternalLinkage;
3870 return llvm::GlobalValue::LinkOnceODRLinkage;
3873 llvm_unreachable(
"Invalid linkage!");
3878static llvm::GlobalValue::VisibilityTypes
3880 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass) {
3881 if (DLLStorageClass == llvm::GlobalValue::DLLExportStorageClass &&
3882 Visibility == llvm::GlobalValue::HiddenVisibility)
3883 return llvm::GlobalValue::DefaultVisibility;
3887llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty) {
3892 SmallString<256> Name;
3893 llvm::raw_svector_ostream
Out(Name);
3896 llvm::GlobalVariable *OldGV = CGM.
getModule().getNamedGlobal(Name);
3897 if (OldGV && !OldGV->isDeclaration()) {
3898 assert(!OldGV->hasAvailableExternallyLinkage() &&
3899 "available_externally typeinfos not yet implemented");
3907 return GetAddrOfExternalRTTIDescriptor(Ty);
3914 llvm::GlobalValue::VisibilityTypes llvmVisibility;
3915 if (llvm::GlobalValue::isLocalLinkage(
Linkage))
3917 llvmVisibility = llvm::GlobalValue::DefaultVisibility;
3919 ItaniumCXXABI::RUK_NonUniqueHidden)
3920 llvmVisibility = llvm::GlobalValue::HiddenVisibility;
3924 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass =
3925 llvm::GlobalValue::DefaultStorageClass;
3927 if ((CGM.
getTriple().isWindowsItaniumEnvironment() &&
3928 RD->
hasAttr<DLLExportAttr>()) ||
3930 !llvm::GlobalValue::isLocalLinkage(
Linkage) &&
3931 llvmVisibility == llvm::GlobalValue::DefaultVisibility))
3932 DLLStorageClass = llvm::GlobalValue::DLLExportStorageClass;
3937 llvm::GlobalValue::DLLStorageClassTypes TypeInfoDLLStorageClass =
3940 TypeInfoDLLStorageClass != llvm::GlobalValue::DLLExportStorageClass) {
3942 if (RD->
hasAttr<DLLExportAttr>() ||
3944 TypeInfoDLLStorageClass = llvm::GlobalValue::DLLExportStorageClass;
3947 llvm::GlobalValue::VisibilityTypes TypeInfoVisibility =
3950 return BuildTypeInfo(Ty,
Linkage, llvmVisibility, DLLStorageClass,
3951 TypeInfoVisibility, TypeInfoDLLStorageClass);
3954llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
3955 QualType Ty, llvm::GlobalVariable::LinkageTypes
Linkage,
3956 llvm::GlobalValue::VisibilityTypes
Visibility,
3957 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass,
3958 llvm::GlobalValue::VisibilityTypes TypeInfoVisibility,
3959 llvm::GlobalValue::DLLStorageClassTypes TypeInfoDLLStorageClass) {
3960 SmallString<256> Name;
3961 llvm::raw_svector_ostream
Out(Name);
3964 llvm::GlobalVariable *OldGV = M.getNamedGlobal(Name);
3966 llvm::GlobalVariable *GV =
3975 llvm::Constant *TypeNameField;
3979 ItaniumCXXABI::RTTIUniquenessKind RTTIUniqueness =
3981 if (RTTIUniqueness != ItaniumCXXABI::RUK_Unique) {
3984 TypeNameField = llvm::ConstantExpr::getPtrToInt(TypeName, CGM.
Int64Ty);
3985 llvm::Constant *flag =
3987 TypeNameField = llvm::ConstantExpr::getAdd(TypeNameField, flag);
3993 Fields.push_back(TypeNameField);
3996#define TYPE(Class, Base)
3997#define ABSTRACT_TYPE(Class, Base)
3998#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3999#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
4000#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4001#include "clang/AST/TypeNodes.inc"
4002 llvm_unreachable(
"Non-canonical and dependent types shouldn't get here");
4007 case Type::ExtVector:
4008 case Type::ConstantMatrix:
4010 case Type::BlockPointer:
4015 case Type::LValueReference:
4016 case Type::RValueReference:
4017 llvm_unreachable(
"References shouldn't get here");
4020 case Type::DeducedTemplateSpecialization:
4021 llvm_unreachable(
"Undeduced type shouldn't get here");
4029 case Type::ConstantArray:
4030 case Type::IncompleteArray:
4031 case Type::VariableArray:
4032 case Type::ArrayParameter:
4037 case Type::FunctionNoProto:
4038 case Type::FunctionProto:
4048 case Type::Record: {
4050 ->getDefinitionOrSelf();
4057 BuildSIClassTypeInfo(RD);
4059 BuildVMIClassTypeInfo(RD);
4064 case Type::ObjCObject:
4065 case Type::ObjCInterface:
4069 case Type::ObjCObjectPointer:
4077 case Type::MemberPointer:
4085 case Type::OverflowBehavior:
4088 case Type::HLSLAttributedResource:
4089 case Type::HLSLInlineSpirv:
4090 llvm_unreachable(
"HLSL doesn't support RTTI");
4093 GV->replaceInitializer(llvm::ConstantStruct::getAnon(Fields));
4097 GV->takeName(OldGV);
4098 OldGV->replaceAllUsesWith(GV);
4099 OldGV->eraseFromParent();
4103 GV->setComdat(M.getOrInsertComdat(GV->getName()));
4127 GV->setVisibility(TypeInfoVisibility);
4130 TypeName->setDLLStorageClass(DLLStorageClass);
4131 GV->setDLLStorageClass(TypeInfoDLLStorageClass);
4141void ItaniumRTTIBuilder::BuildObjCObjectTypeInfo(
const ObjCObjectType *OT) {
4143 const Type *
T = OT->getBaseType().getTypePtr();
4151 ObjCInterfaceDecl *Super =
Class->getSuperClass();
4159 llvm::Constant *BaseTypeInfo =
4160 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(SuperTy);
4161 Fields.push_back(BaseTypeInfo);
4166void ItaniumRTTIBuilder::BuildSIClassTypeInfo(
const CXXRecordDecl *RD) {
4170 llvm::Constant *BaseTypeInfo =
4172 Fields.push_back(BaseTypeInfo);
4178void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(
const CXXRecordDecl *RD) {
4179 llvm::Type *UnsignedIntLTy =
4187 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
4192 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, RD->
getNumBases()));
4225 llvm::Type *OffsetFlagsLTy =
4228 for (
const auto &Base : RD->
bases()) {
4230 Fields.push_back(ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(
Base.getType()));
4232 auto *BaseDecl =
Base.getType()->castAsCXXRecordDecl();
4240 if (
Base.isVirtual())
4252 if (
Base.isVirtual())
4257 Fields.push_back(llvm::ConstantInt::getSigned(OffsetFlagsLTy, OffsetFlags));
4263void ItaniumRTTIBuilder::BuildPointerTypeInfo(QualType PointeeTy) {
4269 llvm::Type *UnsignedIntLTy =
4271 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
4276 llvm::Constant *PointeeTypeInfo =
4277 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(PointeeTy);
4278 Fields.push_back(PointeeTypeInfo);
4284ItaniumRTTIBuilder::BuildPointerToMemberTypeInfo(
const MemberPointerType *Ty) {
4296 llvm::Type *UnsignedIntLTy =
4298 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
4303 llvm::Constant *PointeeTypeInfo =
4304 ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(PointeeTy);
4305 Fields.push_back(PointeeTypeInfo);
4312 Fields.push_back(ItaniumRTTIBuilder(
CXXABI).BuildTypeInfo(
T));
4315llvm::Constant *ItaniumCXXABI::getAddrOfRTTIDescriptor(QualType Ty) {
4316 return ItaniumRTTIBuilder(*this).BuildTypeInfo(Ty);
4319void ItaniumCXXABI::EmitFundamentalRTTIDescriptors(
const CXXRecordDecl *RD) {
4322 QualType FundamentalTypes[] = {
4323 getContext().VoidTy, getContext().NullPtrTy,
4324 getContext().BoolTy, getContext().WCharTy,
4325 getContext().CharTy, getContext().UnsignedCharTy,
4326 getContext().SignedCharTy, getContext().ShortTy,
4327 getContext().UnsignedShortTy, getContext().IntTy,
4328 getContext().UnsignedIntTy, getContext().LongTy,
4329 getContext().UnsignedLongTy, getContext().LongLongTy,
4330 getContext().UnsignedLongLongTy, getContext().Int128Ty,
4331 getContext().UnsignedInt128Ty, getContext().HalfTy,
4332 getContext().FloatTy, getContext().DoubleTy,
4333 getContext().LongDoubleTy, getContext().Float128Ty,
4334 getContext().Char8Ty, getContext().Char16Ty,
4335 getContext().Char32Ty
4337 llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass =
4339 ? llvm::GlobalValue::DLLExportStorageClass
4340 : llvm::GlobalValue::DefaultStorageClass;
4343 for (
const QualType &FundamentalType : FundamentalTypes) {
4344 QualType PointerType = getContext().getPointerType(FundamentalType);
4345 QualType PointerTypeConst = getContext().getPointerType(
4346 FundamentalType.withConst());
4347 for (QualType
Type : {FundamentalType, PointerType, PointerTypeConst})
4348 ItaniumRTTIBuilder(*this).BuildTypeInfo(
4349 Type, llvm::GlobalValue::ExternalLinkage,
Visibility, DLLStorageClass,
4356ItaniumCXXABI::RTTIUniquenessKind ItaniumCXXABI::classifyRTTIUniqueness(
4357 QualType CanTy, llvm::GlobalValue::LinkageTypes
Linkage)
const {
4358 if (shouldRTTIBeUnique())
4362 if (
Linkage != llvm::GlobalValue::LinkOnceODRLinkage &&
4363 Linkage != llvm::GlobalValue::WeakODRLinkage)
4371 if (
Linkage == llvm::GlobalValue::LinkOnceODRLinkage)
4372 return RUK_NonUniqueHidden;
4377 assert(
Linkage == llvm::GlobalValue::WeakODRLinkage);
4378 return RUK_NonUniqueVisible;
4383enum class StructorCodegen { Emit, RAUW, Alias, COMDAT };
4390 llvm::GlobalValue::LinkageTypes
Linkage) {
4394 Linkage != llvm::GlobalValue::AvailableExternallyLinkage;
4400 return StructorCodegen::Emit;
4405 return StructorCodegen::Emit;
4408 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
4416 if (llvm::GlobalValue::isDiscardableIfUnused(
Linkage) &&
4418 return StructorCodegen::RAUW;
4421 if (!llvm::GlobalAlias::isValidLinkage(
Linkage))
4422 return StructorCodegen::RAUW;
4424 if (llvm::GlobalValue::isWeakForLinker(
Linkage)) {
4428 return StructorCodegen::COMDAT;
4429 return StructorCodegen::Emit;
4432 return StructorCodegen::Alias;
4442 if (Entry && !Entry->isDeclaration())
4448 auto *Alias = llvm::GlobalAlias::create(
Linkage,
"", Aliasee);
4451 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4455 assert(Entry->getType() == Aliasee->getType() &&
4456 "declaration exists with different type");
4457 Alias->takeName(Entry);
4458 Entry->replaceAllUsesWith(Alias);
4459 Entry->eraseFromParent();
4461 Alias->setName(MangledName);
4468void ItaniumCXXABI::emitCXXStructor(GlobalDecl GD) {
4470 auto *CD = dyn_cast<CXXConstructorDecl>(MD);
4477 GlobalDecl BaseDecl;
4483 if (CGType == StructorCodegen::Alias || CGType == StructorCodegen::COMDAT) {
4488 if (CGType == StructorCodegen::RAUW) {
4501 CGType != StructorCodegen::COMDAT &&
4519 if (CGType == StructorCodegen::COMDAT) {
4520 SmallString<256> Buffer;
4521 llvm::raw_svector_ostream
Out(Buffer);
4523 getMangleContext().mangleCXXDtorComdat(DD, Out);
4525 getMangleContext().mangleCXXCtorComdat(CD, Out);
4526 llvm::Comdat *
C = CGM.
getModule().getOrInsertComdat(
Out.str());
4535 llvm::FunctionType *FTy = llvm::FunctionType::get(
4543 llvm::FunctionType *FTy =
4544 llvm::FunctionType::get(CGM.
VoidTy,
false);
4551 llvm::FunctionType *FTy = llvm::FunctionType::get(
4570 struct CallEndCatch final : EHScopeStack::Cleanup {
4571 CallEndCatch(
bool MightThrow) : MightThrow(MightThrow) {}
4574 void Emit(CodeGenFunction &CGF, Flags flags)
override {
4593 bool EndMightThrow) {
4594 llvm::CallInst *call =
4597 CGF.
EHStack.pushCleanup<CallEndCatch>(
4599 EndMightThrow && !CGF.
CGM.
getLangOpts().AssumeNothrowExceptionDtor);
4624 llvm::Value *AdjustedExn =
CallBeginCatch(CGF, Exn, EndCatchMightThrow);
4629 if (
const PointerType *PT = dyn_cast<PointerType>(CaughtType)) {
4638 unsigned HeaderSize =
4641 CGF.
Builder.CreateConstGEP1_32(CGF.
Int8Ty, Exn, HeaderSize);
4664 llvm::Value *Casted = CGF.
Builder.CreateBitCast(AdjustedExn, PtrTy);
4672 llvm::Value *ExnCast =
4673 CGF.
Builder.CreateBitCast(AdjustedExn, LLVMCatchTy,
"exn.byref");
4685 if (CatchType->hasPointerRepresentation()) {
4686 llvm::Value *CastExn =
4687 CGF.
Builder.CreateBitCast(AdjustedExn, LLVMCatchTy,
"exn.casted");
4704 llvm_unreachable(
"bad ownership qualifier!");
4722 llvm_unreachable(
"evaluation kind filtered out!");
4724 llvm_unreachable(
"bad evaluation kind");
4728 auto catchRD = CatchType->getAsCXXRecordDecl();
4738 Address adjustedExn(CGF.
Builder.CreateBitCast(rawAdjustedExn, PtrTy),
4739 LLVMCatchTy, caughtExnAlignment);
4748 llvm::CallInst *rawAdjustedExn =
4752 Address adjustedExn(CGF.
Builder.CreateBitCast(rawAdjustedExn, PtrTy),
4753 LLVMCatchTy, caughtExnAlignment);
4784void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF,
4785 const CXXCatchStmt *S) {
4832 C.VoidTy, {C.getPointerType(C.CharTy)});
4835 fnTy,
"__clang_call_terminate", llvm::AttributeList(),
true);
4836 llvm::Function *fn =
4841 fn->setDoesNotThrow();
4842 fn->setDoesNotReturn();
4847 fn->addFnAttr(llvm::Attribute::NoInline);
4851 fn->setLinkage(llvm::Function::LinkOnceODRLinkage);
4852 fn->setVisibility(llvm::Function::HiddenVisibility);
4854 fn->setComdat(CGM.
getModule().getOrInsertComdat(fn->getName()));
4857 llvm::BasicBlock *entry =
4862 llvm::Value *exn = &*fn->arg_begin();
4865 llvm::CallInst *catchCall = builder.CreateCall(
getBeginCatchFn(CGM), exn);
4866 catchCall->setDoesNotThrow();
4870 llvm::CallInst *termCall = builder.CreateCall(CGM.
getTerminateFn());
4871 termCall->setDoesNotThrow();
4872 termCall->setDoesNotReturn();
4876 builder.CreateUnreachable();
4882ItaniumCXXABI::emitTerminateForUnexpectedException(CodeGenFunction &CGF,
4892std::pair<llvm::Value *, const CXXRecordDecl *>
4893ItaniumCXXABI::LoadVTablePtr(CodeGenFunction &CGF, Address This,
4894 const CXXRecordDecl *RD) {
4899ItaniumCXXABI::getSignedVirtualMemberFunctionPointer(
const CXXMethodDecl *MD) {
4900 const CXXMethodDecl *origMD =
4904 llvm::Constant *thunk = getOrCreateVirtualFunctionPointerThunk(origMD);
4910void WebAssemblyCXXABI::emitBeginCatch(CodeGenFunction &CGF,
4911 const CXXCatchStmt *
C) {
4913 CGF.
EHStack.pushCleanup<CatchRetScope>(
4915 ItaniumCXXABI::emitBeginCatch(CGF,
C);
4919WebAssemblyCXXABI::emitTerminateForUnexpectedException(CodeGenFunction &CGF,
4936void XLCXXABI::registerGlobalDtor(CodeGenFunction &CGF,
const VarDecl &D,
4937 llvm::FunctionCallee Dtor,
4938 llvm::Constant *
Addr) {
4943 llvm::FunctionType *AtExitTy =
4944 llvm::FunctionType::get(CGM.
IntTy, {CGM.IntTy, PtrTy},
true);
4947 llvm::FunctionCallee
AtExit =
4955 llvm::Value *NV = llvm::Constant::getNullValue(CGM.
IntTy);
4963 llvm::Function *DtorStub =
4971 emitCXXStermFinalizer(D, DtorStub,
Addr);
4974void XLCXXABI::emitCXXStermFinalizer(
const VarDecl &D, llvm::Function *dtorStub,
4975 llvm::Constant *addr) {
4976 llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.
VoidTy,
false);
4977 SmallString<256> FnName;
4979 llvm::raw_svector_ostream
Out(FnName);
4980 getMangleContext().mangleDynamicStermFinalizer(&D, Out);
4988 CodeGenFunction CGF(CGM);
5002 llvm::BasicBlock *DestructCallBlock = CGF.
createBasicBlock(
"destruct.call");
5007 CGF.
Builder.CreateCondBr(NeedsDestruct, DestructCallBlock, EndBlock);
5012 llvm::CallInst *CI = CGF.
Builder.CreateCall(dtorStub);
5015 CI->setCallingConv(dtorStub->getCallingConv());
5021 if (
auto *IPA = D.
getAttr<InitPriorityAttr>()) {
5023 IPA->getPriority());
static void emitConstructorDestructorAlias(CIRGenModule &cgm, GlobalDecl aliasDecl, GlobalDecl targetDecl)
static Address emitDynamicCastToVoid(CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, Address src)
static cir::GlobalLinkageKind getTypeInfoLinkage(CIRGenModule &cgm, QualType ty)
Return the linkage that the type info and type info name constants should have for the given type.
static mlir::Value performTypeAdjustment(CIRGenFunction &cgf, Address initialPtr, const CXXRecordDecl *unadjustedClass, int64_t nonVirtualAdjustment, int64_t virtualAdjustment, bool isReturnAdjustment)
static mlir::Value emitExactDynamicCast(CIRGenItaniumCXXABI &abi, CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, QualType destRecordTy, cir::PointerType destCIRTy, bool isRefCast, Address src)
static cir::FuncOp getItaniumDynamicCastFn(CIRGenFunction &cgf)
static cir::FuncOp getBadCastFn(CIRGenFunction &cgf)
static RValue performReturnAdjustment(CIRGenFunction &cgf, QualType resultType, RValue rv, const ThunkInfo &thunk)
static StructorCodegen getCodegenToUse(CodeGenModule &CGM, const CXXMethodDecl *MD)
static llvm::FunctionCallee getClangCallTerminateFn(CodeGenModule &CGM)
Get or define the following function: void @__clang_call_terminate(i8* exn) nounwind noreturn This co...
static bool CXXRecordNonInlineHasAttr(const CXXRecordDecl *RD)
static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM, QualType Ty)
ShouldUseExternalRTTIDescriptor - Returns whether the type information for the given type exists some...
static llvm::FunctionCallee getBadTypeidFn(CodeGenFunction &CGF)
static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF, llvm::FunctionCallee dtor, llvm::Constant *addr, bool TLS)
Register a global destructor using __cxa_atexit.
static bool structorSymbolMustBeRetained(CodeGenModule &CGM, const CXXMethodDecl *MD, llvm::GlobalValue::LinkageTypes Linkage)
static llvm::FunctionCallee getBeginCatchFn(CodeGenModule &CGM)
static llvm::Constant * pointerAuthResignMemberFunctionPointer(llvm::Constant *Src, QualType DestType, QualType SrcType, CodeGenModule &CGM)
static llvm::FunctionCallee getGuardReleaseFn(CodeGenModule &CGM, llvm::PointerType *GuardPtrTy)
static llvm::Function * createGlobalInitOrCleanupFn(CodeGen::CodeGenModule &CGM, StringRef FnName)
static llvm::FunctionCallee getAllocateExceptionFn(CodeGenModule &CGM)
static llvm::Value * CallBeginCatch(CodeGenFunction &CGF, llvm::Value *Exn, bool EndMightThrow)
Emits a call to __cxa_begin_catch and enters a cleanup to call __cxa_end_catch.
static llvm::FunctionCallee getGuardAbortFn(CodeGenModule &CGM, llvm::PointerType *GuardPtrTy)
static void InitCatchParam(CodeGenFunction &CGF, const VarDecl &CatchParam, Address ParamAddr, SourceLocation Loc)
A "special initializer" callback for initializing a catch parameter during catch initialization.
static llvm::FunctionCallee getEndCatchFn(CodeGenModule &CGM)
static llvm::FunctionCallee getThrowFn(CodeGenModule &CGM)
static void setVTableSelectiveDLLImportExport(CodeGenModule &CGM, llvm::GlobalVariable *VTable, const CXXRecordDecl *RD)
static llvm::FunctionCallee getGuardAcquireFn(CodeGenModule &CGM, llvm::PointerType *GuardPtrTy)
static llvm::GlobalValue::VisibilityTypes getRTTIVisibility(llvm::GlobalValue::VisibilityTypes Visibility, llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass)
A dllexported global must not be hidden, so dllexport takes precedence over the visibility implied by...
static llvm::Constant * pointerAuthResignConstant(llvm::Value *Ptr, const CGPointerAuthInfo &CurAuthInfo, const CGPointerAuthInfo &NewAuthInfo, CodeGenModule &CGM)
static llvm::FunctionCallee getGetExceptionPtrFn(CodeGenModule &CGM)
static void dtorTy(std::byte *Ptr, const Descriptor *)
Result
Implement __builtin_bit_cast and related operations.
static cir::GlobalLinkageKind getThreadLocalWrapperLinkage(GlobalOp op, const clang::TargetInfo &targetInfo)
static bool isThreadWrapperReplaceable(const clang::TargetInfo &targetInfo)
llvm::MachO::Record Record
static uint64_t getFieldOffset(const ASTContext &C, const FieldDecl *FD)
static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D)
Determine what kind of template specialization the given declaration is.
static QualType getPointeeType(const MemRegion *R)
#define CXXABI(Name, Str)
C Language Family Type Representation.
a trap message and trap category.
const ValueDecl * getMemberPointerDecl() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
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.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
CharUnits getExnObjectAlignment() const
Return the alignment (in bytes) of the thrown exception object.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
CharUnits getPreferredTypeAlignInChars(QualType T) const
Return the PreferredAlignment of a (complete) type T, in characters.
CanQualType UnsignedIntTy
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
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 TargetInfo & getTargetInfo() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
TargetCXXABI::Kind getCXXABIKind() const
Return the C++ ABI kind that should be used.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
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.
QualType getType() const
Retrieves the type of the base class.
SourceLocation getBeginLoc() const LLVM_READONLY
VarDecl * getExceptionDecl() 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.
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a C++ struct/union/class.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_iterator bases_begin()
base_class_range vbases()
bool isAbstract() const
Determine whether this class has a pure virtual function.
bool isDynamicClass() const
bool hasDefinition() const
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
const Expr * getSubExpr() const
static CanQual< Type > CreateUnsafe(QualType Other)
Qualifiers getQualifiers() const
Retrieve all qualifiers.
CastKind getCastKind() const
This is an opaque type for sizes expressed in character units.
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.
PointerAuthOptions PointerAuth
Configuration for pointer-signing.
std::string SymbolPartition
The name of the partition that symbols are assigned to, specified with -fsymbol-partition (see https:...
static ABIArgInfo getIndirect(CharUnits Alignment, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
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...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
unsigned getAddressSpace() const
Return the address space that this address resides in.
llvm::PointerType * getType() const
Return the type of the pointer value.
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
llvm::Value * CreateIsNull(Address Addr, const Twine &Name="")
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="")
Implements C++ ABI-specific code generation functions.
virtual llvm::CallInst * emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn)
MangleContext & getMangleContext()
Gets the mangle context.
All available information about a concrete callee.
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
CGFunctionInfo - Class to encapsulate the information about a function definition.
ABIArgInfo & getReturnInfo()
CanQualType getReturnType() const
llvm::Value * getDiscriminator() const
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
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.
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...
llvm::Value * performAddrSpaceCast(llvm::Value *Src, llvm::Type *DestTy)
llvm::Function * createTLSAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr, llvm::FunctionCallee &AtExit)
Create a stub function, suitable for being passed to __pt_atexit_np, which passes the given address t...
SanitizerSet SanOpts
Sanitizers enabled for this function.
void EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
llvm::Value * getExceptionFromSlot()
Returns the contents of the function's exception object and selector slots.
llvm::Type * ConvertType(QualType T)
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.
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
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)
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
const LangOptions & getLangOpts() const
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
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)
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
void EmitAnyExprToExn(const Expr *E, Address Addr)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
const TargetInfo & getTarget() const
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
std::array< llvm::Constant *, 3 > EmitCFICheckFailStaticArgs(CFITypeCheckKind CheckKind, SourceLocation Loc, QualType Type)
Build the static argument array {CheckKind, SourceLocation, TypeDescriptor} for a UBSan CFICheckFail ...
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.
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerKind::SanitizerOrdinal > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs, const TrapReason *TR=nullptr)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
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.
CGDebugInfo * getDebugInfo()
LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, AlignmentSource Source=AlignmentSource::Type)
Same as MakeAddrLValue above except that the pointer is known to be unsigned.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
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,...
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Emit the concrete pointer authentication informaton for the given authentication schema.
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
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::Value * unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub)
Call unatexit() with function dtorStub.
llvm::Value * emitPointerAuthResign(llvm::Value *Pointer, QualType PointerType, const CGPointerAuthInfo &CurAuthInfo, const CGPointerAuthInfo &NewAuthInfo, bool IsKnownNonNull)
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
ASTContext & getContext() const
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
void EmitAutoVarCleanups(const AutoVarEmission &emission)
void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Registers the dtor using 'llvm.global_dtors' for platforms that do not support an 'atexit()' function...
llvm::Value * LoadCXXVTT()
LoadCXXVTT - Load the VTT parameter to base constructors/destructors have virtual bases.
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
llvm::Type * ConvertTypeForMem(QualType T)
CodeGenTypes & getTypes() const
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
llvm::Value * GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, bool Delegating)
GetVTTParameter - Return the VTT parameter that should be passed to a base constructor/destructor wit...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, bool NoMerge=false, const TrapReason *TR=nullptr)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
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...
llvm::LLVMContext & getLLVMContext()
void PopCleanupBlock(bool FallThroughIsBranchThrough=false, bool ForDeactivation=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
LValue MakeNaturalAlignRawAddrLValue(llvm::Value *V, QualType T)
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
llvm::Value * EmitPointerAuthAuth(const CGPointerAuthInfo &Info, llvm::Value *Pointer)
This class organizes the cross-function state that is used while generating LLVM code.
void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer, int Priority)
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer, int Priority)
Add an sterm finalizer to its own llvm.global_dtors entry.
llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const
Get LLVM TLS mode from CodeGenOptions.
void setDSOLocal(llvm::GlobalValue *GV) const
llvm::Module & getModule() const
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
CodeGenVTables & getVTables()
void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn)
Add an sterm finalizer to the C++ global cleanup function.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
llvm::Constant * getFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return the ABI-correct function pointer value for a reference to the given function.
CGPointerAuthInfo getMemberFunctionPointerAuthInfo(QualType FT)
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
bool shouldMapVisibilityToDLLExport(const NamedDecl *D) const
const TargetInfo & getTarget() const
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
const llvm::DataLayout & getDataLayout() const
CGCXXABI & getCXXABI() const
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V)
llvm::Constant * getMemberFunctionPointer(const FunctionDecl *FD, llvm::Type *Ty=nullptr)
llvm::Function * codegenCXXStructor(GlobalDecl GD)
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
const llvm::Triple & getTriple() const
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, const CXXRecordDecl *Class, CharUnits ExpectedTargetAlign)
Given a class pointer with an actual known alignment, and the expected alignment of an object at a dy...
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
ItaniumVTableContext & getItaniumVTableContext()
ASTContext & getContext() const
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
bool supportsCOMDAT() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, llvm::Align Alignment)
Will return a global variable of the given type.
llvm::FunctionCallee getTerminateFn()
Get the declaration of std::terminate for the platform.
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
LangAS GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
void addReplacement(StringRef Name, llvm::Constant *C)
llvm::Constant * getConstantSignedPointer(llvm::Constant *Pointer, const PointerAuthSchema &Schema, llvm::Constant *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Sign a constant pointer using the given scheme, producing a constant with the same IR type.
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)
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs, const FunctionDecl *ABIInfoFD)
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.
const CodeGenOptions & getCodeGenOpts() const
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....
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
void createVTableInitializer(ConstantStructBuilder &builder, const VTableLayout &layout, llvm::Constant *rtti, bool vtableHasLocalLinkage)
Add vtable components for the given vtable layout to the given global initializer.
void GenerateRelativeVTableAlias(llvm::GlobalVariable *VTable, llvm::StringRef AliasNameRef)
Generate a public facing alias for the vtable and make the vtable either hidden or private.
bool isVTableExternal(const CXXRecordDecl *RD)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
void RemoveHwasanMetadata(llvm::GlobalValue *GV) const
Specify a global should not be instrumented with hwasan.
void EmitVTTDefinition(llvm::GlobalVariable *VTT, llvm::GlobalVariable::LinkageTypes Linkage, const CXXRecordDecl *RD)
EmitVTTDefinition - Emit the definition of the given vtable.
void pushTerminate()
Push a terminate handler on the stack.
void popTerminate()
Pops a terminate handler off the stack.
static RValue get(llvm::Value *V)
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
virtual unsigned getSizeOfUnwindException() const
Determines the size of struct _Unwind_Exception on this platform, in 8-bit units.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isTranslationUnit() const
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
SourceLocation getLocation() const
DeclContext * getDeclContext()
bool shouldEmitInExternalSource() const
Whether the definition of the declaration should be emitted in external sources.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Represents a prototype with parameter type info, e.g.
GlobalDecl - represents a global declaration.
GlobalDecl getWithCtorType(CXXCtorType Type)
CXXCtorType getCtorType() const
GlobalDecl getCanonicalDecl() const
GlobalDecl getWithDtorType(CXXDtorType Type)
CXXDtorType getDtorType() const
const Decl * getDecl() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
GlobalDecl findOriginalMethod(GlobalDecl GD)
Return the method that added the v-table slot that will be used to call the given method.
virtual void mangleCXXRTTI(QualType T, raw_ostream &)=0
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
A pointer to member type per C++ 8.3.3 - Pointers to members.
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.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Visibility getVisibility() const
Determines the visibility of this entity.
bool isExternallyVisible() const
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
The collection of all-type qualifiers we support.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
ObjCLifetime getObjCLifetime() const
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Encodes a location in the source.
SourceLocation getBeginLoc() const LLVM_READONLY
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
unsigned getMaxAtomicInlineWidth() const
Return the maximum width lock-free atomic operation which can be inlined given the supported features...
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool hasPS4DLLImportExport() const
uint64_t getPointerAlign(LangAS AddrSpace) const
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
CXXRecordDecl * castAsCXXRecordDecl() 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.
Visibility getVisibility() const
Determine the visibility of this type.
bool isMemberFunctionPointerType() const
Linkage getLinkage() const
Determine the linkage of this type.
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
size_t getVTableSize(size_t i) const
Represents a variable declaration or definition.
TLSKind getTLSKind() const
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
bool isInline() const
Whether this variable is (C++1z) inline.
const Expr * getInit() const
@ TLS_Dynamic
TLS with a dynamic initializer.
@ TLS_None
Not a TLS variable.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
unsigned extractPBaseFlags(const ASTContext &Ctx, QualType &Type)
Compute the flags for a __pbase_type_info, and remove the corresponding pieces from Type.
bool containsIncompleteClassType(QualType Ty)
Returns whether the given type contains an incomplete class type.
bool canUseSingleInheritance(const CXXRecordDecl *RD)
Return whether the given record decl has a "single, public, non-virtual base at offset zero (i....
unsigned computeVMIClassTypeInfoFlags(const CXXRecordDecl *RD)
Compute the value of the flags member in abi::__vmi_class_type_info.
CharUnits computeOffsetHint(ASTContext &Ctx, const CXXRecordDecl *Src, const CXXRecordDecl *Dst)
Compute the src2dst_offset hint as described in the Itanium C++ ABI [2.9.7].
bool isStandardLibraryRTTIDescriptor(QualType Ty)
Returns whether the type information for the given type exists in the standard library.
@ BCTI_Virtual
BCTI_Virtual - Base class is virtual.
@ BCTI_Public
BCTI_Public - Base class is public.
@ PTI_ContainingClassIncomplete
PTI_ContainingClassIncomplete - Containing class is incomplete.
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
const EHPersonality & getEHPersonality(CodeGenModule &CGM, const FunctionDecl *FD)
Selects the personality function to use for FD, or for the translation unit as a whole when FD is nul...
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
CGCXXABI * CreateItaniumCXXABI(CodeGenModule &CGM)
Creates an Itanium-family ABI.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
constexpr Variable var(Literal L)
Returns the variable of L.
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.
@ Ctor_Comdat
The COMDAT used for ctors.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
@ Success
Annotation was successful.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ VisibleNone
No linkage according to the standard, but is visible from other translation units because of types de...
@ None
No linkage, which means that the entity is unique and can only be referred to from within its scope.
@ UniqueExternal
External linkage within a unique namespace.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
const FunctionProtoType * T
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.
bool isDiscardableGVALinkage(GVALinkage L)
LangAS
Defines the address space values used by the address space qualifier of QualType.
U cast(CodeGen::Address addr)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Visibility
Describes the different kinds of visibility that a declaration may have.
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
__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
const CXXRecordDecl * NearestVBase
llvm::PointerType * VoidPtrTy
llvm::IntegerType * Int64Ty
llvm::PointerType * GlobalsVoidPtrTy
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * CharTy
char
llvm::CallingConv::ID getRuntimeCC() const
llvm::IntegerType * SizeTy
llvm::PointerType * GlobalsInt8PtrTy
llvm::IntegerType * Int32Ty
llvm::IntegerType * IntPtrTy
llvm::IntegerType * IntTy
int
CharUnits getSizeSize() const
CharUnits getSizeAlign() const
llvm::PointerType * Int8PtrTy
llvm::IntegerType * PtrDiffTy
CharUnits getPointerAlign() const
llvm::PointerType * DefaultPtrTy
Extra information about a function prototype.
PointerAuthSchema CXXTypeInfoVTablePointer
TypeInfo has external ABI requirements and is emitted without actually having parsed the libcxx defin...
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
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.
unsigned AddressPointIndex
struct clang::ReturnAdjustment::VirtualAdjustment::@103031170252120233124322035264172076254313213024 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@106065375072164260365214033034320247050276346205 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.