From: Benjamin Kramer Date: Sun, 29 Mar 2015 14:11:22 +0000 (+0000) Subject: [lex] Turn range checks into asserts. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3dd6fa5d291d86c37615fc9f1f09ab28bd44c31b;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233490 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index af3e27fd52..88b64dd8ff 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/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':