Free DbgScope created for dead functions.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.cpp
index b81aad92cbb9f4474d28cb7c5d85474d53e50799..47a9cb65c7b2be305f6b3ea96f6b6f9fb01301f3 100644 (file)
@@ -1753,10 +1753,7 @@ DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
 /// maps as well.
 unsigned DwarfDebug::GetOrCreateSourceID(StringRef DirName, StringRef FileName){
   unsigned DId;
-  if (DirName.empty()) {
-    llvm::sys::Path CWD = llvm::sys::Path::GetCurrentDirectory();
-    DirName = StringRef(CWD.c_str(), CWD.size());
-  }
+  assert (DirName.empty() == false && "Invalid directory name!");
 
   StringMap<unsigned>::iterator DI = DirectoryIdMap.find(DirName);
   if (DI != DirectoryIdMap.end()) {
@@ -2035,6 +2032,7 @@ void DwarfDebug::beginModule(Module *M) {
 void DwarfDebug::endModule() {
   if (!FirstCU) return;
   const Module *M = MMI->getModule();
+  DenseMap<const MDNode *, DbgScope *> DeadFnScopeMap;
   if (NamedMDNode *AllSPs = M->getNamedMetadata("llvm.dbg.sp")) {
     for (unsigned SI = 0, SE = AllSPs->getNumOperands(); SI != SE; ++SI) {
       if (ProcessedSPNodes.count(AllSPs->getOperand(SI)) != 0) continue;
@@ -2052,6 +2050,7 @@ void DwarfDebug::endModule() {
       unsigned E = NMD->getNumOperands();
       if (!E) continue;
       DbgScope *Scope = new DbgScope(NULL, DIDescriptor(SP), NULL);
+      DeadFnScopeMap[SP] = Scope;
       for (unsigned I = 0; I != E; ++I) {
         DIVariable DV(NMD->getOperand(I));
         if (!DV.Verify()) continue;
@@ -2143,6 +2142,8 @@ void DwarfDebug::endModule() {
   // Emit info into a debug str section.
   emitDebugStr();
 
+  // clean up.
+  DeleteContainerSeconds(DeadFnScopeMap);
   for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
          E = CUMap.end(); I != E; ++I)
     delete I->second;