diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 16 | ||||
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.h | 5 |
2 files changed, 21 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(), diff --git a/lib/CodeGen/CGRecordLayoutBuilder.h b/lib/CodeGen/CGRecordLayoutBuilder.h index 4ebf4e88de..cf84053e19 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.h +++ b/lib/CodeGen/CGRecordLayoutBuilder.h @@ -23,6 +23,8 @@ namespace llvm { } namespace clang { + class ASTRecordLayout; + class CXXRecordDecl; class FieldDecl; class RecordDecl; @@ -90,6 +92,9 @@ class CGRecordLayoutBuilder { /// Returns false if the operation failed because the struct is not packed. bool LayoutFields(const RecordDecl *D); + /// LayoutBases - layout the bases and vtable pointer of a record decl. + void LayoutBases(const CXXRecordDecl *RD, const ASTRecordLayout &Layout); + /// LayoutField - layout a single field. Returns false if the operation failed /// because the current struct is not packed. bool LayoutField(const FieldDecl *D, uint64_t FieldOffset); |