From 016765e3453db2e302efe53905e99cdb25501234 Mon Sep 17 00:00:00 2001 From: Christopher Lamb Date: Thu, 29 Nov 2007 06:06:27 +0000 Subject: [PATCH] Support floating point literals of the form "1e-16f" which specify an exponent but no decimal point. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44431 91177308-0d34-0410-b5e6-96231b3b80d8 --- Lex/LiteralSupport.cpp | 4 ++-- test/Lexer/11-27-2007-FloatLiterals.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 test/Lexer/11-27-2007-FloatLiterals.c diff --git a/Lex/LiteralSupport.cpp b/Lex/LiteralSupport.cpp index f6d1a867a3..d00d9c3b16 100644 --- a/Lex/LiteralSupport.cpp +++ b/Lex/LiteralSupport.cpp @@ -261,7 +261,7 @@ NumericLiteralParser(const char *begin, const char *end, s = SkipOctalDigits(s); if (s == ThisTokEnd) { // Done. - } else if (isxdigit(*s)) { + } else if (isxdigit(*s) && !(*s == 'e' || *s == 'E')) { TokLoc = PP.AdvanceToTokenCharacter(TokLoc, s-begin); Diag(TokLoc, diag::err_invalid_octal_digit, std::string(s, s+1)); return; @@ -290,7 +290,7 @@ NumericLiteralParser(const char *begin, const char *end, s = SkipDigits(s); if (s == ThisTokEnd) { // Done. - } else if (isxdigit(*s)) { + } else if (isxdigit(*s) && !(*s == 'e' || *s == 'E')) { Diag(TokLoc, diag::err_invalid_decimal_digit, std::string(s, s+1)); return; } else if (*s == '.') { diff --git a/test/Lexer/11-27-2007-FloatLiterals.c b/test/Lexer/11-27-2007-FloatLiterals.c new file mode 100644 index 0000000000..68f67cf30a --- /dev/null +++ b/test/Lexer/11-27-2007-FloatLiterals.c @@ -0,0 +1,7 @@ +// RUN: clang %s -emit-llvm 2>&1 | grep 0x3BFD83C940000000 | count 2 +// RUN: clang %s -emit-llvm 2>&1 | grep 0x46A3B8B5B5056E16 | count 2 + +float F = 1e-19f; +double D = 2e32; +float F2 = 01e-19f; +double D2 = 02e32;