diff options
author | Anders Carlsson <andersca@mac.com> | 2009-12-16 17:27:20 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-12-16 17:27:20 +0000 |
commit | 4b3e5be334c93c3f48af2a49c0ea7cd9bae2a0e5 (patch) | |
tree | d80e930c0c6b6dd379d55c636a3faa2c06fd7f67 /lib/CodeGen/CGRecordLayoutBuilder.cpp | |
parent | 666183674f6e1b7e7530121f4897f77c43d2f741 (diff) |
Baby steps towards fixing PR5589. If a class needs a vtable pointer, add one.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91545 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGRecordLayoutBuilder.cpp')
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 31784eda5a..9f90ec5ff6 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -216,12 +216,28 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { AppendPadding(Layout.getSize() / 8, Align); } +void CGRecordLayoutBuilder::LayoutBases(const CXXRecordDecl *RD, + const ASTRecordLayout &Layout) { + // Check if we need to add a vtable pointer. + if (RD->isDynamicClass() && !Layout.getPrimaryBase()) { + const llvm::Type *Int8PtrTy = + llvm::Type::getInt8PtrTy(Types.getLLVMContext()); + + assert(NextFieldOffsetInBytes == 0 && + "Vtable pointer must come first!"); + AppendField(NextFieldOffsetInBytes, Int8PtrTy->getPointerTo()); + } +} + bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) { assert(!D->isUnion() && "Can't call LayoutFields on a union!"); assert(Alignment && "Did not set alignment!"); const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(D); + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) + LayoutBases(RD, Layout); + unsigned FieldNo = 0; for (RecordDecl::field_iterator Field = D->field_begin(), |