r235815 changed CGRecordLowering::accumulateBases to ignore non-virtual
bases of size 0, which prevented adding those non-virtual bases to
CGRecordLayout's NonVirtualBases. This caused clang to assert when
CGRecordLayout::getNonVirtualBaseLLVMFieldNo was called in
EmitNullConstant. This commit fixes the bug by ignoring zero-sized
non-virtual bases in EmitNullConstant.
rdar://problem/
28100139
Differential Revision: https://reviews.llvm.org/D24312
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281405
91177308-0d34-0410-b5e6-
96231b3b80d8
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
// Ignore empty bases.
- if (base->isEmpty())
+ if (base->isEmpty() ||
+ CGM.getContext().getASTRecordLayout(base).getNonVirtualSize().isZero())
continue;
unsigned fieldIndex = layout.getNonVirtualBaseLLVMFieldNo(base);
// Type checked at the top of the file.
B b;
};
+
+// This test used to crash when CGRecordLayout::getNonVirtualBaseLLVMFieldNo was called.
+namespace record_layout {
+struct X0 {
+ int x[0];
+};
+
+template<typename>
+struct X2 : X0 {
+};
+
+template<typename>
+struct X3 : X2<int> {
+ X3() : X2<int>() {}
+};
+
+
+void test0() {
+ X3<int>();
+}
+}