Browse Source

Fix typo causing assert in self-host.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337508 91177308-0d34-0410-b5e6-96231b3b80d8
Richard Smith 7 years ago
parent
commit
02e5d2661d
2 changed files with 12 additions and 1 deletions
  1. 1 1
      lib/CodeGen/CGExprConstant.cpp
  2. 11 0
      test/CodeGen/init.c

+ 1 - 1
lib/CodeGen/CGExprConstant.cpp

@@ -664,7 +664,7 @@ EmitArrayConstant(CodeGenModule &CGM, const ConstantArrayType *DestType,
     // struct of two arrays (the nonzero data and the zeroinitializer).
     if (CommonElementType && NonzeroLength >= 8) {
       llvm::Constant *Initial = llvm::ConstantArray::get(
-          llvm::ArrayType::get(CommonElementType, ArrayBound),
+          llvm::ArrayType::get(CommonElementType, NonzeroLength),
           makeArrayRef(Elements).take_front(NonzeroLength));
       Elements.resize(2);
       Elements[0] = Initial;

+ 11 - 0
test/CodeGen/init.c

@@ -86,6 +86,17 @@ const char large_array_with_zeroes[1000] = {
   'a', 'b', 'c', 1, 2, 3, 'x', 'y', 'z', 'z', 'y', [20] = 'q'
 };
 
+char global;
+
+// CHECK-DAG: @large_array_with_zeroes_2 = global <{ [10 x i8*], [90 x i8*] }> <{ [10 x i8*] [i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* @global], [90 x i8*] zeroinitializer }>
+const void *large_array_with_zeroes_2[100] = {
+  [9] = &global
+};
+// CHECK-DAG: @large_array_with_zeroes_3 = global <{ [10 x i8*], [990 x i8*] }> <{ [10 x i8*] [i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* @global], [990 x i8*] zeroinitializer }>
+const void *large_array_with_zeroes_3[1000] = {
+  [9] = &global
+};
+
 // PR279 comment #3
 char test8(int X) {
   char str[100000] = "abc"; // tail should be memset.