Fix typo causing assert in self-host.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 19 Jul 2018 23:24:41 +0000 (23:24 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 19 Jul 2018 23:24:41 +0000 (23:24 +0000)
llvm-svn: 337508

clang/lib/CodeGen/CGExprConstant.cpp
clang/test/CodeGen/init.c

index afe2bfe..cfd0b85 100644 (file)
@@ -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;
index 770995f..0353ba8 100644 (file)
@@ -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.