forked from OSchip/llvm-project
Audit all getBuffer() callers (for both the FullSourceLoc and
SourceManager versions), updating those callers that need to recover gracefully from failure. llvm-svn: 98665
This commit is contained in:
parent
26266da3c3
commit
4fb7fbef3b
|
@ -208,11 +208,11 @@ public:
|
||||||
|
|
||||||
const char *getCharacterData() const;
|
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
|
/// getBufferData - Return a StringRef to the source buffer data for the
|
||||||
/// specified FileID.
|
/// specified FileID.
|
||||||
llvm::StringRef getBufferData() const;
|
llvm::StringRef getBufferData(bool *Invalid = 0) const;
|
||||||
|
|
||||||
/// getDecomposedLoc - Decompose the specified location into a raw FileID +
|
/// getDecomposedLoc - Decompose the specified location into a raw FileID +
|
||||||
/// Offset pair. The first element is the FileID, the second is the
|
/// Offset pair. The first element is the FileID, the second is the
|
||||||
|
|
|
@ -110,13 +110,13 @@ const char *FullSourceLoc::getCharacterData() const {
|
||||||
return SrcMgr->getCharacterData(*this);
|
return SrcMgr->getCharacterData(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const {
|
const llvm::MemoryBuffer* FullSourceLoc::getBuffer(bool *Invalid) const {
|
||||||
assert(isValid());
|
assert(isValid());
|
||||||
return SrcMgr->getBuffer(SrcMgr->getFileID(*this));
|
return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::StringRef FullSourceLoc::getBufferData() const {
|
llvm::StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
|
||||||
return getBuffer()->getBuffer();
|
return getBuffer(Invalid)->getBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const {
|
std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const {
|
||||||
|
|
|
@ -475,15 +475,14 @@ bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
|
llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
|
||||||
|
bool MyInvalid = false;
|
||||||
|
const llvm::MemoryBuffer *Buf = getBuffer(FID, &MyInvalid);
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
*Invalid = false;
|
*Invalid = MyInvalid;
|
||||||
|
|
||||||
const llvm::MemoryBuffer *Buf = getBuffer(FID);
|
if (MyInvalid)
|
||||||
if (!Buf) {
|
|
||||||
if (*Invalid)
|
|
||||||
*Invalid = true;
|
|
||||||
return "";
|
return "";
|
||||||
}
|
|
||||||
return Buf->getBuffer();
|
return Buf->getBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,10 @@ bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the MemoryBuffer for this FID, if it fails, we fail.
|
// Get the MemoryBuffer for this FID, if it fails, we fail.
|
||||||
const llvm::MemoryBuffer *InputFile = getSourceManager().getBuffer(FID);
|
bool Invalid = false;
|
||||||
if (!InputFile)
|
const llvm::MemoryBuffer *InputFile = getSourceManager().getBuffer(FID,
|
||||||
|
&Invalid);
|
||||||
|
if (Invalid)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir);
|
EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir);
|
||||||
|
|
Loading…
Reference in New Issue