[cfe-commits] r54237 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp test/CodeGen/2008-07-30-implicit-initialization.c

Daniel Dunbar daniel at zuster.org
Wed Jul 30 14:00:25 PDT 2008


Author: ddunbar
Date: Wed Jul 30 16:00:24 2008
New Revision: 54237

URL: http://llvm.org/viewvc/llvm-project?rev=54237&view=rev
Log:
Fix implicit initialization of structures.

<rdar://problem/6113085>

Added:
    cfe/trunk/test/CodeGen/2008-07-30-implicit-initialization.c
Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=54237&r1=54236&r2=54237&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Jul 30 16:00:24 2008
@@ -426,11 +426,6 @@
   // 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;"

Added: cfe/trunk/test/CodeGen/2008-07-30-implicit-initialization.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2008-07-30-implicit-initialization.c?rev=54237&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/2008-07-30-implicit-initialization.c (added)
+++ cfe/trunk/test/CodeGen/2008-07-30-implicit-initialization.c Wed Jul 30 16:00:24 2008
@@ -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];
+}
+





More information about the cfe-commits mailing list