14 #ifndef LLVM_CLANG_AST_VTABLEBUILDER_H
15 #define LLVM_CLANG_AST_VTABLEBUILDER_H
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SetVector.h"
73 assert(!isa<CXXDestructorDecl>(MD) &&
74 "Don't use MakeFunction with destructors!");
77 reinterpret_cast<uintptr_t>(MD));
82 reinterpret_cast<uintptr_t>(DD));
87 reinterpret_cast<uintptr_t>(DD));
91 assert(!isa<CXXDestructorDecl>(MD) &&
92 "Don't use MakeUnusedFunction with destructors!");
94 reinterpret_cast<uintptr_t>(MD));
125 assert(
isRTTIKind() &&
"Invalid component kind!");
172 return ComponentKind ==
CK_RTTI;
179 assert(Offset.getQuantity() < (1LL << 56) &&
"Offset is too big!");
180 assert(Offset.getQuantity() >= -(1LL << 56) &&
"Offset is too small!");
182 Value = (uint64_t(Offset.getQuantity()) << 3) | ComponentKind;
187 "Invalid component kind!");
189 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
191 Value = Ptr | ComponentKind;
194 CharUnits getOffset()
const {
203 "Invalid component kind!");
225 typedef llvm::iterator_range<vtable_component_iterator>
231 uint64_t NumVTableComponents;
232 std::unique_ptr<VTableComponent[]> VTableComponents;
235 uint64_t NumVTableThunks;
236 std::unique_ptr<VTableThunkTy[]> VTableThunks;
246 uint64_t NumVTableThunks,
249 bool IsMicrosoftABI);
253 return NumVTableComponents;
262 return VTableComponents.get();
266 return VTableComponents.get() + NumVTableComponents;
272 return VTableThunks.get();
276 return VTableThunks.get() + NumVTableThunks;
280 assert(AddressPoints.count(Base) &&
281 "Did not find address point!");
283 uint64_t AddressPoint = AddressPoints.lookup(Base);
284 assert(AddressPoint != 0 || IsMicrosoftABI);
285 (void)IsMicrosoftABI;
291 return AddressPoints;
304 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
322 ThunksMapTy::const_iterator
I =
Thunks.find(MD);
339 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
340 MethodVTableIndicesTy MethodVTableIndices;
342 typedef llvm::DenseMap<const CXXRecordDecl *, const VTableLayout *>
344 VTableLayoutMapTy VTableLayouts;
353 typedef llvm::DenseMap<ClassPairTy, CharUnits>
354 VirtualBaseClassOffsetOffsetsMapTy;
355 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
357 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
364 computeVTableRelatedInformation(RD);
365 assert(VTableLayouts.count(RD) &&
"No layout for this record decl!");
367 return *VTableLayouts[RD];
373 bool MostDerivedClassIsVirtual,
487 : VBTableIndex(VBTableIndex), VBase(VBase),
488 VFPtrOffset(VFPtrOffset), Index(Index) {}
503 typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
504 MethodVFTableLocationsTy;
505 MethodVFTableLocationsTy MethodVFTableLocations;
507 typedef llvm::DenseMap<const CXXRecordDecl *, VPtrInfoVector *>
509 VFPtrLocationsMapTy VFPtrLocations;
511 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
512 typedef llvm::DenseMap<VFTableIdTy, const VTableLayout *> VFTableLayoutMapTy;
513 VFTableLayoutMapTy VFTableLayouts;
515 llvm::DenseMap<const CXXRecordDecl *, VirtualBaseInfo *> VBaseInfo;
519 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
522 const MethodVFTableLocationsTy &NewMethods,
528 void computeVTablePaths(
bool ForVBTables,
const CXXRecordDecl *RD,
546 if (isa<CXXDestructorDecl>(GD.
getDecl()) &&
CharUnits getOffsetToTop() const
VTableLayout * createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset, bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass)
ItaniumVTableContext(ASTContext &Context)
static VTableComponent MakeRTTI(const CXXRecordDecl *RD)
VPtrInfoVector VBPtrPaths
Information on all virtual base tables used when this record is the most derived class.
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
vtable_component_iterator vtable_component_begin() const
const VTableThunkTy * vtable_thunk_iterator
vtable_component_iterator vtable_component_end() const
BasePath MangledPath
The bases from the inheritance path that got used to mangle the vbtable name.
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD)
static VTableComponent getFromOpaqueInteger(uint64_t I)
static VTableComponent MakeVCallOffset(CharUnits Offset)
const CXXRecordDecl * getVBaseWithVPtr() const
The vptr is stored inside the non-virtual component of this virtual base.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
BasePath PathToBaseWithVPtr
This holds the base classes path from the complete type to the first base with the given vfptr offset...
uint64_t getNumVTableComponents() const
VTableLayout(uint64_t NumVTableComponents, const VTableComponent *VTableComponents, uint64_t NumVTableThunks, const VTableThunkTy *VTableThunks, const AddressPointsMapTy &AddressPoints, bool IsMicrosoftABI)
static VTableComponent MakeCompleteDtor(const CXXDestructorDecl *DD)
llvm::DenseMap< const CXXRecordDecl *, unsigned > VBTableIndices
A map from virtual base to vbtable index for doing a conversion from the the derived class to the a b...
const VTableComponent * vtable_component_iterator
const Decl * getDecl() const
const CXXRecordDecl * NextBaseToMangle
The next base to push onto the mangled path if this path is ambiguous in a derived class...
uint64_t getAddressPoint(BaseSubobject Base) const
const CXXMethodDecl * getFunctionDecl() const
~ItaniumVTableContext() override
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::DenseMap< const CXXMethodDecl *, ThunkInfoVectorTy > ThunksMapTy
~MicrosoftVTableContext() override
CharUnits getVCallOffset() const
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
CharUnits VFPtrOffset
This is the offset of the vfptr from the start of the last vbase, or the complete type if there are n...
const VPtrInfoVector & getVFPtrOffsets(const CXXRecordDecl *RD)
Enums/classes describing ABI related information about constructors, destructors and thunks...
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
detail::InMemoryDirectory::const_iterator I
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
static VTableComponent MakeDeletingDtor(const CXXDestructorDecl *DD)
uint64_t VBTableIndex
If nonzero, holds the vbtable index of the virtual base with the vfptr.
BasePath ContainingVBases
The set of possibly indirect vbases that contain this vbtable.
const CXXRecordDecl * VBase
If nonnull, holds the last vbase which contains the vfptr that the method definition is adjusted to...
CXXDtorType getDtorType() const
SmallVector< ThunkInfo, 1 > ThunkInfoVectorTy
static bool classof(const VTableContextBase *VT)
bool operator<(const MethodVFTableLocation &other) const
Represents a C++ destructor within a class.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
vtable_thunk_iterator vtable_thunk_end() const
llvm::DenseMap< BaseSubobject, uint64_t > AddressPointsMapTy
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
SmallVector< VPtrInfo *, 2 > VPtrInfoVector
The result type of a method or function.
SmallVector< const CXXRecordDecl *, 1 > BasePath
const CXXRecordDecl * ReusingBase
The vtable will hold all of the virtual bases or virtual methods of ReusingBase.
const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD) override
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
GlobalDecl - represents a global declaration.
bool isUsedFunctionPointerKind() const
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived.
const CXXRecordDecl * getRTTIDecl() const
uint64_t getNumVTableThunks() const
virtual ~VTableContextBase()
Represents a single component in a vtable.
Represents a static or instance method of a struct/union/class.
const VTableLayout & getVFTableLayout(const CXXRecordDecl *RD, CharUnits VFPtrOffset)
const CXXDestructorDecl * getDestructorDecl() const
const CXXRecordDecl * BaseWithVPtr
The vptr is stored inside this subobject.
VTableContextBase(bool MS)
MicrosoftVTableContext(ASTContext &Context)
static VTableComponent MakeVBaseOffset(CharUnits Offset)
bool isFunctionPointerKind() const
VTableComponent()=default
const VPtrInfoVector & enumerateVBTables(const CXXRecordDecl *RD)
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
CharUnits getVBaseOffset() const
VPtrInfo(const CXXRecordDecl *RD)
CharUnits NonVirtualOffset
BaseWithVPtr is at this offset from its containing complete object or virtual base.
vtable_component_range vtable_components() const
All virtual base related information about a given record decl.
vtable_thunk_iterator vtable_thunk_begin() const
bool isDestructorKind() const
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
Represents a C++ struct/union/class.
llvm::iterator_range< vtable_component_iterator > vtable_component_range
std::pair< uint64_t, ThunkInfo > VTableThunkTy
CharUnits FullOffsetInMDC
Static offset from the top of the most derived class to this vfptr, including any virtual base offset...
uint64_t Index
Method's index in the vftable.
A pointer to the deleting destructor.
static VTableComponent MakeFunction(const CXXMethodDecl *MD)
Holds information about the inheritance path to a virtual base or function table pointer.
Kind getKind() const
Get the kind of this vtable component.
const AddressPointsMapTy & getAddressPoints() const
const CXXMethodDecl * getUnusedFunctionDecl() const
A pointer to the complete destructor.
An entry that is never used.
const MethodVFTableLocation & getMethodVFTableLocation(GlobalDecl GD)
virtual void computeVTableRelatedInformation(const CXXRecordDecl *RD)=0
Compute and store all vtable related information (vtable layout, vbase offset offsets, thunks etc) for the given record decl.
static bool classof(const VTableContextBase *VT)
static VTableComponent MakeOffsetToTop(CharUnits Offset)