diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-18 18:35:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-18 18:35:15 +0000 |
commit | d66f172ab1b6ac1bfb33c2e0f7d384b6dcb670d1 (patch) | |
tree | 0dbe3be18f65de7fff95bc71e4af91ce2946137f /clang/lib | |
parent | 13590cb204b7755d74b01f96e763bd802812c653 (diff) | |
download | bcm5719-llvm-d66f172ab1b6ac1bfb33c2e0f7d384b6dcb670d1.tar.gz bcm5719-llvm-d66f172ab1b6ac1bfb33c2e0f7d384b6dcb670d1.zip |
more fun with line markers: the digit string is required to be interpreted
as decimal, even if it starts with 0. Also, since things like 0x1 are
completely illegal, don't even bother using numericliteralparser for them.
llvm-svn: 69454
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 3d312748f95..e0bd5a1ee07 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -624,24 +624,27 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, IntegerBuffer.resize(DigitTok.getLength()); const char *DigitTokBegin = &IntegerBuffer[0]; unsigned ActualLength = PP.getSpelling(DigitTok, DigitTokBegin); - NumericLiteralParser Literal(DigitTokBegin, DigitTokBegin+ActualLength, - DigitTok.getLocation(), PP); - if (Literal.hadError) - return true; // Error already emitted. - if (Literal.isFloatingLiteral() || Literal.isImaginary) { - PP.Diag(DigitTok, DiagID); - return true; - } - - // Parse the integer literal into Result. - llvm::APInt APVal(32, 0); - if (Literal.GetIntegerValue(APVal)) { - // Overflow parsing integer literal. - PP.Diag(DigitTok, DiagID); - return true; + // Verify that we have a simple digit-sequence, and compute the value. This + // is always a simple digit string computed in decimal, so we do this manually + // here. + Val = 0; + for (unsigned i = 0; i != ActualLength; ++i) { + if (!isdigit(DigitTokBegin[i])) { + PP.Diag(PP.AdvanceToTokenCharacter(DigitTok.getLocation(), i), + diag::err_pp_line_digit_sequence); + PP.DiscardUntilEndOfDirective(); + return true; + } + + unsigned NextVal = Val*10+(DigitTokBegin[i]-'0'); + if (NextVal < Val) { // overflow. + PP.Diag(DigitTok, DiagID); + PP.DiscardUntilEndOfDirective(); + return true; + } + Val = NextVal; } - Val = APVal.getZExtValue(); // Reject 0, this is needed both by #line numbers and flags. if (Val == 0) { @@ -650,12 +653,9 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, return true; } - // Warn about hex and octal line numbers. Do this after the check for 0, - // because it is octal. - if (Literal.getRadix() != 10) - PP.Diag(DigitTok, diag::warn_pp_line_decimal); - else if (Literal.hasSuffix()) - PP.Diag(DigitTok, diag::warn_pp_line_digit_sequence); + if (DigitTokBegin[0] == '0') + PP.Diag(DigitTok.getLocation(), diag::warn_pp_line_decimal); + return false; } @@ -671,7 +671,7 @@ void Preprocessor::HandleLineDirective(Token &Tok) { // Validate the number and convert it to an unsigned. unsigned LineNo; - if (GetLineValue(DigitTok, LineNo, diag::err_pp_line_requires_integer, *this)) + if (GetLineValue(DigitTok, LineNo, diag::err_pp_line_requires_integer,*this)) return; // Enforce C99 6.10.4p3: "The digit sequence shall not specify ... a |