diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-08-30 14:50:47 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-08-30 14:50:47 +0000 |
| commit | 759ef23bb86ecd18cff8d9732ec54b9cb6f608a9 (patch) | |
| tree | eee68173589d45faa59546893d06fd5fccf982c9 | |
| parent | 41c18853c84d97454b8517d4f526f575919513a9 (diff) | |
| download | bcm5719-llvm-759ef23bb86ecd18cff8d9732ec54b9cb6f608a9.tar.gz bcm5719-llvm-759ef23bb86ecd18cff8d9732ec54b9cb6f608a9.zip | |
In Microsoft compatibility mode, don't parse the exponent as part of
the pp-number in a hexadecimal floating point literal, from Francois
Pichet! Fixes PR7968.
llvm-svn: 112481
| -rw-r--r-- | clang/lib/Lex/Lexer.cpp | 11 | ||||
| -rw-r--r-- | clang/test/Lexer/ms-extensions.c | 8 |
2 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index b4cafb49f8c..4fd35be19c2 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -925,6 +925,11 @@ FinishIdentifier: } } +/// isHexaLiteral - Return true if Start points to a hex constant. +static inline bool isHexaLiteral(const char* Start, const char* End) { + return ((End - Start > 2) && Start[0] == '0' && + (Start[1] == 'x' || Start[1] == 'X')); +} /// LexNumericConstant - Lex the remainder of a integer or floating point /// constant. From[-1] is the first character lexed. Return the end of the @@ -940,7 +945,11 @@ void Lexer::LexNumericConstant(Token &Result, const char *CurPtr) { } // If we fell out, check for a sign, due to 1e+12. If we have one, continue. - if ((C == '-' || C == '+') && (PrevCh == 'E' || PrevCh == 'e')) + // If we are in Microsoft mode, don't continue if the constant is hex. + // For example, MSVC will accept the following as 3 tokens: 0x1234567e+1 + if ((C == '-' || C == '+') && (PrevCh == 'E' || PrevCh == 'e') && + (!PP || !PP->getLangOptions().Microsoft || + !isHexaLiteral(BufferPtr, CurPtr))) return LexNumericConstant(Result, ConsumeChar(CurPtr, Size, Result)); // If we have a hex FP constant, continue. diff --git a/clang/test/Lexer/ms-extensions.c b/clang/test/Lexer/ms-extensions.c index 97e660080d4..5b45ab4ab54 100644 --- a/clang/test/Lexer/ms-extensions.c +++ b/clang/test/Lexer/ms-extensions.c @@ -23,3 +23,11 @@ void a() { unsigned short s = USHORT; unsigned char c = UCHAR; } + +void pr_7968() +{ + int var1 = 0x1111111e+1; + int var2 = 0X1111111e+1; + int var3 = 0xe+1; + int var4 = 0XE+1; +} |

