diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-19 18:30:49 -0400 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-26 20:56:28 -0400 |
commit | aab50af8c18ab2eb2149bb516c8a0993ffc5abb7 (patch) | |
tree | 701fd435058ad0109940dab16258826c321a0fe8 /clang/lib/Basic/SourceManager.cpp | |
parent | 17cdba61d4364ac7d89f6be770afdd4cc8daef83 (diff) | |
download | llvm-aab50af8c18ab2eb2149bb516c8a0993ffc5abb7.zip llvm-aab50af8c18ab2eb2149bb516c8a0993ffc5abb7.tar.gz llvm-aab50af8c18ab2eb2149bb516c8a0993ffc5abb7.tar.bz2 |
SourceManager: Use the same fake SLocEntry whenever it fails to load
Instead of putting a fake `SLocEntry` at `LoadedSLocEntryTable[Index]`
when it fails to load in `SourceManager::loadSLocEntry`, allocate a fake
one. Unless someone is sniffing the address of the returned `SLocEntry`
(doubtful), this won't be a functionality change. Note that
`SLocEntryLoaded[Index]` wasn't being set to `true` either before or
after this change so no accessor is every going to look at
`LoadedSLocEntryTable[Index]`.
As a side effect, drop the `mutable` from `LoadedSLocEntryTable`.
Differential Revision: https://reviews.llvm.org/D89748
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 6eae0f0..88f95d1 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -434,9 +434,11 @@ const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index, // 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>(SLocEntry::get( + 0, FileInfo::get(SourceLocation(), getFakeContentCacheForRecovery(), + SrcMgr::C_User, ""))); + return *FakeSLocEntryForRecovery; } } |