ahatanak created this revision. ahatanak added a reviewer: rjmccall. ahatanak added a subscriber: cfe-commits.
r235815 changed CGRecordLowering::accumulateBases to ignore non-virtual bases of size 0, which prevented adding those non-virtual bases to CGRecordLayout's NonVirtualBases. EmitNullConstant calls CGRecordLayout::getNonVirtualBaseLLVMFieldNo to get the field number of the base, which causes an assert. This patch fixes the bug. https://reviews.llvm.org/D24312 Files: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/empty-classes.cpp Index: test/CodeGenCXX/empty-classes.cpp =================================================================== --- test/CodeGenCXX/empty-classes.cpp +++ test/CodeGenCXX/empty-classes.cpp @@ -96,3 +96,24 @@ // 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>(); +} +} Index: lib/CodeGen/CGExprConstant.cpp =================================================================== --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -1532,7 +1532,8 @@ 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);
Index: test/CodeGenCXX/empty-classes.cpp =================================================================== --- test/CodeGenCXX/empty-classes.cpp +++ test/CodeGenCXX/empty-classes.cpp @@ -96,3 +96,24 @@ // 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>(); +} +} Index: lib/CodeGen/CGExprConstant.cpp =================================================================== --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -1532,7 +1532,8 @@ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits