Audit all getBuffer() callers (for both the FullSourceLoc and
SourceManager versions), updating those callers that need to recover
gracefully from failure.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98665 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/SourceLocation.cpp b/lib/Basic/SourceLocation.cpp
index 126d640..85e5595 100644
--- a/lib/Basic/SourceLocation.cpp
+++ b/lib/Basic/SourceLocation.cpp
@@ -110,13 +110,13 @@
return SrcMgr->getCharacterData(*this);
}
-const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const {
+const llvm::MemoryBuffer* FullSourceLoc::getBuffer(bool *Invalid) const {
assert(isValid());
- return SrcMgr->getBuffer(SrcMgr->getFileID(*this));
+ return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid);
}
-llvm::StringRef FullSourceLoc::getBufferData() const {
- return getBuffer()->getBuffer();
+llvm::StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
+ return getBuffer(Invalid)->getBuffer();
}
std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const {
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 4007ccf..254aec0 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -475,15 +475,14 @@
}
llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
+ bool MyInvalid = false;
+ const llvm::MemoryBuffer *Buf = getBuffer(FID, &MyInvalid);
if (Invalid)
- *Invalid = false;
-
- const llvm::MemoryBuffer *Buf = getBuffer(FID);
- if (!Buf) {
- if (*Invalid)
- *Invalid = true;
+ *Invalid = MyInvalid;
+
+ if (MyInvalid)
return "";
- }
+
return Buf->getBuffer();
}