From: Anders Carlsson Date: Sat, 13 Feb 2010 21:16:54 +0000 (+0000) Subject: Don't make return adjustments for pure virtual member functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d05be51b09ae1ce65b1ecd6220bade12908586d;p=clang Don't make return adjustments for pure virtual member functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96120 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 912f33c5d6..f16f66af2a 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -426,11 +426,14 @@ void FinalOverriders::PropagateOverrider(const CXXMethodDecl *OldMD, assert(Overrider.Method && "Did not find existing overrider!"); // Get the return adjustment base offset. - BaseOffset ReturnBaseOffset = - ComputeReturnTypeBaseOffset(Context, NewMD, OverriddenMD); - if (!ReturnBaseOffset.isEmpty()) { - // Store the return adjustment base offset. - ReturnAdjustments[SubobjectAndMethod] = ReturnBaseOffset; + // (We don't want to do this for pure virtual member functions). + if (!NewMD->isPure()) { + BaseOffset ReturnBaseOffset = + ComputeReturnTypeBaseOffset(Context, NewMD, OverriddenMD); + if (!ReturnBaseOffset.isEmpty()) { + // Store the return adjustment base offset. + ReturnAdjustments[SubobjectAndMethod] = ReturnBaseOffset; + } } // Set the new overrider. diff --git a/test/CodeGenCXX/vtable-layout.cpp b/test/CodeGenCXX/vtable-layout.cpp index 19ce8da4cf..622983f7c8 100644 --- a/test/CodeGenCXX/vtable-layout.cpp +++ b/test/CodeGenCXX/vtable-layout.cpp @@ -182,6 +182,23 @@ struct E : A { }; V3 *E::f() { return 0;} +// Test that a pure virtual member doesn't get a thunk. + +// CHECK: Vtable for 'Test4::F' (5 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test4::F RTTI +// CHECK-NEXT: -- (Test4::A, 0) vtable address -- +// CHECK-NEXT: -- (Test4::F, 0) vtable address -- +// CHECK-NEXT: 2 | Test4::R3 *Test4::F::f() [pure] +// CHECK-NEXT: 3 | void Test4::F::g() +// CHECK-NEXT: 4 | Test4::R3 *Test4::F::f() [pure] +struct F : A { + virtual void g(); + virtual R3 *f() = 0; +}; + +void F::g() { } + } // For now, just verify this doesn't crash.