Use a more appropriate LLVM type for the vtable pointer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103078 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Carlsson 2010-05-05 05:47:36 +00:00
Родитель 71b1d0e5f0
Коммит 68e3013ade
2 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -439,12 +439,14 @@ 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());
const llvm::Type *FunctionType =
llvm::FunctionType::get(llvm::Type::getInt32Ty(Types.getLLVMContext()),
/*isVarArg=*/true);
const llvm::Type *VTableTy = FunctionType->getPointerTo();
assert(NextFieldOffsetInBytes == 0 &&
"VTable pointer must come first!");
AppendField(NextFieldOffsetInBytes, Int8PtrTy->getPointerTo());
AppendField(NextFieldOffsetInBytes, VTableTy->getPointerTo());
}
}

Просмотреть файл

@ -1,6 +1,6 @@
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
// An extra byte shoudl be allocated for an empty class.
// An extra byte should be allocated for an empty class.
// CHECK: %struct.A = type { i8 }
struct A { } a;
@ -9,5 +9,5 @@ struct A { } a;
struct B { void *a; int b; } b;
// C should have a vtable pointer.
// CHECK: %struct.C = type { i8**, i32 }
// CHECK: %struct.C = type { i32 (...)**, i32 }
struct C { virtual void f(); int a; } *c;