Audit all callers of SourceManager::getCharacterData(); update some of
them to recover more gracefully on failure.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98672 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/SourceLocation.cpp b/lib/Basic/SourceLocation.cpp
index 85e5595..5ccd731 100644
--- a/lib/Basic/SourceLocation.cpp
+++ b/lib/Basic/SourceLocation.cpp
@@ -105,9 +105,9 @@
   return SrcMgr->isInSystemHeader(*this);
 }
 
-const char *FullSourceLoc::getCharacterData() const {
+const char *FullSourceLoc::getCharacterData(bool *Invalid) const {
   assert(isValid());
-  return SrcMgr->getCharacterData(*this);
+  return SrcMgr->getCharacterData(*this, Invalid);
 }
 
 const llvm::MemoryBuffer* FullSourceLoc::getBuffer(bool *Invalid) const {
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 6cdb96f..0b8b624 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -163,6 +163,7 @@
   // Now that the lexer is created, change the start/end locations so that we
   // just lex the subsection of the file that we want.  This is lexing from a
   // scratch buffer.
+  bool Invalid = false;
   const char *StrData = SM.getCharacterData(SpellingLoc);
 
   L->BufferPtr = StrData;
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index cddc6cf..3bf3fc4 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -204,7 +204,12 @@
     // to spell an i/e in a strange way that is another letter.  Skipping this
     // allows us to avoid looking up the identifier info for #define/#undef and
     // other common directives.
-    const char *RawCharData = SourceMgr.getCharacterData(Tok.getLocation());
+    bool Invalid = false;
+    const char *RawCharData = SourceMgr.getCharacterData(Tok.getLocation(),
+                                                         &Invalid);
+    if (Invalid)
+      return;
+    
     char FirstChar = RawCharData[0];
     if (FirstChar >= 'a' && FirstChar <= 'z' &&
         FirstChar != 'i' && FirstChar != 'e') {
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 880ff43..a86799a 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -428,10 +428,11 @@
   // Figure out how many physical characters away the specified instantiation
   // character is.  This needs to take into consideration newlines and
   // trigraphs.
-  const char *TokPtr = SourceMgr.getCharacterData(TokStart);
+  bool Invalid = false;
+  const char *TokPtr = SourceMgr.getCharacterData(TokStart, &Invalid);
 
   // If they request the first char of the token, we're trivially done.
-  if (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr))
+  if (Invalid || (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr)))
     return TokStart;
 
   unsigned PhysOffset = 0;