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
This commit is contained in:
Anders Carlsson 2011-01-29 03:18:56 +00:00
parent 65b8ccf6ac
commit a376b53695
2 changed files with 27 additions and 2 deletions

View File

@ -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<FinalAttr>()) {
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,

View File

@ -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;
}