Re: [PATCH] D24312: [CodeGen] Fix an assert in EmitNullConstant
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=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 +struct X2 : X0 { +}; + +template +struct X3 : X2 { + X3() : X2() {} +}; + + +void test0() { + X3(); +} +} Index: cfe/trunk/lib/CodeGen/CGExprConstant.cpp === --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp @@ -1532,7 +1532,8 @@ cast(I.getType()->castAs()->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 +struct X2 : X0 { +}; + +template +struct X3 : X2 { + X3() : X2() {} +}; + + +void test0() { + X3(); +} +} Index: cfe/trunk/lib/CodeGen/CGExprConstant.cpp === --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp @@ -1532,7 +1532,8 @@ cast(I.getType()->castAs()->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
Re: [PATCH] D24312: [CodeGen] Fix an assert in EmitNullConstant
rjmccall added a comment. LGTM. https://reviews.llvm.org/D24312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24312: [CodeGen] Fix an assert in EmitNullConstant
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 +struct X2 : X0 { +}; + +template +struct X3 : X2 { + X3() : X2() {} +}; + + +void test0() { + X3(); +} +} Index: lib/CodeGen/CGExprConstant.cpp === --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -1532,7 +1532,8 @@ cast(I.getType()->castAs()->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 +struct X2 : X0 { +}; + +template +struct X3 : X2 { + X3() : X2() {} +}; + + +void test0() { + X3(); +} +} Index: lib/CodeGen/CGExprConstant.cpp === --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -1532,7 +1532,8 @@ cast(I.getType()->castAs()->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