[PATCH] D41834: [Lex] Fix handling numerical literals ending with ' and signed exponent.
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 9 10:47:02 PST 2018
vsapsai updated this revision to Diff 129125.
vsapsai added a comment.
- Don't parse exponent past the end of token, add same test+fix for hexadecimal numbers.
https://reviews.llvm.org/D41834
Files:
clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/cxx1y_digit_separators.cpp
Index: clang/test/Lexer/cxx1y_digit_separators.cpp
===================================================================
--- clang/test/Lexer/cxx1y_digit_separators.cpp
+++ clang/test/Lexer/cxx1y_digit_separators.cpp
@@ -51,6 +51,8 @@
float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires a significand}}
float v = 0e'f; // expected-error {{exponent has no digits}}
float w = 0x0p'f; // expected-error {{exponent has no digits}}
+ float x = 0'e+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
+ float y = 0x0'p+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
}
#line 123'456
Index: clang/lib/Lex/LiteralSupport.cpp
===================================================================
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -738,15 +738,17 @@
s++;
radix = 10;
saw_exponent = true;
- if (*s == '+' || *s == '-') s++; // sign
+ if (s != ThisTokEnd && (*s == '+' || *s == '-')) s++; // sign
const char *first_non_digit = SkipDigits(s);
if (containsDigits(s, first_non_digit)) {
checkSeparator(TokLoc, s, CSK_BeforeDigits);
s = first_non_digit;
} else {
- PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
- diag::err_exponent_has_no_digits);
- hadError = true;
+ if (!hadError) {
+ PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
+ diag::err_exponent_has_no_digits);
+ hadError = true;
+ }
return;
}
}
@@ -787,10 +789,12 @@
} else if (Pos == ThisTokEnd)
return;
- if (isDigitSeparator(*Pos))
+ if (isDigitSeparator(*Pos)) {
PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Pos - ThisTokBegin),
diag::err_digit_separator_not_between_digits)
<< IsAfterDigits;
+ hadError = true;
+ }
}
/// ParseNumberStartingWithZero - This method is called when the first character
@@ -840,12 +844,14 @@
const char *Exponent = s;
s++;
saw_exponent = true;
- if (*s == '+' || *s == '-') s++; // sign
+ if (s != ThisTokEnd && (*s == '+' || *s == '-')) s++; // sign
const char *first_non_digit = SkipDigits(s);
if (!containsDigits(s, first_non_digit)) {
- PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
- diag::err_exponent_has_no_digits);
- hadError = true;
+ if (!hadError) {
+ PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
+ diag::err_exponent_has_no_digits);
+ hadError = true;
+ }
return;
}
checkSeparator(TokLoc, s, CSK_BeforeDigits);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41834.129125.patch
Type: text/x-patch
Size: 2746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180109/cc2b0dcd/attachment.bin>
More information about the cfe-commits
mailing list