Only emit string initializers in-place if types match. Fixes PR9373.

llvm-svn: 126883
This commit is contained in:
Benjamin Kramer 2011-03-02 21:27:44 +00:00
parent e84af17b6e
commit 0f074df979
2 changed files with 5 additions and 1 deletions

View 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));

View 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).