diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-02 21:27:44 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-02 21:27:44 +0000 |
commit | 0483a6fcf8a70f1dd900b634300510c7991a1c7c (patch) | |
tree | 05b103d118874ef9e2b348f0b10ef87da0556924 | |
parent | 75e85048e73fcde2ce9d8a48dfdb1220e132eb59 (diff) |
Only emit string initializers in-place if types match. Fixes PR9373.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126883 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 2 | ||||
-rw-r--r-- | test/CodeGen/const-init.c | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 40d7b6c32e..a4e054d06e 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -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)); diff --git a/test/CodeGen/const-init.c b/test/CodeGen/const-init.c index 32b762d646..c6778630a0 100644 --- a/test/CodeGen/const-init.c +++ b/test/CodeGen/const-init.c @@ -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). |