r251036 - [MS ABI] Don't crash when inheriting from base with trailing empty array member
David Majnemer via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 22 11:04:22 PDT 2015
Author: majnemer
Date: Thu Oct 22 13:04:22 2015
New Revision: 251036
URL: http://llvm.org/viewvc/llvm-project?rev=251036&view=rev
Log:
[MS ABI] Don't crash when inheriting from base with trailing empty array member
We got this right for Itanium but not MSVC because CGRecordLayoutBuilder
was checking if the base's size was zero when it should have been
checking the non-virtual size.
This fixes PR21040.
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/trunk/test/Layout/ms-x86-empty-nonvirtual-bases.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=251036&r1=251035&r2=251036&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Thu Oct 22 13:04:22 2015
@@ -454,7 +454,7 @@ void CGRecordLowering::accumulateBases()
// contain only a trailing array member.
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
if (!BaseDecl->isEmpty() &&
- !Context.getASTRecordLayout(BaseDecl).getSize().isZero())
+ !Context.getASTRecordLayout(BaseDecl).getNonVirtualSize().isZero())
Members.push_back(MemberInfo(Layout.getBaseClassOffset(BaseDecl),
MemberInfo::Base, getStorageType(BaseDecl), BaseDecl));
}
Modified: cfe/trunk/test/Layout/ms-x86-empty-nonvirtual-bases.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-empty-nonvirtual-bases.cpp?rev=251036&r1=251035&r2=251036&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-empty-nonvirtual-bases.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-empty-nonvirtual-bases.cpp Thu Oct 22 13:04:22 2015
@@ -159,6 +159,28 @@ struct __declspec(align(32)) H : B0, B1,
// CHECK-NEXT: | [sizeof=64, align=32
// CHECK-NEXT: | nvsize=40, nvalign=32]
+struct I {
+ int i0[0];
+};
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct I
+// CHECK-NEXT: 0 | int [0] i0
+// CHECK-NEXT: | [sizeof={{1|4}}, align=4,
+// CHECK-NEXT: | nvsize=0, nvalign=4]
+
+struct J : I {
+ int j;
+};
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct J
+// CHECK-NEXT: 0 | struct I (base)
+// CHECK-NEXT: 0 | int [0] i0
+// CHECK-NEXT: 0 | int j
+// CHECK-NEXT: | [sizeof=4, align=4,
+// CHECK-NEXT: | nvsize=4, nvalign=4]
+
int a[
sizeof(A)+
sizeof(B)+
@@ -167,4 +189,6 @@ sizeof(D)+
sizeof(E)+
sizeof(F)+
sizeof(G)+
-sizeof(H)];
+sizeof(H)+
+sizeof(I)+
+sizeof(J)];
More information about the cfe-commits
mailing list