Add a missing check in CodeGen of packed classes with vtables. <rdar://problem/11324125>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155689 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Friedman 2012-04-27 02:34:46 +00:00
Родитель 526cda38f9
Коммит c8f11e9b4b
2 изменённых файлов: 21 добавлений и 1 удалений

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

@ -721,7 +721,13 @@ CGRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD,
llvm::FunctionType::get(llvm::Type::getInt32Ty(Types.getLLVMContext()),
/*isVarArg=*/true);
llvm::Type *VTableTy = FunctionType->getPointerTo();
if (getTypeAlignment(VTableTy) > Alignment) {
// FIXME: Should we allow this to happen in Sema?
assert(!Packed && "Alignment is wrong even with packed struct!");
return false;
}
assert(NextFieldOffset.isZero() &&
"VTable pointer must come first!");
AppendField(CharUnits::Zero(), VTableTy->getPointerTo());

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

@ -77,3 +77,17 @@ namespace Test6 {
class E : public B {};
E *e;
}
// <rdar://problem/11324125>: Make sure this doesn't crash. (It's okay
// if we start rejecting it at some point.)
namespace Test7 {
#pragma pack (1)
class A {};
// CHECK: %"class.Test7::B" = type <{ i32 (...)**, %"class.Test7::A" }>
class B {
virtual ~B();
A a;
};
B* b;
#pragma pack ()
}