13 #ifndef LLVM_CLANG_AST_VTABLEBUILDER_H 14 #define LLVM_CLANG_AST_VTABLEBUILDER_H 21 #include "llvm/ADT/DenseMap.h" 71 assert(!isa<CXXDestructorDecl>(MD) &&
72 "Don't use MakeFunction with destructors!");
75 reinterpret_cast<uintptr_t>(MD));
80 reinterpret_cast<uintptr_t>(DD));
85 reinterpret_cast<uintptr_t>(DD));
89 assert(!isa<CXXDestructorDecl>(MD) &&
90 "Don't use MakeUnusedFunction with destructors!");
92 reinterpret_cast<uintptr_t>(MD));
119 assert(
isRTTIKind() &&
"Invalid component kind!");
154 "GlobalDecl can be created only from virtual function");
169 llvm_unreachable(
"Only function pointers kinds");
171 llvm_unreachable(
"Should already return");
188 return ComponentKind ==
CK_RTTI;
195 assert(Offset.
getQuantity() < (1LL << 56) &&
"Offset is too big!");
196 assert(Offset.
getQuantity() >= -(1LL << 56) &&
"Offset is too small!");
203 "Invalid component kind!");
205 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
207 Value = Ptr | ComponentKind;
219 "Invalid component kind!");
238 typedef llvm::DenseMap<BaseSubobject, AddressPointLocation>
264 return VTableComponents;
272 assert(AddressPoints.count(Base) &&
"Did not find address point!");
273 return AddressPoints.find(Base)->second;
277 return AddressPoints;
281 if (VTableIndices.empty())
283 return VTableIndices.size();
287 if (VTableIndices.empty()) {
291 return VTableIndices[i];
295 if (VTableIndices.empty()) {
297 return vtable_components().size();
300 size_t thisIndex = VTableIndices[i];
301 size_t nextIndex = (i + 1 == VTableIndices.size())
302 ? vtable_components().size()
303 : VTableIndices[i + 1];
304 return nextIndex - thisIndex;
317 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
324 virtual void computeVTableRelatedInformation(
const CXXRecordDecl *RD) = 0;
331 computeVTableRelatedInformation(MD->
getParent());
335 ThunksMapTy::const_iterator I = Thunks.find(MD);
336 if (I == Thunks.end()) {
352 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
353 MethodVTableIndicesTy MethodVTableIndices;
356 std::unique_ptr<const VTableLayout>>
358 VTableLayoutMapTy VTableLayouts;
360 typedef std::pair<
const CXXRecordDecl *,
361 const CXXRecordDecl *> ClassPairTy;
367 typedef llvm::DenseMap<ClassPairTy, CharUnits>
368 VirtualBaseClassOffsetOffsetsMapTy;
369 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
371 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
378 computeVTableRelatedInformation(RD);
379 assert(VTableLayouts.count(RD) &&
"No layout for this record decl!");
381 return *VTableLayouts[RD];
384 std::unique_ptr<VTableLayout> createConstructionVTableLayout(
385 const CXXRecordDecl *MostDerivedClass,
CharUnits MostDerivedClassOffset,
386 bool MostDerivedClassIsVirtual,
const CXXRecordDecl *LayoutClass);
399 CharUnits getVirtualBaseOffsetOffset(
const CXXRecordDecl *RD,
400 const CXXRecordDecl *VBase);
414 : ObjectWithVPtr(RD), IntroducingObject(RD), NextBaseToMangle(RD) {}
455 return ContainingVBases.empty() ? nullptr : ContainingVBases.front();
490 : VBTableIndex(0), VBase(nullptr), VFPtrOffset(
CharUnits::
Zero()),
495 : VBTableIndex(VBTableIndex), VBase(VBase), VFPtrOffset(VFPtrOffset),
500 assert(VBase != other.
VBase);
503 return std::tie(VFPtrOffset, Index) <
514 typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
515 MethodVFTableLocationsTy;
516 MethodVFTableLocationsTy MethodVFTableLocations;
518 typedef llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VPtrInfoVector>>
520 VFPtrLocationsMapTy VFPtrLocations;
522 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
523 typedef llvm::DenseMap<VFTableIdTy, std::unique_ptr<const VTableLayout>>
525 VFTableLayoutMapTy VFTableLayouts;
527 llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VirtualBaseInfo>>
532 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
535 const MethodVFTableLocationsTy &NewMethods,
541 void computeVTablePaths(
bool ForVBTables,
const CXXRecordDecl *RD,
542 VPtrInfoVector &Paths);
550 const VPtrInfoVector &getVFPtrOffsets(
const CXXRecordDecl *RD);
559 if (isa<CXXDestructorDecl>(GD.
getDecl()) &&
572 const VPtrInfoVector &enumerateVBTables(
const CXXRecordDecl *RD);
size_t getNumVTables() const
bool isFunctionPointerKind() const
const AddressPointsMapTy & getAddressPoints() 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)
CharUnits VFPtrOffset
This is the offset of the vfptr from the start of the last vbase, or the complete type if there are n...
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
const CXXRecordDecl * VBase
If nonnull, holds the last vbase which contains the vfptr that the method definition is adjusted to...
static VTableComponent MakeVCallOffset(CharUnits Offset)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool Zero(InterpState &S, CodePtr OpPC)
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...
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)
BasePath ContainingVBases
The set of possibly indirect vbases that contain this vbtable.
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.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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
const CXXDestructorDecl * getDestructorDecl() const
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
The result type of a method or function.
SmallVector< const CXXRecordDecl *, 1 > BasePath
const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD) override
GlobalDecl - represents a global declaration.
ArrayRef< VTableThunkTy > vtable_thunks() const
virtual ~VTableContextBase()
uint64_t VBTableIndex
If nonzero, holds the vbtable index of the virtual base with the vfptr.
bool operator<(const MethodVFTableLocation &other) const
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.
uint64_t Index
Method's index in the vftable.
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
const CXXRecordDecl * getParent() const
Return 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...
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)