Layout the primary base first in the vtable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78327 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 7cf397f..567c583 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -576,6 +576,18 @@
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
+ // The primary base comes first.
+ if (PrimaryBase)
+ GenerateVtableForBase(PrimaryBase, methods);
+ 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 (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
if (i->isVirtual())
@@ -591,29 +603,10 @@
// FIXME: GenerateRtti for Base in RD.
m = llvm::Constant::getNullValue(Ptr8Ty);
methods.push_back(m);
- }
- GenerateVtableForBase(Base, methods);
- 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);
- }
- }
+ GenerateVtableForBase(Base, methods);
}
}
- 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);
- }
- }
- }
+
// FIXME: finish layout for virtual bases
// FIXME: audit indirect virtual bases
for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),