Fixing PR18510 by checking whether the non-virtual base of the derived class

might have a smaller size as compared to the stand-alone type of the base class.
This is possible when the derived class is packed and hence might have smaller
alignment requirement than the base class.

Differential Revision: http://llvm-reviews.chandlerc.com/D2599

llvm-svn: 200031
This commit is contained in:
Yunzhong Gao 2014-01-24 19:28:24 +00:00
parent 3c68b0d484
commit 063763ea42
2 changed files with 23 additions and 1 deletions

View File

@ -558,7 +558,12 @@ bool CGRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *base,
if (getTypeAlignment(subobjectType) > Alignment)
return false;
if (LastLaidOutBase.NonVirtualSize < CharUnits::fromQuantity(
Types.getDataLayout().getStructLayout(subobjectType)->getSizeInBytes()))
AppendBytes(LastLaidOutBase.NonVirtualSize);
else
AppendField(baseOffset, subobjectType);
return true;
}

View File

@ -0,0 +1,17 @@
// RUN: %clang_cc1 %s -triple=i686-apple-darwin10 -emit-llvm -o - | FileCheck %s
struct Base {
char a;
};
struct Derived_1 : virtual Base
{
char b;
};
#pragma pack(1)
struct Derived_2 : Derived_1 {
// CHECK: %struct.Derived_2 = type <{ [5 x i8], %struct.Base }>
};
Derived_2 x;