Introduce a new BufferResult class to act as the return type of
SourceManager's getBuffer() (and similar) operations. This abstract
can be used to force callers to cope with errors in getBuffer(), such
as missing files and changed files. Fix a bunch of callers to use the
new interface.

Add some very basic checks for file consistency (file size,
modification time) into ContentCache::getBuffer(), although these
checks don't help much until we've updated the main callers (e.g.,
SourceManager::getSpelling()).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98585 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index b52a32e..c570ee4 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -2043,7 +2043,10 @@
   std::pair<FileID, unsigned> LocInfo
     = CXXUnit->getSourceManager().getDecomposedLoc(Loc);
   std::pair<const char *,const char *> Buffer
-    = CXXUnit->getSourceManager().getBufferData(LocInfo.first);
+    = CXXUnit->getSourceManager().getBufferData(LocInfo.first,
+                                  CXXUnit->getPreprocessor().getDiagnostics());
+  if (!Buffer.first)
+    return createCXString("");
 
   return createCXString(llvm::StringRef(Buffer.first+LocInfo.second,
                                         CXTok.int_data[2]));
@@ -2096,7 +2099,11 @@
 
   // Create a lexer
   std::pair<const char *,const char *> Buffer
-    = SourceMgr.getBufferData(BeginLocInfo.first);
+    = SourceMgr.getBufferData(BeginLocInfo.first, 
+                              CXXUnit->getPreprocessor().getDiagnostics());
+  if (!Buffer.first)
+    return;
+  
   Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
             CXXUnit->getASTContext().getLangOptions(),
             Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second);
@@ -2125,12 +2132,16 @@
       CXTok.int_data[0] = CXToken_Literal;
       CXTok.ptr_data = (void *)Tok.getLiteralData();
     } else if (Tok.is(tok::identifier)) {
-      // Lookup the identifier to determine whether we have a
+      // Lookup the identifier to determine whether we have a keyword.
       std::pair<FileID, unsigned> LocInfo
         = SourceMgr.getDecomposedLoc(Tok.getLocation());
-      const char *StartPos
-        = CXXUnit->getSourceManager().getBufferData(LocInfo.first).first +
-          LocInfo.second;
+      std::pair<const char *, const char *> Buf
+        = CXXUnit->getSourceManager().getBufferData(LocInfo.first,
+                                  CXXUnit->getPreprocessor().getDiagnostics());
+      if (!Buf.first)
+        return;
+      
+      const char *StartPos= Buf.first + LocInfo.second;
       IdentifierInfo *II
         = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);
       CXTok.int_data[0] = II->getTokenID() == tok::identifier?