diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-14 17:17:34 -0400 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-20 13:35:46 -0400 |
commit | 51d1d585e5838ea0f02f1271f7543c4e43639969 (patch) | |
tree | 3d3fb9ba09116272f10ea8832fbd4cbd3575f7fc /clang/lib/Basic/SourceManager.cpp | |
parent | 59286b36dfb5da3a73401f66d1fa8d65c7817f94 (diff) | |
download | llvm-51d1d585e5838ea0f02f1271f7543c4e43639969.zip llvm-51d1d585e5838ea0f02f1271f7543c4e43639969.tar.gz llvm-51d1d585e5838ea0f02f1271f7543c4e43639969.tar.bz2 |
clang/Frontend: Use MemoryBufferRef in FrontendInputFile (and remove SourceManager::getBuffer)
In order to drop the final callers to `SourceManager::getBuffer`, change
`FrontendInputFile` to use `Optional<MemoryBufferRef>`. Also updated
the "unowned" version of `SourceManager::createFileID` to take a
`MemoryBufferRef` (it now calls `MemoryBuffer::getMemBuffer`, which
creates a `MemoryBuffer` that does not own the buffer data).
Differential Revision: https://reviews.llvm.org/D89427
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 61e186e..9902709 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -443,14 +443,13 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, /// Create a new ContentCache for the specified memory buffer. /// This does no caching. -const ContentCache * -SourceManager::createMemBufferContentCache(const llvm::MemoryBuffer *Buffer, - bool DoNotFree) { +const ContentCache *SourceManager::createMemBufferContentCache( + std::unique_ptr<llvm::MemoryBuffer> Buffer) { // Add a new ContentCache to the MemBufferInfos list and return it. ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(); new (Entry) ContentCache(); MemBufferInfos.push_back(Entry); - Entry->replaceBuffer(Buffer, DoNotFree); + Entry->replaceBuffer(Buffer.release(), /*DoNotFree=*/false); return Entry; } @@ -585,22 +584,20 @@ FileID SourceManager::createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer, int LoadedID, unsigned LoadedOffset, SourceLocation IncludeLoc) { StringRef Name = Buffer->getBufferIdentifier(); - return createFileID( - createMemBufferContentCache(Buffer.release(), /*DoNotFree*/ false), - Name, IncludeLoc, FileCharacter, LoadedID, LoadedOffset); + return createFileID(createMemBufferContentCache(std::move(Buffer)), Name, + IncludeLoc, FileCharacter, LoadedID, LoadedOffset); } /// Create a new FileID that represents the specified memory buffer. /// /// This does not take ownership of the MemoryBuffer. The memory buffer must /// outlive the SourceManager. -FileID SourceManager::createFileID(UnownedTag, const llvm::MemoryBuffer *Buffer, +FileID SourceManager::createFileID(const llvm::MemoryBufferRef &Buffer, SrcMgr::CharacteristicKind FileCharacter, int LoadedID, unsigned LoadedOffset, SourceLocation IncludeLoc) { - return createFileID(createMemBufferContentCache(Buffer, /*DoNotFree*/ true), - Buffer->getBufferIdentifier(), IncludeLoc, - FileCharacter, LoadedID, LoadedOffset); + return createFileID(llvm::MemoryBuffer::getMemBuffer(Buffer), FileCharacter, + LoadedID, LoadedOffset, IncludeLoc); } /// Get the FileID for \p SourceFile if it exists. Otherwise, create a |