Remove FileVarDecl and BlockVarDecl. They are replaced by VarDecl::isBlockVarDecl() and VarDecl::isFileVarDecl().

This is a fairly mechanical/large change. As a result, I avoided making any changes/simplifications that weren't directly related. I did break two Analysis tests. I also have a couple FIXME's in UninitializedValues.cpp. Ted, can you take a look? If the bug isn't obvious, I am happy to dig in and fix it (since I broke it).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49748 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 8255c12..e186bb6 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -23,8 +23,6 @@
 void CodeGenFunction::EmitDecl(const Decl &D) {
   switch (D.getKind()) {
   default: assert(0 && "Unknown decl kind!");
-  case Decl::FileVar:
-    assert(0 && "Should not see file-scope variables inside a function!");
   case Decl::ParmVar:
     assert(0 && "Parmdecls should not be in declstmts!");
   case Decl::Typedef:   // typedef int X;
@@ -36,8 +34,11 @@
     // None of these decls require codegen support.
     return;
     
-  case Decl::BlockVar:
-    return EmitBlockVarDecl(cast<BlockVarDecl>(D));
+  case Decl::Var:
+    if (cast<VarDecl>(D).isBlockVarDecl())
+      return EmitBlockVarDecl(cast<VarDecl>(D));
+    assert(0 && "Should not see file-scope variables inside a function!");
+  
   case Decl::EnumConstant:
     return EmitEnumConstantDecl(cast<EnumConstantDecl>(D));
   }
@@ -49,7 +50,7 @@
 
 /// EmitBlockVarDecl - This method handles emission of any variable declaration
 /// inside a function, including static vars etc.
-void CodeGenFunction::EmitBlockVarDecl(const BlockVarDecl &D) {
+void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) {
   switch (D.getStorageClass()) {
   case VarDecl::Static:
     return EmitStaticBlockVarDecl(D);
@@ -65,7 +66,7 @@
   }
 }
 
-void CodeGenFunction::EmitStaticBlockVarDecl(const BlockVarDecl &D) {
+void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
   QualType Ty = D.getType();
   assert(Ty->isConstantSizeType() && "VLAs can't be static");
   
@@ -99,7 +100,7 @@
 /// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
 /// variable declaration with auto, register, or no storage class specifier.
 /// These turn into simple stack objects.
-void CodeGenFunction::EmitLocalBlockVarDecl(const BlockVarDecl &D) {
+void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
   QualType Ty = D.getType();
 
   llvm::Value *DeclPtr;
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 8175730..5714f3c 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -338,20 +338,20 @@
 
 
 LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
-  const ValueDecl *D = E->getDecl();
-  if (isa<BlockVarDecl>(D) || isa<ParmVarDecl>(D)) {
-    const VarDecl *VD = cast<VarDecl>(D);
+  const VarDecl *VD = dyn_cast<VarDecl>(E->getDecl());
+  
+  if (VD && (VD->isBlockVarDecl() || isa<ParmVarDecl>(VD))) {
     if (VD->getStorageClass() == VarDecl::Extern)
       return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false));
     else {
-      llvm::Value *V = LocalDeclMap[D];
+      llvm::Value *V = LocalDeclMap[VD];
       assert(V && "BlockVarDecl not entered in LocalDeclMap?");
       return LValue::MakeAddr(V);
     }
-  } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+  } else if (VD && VD->isFileVarDecl()) {
+    return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false));
+  } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
     return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false));
-  } else if (const FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
-    return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(FVD, false));
   }
   assert(0 && "Unimp declref");
   //an invalid LValue, but the assert will
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 2ca71c3..ace494c 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -541,11 +541,13 @@
       ValueDecl *Decl = cast<DeclRefExpr>(E)->getDecl();
       if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl))
         return CGM.GetAddrOfFunctionDecl(FD, false);
-      if (const FileVarDecl* VD = dyn_cast<FileVarDecl>(Decl))
-        return CGM.GetAddrOfGlobalVar(VD, false);
-      if (const BlockVarDecl* BVD = dyn_cast<BlockVarDecl>(Decl)) {
-        assert(CGF && "Can't access static local vars without CGF");
-        return CGF->GetAddrOfStaticLocalVar(BVD);
+      if (const VarDecl* VD = dyn_cast<VarDecl>(Decl)) {
+        if (VD->isFileVarDecl())
+          return CGM.GetAddrOfGlobalVar(VD, false);
+        else if (VD->isBlockVarDecl()) {
+          assert(CGF && "Can't access static local vars without CGF");
+          return CGF->GetAddrOfStaticLocalVar(VD);
+        }
       }
       break;
     }
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index e1c8d38..1b94c59 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -42,7 +42,7 @@
 }
 
 llvm::Constant *
