[cfe-commits] r91545 - in /cfe/trunk: lib/CodeGen/CGRecordLayoutBuilder.cpp lib/CodeGen/CGRecordLayoutBuilder.h test/CodeGenCXX/class-layout.cpp test/CodeGenCXX/virt.cpp
Anders Carlsson
andersca at mac.com
Wed Dec 16 09:27:20 PST 2009
Author: andersca
Date: Wed Dec 16 11:27:20 2009
New Revision: 91545
URL: http://llvm.org/viewvc/llvm-project?rev=91545&view=rev
Log:
Baby steps towards fixing PR5589. If a class needs a vtable pointer, add one.
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h
cfe/trunk/test/CodeGenCXX/class-layout.cpp
cfe/trunk/test/CodeGenCXX/virt.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=91545&r1=91544&r2=91545&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Wed Dec 16 11:27:20 2009
@@ -216,12 +216,28 @@
AppendPadding(Layout.getSize() / 8, Align);
}
+void CGRecordLayoutBuilder::LayoutBases(const CXXRecordDecl *RD,
+ const ASTRecordLayout &Layout) {
+ // Check if we need to add a vtable pointer.
+ if (RD->isDynamicClass() && !Layout.getPrimaryBase()) {
+ const llvm::Type *Int8PtrTy =
+ llvm::Type::getInt8PtrTy(Types.getLLVMContext());
+
+ assert(NextFieldOffsetInBytes == 0 &&
+ "Vtable pointer must come first!");
+ AppendField(NextFieldOffsetInBytes, Int8PtrTy->getPointerTo());
+ }
+}
+
bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
assert(!D->isUnion() && "Can't call LayoutFields on a union!");
assert(Alignment && "Did not set alignment!");
const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(D);
+ if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
+ LayoutBases(RD, Layout);
+
unsigned FieldNo = 0;
for (RecordDecl::field_iterator Field = D->field_begin(),
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h?rev=91545&r1=91544&r2=91545&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h Wed Dec 16 11:27:20 2009
@@ -23,6 +23,8 @@
}
namespace clang {
+ class ASTRecordLayout;
+ class CXXRecordDecl;
class FieldDecl;
class RecordDecl;
@@ -90,6 +92,9 @@
/// Returns false if the operation failed because the struct is not packed.
bool LayoutFields(const RecordDecl *D);
+ /// LayoutBases - layout the bases and vtable pointer of a record decl.
+ void LayoutBases(const CXXRecordDecl *RD, const ASTRecordLayout &Layout);
+
/// LayoutField - layout a single field. Returns false if the operation failed
/// because the current struct is not packed.
bool LayoutField(const FieldDecl *D, uint64_t FieldOffset);
Modified: cfe/trunk/test/CodeGenCXX/class-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/class-layout.cpp?rev=91545&r1=91544&r2=91545&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/class-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/class-layout.cpp Wed Dec 16 11:27:20 2009
@@ -7,3 +7,7 @@
// No need to add tail padding here.
// CHECK: %struct.B = type { i8*, i32 }
struct B { void *a; int b; } b;
+
+// C should have a vtable pointer.
+// CHECK: %struct.C = type { i8**, i32 }
+struct C { virtual void f(); int a; } *c;
Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=91545&r1=91544&r2=91545&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Wed Dec 16 11:27:20 2009
@@ -147,12 +147,12 @@
}
// CHECK-LPLL64:define void @_Z10test12_foov() nounwind {
-// CHECK-LPLL64: call void %2(%class.test14* %tmp)
-// CHECK-LPLL64: call void %5(%class.test14* %tmp1)
-// CHECK-LPLL64: call void %8(%class.test14* %tmp3)
-// CHECK-LPLL64: call void %11(%class.test14* %tmp5)
-// CHECK-LPLL64: call void %14(%class.test14* %tmp7)
-// CHECK-LPLL64: call void %17(%class.test14* %tmp9)
+// CHECK-LPLL64: call void %
+// CHECK-LPLL64: call void %
+// CHECK-LPLL64: call void %
+// CHECK-LPLL64: call void %
+// CHECK-LPLL64: call void %
+// CHECK-LPLL64: call void %
// CHECK-LPLL64: call void @_ZN8test12_A3fooEv(%class.test14* %tmp11)
More information about the cfe-commits
mailing list