summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/SourceLocation.h4
-rw-r--r--clang/lib/Basic/SourceLocation.cpp8
-rw-r--r--clang/lib/Basic/SourceManager.cpp13
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp6
4 files changed, 16 insertions, 15 deletions
diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h
index 34dfecd9b6a..adfe2130957 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -208,11 +208,11 @@ public:
const char *getCharacterData() const;
- const llvm::MemoryBuffer* getBuffer() const;
+ const llvm::MemoryBuffer* getBuffer(bool *Invalid = 0) const;
/// getBufferData - Return a StringRef to the source buffer data for the
/// specified FileID.
- llvm::StringRef getBufferData() const;
+ llvm::StringRef getBufferData(bool *Invalid = 0) const;
/// getDecomposedLoc - Decompose the specified location into a raw FileID +
/// Offset pair. The first element is the FileID, the second is the
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp
index 126d640364d..85e5595dc2e 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -110,13 +110,13 @@ const char *FullSourceLoc::getCharacterData() const {
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/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 4007ccf2a61..254aec02262 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -475,15 +475,14 @@ bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
}
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();
}
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 81e6bf80902..6d1c132fc0a 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -80,8 +80,10 @@ bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
}
// Get the MemoryBuffer for this FID, if it fails, we fail.
- const llvm::MemoryBuffer *InputFile = getSourceManager().getBuffer(FID);
- if (!InputFile)
+ bool Invalid = false;
+ const llvm::MemoryBuffer *InputFile = getSourceManager().getBuffer(FID,
+ &Invalid);
+ if (Invalid)
return true;
EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir);
OpenPOWER on IntegriCloud