-CodeGenFunction::GetAddrOfStaticLocalVar(const BlockVarDecl *BVD) {
+CodeGenFunction::GetAddrOfStaticLocalVar(const VarDecl *BVD) {
   return cast<llvm::Constant>(LocalDeclMap[BVD]);
 }
 
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index df2c8b2..f40a0fa 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -70,7 +70,7 @@
   class ObjCIvarRefExpr;
   class MemberExpr;
 
-  class BlockVarDecl;
+  class VarDecl;
   class EnumConstantDecl;
   class ParmVarDecl;
   class FieldDecl;
@@ -344,16 +344,16 @@
   const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
 
   /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
-  llvm::Constant *GetAddrOfStaticLocalVar(const BlockVarDecl *BVD);
+  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
   //===--------------------------------------------------------------------===//
   //                            Declaration Emission
   //===--------------------------------------------------------------------===//
   
   void EmitDecl(const Decl &D);
   void EmitEnumConstantDecl(const EnumConstantDecl &D);
-  void EmitBlockVarDecl(const BlockVarDecl &D);
-  void EmitLocalBlockVarDecl(const BlockVarDecl &D);
-  void EmitStaticBlockVarDecl(const BlockVarDecl &D);
+  void EmitBlockVarDecl(const VarDecl &D);
+  void EmitLocalBlockVarDecl(const VarDecl &D);
+  void EmitStaticBlockVarDecl(const VarDecl &D);
   void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
   
   //===--------------------------------------------------------------------===//
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 83f661f..cb34fb5 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -288,7 +288,7 @@
   return EmitConstantExpr(Expr);
 }
 
-void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
+void CodeGenModule::EmitGlobalVar(const VarDecl *D) {
   // If this is just a forward declaration of the variable, don't emit it now,
   // allow it to be emitted lazily on its first use.
   if (D->getStorageClass() == VarDecl::Extern && D->getInit() == 0)
@@ -352,9 +352,10 @@
 
 /// EmitGlobalVarDeclarator - Emit all the global vars attached to the specified
 /// declarator chain.
-void CodeGenModule::EmitGlobalVarDeclarator(const FileVarDecl *D) {
-  for (; D; D = cast_or_null<FileVarDecl>(D->getNextDeclarator()))
-    EmitGlobalVar(D);
+void CodeGenModule::EmitGlobalVarDeclarator(const VarDecl *D) {
+  for (; D; D = cast_or_null<VarDecl>(D->getNextDeclarator()))
+    if (D->isFileVarDecl())
+      EmitGlobalVar(D);
 }
 
 void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index 553b366..3fcb56e 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -37,7 +37,6 @@
   class ValueDecl;
   class VarDecl;
   class TypeDecl;
-  class FileVarDecl;
   struct LangOptions;
   class Diagnostic;
     
@@ -103,8 +102,8 @@
 
   void EmitObjCMethod(const ObjCMethodDecl *OMD);
   void EmitFunction(const FunctionDecl *FD);
-  void EmitGlobalVar(const FileVarDecl *D);
-  void EmitGlobalVarDeclarator(const FileVarDecl *D);
+  void EmitGlobalVar(const VarDecl *D);
+  void EmitGlobalVarDeclarator(const VarDecl *D);
   void UpdateCompletedType(const TagDecl *D);
   llvm::Constant *EmitGlobalInit(const Expr *E);
   llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp
index 5710d8b..53ee2e4 100644
--- a/lib/CodeGen/ModuleBuilder.cpp
+++ b/lib/CodeGen/ModuleBuilder.cpp
@@ -63,8 +63,9 @@
       
       if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
         Builder->EmitFunction(FD);
-      } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
-        Builder->EmitGlobalVarDeclarator(FVD);
+      } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
+        if (VD->isFileVarDecl())
+          Builder->EmitGlobalVarDeclarator(VD);
       } else if (isa<ObjCClassDecl>(D) || isa<ObjCCategoryDecl>(D)) {
         // Forward declaration.  Only used for type checking.
       } else if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)){