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
;
60 Address
getThisAddress(CodeGenFunction
&CGF
) {
63 CGF
.ConvertTypeForMem(CGF
.CXXABIThisDecl
->getType()->getPointeeType()),
64 CGF
.CXXABIThisAlignment
);
67 /// Issue a diagnostic about unsupported features in the ABI.
68 void ErrorUnsupportedABI(CodeGenFunction
&CGF
, StringRef S
);
70 /// Get a null value for unsupported member pointers.
71 llvm::Constant
*GetBogusMemberPointer(QualType T
);
73 ImplicitParamDecl
*&getStructorImplicitParamDecl(CodeGenFunction
&CGF
) {
74 return CGF
.CXXStructorImplicitParamDecl
;
76 llvm::Value
*&getStructorImplicitParamValue(CodeGenFunction
&CGF
) {
77 return CGF
.CXXStructorImplicitParamValue
;
80 /// Loads the incoming C++ this pointer as it was passed by the caller.
81 llvm::Value
*loadIncomingCXXThis(CodeGenFunction
&CGF
);
83 void setCXXABIThisValue(CodeGenFunction
&CGF
, llvm::Value
*ThisPtr
);
85 ASTContext
&getContext() const { return CGM
.getContext(); }
87 bool mayNeedDestruction(const VarDecl
*VD
) const;
89 /// Determine whether we will definitely emit this variable with a constant
90 /// initializer, either because the language semantics demand it or because
91 /// we know that the initializer is a constant.
92 // For weak definitions, any initializer available in the current translation
93 // is not necessarily reflective of the initializer used; such initializers
94 // are ignored unless if InspectInitForWeakDef is true.
96 isEmittedWithConstantInitializer(const VarDecl
*VD
,
97 bool InspectInitForWeakDef
= false) const;
99 virtual bool requiresArrayCookie(const CXXDeleteExpr
*E
, QualType eltType
);
100 virtual bool requiresArrayCookie(const CXXNewExpr
*E
);
102 /// Determine whether there's something special about the rules of
103 /// the ABI tell us that 'this' is a complete object within the
104 /// given function. Obvious common logic like being defined on a
105 /// final class will have been taken care of by the caller.
106 virtual bool isThisCompleteObject(GlobalDecl GD
) const = 0;
108 virtual bool constructorsAndDestructorsReturnThis() const {
109 return CGM
.getCodeGenOpts().CtorDtorReturnThis
;
116 /// Gets the mangle context.
117 MangleContext
&getMangleContext() {
121 /// Returns true if the given constructor or destructor is one of the
122 /// kinds that the ABI says returns 'this' (only applies when called
123 /// non-virtually for destructors).
125 /// There currently is no way to indicate if a destructor returns 'this'
126 /// when called virtually, and code generation does not support the case.
127 virtual bool HasThisReturn(GlobalDecl GD
) const {
128 if (isa
<CXXConstructorDecl
>(GD
.getDecl()) ||
129 (isa
<CXXDestructorDecl
>(GD
.getDecl()) &&
130 GD
.getDtorType() != Dtor_Deleting
))
131 return constructorsAndDestructorsReturnThis();
135 virtual bool hasMostDerivedReturn(GlobalDecl GD
) const { return false; }
137 virtual bool useSinitAndSterm() const { return false; }
139 /// Returns true if the target allows calling a function through a pointer
140 /// with a different signature than the actual function (or equivalently,
141 /// bitcasting a function or function pointer to a different function type).
142 /// In principle in the most general case this could depend on the target, the
143 /// calling convention, and the actual types of the arguments and return
144 /// value. Here it just means whether the signature mismatch could *ever* be
145 /// allowed; in other words, does the target do strict checking of signatures
147 virtual bool canCallMismatchedFunctionType() const { return true; }
149 /// If the C++ ABI requires the given type be returned in a particular way,
150 /// this method sets RetAI and returns true.
151 virtual bool classifyReturnType(CGFunctionInfo
&FI
) const = 0;
153 /// Specify how one should pass an argument of a record type.
155 /// Pass it using the normal C aggregate rules for the ABI, potentially
156 /// introducing extra copies and passing some or all of it in registers.
159 /// Pass it on the stack using its defined layout. The argument must be
160 /// evaluated directly into the correct stack position in the arguments area,
161 /// and the call machinery must not move it or introduce extra copies.
164 /// Pass it as a pointer to temporary memory.
168 /// Returns how an argument of the given record type should be passed.
169 virtual RecordArgABI
getRecordArgABI(const CXXRecordDecl
*RD
) const = 0;
171 /// Returns true if the implicit 'sret' parameter comes after the implicit
172 /// 'this' parameter of C++ instance methods.
173 virtual bool isSRetParameterAfterThis() const { return false; }
175 /// Returns true if the ABI permits the argument to be a homogeneous
178 isPermittedToBeHomogeneousAggregate(const CXXRecordDecl
*RD
) const {
182 /// Find the LLVM type used to represent the given member pointer
185 ConvertMemberPointerType(const MemberPointerType
*MPT
);
187 /// Load a member function from an object and a member function
188 /// pointer. Apply the this-adjustment and set 'This' to the
190 virtual CGCallee
EmitLoadOfMemberFunctionPointer(
191 CodeGenFunction
&CGF
, const Expr
*E
, Address This
,
192 llvm::Value
*&ThisPtrForCall
, llvm::Value
*MemPtr
,
193 const MemberPointerType
*MPT
);
195 /// Calculate an l-value from an object and a data member pointer.
196 virtual llvm::Value
*
197 EmitMemberDataPointerAddress(CodeGenFunction
&CGF
, const Expr
*E
,
198 Address Base
, llvm::Value
*MemPtr
,
199 const MemberPointerType
*MPT
);
201 /// Perform a derived-to-base, base-to-derived, or bitcast member
202 /// pointer conversion.
203 virtual llvm::Value
*EmitMemberPointerConversion(CodeGenFunction
&CGF
,
207 /// Perform a derived-to-base, base-to-derived, or bitcast member
208 /// pointer conversion on a constant value.
209 virtual llvm::Constant
*EmitMemberPointerConversion(const CastExpr
*E
,
210 llvm::Constant
*Src
);
212 /// Return true if the given member pointer can be zero-initialized
213 /// (in the C++ sense) with an LLVM zeroinitializer.
214 virtual bool isZeroInitializable(const MemberPointerType
*MPT
);
216 /// Return whether or not a member pointers type is convertible to an IR type.
217 virtual bool isMemberPointerConvertible(const MemberPointerType
*MPT
) const {
221 /// Create a null member pointer of the given type.
222 virtual llvm::Constant
*EmitNullMemberPointer(const MemberPointerType
*MPT
);
224 /// Create a member pointer for the given method.
225 virtual llvm::Constant
*EmitMemberFunctionPointer(const CXXMethodDecl
*MD
);
227 /// Create a member pointer for the given field.
228 virtual llvm::Constant
*EmitMemberDataPointer(const MemberPointerType
*MPT
,
231 /// Create a member pointer for the given member pointer constant.
232 virtual llvm::Constant
*EmitMemberPointer(const APValue
&MP
, QualType MPT
);
234 /// Emit a comparison between two member pointers. Returns an i1.
235 virtual llvm::Value
*
236 EmitMemberPointerComparison(CodeGenFunction
&CGF
,
239 const MemberPointerType
*MPT
,
242 /// Determine if a member pointer is non-null. Returns an i1.
243 virtual llvm::Value
*
244 EmitMemberPointerIsNotNull(CodeGenFunction
&CGF
,
246 const MemberPointerType
*MPT
);
249 /// A utility method for computing the offset required for the given
250 /// base-to-derived or derived-to-base member-pointer conversion.
251 /// Does not handle virtual conversions (in case we ever fully
252 /// support an ABI that allows this). Returns null if no adjustment
254 llvm::Constant
*getMemberPointerAdjustment(const CastExpr
*E
);
257 virtual void emitVirtualObjectDelete(CodeGenFunction
&CGF
,
258 const CXXDeleteExpr
*DE
,
259 Address Ptr
, QualType ElementType
,
260 const CXXDestructorDecl
*Dtor
) = 0;
261 virtual void emitRethrow(CodeGenFunction
&CGF
, bool isNoReturn
) = 0;
262 virtual void emitThrow(CodeGenFunction
&CGF
, const CXXThrowExpr
*E
) = 0;
263 virtual llvm::GlobalVariable
*getThrowInfo(QualType T
) { return nullptr; }
265 /// Determine whether it's possible to emit a vtable for \p RD, even
266 /// though we do not know that the vtable has been marked as used by semantic
268 virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl
*RD
) const = 0;
270 virtual void emitBeginCatch(CodeGenFunction
&CGF
, const CXXCatchStmt
*C
) = 0;
272 virtual llvm::CallInst
*
273 emitTerminateForUnexpectedException(CodeGenFunction
&CGF
,
276 virtual llvm::Constant
*getAddrOfRTTIDescriptor(QualType Ty
) = 0;
277 virtual CatchTypeInfo
278 getAddrOfCXXCatchHandlerType(QualType Ty
, QualType CatchHandlerType
) = 0;
279 virtual CatchTypeInfo
getCatchAllTypeInfo();
281 virtual bool shouldTypeidBeNullChecked(bool IsDeref
,
282 QualType SrcRecordTy
) = 0;
283 virtual void EmitBadTypeidCall(CodeGenFunction
&CGF
) = 0;
284 virtual llvm::Value
*EmitTypeid(CodeGenFunction
&CGF
, QualType SrcRecordTy
,
286 llvm::Type
*StdTypeInfoPtrTy
) = 0;
288 virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr
,
289 QualType SrcRecordTy
) = 0;
290 virtual bool shouldEmitExactDynamicCast(QualType DestRecordTy
) = 0;
292 virtual llvm::Value
*emitDynamicCastCall(CodeGenFunction
&CGF
, Address Value
,
293 QualType SrcRecordTy
,
295 QualType DestRecordTy
,
296 llvm::BasicBlock
*CastEnd
) = 0;
298 virtual llvm::Value
*emitDynamicCastToVoid(CodeGenFunction
&CGF
,
300 QualType SrcRecordTy
) = 0;
302 /// Emit a dynamic_cast from SrcRecordTy to DestRecordTy. The cast fails if
303 /// the dynamic type of Value is not exactly DestRecordTy.
304 virtual llvm::Value
*emitExactDynamicCast(CodeGenFunction
&CGF
, Address Value
,
305 QualType SrcRecordTy
,
307 QualType DestRecordTy
,
308 llvm::BasicBlock
*CastSuccess
,
309 llvm::BasicBlock
*CastFail
) = 0;
311 virtual bool EmitBadCastCall(CodeGenFunction
&CGF
) = 0;
313 virtual llvm::Value
*GetVirtualBaseClassOffset(CodeGenFunction
&CGF
,
315 const CXXRecordDecl
*ClassDecl
,
316 const CXXRecordDecl
*BaseClassDecl
) = 0;
318 virtual llvm::BasicBlock
*EmitCtorCompleteObjectHandler(CodeGenFunction
&CGF
,
319 const CXXRecordDecl
*RD
);
321 /// Emit the code to initialize hidden members required
322 /// to handle virtual inheritance, if needed by the ABI.
324 initializeHiddenVirtualInheritanceMembers(CodeGenFunction
&CGF
,
325 const CXXRecordDecl
*RD
) {}
327 /// Emit constructor variants required by this ABI.
328 virtual void EmitCXXConstructors(const CXXConstructorDecl
*D
) = 0;
330 /// Additional implicit arguments to add to the beginning (Prefix) and end
331 /// (Suffix) of a constructor / destructor arg list.
333 /// Note that Prefix should actually be inserted *after* the first existing
334 /// arg; `this` arguments always come first.
335 struct AddedStructorArgs
{
340 SmallVector
<Arg
, 1> Prefix
;
341 SmallVector
<Arg
, 1> Suffix
;
342 AddedStructorArgs() = default;
343 AddedStructorArgs(SmallVector
<Arg
, 1> P
, SmallVector
<Arg
, 1> S
)
344 : Prefix(std::move(P
)), Suffix(std::move(S
)) {}
345 static AddedStructorArgs
prefix(SmallVector
<Arg
, 1> Args
) {
346 return {std::move(Args
), {}};
348 static AddedStructorArgs
suffix(SmallVector
<Arg
, 1> Args
) {
349 return {{}, std::move(Args
)};
353 /// Similar to AddedStructorArgs, but only notes the number of additional
355 struct AddedStructorArgCounts
{
358 AddedStructorArgCounts() = default;
359 AddedStructorArgCounts(unsigned P
, unsigned S
) : Prefix(P
), Suffix(S
) {}
360 static AddedStructorArgCounts
prefix(unsigned N
) { return {N
, 0}; }
361 static AddedStructorArgCounts
suffix(unsigned N
) { return {0, N
}; }
364 /// Build the signature of the given constructor or destructor variant by
365 /// adding any required parameters. For convenience, ArgTys has been
366 /// initialized with the type of 'this'.
367 virtual AddedStructorArgCounts
368 buildStructorSignature(GlobalDecl GD
,
369 SmallVectorImpl
<CanQualType
> &ArgTys
) = 0;
371 /// Returns true if the given destructor type should be emitted as a linkonce
372 /// delegating thunk, regardless of whether the dtor is defined in this TU or
374 virtual bool useThunkForDtorVariant(const CXXDestructorDecl
*Dtor
,
375 CXXDtorType DT
) const = 0;
377 virtual void setCXXDestructorDLLStorage(llvm::GlobalValue
*GV
,
378 const CXXDestructorDecl
*Dtor
,
379 CXXDtorType DT
) const;
381 virtual llvm::GlobalValue::LinkageTypes
382 getCXXDestructorLinkage(GVALinkage Linkage
, const CXXDestructorDecl
*Dtor
,
383 CXXDtorType DT
) const;
385 /// Emit destructor variants required by this ABI.
386 virtual void EmitCXXDestructors(const CXXDestructorDecl
*D
) = 0;
388 /// Get the type of the implicit "this" parameter used by a method. May return
389 /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
390 /// parameter to point to some artificial offset in a complete object due to
391 /// vbases being reordered.
392 virtual const CXXRecordDecl
*getThisArgumentTypeForMethod(GlobalDecl GD
) {
393 return cast
<CXXMethodDecl
>(GD
.getDecl())->getParent();
396 /// Perform ABI-specific "this" argument adjustment required prior to
397 /// a call of a virtual function.
398 /// The "VirtualCall" argument is true iff the call itself is virtual.
400 adjustThisArgumentForVirtualFunctionCall(CodeGenFunction
&CGF
, GlobalDecl GD
,
401 Address This
, bool VirtualCall
) {
405 /// Build a parameter variable suitable for 'this'.
406 void buildThisParam(CodeGenFunction
&CGF
, FunctionArgList
&Params
);
408 /// Insert any ABI-specific implicit parameters into the parameter list for a
409 /// function. This generally involves extra data for constructors and
412 /// ABIs may also choose to override the return type, which has been
413 /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
414 /// the formal return type of the function otherwise.
415 virtual void addImplicitStructorParams(CodeGenFunction
&CGF
, QualType
&ResTy
,
416 FunctionArgList
&Params
) = 0;
418 /// Get the ABI-specific "this" parameter adjustment to apply in the prologue
419 /// of a virtual function.
420 virtual CharUnits
getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD
) {
421 return CharUnits::Zero();
424 /// Emit the ABI-specific prolog for the function.
425 virtual void EmitInstanceFunctionProlog(CodeGenFunction
&CGF
) = 0;
427 virtual AddedStructorArgs
428 getImplicitConstructorArgs(CodeGenFunction
&CGF
, const CXXConstructorDecl
*D
,
429 CXXCtorType Type
, bool ForVirtualBase
,
430 bool Delegating
) = 0;
432 /// Add any ABI-specific implicit arguments needed to call a constructor.
434 /// \return The number of arguments added at the beginning and end of the
435 /// call, which is typically zero or one.
436 AddedStructorArgCounts
437 addImplicitConstructorArgs(CodeGenFunction
&CGF
, const CXXConstructorDecl
*D
,
438 CXXCtorType Type
, bool ForVirtualBase
,
439 bool Delegating
, CallArgList
&Args
);
441 /// Get the implicit (second) parameter that comes after the "this" pointer,
442 /// or nullptr if there is isn't one.
443 virtual llvm::Value
*
444 getCXXDestructorImplicitParam(CodeGenFunction
&CGF
,
445 const CXXDestructorDecl
*DD
, CXXDtorType Type
,
446 bool ForVirtualBase
, bool Delegating
) = 0;
448 /// Emit the destructor call.
449 virtual void EmitDestructorCall(CodeGenFunction
&CGF
,
450 const CXXDestructorDecl
*DD
, CXXDtorType Type
,
451 bool ForVirtualBase
, bool Delegating
,
452 Address This
, QualType ThisTy
) = 0;
454 /// Emits the VTable definitions required for the given record type.
455 virtual void emitVTableDefinitions(CodeGenVTables
&CGVT
,
456 const CXXRecordDecl
*RD
) = 0;
458 /// Checks if ABI requires extra virtual offset for vtable field.
460 isVirtualOffsetNeededForVTableField(CodeGenFunction
&CGF
,
461 CodeGenFunction::VPtr Vptr
) = 0;
463 /// Checks if ABI requires to initialize vptrs for given dynamic class.
464 virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl
*VTableClass
) = 0;
466 /// Get the address point of the vtable for the given base subobject.
467 virtual llvm::Constant
*
468 getVTableAddressPoint(BaseSubobject Base
,
469 const CXXRecordDecl
*VTableClass
) = 0;
471 /// Get the address point of the vtable for the given base subobject while
472 /// building a constructor or a destructor.
473 virtual llvm::Value
*
474 getVTableAddressPointInStructor(CodeGenFunction
&CGF
, const CXXRecordDecl
*RD
,
476 const CXXRecordDecl
*NearestVBase
) = 0;
478 /// Get the address point of the vtable for the given base subobject while
479 /// building a constexpr.
480 virtual llvm::Constant
*
481 getVTableAddressPointForConstExpr(BaseSubobject Base
,
482 const CXXRecordDecl
*VTableClass
) = 0;
484 /// Get the address of the vtable for the given record decl which should be
485 /// used for the vptr at the given offset in RD.
486 virtual llvm::GlobalVariable
*getAddrOfVTable(const CXXRecordDecl
*RD
,
487 CharUnits VPtrOffset
) = 0;
489 /// Build a virtual function pointer in the ABI-specific way.
490 virtual CGCallee
getVirtualFunctionPointer(CodeGenFunction
&CGF
,
491 GlobalDecl GD
, Address This
,
493 SourceLocation Loc
) = 0;
495 using DeleteOrMemberCallExpr
=
496 llvm::PointerUnion
<const CXXDeleteExpr
*, const CXXMemberCallExpr
*>;
498 /// Emit the ABI-specific virtual destructor call.
499 virtual llvm::Value
*EmitVirtualDestructorCall(CodeGenFunction
&CGF
,
500 const CXXDestructorDecl
*Dtor
,
501 CXXDtorType DtorType
,
503 DeleteOrMemberCallExpr E
) = 0;
505 virtual void adjustCallArgsForDestructorThunk(CodeGenFunction
&CGF
,
507 CallArgList
&CallArgs
) {}
509 /// Emit any tables needed to implement virtual inheritance. For Itanium,
510 /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
512 virtual void emitVirtualInheritanceTables(const CXXRecordDecl
*RD
) = 0;
514 virtual bool exportThunk() = 0;
515 virtual void setThunkLinkage(llvm::Function
*Thunk
, bool ForVTable
,
516 GlobalDecl GD
, bool ReturnAdjustment
) = 0;
518 virtual llvm::Value
*performThisAdjustment(CodeGenFunction
&CGF
,
520 const ThisAdjustment
&TA
) = 0;
522 virtual llvm::Value
*performReturnAdjustment(CodeGenFunction
&CGF
,
524 const ReturnAdjustment
&RA
) = 0;
526 virtual void EmitReturnFromThunk(CodeGenFunction
&CGF
,
527 RValue RV
, QualType ResultType
);
529 virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl
*,
530 FunctionArgList
&Args
) const = 0;
532 /// Gets the offsets of all the virtual base pointers in a given class.
533 virtual std::vector
<CharUnits
> getVBPtrOffsets(const CXXRecordDecl
*RD
);
535 /// Gets the pure virtual member call function.
536 virtual StringRef
GetPureVirtualCallName() = 0;
538 /// Gets the deleted virtual member call name.
539 virtual StringRef
GetDeletedVirtualCallName() = 0;
541 /**************************** Array cookies ******************************/
543 /// Returns the extra size required in order to store the array
544 /// cookie for the given new-expression. May return 0 to indicate that no
545 /// array cookie is required.
547 /// Several cases are filtered out before this method is called:
548 /// - non-array allocations never need a cookie
549 /// - calls to \::operator new(size_t, void*) never need a cookie
551 /// \param expr - the new-expression being allocated.
552 virtual CharUnits
GetArrayCookieSize(const CXXNewExpr
*expr
);
554 /// Initialize the array cookie for the given allocation.
556 /// \param NewPtr - a char* which is the presumed-non-null
557 /// return value of the allocation function
558 /// \param NumElements - the computed number of elements,
559 /// potentially collapsed from the multidimensional array case;
561 /// \param ElementType - the base element allocated type,
562 /// i.e. the allocated type after stripping all array types
563 virtual Address
InitializeArrayCookie(CodeGenFunction
&CGF
,
565 llvm::Value
*NumElements
,
566 const CXXNewExpr
*expr
,
567 QualType ElementType
);
569 /// Reads the array cookie associated with the given pointer,
572 /// \param Ptr - a pointer to the first element in the array
573 /// \param ElementType - the base element type of elements of the array
574 /// \param NumElements - an out parameter which will be initialized
575 /// with the number of elements allocated, or zero if there is no
577 /// \param AllocPtr - an out parameter which will be initialized
578 /// with a char* pointing to the address returned by the allocation
580 /// \param CookieSize - an out parameter which will be initialized
581 /// with the size of the cookie, or zero if there is no cookie
582 virtual void ReadArrayCookie(CodeGenFunction
&CGF
, Address Ptr
,
583 const CXXDeleteExpr
*expr
,
584 QualType ElementType
, llvm::Value
*&NumElements
,
585 llvm::Value
*&AllocPtr
, CharUnits
&CookieSize
);
587 /// Return whether the given global decl needs a VTT parameter.
588 virtual bool NeedsVTTParameter(GlobalDecl GD
);
591 /// Returns the extra size required in order to store the array
592 /// cookie for the given type. Assumes that an array cookie is
594 virtual CharUnits
getArrayCookieSizeImpl(QualType elementType
);
596 /// Reads the array cookie for an allocation which is known to have one.
597 /// This is called by the standard implementation of ReadArrayCookie.
599 /// \param ptr - a pointer to the allocation made for an array, as a char*
600 /// \param cookieSize - the computed cookie size of an array
602 /// Other parameters are as above.
605 virtual llvm::Value
*readArrayCookieImpl(CodeGenFunction
&IGF
, Address ptr
,
606 CharUnits cookieSize
);
610 /*************************** Static local guards ****************************/
612 /// Emits the guarded initializer and destructor setup for the given
613 /// variable, given that it couldn't be emitted as a constant.
614 /// If \p PerformInit is false, the initialization has been folded to a
615 /// constant and should not be performed.
617 /// The variable may be:
618 /// - a static local variable
619 /// - a static data member of a class template instantiation
620 virtual void EmitGuardedInit(CodeGenFunction
&CGF
, const VarDecl
&D
,
621 llvm::GlobalVariable
*DeclPtr
,
622 bool PerformInit
) = 0;
624 /// Emit code to force the execution of a destructor during global
625 /// teardown. The default implementation of this uses atexit.
627 /// \param Dtor - a function taking a single pointer argument
628 /// \param Addr - a pointer to pass to the destructor function.
629 virtual void registerGlobalDtor(CodeGenFunction
&CGF
, const VarDecl
&D
,
630 llvm::FunctionCallee Dtor
,
631 llvm::Constant
*Addr
) = 0;
633 /*************************** thread_local initialization ********************/
635 /// Emits ABI-required functions necessary to initialize thread_local
636 /// variables in this translation unit.
638 /// \param CXXThreadLocals - The thread_local declarations in this translation
640 /// \param CXXThreadLocalInits - If this translation unit contains any
641 /// non-constant initialization or non-trivial destruction for
642 /// thread_local variables, a list of functions to perform the
644 virtual void EmitThreadLocalInitFuncs(
645 CodeGenModule
&CGM
, ArrayRef
<const VarDecl
*> CXXThreadLocals
,
646 ArrayRef
<llvm::Function
*> CXXThreadLocalInits
,
647 ArrayRef
<const VarDecl
*> CXXThreadLocalInitVars
) = 0;
649 // Determine if references to thread_local global variables can be made
650 // directly or require access through a thread wrapper function.
651 virtual bool usesThreadWrapperFunction(const VarDecl
*VD
) const = 0;
653 /// Emit a reference to a non-local thread_local variable (including
654 /// triggering the initialization of all thread_local variables in its
655 /// translation unit).
656 virtual LValue
EmitThreadLocalVarDeclLValue(CodeGenFunction
&CGF
,
658 QualType LValType
) = 0;
660 /// Emit a single constructor/destructor with the given type from a C++
661 /// constructor Decl.
662 virtual void emitCXXStructor(GlobalDecl GD
) = 0;
664 /// Load a vtable from This, an object of polymorphic type RD, or from one of
665 /// its virtual bases if it does not have its own vtable. Returns the vtable
666 /// and the class from which the vtable was loaded.
667 virtual std::pair
<llvm::Value
*, const CXXRecordDecl
*>
668 LoadVTablePtr(CodeGenFunction
&CGF
, Address This
,
669 const CXXRecordDecl
*RD
) = 0;
672 // Create an instance of a C++ ABI class:
674 /// Creates an Itanium-family ABI.
675 CGCXXABI
*CreateItaniumCXXABI(CodeGenModule
&CGM
);
677 /// Creates a Microsoft-family ABI.
678 CGCXXABI
*CreateMicrosoftCXXABI(CodeGenModule
&CGM
);
680 struct CatchRetScope final
: EHScopeStack::Cleanup
{
681 llvm::CatchPadInst
*CPI
;
683 CatchRetScope(llvm::CatchPadInst
*CPI
) : CPI(CPI
) {}
685 void Emit(CodeGenFunction
&CGF
, Flags flags
) override
{
686 llvm::BasicBlock
*BB
= CGF
.createBasicBlock("catchret.dest");
687 CGF
.Builder
.CreateCatchRet(CPI
, BB
);