From 607f67b16ca25c9d9afa725dd644487089702ff3 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 24 Oct 2008 00:46:51 +0000 Subject: [PATCH] Map compilation units using FileEntry pointers instead of FileIDs. This seems better conceptually and lets the SourceManager handle details of mapping the location to a file ID. - In practice, fixes an assert because this code wasn't using getPhysicalLoc. llvm-svn: 58055 --- clang/lib/CodeGen/CGDebugInfo.cpp | 17 +++++++---------- clang/lib/CodeGen/CGDebugInfo.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index e1889603ee76..89d00aee5e87 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -64,7 +64,7 @@ CGDebugInfo::~CGDebugInfo() delete SR; // Free CompileUnitCache. - for (std::map::iterator I + for (std::map::iterator I = CompileUnitCache.begin(); I != CompileUnitCache.end(); ++I) { delete I->second; } @@ -134,15 +134,17 @@ llvm::Value *CGDebugInfo::getValueFor(llvm::DebugInfoDesc *DD) { /// one if necessary. llvm::CompileUnitDesc *CGDebugInfo::getOrCreateCompileUnit(const SourceLocation Loc) { + SourceManager &SM = M->getContext().getSourceManager(); + const FileEntry *FE = SM.getFileEntryForLoc(Loc); // See if this compile unit has been used before. - llvm::CompileUnitDesc *&Slot = CompileUnitCache[Loc.getFileID()]; - if (Slot) return Slot; - + llvm::CompileUnitDesc *&Unit = CompileUnitCache[FE]; + if (Unit) return Unit; + // Create new compile unit. // FIXME: Where to free these? // One way is to iterate over the CompileUnitCache in ~CGDebugInfo. - llvm::CompileUnitDesc *Unit = new llvm::CompileUnitDesc(); + Unit = new llvm::CompileUnitDesc(); // Make sure we have an anchor. if (!CompileUnitAnchor) { @@ -150,8 +152,6 @@ llvm::CompileUnitDesc } // Get source file information. - SourceManager &SM = M->getContext().getSourceManager(); - const FileEntry *FE = SM.getFileEntryForLoc(Loc); const char *FileName, *DirName; if (FE) { FileName = FE->getName(); @@ -173,9 +173,6 @@ llvm::CompileUnitDesc // FIXME: Handle other languages as well. Unit->setLanguage(llvm::dwarf::DW_LANG_C89); - // Update cache. - Slot = Unit; - return Unit; } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 9352505a96d5..07d5b54b3d9a 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -57,7 +57,7 @@ private: typedef llvm::IRBuilder<> BuilderType; /// CompileUnitCache - Cache of previously constructed CompileUnits. - std::map CompileUnitCache; + std::map CompileUnitCache; /// TypeCache - Cache of previously constructed Types. std::map TypeCache;