Emit debug info for namespaces.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94991 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index b0f2c0f..36b3a83 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -57,6 +57,8 @@
      I = RegionMap.find(Parent);
    if (I != RegionMap.end())
      return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second));
+   if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Parent))
+     return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit));
   }
   return CompileUnit;
 }
@@ -1802,3 +1804,26 @@
                                     Var->hasInternalLinkage(),
                                     true/*definition*/, Var);
 }
+
+/// getOrCreateNamesSpace - Return namespace descriptor for the given
+/// namespace decl.
+llvm::DINameSpace 
+CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, 
+                                  llvm::DIDescriptor Unit) {
+  llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = 
+    NameSpaceCache.find(NSDecl);
+  if (I != NameSpaceCache.end())
+    return llvm::DINameSpace(cast<llvm::MDNode>(I->second));
+  
+  SourceManager &SM = CGM.getContext().getSourceManager();
+  PresumedLoc PLoc = SM.getPresumedLoc(NSDecl->getLocation());
+  unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
+
+  llvm::DIDescriptor Context = 
+    getContextDescriptor(NSDecl, Unit);
+  llvm::DINameSpace NS =
+    DebugFactory.CreateNameSpace(Context, NSDecl->getName(), 
+	llvm::DICompileUnit(Unit.getNode()), LineNo);
+  NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode());
+  return NS;
+}