diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-14 10:32:00 -0400 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-14 22:42:56 -0400 |
commit | 54c1bcab90102481fe43b73f8547d47446ba2163 (patch) | |
tree | 7f4e8d52b72cb4be5b4bb598c3338d444a628700 /clang/lib/Basic/SourceManager.cpp | |
parent | 32a4ad3b6ce6028a371b028cf06fa5feff9534bf (diff) | |
download | llvm-54c1bcab90102481fe43b73f8547d47446ba2163.zip llvm-54c1bcab90102481fe43b73f8547d47446ba2163.tar.gz llvm-54c1bcab90102481fe43b73f8547d47446ba2163.tar.bz2 |
clang/Basic: Stop using SourceManager::getBuffer, NFC
Update clang/lib/Basic to stop relying on a `MemoryBuffer*`, using the
`MemoryBufferRef` from `getBufferOrNone` or `getBufferOrFake` instead of
`getBuffer`.
Differential Revision: https://reviews.llvm.org/D89394
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 1e191519..61e186e 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -1228,12 +1228,11 @@ const char *SourceManager::getCharacterData(SourceLocation SL, /// this is significantly cheaper to compute than the line number. unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid) const { - bool MyInvalid = false; - const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); + llvm::Optional<llvm::MemoryBufferRef> MemBuf = getBufferOrNone(FID); if (Invalid) - *Invalid = MyInvalid; + *Invalid = !MemBuf; - if (MyInvalid) + if (!MemBuf) return 1; // It is okay to request a position just past the end of the buffer. @@ -1509,7 +1508,10 @@ StringRef SourceManager::getBufferName(SourceLocation Loc, bool *Invalid) const { if (isInvalid(Loc, Invalid)) return "<invalid loc>"; - return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier(); + auto B = getBufferOrNone(getFileID(Loc)); + if (Invalid) + *Invalid = !B; + return B ? B->getBufferIdentifier() : "<invalid buffer>"; } /// getPresumedLoc - This method returns the "presumed" location of a @@ -2047,8 +2049,8 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // If we arrived here, the location is either in a built-ins buffer or // associated with global inline asm. PR5662 and PR22576 are examples. - StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier(); - StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier(); + StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier(); + StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier(); bool LIsBuiltins = LB == "<built-in>"; bool RIsBuiltins = RB == "<built-in>"; // Sort built-in before non-built-in. |