clang  3.7.0
CGCXXABI.h
Go to the documentation of this file.
1 //===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides an abstract class for C++ code generation. Concrete subclasses
11 // of this implement code generation for specific C++ ABIs.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
17 
18 #include "CodeGenFunction.h"
19 #include "clang/Basic/LLVM.h"
20 
21 namespace llvm {
22 class Constant;
23 class Type;
24 class Value;
25 class CallInst;
26 }
27 
28 namespace clang {
29 class CastExpr;
30 class CXXConstructorDecl;
31 class CXXDestructorDecl;
32 class CXXMethodDecl;
33 class CXXRecordDecl;
34 class FieldDecl;
35 class MangleContext;
36 
37 namespace CodeGen {
38 class CodeGenFunction;
39 class CodeGenModule;
40 
41 /// \brief Implements C++ ABI-specific code generation functions.
42 class CGCXXABI {
43 protected:
45  std::unique_ptr<MangleContext> MangleCtx;
46 
48  : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
49 
50 protected:
52  return CGF.CXXABIThisDecl;
53  }
55  return CGF.CXXABIThisValue;
56  }
57 
58  /// Issue a diagnostic about unsupported features in the ABI.
59  void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
60 
61  /// Get a null value for unsupported member pointers.
62  llvm::Constant *GetBogusMemberPointer(QualType T);
63 
65  return CGF.CXXStructorImplicitParamDecl;
66  }
68  return CGF.CXXStructorImplicitParamValue;
69  }
70 
71  /// Perform prolog initialization of the parameter variable suitable
72  /// for 'this' emitted by buildThisParam.
73  void EmitThisParam(CodeGenFunction &CGF);
74 
75  ASTContext &getContext() const { return CGM.getContext(); }
76 
77  virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
78  virtual bool requiresArrayCookie(const CXXNewExpr *E);
79 
80 public:
81 
82  virtual ~CGCXXABI();
83 
84  /// Gets the mangle context.
86  return *MangleCtx;
87  }
88 
89  /// Returns true if the given constructor or destructor is one of the
90  /// kinds that the ABI says returns 'this' (only applies when called
91  /// non-virtually for destructors).
92  ///
93  /// There currently is no way to indicate if a destructor returns 'this'
94  /// when called virtually, and code generation does not support the case.
95  virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
96 
97  virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
98 
99  /// If the C++ ABI requires the given type be returned in a particular way,
100  /// this method sets RetAI and returns true.
101  virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0;
102 
103  /// Specify how one should pass an argument of a record type.
105  /// Pass it using the normal C aggregate rules for the ABI, potentially
106  /// introducing extra copies and passing some or all of it in registers.
108 
109  /// Pass it on the stack using its defined layout. The argument must be
110  /// evaluated directly into the correct stack position in the arguments area,
111  /// and the call machinery must not move it or introduce extra copies.
113 
114  /// Pass it as a pointer to temporary memory.
116  };
117 
118  /// Returns true if C++ allows us to copy the memory of an object of type RD
119  /// when it is passed as an argument.
120  bool canCopyArgument(const CXXRecordDecl *RD) const;
121 
122  /// Returns how an argument of the given record type should be passed.
123  virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
124 
125  /// Returns true if the implicit 'sret' parameter comes after the implicit
126  /// 'this' parameter of C++ instance methods.
127  virtual bool isSRetParameterAfterThis() const { return false; }
128 
129  /// Find the LLVM type used to represent the given member pointer
130  /// type.
131  virtual llvm::Type *
133 
134  /// Load a member function from an object and a member function
135  /// pointer. Apply the this-adjustment and set 'This' to the
136  /// adjusted value.
138  CodeGenFunction &CGF, const Expr *E, llvm::Value *&This,
139  llvm::Value *MemPtr, const MemberPointerType *MPT);
140 
141  /// Calculate an l-value from an object and a data member pointer.
142  virtual llvm::Value *
144  llvm::Value *Base, llvm::Value *MemPtr,
145  const MemberPointerType *MPT);
146 
147  /// Perform a derived-to-base, base-to-derived, or bitcast member
148  /// pointer conversion.
150  const CastExpr *E,
151  llvm::Value *Src);
152 
153  /// Perform a derived-to-base, base-to-derived, or bitcast member
154  /// pointer conversion on a constant value.
155  virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
156  llvm::Constant *Src);
157 
158  /// Return true if the given member pointer can be zero-initialized
159  /// (in the C++ sense) with an LLVM zeroinitializer.
160  virtual bool isZeroInitializable(const MemberPointerType *MPT);
161 
162  /// Return whether or not a member pointers type is convertible to an IR type.
163  virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
164  return true;
165  }
166 
167  virtual bool isTypeInfoCalculable(QualType Ty) const {
168  return !Ty->isIncompleteType();
169  }
170 
171  /// Create a null member pointer of the given type.
172  virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
173 
174  /// Create a member pointer for the given method.
175  virtual llvm::Constant *EmitMemberFunctionPointer(const CXXMethodDecl *MD);
176 
177  /// Create a member pointer for the given field.
178  virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
179  CharUnits offset);
180 
181  /// Create a member pointer for the given member pointer constant.
182  virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
183 
184  /// Emit a comparison between two member pointers. Returns an i1.
185  virtual llvm::Value *
187  llvm::Value *L,
188  llvm::Value *R,
189  const MemberPointerType *MPT,
190  bool Inequality);
191 
192  /// Determine if a member pointer is non-null. Returns an i1.
193  virtual llvm::Value *
195  llvm::Value *MemPtr,
196  const MemberPointerType *MPT);
197 
198 protected:
199  /// A utility method for computing the offset required for the given
200  /// base-to-derived or derived-to-base member-pointer conversion.
201  /// Does not handle virtual conversions (in case we ever fully
202  /// support an ABI that allows this). Returns null if no adjustment
203  /// is required.
204  llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
205 
206  /// \brief Computes the non-virtual adjustment needed for a member pointer
207  /// conversion along an inheritance path stored in an APValue. Unlike
208  /// getMemberPointerAdjustment(), the adjustment can be negative if the path
209  /// is from a derived type to a base type.
211 
212 public:
213  virtual void emitVirtualObjectDelete(CodeGenFunction &CGF,
214  const CXXDeleteExpr *DE,
215  llvm::Value *Ptr, QualType ElementType,
216  const CXXDestructorDecl *Dtor) = 0;
217  virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0;
218  virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
219  virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
220 
221  virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
222 
223  virtual llvm::CallInst *
225  llvm::Value *Exn);
226 
227  virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
228  virtual llvm::Constant *
229  getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0;
230 
231  virtual bool shouldTypeidBeNullChecked(bool IsDeref,
232  QualType SrcRecordTy) = 0;
233  virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
234  virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
235  llvm::Value *ThisPtr,
236  llvm::Type *StdTypeInfoPtrTy) = 0;
237 
238  virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
239  QualType SrcRecordTy) = 0;
240 
241  virtual llvm::Value *
243  QualType SrcRecordTy, QualType DestTy,
244  QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
245 
248  QualType SrcRecordTy,
249  QualType DestTy) = 0;
250 
251  virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
252 
254  llvm::Value *This,
255  const CXXRecordDecl *ClassDecl,
256  const CXXRecordDecl *BaseClassDecl) = 0;
257 
258  virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
259  const CXXRecordDecl *RD);
260 
261  /// Emit the code to initialize hidden members required
262  /// to handle virtual inheritance, if needed by the ABI.
263  virtual void
265  const CXXRecordDecl *RD) {}
266 
267  /// Emit constructor variants required by this ABI.
268  virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
269 
270  /// Build the signature of the given constructor or destructor variant by
271  /// adding any required parameters. For convenience, ArgTys has been
272  /// initialized with the type of 'this'.
273  virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
274  SmallVectorImpl<CanQualType> &ArgTys) = 0;
275 
276  /// Returns true if the given destructor type should be emitted as a linkonce
277  /// delegating thunk, regardless of whether the dtor is defined in this TU or
278  /// not.
279  virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
280  CXXDtorType DT) const = 0;
281 
282  /// Emit destructor variants required by this ABI.
283  virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
284 
285  /// Get the type of the implicit "this" parameter used by a method. May return
286  /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
287  /// parameter to point to some artificial offset in a complete object due to
288  /// vbases being reordered.
289  virtual const CXXRecordDecl *
291  return MD->getParent();
292  }
293 
294  /// Perform ABI-specific "this" argument adjustment required prior to
295  /// a call of a virtual function.
296  /// The "VirtualCall" argument is true iff the call itself is virtual.
297  virtual llvm::Value *
299  llvm::Value *This,
300  bool VirtualCall) {
301  return This;
302  }
303 
304  /// Build a parameter variable suitable for 'this'.
305  void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
306 
307  /// Insert any ABI-specific implicit parameters into the parameter list for a
308  /// function. This generally involves extra data for constructors and
309  /// destructors.
310  ///
311  /// ABIs may also choose to override the return type, which has been
312  /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
313  /// the formal return type of the function otherwise.
314  virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
315  FunctionArgList &Params) = 0;
316 
317  /// Perform ABI-specific "this" parameter adjustment in a virtual function
318  /// prologue.
320  CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
321  return This;
322  }
323 
324  /// Emit the ABI-specific prolog for the function.
325  virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
326 
327  /// Add any ABI-specific implicit arguments needed to call a constructor.
328  ///
329  /// \return The number of args added to the call, which is typically zero or
330  /// one.
331  virtual unsigned
333  CXXCtorType Type, bool ForVirtualBase,
334  bool Delegating, CallArgList &Args) = 0;
335 
336  /// Emit the destructor call.
337  virtual void EmitDestructorCall(CodeGenFunction &CGF,
339  bool ForVirtualBase, bool Delegating,
340  llvm::Value *This) = 0;
341 
342  /// Emits the VTable definitions required for the given record type.
343  virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
344  const CXXRecordDecl *RD) = 0;
345 
346  /// Get the address point of the vtable for the given base subobject while
347  /// building a constructor or a destructor. On return, NeedsVirtualOffset
348  /// tells if a virtual base adjustment is needed in order to get the offset
349  /// of the base subobject.
352  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
353 
354  /// Get the address point of the vtable for the given base subobject while
355  /// building a constexpr.
356  virtual llvm::Constant *
358  const CXXRecordDecl *VTableClass) = 0;
359 
360  /// Get the address of the vtable for the given record decl which should be
361  /// used for the vptr at the given offset in RD.
362  virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
363  CharUnits VPtrOffset) = 0;
364 
365  /// Build a virtual function pointer in the ABI-specific way.
367  GlobalDecl GD,
368  llvm::Value *This,
369  llvm::Type *Ty,
370  SourceLocation Loc) = 0;
371 
372  /// Emit the ABI-specific virtual destructor call.
373  virtual llvm::Value *
375  CXXDtorType DtorType, llvm::Value *This,
376  const CXXMemberCallExpr *CE) = 0;
377 
379  GlobalDecl GD,
380  CallArgList &CallArgs) {}
381 
382  /// Emit any tables needed to implement virtual inheritance. For Itanium,
383  /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
384  /// base tables.
385  virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
386 
387  virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
388  GlobalDecl GD, bool ReturnAdjustment) = 0;
389 
391  llvm::Value *This,
392  const ThisAdjustment &TA) = 0;
393 
395  llvm::Value *Ret,
396  const ReturnAdjustment &RA) = 0;
397 
398  virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
399  RValue RV, QualType ResultType);
400 
401  virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
402  FunctionArgList &Args) const = 0;
403 
404  /// Gets the pure virtual member call function.
405  virtual StringRef GetPureVirtualCallName() = 0;
406 
407  /// Gets the deleted virtual member call name.
408  virtual StringRef GetDeletedVirtualCallName() = 0;
409 
410  /**************************** Array cookies ******************************/
411 
412  /// Returns the extra size required in order to store the array
413  /// cookie for the given new-expression. May return 0 to indicate that no
414  /// array cookie is required.
415  ///
416  /// Several cases are filtered out before this method is called:
417  /// - non-array allocations never need a cookie
418  /// - calls to \::operator new(size_t, void*) never need a cookie
419  ///
420  /// \param expr - the new-expression being allocated.
422 
423  /// Initialize the array cookie for the given allocation.
424  ///
425  /// \param NewPtr - a char* which is the presumed-non-null
426  /// return value of the allocation function
427  /// \param NumElements - the computed number of elements,
428  /// potentially collapsed from the multidimensional array case;
429  /// always a size_t
430  /// \param ElementType - the base element allocated type,
431  /// i.e. the allocated type after stripping all array types
433  llvm::Value *NewPtr,
434  llvm::Value *NumElements,
435  const CXXNewExpr *expr,
436  QualType ElementType);
437 
438  /// Reads the array cookie associated with the given pointer,
439  /// if it has one.
440  ///
441  /// \param Ptr - a pointer to the first element in the array
442  /// \param ElementType - the base element type of elements of the array
443  /// \param NumElements - an out parameter which will be initialized
444  /// with the number of elements allocated, or zero if there is no
445  /// cookie
446  /// \param AllocPtr - an out parameter which will be initialized
447  /// with a char* pointing to the address returned by the allocation
448  /// function
449  /// \param CookieSize - an out parameter which will be initialized
450  /// with the size of the cookie, or zero if there is no cookie
451  virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
452  const CXXDeleteExpr *expr,
453  QualType ElementType, llvm::Value *&NumElements,
454  llvm::Value *&AllocPtr, CharUnits &CookieSize);
455 
456  /// Return whether the given global decl needs a VTT parameter.
457  virtual bool NeedsVTTParameter(GlobalDecl GD);
458 
459 protected:
460  /// Returns the extra size required in order to store the array
461  /// cookie for the given type. Assumes that an array cookie is
462  /// required.
463  virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
464 
465  /// Reads the array cookie for an allocation which is known to have one.
466  /// This is called by the standard implementation of ReadArrayCookie.
467  ///
468  /// \param ptr - a pointer to the allocation made for an array, as a char*
469  /// \param cookieSize - the computed cookie size of an array
470  ///
471  /// Other parameters are as above.
472  ///
473  /// \return a size_t
475  llvm::Value *ptr,
476  CharUnits cookieSize);
477 
478 public:
479 
480  /*************************** Static local guards ****************************/
481 
482  /// Emits the guarded initializer and destructor setup for the given
483  /// variable, given that it couldn't be emitted as a constant.
484  /// If \p PerformInit is false, the initialization has been folded to a
485  /// constant and should not be performed.
486  ///
487  /// The variable may be:
488  /// - a static local variable
489  /// - a static data member of a class template instantiation
490  virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
491  llvm::GlobalVariable *DeclPtr,
492  bool PerformInit) = 0;
493 
494  /// Emit code to force the execution of a destructor during global
495  /// teardown. The default implementation of this uses atexit.
496  ///
497  /// \param Dtor - a function taking a single pointer argument
498  /// \param Addr - a pointer to pass to the destructor function.
499  virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
500  llvm::Constant *Dtor,
501  llvm::Constant *Addr) = 0;
502 
503  /*************************** thread_local initialization ********************/
504 
505  /// Emits ABI-required functions necessary to initialize thread_local
506  /// variables in this translation unit.
507  ///
508  /// \param CXXThreadLocals - The thread_local declarations in this translation
509  /// unit.
510  /// \param CXXThreadLocalInits - If this translation unit contains any
511  /// non-constant initialization or non-trivial destruction for
512  /// thread_local variables, a list of functions to perform the
513  /// initialization.
514  virtual void EmitThreadLocalInitFuncs(
516  ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *>>
517  CXXThreadLocals,
518  ArrayRef<llvm::Function *> CXXThreadLocalInits,
519  ArrayRef<llvm::GlobalVariable *> CXXThreadLocalInitVars) = 0;
520 
521  // Determine if references to thread_local global variables can be made
522  // directly or require access through a thread wrapper function.
523  virtual bool usesThreadWrapperFunction() const = 0;
524 
525  /// Emit a reference to a non-local thread_local variable (including
526  /// triggering the initialization of all thread_local variables in its
527  /// translation unit).
529  const VarDecl *VD,
530  QualType LValType) = 0;
531 
532  /// Emit a single constructor/destructor with the given type from a C++
533  /// constructor Decl.
534  virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
535 };
536 
537 // Create an instance of a C++ ABI class:
538 
539 /// Creates an Itanium-family ABI.
540 CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
541 
542 /// Creates a Microsoft-family ABI.
543 CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
544 
545 }
546 }
547 
548 #endif
virtual llvm::Value * adjustThisParameterInVirtualFunctionPrologue(CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This)
Definition: CGCXXABI.h:319
virtual void EmitBadTypeidCall(CodeGenFunction &CGF)=0
virtual llvm::Constant * EmitMemberPointer(const APValue &MP, QualType MPT)
Create a member pointer for the given member pointer constant.
Definition: CGCXXABI.cpp:143
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, llvm::Value *ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Definition: ASTMatchers.h:1110
virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E)=0
virtual llvm::Value * readArrayCookieImpl(CodeGenFunction &IGF, llvm::Value *ptr, CharUnits cookieSize)
Definition: CGCXXABI.cpp:241
virtual void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResultType)
Definition: CGCXXABI.cpp:173
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, QualType SrcRecordTy)=0
virtual StringRef GetDeletedVirtualCallName()=0
Gets the deleted virtual member call name.
ImplicitParamDecl *& getThisDecl(CodeGenFunction &CGF)
Definition: CGCXXABI.h:51
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2147
virtual llvm::Value * performThisAdjustment(CodeGenFunction &CGF, llvm::Value *This, const ThisAdjustment &TA)=0
llvm::Value *& getStructorImplicitParamValue(CodeGenFunction &CGF)
Definition: CGCXXABI.h:67
virtual llvm::BasicBlock * EmitCtorCompleteObjectHandler(CodeGenFunction &CGF, const CXXRecordDecl *RD)
Definition: CGCXXABI.cpp:292
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, llvm::Value *Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
A this pointer adjustment.
Definition: ABI.h:108
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:808
virtual llvm::Value * performReturnAdjustment(CodeGenFunction &CGF, llvm::Value *Ret, const ReturnAdjustment &RA)=0
void EmitThisParam(CodeGenFunction &CGF)
Definition: CGCXXABI.cpp:165
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
Definition: CGCXXABI.h:97
virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType)
Definition: CGCXXABI.cpp:199
virtual llvm::Constant * getVTableAddressPointForConstExpr(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
virtual llvm::Value * getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base, const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset)=0
A return adjustment.
Definition: ABI.h:42
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
virtual void emitVTableDefinitions(CodeGenVTables &CGVT, const CXXRecordDecl *RD)=0
Emits the VTable definitions required for the given record type.
virtual bool isTypeInfoCalculable(QualType Ty) const
Definition: CGCXXABI.h:167
virtual llvm::Value * getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This, llvm::Type *Ty, SourceLocation Loc)=0
Build a virtual function pointer in the ABI-specific way.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const CXXRecordDecl * getParent() const
Definition: DeclCXX.h:1817
virtual llvm::Value * EmitMemberPointerIsNotNull(CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)
Determine if a member pointer is non-null. Returns an i1.
Definition: CGCXXABI.cpp:121
CodeGenModule & CGM
Definition: CGCXXABI.h:44
bool isIncompleteType(NamedDecl **Def=nullptr) const
Def If non-NULL, and the type refers to some kind of declaration that can be completed (such as a C s...
Definition: Type.cpp:1869
virtual llvm::Type * ConvertMemberPointerType(const MemberPointerType *MPT)
Definition: CGCXXABI.cpp:71
virtual bool isZeroInitializable(const MemberPointerType *MPT)
Definition: CGCXXABI.cpp:147
virtual bool isSRetParameterAfterThis() const
Definition: CGCXXABI.h:127
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)
Definition: CGCXXABI.cpp:178
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType)=0
virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const
Return whether or not a member pointers type is convertible to an IR type.
Definition: CGCXXABI.h:163
ImplicitParamDecl *& getStructorImplicitParamDecl(CodeGenFunction &CGF)
Definition: CGCXXABI.h:64
virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr, const CXXDeleteExpr *expr, QualType ElementType, llvm::Value *&NumElements, llvm::Value *&AllocPtr, CharUnits &CookieSize)
Definition: CGCXXABI.cpp:218
CXXDtorType
C++ destructor types.
Definition: ABI.h:34
virtual void EmitCXXConstructors(const CXXConstructorDecl *D)=0
Emit constructor variants required by this ABI.
virtual llvm::Value * EmitDynamicCastCall(CodeGenFunction &CGF, llvm::Value *Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd)=0
virtual void EmitCXXDestructors(const CXXDestructorDecl *D)=0
Emit destructor variants required by this ABI.
virtual CharUnits getArrayCookieSizeImpl(QualType elementType)
Definition: CGCXXABI.cpp:184
virtual llvm::Constant * getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)=0
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2358
CGCXXABI(CodeGenModule &CGM)
Definition: CGCXXABI.h:47
virtual StringRef GetPureVirtualCallName()=0
Gets the pure virtual member call function.
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)=0
virtual bool classifyReturnType(CGFunctionInfo &FI) const =0
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
ASTContext & getContext() const
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Dtor, llvm::Constant *Addr)=0
virtual llvm::Value * EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, llvm::Value *This, const CXXMemberCallExpr *CE)=0
Emit the ABI-specific virtual destructor call.
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
Definition: CGCXXABI.cpp:133
virtual bool HasThisReturn(GlobalDecl GD) const
Definition: CGCXXABI.h:95
void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S)
Issue a diagnostic about unsupported features in the ABI.
Definition: CGCXXABI.cpp:22
virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD, CallArgList &CallArgs)
Definition: CGCXXABI.h:378
virtual void EmitThreadLocalInitFuncs(CodeGenModule &CGM, ArrayRef< std::pair< const VarDecl *, llvm::GlobalVariable * >> CXXThreadLocals, ArrayRef< llvm::Function * > CXXThreadLocalInits, ArrayRef< llvm::GlobalVariable * > CXXThreadLocalInitVars)=0
Pass it as a pointer to temporary memory.
Definition: CGCXXABI.h:115
virtual unsigned addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, CallArgList &Args)=0
virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn)=0
virtual llvm::Value * EmitMemberPointerConversion(CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)
Definition: CGCXXABI.cpp:98
virtual bool NeedsVTTParameter(GlobalDecl GD)
Return whether the given global decl needs a VTT parameter.
Definition: CGCXXABI.cpp:301
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool canCopyArgument(const CXXRecordDecl *RD) const
Definition: CGCXXABI.cpp:31
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:1623
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1717
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, FunctionArgList &Args) const =0
virtual llvm::Value * EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, const Expr *E, llvm::Value *&This, llvm::Value *MemPtr, const MemberPointerType *MPT)
Definition: CGCXXABI.cpp:75
virtual llvm::Value * GetVirtualBaseClassOffset(CodeGenFunction &CGF, llvm::Value *This, const CXXRecordDecl *ClassDecl, const CXXRecordDecl *BaseClassDecl)=0
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD)=0
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:85
CGCXXABI * CreateMicrosoftCXXABI(CodeGenModule &CGM)
Creates a Microsoft-family ABI.
virtual llvm::Constant * EmitNullMemberPointer(const MemberPointerType *MPT)
Create a null member pointer of the given type.
Definition: CGCXXABI.cpp:129
CXXCtorType
C++ constructor types.
Definition: ABI.h:25
llvm::Constant * getMemberPointerAdjustment(const CastExpr *E)
Definition: CGCXXABI.cpp:251
virtual llvm::Value * EmitMemberPointerComparison(CodeGenFunction &CGF, llvm::Value *L, llvm::Value *R, const MemberPointerType *MPT, bool Inequality)
Emit a comparison between two member pointers. Returns an i1.
Definition: CGCXXABI.cpp:111
Represents a delete expression for memory deallocation and destructor calls, e.g. "delete[] pArray"...
Definition: ExprCXX.h:1819
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T, SmallVectorImpl< CanQualType > &ArgTys)=0
virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type)=0
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
Definition: CGCXXABI.cpp:152
std::unique_ptr< MangleContext > MangleCtx
Definition: CGCXXABI.h:45
virtual void initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF, const CXXRecordDecl *RD)
Definition: CGCXXABI.h:264
virtual llvm::Value * EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, llvm::Value *Base, llvm::Value *MemPtr, const MemberPointerType *MPT)
Calculate an l-value from an object and a data member pointer.
Definition: CGCXXABI.cpp:90
virtual llvm::Constant * getAddrOfRTTIDescriptor(QualType Ty)=0
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:42
virtual bool usesThreadWrapperFunction() const =0
ASTContext & getContext() const
Definition: CGCXXABI.h:75
virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)
Create a member pointer for the given field.
Definition: CGCXXABI.cpp:138
virtual void EmitDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *DD, CXXDtorType Type, bool ForVirtualBase, bool Delegating, llvm::Value *This)=0
Emit the destructor call.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
CGCXXABI * CreateItaniumCXXABI(CodeGenModule &CGM)
Creates an Itanium-family ABI.
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Definition: CGCXXABI.h:290
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
virtual llvm::Value * adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This, bool VirtualCall)
Definition: CGCXXABI.h:298
virtual llvm::CallInst * emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn)
Definition: CGCXXABI.cpp:306
virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor, CXXDtorType DT) const =0
virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C)=0
virtual llvm::GlobalVariable * getThrowInfo(QualType T)
Definition: CGCXXABI.h:219
virtual llvm::Value * EmitDynamicCastToVoid(CodeGenFunction &CGF, llvm::Value *Value, QualType SrcRecordTy, QualType DestTy)=0
virtual llvm::Value * InitializeArrayCookie(CodeGenFunction &CGF, llvm::Value *NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
Definition: CGCXXABI.cpp:189
RecordArgABI
Specify how one should pass an argument of a record type.
Definition: CGCXXABI.h:104
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD, bool ReturnAdjustment)=0
llvm::Value *& getThisValue(CodeGenFunction &CGF)
Definition: CGCXXABI.h:54
llvm::Constant * GetBogusMemberPointer(QualType T)
Get a null value for unsupported member pointers.
Definition: CGCXXABI.cpp:66
CharUnits getMemberPointerPathAdjustment(const APValue &MP)
Computes the non-virtual adjustment needed for a member pointer conversion along an inheritance path ...
Definition: CGCXXABI.cpp:269