Only emit string initializers in-place if types match. Fixes PR9373.
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 2 Mar 2011 21:27:44 +0000 (21:27 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 2 Mar 2011 21:27:44 +0000 (21:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126883 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGen/const-init.c

index 40d7b6c32e4b02e9a3df9c7c6c975f4d90048ba5..a4e054d06e4c5653b21a5cf91e3fc66016d6ad52 100644 (file)
@@ -562,7 +562,7 @@ public:
 
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE) {
     unsigned NumInitElements = ILE->getNumInits();
-    if (NumInitElements == 1 &&
+    if (NumInitElements == 1 && ILE->getType() == ILE->getInit(0)->getType() &&
         (isa<StringLiteral>(ILE->getInit(0)) ||
          isa<ObjCEncodeExpr>(ILE->getInit(0))))
       return Visit(ILE->getInit(0));
index 32b762d646e6c81dc1b4a054c60f66e809f0cf5d..c6778630a0a0f0eda9661d4b8387736850a53f40 100644 (file)
@@ -4,6 +4,10 @@
 
 // Brace-enclosed string array initializers
 char a[] = { "asdf" };
+// CHECK: @a = global [5 x i8] c"asdf\00"
+
+char a2[2][5] = { "asdf" };
+// CHECK: @a2 = global [2 x [5 x i8]] {{\[}}[5 x i8] c"asdf\00", [5 x i8] zeroinitializer]
 
 // Double-implicit-conversions of array/functions (not legal C, but
 // clang accepts it for gcc compat).