Coverage Report

Created: 2018-09-23 22:08

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