1 //===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This provides an abstract class for C++ code generation. Concrete subclasses
10 // of this implement code generation for specific C++ ABIs.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
17 #include "CodeGenFunction.h"
18 #include "clang/Basic/LLVM.h"
19 #include "clang/CodeGen/CodeGenABITypes.h"
30 class CXXConstructorDecl
;
31 class CXXDestructorDecl
;
38 class CodeGenFunction
;
42 /// Implements C++ ABI-specific code generation functions.
44 friend class CodeGenModule
;
48 std::unique_ptr
<MangleContext
> MangleCtx
;
50 CGCXXABI(CodeGenModule
&CGM
)
51 : CGM(CGM
), MangleCtx(CGM
.getContext().createMangleContext()) {}
54 ImplicitParamDecl
*getThisDecl(CodeGenFunction
&CGF
) {
55 return CGF
.CXXABIThisDecl
;
57 llvm::Value
*getThisValue(CodeGenFunction
&CGF
) {
58 return CGF
.CXXABIThisValue
;
61 Address
getThisAddress(CodeGenFunction
&CGF
);
63 /// Issue a diagnostic about unsupported features in the ABI.
64 void ErrorUnsupportedABI(CodeGenFunction
&CGF
, StringRef S
);
66 /// Get a null value for unsupported member pointers.
67 llvm::Constant
*GetBogusMemberPointer(QualType T
);
69 ImplicitParamDecl
*&getStructorImplicitParamDecl(CodeGenFunction
&CGF
) {
70 return CGF
.CXXStructorImplicitParamDecl
;
72 llvm::Value
*&getStructorImplicitParamValue(CodeGenFunction
&CGF
) {
73 return CGF
.CXXStructorImplicitParamValue
;
76 /// Loads the incoming C++ this pointer as it was passed by the caller.
77 llvm::Value
*loadIncomingCXXThis(CodeGenFunction
&CGF
);
79 void setCXXABIThisValue(CodeGenFunction
&CGF
, llvm::Value
*ThisPtr
);
81 ASTContext
&getContext() const { return CGM
.getContext(); }
83 bool mayNeedDestruction(const VarDecl
*VD
) const;
85 /// Determine whether we will definitely emit this variable with a constant
86 /// initializer, either because the language semantics demand it or because
87 /// we know that the initializer is a constant.
88 // For weak definitions, any initializer available in the current translation
89 // is not necessarily reflective of the initializer used; such initializers
90 // are ignored unless if InspectInitForWeakDef is true.
92 isEmittedWithConstantInitializer(const VarDecl
*VD
,
93 bool InspectInitForWeakDef
= false) const;
95 virtual bool requiresArrayCookie(const CXXDeleteExpr
*E
, QualType eltType
);
96 virtual bool requiresArrayCookie(const CXXNewExpr
*E
);
98 /// Determine whether there's something special about the rules of
99 /// the ABI tell us that 'this' is a complete object within the
100 /// given function. Obvious common logic like being defined on a
101 /// final class will have been taken care of by the caller.
102 virtual bool isThisCompleteObject(GlobalDecl GD
) const = 0;
104 virtual bool constructorsAndDestructorsReturnThis() const {
105 return CGM
.getCodeGenOpts().CtorDtorReturnThis
;
112 /// Gets the mangle context.
113 MangleContext
&getMangleContext() {
117 /// Returns true if the given constructor or destructor is one of the
118 /// kinds that the ABI says returns 'this' (only applies when called
119 /// non-virtually for destructors).
121 /// There currently is no way to indicate if a destructor returns 'this'
122 /// when called virtually, and code generation does not support the case.
123 virtual bool HasThisReturn(GlobalDecl GD
) const {
124 if (isa
<CXXConstructorDecl
>(GD
.getDecl()) ||
125 (isa
<CXXDestructorDecl
>(GD
.getDecl()) &&
126 GD
.getDtorType() != Dtor_Deleting
))
127 return constructorsAndDestructorsReturnThis();
131 virtual bool hasMostDerivedReturn(GlobalDecl GD
) const { return false; }
133 virtual bool useSinitAndSterm() const { return false; }
135 /// Returns true if the target allows calling a function through a pointer
136 /// with a different signature than the actual function (or equivalently,
137 /// bitcasting a function or function pointer to a different function type).
138 /// In principle in the most general case this could depend on the target, the
139 /// calling convention, and the actual types of the arguments and return
140 /// value. Here it just means whether the signature mismatch could *ever* be
141 /// allowed; in other words, does the target do strict checking of signatures
143 virtual bool canCallMismatchedFunctionType() const { return true; }
145 /// If the C++ ABI requires the given type be returned in a particular way,
146 /// this method sets RetAI and returns true.
147 virtual bool classifyReturnType(CGFunctionInfo
&FI
) const = 0;
149 /// Specify how one should pass an argument of a record type.
151 /// Pass it using the normal C aggregate rules for the ABI, potentially
152 /// introducing extra copies and passing some or all of it in registers.
155 /// Pass it on the stack using its defined layout. The argument must be
156 /// evaluated directly into the correct stack position in the arguments area,
157 /// and the call machinery must not move it or introduce extra copies.
160 /// Pass it as a pointer to temporary memory.
164 /// Returns how an argument of the given record type should be passed.
165 virtual RecordArgABI
getRecordArgABI(const CXXRecordDecl
*RD
) const = 0;
167 /// Returns true if the implicit 'sret' parameter comes after the implicit
168 /// 'this' parameter of C++ instance methods.
169 virtual bool isSRetParameterAfterThis() const { return false; }
171 /// Returns true if the ABI permits the argument to be a homogeneous
174 isPermittedToBeHomogeneousAggregate(const CXXRecordDecl
*RD
) const {
178 /// Find the LLVM type used to represent the given member pointer
181 ConvertMemberPointerType(const MemberPointerType
*MPT
);
183 /// Load a member function from an object and a member function
184 /// pointer. Apply the this-adjustment and set 'This' to the
186 virtual CGCallee
EmitLoadOfMemberFunctionPointer(
187 CodeGenFunction
&CGF
, const Expr
*E
, Address This
,
188 llvm::Value
*&ThisPtrForCall
, llvm::Value
*MemPtr
,
189 const MemberPointerType
*MPT
);
191 /// Calculate an l-value from an object and a data member pointer.
192 virtual llvm::Value
*
193 EmitMemberDataPointerAddress(CodeGenFunction
&CGF
, const Expr
*E
,
194 Address Base
, llvm::Value
*MemPtr
,
195 const MemberPointerType
*MPT
);
197 /// Perform a derived-to-base, base-to-derived, or bitcast member
198 /// pointer conversion.
199 virtual llvm::Value
*EmitMemberPointerConversion(CodeGenFunction
&CGF
,
203 /// Perform a derived-to-base, base-to-derived, or bitcast member
204 /// pointer conversion on a constant value.
205 virtual llvm::Constant
*EmitMemberPointerConversion(const CastExpr
*E
,
206 llvm::Constant
*Src
);
208 /// Return true if the given member pointer can be zero-initialized
209 /// (in the C++ sense) with an LLVM zeroinitializer.
210 virtual bool isZeroInitializable(const MemberPointerType
*MPT
);
212 /// Return whether or not a member pointers type is convertible to an IR type.
213 virtual bool isMemberPointerConvertible(const MemberPointerType
*MPT
) const {
217 /// Create a null member pointer of the given type.
218 virtual llvm::Constant
*EmitNullMemberPointer(const MemberPointerType
*MPT
);
220 /// Create a member pointer for the given method.
221 virtual llvm::Constant
*EmitMemberFunctionPointer(const CXXMethodDecl
*MD
);
223 /// Create a member pointer for the given field.
224 virtual llvm::Constant
*EmitMemberDataPointer(const MemberPointerType
*MPT
,
227 /// Create a member pointer for the given member pointer constant.
228 virtual llvm::Constant
*EmitMemberPointer(const APValue
&MP
, QualType MPT
);
230 /// Emit a comparison between two member pointers. Returns an i1.
231 virtual llvm::Value
*
232 EmitMemberPointerComparison(CodeGenFunction
&CGF
,
235 const MemberPointerType
*MPT
,
238 /// Determine if a member pointer is non-null. Returns an i1.
239 virtual llvm::Value
*
240 EmitMemberPointerIsNotNull(CodeGenFunction
&CGF
,
242 const MemberPointerType
*MPT
);
245 /// A utility method for computing the offset required for the given
246 /// base-to-derived or derived-to-base member-pointer conversion.
247 /// Does not handle virtual conversions (in case we ever fully
248 /// support an ABI that allows this). Returns null if no adjustment
250 llvm::Constant
*getMemberPointerAdjustment(const CastExpr
*E
);
253 virtual void emitVirtualObjectDelete(CodeGenFunction
&CGF
,
254 const CXXDeleteExpr
*DE
,
255 Address Ptr
, QualType ElementType
,
256 const CXXDestructorDecl
*Dtor
) = 0;
257 virtual void emitRethrow(CodeGenFunction
&CGF
, bool isNoReturn
) = 0;
258 virtual void emitThrow(CodeGenFunction
&CGF
, const CXXThrowExpr
*E
) = 0;
259 virtual llvm::GlobalVariable
*getThrowInfo(QualType T
) { return nullptr; }
261 /// Determine whether it's possible to emit a vtable for \p RD, even
262 /// though we do not know that the vtable has been marked as used by semantic
264 virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl
*RD
) const = 0;
266 virtual void emitBeginCatch(CodeGenFunction
&CGF
, const CXXCatchStmt
*C
) = 0;
268 virtual llvm::CallInst
*
269 emitTerminateForUnexpectedException(CodeGenFunction
&CGF
,
272 virtual llvm::Constant
*getAddrOfRTTIDescriptor(QualType Ty
) = 0;
273 virtual CatchTypeInfo
274 getAddrOfCXXCatchHandlerType(QualType Ty
, QualType CatchHandlerType
) = 0;
275 virtual CatchTypeInfo
getCatchAllTypeInfo();
277 virtual bool shouldTypeidBeNullChecked(QualType SrcRecordTy
) = 0;
278 virtual void EmitBadTypeidCall(CodeGenFunction
&CGF
) = 0;
279 virtual llvm::Value
*EmitTypeid(CodeGenFunction
&CGF
, QualType SrcRecordTy
,
281 llvm::Type
*StdTypeInfoPtrTy
) = 0;
283 virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr
,
284 QualType SrcRecordTy
) = 0;
285 virtual bool shouldEmitExactDynamicCast(QualType DestRecordTy
) = 0;
287 virtual llvm::Value
*emitDynamicCastCall(CodeGenFunction
&CGF
, Address Value
,
288 QualType SrcRecordTy
,
290 QualType DestRecordTy
,
291 llvm::BasicBlock
*CastEnd
) = 0;
293 virtual llvm::Value
*emitDynamicCastToVoid(CodeGenFunction
&CGF
,
295 QualType SrcRecordTy
) = 0;
297 /// Emit a dynamic_cast from SrcRecordTy to DestRecordTy. The cast fails if
298 /// the dynamic type of Value is not exactly DestRecordTy.
299 virtual llvm::Value
*emitExactDynamicCast(CodeGenFunction
&CGF
, Address Value
,
300 QualType SrcRecordTy
,
302 QualType DestRecordTy
,
303 llvm::BasicBlock
*CastSuccess
,
304 llvm::BasicBlock
*CastFail
) = 0;
306 virtual bool EmitBadCastCall(CodeGenFunction
&CGF
) = 0;
308 virtual llvm::Value
*GetVirtualBaseClassOffset(CodeGenFunction
&CGF
,
310 const CXXRecordDecl
*ClassDecl
,
311 const CXXRecordDecl
*BaseClassDecl
) = 0;
313 virtual llvm::BasicBlock
*EmitCtorCompleteObjectHandler(CodeGenFunction
&CGF
,
314 const CXXRecordDecl
*RD
);
316 /// Emit the code to initialize hidden members required
317 /// to handle virtual inheritance, if needed by the ABI.
319 initializeHiddenVirtualInheritanceMembers(CodeGenFunction
&CGF
,
320 const CXXRecordDecl
*RD
) {}
322 /// Emit constructor variants required by this ABI.
323 virtual void EmitCXXConstructors(const CXXConstructorDecl
*D
) = 0;
325 /// Additional implicit arguments to add to the beginning (Prefix) and end
326 /// (Suffix) of a constructor / destructor arg list.
328 /// Note that Prefix should actually be inserted *after* the first existing
329 /// arg; `this` arguments always come first.
330 struct AddedStructorArgs
{
335 SmallVector
<Arg
, 1> Prefix
;
336 SmallVector
<Arg
, 1> Suffix
;
337 AddedStructorArgs() = default;
338 AddedStructorArgs(SmallVector
<Arg
, 1> P
, SmallVector
<Arg
, 1> S
)
339 : Prefix(std::move(P
)), Suffix(std::move(S
)) {}
340 static AddedStructorArgs
prefix(SmallVector
<Arg
, 1> Args
) {
341 return {std::move(Args
), {}};
343 static AddedStructorArgs
suffix(SmallVector
<Arg
, 1> Args
) {
344 return {{}, std::move(Args
)};
348 /// Similar to AddedStructorArgs, but only notes the number of additional
350 struct AddedStructorArgCounts
{
353 AddedStructorArgCounts() = default;
354 AddedStructorArgCounts(unsigned P
, unsigned S
) : Prefix(P
), Suffix(S
) {}
355 static AddedStructorArgCounts
prefix(unsigned N
) { return {N
, 0}; }
356 static AddedStructorArgCounts
suffix(unsigned N
) { return {0, N
}; }
359 /// Build the signature of the given constructor or destructor variant by
360 /// adding any required parameters. For convenience, ArgTys has been
361 /// initialized with the type of 'this'.
362 virtual AddedStructorArgCounts
363 buildStructorSignature(GlobalDecl GD
,
364 SmallVectorImpl
<CanQualType
> &ArgTys
) = 0;
366 /// Returns true if the given destructor type should be emitted as a linkonce
367 /// delegating thunk, regardless of whether the dtor is defined in this TU or
369 virtual bool useThunkForDtorVariant(const CXXDestructorDecl
*Dtor
,
370 CXXDtorType DT
) const = 0;
372 virtual void setCXXDestructorDLLStorage(llvm::GlobalValue
*GV
,
373 const CXXDestructorDecl
*Dtor
,
374 CXXDtorType DT
) const;
376 virtual llvm::GlobalValue::LinkageTypes
377 getCXXDestructorLinkage(GVALinkage Linkage
, const CXXDestructorDecl
*Dtor
,
378 CXXDtorType DT
) const;
380 /// Emit destructor variants required by this ABI.
381 virtual void EmitCXXDestructors(const CXXDestructorDecl
*D
) = 0;
383 /// Get the type of the implicit "this" parameter used by a method. May return
384 /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
385 /// parameter to point to some artificial offset in a complete object due to
386 /// vbases being reordered.
387 virtual const CXXRecordDecl
*getThisArgumentTypeForMethod(GlobalDecl GD
) {
388 return cast
<CXXMethodDecl
>(GD
.getDecl())->getParent();
391 /// Perform ABI-specific "this" argument adjustment required prior to
392 /// a call of a virtual function.
393 /// The "VirtualCall" argument is true iff the call itself is virtual.
395 adjustThisArgumentForVirtualFunctionCall(CodeGenFunction
&CGF
, GlobalDecl GD
,
396 Address This
, bool VirtualCall
) {
400 /// Build a parameter variable suitable for 'this'.
401 void buildThisParam(CodeGenFunction
&CGF
, FunctionArgList
&Params
);
403 /// Insert any ABI-specific implicit parameters into the parameter list for a
404 /// function. This generally involves extra data for constructors and
407 /// ABIs may also choose to override the return type, which has been
408 /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
409 /// the formal return type of the function otherwise.
410 virtual void addImplicitStructorParams(CodeGenFunction
&CGF
, QualType
&ResTy
,
411 FunctionArgList
&Params
) = 0;
413 /// Get the ABI-specific "this" parameter adjustment to apply in the prologue
414 /// of a virtual function.
415 virtual CharUnits
getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD
) {
416 return CharUnits::Zero();
419 /// Emit the ABI-specific prolog for the function.
420 virtual void EmitInstanceFunctionProlog(CodeGenFunction
&CGF
) = 0;
422 virtual AddedStructorArgs
423 getImplicitConstructorArgs(CodeGenFunction
&CGF
, const CXXConstructorDecl
*D
,
424 CXXCtorType Type
, bool ForVirtualBase
,
425 bool Delegating
) = 0;
427 /// Add any ABI-specific implicit arguments needed to call a constructor.
429 /// \return The number of arguments added at the beginning and end of the
430 /// call, which is typically zero or one.
431 AddedStructorArgCounts
432 addImplicitConstructorArgs(CodeGenFunction
&CGF
, const CXXConstructorDecl
*D
,
433 CXXCtorType Type
, bool ForVirtualBase
,
434 bool Delegating
, CallArgList
&Args
);
436 /// Get the implicit (second) parameter that comes after the "this" pointer,
437 /// or nullptr if there is isn't one.
438 virtual llvm::Value
*
439 getCXXDestructorImplicitParam(CodeGenFunction
&CGF
,
440 const CXXDestructorDecl
*DD
, CXXDtorType Type
,
441 bool ForVirtualBase
, bool Delegating
) = 0;
443 /// Emit the destructor call.
444 virtual void EmitDestructorCall(CodeGenFunction
&CGF
,
445 const CXXDestructorDecl
*DD
, CXXDtorType Type
,
446 bool ForVirtualBase
, bool Delegating
,
447 Address This
, QualType ThisTy
) = 0;
449 /// Emits the VTable definitions required for the given record type.
450 virtual void emitVTableDefinitions(CodeGenVTables
&CGVT
,
451 const CXXRecordDecl
*RD
) = 0;
453 /// Checks if ABI requires extra virtual offset for vtable field.
455 isVirtualOffsetNeededForVTableField(CodeGenFunction
&CGF
,
456 CodeGenFunction::VPtr Vptr
) = 0;
458 /// Checks if ABI requires to initialize vptrs for given dynamic class.
459 virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl
*VTableClass
) = 0;
461 /// Get the address point of the vtable for the given base subobject.
462 virtual llvm::Constant
*
463 getVTableAddressPoint(BaseSubobject Base
,
464 const CXXRecordDecl
*VTableClass
) = 0;
466 /// Get the address point of the vtable for the given base subobject while
467 /// building a constructor or a destructor.
468 virtual llvm::Value
*
469 getVTableAddressPointInStructor(CodeGenFunction
&CGF
, const CXXRecordDecl
*RD
,
471 const CXXRecordDecl
*NearestVBase
) = 0;
473 /// Get the address of the vtable for the given record decl which should be
474 /// used for the vptr at the given offset in RD.
475 virtual llvm::GlobalVariable
*getAddrOfVTable(const CXXRecordDecl
*RD
,
476 CharUnits VPtrOffset
) = 0;
478 /// Build a virtual function pointer in the ABI-specific way.
479 virtual CGCallee
getVirtualFunctionPointer(CodeGenFunction
&CGF
,
480 GlobalDecl GD
, Address This
,
482 SourceLocation Loc
) = 0;
484 using DeleteOrMemberCallExpr
=
485 llvm::PointerUnion
<const CXXDeleteExpr
*, const CXXMemberCallExpr
*>;
487 /// Emit the ABI-specific virtual destructor call.
488 virtual llvm::Value
*
489 EmitVirtualDestructorCall(CodeGenFunction
&CGF
, const CXXDestructorDecl
*Dtor
,
490 CXXDtorType DtorType
, Address This
,
491 DeleteOrMemberCallExpr E
,
492 llvm::CallBase
**CallOrInvoke
) = 0;
494 virtual void adjustCallArgsForDestructorThunk(CodeGenFunction
&CGF
,
496 CallArgList
&CallArgs
) {}
498 /// Emit any tables needed to implement virtual inheritance. For Itanium,
499 /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
501 virtual void emitVirtualInheritanceTables(const CXXRecordDecl
*RD
) = 0;
503 virtual bool exportThunk() = 0;
504 virtual void setThunkLinkage(llvm::Function
*Thunk
, bool ForVTable
,
505 GlobalDecl GD
, bool ReturnAdjustment
) = 0;
507 virtual llvm::Value
*
508 performThisAdjustment(CodeGenFunction
&CGF
, Address This
,
509 const CXXRecordDecl
*UnadjustedClass
,
510 const ThunkInfo
&TI
) = 0;
512 virtual llvm::Value
*
513 performReturnAdjustment(CodeGenFunction
&CGF
, Address Ret
,
514 const CXXRecordDecl
*UnadjustedClass
,
515 const ReturnAdjustment
&RA
) = 0;
517 virtual void EmitReturnFromThunk(CodeGenFunction
&CGF
,
518 RValue RV
, QualType ResultType
);
520 virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl
*,
521 FunctionArgList
&Args
) const = 0;
523 /// Gets the offsets of all the virtual base pointers in a given class.
524 virtual std::vector
<CharUnits
> getVBPtrOffsets(const CXXRecordDecl
*RD
);
526 /// Gets the pure virtual member call function.
527 virtual StringRef
GetPureVirtualCallName() = 0;
529 /// Gets the deleted virtual member call name.
530 virtual StringRef
GetDeletedVirtualCallName() = 0;
532 /**************************** Array cookies ******************************/
534 /// Returns the extra size required in order to store the array
535 /// cookie for the given new-expression. May return 0 to indicate that no
536 /// array cookie is required.
538 /// Several cases are filtered out before this method is called:
539 /// - non-array allocations never need a cookie
540 /// - calls to \::operator new(size_t, void*) never need a cookie
542 /// \param expr - the new-expression being allocated.
543 virtual CharUnits
GetArrayCookieSize(const CXXNewExpr
*expr
);
545 /// Initialize the array cookie for the given allocation.
547 /// \param NewPtr - a char* which is the presumed-non-null
548 /// return value of the allocation function
549 /// \param NumElements - the computed number of elements,
550 /// potentially collapsed from the multidimensional array case;
552 /// \param ElementType - the base element allocated type,
553 /// i.e. the allocated type after stripping all array types
554 virtual Address
InitializeArrayCookie(CodeGenFunction
&CGF
,
556 llvm::Value
*NumElements
,
557 const CXXNewExpr
*expr
,
558 QualType ElementType
);
560 /// Reads the array cookie associated with the given pointer,
563 /// \param Ptr - a pointer to the first element in the array
564 /// \param ElementType - the base element type of elements of the array
565 /// \param NumElements - an out parameter which will be initialized
566 /// with the number of elements allocated, or zero if there is no
568 /// \param AllocPtr - an out parameter which will be initialized
569 /// with a char* pointing to the address returned by the allocation
571 /// \param CookieSize - an out parameter which will be initialized
572 /// with the size of the cookie, or zero if there is no cookie
573 virtual void ReadArrayCookie(CodeGenFunction
&CGF
, Address Ptr
,
574 const CXXDeleteExpr
*expr
,
575 QualType ElementType
, llvm::Value
*&NumElements
,
576 llvm::Value
*&AllocPtr
, CharUnits
&CookieSize
);
578 /// Return whether the given global decl needs a VTT parameter.
579 virtual bool NeedsVTTParameter(GlobalDecl GD
);
582 /// Returns the extra size required in order to store the array
583 /// cookie for the given type. Assumes that an array cookie is
585 virtual CharUnits
getArrayCookieSizeImpl(QualType elementType
);
587 /// Reads the array cookie for an allocation which is known to have one.
588 /// This is called by the standard implementation of ReadArrayCookie.
590 /// \param ptr - a pointer to the allocation made for an array, as a char*
591 /// \param cookieSize - the computed cookie size of an array
593 /// Other parameters are as above.
596 virtual llvm::Value
*readArrayCookieImpl(CodeGenFunction
&IGF
, Address ptr
,
597 CharUnits cookieSize
);
601 /*************************** Static local guards ****************************/
603 /// Emits the guarded initializer and destructor setup for the given
604 /// variable, given that it couldn't be emitted as a constant.
605 /// If \p PerformInit is false, the initialization has been folded to a
606 /// constant and should not be performed.
608 /// The variable may be:
609 /// - a static local variable
610 /// - a static data member of a class template instantiation
611 virtual void EmitGuardedInit(CodeGenFunction
&CGF
, const VarDecl
&D
,
612 llvm::GlobalVariable
*DeclPtr
,
613 bool PerformInit
) = 0;
615 /// Emit code to force the execution of a destructor during global
616 /// teardown. The default implementation of this uses atexit.
618 /// \param Dtor - a function taking a single pointer argument
619 /// \param Addr - a pointer to pass to the destructor function.
620 virtual void registerGlobalDtor(CodeGenFunction
&CGF
, const VarDecl
&D
,
621 llvm::FunctionCallee Dtor
,
622 llvm::Constant
*Addr
) = 0;
624 /*************************** thread_local initialization ********************/
626 /// Emits ABI-required functions necessary to initialize thread_local
627 /// variables in this translation unit.
629 /// \param CXXThreadLocals - The thread_local declarations in this translation
631 /// \param CXXThreadLocalInits - If this translation unit contains any
632 /// non-constant initialization or non-trivial destruction for
633 /// thread_local variables, a list of functions to perform the
635 virtual void EmitThreadLocalInitFuncs(
636 CodeGenModule
&CGM
, ArrayRef
<const VarDecl
*> CXXThreadLocals
,
637 ArrayRef
<llvm::Function
*> CXXThreadLocalInits
,
638 ArrayRef
<const VarDecl
*> CXXThreadLocalInitVars
) = 0;
640 // Determine if references to thread_local global variables can be made
641 // directly or require access through a thread wrapper function.
642 virtual bool usesThreadWrapperFunction(const VarDecl
*VD
) const = 0;
644 /// Emit a reference to a non-local thread_local variable (including
645 /// triggering the initialization of all thread_local variables in its
646 /// translation unit).
647 virtual LValue
EmitThreadLocalVarDeclLValue(CodeGenFunction
&CGF
,
649 QualType LValType
) = 0;
651 /// Emit a single constructor/destructor with the given type from a C++
652 /// constructor Decl.
653 virtual void emitCXXStructor(GlobalDecl GD
) = 0;
655 /// Load a vtable from This, an object of polymorphic type RD, or from one of
656 /// its virtual bases if it does not have its own vtable. Returns the vtable
657 /// and the class from which the vtable was loaded.
658 virtual std::pair
<llvm::Value
*, const CXXRecordDecl
*>
659 LoadVTablePtr(CodeGenFunction
&CGF
, Address This
,
660 const CXXRecordDecl
*RD
) = 0;
663 // Create an instance of a C++ ABI class:
665 /// Creates an Itanium-family ABI.
666 CGCXXABI
*CreateItaniumCXXABI(CodeGenModule
&CGM
);
668 /// Creates a Microsoft-family ABI.
669 CGCXXABI
*CreateMicrosoftCXXABI(CodeGenModule
&CGM
);
671 struct CatchRetScope final
: EHScopeStack::Cleanup
{
672 llvm::CatchPadInst
*CPI
;
674 CatchRetScope(llvm::CatchPadInst
*CPI
) : CPI(CPI
) {}
676 void Emit(CodeGenFunction
&CGF
, Flags flags
) override
{
677 llvm::BasicBlock
*BB
= CGF
.createBasicBlock("catchret.dest");
678 CGF
.Builder
.CreateCatchRet(CPI
, BB
);