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!");
208 "Invalid component kind!");
210 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
212 Value = Ptr | ComponentKind;
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()) {
305 return vtable_components().size();
308 size_t thisIndex = VTableIndices[i];
309 size_t nextIndex = (i + 1 == VTableIndices.size())
310 ? vtable_components().size()
311 : VTableIndices[i + 1];
312 return nextIndex - thisIndex;
325 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
332 virtual void computeVTableRelatedInformation(
const CXXRecordDecl *RD) = 0;
339 computeVTableRelatedInformation(MD->
getParent());
343 ThunksMapTy::const_iterator I = Thunks.find(MD);
344 if (I == Thunks.end()) {
360 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
361 MethodVTableIndicesTy MethodVTableIndices;
364 std::unique_ptr<const VTableLayout>>
366 VTableLayoutMapTy VTableLayouts;
368 typedef std::pair<
const CXXRecordDecl *,
369 const CXXRecordDecl *> ClassPairTy;
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];
392 std::unique_ptr<VTableLayout> createConstructionVTableLayout(
393 const CXXRecordDecl *MostDerivedClass,
CharUnits MostDerivedClassOffset,
394 bool MostDerivedClassIsVirtual,
const CXXRecordDecl *LayoutClass);
407 CharUnits getVirtualBaseOffsetOffset(
const CXXRecordDecl *RD,
408 const CXXRecordDecl *VBase);
422 : ObjectWithVPtr(RD), IntroducingObject(RD), NextBaseToMangle(RD) {}
463 return ContainingVBases.empty() ? nullptr : ContainingVBases.front();
500 : VBTableIndex(0), VBase(nullptr), VFPtrOffset(
CharUnits::Zero()),
505 : VBTableIndex(VBTableIndex), VBase(VBase),
506 VFPtrOffset(VFPtrOffset), Index(Index) {}
510 assert(VBase != other.
VBase);
513 return std::tie(VFPtrOffset, 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,
549 VPtrInfoVector &Paths);
557 const VPtrInfoVector &getVFPtrOffsets(
const CXXRecordDecl *RD);
566 if (isa<CXXDestructorDecl>(GD.
getDecl()) &&
579 const VPtrInfoVector &enumerateVBTables(
const CXXRecordDecl *RD);
size_t getNumVTables() const
bool isFunctionPointerKind() const
const AddressPointsMapTy & getAddressPoints() const
bool operator<(const MethodVFTableLocation &other) const
CXXDtorType getDtorType() const
static VTableComponent MakeRTTI(const CXXRecordDecl *RD)
const CXXMethodDecl * getFunctionDecl() const
VPtrInfoVector VBPtrPaths
Information on all virtual base tables used when this record is the most derived class.
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
AddressPointLocation getAddressPoint(BaseSubobject Base) const
bool isUsedFunctionPointerKind() const
BasePath MangledPath
The bases from the inheritance path that got used to mangle the vbtable name.
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD)
const CXXMethodDecl * getUnusedFunctionDecl() const
static VTableComponent getFromOpaqueInteger(uint64_t I)
static VTableComponent MakeVCallOffset(CharUnits Offset)
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 CXXRecordDecl * NextBaseToMangle
The next base to push onto the mangled path if this path is ambiguous in a derived class...
ArrayRef< VTableComponent > vtable_components() const
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::DenseMap< const CXXMethodDecl *, ThunkInfoVectorTy > ThunksMapTy
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
Enums/classes describing ABI related information about constructors, destructors and thunks...
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...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
SmallVector< ThunkInfo, 1 > ThunkInfoVectorTy
static bool classof(const VTableContextBase *VT)
Kind getKind() const
Get the kind of this vtable component.
Represents a C++ destructor within a class.
CharUnits getOffsetToTop() const
CharUnits getVCallOffset() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
bool isDestructorKind() const
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
const CXXDestructorDecl * getDestructorDecl() const
The result type of a method or function.
SmallVector< const CXXRecordDecl *, 1 > BasePath
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.
ArrayRef< VTableThunkTy > vtable_thunks() const
virtual ~VTableContextBase()
const Decl * getDecl() const
Represents a single component in a vtable.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * ObjectWithVPtr
This is the most derived class that has this vptr at offset zero.
VTableContextBase(bool MS)
MicrosoftVTableContext(ASTContext &Context)
const CXXRecordDecl * getRTTIDecl() const
static VTableComponent MakeVBaseOffset(CharUnits Offset)
VTableComponent()=default
Dataflow Directional Tag Classes.
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
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.
const CXXRecordDecl * getVBaseWithVPtr() const
The vptr is stored inside the non-virtual component of this virtual base.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
Represents a C++ struct/union/class.
size_t getVTableSize(size_t i) const
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.
GlobalDecl getGlobalDecl() const
CharUnits getVBaseOffset() const
BasePath PathToIntroducingObject
This holds the base classes path from the complete type to the first base with the given vfptr offset...
A pointer to the complete destructor.
size_t getVTableOffset(size_t i) const
An entry that is never used.
static bool classof(const VTableContextBase *VT)
static VTableComponent MakeOffsetToTop(CharUnits Offset)