From: Reid Kleckner Date: Mon, 14 Oct 2013 21:14:05 +0000 (+0000) Subject: PR17576: Fix assertion on polymorphic classes with small alignment X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7dec298303edbf3eb2c7993801c602a1d88e9db;p=clang PR17576: Fix assertion on polymorphic classes with small alignment We have to reserve at least the width of a pointer for the vfptr. For classes with small alignment, we weren't reserving enough space, and were overlapping the first field with the vfptr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192626 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 05eeae154d..b0230ac6ef 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -2660,8 +2660,8 @@ void MicrosoftRecordLayoutBuilder::layoutVFPtr(const CXXRecordDecl *RD) { // the max alignment of all the non-virtual data in the class. The resulting // layout is essentially { vftbl, { nvdata } }. This is completely // unnecessary, but we're not here to pass judgment. - Size += Alignment; updateAlignment(PointerAlignment); + Size += Alignment; } void diff --git a/test/Layout/ms-x86-size-alignment-fail.cpp b/test/Layout/ms-x86-size-alignment-fail.cpp index c15d3825c2..6ce8a4b720 100644 --- a/test/Layout/ms-x86-size-alignment-fail.cpp +++ b/test/Layout/ms-x86-size-alignment-fail.cpp @@ -58,10 +58,20 @@ struct E : virtual B0, virtual B1 {}; // CHECK: 5 | struct B1 (virtual base) (empty) // CHECK: | [sizeof=8, align=4 // CHECK: | nvsize=4, nvalign=4] - + +struct F { char a; virtual ~F(); }; + +// CHECK: *** Dumping AST Record Layout +// CHECK: 0 | struct F +// CHECK: 0 | (F vftable pointer) +// CHECK: 4 | char a +// CHECK: | [sizeof=8, align=4 +// CHECK: | nvsize=8, nvalign=4] + int a[ sizeof(A)+ sizeof(B)+ sizeof(C)+ sizeof(D)+ -sizeof(E)]; +sizeof(E)+ +sizeof(F)];