14 #ifndef LLVM_CLANG_AST_VTABLEBUILDER_H
15 #define LLVM_CLANG_AST_VTABLEBUILDER_H
22 #include "llvm/ADT/DenseMap.h"
72 assert(!isa<CXXDestructorDecl>(MD) &&
73 "Don't use MakeFunction with destructors!");
76 reinterpret_cast<uintptr_t>(MD));
81 reinterpret_cast<uintptr_t>(DD));
86 reinterpret_cast<uintptr_t>(DD));
90 assert(!isa<CXXDestructorDecl>(MD) &&
91 "Don't use MakeUnusedFunction with destructors!");
93 reinterpret_cast<uintptr_t>(MD));
124 assert(
isRTTIKind() &&
"Invalid component kind!");
159 "GlobalDecl can be created only from virtual function");
174 llvm_unreachable(
"Only function pointers kinds");
176 llvm_unreachable(
"Should already return");
193 return ComponentKind ==
CK_RTTI;
200 assert(Offset.getQuantity() < (1LL << 56) &&
"Offset is too big!");
201 assert(Offset.getQuantity() >= -(1LL << 56) &&
"Offset is too small!");
203 Value = (uint64_t(Offset.getQuantity()) << 3) | ComponentKind;
208 "Invalid component kind!");
210 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
212 Value = Ptr | ComponentKind;
215 CharUnits getOffset()
const {
224 "Invalid component kind!");
246 typedef llvm::DenseMap<BaseSubobject, AddressPointLocation>
272 return VTableComponents;
280 assert(AddressPoints.count(Base) &&
"Did not find address point!");
281 return AddressPoints.find(Base)->second;
285 return AddressPoints;
289 if (VTableIndices.empty())
291 return VTableIndices.size();
295 if (VTableIndices.empty()) {
299 return VTableIndices[i];
303 if (VTableIndices.empty()) {
308 size_t thisIndex = VTableIndices[i];
309 size_t nextIndex = (i + 1 == VTableIndices.size())
311 : VTableIndices[i + 1];
312 return nextIndex - thisIndex;
325 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
343 ThunksMapTy::const_iterator
I =
Thunks.find(MD);
360 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
361 MethodVTableIndicesTy MethodVTableIndices;
364 std::unique_ptr<const VTableLayout>>
366 VTableLayoutMapTy VTableLayouts;
375 typedef llvm::DenseMap<ClassPairTy, CharUnits>
376 VirtualBaseClassOffsetOffsetsMapTy;
377 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
379 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
386 computeVTableRelatedInformation(RD);
387 assert(VTableLayouts.count(RD) &&
"No layout for this record decl!");
389 return *VTableLayouts[RD];
394 bool MostDerivedClassIsVirtual,
const CXXRecordDecl *LayoutClass);
505 : VBTableIndex(VBTableIndex), VBase(VBase),
506 VFPtrOffset(VFPtrOffset), Index(Index) {}
521 typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
522 MethodVFTableLocationsTy;
523 MethodVFTableLocationsTy MethodVFTableLocations;
525 typedef llvm::DenseMap<const CXXRecordDecl *, VPtrInfoVector>
527 VFPtrLocationsMapTy VFPtrLocations;
529 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
530 typedef llvm::DenseMap<VFTableIdTy, std::unique_ptr<const VTableLayout>>
532 VFTableLayoutMapTy VFTableLayouts;
534 llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VirtualBaseInfo>>
539 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
542 const MethodVFTableLocationsTy &NewMethods,
548 void computeVTablePaths(
bool ForVBTables,
const CXXRecordDecl *RD,
566 if (isa<CXXDestructorDecl>(GD.
getDecl()) &&
CharUnits getOffsetToTop() const
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)
BasePath MangledPath
The bases from the inheritance path that got used to mangle the vbtable name.
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD)
unsigned AddressPointIndex
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 ...
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 Decl * getDecl() const
const CXXRecordDecl * NextBaseToMangle
The next base to push onto the mangled path if this path is ambiguous in a derived class...
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...
const CXXRecordDecl * IntroducingObject
This is the class that introduced the vptr by declaring new virtual methods or virtual bases...
CharUnits VFPtrOffset
This is the offset of the vfptr from the start of the last vbase, or the complete type if there are n...
SmallVector< std::unique_ptr< VPtrInfo >, 2 > VPtrInfoVector
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...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
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...
ArrayRef< VTableThunkTy > vtable_thunks() const
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.
size_t getVTableSize(size_t i) const
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
AddressPointLocation getAddressPoint(BaseSubobject Base) const
The result type of a method or function.
SmallVector< const CXXRecordDecl *, 1 > BasePath
size_t getNumVTables() const
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
virtual ~VTableContextBase()
std::unique_ptr< VTableLayout > createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset, bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass)
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)
ArrayRef< VTableComponent > vtable_components() const
const CXXDestructorDecl * getDestructorDecl() const
const CXXRecordDecl * ObjectWithVPtr
This is the most derived class that has this vptr at offset zero.
VTableContextBase(bool MS)
MicrosoftVTableContext(ASTContext &Context)
static VTableComponent MakeVBaseOffset(CharUnits Offset)
bool isFunctionPointerKind() const
VTableComponent()=default
const VPtrInfoVector & enumerateVBTables(const CXXRecordDecl *RD)
size_t getVTableOffset(size_t i) const
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
CharUnits getVBaseOffset() const
VPtrInfo(const CXXRecordDecl *RD)
CharUnits NonVirtualOffset
IntroducingObject is at this offset from its containing complete object or virtual base...
All virtual base related information about a given record decl.
VTableLayout(ArrayRef< size_t > VTableIndices, ArrayRef< VTableComponent > VTableComponents, ArrayRef< VTableThunkTy > VTableThunks, const AddressPointsMapTy &AddressPoints)
bool isDestructorKind() const
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
Represents a C++ struct/union/class.
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
BasePath PathToIntroducingObject
This holds the base classes path from the complete type to the first base with the given vfptr offset...
GlobalDecl getGlobalDecl() 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)