Audit all callers of SourceManager::getCharacterData(); update some of

them to recover more gracefully on failure.

llvm-svn: 98672
This commit is contained in:
Douglas Gregor 2010-03-16 20:46:42 +00:00
parent f2e4b5dd7f
commit 42fe858cd6
6 changed files with 14 additions and 7 deletions

View File

@ -206,7 +206,7 @@ public:
unsigned getSpellingLineNumber() const;
unsigned getSpellingColumnNumber() const;
const char *getCharacterData() const;
const char *getCharacterData(bool *Invalid = 0) const;
const llvm::MemoryBuffer* getBuffer(bool *Invalid = 0) const;

View File

@ -595,7 +595,7 @@ public:
// Otherwise, fall back on getCharacterData, which is slower, but always
// works.
return *SourceMgr.getCharacterData(Tok.getLocation());
return *SourceMgr.getCharacterData(Tok.getLocation(), Invalid);
}
/// CreateString - Plop the specified string into a scratch buffer and set the

View File

@ -105,9 +105,9 @@ bool FullSourceLoc::isInSystemHeader() const {
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 {

View File

@ -163,6 +163,7 @@ Lexer *Lexer::Create_PragmaLexer(SourceLocation SpellingLoc,
// 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;

View File

@ -204,7 +204,12 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
// 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') {

View File

@ -428,10 +428,11 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart,
// 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;