summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-02-23 03:26:17 +0000
committerAnders Carlsson <andersca@mac.com>2010-02-23 03:26:17 +0000
commitbae46277fe0a00b36f7932fbfbdfb5e1dbd94204 (patch)
tree13968b8e91f2bcf6d708547414527da9237bae3b
parent510d22d0978fd0bc2cb4c91a09460ecd5f14b655 (diff)
downloadbcm5719-llvm-bae46277fe0a00b36f7932fbfbdfb5e1dbd94204.tar.gz
bcm5719-llvm-bae46277fe0a00b36f7932fbfbdfb5e1dbd94204.zip
Always emit vcall offset for the primary base, not only if it's virtual. Remove a debug printf, and add the test case that now passes.
llvm-svn: 96880
-rw-r--r--clang/lib/CodeGen/CGVtable.cpp6
-rw-r--r--clang/test/CodeGenCXX/vtable-layout.cpp59
2 files changed, 60 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGVtable.cpp b/clang/lib/CodeGen/CGVtable.cpp
index 52e82d9669a..93cd42c9f56 100644
--- a/clang/lib/CodeGen/CGVtable.cpp
+++ b/clang/lib/CodeGen/CGVtable.cpp
@@ -1112,15 +1112,11 @@ VtableBuilder::AddVCallAndVBaseOffsets(BaseSubobject Base,
}
void VtableBuilder::AddVCallOffsets(BaseSubobject Base, uint64_t VBaseOffset) {
- printf("adding call offsets for (%s, %llu) vbase offset %llu\n",
- Base.getBase()->getQualifiedNameAsString().c_str(),
- Base.getBaseOffset(), VBaseOffset);
const CXXRecordDecl *RD = Base.getBase();
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
// Handle the primary base first.
- const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
- if (PrimaryBase && Layout.getPrimaryBaseWasVirtual()) {
+ if (const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase()) {
// Get the base offset of the primary base.
uint64_t PrimaryBaseOffset = Base.getBaseOffset() +
Layout.getBaseClassOffset(PrimaryBase);
diff --git a/clang/test/CodeGenCXX/vtable-layout.cpp b/clang/test/CodeGenCXX/vtable-layout.cpp
index bb5996707f0..237c9337f43 100644
--- a/clang/test/CodeGenCXX/vtable-layout.cpp
+++ b/clang/test/CodeGenCXX/vtable-layout.cpp
@@ -422,3 +422,62 @@ struct C : virtual B {
void C::f() { }
}
+
+namespace Test12 {
+
+// Test that the right vcall offsets are generated in the right order.
+
+// CHECK: Vtable for 'Test12::B' (19 entries).
+// CHECK-NEXT: 0 | vbase_offset (8)
+// CHECK-NEXT: 1 | offset_to_top (0)
+// CHECK-NEXT: 2 | Test12::B RTTI
+// CHECK-NEXT: -- (Test12::B, 0) vtable address --
+// CHECK-NEXT: 3 | void Test12::B::f()
+// CHECK-NEXT: 4 | void Test12::B::a()
+// CHECK-NEXT: 5 | vcall_offset (32)
+// CHECK-NEXT: 6 | vcall_offset (16)
+// CHECK-NEXT: 7 | vcall_offset (-8)
+// CHECK-NEXT: 8 | vcall_offset (0)
+// CHECK-NEXT: 9 | offset_to_top (-8)
+// CHECK-NEXT: 10 | Test12::B RTTI
+// CHECK-NEXT: -- (Test12::A, 8) vtable address --
+// CHECK-NEXT: -- (Test12::A1, 8) vtable address --
+// CHECK-NEXT: 11 | void Test12::A1::a1()
+// CHECK-NEXT: 12 | void Test12::B::a()
+// CHECK-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
+// CHECK-NEXT: 13 | offset_to_top (-24)
+// CHECK-NEXT: 14 | Test12::B RTTI
+// CHECK-NEXT: -- (Test12::A2, 24) vtable address --
+// CHECK-NEXT: 15 | void Test12::A2::a2()
+// CHECK-NEXT: 16 | offset_to_top (-40)
+// CHECK-NEXT: 17 | Test12::B RTTI
+// CHECK-NEXT: -- (Test12::A3, 40) vtable address --
+// CHECK-NEXT: 18 | void Test12::A3::a3()
+struct A1 {
+ virtual void a1();
+ int a;
+};
+
+struct A2 {
+ virtual void a2();
+ int a;
+};
+
+struct A3 {
+ virtual void a3();
+ int a;
+};
+
+struct A : A1, A2, A3 {
+ virtual void a();
+ int i;
+};
+
+struct B : virtual A {
+ virtual void f();
+
+ virtual void a();
+};
+void B::f() { }
+
+}
OpenPOWER on IntegriCloud