1 //===------ CXXInheritance.cpp - C++ Inheritance ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides routines that help analyzing C++ inheritance hierarchies.
12 //===----------------------------------------------------------------------===//
13 #include "clang/AST/CXXInheritance.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/RecordLayout.h"
17 #include "llvm/ADT/SetVector.h"
21 using namespace clang;
23 /// \brief Computes the set of declarations referenced by these base
25 void CXXBasePaths::ComputeDeclsFound() {
26 assert(NumDeclsFound == 0 && !DeclsFound &&
27 "Already computed the set of declarations");
29 llvm::SetVector<NamedDecl *, SmallVector<NamedDecl *, 8> > Decls;
30 for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path)
31 Decls.insert(Path->Decls.front());
33 NumDeclsFound = Decls.size();
34 DeclsFound = new NamedDecl * [NumDeclsFound];
35 std::copy(Decls.begin(), Decls.end(), DeclsFound);
38 CXXBasePaths::decl_iterator CXXBasePaths::found_decls_begin() {
39 if (NumDeclsFound == 0)
44 CXXBasePaths::decl_iterator CXXBasePaths::found_decls_end() {
45 if (NumDeclsFound == 0)
47 return DeclsFound + NumDeclsFound;
50 /// isAmbiguous - Determines whether the set of paths provided is
51 /// ambiguous, i.e., there are two or more paths that refer to
52 /// different base class subobjects of the same type. BaseType must be
53 /// an unqualified, canonical class type.
54 bool CXXBasePaths::isAmbiguous(CanQualType BaseType) {
55 BaseType = BaseType.getUnqualifiedType();
56 std::pair<bool, unsigned>& Subobjects = ClassSubobjects[BaseType];
57 return Subobjects.second + (Subobjects.first? 1 : 0) > 1;
60 /// clear - Clear out all prior path information.
61 void CXXBasePaths::clear() {
63 ClassSubobjects.clear();
68 /// @brief Swaps the contents of this CXXBasePaths structure with the
69 /// contents of Other.
70 void CXXBasePaths::swap(CXXBasePaths &Other) {
71 std::swap(Origin, Other.Origin);
72 Paths.swap(Other.Paths);
73 ClassSubobjects.swap(Other.ClassSubobjects);
74 std::swap(FindAmbiguities, Other.FindAmbiguities);
75 std::swap(RecordPaths, Other.RecordPaths);
76 std::swap(DetectVirtual, Other.DetectVirtual);
77 std::swap(DetectedVirtual, Other.DetectedVirtual);
80 bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base) const {
81 CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false,
82 /*DetectVirtual=*/false);
83 return isDerivedFrom(Base, Paths);
86 bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
87 CXXBasePaths &Paths) const {
88 if (getCanonicalDecl() == Base->getCanonicalDecl())
91 Paths.setOrigin(const_cast<CXXRecordDecl*>(this));
92 return lookupInBases(&FindBaseClass,
93 const_cast<CXXRecordDecl*>(Base->getCanonicalDecl()),
97 bool CXXRecordDecl::isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const {
101 CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false,
102 /*DetectVirtual=*/false);
104 if (getCanonicalDecl() == Base->getCanonicalDecl())
107 Paths.setOrigin(const_cast<CXXRecordDecl*>(this));
109 const void *BasePtr = static_cast<const void*>(Base->getCanonicalDecl());
110 return lookupInBases(&FindVirtualBaseClass,
111 const_cast<void *>(BasePtr),
115 static bool BaseIsNot(const CXXRecordDecl *Base, void *OpaqueTarget) {
116 // OpaqueTarget is a CXXRecordDecl*.
117 return Base->getCanonicalDecl() != (const CXXRecordDecl*) OpaqueTarget;
120 bool CXXRecordDecl::isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const {
121 return forallBases(BaseIsNot,
122 const_cast<CXXRecordDecl *>(Base->getCanonicalDecl()));
126 CXXRecordDecl::isCurrentInstantiation(const DeclContext *CurContext) const {
127 assert(isDependentContext());
129 for (; !CurContext->isFileContext(); CurContext = CurContext->getParent())
130 if (CurContext->Equals(this))
136 bool CXXRecordDecl::forallBases(ForallBasesCallback *BaseMatches,
138 bool AllowShortCircuit) const {
139 SmallVector<const CXXRecordDecl*, 8> Queue;
141 const CXXRecordDecl *Record = this;
142 bool AllMatches = true;
144 for (CXXRecordDecl::base_class_const_iterator
145 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) {
146 const RecordType *Ty = I->getType()->getAs<RecordType>();
148 if (AllowShortCircuit) return false;
153 CXXRecordDecl *Base =
154 cast_or_null<CXXRecordDecl>(Ty->getDecl()->getDefinition());
156 (Base->isDependentContext() &&
157 !Base->isCurrentInstantiation(Record))) {
158 if (AllowShortCircuit) return false;
163 Queue.push_back(Base);
164 if (!BaseMatches(Base, OpaqueData)) {
165 if (AllowShortCircuit) return false;
171 if (Queue.empty()) break;
172 Record = Queue.back(); // not actually a queue.
179 bool CXXBasePaths::lookupInBases(ASTContext &Context,
180 const CXXRecordDecl *Record,
181 CXXRecordDecl::BaseMatchesCallback *BaseMatches,
183 bool FoundPath = false;
185 // The access of the path down to this record.
186 AccessSpecifier AccessToHere = ScratchPath.Access;
187 bool IsFirstStep = ScratchPath.empty();
189 for (CXXRecordDecl::base_class_const_iterator BaseSpec = Record->bases_begin(),
190 BaseSpecEnd = Record->bases_end();
191 BaseSpec != BaseSpecEnd;
193 // Find the record of the base class subobjects for this type.
194 QualType BaseType = Context.getCanonicalType(BaseSpec->getType())
195 .getUnqualifiedType();
198 // In the definition of a class template or a member of a class template,
199 // if a base class of the class template depends on a template-parameter,
200 // the base class scope is not examined during unqualified name lookup
201 // either at the point of definition of the class template or member or
202 // during an instantiation of the class tem- plate or member.
203 if (BaseType->isDependentType())
206 // Determine whether we need to visit this base class at all,
207 // updating the count of subobjects appropriately.
208 std::pair<bool, unsigned>& Subobjects = ClassSubobjects[BaseType];
209 bool VisitBase = true;
210 bool SetVirtual = false;
211 if (BaseSpec->isVirtual()) {
212 VisitBase = !Subobjects.first;
213 Subobjects.first = true;
214 if (isDetectingVirtual() && DetectedVirtual == 0) {
215 // If this is the first virtual we find, remember it. If it turns out
216 // there is no base path here, we'll reset it later.
217 DetectedVirtual = BaseType->getAs<RecordType>();
223 if (isRecordingPaths()) {
224 // Add this base specifier to the current path.
225 CXXBasePathElement Element;
226 Element.Base = &*BaseSpec;
227 Element.Class = Record;
228 if (BaseSpec->isVirtual())
229 Element.SubobjectNumber = 0;
231 Element.SubobjectNumber = Subobjects.second;
232 ScratchPath.push_back(Element);
234 // Calculate the "top-down" access to this base class.
235 // The spec actually describes this bottom-up, but top-down is
236 // equivalent because the definition works out as follows:
237 // 1. Write down the access along each step in the inheritance
238 // chain, followed by the access of the decl itself.
240 // class A { public: int foo; };
241 // class B : protected A {};
242 // class C : public B {};
243 // class D : private C {};
245 // private public protected public
246 // 2. If 'private' appears anywhere except far-left, access is denied.
247 // 3. Otherwise, overall access is determined by the most restrictive
248 // access in the sequence.
250 ScratchPath.Access = BaseSpec->getAccessSpecifier();
252 ScratchPath.Access = CXXRecordDecl::MergeAccess(AccessToHere,
253 BaseSpec->getAccessSpecifier());
256 // Track whether there's a path involving this specific base.
257 bool FoundPathThroughBase = false;
259 if (BaseMatches(BaseSpec, ScratchPath, UserData)) {
260 // We've found a path that terminates at this base.
261 FoundPath = FoundPathThroughBase = true;
262 if (isRecordingPaths()) {
263 // We have a path. Make a copy of it before moving on.
264 Paths.push_back(ScratchPath);
265 } else if (!isFindingAmbiguities()) {
266 // We found a path and we don't care about ambiguities;
267 // return immediately.
270 } else if (VisitBase) {
271 CXXRecordDecl *BaseRecord
272 = cast<CXXRecordDecl>(BaseSpec->getType()->castAs<RecordType>()
274 if (lookupInBases(Context, BaseRecord, BaseMatches, UserData)) {
275 // C++ [class.member.lookup]p2:
276 // A member name f in one sub-object B hides a member name f in
277 // a sub-object A if A is a base class sub-object of B. Any
278 // declarations that are so hidden are eliminated from
281 // There is a path to a base class that meets the criteria. If we're
282 // not collecting paths or finding ambiguities, we're done.
283 FoundPath = FoundPathThroughBase = true;
284 if (!isFindingAmbiguities())
289 // Pop this base specifier off the current path (if we're
290 // collecting paths).
291 if (isRecordingPaths()) {
292 ScratchPath.pop_back();
295 // If we set a virtual earlier, and this isn't a path, forget it again.
296 if (SetVirtual && !FoundPathThroughBase) {
301 // Reset the scratch path access.
302 ScratchPath.Access = AccessToHere;
307 bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
309 CXXBasePaths &Paths) const {
310 // If we didn't find anything, report that.
311 if (!Paths.lookupInBases(getASTContext(), this, BaseMatches, UserData))
314 // If we're not recording paths or we won't ever find ambiguities,
316 if (!Paths.isRecordingPaths() || !Paths.isFindingAmbiguities())
319 // C++ [class.member.lookup]p6:
320 // When virtual base classes are used, a hidden declaration can be
321 // reached along a path through the sub-object lattice that does
322 // not pass through the hiding declaration. This is not an
323 // ambiguity. The identical use with nonvirtual base classes is an
324 // ambiguity; in that case there is no unique instance of the name
325 // that hides all the others.
327 // FIXME: This is an O(N^2) algorithm, but DPG doesn't see an easy
328 // way to make it any faster.
329 for (CXXBasePaths::paths_iterator P = Paths.begin(), PEnd = Paths.end();
330 P != PEnd; /* increment in loop */) {
333 for (CXXBasePath::iterator PE = P->begin(), PEEnd = P->end();
334 PE != PEEnd && !Hidden; ++PE) {
335 if (PE->Base->isVirtual()) {
336 CXXRecordDecl *VBase = 0;
337 if (const RecordType *Record = PE->Base->getType()->getAs<RecordType>())
338 VBase = cast<CXXRecordDecl>(Record->getDecl());
342 // The declaration(s) we found along this path were found in a
343 // subobject of a virtual base. Check whether this virtual
344 // base is a subobject of any other path; if so, then the
345 // declaration in this path are hidden by that patch.
346 for (CXXBasePaths::paths_iterator HidingP = Paths.begin(),
347 HidingPEnd = Paths.end();
348 HidingP != HidingPEnd;
350 CXXRecordDecl *HidingClass = 0;
351 if (const RecordType *Record
352 = HidingP->back().Base->getType()->getAs<RecordType>())
353 HidingClass = cast<CXXRecordDecl>(Record->getDecl());
357 if (HidingClass->isVirtuallyDerivedFrom(VBase)) {
366 P = Paths.Paths.erase(P);
374 bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier *Specifier,
377 assert(((Decl *)BaseRecord)->getCanonicalDecl() == BaseRecord &&
378 "User data for FindBaseClass is not canonical!");
379 return Specifier->getType()->castAs<RecordType>()->getDecl()
380 ->getCanonicalDecl() == BaseRecord;
383 bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
386 assert(((Decl *)BaseRecord)->getCanonicalDecl() == BaseRecord &&
387 "User data for FindBaseClass is not canonical!");
388 return Specifier->isVirtual() &&
389 Specifier->getType()->castAs<RecordType>()->getDecl()
390 ->getCanonicalDecl() == BaseRecord;
393 bool CXXRecordDecl::FindTagMember(const CXXBaseSpecifier *Specifier,
396 RecordDecl *BaseRecord =
397 Specifier->getType()->castAs<RecordType>()->getDecl();
399 DeclarationName N = DeclarationName::getFromOpaquePtr(Name);
400 for (Path.Decls = BaseRecord->lookup(N);
402 Path.Decls = Path.Decls.slice(1)) {
403 if (Path.Decls.front()->isInIdentifierNamespace(IDNS_Tag))
410 bool CXXRecordDecl::FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
413 RecordDecl *BaseRecord =
414 Specifier->getType()->castAs<RecordType>()->getDecl();
416 const unsigned IDNS = IDNS_Ordinary | IDNS_Tag | IDNS_Member;
417 DeclarationName N = DeclarationName::getFromOpaquePtr(Name);
418 for (Path.Decls = BaseRecord->lookup(N);
420 Path.Decls = Path.Decls.slice(1)) {
421 if (Path.Decls.front()->isInIdentifierNamespace(IDNS))
429 FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
432 RecordDecl *BaseRecord =
433 Specifier->getType()->castAs<RecordType>()->getDecl();
435 DeclarationName N = DeclarationName::getFromOpaquePtr(Name);
436 for (Path.Decls = BaseRecord->lookup(N);
438 Path.Decls = Path.Decls.slice(1)) {
439 // FIXME: Refactor the "is it a nested-name-specifier?" check
440 if (isa<TypedefNameDecl>(Path.Decls.front()) ||
441 Path.Decls.front()->isInIdentifierNamespace(IDNS_Tag))
448 void OverridingMethods::add(unsigned OverriddenSubobject,
449 UniqueVirtualMethod Overriding) {
450 SmallVector<UniqueVirtualMethod, 4> &SubobjectOverrides
451 = Overrides[OverriddenSubobject];
452 if (std::find(SubobjectOverrides.begin(), SubobjectOverrides.end(),
453 Overriding) == SubobjectOverrides.end())
454 SubobjectOverrides.push_back(Overriding);
457 void OverridingMethods::add(const OverridingMethods &Other) {
458 for (const_iterator I = Other.begin(), IE = Other.end(); I != IE; ++I) {
459 for (overriding_const_iterator M = I->second.begin(),
460 MEnd = I->second.end();
467 void OverridingMethods::replaceAll(UniqueVirtualMethod Overriding) {
468 for (iterator I = begin(), IEnd = end(); I != IEnd; ++I) {
470 I->second.push_back(Overriding);
476 class FinalOverriderCollector {
477 /// \brief The number of subobjects of a given class type that
478 /// occur within the class hierarchy.
479 llvm::DenseMap<const CXXRecordDecl *, unsigned> SubobjectCount;
481 /// \brief Overriders for each virtual base subobject.
482 llvm::DenseMap<const CXXRecordDecl *, CXXFinalOverriderMap *> VirtualOverriders;
484 CXXFinalOverriderMap FinalOverriders;
487 ~FinalOverriderCollector();
489 void Collect(const CXXRecordDecl *RD, bool VirtualBase,
490 const CXXRecordDecl *InVirtualSubobject,
491 CXXFinalOverriderMap &Overriders);
495 void FinalOverriderCollector::Collect(const CXXRecordDecl *RD,
497 const CXXRecordDecl *InVirtualSubobject,
498 CXXFinalOverriderMap &Overriders) {
499 unsigned SubobjectNumber = 0;
502 = ++SubobjectCount[cast<CXXRecordDecl>(RD->getCanonicalDecl())];
504 for (CXXRecordDecl::base_class_const_iterator Base = RD->bases_begin(),
505 BaseEnd = RD->bases_end(); Base != BaseEnd; ++Base) {
506 if (const RecordType *RT = Base->getType()->getAs<RecordType>()) {
507 const CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(RT->getDecl());
508 if (!BaseDecl->isPolymorphic())
511 if (Overriders.empty() && !Base->isVirtual()) {
512 // There are no other overriders of virtual member functions,
513 // so let the base class fill in our overriders for us.
514 Collect(BaseDecl, false, InVirtualSubobject, Overriders);
518 // Collect all of the overridders from the base class subobject
519 // and merge them into the set of overridders for this class.
520 // For virtual base classes, populate or use the cached virtual
521 // overrides so that we do not walk the virtual base class (and
522 // its base classes) more than once.
523 CXXFinalOverriderMap ComputedBaseOverriders;
524 CXXFinalOverriderMap *BaseOverriders = &ComputedBaseOverriders;
525 if (Base->isVirtual()) {
526 CXXFinalOverriderMap *&MyVirtualOverriders = VirtualOverriders[BaseDecl];
527 BaseOverriders = MyVirtualOverriders;
528 if (!MyVirtualOverriders) {
529 MyVirtualOverriders = new CXXFinalOverriderMap;
531 // Collect may cause VirtualOverriders to reallocate, invalidating the
532 // MyVirtualOverriders reference. Set BaseOverriders to the right
534 BaseOverriders = MyVirtualOverriders;
536 Collect(BaseDecl, true, BaseDecl, *MyVirtualOverriders);
539 Collect(BaseDecl, false, InVirtualSubobject, ComputedBaseOverriders);
541 // Merge the overriders from this base class into our own set of
543 for (CXXFinalOverriderMap::iterator OM = BaseOverriders->begin(),
544 OMEnd = BaseOverriders->end();
547 const CXXMethodDecl *CanonOM
548 = cast<CXXMethodDecl>(OM->first->getCanonicalDecl());
549 Overriders[CanonOM].add(OM->second);
554 for (CXXRecordDecl::method_iterator M = RD->method_begin(),
555 MEnd = RD->method_end();
558 // We only care about virtual methods.
562 CXXMethodDecl *CanonM = cast<CXXMethodDecl>(M->getCanonicalDecl());
564 if (CanonM->begin_overridden_methods()
565 == CanonM->end_overridden_methods()) {
566 // This is a new virtual function that does not override any
567 // other virtual function. Add it to the map of virtual
568 // functions for which we are tracking overridders.
570 // C++ [class.virtual]p2:
571 // For convenience we say that any virtual function overrides itself.
572 Overriders[CanonM].add(SubobjectNumber,
573 UniqueVirtualMethod(CanonM, SubobjectNumber,
574 InVirtualSubobject));
578 // This virtual method overrides other virtual methods, so it does
579 // not add any new slots into the set of overriders. Instead, we
580 // replace entries in the set of overriders with the new
581 // overrider. To do so, we dig down to the original virtual
582 // functions using data recursion and update all of the methods it
584 typedef std::pair<CXXMethodDecl::method_iterator,
585 CXXMethodDecl::method_iterator> OverriddenMethods;
586 SmallVector<OverriddenMethods, 4> Stack;
587 Stack.push_back(std::make_pair(CanonM->begin_overridden_methods(),
588 CanonM->end_overridden_methods()));
589 while (!Stack.empty()) {
590 OverriddenMethods OverMethods = Stack.back();
593 for (; OverMethods.first != OverMethods.second; ++OverMethods.first) {
594 const CXXMethodDecl *CanonOM
595 = cast<CXXMethodDecl>((*OverMethods.first)->getCanonicalDecl());
597 // C++ [class.virtual]p2:
598 // A virtual member function C::vf of a class object S is
599 // a final overrider unless the most derived class (1.8)
600 // of which S is a base class subobject (if any) declares
601 // or inherits another member function that overrides vf.
603 // Treating this object like the most derived class, we
604 // replace any overrides from base classes with this
605 // overriding virtual function.
606 Overriders[CanonOM].replaceAll(
607 UniqueVirtualMethod(CanonM, SubobjectNumber,
608 InVirtualSubobject));
610 if (CanonOM->begin_overridden_methods()
611 == CanonOM->end_overridden_methods())
614 // Continue recursion to the methods that this virtual method
616 Stack.push_back(std::make_pair(CanonOM->begin_overridden_methods(),
617 CanonOM->end_overridden_methods()));
621 // C++ [class.virtual]p2:
622 // For convenience we say that any virtual function overrides itself.
623 Overriders[CanonM].add(SubobjectNumber,
624 UniqueVirtualMethod(CanonM, SubobjectNumber,
625 InVirtualSubobject));
629 FinalOverriderCollector::~FinalOverriderCollector() {
630 for (llvm::DenseMap<const CXXRecordDecl *, CXXFinalOverriderMap *>::iterator
631 VO = VirtualOverriders.begin(), VOEnd = VirtualOverriders.end();
638 CXXRecordDecl::getFinalOverriders(CXXFinalOverriderMap &FinalOverriders) const {
639 FinalOverriderCollector Collector;
640 Collector.Collect(this, false, 0, FinalOverriders);
642 // Weed out any final overriders that come from virtual base class
643 // subobjects that were hidden by other subobjects along any path.
644 // This is the final-overrider variant of C++ [class.member.lookup]p10.
645 for (CXXFinalOverriderMap::iterator OM = FinalOverriders.begin(),
646 OMEnd = FinalOverriders.end();
649 for (OverridingMethods::iterator SO = OM->second.begin(),
650 SOEnd = OM->second.end();
653 SmallVector<UniqueVirtualMethod, 4> &Overriding = SO->second;
654 if (Overriding.size() < 2)
657 for (SmallVector<UniqueVirtualMethod, 4>::iterator
658 Pos = Overriding.begin(), PosEnd = Overriding.end();
660 /* increment in loop */) {
661 if (!Pos->InVirtualSubobject) {
666 // We have an overriding method in a virtual base class
667 // subobject (or non-virtual base class subobject thereof);
668 // determine whether there exists an other overriding method
669 // in a base class subobject that hides the virtual base class
672 for (SmallVector<UniqueVirtualMethod, 4>::iterator
673 OP = Overriding.begin(), OPEnd = Overriding.end();
674 OP != OPEnd && !Hidden;
679 if (OP->Method->getParent()->isVirtuallyDerivedFrom(
680 const_cast<CXXRecordDecl *>(Pos->InVirtualSubobject)))
685 // The current overriding function is hidden by another
686 // overriding function; remove this one.
687 Pos = Overriding.erase(Pos);
688 PosEnd = Overriding.end();
698 AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext &Context,
699 CXXIndirectPrimaryBaseSet& Bases) {
700 // If the record has a virtual primary base class, add it to our set.
701 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
702 if (Layout.isPrimaryBaseVirtual())
703 Bases.insert(Layout.getPrimaryBase());
705 for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
706 E = RD->bases_end(); I != E; ++I) {
707 assert(!I->getType()->isDependentType() &&
708 "Cannot get indirect primary bases for class with dependent bases.");
710 const CXXRecordDecl *BaseDecl =
711 cast<CXXRecordDecl>(I->getType()->castAs<RecordType>()->getDecl());
713 // Only bases with virtual bases participate in computing the
714 // indirect primary virtual base classes.
715 if (BaseDecl->getNumVBases())
716 AddIndirectPrimaryBases(BaseDecl, Context, Bases);
722 CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
723 ASTContext &Context = getASTContext();
728 for (CXXRecordDecl::base_class_const_iterator I = bases_begin(),
729 E = bases_end(); I != E; ++I) {
730 assert(!I->getType()->isDependentType() &&
731 "Cannot get indirect primary bases for class with dependent bases.");
733 const CXXRecordDecl *BaseDecl =
734 cast<CXXRecordDecl>(I->getType()->castAs<RecordType>()->getDecl());
736 // Only bases with virtual bases participate in computing the
737 // indirect primary virtual base classes.
738 if (BaseDecl->getNumVBases())
739 AddIndirectPrimaryBases(BaseDecl, Context, Bases);