clang  3.8.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 struct CatchTypeInfo;
41 
42 /// \brief Implements C++ ABI-specific code generation functions.
43 class CGCXXABI {
44 protected:
46  std::unique_ptr<MangleContext> MangleCtx;
47 
49  : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
50 
51 protected:
53  return CGF.CXXABIThisDecl;
54  }
56  return CGF.CXXABIThisValue;
57  }
59  return Address(CGF.CXXABIThisValue, CGF.CXXABIThisAlignment);
60  }
61 
62  /// Issue a diagnostic about unsupported features in the ABI.
63  void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
64 
65  /// Get a null value for unsupported member pointers.
66  llvm::Constant *GetBogusMemberPointer(QualType T);
67 
69  return CGF.CXXStructorImplicitParamDecl;
70  }
72  return CGF.CXXStructorImplicitParamValue;
73  }
74 
75  /// Perform prolog initialization of the parameter variable suitable
76  /// for 'this' emitted by buildThisParam.
77  void EmitThisParam(CodeGenFunction &CGF);
78 
79  ASTContext &getContext() const { return CGM.getContext(); }
80 
81  virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
82  virtual bool requiresArrayCookie(const CXXNewExpr *E);
83 
84  /// Determine whether there's something special about the rules of
85  /// the ABI tell us that 'this' is a complete object within the
86  /// given function. Obvious common logic like being defined on a
87  /// final class will have been taken care of by the caller.
88  virtual bool isThisCompleteObject(GlobalDecl GD) const = 0;
89 
90 public:
91 
92  virtual ~CGCXXABI();
93 
94  /// Gets the mangle context.
96  return *MangleCtx;
97  }
98 
99  /// Returns true if the given constructor or destructor is one of the
100  /// kinds that the ABI says returns 'this' (only applies when called
101  /// non-virtually for destructors).
102  ///
103  /// There currently is no way to indicate if a destructor returns 'this'
104  /// when called virtually, and code generation does not support the case.
105  virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
106 
107  virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
108 
109  /// If the C++ ABI requires the given type be returned in a particular way,
110  /// this method sets RetAI and returns true.
111  virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0;
112 
113  /// Specify how one should pass an argument of a record type.
115  /// Pass it using the normal C aggregate rules for the ABI, potentially
116  /// introducing extra copies and passing some or all of it in registers.
118 
119  /// Pass it on the stack using its defined layout. The argument must be
120  /// evaluated directly into the correct stack position in the arguments area,
121  /// and the call machinery must not move it or introduce extra copies.
123 
124  /// Pass it as a pointer to temporary memory.
126  };
127 
128  /// Returns true if C++ allows us to copy the memory of an object of type RD
129  /// when it is passed as an argument.
130  bool canCopyArgument(const CXXRecordDecl *RD) const;
131 
132  /// Returns how an argument of the given record type should be passed.
133  virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
134 
135  /// Returns true if the implicit 'sret' parameter comes after the implicit
136  /// 'this' parameter of C++ instance methods.
137  virtual bool isSRetParameterAfterThis() const { return false; }
138 
139  /// Find the LLVM type used to represent the given member pointer
140  /// type.
141  virtual llvm::Type *
143 
144  /// Load a member function from an object and a member function
145  /// pointer. Apply the this-adjustment and set 'This' to the
146  /// adjusted value.
148  CodeGenFunction &CGF, const Expr *E, Address This,
149  llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr,
150  const MemberPointerType *MPT);
151 
152  /// Calculate an l-value from an object and a data member pointer.
153  virtual llvm::Value *
155  Address Base, llvm::Value *MemPtr,
156  const MemberPointerType *MPT);
157 
158  /// Perform a derived-to-base, base-to-derived, or bitcast member
159  /// pointer conversion.
161  const CastExpr *E,
162  llvm::Value *Src);
163 
164  /// Perform a derived-to-base, base-to-derived, or bitcast member
165  /// pointer conversion on a constant value.
166  virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
167  llvm::Constant *Src);
168 
169  /// Return true if the given member pointer can be zero-initialized
170  /// (in the C++ sense) with an LLVM zeroinitializer.
171  virtual bool isZeroInitializable(const MemberPointerType *MPT);
172 
173  /// Return whether or not a member pointers type is convertible to an IR type.
174  virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
175  return true;
176  }
177 
178  /// Create a null member pointer of the given type.
179  virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
180 
181  /// Create a member pointer for the given method.
182  virtual llvm::Constant *EmitMemberFunctionPointer(const CXXMethodDecl *MD);
183 
184  /// Create a member pointer for the given field.
185  virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
186  CharUnits offset);
187 
188  /// Create a member pointer for the given member pointer constant.
189  virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
190 
191  /// Emit a comparison between two member pointers. Returns an i1.
192  virtual llvm::Value *
194  llvm::Value *L,
195  llvm::Value *R,
196  const MemberPointerType *MPT,
197  bool Inequality);
198 
199  /// Determine if a member pointer is non-null. Returns an i1.
200  virtual llvm::Value *
202  llvm::Value *MemPtr,
203  const MemberPointerType *MPT);
204 
205 protected:
206  /// A utility method for computing the offset required for the given
207  /// base-to-derived or derived-to-base member-pointer conversion.
208  /// Does not handle virtual conversions (in case we ever fully
209  /// support an ABI that allows this). Returns null if no adjustment
210  /// is required.
211  llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
212 
213  /// \brief Computes the non-virtual adjustment needed for a member pointer
214  /// conversion along an inheritance path stored in an APValue. Unlike
215  /// getMemberPointerAdjustment(), the adjustment can be negative if the path
216  /// is from a derived type to a base type.
218 
219 public:
220  virtual void emitVirtualObjectDelete(CodeGenFunction &CGF,
221  const CXXDeleteExpr *DE,
222  Address Ptr, QualType ElementType,
223  const CXXDestructorDecl *Dtor) = 0;
224  virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0;
225  virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
226  virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
227 
228  /// \brief Determine whether it's possible to emit a vtable for \p RD, even
229  /// though we do not know that the vtable has been marked as used by semantic
230  /// analysis.
231  virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0;
232 
233  virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
234 
235  virtual llvm::CallInst *
237  llvm::Value *Exn);
238 
239  virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
240  virtual CatchTypeInfo
241  getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0;
243 
244  virtual bool shouldTypeidBeNullChecked(bool IsDeref,
245  QualType SrcRecordTy) = 0;
246  virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
247  virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
248  Address ThisPtr,
249  llvm::Type *StdTypeInfoPtrTy) = 0;
250 
251  virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
252  QualType SrcRecordTy) = 0;
253 
254  virtual llvm::Value *
256  QualType SrcRecordTy, QualType DestTy,
257  QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
258 
260  Address Value,
261  QualType SrcRecordTy,
262  QualType DestTy) = 0;
263 
264  virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
265 
267  Address This,
268  const CXXRecordDecl *ClassDecl,
269  const CXXRecordDecl *BaseClassDecl) = 0;
270 
271  virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
272  const CXXRecordDecl *RD);
273 
274  /// Emit the code to initialize hidden members required
275  /// to handle virtual inheritance, if needed by the ABI.
276  virtual void
278  const CXXRecordDecl *RD) {}
279 
280  /// Emit constructor variants required by this ABI.
281  virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
282 
283  /// Build the signature of the given constructor or destructor variant by
284  /// adding any required parameters. For convenience, ArgTys has been
285  /// initialized with the type of 'this'.
286  virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
287  SmallVectorImpl<CanQualType> &ArgTys) = 0;
288 
289  /// Returns true if the given destructor type should be emitted as a linkonce
290  /// delegating thunk, regardless of whether the dtor is defined in this TU or
291  /// not.
292  virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
293  CXXDtorType DT) const = 0;
294 
295  /// Emit destructor variants required by this ABI.
296  virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
297 
298  /// Get the type of the implicit "this" parameter used by a method. May return
299  /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
300  /// parameter to point to some artificial offset in a complete object due to
301  /// vbases being reordered.
302  virtual const CXXRecordDecl *
304  return MD->getParent();
305  }
306 
307  /// Perform ABI-specific "this" argument adjustment required prior to
308  /// a call of a virtual function.
309  /// The "VirtualCall" argument is true iff the call itself is virtual.
310  virtual Address
312  Address This, bool VirtualCall) {
313  return This;
314  }
315 
316  /// Build a parameter variable suitable for 'this'.
317  void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
318 
319  /// Insert any ABI-specific implicit parameters into the parameter list for a
320  /// function. This generally involves extra data for constructors and
321  /// destructors.
322  ///
323  /// ABIs may also choose to override the return type, which has been
324  /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
325  /// the formal return type of the function otherwise.
326  virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
327  FunctionArgList &Params) = 0;
328 
329  /// Perform ABI-specific "this" parameter adjustment in a virtual function
330  /// prologue.
332  CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
333  return This;
334  }
335 
336  /// Emit the ABI-specific prolog for the function.
337  virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
338 
339  /// Add any ABI-specific implicit arguments needed to call a constructor.
340  ///
341  /// \return The number of args added to the call, which is typically zero or
342  /// one.
343  virtual unsigned
345  CXXCtorType Type, bool ForVirtualBase,
346  bool Delegating, CallArgList &Args) = 0;
347 
348  /// Emit the destructor call.
349  virtual void EmitDestructorCall(CodeGenFunction &CGF,
351  bool ForVirtualBase, bool Delegating,
352  Address This) = 0;
353 
354  /// Emits the VTable definitions required for the given record type.
355  virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
356  const CXXRecordDecl *RD) = 0;
357 
358  /// Checks if ABI requires extra virtual offset for vtable field.
359  virtual bool
361  CodeGenFunction::VPtr Vptr) = 0;
362 
363  /// Checks if ABI requires to initilize vptrs for given dynamic class.
364  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 0;
365 
366  /// Get the address point of the vtable for the given base subobject.
367  virtual llvm::Constant *
369  const CXXRecordDecl *VTableClass) = 0;
370 
371  /// Get the address point of the vtable for the given base subobject while
372  /// building a constructor or a destructor.
373  virtual llvm::Value *
376  const CXXRecordDecl *NearestVBase) = 0;
377 
378  /// Get the address point of the vtable for the given base subobject while
379  /// building a constexpr.
380  virtual llvm::Constant *
382  const CXXRecordDecl *VTableClass) = 0;
383 
384  /// Get the address of the vtable for the given record decl which should be
385  /// used for the vptr at the given offset in RD.
386  virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
387  CharUnits VPtrOffset) = 0;
388 
389  /// Build a virtual function pointer in the ABI-specific way.
391  GlobalDecl GD,
392  Address This,
393  llvm::Type *Ty,
394  SourceLocation Loc) = 0;
395 
396  /// Emit the ABI-specific virtual destructor call.
397  virtual llvm::Value *
399  CXXDtorType DtorType, Address This,
400  const CXXMemberCallExpr *CE) = 0;
401 
403  GlobalDecl GD,
404  CallArgList &CallArgs) {}
405 
406  /// Emit any tables needed to implement virtual inheritance. For Itanium,
407  /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
408  /// base tables.
409  virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
410 
411  virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
412  GlobalDecl GD, bool ReturnAdjustment) = 0;
413 
415  Address This,
416  const ThisAdjustment &TA) = 0;
417 
419  Address Ret,
420  const ReturnAdjustment &RA) = 0;
421 
422  virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
423  RValue RV, QualType ResultType);
424 
425  virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
426  FunctionArgList &Args) const = 0;
427 
428  /// Gets the offsets of all the virtual base pointers in a given class.
429  virtual std::vector<CharUnits> getVBPtrOffsets(const CXXRecordDecl *RD);
430 
431  /// Gets the pure virtual member call function.
432  virtual StringRef GetPureVirtualCallName() = 0;
433 
434  /// Gets the deleted virtual member call name.
435  virtual StringRef GetDeletedVirtualCallName() = 0;
436 
437  /**************************** Array cookies ******************************/
438 
439  /// Returns the extra size required in order to store the array
440  /// cookie for the given new-expression. May return 0 to indicate that no
441  /// array cookie is required.
442  ///
443  /// Several cases are filtered out before this method is called:
444  /// - non-array allocations never need a cookie
445  /// - calls to \::operator new(size_t, void*) never need a cookie
446  ///
447  /// \param expr - the new-expression being allocated.
449 
450  /// Initialize the array cookie for the given allocation.
451  ///
452  /// \param NewPtr - a char* which is the presumed-non-null
453  /// return value of the allocation function
454  /// \param NumElements - the computed number of elements,
455  /// potentially collapsed from the multidimensional array case;
456  /// always a size_t
457  /// \param ElementType - the base element allocated type,
458  /// i.e. the allocated type after stripping all array types
460  Address NewPtr,
461  llvm::Value *NumElements,
462  const CXXNewExpr *expr,
463  QualType ElementType);
464 
465  /// Reads the array cookie associated with the given pointer,
466  /// if it has one.
467  ///
468  /// \param Ptr - a pointer to the first element in the array
469  /// \param ElementType - the base element type of elements of the array
470  /// \param NumElements - an out parameter which will be initialized
471  /// with the number of elements allocated, or zero if there is no
472  /// cookie
473  /// \param AllocPtr - an out parameter which will be initialized
474  /// with a char* pointing to the address returned by the allocation
475  /// function
476  /// \param CookieSize - an out parameter which will be initialized
477  /// with the size of the cookie, or zero if there is no cookie
478  virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr,
479  const CXXDeleteExpr *expr,
480  QualType ElementType, llvm::Value *&NumElements,
481  llvm::Value *&AllocPtr, CharUnits &CookieSize);
482 
483  /// Return whether the given global decl needs a VTT parameter.
484  virtual bool NeedsVTTParameter(GlobalDecl GD);
485 
486 protected:
487  /// Returns the extra size required in order to store the array
488  /// cookie for the given type. Assumes that an array cookie is
489  /// required.
490  virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
491 
492  /// Reads the array cookie for an allocation which is known to have one.
493  /// This is called by the standard implementation of ReadArrayCookie.
494  ///
495  /// \param ptr - a pointer to the allocation made for an array, as a char*
496  /// \param cookieSize - the computed cookie size of an array
497  ///
498  /// Other parameters are as above.
499  ///
500  /// \return a size_t
502  CharUnits cookieSize);
503 
504 public:
505 
506  /*************************** Static local guards ****************************/
507 
508  /// Emits the guarded initializer and destructor setup for the given
509  /// variable, given that it couldn't be emitted as a constant.
510  /// If \p PerformInit is false, the initialization has been folded to a
511  /// constant and should not be performed.
512  ///
513  /// The variable may be:
514  /// - a static local variable
515  /// - a static data member of a class template instantiation
516  virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
517  llvm::GlobalVariable *DeclPtr,
518  bool PerformInit) = 0;
519 
520  /// Emit code to force the execution of a destructor during global
521  /// teardown. The default implementation of this uses atexit.
522  ///
523  /// \param Dtor - a function taking a single pointer argument
524  /// \param Addr - a pointer to pass to the destructor function.
525  virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
526  llvm::Constant *Dtor,
527  llvm::Constant *Addr) = 0;
528 
529  /*************************** thread_local initialization ********************/
530 
531  /// Emits ABI-required functions necessary to initialize thread_local
532  /// variables in this translation unit.
533  ///
534  /// \param CXXThreadLocals - The thread_local declarations in this translation
535  /// unit.
536  /// \param CXXThreadLocalInits - If this translation unit contains any
537  /// non-constant initialization or non-trivial destruction for
538  /// thread_local variables, a list of functions to perform the
539  /// initialization.
540  virtual void EmitThreadLocalInitFuncs(
541  CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals,
542  ArrayRef<llvm::Function *> CXXThreadLocalInits,
543  ArrayRef<const VarDecl *> CXXThreadLocalInitVars) = 0;
544 
545  // Determine if references to thread_local global variables can be made
546  // directly or require access through a thread wrapper function.
547  virtual bool usesThreadWrapperFunction() const = 0;
548 
549  /// Emit a reference to a non-local thread_local variable (including
550  /// triggering the initialization of all thread_local variables in its
551  /// translation unit).
553  const VarDecl *VD,
554  QualType LValType) = 0;
555 
556  /// Emit a single constructor/destructor with the given type from a C++
557  /// constructor Decl.
558  virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
559 };
560 
561 // Create an instance of a C++ ABI class:
562 
563 /// Creates an Itanium-family ABI.
564 CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
565 
566 /// Creates a Microsoft-family ABI.
567 CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
568 
569 }
570 }
571 
572 #endif
virtual llvm::Value * EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, Address This, const CXXMemberCallExpr *CE)=0
Emit the ABI-specific virtual destructor call.
virtual llvm::Value * adjustThisParameterInVirtualFunctionPrologue(CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This)
Perform ABI-specific "this" parameter adjustment in a virtual function prologue.
Definition: CGCXXABI.h:331
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:147
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Definition: ASTMatchers.h:1192
virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E)=0
A (possibly-)qualified type.
Definition: Type.h:575
virtual void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResultType)
Definition: CGCXXABI.cpp:188
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
virtual Address adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, Address This, bool VirtualCall)
Perform ABI-specific "this" argument adjustment required prior to a call of a virtual function...
Definition: CGCXXABI.h:311
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
virtual llvm::Value * performThisAdjustment(CodeGenFunction &CGF, Address This, const ThisAdjustment &TA)=0
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, QualType SrcRecordTy)=0
The base class of the type hierarchy.
Definition: Type.h:1249
virtual StringRef GetDeletedVirtualCallName()=0
Gets the deleted virtual member call name.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2134
llvm::Value *& getStructorImplicitParamValue(CodeGenFunction &CGF)
Definition: CGCXXABI.h:71
virtual llvm::BasicBlock * EmitCtorCompleteObjectHandler(CodeGenFunction &CGF, const CXXRecordDecl *RD)
Definition: CGCXXABI.cpp:306
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
virtual llvm::Value * getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD, Address This, llvm::Type *Ty, SourceLocation Loc)=0
Build a virtual function pointer in the ABI-specific way.
A this pointer adjustment.
Definition: ABI.h:108
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:900
void EmitThisParam(CodeGenFunction &CGF)
Perform prolog initialization of the parameter variable suitable for 'this' emitted by buildThisParam...
Definition: CGCXXABI.cpp:180
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
Definition: CGCXXABI.h:107
virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType)
Definition: CGCXXABI.cpp:214
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
virtual llvm::Constant * getVTableAddressPointForConstExpr(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Get the address point of the vtable for the given base subobject while building a constexpr...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass)=0
Checks if ABI requires to initilize vptrs for given dynamic class.
A return adjustment.
Definition: ABI.h:42
virtual bool isThisCompleteObject(GlobalDecl GD) const =0
Determine whether there's something special about the rules of the ABI tell us that 'this' is a compl...
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
virtual llvm::Value * EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, Address Base, llvm::Value *MemPtr, const MemberPointerType *MPT)
Calculate an l-value from an object and a data member pointer.
Definition: CGCXXABI.cpp:93
virtual void emitVTableDefinitions(CodeGenVTables &CGVT, const CXXRecordDecl *RD)=0
Emits the VTable definitions required for the given record type.
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
virtual llvm::Value * GetVirtualBaseClassOffset(CodeGenFunction &CGF, Address This, const CXXRecordDecl *ClassDecl, const CXXRecordDecl *BaseClassDecl)=0
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:1801
virtual llvm::Value * EmitDynamicCastCall(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd)=0
virtual llvm::Value * EmitDynamicCastToVoid(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy)=0
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:125
CodeGenModule & CGM
Definition: CGCXXABI.h:45
ImplicitParamDecl * getThisDecl(CodeGenFunction &CGF)
Definition: CGCXXABI.h:52
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const =0
Determine whether it's possible to emit a vtable for RD, even though we do not know that the vtable h...
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2610
virtual void EmitDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *DD, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This)=0
Emit the destructor call.
virtual void EmitThreadLocalInitFuncs(CodeGenModule &CGM, ArrayRef< const VarDecl * > CXXThreadLocals, ArrayRef< llvm::Function * > CXXThreadLocalInits, ArrayRef< const VarDecl * > CXXThreadLocalInitVars)=0
Emits ABI-required functions necessary to initialize thread_local variables in this translation unit...
virtual llvm::Type * ConvertMemberPointerType(const MemberPointerType *MPT)
Find the LLVM type used to represent the given member pointer type.
Definition: CGCXXABI.cpp:72
virtual bool isZeroInitializable(const MemberPointerType *MPT)
Return true if the given member pointer can be zero-initialized (in the C++ sense) with an LLVM zeroi...
Definition: CGCXXABI.cpp:151
virtual bool isSRetParameterAfterThis() const
Returns true if the implicit 'sret' parameter comes after the implicit 'this' parameter of C++ instan...
Definition: CGCXXABI.h:137
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)
Returns the extra size required in order to store the array cookie for the given new-expression.
Definition: CGCXXABI.cpp:193
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
Definition: CGValue.h:38
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType)=0
Emit a reference to a non-local thread_local variable (including triggering the initialization of all...
virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const
Return whether or not a member pointers type is convertible to an IR type.
Definition: CGCXXABI.h:174
ImplicitParamDecl *& getStructorImplicitParamDecl(CodeGenFunction &CGF)
Definition: CGCXXABI.h:68
CXXDtorType
C++ destructor types.
Definition: ABI.h:34
virtual void EmitCXXConstructors(const CXXConstructorDecl *D)=0
Emit constructor variants required by this ABI.
Expr - This represents one expression.
Definition: Expr.h:104
virtual void EmitCXXDestructors(const CXXDestructorDecl *D)=0
Emit destructor variants required by this ABI.
virtual CharUnits getArrayCookieSizeImpl(QualType elementType)
Returns the extra size required in order to store the array cookie for the given type.
Definition: CGCXXABI.cpp:199
virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, const CXXDeleteExpr *expr, QualType ElementType, llvm::Value *&NumElements, llvm::Value *&AllocPtr, CharUnits &CookieSize)
Reads the array cookie associated with the given pointer, if it has one.
Definition: CGCXXABI.cpp:233
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2345
CGCXXABI(CodeGenModule &CGM)
Definition: CGCXXABI.h:48
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
Emits the guarded initializer and destructor setup for the given variable, given that it couldn't be ...
virtual bool classifyReturnType(CGFunctionInfo &FI) const =0
If the C++ ABI requires the given type be returned in a particular way, this method sets RetAI and re...
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
ASTContext & getContext() const
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
Definition: CGCXXABI.cpp:137
virtual bool HasThisReturn(GlobalDecl GD) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns 'th...
Definition: CGCXXABI.h:105
void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S)
Issue a diagnostic about unsupported features in the ABI.
Definition: CGCXXABI.cpp:23
virtual CatchTypeInfo getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)=0
virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD, CallArgList &CallArgs)
Definition: CGCXXABI.h:402
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:28
The l-value was considered opaque, so the alignment was determined from a type.
Pass it as a pointer to temporary memory.
Definition: CGCXXABI.h:125
virtual unsigned addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, CallArgList &Args)=0
Add any ABI-specific implicit arguments needed to call a constructor.
virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn)=0
virtual llvm::Value * EmitMemberPointerConversion(CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)
Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion. ...
Definition: CGCXXABI.cpp:102
virtual bool NeedsVTTParameter(GlobalDecl GD)
Return whether the given global decl needs a VTT parameter.
Definition: CGCXXABI.cpp:315
Encodes a location in the source.
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, Address ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
bool canCopyArgument(const CXXRecordDecl *RD) const
Returns true if C++ allows us to copy the memory of an object of type RD when it is passed as an argu...
Definition: CGCXXABI.cpp:32
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:1723
Represents a call to a member function that may be written either with member call syntax (e...
Definition: ExprCXX.h:124
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1701
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:41
virtual CatchTypeInfo getCatchAllTypeInfo()
Definition: CGCXXABI.cpp:326
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, FunctionArgList &Args) const =0
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
An aligned address.
Definition: Address.h:25
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD)=0
Emit any tables needed to implement virtual inheritance.
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:95
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:133
The MS C++ ABI needs a pointer to RTTI data plus some flags to describe the type of a catch handler...
Definition: CGCleanup.h:38
virtual bool isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF, CodeGenFunction::VPtr Vptr)=0
Checks if ABI requires extra virtual offset for vtable field.
CXXCtorType
C++ constructor types.
Definition: ABI.h:25
virtual Address InitializeArrayCookie(CodeGenFunction &CGF, Address NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
Initialize the array cookie for the given allocation.
Definition: CGCXXABI.cpp:204
llvm::Constant * getMemberPointerAdjustment(const CastExpr *E)
A utility method for computing the offset required for the given base-to-derived or derived-to-base m...
Definition: CGCXXABI.cpp:265
FunctionArgList - Type for representing both the decl and type of parameters to a function...
Definition: CGCall.h:146
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:115
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
Definition: ExprCXX.h:1927
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T, SmallVectorImpl< CanQualType > &ArgTys)=0
Build the signature of the given constructor or destructor variant by adding any required parameters...
virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type)=0
Emit a single constructor/destructor with the given type from a C++ constructor Decl.
virtual llvm::Value * readArrayCookieImpl(CodeGenFunction &IGF, Address ptr, CharUnits cookieSize)
Reads the array cookie for an allocation which is known to have one.
Definition: CGCXXABI.cpp:255
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
Definition: CGCXXABI.cpp:156
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2369
std::unique_ptr< MangleContext > MangleCtx
Definition: CGCXXABI.h:46
virtual void initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF, const CXXRecordDecl *RD)
Emit the code to initialize hidden members required to handle virtual inheritance, if needed by the ABI.
Definition: CGCXXABI.h:277
virtual llvm::Constant * getVTableAddressPoint(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Get the address point of the vtable for the given base subobject.
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
Definition: CGCXXABI.h:117
virtual llvm::Constant * getAddrOfRTTIDescriptor(QualType Ty)=0
Address getThisAddress(CodeGenFunction &CGF)
Definition: CGCXXABI.h:58
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
virtual bool usesThreadWrapperFunction() const =0
ASTContext & getContext() const
Definition: CGCXXABI.h:79
virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)
Create a member pointer for the given field.
Definition: CGCXXABI.cpp:142
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
Pass it on the stack using its defined layout.
Definition: CGCXXABI.h:122
virtual llvm::Value * getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base, const CXXRecordDecl *NearestVBase)=0
Get the address point of the vtable for the given base subobject while building a constructor or a de...
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)
Get the type of the implicit "this" parameter used by a method.
Definition: CGCXXABI.h:303
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:29
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
virtual llvm::Value * EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, const Expr *E, Address This, llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, const MemberPointerType *MPT)
Load a member function from an object and a member function pointer.
Definition: CGCXXABI.cpp:76
virtual llvm::CallInst * emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn)
Definition: CGCXXABI.cpp:320
virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor, CXXDtorType DT) const =0
Returns true if the given destructor type should be emitted as a linkonce delegating thunk...
Struct with all informations about dynamic [sub]class needed to set vptr.
virtual llvm::Value * performReturnAdjustment(CodeGenFunction &CGF, Address Ret, const ReturnAdjustment &RA)=0
virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C)=0
virtual std::vector< CharUnits > getVBPtrOffsets(const CXXRecordDecl *RD)
Gets the offsets of all the virtual base pointers in a given class.
Definition: CGCXXABI.cpp:330
virtual llvm::GlobalVariable * getThrowInfo(QualType T)
Definition: CGCXXABI.h:226
LValue - This represents an lvalue references.
Definition: CGValue.h:152
RecordArgABI
Specify how one should pass an argument of a record type.
Definition: CGCXXABI.h:114
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:56
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD, bool ReturnAdjustment)=0
llvm::Value * getThisValue(CodeGenFunction &CGF)
Definition: CGCXXABI.h:55
llvm::Constant * GetBogusMemberPointer(QualType T)
Get a null value for unsupported member pointers.
Definition: CGCXXABI.cpp:67
CharUnits getMemberPointerPathAdjustment(const APValue &MP)
Computes the non-virtual adjustment needed for a member pointer conversion along an inheritance path ...
Definition: CGCXXABI.cpp:283