aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-08-12 18:50:26 +0000
committerMike Stump <mrs@apple.com>2009-08-12 18:50:26 +0000
commit34fae9cf27b19664f1f4526e195aff2299de2c40 (patch)
tree51243eed0ce6ab843d5c3e69d76976dfe586a80d
parentacf2d137f362ede2b8f6a86b4f9dd9f6bcf00d7a (diff)
Improve the secondary vtables to not include vbase offsets. WIP.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78831 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGCXX.cpp28
-rw-r--r--test/CodeGenCXX/virt.cpp39
2 files changed, 52 insertions, 15 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 7541357a72..f161f9f68e 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -638,19 +638,21 @@ void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Class);
- // The virtual base offsets come first...
- for (CXXRecordDecl::reverse_base_class_const_iterator i
- = Class->bases_rbegin(),
- e = Class->bases_rend(); i != e; ++i) {
- if (!i->isVirtual())
- continue;
- const CXXRecordDecl *Base =
- cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
- int64_t BaseOffset = Layout.getBaseClassOffset(Base) / 8;
- llvm::Constant *m;
- m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
- m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
- methods.push_back(m);
+ if (isPrimary) {
+ // The virtual base offsets come first...
+ for (CXXRecordDecl::reverse_base_class_const_iterator i
+ = Class->bases_rbegin(),
+ e = Class->bases_rend(); i != e; ++i) {
+ if (!i->isVirtual())
+ continue;
+ const CXXRecordDecl *Base =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ int64_t BaseOffset = Layout.getBaseClassOffset(Base) / 8;
+ llvm::Constant *m;
+ m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
+ m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
+ methods.push_back(m);
+ }
}
// then comes the the vcall offsets for all our functions...
diff --git a/test/CodeGenCXX/virt.cpp b/test/CodeGenCXX/virt.cpp
index 7c51a39376..d9e8664460 100644
--- a/test/CodeGenCXX/virt.cpp
+++ b/test/CodeGenCXX/virt.cpp
@@ -128,6 +128,41 @@ struct test3_D : virtual test3_B1 {
// CHECK-LP64: .quad __ZN8test3_B16funcB1Ev
// CHECK-LP64: .quad __ZN7test3_D5funcDEv
+struct test4_D : virtual B, virtual C {
+};
+
+// CHECK-LP32:__ZTV7test4_D:
+// CHECK-LP32: .space 4
+// CHECK-LP32: .long 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .long __ZTI7test4_D
+// CHECK-LP32: .long __ZN1C4bee1Ev
+// CHECK-LP32: .long __ZN1C4bee2Ev
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .long 4294967292
+// CHECK-LP32: .long __ZTI7test4_D
+// CHECK-LP32: .long __ZN1B4bar1Ev
+// CHECK-LP32: .long __ZN1B4bar2Ev
+
+// CHECK-LP64:__ZTV7test4_D:
+// CHECK-LP64: .space 8
+// CHECK-LP64: .quad 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .quad __ZTI7test4_D
+// CHECK-LP64: .quad __ZN1C4bee1Ev
+// CHECK-LP64: .quad __ZN1C4bee2Ev
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .quad 18446744073709551608
+// CHECK-LP64: .quad __ZTI7test4_D
+// CHECK-LP64: .quad __ZN1B4bar1Ev
+// CHECK-LP64: .quad __ZN1B4bar2Ev
+
@@ -210,5 +245,5 @@ struct test3_D : virtual test3_B1 {
// CHECK-LP64: .quad __ZN2D14bar5Ev
-test3_D d;
-
+test4_D d4;
+test3_D d3;