VTableBuilder.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- VTableBuilder.h - C++ vtable layout builder --------------*- C++ -*-=//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This contains code dealing with generation of the layout of virtual tables.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_VTABLEBUILDER_H
  18. #define LLVM_CLANG_AST_VTABLEBUILDER_H
  19. #include "clang/AST/BaseSubobject.h"
  20. #include "clang/AST/CXXInheritance.h"
  21. #include "clang/AST/GlobalDecl.h"
  22. #include "clang/AST/RecordLayout.h"
  23. #include "clang/Basic/ABI.h"
  24. #include "clang/Basic/Thunk.h"
  25. #include "llvm/ADT/DenseMap.h"
  26. #include <memory>
  27. #include <utility>
  28. namespace clang {
  29. class CXXRecordDecl;
  30. /// Represents a single component in a vtable.
  31. class VTableComponent {
  32. public:
  33. enum Kind {
  34. CK_VCallOffset,
  35. CK_VBaseOffset,
  36. CK_OffsetToTop,
  37. CK_RTTI,
  38. CK_FunctionPointer,
  39. /// A pointer to the complete destructor.
  40. CK_CompleteDtorPointer,
  41. /// A pointer to the deleting destructor.
  42. CK_DeletingDtorPointer,
  43. /// An entry that is never used.
  44. ///
  45. /// In some cases, a vtable function pointer will end up never being
  46. /// called. Such vtable function pointers are represented as a
  47. /// CK_UnusedFunctionPointer.
  48. CK_UnusedFunctionPointer
  49. };
  50. VTableComponent() = default;
  51. static VTableComponent MakeVCallOffset(CharUnits Offset) {
  52. return VTableComponent(CK_VCallOffset, Offset);
  53. }
  54. static VTableComponent MakeVBaseOffset(CharUnits Offset) {
  55. return VTableComponent(CK_VBaseOffset, Offset);
  56. }
  57. static VTableComponent MakeOffsetToTop(CharUnits Offset) {
  58. return VTableComponent(CK_OffsetToTop, Offset);
  59. }
  60. static VTableComponent MakeRTTI(const CXXRecordDecl *RD) {
  61. return VTableComponent(CK_RTTI, reinterpret_cast<uintptr_t>(RD));
  62. }
  63. static VTableComponent MakeFunction(const CXXMethodDecl *MD) {
  64. assert(!isa<CXXDestructorDecl>(MD) &&
  65. "Don't use MakeFunction with destructors!");
  66. return VTableComponent(CK_FunctionPointer,
  67. reinterpret_cast<uintptr_t>(MD));
  68. }
  69. static VTableComponent MakeCompleteDtor(const CXXDestructorDecl *DD) {
  70. return VTableComponent(CK_CompleteDtorPointer,
  71. reinterpret_cast<uintptr_t>(DD));
  72. }
  73. static VTableComponent MakeDeletingDtor(const CXXDestructorDecl *DD) {
  74. return VTableComponent(CK_DeletingDtorPointer,
  75. reinterpret_cast<uintptr_t>(DD));
  76. }
  77. static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD) {
  78. assert(!isa<CXXDestructorDecl>(MD) &&
  79. "Don't use MakeUnusedFunction with destructors!");
  80. return VTableComponent(CK_UnusedFunctionPointer,
  81. reinterpret_cast<uintptr_t>(MD));
  82. }
  83. /// Get the kind of this vtable component.
  84. Kind getKind() const {
  85. return (Kind)(Value & 0x7);
  86. }
  87. CharUnits getVCallOffset() const {
  88. assert(getKind() == CK_VCallOffset && "Invalid component kind!");
  89. return getOffset();
  90. }
  91. CharUnits getVBaseOffset() const {
  92. assert(getKind() == CK_VBaseOffset && "Invalid component kind!");
  93. return getOffset();
  94. }
  95. CharUnits getOffsetToTop() const {
  96. assert(getKind() == CK_OffsetToTop && "Invalid component kind!");
  97. return getOffset();
  98. }
  99. const CXXRecordDecl *getRTTIDecl() const {
  100. assert(isRTTIKind() && "Invalid component kind!");
  101. return reinterpret_cast<CXXRecordDecl *>(getPointer());
  102. }
  103. const CXXMethodDecl *getFunctionDecl() const {
  104. assert(isFunctionPointerKind() && "Invalid component kind!");
  105. if (isDestructorKind())
  106. return getDestructorDecl();
  107. return reinterpret_cast<CXXMethodDecl *>(getPointer());
  108. }
  109. const CXXDestructorDecl *getDestructorDecl() const {
  110. assert(isDestructorKind() && "Invalid component kind!");
  111. return reinterpret_cast<CXXDestructorDecl *>(getPointer());
  112. }
  113. const CXXMethodDecl *getUnusedFunctionDecl() const {
  114. assert(getKind() == CK_UnusedFunctionPointer && "Invalid component kind!");
  115. return reinterpret_cast<CXXMethodDecl *>(getPointer());
  116. }
  117. bool isDestructorKind() const { return isDestructorKind(getKind()); }
  118. bool isUsedFunctionPointerKind() const {
  119. return isUsedFunctionPointerKind(getKind());
  120. }
  121. bool isFunctionPointerKind() const {
  122. return isFunctionPointerKind(getKind());
  123. }
  124. bool isRTTIKind() const { return isRTTIKind(getKind()); }
  125. GlobalDecl getGlobalDecl() const {
  126. assert(isUsedFunctionPointerKind() &&
  127. "GlobalDecl can be created only from virtual function");
  128. auto *DtorDecl = dyn_cast<CXXDestructorDecl>(getFunctionDecl());
  129. switch (getKind()) {
  130. case CK_FunctionPointer:
  131. return GlobalDecl(getFunctionDecl());
  132. case CK_CompleteDtorPointer:
  133. return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
  134. case CK_DeletingDtorPointer:
  135. return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
  136. case CK_VCallOffset:
  137. case CK_VBaseOffset:
  138. case CK_OffsetToTop:
  139. case CK_RTTI:
  140. case CK_UnusedFunctionPointer:
  141. llvm_unreachable("Only function pointers kinds");
  142. }
  143. llvm_unreachable("Should already return");
  144. }
  145. private:
  146. static bool isFunctionPointerKind(Kind ComponentKind) {
  147. return isUsedFunctionPointerKind(ComponentKind) ||
  148. ComponentKind == CK_UnusedFunctionPointer;
  149. }
  150. static bool isUsedFunctionPointerKind(Kind ComponentKind) {
  151. return ComponentKind == CK_FunctionPointer ||
  152. isDestructorKind(ComponentKind);
  153. }
  154. static bool isDestructorKind(Kind ComponentKind) {
  155. return ComponentKind == CK_CompleteDtorPointer ||
  156. ComponentKind == CK_DeletingDtorPointer;
  157. }
  158. static bool isRTTIKind(Kind ComponentKind) {
  159. return ComponentKind == CK_RTTI;
  160. }
  161. VTableComponent(Kind ComponentKind, CharUnits Offset) {
  162. assert((ComponentKind == CK_VCallOffset ||
  163. ComponentKind == CK_VBaseOffset ||
  164. ComponentKind == CK_OffsetToTop) && "Invalid component kind!");
  165. assert(Offset.getQuantity() < (1LL << 56) && "Offset is too big!");
  166. assert(Offset.getQuantity() >= -(1LL << 56) && "Offset is too small!");
  167. Value = (uint64_t(Offset.getQuantity()) << 3) | ComponentKind;
  168. }
  169. VTableComponent(Kind ComponentKind, uintptr_t Ptr) {
  170. assert((isRTTIKind(ComponentKind) || isFunctionPointerKind(ComponentKind)) &&
  171. "Invalid component kind!");
  172. assert((Ptr & 7) == 0 && "Pointer not sufficiently aligned!");
  173. Value = Ptr | ComponentKind;
  174. }
  175. CharUnits getOffset() const {
  176. assert((getKind() == CK_VCallOffset || getKind() == CK_VBaseOffset ||
  177. getKind() == CK_OffsetToTop) && "Invalid component kind!");
  178. return CharUnits::fromQuantity(Value >> 3);
  179. }
  180. uintptr_t getPointer() const {
  181. assert((getKind() == CK_RTTI || isFunctionPointerKind()) &&
  182. "Invalid component kind!");
  183. return static_cast<uintptr_t>(Value & ~7ULL);
  184. }
  185. /// The kind is stored in the lower 3 bits of the value. For offsets, we
  186. /// make use of the facts that classes can't be larger than 2^55 bytes,
  187. /// so we store the offset in the lower part of the 61 bits that remain.
  188. /// (The reason that we're not simply using a PointerIntPair here is that we
  189. /// need the offsets to be 64-bit, even when on a 32-bit machine).
  190. int64_t Value;
  191. };
  192. class VTableLayout {
  193. public:
  194. typedef std::pair<uint64_t, ThunkInfo> VTableThunkTy;
  195. struct AddressPointLocation {
  196. unsigned VTableIndex, AddressPointIndex;
  197. };
  198. typedef llvm::DenseMap<BaseSubobject, AddressPointLocation>
  199. AddressPointsMapTy;
  200. // Mapping between the VTable index and address point index. This is useful
  201. // when you don't care about the base subobjects and only want the address
  202. // point for a given vtable index.
  203. typedef llvm::SmallVector<unsigned, 4> AddressPointsIndexMapTy;
  204. private:
  205. // Stores the component indices of the first component of each virtual table in
  206. // the virtual table group. To save a little memory in the common case where
  207. // the vtable group contains a single vtable, an empty vector here represents
  208. // the vector {0}.
  209. OwningArrayRef<size_t> VTableIndices;
  210. OwningArrayRef<VTableComponent> VTableComponents;
  211. /// Contains thunks needed by vtables, sorted by indices.
  212. OwningArrayRef<VTableThunkTy> VTableThunks;
  213. /// Address points for all vtables.
  214. AddressPointsMapTy AddressPoints;
  215. /// Address points for all vtable indices.
  216. AddressPointsIndexMapTy AddressPointIndices;
  217. public:
  218. VTableLayout(ArrayRef<size_t> VTableIndices,
  219. ArrayRef<VTableComponent> VTableComponents,
  220. ArrayRef<VTableThunkTy> VTableThunks,
  221. const AddressPointsMapTy &AddressPoints);
  222. ~VTableLayout();
  223. ArrayRef<VTableComponent> vtable_components() const {
  224. return VTableComponents;
  225. }
  226. ArrayRef<VTableThunkTy> vtable_thunks() const {
  227. return VTableThunks;
  228. }
  229. AddressPointLocation getAddressPoint(BaseSubobject Base) const {
  230. assert(AddressPoints.count(Base) && "Did not find address point!");
  231. return AddressPoints.find(Base)->second;
  232. }
  233. const AddressPointsMapTy &getAddressPoints() const {
  234. return AddressPoints;
  235. }
  236. const AddressPointsIndexMapTy &getAddressPointIndices() const {
  237. return AddressPointIndices;
  238. }
  239. size_t getNumVTables() const {
  240. if (VTableIndices.empty())
  241. return 1;
  242. return VTableIndices.size();
  243. }
  244. size_t getVTableOffset(size_t i) const {
  245. if (VTableIndices.empty()) {
  246. assert(i == 0);
  247. return 0;
  248. }
  249. return VTableIndices[i];
  250. }
  251. size_t getVTableSize(size_t i) const {
  252. if (VTableIndices.empty()) {
  253. assert(i == 0);
  254. return vtable_components().size();
  255. }
  256. size_t thisIndex = VTableIndices[i];
  257. size_t nextIndex = (i + 1 == VTableIndices.size())
  258. ? vtable_components().size()
  259. : VTableIndices[i + 1];
  260. return nextIndex - thisIndex;
  261. }
  262. };
  263. class VTableContextBase {
  264. public:
  265. typedef SmallVector<ThunkInfo, 1> ThunkInfoVectorTy;
  266. bool isMicrosoft() const { return IsMicrosoftABI; }
  267. virtual ~VTableContextBase() {}
  268. protected:
  269. typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy> ThunksMapTy;
  270. /// Contains all thunks that a given method decl will need.
  271. ThunksMapTy Thunks;
  272. /// Compute and store all vtable related information (vtable layout, vbase
  273. /// offset offsets, thunks etc) for the given record decl.
  274. virtual void computeVTableRelatedInformation(const CXXRecordDecl *RD) = 0;
  275. VTableContextBase(bool MS) : IsMicrosoftABI(MS) {}
  276. public:
  277. virtual const ThunkInfoVectorTy *getThunkInfo(GlobalDecl GD) {
  278. const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl()->getCanonicalDecl());
  279. computeVTableRelatedInformation(MD->getParent());
  280. // This assumes that all the destructors present in the vtable
  281. // use exactly the same set of thunks.
  282. ThunksMapTy::const_iterator I = Thunks.find(MD);
  283. if (I == Thunks.end()) {
  284. // We did not find a thunk for this method.
  285. return nullptr;
  286. }
  287. return &I->second;
  288. }
  289. bool IsMicrosoftABI;
  290. /// Determine whether this function should be assigned a vtable slot.
  291. static bool hasVtableSlot(const CXXMethodDecl *MD);
  292. };
  293. class ItaniumVTableContext : public VTableContextBase {
  294. private:
  295. /// Contains the index (relative to the vtable address point)
  296. /// where the function pointer for a virtual function is stored.
  297. typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
  298. MethodVTableIndicesTy MethodVTableIndices;
  299. typedef llvm::DenseMap<const CXXRecordDecl *,
  300. std::unique_ptr<const VTableLayout>>
  301. VTableLayoutMapTy;
  302. VTableLayoutMapTy VTableLayouts;
  303. typedef std::pair<const CXXRecordDecl *,
  304. const CXXRecordDecl *> ClassPairTy;
  305. /// vtable offsets for offsets of virtual bases of a class.
  306. ///
  307. /// Contains the vtable offset (relative to the address point) in chars
  308. /// where the offsets for virtual bases of a class are stored.
  309. typedef llvm::DenseMap<ClassPairTy, CharUnits>
  310. VirtualBaseClassOffsetOffsetsMapTy;
  311. VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
  312. void computeVTableRelatedInformation(const CXXRecordDecl *RD) override;
  313. public:
  314. enum VTableComponentLayout {
  315. /// Components in the vtable are pointers to other structs/functions.
  316. Pointer,
  317. /// Components in the vtable are relative offsets between the vtable and the
  318. /// other structs/functions.
  319. Relative,
  320. };
  321. ItaniumVTableContext(ASTContext &Context,
  322. VTableComponentLayout ComponentLayout = Pointer);
  323. ~ItaniumVTableContext() override;
  324. const VTableLayout &getVTableLayout(const CXXRecordDecl *RD) {
  325. computeVTableRelatedInformation(RD);
  326. assert(VTableLayouts.count(RD) && "No layout for this record decl!");
  327. return *VTableLayouts[RD];
  328. }
  329. std::unique_ptr<VTableLayout> createConstructionVTableLayout(
  330. const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset,
  331. bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass);
  332. /// Locate a virtual function in the vtable.
  333. ///
  334. /// Return the index (relative to the vtable address point) where the
  335. /// function pointer for the given virtual function is stored.
  336. uint64_t getMethodVTableIndex(GlobalDecl GD);
  337. /// Return the offset in chars (relative to the vtable address point) where
  338. /// the offset of the virtual base that contains the given base is stored,
  339. /// otherwise, if no virtual base contains the given class, return 0.
  340. ///
  341. /// Base must be a virtual base class or an unambiguous base.
  342. CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
  343. const CXXRecordDecl *VBase);
  344. static bool classof(const VTableContextBase *VT) {
  345. return !VT->isMicrosoft();
  346. }
  347. VTableComponentLayout getVTableComponentLayout() const {
  348. return ComponentLayout;
  349. }
  350. bool isPointerLayout() const { return ComponentLayout == Pointer; }
  351. bool isRelativeLayout() const { return ComponentLayout == Relative; }
  352. private:
  353. VTableComponentLayout ComponentLayout;
  354. };
  355. /// Holds information about the inheritance path to a virtual base or function
  356. /// table pointer. A record may contain as many vfptrs or vbptrs as there are
  357. /// base subobjects.
  358. struct VPtrInfo {
  359. typedef SmallVector<const CXXRecordDecl *, 1> BasePath;
  360. VPtrInfo(const CXXRecordDecl *RD)
  361. : ObjectWithVPtr(RD), IntroducingObject(RD), NextBaseToMangle(RD) {}
  362. /// This is the most derived class that has this vptr at offset zero. When
  363. /// single inheritance is used, this is always the most derived class. If
  364. /// multiple inheritance is used, it may be any direct or indirect base.
  365. const CXXRecordDecl *ObjectWithVPtr;
  366. /// This is the class that introduced the vptr by declaring new virtual
  367. /// methods or virtual bases.
  368. const CXXRecordDecl *IntroducingObject;
  369. /// IntroducingObject is at this offset from its containing complete object or
  370. /// virtual base.
  371. CharUnits NonVirtualOffset;
  372. /// The bases from the inheritance path that got used to mangle the vbtable
  373. /// name. This is not really a full path like a CXXBasePath. It holds the
  374. /// subset of records that need to be mangled into the vbtable symbol name in
  375. /// order to get a unique name.
  376. BasePath MangledPath;
  377. /// The next base to push onto the mangled path if this path is ambiguous in a
  378. /// derived class. If it's null, then it's already been pushed onto the path.
  379. const CXXRecordDecl *NextBaseToMangle;
  380. /// The set of possibly indirect vbases that contain this vbtable. When a
  381. /// derived class indirectly inherits from the same vbase twice, we only keep
  382. /// vtables and their paths from the first instance.
  383. BasePath ContainingVBases;
  384. /// This holds the base classes path from the complete type to the first base
  385. /// with the given vfptr offset, in the base-to-derived order. Only used for
  386. /// vftables.
  387. BasePath PathToIntroducingObject;
  388. /// Static offset from the top of the most derived class to this vfptr,
  389. /// including any virtual base offset. Only used for vftables.
  390. CharUnits FullOffsetInMDC;
  391. /// The vptr is stored inside the non-virtual component of this virtual base.
  392. const CXXRecordDecl *getVBaseWithVPtr() const {
  393. return ContainingVBases.empty() ? nullptr : ContainingVBases.front();
  394. }
  395. };
  396. typedef SmallVector<std::unique_ptr<VPtrInfo>, 2> VPtrInfoVector;
  397. /// All virtual base related information about a given record decl. Includes
  398. /// information on all virtual base tables and the path components that are used
  399. /// to mangle them.
  400. struct VirtualBaseInfo {
  401. /// A map from virtual base to vbtable index for doing a conversion from the
  402. /// the derived class to the a base.
  403. llvm::DenseMap<const CXXRecordDecl *, unsigned> VBTableIndices;
  404. /// Information on all virtual base tables used when this record is the most
  405. /// derived class.
  406. VPtrInfoVector VBPtrPaths;
  407. };
  408. struct MethodVFTableLocation {
  409. /// If nonzero, holds the vbtable index of the virtual base with the vfptr.
  410. uint64_t VBTableIndex;
  411. /// If nonnull, holds the last vbase which contains the vfptr that the
  412. /// method definition is adjusted to.
  413. const CXXRecordDecl *VBase;
  414. /// This is the offset of the vfptr from the start of the last vbase, or the
  415. /// complete type if there are no virtual bases.
  416. CharUnits VFPtrOffset;
  417. /// Method's index in the vftable.
  418. uint64_t Index;
  419. MethodVFTableLocation()
  420. : VBTableIndex(0), VBase(nullptr), VFPtrOffset(CharUnits::Zero()),
  421. Index(0) {}
  422. MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase,
  423. CharUnits VFPtrOffset, uint64_t Index)
  424. : VBTableIndex(VBTableIndex), VBase(VBase), VFPtrOffset(VFPtrOffset),
  425. Index(Index) {}
  426. bool operator<(const MethodVFTableLocation &other) const {
  427. if (VBTableIndex != other.VBTableIndex) {
  428. assert(VBase != other.VBase);
  429. return VBTableIndex < other.VBTableIndex;
  430. }
  431. return std::tie(VFPtrOffset, Index) <
  432. std::tie(other.VFPtrOffset, other.Index);
  433. }
  434. };
  435. class MicrosoftVTableContext : public VTableContextBase {
  436. public:
  437. private:
  438. ASTContext &Context;
  439. typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
  440. MethodVFTableLocationsTy;
  441. MethodVFTableLocationsTy MethodVFTableLocations;
  442. typedef llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VPtrInfoVector>>
  443. VFPtrLocationsMapTy;
  444. VFPtrLocationsMapTy VFPtrLocations;
  445. typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
  446. typedef llvm::DenseMap<VFTableIdTy, std::unique_ptr<const VTableLayout>>
  447. VFTableLayoutMapTy;
  448. VFTableLayoutMapTy VFTableLayouts;
  449. llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VirtualBaseInfo>>
  450. VBaseInfo;
  451. void enumerateVFPtrs(const CXXRecordDecl *ForClass, VPtrInfoVector &Result);
  452. void computeVTableRelatedInformation(const CXXRecordDecl *RD) override;
  453. void dumpMethodLocations(const CXXRecordDecl *RD,
  454. const MethodVFTableLocationsTy &NewMethods,
  455. raw_ostream &);
  456. const VirtualBaseInfo &
  457. computeVBTableRelatedInformation(const CXXRecordDecl *RD);
  458. void computeVTablePaths(bool ForVBTables, const CXXRecordDecl *RD,
  459. VPtrInfoVector &Paths);
  460. public:
  461. MicrosoftVTableContext(ASTContext &Context)
  462. : VTableContextBase(/*MS=*/true), Context(Context) {}
  463. ~MicrosoftVTableContext() override;
  464. const VPtrInfoVector &getVFPtrOffsets(const CXXRecordDecl *RD);
  465. const VTableLayout &getVFTableLayout(const CXXRecordDecl *RD,
  466. CharUnits VFPtrOffset);
  467. MethodVFTableLocation getMethodVFTableLocation(GlobalDecl GD);
  468. const ThunkInfoVectorTy *getThunkInfo(GlobalDecl GD) override {
  469. // Complete destructors don't have a slot in a vftable, so no thunks needed.
  470. if (isa<CXXDestructorDecl>(GD.getDecl()) &&
  471. GD.getDtorType() == Dtor_Complete)
  472. return nullptr;
  473. return VTableContextBase::getThunkInfo(GD);
  474. }
  475. /// Returns the index of VBase in the vbtable of Derived.
  476. /// VBase must be a morally virtual base of Derived.
  477. /// The vbtable is an array of i32 offsets. The first entry is a self entry,
  478. /// and the rest are offsets from the vbptr to virtual bases.
  479. unsigned getVBTableIndex(const CXXRecordDecl *Derived,
  480. const CXXRecordDecl *VBase);
  481. const VPtrInfoVector &enumerateVBTables(const CXXRecordDecl *RD);
  482. static bool classof(const VTableContextBase *VT) { return VT->isMicrosoft(); }
  483. };
  484. } // namespace clang
  485. #endif
  486. #ifdef __GNUC__
  487. #pragma GCC diagnostic pop
  488. #endif