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

Anders Carlsson andersca at mac.com
Mon Mar 29 08:08:41 PDT 2010


Author: andersca
Date: Mon Mar 29 10:08:41 2010
New Revision: 99812

URL: http://llvm.org/viewvc/llvm-project?rev=99812&view=rev
Log:
Another vtable layout fix, making us match gcc better.

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=99812&r1=99811&r2=99812&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Mon Mar 29 10:08:41 2010
@@ -1401,8 +1401,15 @@
                                             MethodInfo.BaseOffset), MD);
     
     // Check if we need an adjustment at all.
-    if (MethodInfo.BaseOffsetInLayoutClass == Overrider.Offset)
-      continue;
+    if (MethodInfo.BaseOffsetInLayoutClass == Overrider.Offset) {
+      // When a return thunk is needed by a derived class that overrides a
+      // virtual base, gcc uses a virtual 'this' adjustment as well. 
+      // While the thunk itself might be needed by vtables in subclasses or
+      // in construction vtables, there doesn't seem to be a reason for using
+      // the thunk in this vtable. Still, we do so to match gcc.
+      if (VTableThunks.lookup(VtableIndex).Return.isEmpty())
+        continue;
+    }
 
     ThisAdjustment ThisAdjustment =
       ComputeThisAdjustment(MD, MethodInfo.BaseOffsetInLayoutClass, Overrider);

Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=99812&r1=99811&r2=99812&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Mon Mar 29 10:08:41 2010
@@ -1273,3 +1273,33 @@
 void E::e() { }
 
 }
+
+namespace Test29 {
+
+// Test that the covariant return thunk for B::f will have a virtual 'this' adjustment,
+// matching gcc.
+
+struct V1 { };
+struct V2 : virtual V1 { };
+
+struct A {
+  virtual V1 *f();
+};
+
+// CHECK:      Vtable for 'Test29::B' (6 entries).
+// CHECK-NEXT:    0 | vbase_offset (0)
+// CHECK-NEXT:    1 | vcall_offset (0)
+// CHECK-NEXT:    2 | offset_to_top (0)
+// CHECK-NEXT:    3 | Test29::B RTTI
+// CHECK-NEXT:        -- (Test29::A, 0) vtable address --
+// CHECK-NEXT:        -- (Test29::B, 0) vtable address --
+// CHECK-NEXT:    4 | Test29::V2 *Test29::B::f()
+// CHECK-NEXT:        [return adjustment: 0 non-virtual, -24 vbase offset offset]
+// CHECK-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
+// CHECK-NEXT:    5 | Test29::V2 *Test29::B::f()
+struct B : virtual A {
+  virtual V2 *f();
+};
+V2 *B::f() { return 0; }
+
+}





More information about the cfe-commits mailing list