aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-07-30 21:00:24 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-07-30 21:00:24 +0000
commitf9eede163826dd55a56c479330ef041eaa856417 (patch)
tree89bf8842a48e940f09dc0b2cb67510abb18003cf
parent5b08cbc9cbfb24bb9500380f45ecc9dd94d61f40 (diff)
Fix implicit initialization of structures.
<rdar://problem/6113085> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54237 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprAgg.cpp5
-rw-r--r--test/CodeGen/2008-07-30-implicit-initialization.c28
2 files changed, 28 insertions, 5 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index ac2e6dec90..815e296e79 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -426,11 +426,6 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
// Here we iterate over the fields; this makes it simpler to both
// default-initialize fields and skip over unnamed fields.
for (unsigned CurFieldNo = 0; CurFieldNo != NumMembers; ++CurFieldNo) {
- if (CurInitVal >= NumInitElements) {
- // No more initializers; we're done.
- break;
- }
-
FieldDecl *CurField = SD->getMember(CurFieldNo);
if (CurField->getIdentifier() == 0) {
// Initializers can't initialize unnamed fields, e.g. "int : 20;"
diff --git a/test/CodeGen/2008-07-30-implicit-initialization.c b/test/CodeGen/2008-07-30-implicit-initialization.c
new file mode 100644
index 0000000000..ee33b6d70c
--- /dev/null
+++ b/test/CodeGen/2008-07-30-implicit-initialization.c
@@ -0,0 +1,28 @@
+// RUN: clang --emit-llvm-bc -o - %s | opt --std-compile-opts | llvm-dis > %t &&
+// RUN: grep "ret i32" %t | count 2 &&
+// RUN: grep "ret i32 0" %t | count 2
+// <rdar://problem/6113085>
+
+struct s0 {
+ int x, y;
+};
+
+int f0() {
+ struct s0 x = {0};
+ return x.y;
+}
+
+#if 0
+/* Optimizer isn't smart enough to reduce this since we use
+ memset. Hrm. */
+int f1() {
+ struct s0 x[2] = { {0} };
+ return x[1].x;
+}
+#endif
+
+int f2() {
+ int x[2] = { 0 };
+ return x[1];
+}
+