[cfe-commits] r97338 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-layout.cpp

Anders Carlsson andersca at mac.com
Sat Feb 27 11:21:58 PST 2010


Author: andersca
Date: Sat Feb 27 13:21:58 2010
New Revision: 97338

URL: http://llvm.org/viewvc/llvm-project?rev=97338&view=rev
Log:
Use the real base offset when calculating vbase offsets.

Modified:
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/test/CodeGenCXX/vtable-layout.cpp

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=97338&r1=97337&r2=97338&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Sat Feb 27 13:21:58 2010
@@ -971,7 +971,7 @@
   }
 
   // FIXME: Don't use /8 here.
-  int64_t OffsetToTop = -(int64_t)Base.getBaseOffset() / 8;
+  int64_t OffsetToTop = -(int64_t)RealBaseOffset / 8;
   AddVBaseOffsets(Base.getBase(), OffsetToTop);
 
   // We only want to add vcall offsets for virtual bases.

Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=97338&r1=97337&r2=97338&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Sat Feb 27 13:21:58 2010
@@ -787,3 +787,49 @@
 void C::h() { }
 
 }
+
+namespace Test21 {
+
+// Test that we get vbase offsets right in secondary vtables.
+struct A { 
+  virtual void f();
+};
+
+struct B : virtual A { };
+class C : virtual B { };
+class D : virtual C { };
+
+class E : virtual C { };
+
+// CHECK:      Vtable for 'Test21::F' (16 entries).
+// CHECK-NEXT:    0 | vbase_offset (8)
+// CHECK-NEXT:    1 | vbase_offset (0)
+// CHECK-NEXT:    2 | vbase_offset (0)
+// CHECK-NEXT:    3 | vbase_offset (0)
+// CHECK-NEXT:    4 | vbase_offset (0)
+// CHECK-NEXT:    5 | vcall_offset (0)
+// CHECK-NEXT:    6 | offset_to_top (0)
+// CHECK-NEXT:    7 | Test21::F RTTI
+// CHECK-NEXT:        -- (Test21::A, 0) vtable address --
+// CHECK-NEXT:        -- (Test21::B, 0) vtable address --
+// CHECK-NEXT:        -- (Test21::C, 0) vtable address --
+// CHECK-NEXT:        -- (Test21::D, 0) vtable address --
+// CHECK-NEXT:        -- (Test21::F, 0) vtable address --
+// CHECK-NEXT:    8 | void Test21::F::f()
+// CHECK-NEXT:    9 | vbase_offset (-8)
+// CHECK-NEXT:   10 | vbase_offset (-8)
+// CHECK-NEXT:   11 | vbase_offset (-8)
+// CHECK-NEXT:   12 | vcall_offset (-8)
+// CHECK-NEXT:   13 | offset_to_top (-8)
+// CHECK-NEXT:   14 | Test21::F RTTI
+// CHECK-NEXT:        -- (Test21::A, 8) vtable address --
+// CHECK-NEXT:        -- (Test21::B, 8) vtable address --
+// CHECK-NEXT:        -- (Test21::C, 8) vtable address --
+// CHECK-NEXT:        -- (Test21::E, 8) vtable address --
+// CHECK-NEXT:   15 | [unused] void Test21::F::f()
+class F : virtual D, virtual E {
+  virtual void f();
+};
+void F::f() { }
+
+}





More information about the cfe-commits mailing list