[Basic] Don't rewrite source buffer copy multiple times

The on-disc buffer file name was not recorded correctly.

rdar://130478685
This commit is contained in:
Rintaro Ishizaki
2024-07-09 14:36:56 -07:00
parent ad61e531a3
commit 90c2975d66
4 changed files with 9 additions and 9 deletions

View File

@@ -288,7 +288,8 @@ StringRef SourceManager::getIdentifierForBuffer(
// If this is generated source code, and we're supposed to force it to disk
// so external clients can see it, do so now.
if (ForceGeneratedSourceToDisk) {
if (auto generatedInfo = getGeneratedSourceInfo(bufferID)) {
if (const GeneratedSourceInfo *generatedInfo =
getGeneratedSourceInfo(bufferID)) {
// We only care about macros, so skip everything else.
if (generatedInfo->kind == GeneratedSourceInfo::ReplacedFunctionBody ||
generatedInfo->kind == GeneratedSourceInfo::PrettyPrinted ||
@@ -403,12 +404,12 @@ bool SourceManager::hasGeneratedSourceInfo(unsigned bufferID) {
return GeneratedSourceInfos.count(bufferID);
}
std::optional<GeneratedSourceInfo>
const GeneratedSourceInfo *
SourceManager::getGeneratedSourceInfo(unsigned bufferID) const {
auto known = GeneratedSourceInfos.find(bufferID);
if (known == GeneratedSourceInfos.end())
return std::nullopt;
return known->second;
return nullptr;
return &known->second;
}
namespace {