clang/Lex: Stop using SourceManager::getBuffer

Update clang/lib/Lex to stop relying on a `MemoryBuffer*`, using the
`MemoryBufferRef` from `getBufferOrNone` since both locations had logic
for checking validity of the buffer. There's potentially a functionality
change, since the logic was wrong (it checked for `nullptr`, which was
never returned by the old API), but if that was reachable the new
behaviour should be better.

Differential Revision: https://reviews.llvm.org/D89402
This commit is contained in:
Duncan P. N. Exon Smith 2020-10-14 12:37:19 -04:00
parent a668ad92d5
commit b03ae74319
2 changed files with 3 additions and 2 deletions

View File

@ -3004,7 +3004,7 @@ bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
}
assert(Target && "Missing target information");
const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(ID);
llvm::Optional<llvm::MemoryBufferRef> Buffer = SourceMgr.getBufferOrNone(ID);
if (!Buffer)
return ParsedModuleMap[File] = true;
assert((!Offset || *Offset <= Buffer->getBufferSize()) &&

View File

@ -379,7 +379,8 @@ Optional<unsigned> Preprocessor::getSkippedRangeForExcludedConditionalBlock(
std::pair<FileID, unsigned> HashFileOffset =
SourceMgr.getDecomposedLoc(HashLoc);
const llvm::MemoryBuffer *Buf = SourceMgr.getBuffer(HashFileOffset.first);
Optional<llvm::MemoryBufferRef> Buf =
SourceMgr.getBufferOrNone(HashFileOffset.first);
if (!Buf)
return None;
auto It =