Index: clang/lib/CodeGen/CGDebugInfo.h =================================================================== --- clang/lib/CodeGen/CGDebugInfo.h +++ clang/lib/CodeGen/CGDebugInfo.h @@ -148,7 +148,7 @@ llvm::BumpPtrAllocator DebugInfoNames; StringRef CWDName; - llvm::StringMap DIFileCache; + llvm::DenseMap DIFileCache; llvm::DenseMap SPCache; /// Cache declarations relevant to DW_TAG_imported_declarations (C++ /// using declarations and global alias variables) that aren't covered Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -397,6 +397,17 @@ // createFile() below for canonicalization if the source file was specified // with an absolute path. FileName = TheCU->getFile()->getFilename(); + for (auto It : DIFileCache) { + // StringRef operator== does a content comparison. + if (FileName == It.first) { + // Got a string match, use the existing DIFile if possible. + if (llvm::Metadata *V = It.second) + return cast(V); + // Fall through to create the DIFile but use the original string. + FileName = It.first; + break; + } + } } else { PresumedLoc PLoc = SM.getPresumedLoc(Loc); FileName = PLoc.getFilename();