static int i;
void foo() { /* use i */ }
static int i = 42;

Convert this properly.

llvm-svn: 59286
diff --git a/llvm-gcc-4.2/gcc/llvm-backend.cpp b/llvm-gcc-4.2/gcc/llvm-backend.cpp
index 2ead6b1..86a27e0 100644
--- a/llvm-gcc-4.2/gcc/llvm-backend.cpp
+++ b/llvm-gcc-4.2/gcc/llvm-backend.cpp
@@ -1013,6 +1013,11 @@
   if (TREE_CODE(decl) == VAR_DECL && DECL_REGISTER(decl))
     return;
 
+  // If tree nodes says defer output then do not emit global yet.
+  if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS) 
+      && (DECL_DEFER_OUTPUT(decl)))
+      return;
+
   timevar_push(TV_LLVM_GLOBALS);
 
   // Get or create the global variable now.
diff --git a/llvm-gcc-4.2/gcc/testsuite/gcc.apple/StaticInit.c b/llvm-gcc-4.2/gcc/testsuite/gcc.apple/StaticInit.c
new file mode 100644
index 0000000..c653272
--- /dev/null
+++ b/llvm-gcc-4.2/gcc/testsuite/gcc.apple/StaticInit.c
@@ -0,0 +1,16 @@
+/* LLVM LOCAL file */
+/* { dg-do run } */
+static int (*foo)(long int key);
+static int bar(long int key)
+{
+    foo = 0;
+    return key;
+}
+static int (*foo)(long int key) = bar;
+
+int main() {
+	foo(123);
+	return 0;
+}
+
+