]> granicus.if.org Git - clang/commitdiff
Audit all getBuffer() callers (for both the FullSourceLoc and
authorDouglas Gregor <dgregor@apple.com>
Tue, 16 Mar 2010 20:01:30 +0000 (20:01 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 16 Mar 2010 20:01:30 +0000 (20:01 +0000)
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

include/clang/Basic/SourceLocation.h
lib/Basic/SourceLocation.cpp
lib/Basic/SourceManager.cpp
lib/Lex/PPLexerChange.cpp

index 34dfecd9b6a83e3863832a72231538071640be3f..adfe21309570ab22c150d4ca34d86a3b2c647d3b 100644 (file)
@@ -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
index 126d640364d07da90a628da623f184b4005bd5cf..85e5595dc2e1d8e20f100d1169e48dc221570a7a 100644 (file)
@@ -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 {
index 4007ccf2a61e7e919e32dc26b34e07e26dac2fd8..254aec02262ce15c157811da4d30f0da43627730 100644 (file)
@@ -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();
 }
 
index 81e6bf8090251aa82b8424f490dbcfeae504dbc7..6d1c132fc0a95739e5bff94847fa2718988210f2 100644 (file)
@@ -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);