local static vars are globals also.  This fixes a testcase
reported by Seo.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45156 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 8d136bc..c20680b 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -273,7 +273,7 @@
   } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false));
   } else if (const FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
-    return LValue::MakeAddr(CGM.GetAddrOfFileVarDecl(FVD, false));
+    return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(FVD, false));
   }
   assert(0 && "Unimp declref");
   //an invalid LValue, but the assert will
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index a09932e..d6412a7 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -113,8 +113,10 @@
   return Entry = NewFn;
 }
 
-llvm::Constant *CodeGenModule::GetAddrOfFileVarDecl(const FileVarDecl *D,
-                                                    bool isDefinition) {
+llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
+                                                  bool isDefinition) {
+  assert(D->hasGlobalStorage() && "Not a global variable");
+  
   // See if it is already in the map.
   llvm::Constant *&Entry = GlobalDeclMap[D];
   if (Entry) return Entry;
@@ -433,8 +435,8 @@
       // The only thing that can have array type like this is a
       // DeclRefExpr(FileVarDecl)?
       const DeclRefExpr *DRE = cast<DeclRefExpr>(ICExpr->getSubExpr());
-      const FileVarDecl *FVD = cast<FileVarDecl>(DRE->getDecl());
-      llvm::Constant *C = CGM.GetAddrOfFileVarDecl(FVD, false);
+      const VarDecl *VD = cast<VarDecl>(DRE->getDecl());
+      llvm::Constant *C = CGM.GetAddrOfGlobalVar(VD, false);
       assert(isa<llvm::PointerType>(C->getType()) &&
              isa<llvm::ArrayType>(cast<llvm::PointerType>(C->getType())
                                   ->getElementType()));
@@ -486,7 +488,7 @@
   
   // Get the global, forcing it to be a direct reference.
   llvm::GlobalVariable *GV = 
-    cast<llvm::GlobalVariable>(GetAddrOfFileVarDecl(D, true));
+    cast<llvm::GlobalVariable>(GetAddrOfGlobalVar(D, true));
   
   // Convert the initializer, or use zero if appropriate.
   llvm::Constant *Init = 0;
diff --git a/CodeGen/CodeGenModule.h b/CodeGen/CodeGenModule.h
index 5c61ad8..6339f51 100644
--- a/CodeGen/CodeGenModule.h
+++ b/CodeGen/CodeGenModule.h
@@ -33,6 +33,7 @@
   class Expr;
   class Stmt;
   class ValueDecl;
+  class VarDecl;
   class FileVarDecl;
   struct LangOptions;
   class Diagnostic;
@@ -69,8 +70,7 @@
   
   llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
                                         bool isDefinition);
-  llvm::Constant *GetAddrOfFileVarDecl(const FileVarDecl *D,
-                                       bool isDefinition);
+  llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition);
   
   
   /// getBuiltinLibFunction - Given a builtin id for a function like
diff --git a/test/CodeGen/globalinit.c b/test/CodeGen/globalinit.c
index f47fd5c..66bffd3 100644
--- a/test/CodeGen/globalinit.c
+++ b/test/CodeGen/globalinit.c
@@ -19,3 +19,10 @@
 char string[8] = "string";   // extend init
 char string2[4] = "string";  // truncate init
 
+char *test(int c) {
+ static char buf[10];
+ static char *bufptr = buf;
+
+ return c ? buf : bufptr;
+}
+