aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-16 20:46:42 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-16 20:46:42 +0000
commita543016fe07030f695d6d56fd22c8c8da617e0d7 (patch)
tree4f007b8435178d3d477774b9f2a69f4b70a1badf
parent47a3fcd4afe122b23f9e7b6148f147bfa460cfe8 (diff)
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
-rw-r--r--include/clang/Basic/SourceLocation.h2
-rw-r--r--include/clang/Lex/Preprocessor.h2
-rw-r--r--lib/Basic/SourceLocation.cpp4
-rw-r--r--lib/Lex/Lexer.cpp1
-rw-r--r--lib/Lex/PPDirectives.cpp7
-rw-r--r--lib/Lex/Preprocessor.cpp5
6 files changed, 14 insertions, 7 deletions
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h
index adfe213095..5b7f877200 100644
--- a/include/clang/Basic/SourceLocation.h
+++ b/include/clang/Basic/SourceLocation.h
@@ -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;
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 2b27a06070..3ef1fcdbda 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -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
diff --git a/lib/Basic/SourceLocation.cpp b/lib/Basic/SourceLocation.cpp
index 85e5595dc2..5ccd73171e 100644
--- a/lib/Basic/SourceLocation.cpp
+++ b/lib/Basic/SourceLocation.cpp
@@ -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 {
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 6cdb96f37d..0b8b6242db 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -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;
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index cddc6cff72..3bf3fc4af9 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -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') {
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 880ff43c66..a86799aafa 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -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;