]> granicus.if.org Git - clang/commitdiff
When re-using a vtable slot for the nearest overridden method, just because
authorJohn McCall <rjmccall@apple.com>
Tue, 9 Nov 2010 01:18:05 +0000 (01:18 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 9 Nov 2010 01:18:05 +0000 (01:18 +0000)
there's no return adjustment from the overridden to the overrider doesn't
mean there isn't a return adjustment from the overrider to the final
overrider.  This matters if we're emitting a virtual this-adjustment thunk
because the overrider virtually inherits from the class providing the
nearest overridden method.  Do the appropriate return adjustment in this case.

Fixes PR7611.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118466 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVTables.cpp
test/CodeGenCXX/thunks.cpp

index 70fdf129674bbf7be0ecbfb23edaa25b1e4ba32e..066b20c837547308d13bedf40c0488df912dfe5a 100644 (file)
@@ -1664,9 +1664,18 @@ VTableBuilder::AddMethods(BaseSubobject Base, uint64_t BaseOffsetInLayoutClass,
 
           if (ThisAdjustment.VCallOffsetOffset &&
               Overrider.Method->getParent() == MostDerivedClass) {
+
+            // There's no return adjustment from OverriddenMD and MD,
+            // but that doesn't mean there isn't one between MD and
+            // the final overrider.
+            BaseOffset ReturnAdjustmentOffset =
+              ComputeReturnAdjustmentBaseOffset(Context, Overrider.Method, MD);
+            ReturnAdjustment ReturnAdjustment = 
+              ComputeReturnAdjustment(ReturnAdjustmentOffset);
+
             // This is a virtual thunk for the most derived class, add it.
             AddThunk(Overrider.Method, 
-                     ThunkInfo(ThisAdjustment, ReturnAdjustment()));
+                     ThunkInfo(ThisAdjustment, ReturnAdjustment));
           }
         }
 
index ba60385ab6f33fc0f2d1b3f96a427d8963d5d42b..238032cc6de24ba68bcd4d47a9d09bc60fc12482 100644 (file)
@@ -260,6 +260,25 @@ namespace Test10 {
   }
 }
 
+// PR7611
+namespace Test11 {
+  struct A {             virtual A* f(); };
+  struct B : virtual A { virtual A* f(); };
+  struct C : B         { virtual C* f(); };
+  C* C::f() { return 0; }
+
+  //  The this-adjustment and return-adjustment thunk required when
+  //  C::f appears in a vtable where A is at a nonzero offset from C.
+  // CHECK: define {{.*}} @_ZTcv0_n24_v0_n32_N6Test111C1fEv(
+
+  //  C::f itself.
+  // CHECK: define {{.*}} @_ZN6Test111C1fEv(
+
+  //  The return-adjustment thunk required when C::f appears in a vtable
+  //  where A is at a zero offset from C.
+  // CHECK: define {{.*}} @_ZTch0_v0_n32_N6Test111C1fEv(
+}
+
 /**** The following has to go at the end of the file ****/
 
 // This is from Test5: