[cfe-commits] r98672 - in /cfe/trunk: include/clang/Basic/SourceLocation.h include/clang/Lex/Preprocessor.h lib/Basic/SourceLocation.cpp lib/Lex/Lexer.cpp lib/Lex/PPDirectives.cpp lib/Lex/Preprocessor.cpp
Douglas Gregor
dgregor at apple.com
Tue Mar 16 13:46:42 PDT 2010
Author: dgregor
Date: Tue Mar 16 15:46:42 2010
New Revision: 98672
URL: http://llvm.org/viewvc/llvm-project?rev=98672&view=rev
Log:
Audit all callers of SourceManager::getCharacterData(); update some of
them to recover more gracefully on failure.
Modified:
cfe/trunk/include/clang/Basic/SourceLocation.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Basic/SourceLocation.cpp
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=98672&r1=98671&r2=98672&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Tue Mar 16 15:46:42 2010
@@ -206,7 +206,7 @@
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;
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=98672&r1=98671&r2=98672&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Mar 16 15:46:42 2010
@@ -595,7 +595,7 @@
// 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
Modified: cfe/trunk/lib/Basic/SourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceLocation.cpp?rev=98672&r1=98671&r2=98672&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceLocation.cpp (original)
+++ cfe/trunk/lib/Basic/SourceLocation.cpp Tue Mar 16 15:46:42 2010
@@ -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 {
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=98672&r1=98671&r2=98672&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Mar 16 15:46:42 2010
@@ -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;
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=98672&r1=98671&r2=98672&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Mar 16 15:46:42 2010
@@ -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') {
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=98672&r1=98671&r2=98672&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Mar 16 15:46:42 2010
@@ -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;
More information about the cfe-commits
mailing list