diff options
| author | Mike Stump <mrs@apple.com> | 2009-08-05 22:37:18 +0000 |
|---|---|---|
| committer | Mike Stump <mrs@apple.com> | 2009-08-05 22:37:18 +0000 |
| commit | d8fe7b2792b14a61749658d35e924c0811d395a9 (patch) | |
| tree | 6f2df4bc386869d040bd2fb9a00f3b825001aaaa /clang/lib/CodeGen/CGCXX.cpp | |
| parent | dc3416b7b3ad92fb788def0da53f812c648f7591 (diff) | |
| download | bcm5719-llvm-d8fe7b2792b14a61749658d35e924c0811d395a9.tar.gz bcm5719-llvm-d8fe7b2792b14a61749658d35e924c0811d395a9.zip | |
Calculate the primary base class better and use that when laying down
the vtable. Still a work in progress.
llvm-svn: 78252
Diffstat (limited to 'clang/lib/CodeGen/CGCXX.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 97937ea89a1..375c9ac40e4 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -540,9 +540,12 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { llvm::Type *Ptr8Ty; Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); m = llvm::Constant::getNullValue(Ptr8Ty); - int64_t offset = 0; - methods.push_back(m); offset += LLVMPointerWidth; - methods.push_back(GenerateRtti(RD)); offset += LLVMPointerWidth; + int64_t Offset = 0; + methods.push_back(m); Offset += LLVMPointerWidth; + methods.push_back(GenerateRtti(RD)); Offset += LLVMPointerWidth; + + const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD); + const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), e = RD->bases_end(); i != e; ++i) { @@ -550,6 +553,16 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { continue; const CXXRecordDecl *Base = cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); + if (PrimaryBase != Base) { + const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD); + int64_t BaseOffset = -(Layout.getBaseClassOffset(Base) / 8); + m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset); + m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty); + methods.push_back(m); + // FIXME: GenerateRtti for Base in RD. + m = llvm::Constant::getNullValue(Ptr8Ty); + methods.push_back(m); + } for (meth_iter mi = Base->method_begin(), me = Base->method_end(); mi != me; ++mi) { if (mi->isVirtual()) { @@ -558,16 +571,28 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { methods.push_back(m); } } + if (PrimaryBase == Base) { + for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me; + ++mi) { + if (mi->isVirtual()) { + m = CGM.GetAddrOfFunction(GlobalDecl(*mi)); + m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty); + methods.push_back(m); + } + } + } } - - for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me; - ++mi) { - if (mi->isVirtual()) { - m = CGM.GetAddrOfFunction(GlobalDecl(*mi)); - m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty); - methods.push_back(m); + if (PrimaryBase == 0) { + for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me; + ++mi) { + if (mi->isVirtual()) { + m = CGM.GetAddrOfFunction(GlobalDecl(*mi)); + m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty); + methods.push_back(m); + } } } + llvm::Constant *C; llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size()); C = llvm::ConstantArray::get(type, methods); @@ -577,7 +602,7 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { // FIXME: finish layout for virtual bases vtable = Builder.CreateGEP(vtable, llvm::ConstantInt::get(llvm::Type::Int64Ty, - offset/8)); + Offset/8)); return vtable; } |

