13#ifndef LLVM_CLANG_AST_VTABLEBUILDER_H
14#define LLVM_CLANG_AST_VTABLEBUILDER_H
22#include "llvm/ADT/DenseMap.h"
72 assert(!isa<CXXDestructorDecl>(MD) &&
73 "Don't use MakeFunction with destructors!");
90 assert(!isa<CXXDestructorDecl>(MD) &&
91 "Don't use MakeUnusedFunction with destructors!");
120 assert(
isRTTIKind() &&
"Invalid component kind!");
155 "GlobalDecl can be created only from virtual function");
170 llvm_unreachable(
"Only function pointers kinds");
172 llvm_unreachable(
"Should already return");
189 return ComponentKind ==
CK_RTTI;
196 assert(Offset.getQuantity() < (1LL << 56) &&
"Offset is too big!");
197 assert(Offset.getQuantity() >= -(1LL << 56) &&
"Offset is too small!");
199 Value = (
uint64_t(Offset.getQuantity()) << 3) | ComponentKind;
204 "Invalid component kind!");
206 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
208 Value = Ptr | ComponentKind;
211 CharUnits getOffset()
const {
220 "Invalid component kind!");
239 typedef llvm::DenseMap<BaseSubobject, AddressPointLocation>
273 return VTableComponents;
281 assert(AddressPoints.count(
Base) &&
"Did not find address point!");
282 return AddressPoints.lookup(
Base);
286 return AddressPoints;
290 return AddressPointIndices;
294 if (VTableIndices.empty())
296 return VTableIndices.size();
300 if (VTableIndices.empty()) {
304 return VTableIndices[i];
308 if (VTableIndices.empty()) {
313 size_t thisIndex = VTableIndices[i];
314 size_t nextIndex = (i + 1 == VTableIndices.size())
316 : VTableIndices[i + 1];
317 return nextIndex - thisIndex;
330 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
348 ThunksMapTy::const_iterator I =
Thunks.find(MD);
365 typedef llvm::DenseMap<const CXXMethodDecl *, const CXXMethodDecl *>
372 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
373 MethodVTableIndicesTy MethodVTableIndices;
376 std::unique_ptr<const VTableLayout>>
378 VTableLayoutMapTy VTableLayouts;
387 typedef llvm::DenseMap<ClassPairTy, CharUnits>
388 VirtualBaseClassOffsetOffsetsMapTy;
389 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
395 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
412 computeVTableRelatedInformation(RD);
413 assert(VTableLayouts.count(RD) &&
"No layout for this record decl!");
415 return *VTableLayouts[RD];
420 bool MostDerivedClassIsVirtual,
const CXXRecordDecl *LayoutClass);
448 OriginalMethodMap[Key] = Val;
454 return OriginalMethodMap;
462 return ComponentLayout;
579 typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
580 MethodVFTableLocationsTy;
581 MethodVFTableLocationsTy MethodVFTableLocations;
583 typedef llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VPtrInfoVector>>
585 VFPtrLocationsMapTy VFPtrLocations;
587 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
588 typedef llvm::DenseMap<VFTableIdTy, std::unique_ptr<const VTableLayout>>
590 VFTableLayoutMapTy VFTableLayouts;
592 llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VirtualBaseInfo>>
595 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
598 const MethodVFTableLocationsTy &NewMethods,
604 void computeVTablePaths(
bool ForVBTables,
const CXXRecordDecl *RD,
622 if (isa<CXXDestructorDecl>(GD.
getDecl()) &&
Enums/classes describing ABI related information about constructors, destructors and thunks.
Enums/classes describing THUNK related information about constructors, destructors and thunks.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a C++ struct/union/class.
CharUnits - This is an opaque type for sizes expressed in character units.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
GlobalDecl - represents a global declaration.
CXXDtorType getDtorType() const
const Decl * getDecl() const
@ Relative
Components in the vtable are relative offsets between the vtable and the other structs/functions.
@ Pointer
Components in the vtable are pointers to other structs/functions.
bool isPointerLayout() const
const CXXMethodDecl * findOriginalMethodInMap(const CXXMethodDecl *MD) const
const OriginalMethodMapTy & getOriginalMethodMap()
This method is reserved for the implementation and shouldn't be used directly.
VTableComponentLayout getVTableComponentLayout() const
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
llvm::DenseMap< const CXXMethodDecl *, const CXXMethodDecl * > OriginalMethodMapTy
bool isRelativeLayout() const
std::unique_ptr< VTableLayout > createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset, bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass)
~ItaniumVTableContext() override
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
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...
GlobalDecl findOriginalMethod(GlobalDecl GD)
Return the method that added the v-table slot that will be used to call the given method.
void setOriginalMethod(const CXXMethodDecl *Key, const CXXMethodDecl *Val)
static bool classof(const VTableContextBase *VT)
static bool classof(const VTableContextBase *VT)
const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD) override
MicrosoftVTableContext(ASTContext &Context)
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived.
const VPtrInfoVector & enumerateVBTables(const CXXRecordDecl *RD)
MethodVFTableLocation getMethodVFTableLocation(GlobalDecl GD)
const VPtrInfoVector & getVFPtrOffsets(const CXXRecordDecl *RD)
const VTableLayout & getVFTableLayout(const CXXRecordDecl *RD, CharUnits VFPtrOffset)
~MicrosoftVTableContext() override
Represents a single component in a vtable.
VTableComponent()=default
static VTableComponent MakeCompleteDtor(const CXXDestructorDecl *DD)
static VTableComponent MakeRTTI(const CXXRecordDecl *RD)
GlobalDecl getGlobalDecl() const
const CXXMethodDecl * getUnusedFunctionDecl() const
static VTableComponent MakeOffsetToTop(CharUnits Offset)
bool isUsedFunctionPointerKind() const
bool isDestructorKind() const
CharUnits getVBaseOffset() const
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD)
Kind getKind() const
Get the kind of this vtable component.
static VTableComponent MakeFunction(const CXXMethodDecl *MD)
@ CK_DeletingDtorPointer
A pointer to the deleting destructor.
@ CK_UnusedFunctionPointer
An entry that is never used.
@ CK_CompleteDtorPointer
A pointer to the complete destructor.
static VTableComponent MakeVBaseOffset(CharUnits Offset)
const CXXRecordDecl * getRTTIDecl() const
static VTableComponent MakeDeletingDtor(const CXXDestructorDecl *DD)
bool isFunctionPointerKind() const
CharUnits getOffsetToTop() const
const CXXMethodDecl * getFunctionDecl() const
static VTableComponent MakeVCallOffset(CharUnits Offset)
CharUnits getVCallOffset() const
const CXXDestructorDecl * getDestructorDecl() const
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
VTableContextBase(bool MS)
static bool hasVtableSlot(const CXXMethodDecl *MD)
Determine whether this function should be assigned a vtable slot.
virtual ~VTableContextBase()
virtual void computeVTableRelatedInformation(const CXXRecordDecl *RD)=0
Compute and store all vtable related information (vtable layout, vbase offset offsets,...
SmallVector< ThunkInfo, 1 > ThunkInfoVectorTy
llvm::DenseMap< const CXXMethodDecl *, ThunkInfoVectorTy > ThunksMapTy
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
const AddressPointsIndexMapTy & getAddressPointIndices() const
size_t getVTableOffset(size_t i) const
llvm::SmallVector< unsigned, 4 > AddressPointsIndexMapTy
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
AddressPointLocation getAddressPoint(BaseSubobject Base) const
std::pair< uint64_t, ThunkInfo > VTableThunkTy
ArrayRef< VTableComponent > vtable_components() const
size_t getNumVTables() const
ArrayRef< VTableThunkTy > vtable_thunks() const
const AddressPointsMapTy & getAddressPoints() const
size_t getVTableSize(size_t i) const
The JSON file list parser is used to communicate input to InstallAPI.
SmallVector< std::unique_ptr< VPtrInfo >, 2 > VPtrInfoVector
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
bool operator<(const MethodVFTableLocation &other) const
const CXXRecordDecl * VBase
If nonnull, holds the last vbase which contains the vfptr that the method definition is adjusted to.
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
CharUnits VFPtrOffset
This is the offset of the vfptr from the start of the last vbase, or the complete type if there are n...
uint64_t VBTableIndex
If nonzero, holds the vbtable index of the virtual base with the vfptr.
uint64_t Index
Method's index in the vftable.
Holds information about the inheritance path to a virtual base or function table pointer.
CharUnits NonVirtualOffset
IntroducingObject is at this offset from its containing complete object or virtual base.
CharUnits FullOffsetInMDC
Static offset from the top of the most derived class to this vfptr, including any virtual base offset...
const CXXRecordDecl * getVBaseWithVPtr() const
The vptr is stored inside the non-virtual component of this virtual base.
SmallVector< const CXXRecordDecl *, 1 > BasePath
VPtrInfo(const CXXRecordDecl *RD)
BasePath ContainingVBases
The set of possibly indirect vbases that contain this vbtable.
const CXXRecordDecl * IntroducingObject
This is the class that introduced the vptr by declaring new virtual methods or virtual bases.
BasePath MangledPath
The bases from the inheritance path that got used to mangle the vbtable name.
const CXXRecordDecl * NextBaseToMangle
The next base to push onto the mangled path if this path is ambiguous in a derived class.
BasePath PathToIntroducingObject
This holds the base classes path from the complete type to the first base with the given vfptr offset...
const CXXRecordDecl * ObjectWithVPtr
This is the most derived class that has this vptr at offset zero.
unsigned AddressPointIndex
All virtual base related information about a given record decl.
VPtrInfoVector VBPtrPaths
Information on all virtual base tables used when this record is the most derived class.
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...