On Aug 30, 2010, at 7:50 AM, Douglas Gregor wrote: > Author: dgregor > Date: Mon Aug 30 09:50:47 2010 > New Revision: 112481 > > URL: http://llvm.org/viewvc/llvm-project?rev=112481&view=rev > Log: > 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.
You may or may not care, but this patch isn't correct. It will not correctly lex things like: 0\ x1234e+1 Please change this to use getCharAndSize. -Chris > > Modified: > cfe/trunk/lib/Lex/Lexer.cpp > cfe/trunk/test/Lexer/ms-extensions.c > > Modified: cfe/trunk/lib/Lex/Lexer.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=112481&r1=112480&r2=112481&view=diff > ============================================================================== > --- cfe/trunk/lib/Lex/Lexer.cpp (original) > +++ cfe/trunk/lib/Lex/Lexer.cpp Mon Aug 30 09:50:47 2010 > @@ -925,6 +925,11 @@ > } > } > > +/// 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 @@ > } > > // 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. > > Modified: cfe/trunk/test/Lexer/ms-extensions.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/ms-extensions.c?rev=112481&r1=112480&r2=112481&view=diff > ============================================================================== > --- cfe/trunk/test/Lexer/ms-extensions.c (original) > +++ cfe/trunk/test/Lexer/ms-extensions.c Mon Aug 30 09:50:47 2010 > @@ -23,3 +23,11 @@ > 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; > +} > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
