diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-03-16 05:20:39 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-03-16 05:20:39 +0000 |
commit | 7bda4b831018692de8221bd0283d6d55f70dc35b (patch) | |
tree | 92d028bd8ca7787a74e5960f4840ba3021eaeb23 /clang/lib/Lex/PPExpressions.cpp | |
parent | e03ecd01aa0b5a9c1c62086f6d376f7b1fee892f (diff) | |
download | llvm-7bda4b831018692de8221bd0283d6d55f70dc35b.zip llvm-7bda4b831018692de8221bd0283d6d55f70dc35b.tar.gz llvm-7bda4b831018692de8221bd0283d6d55f70dc35b.tar.bz2 |
Introduce optional "Invalid" parameters to routines that invoke the
SourceManager's getBuffer() and, therefore, could fail, along with
Preprocessor::getSpelling(). Use the Invalid parameters in the literal
parsers (string, floating point, integral, character) to make them
robust against errors that stem from, e.g., PCH files that are not
consistent with the underlying file system.
I still need to audit every use caller to all of these routines, to
determine which ones need specific handling of error conditions.
llvm-svn: 98608
Diffstat (limited to 'clang/lib/Lex/PPExpressions.cpp')
-rw-r--r-- | clang/lib/Lex/PPExpressions.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp index ede129e..756ce27 100644 --- a/clang/lib/Lex/PPExpressions.cpp +++ b/clang/lib/Lex/PPExpressions.cpp @@ -170,7 +170,12 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, return true; case tok::numeric_constant: { llvm::SmallString<64> IntegerBuffer; - llvm::StringRef Spelling = PP.getSpelling(PeekTok, IntegerBuffer); + bool NumberInvalid = false; + llvm::StringRef Spelling = PP.getSpelling(PeekTok, IntegerBuffer, + &NumberInvalid); + if (NumberInvalid) + return true; // a diagnostic was already reported + NumericLiteralParser Literal(Spelling.begin(), Spelling.end(), PeekTok.getLocation(), PP); if (Literal.hadError) @@ -216,7 +221,10 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, } case tok::char_constant: { // 'x' llvm::SmallString<32> CharBuffer; - llvm::StringRef ThisTok = PP.getSpelling(PeekTok, CharBuffer); + bool CharInvalid = false; + llvm::StringRef ThisTok = PP.getSpelling(PeekTok, CharBuffer, &CharInvalid); + if (CharInvalid) + return true; CharLiteralParser Literal(ThisTok.begin(), ThisTok.end(), PeekTok.getLocation(), PP); |