r192626 - PR17576: Fix assertion on polymorphic classes with small alignment
Reid Kleckner
reid at kleckner.net
Mon Oct 14 14:14:05 PDT 2013
Author: rnk
Date: Mon Oct 14 16:14:05 2013
New Revision: 192626
URL: http://llvm.org/viewvc/llvm-project?rev=192626&view=rev
Log:
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.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/Layout/ms-x86-size-alignment-fail.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=192626&r1=192625&r2=192626&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Oct 14 16:14:05 2013
@@ -2660,8 +2660,8 @@ void MicrosoftRecordLayoutBuilder::layou
// 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
Modified: cfe/trunk/test/Layout/ms-x86-size-alignment-fail.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-size-alignment-fail.cpp?rev=192626&r1=192625&r2=192626&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-size-alignment-fail.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-size-alignment-fail.cpp Mon Oct 14 16:14:05 2013
@@ -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)];
More information about the cfe-commits
mailing list