summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-03-29 14:11:22 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-03-29 14:11:22 +0000
commit7fd88386b058702e4aad1cb95c5e67678018bf5e (patch)
tree3b0ea5040d87905a43b5c486fb527f0febe515c6 /clang
parent72e3ccc37530cc5bcd79cc02fd7a0ce940980068 (diff)
downloadbcm5719-llvm-7fd88386b058702e4aad1cb95c5e67678018bf5e.tar.gz
bcm5719-llvm-7fd88386b058702e4aad1cb95c5e67678018bf5e.zip
[lex] Turn range checks into asserts.
We know that the last accessible char is not in [a-zA-Z0-9_.] so we can happily scan on as long as it is. No functionality change. llvm-svn: 233490
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Lex/LiteralSupport.cpp80
1 files changed, 36 insertions, 44 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index af3e27fd521..88b64dd8ffc 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -597,7 +597,8 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
if (isFloat) break; // LF invalid.
// Check for long long. The L's need to be adjacent and the same case.
- if (s+1 != ThisTokEnd && s[1] == s[0]) {
+ if (s[1] == s[0]) {
+ assert(s + 1 < ThisTokEnd && "didn't maximally munch?");
if (isFPConstant) break; // long long invalid for floats.
isLongLong = true;
++s; // Eat both of them.
@@ -611,54 +612,45 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
if (isLong || isLongLong || MicrosoftInteger)
break;
- // Allow i8, i16, i32, i64, and i128.
- if (s + 1 != ThisTokEnd) {
+ if (!isFPConstant) {
+ // Allow i8, i16, i32, i64, and i128.
switch (s[1]) {
- case '8':
- if (isFPConstant) break;
- s += 2; // i8 suffix
- MicrosoftInteger = 8;
- break;
- case '1':
- if (isFPConstant) break;
- if (s + 2 == ThisTokEnd) break;
- if (s[2] == '6') {
- s += 3; // i16 suffix
- MicrosoftInteger = 16;
- }
- else if (s[2] == '2') {
- if (s + 3 == ThisTokEnd) break;
- if (s[3] == '8') {
- s += 4; // i128 suffix
- MicrosoftInteger = 128;
- }
- }
- break;
- case '3':
- if (isFPConstant) break;
- if (s + 2 == ThisTokEnd) break;
- if (s[2] == '2') {
- s += 3; // i32 suffix
- MicrosoftInteger = 32;
- }
- break;
- case '6':
- if (isFPConstant) break;
- if (s + 2 == ThisTokEnd) break;
- if (s[2] == '4') {
- s += 3; // i64 suffix
- MicrosoftInteger = 64;
- }
- break;
- default:
- break;
- }
- if (MicrosoftInteger)
+ case '8':
+ s += 2; // i8 suffix
+ MicrosoftInteger = 8;
+ break;
+ case '1':
+ if (s[2] == '6') {
+ s += 3; // i16 suffix
+ MicrosoftInteger = 16;
+ } else if (s[2] == '2' && s[3] == '8') {
+ s += 4; // i128 suffix
+ MicrosoftInteger = 128;
+ }
+ break;
+ case '3':
+ if (s[2] == '2') {
+ s += 3; // i32 suffix
+ MicrosoftInteger = 32;
+ }
+ break;
+ case '6':
+ if (s[2] == '4') {
+ s += 3; // i64 suffix
+ MicrosoftInteger = 64;
+ }
break;
+ default:
+ break;
+ }
+ }
+ if (MicrosoftInteger) {
+ assert(s <= ThisTokEnd && "didn't maximally munch?");
+ break;
}
}
// "i", "if", and "il" are user-defined suffixes in C++1y.
- if (PP.getLangOpts().CPlusPlus14 && *s == 'i')
+ if (*s == 'i' && PP.getLangOpts().CPlusPlus14)
break;
// fall through.
case 'j':
OpenPOWER on IntegriCloud