diff options
| author | Anders Carlsson <andersca@mac.com> | 2010-02-16 16:02:57 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2010-02-16 16:02:57 +0000 |
| commit | 14157939ab9264ae92c667022bb4f24cba3c3bcb (patch) | |
| tree | 11152d607d38fa75a3ed7b7a50bb44113438fd29 /clang/lib | |
| parent | cbd43f89acea19925401398cf10d2c8e0f9b8b1f (diff) | |
| download | bcm5719-llvm-14157939ab9264ae92c667022bb4f24cba3c3bcb.tar.gz bcm5719-llvm-14157939ab9264ae92c667022bb4f24cba3c3bcb.zip | |
Fix a bug where we would not emit secondary vtables for bases of a primary base.
llvm-svn: 96351
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CGVtable.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CGVtable.cpp b/clang/lib/CodeGen/CGVtable.cpp index 970bbd777f1..6199c055b70 100644 --- a/clang/lib/CodeGen/CGVtable.cpp +++ b/clang/lib/CodeGen/CGVtable.cpp @@ -822,6 +822,10 @@ private: /// LayoutVtable - Layout a vtable and all its secondary vtables. void LayoutVtable(BaseSubobject Base); + /// LayoutSecondaryVtables - Layout the secondary vtables for the given base + /// subobject. + void LayoutSecondaryVtables(BaseSubobject Base); + public: VtableBuilder(CGVtableInfo &VtableInfo, const CXXRecordDecl *MostDerivedClass) : VtableInfo(VtableInfo), MostDerivedClass(MostDerivedClass), @@ -1070,36 +1074,49 @@ void VtableBuilder::LayoutVtable(BaseSubobject Base) { AddressPoints.insert(std::make_pair(PrimaryBase, AddressPoint)); } + // Layout secondary vtables. + LayoutSecondaryVtables(Base); + + // FIXME: Emit vtables for virtual bases here. +} + +void VtableBuilder::LayoutSecondaryVtables(BaseSubobject Base) { + // Itanium C++ ABI 2.5.2: + // Following the primary virtual table of a derived class are secondary + // virtual tables for each of its proper base classes, except any primary + // base(s) with which it shares its primary virtual table. + + const CXXRecordDecl *RD = Base.getBase(); const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); - - // Layout secondary vtables. + for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(), E = RD->bases_end(); I != E; ++I) { + // Ignore virtual bases, we'll emit them later. + if (I->isVirtual()) + continue; + const CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl()); // Ignore bases that don't have a vtable. if (!BaseDecl->isDynamicClass()) continue; - - // Ignore the primary base. - if (BaseDecl == PrimaryBase) - continue; - // Ignore virtual bases, we'll emit them later. - if (I->isVirtual()) - continue; - // Get the base offset of this base. uint64_t BaseOffset = Base.getBaseOffset() + Layout.getBaseClassOffset(BaseDecl); + + // Don't emit a secondary vtable for a primary base. We might however want + // to emit secondary vtables for other bases of this base. + if (BaseDecl == PrimaryBase) { + LayoutSecondaryVtables(BaseSubobject(BaseDecl, BaseOffset)); + continue; + } // Layout this secondary vtable. LayoutVtable(BaseSubobject(BaseDecl, BaseOffset)); } - - // FIXME: Emit vtables for virtual bases here. } /// dumpLayout - Dump the vtable layout. |

