[cfe-commits] r124523 - in /cfe/trunk: lib/CodeGen/CGClass.cpp test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp
Anders Carlsson
andersca at mac.com
Fri Jan 28 19:18:56 PST 2011
Author: andersca
Date: Fri Jan 28 21:18:56 2011
New Revision: 124523
URL: http://llvm.org/viewvc/llvm-project?rev=124523&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=124523&r1=124522&r2=124523&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Jan 28 21:18:56 2011
@@ -180,8 +180,17 @@
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,
Added: cfe/trunk/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp?rev=124523&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/derived-to-virtual-base-class-calls-final.cpp Fri Jan 28 21:18:56 2011
@@ -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;
+}
More information about the cfe-commits
mailing list