Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -671,7 +671,7 @@ /// /// Negative FileIDs are indexes into this table. To get from ID to an index, /// use (-ID - 2). - mutable SmallVector LoadedSLocEntryTable; + SmallVector LoadedSLocEntryTable; /// The starting offset of the next local SLocEntry. /// @@ -753,6 +753,8 @@ mutable std::unique_ptr FakeContentCacheForRecovery; + mutable std::unique_ptr FakeSLocEntryForRecovery; + /// Lazily computed map of macro argument chunks to their expanded /// source location. using MacroArgsMap = std::map; Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -434,9 +434,12 @@ // If the file of the SLocEntry changed we could still have loaded it. if (!SLocEntryLoaded[Index]) { // Try to recover; create a SLocEntry so the rest of clang can handle it. - LoadedSLocEntryTable[Index] = SLocEntry::get( - 0, FileInfo::get(SourceLocation(), *getFakeContentCacheForRecovery(), - SrcMgr::C_User, "")); + if (!FakeSLocEntryForRecovery) + FakeSLocEntryForRecovery = std::make_unique( + SLocEntry::get(0, FileInfo::get(SourceLocation(), + *getFakeContentCacheForRecovery(), + SrcMgr::C_User, ""))); + return *FakeSLocEntryForRecovery; } }