]> granicus.if.org Git - clang/commitdiff
[CodeGen] Fix an assert in EmitNullConstant.
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 13 Sep 2016 22:13:02 +0000 (22:13 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 13 Sep 2016 22:13:02 +0000 (22:13 +0000)
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

lib/CodeGen/CGExprConstant.cpp
test/CodeGenCXX/empty-classes.cpp

index 0e818e99eec85e153aad07f43f79cad86e499809..c268c0379256a1af5d0e5146ad10caf3fa169a75 100644 (file)
@@ -1532,7 +1532,8 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM,
       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 e27a961e123a3aabe139d2d3acc6da8c26d8a516..5727d59182918f80db4bcd9a7a3a6c3ff2d80e2d 100644 (file)
@@ -96,3 +96,24 @@ namespace rdar20621065 {
   // 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>();
+}
+}