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(); +} +}