This revision was automatically updated to reflect the committed changes. Closed by commit rL281405: [CodeGen] Fix an assert in EmitNullConstant. (authored by ahatanak).
Changed prior to commit: https://reviews.llvm.org/D24312?vs=70589&id=71248#toc Repository: rL LLVM https://reviews.llvm.org/D24312 Files: cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/test/CodeGenCXX/empty-classes.cpp Index: cfe/trunk/test/CodeGenCXX/empty-classes.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/empty-classes.cpp +++ cfe/trunk/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: cfe/trunk/lib/CodeGen/CGExprConstant.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp +++ cfe/trunk/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: cfe/trunk/test/CodeGenCXX/empty-classes.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/empty-classes.cpp +++ cfe/trunk/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: cfe/trunk/lib/CodeGen/CGExprConstant.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp +++ cfe/trunk/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