[cfe-commits] r126883 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/const-init.c
Benjamin Kramer
benny.kra at googlemail.com
Wed Mar 2 13:27:44 PST 2011
Author: d0k
Date: Wed Mar 2 15:27:44 2011
New Revision: 126883
URL: http://llvm.org/viewvc/llvm-project?rev=126883&view=rev
Log:
Only emit string initializers in-place if types match. Fixes PR9373.
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/test/CodeGen/const-init.c
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=126883&r1=126882&r2=126883&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed Mar 2 15:27:44 2011
@@ -562,7 +562,7 @@
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));
Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=126883&r1=126882&r2=126883&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Wed Mar 2 15:27:44 2011
@@ -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).
More information about the cfe-commits
mailing list