From a376b536951f892bcc31928a7a9cc205d5d9bc1b Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 29 Jan 2011 03:18:56 +0000 Subject: [PATCH] When doing a derived-to-base class through a virtual class, we don't have to get the vbase offset from the vtable if the derived class is marked final. llvm-svn: 124523 --- clang/lib/CodeGen/CGClass.cpp | 13 +++++++++++-- ...derived-to-virtual-base-class-calls-final.cpp | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 2a92258b8469..a7b8f659786f 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -180,8 +180,17 @@ CodeGenFunction::GetAddressOfBaseClass(llvm::Value *Value, llvm::Value *VirtualOffset = 0; - if (VBase) - VirtualOffset = GetVirtualBaseClassOffset(Value, Derived, VBase); + if (VBase) { + if (Derived->hasAttr()) { + VirtualOffset = 0; + + const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Derived); + + uint64_t VBaseOffset = Layout.getVBaseClassOffsetInBits(VBase); + NonVirtualOffset += VBaseOffset / 8; + } else + VirtualOffset = GetVirtualBaseClassOffset(Value, Derived, VBase); + } // Apply the offsets. Value = ApplyNonVirtualAndVirtualOffset(*this, Value, NonVirtualOffset, diff --git a/clang/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp b/clang/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp new file mode 100644 index 000000000000..e332f4020001 --- /dev/null +++ b/clang/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +struct A { int i; }; +struct B { int j; }; +struct C : A, B { int k; }; + +struct D final : virtual C { + D(); + virtual void f(); +}; + +// CHECK: define %struct.B* @_Z1fR1D +B &f(D &d) { + // CHECK-NOT: load i8** + return d; +}