Skip to content
Snippets Groups Projects
Commit 9c23bab9 authored by Yunzhong Gao's avatar Yunzhong Gao
Browse files

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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200031 91177308-0d34-0410-b5e6-96231b3b80d8
parent eb0acd8b
No related branches found
No related tags found
No related merge requests found
......@@ -558,7 +558,12 @@ bool CGRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *base,
if (getTypeAlignment(subobjectType) > Alignment)
return false;
AppendField(baseOffset, subobjectType);
if (LastLaidOutBase.NonVirtualSize < CharUnits::fromQuantity(
Types.getDataLayout().getStructLayout(subobjectType)->getSizeInBytes()))
AppendBytes(LastLaidOutBase.NonVirtualSize);
else
AppendField(baseOffset, subobjectType);
return true;
}
......
// 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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment