Index: llvm/include/llvm/MC/MCParser/AsmLexer.h =================================================================== --- llvm/include/llvm/MC/MCParser/AsmLexer.h +++ llvm/include/llvm/MC/MCParser/AsmLexer.h @@ -62,7 +62,7 @@ AsmToken LexDigit(); AsmToken LexSingleQuote(); AsmToken LexQuote(); - AsmToken LexFloatLiteral(); + AsmToken LexFloatLiteral(bool isDotSeperated); AsmToken LexHexFloatLiteral(bool NoIntDigits); StringRef LexUntilEndOfLine(); Index: llvm/lib/MC/MCParser/AsmLexer.cpp =================================================================== --- llvm/lib/MC/MCParser/AsmLexer.cpp +++ llvm/lib/MC/MCParser/AsmLexer.cpp @@ -66,7 +66,7 @@ /// The leading integral digit sequence and dot should have already been /// consumed, some or all of the fractional digit sequence *can* have been /// consumed. -AsmToken AsmLexer::LexFloatLiteral() { +AsmToken AsmLexer::LexFloatLiteral(bool isDotSeperated) { // Skip the fractional digit sequence. while (isDigit(*CurPtr)) ++CurPtr; @@ -74,9 +74,11 @@ // Check for exponent; we intentionally accept a slighlty wider set of // literals here and rely on the upstream client to reject invalid ones (e.g., // "1e+"). - if (*CurPtr == 'e' || *CurPtr == 'E') { + if (isDotSeperated && (*CurPtr == 'e' || *CurPtr == 'E') && + (isDigit(CurPtr[1]) || + ((CurPtr[1] == '-' || CurPtr[1] == '+') && isDigit(CurPtr[2])))) { ++CurPtr; - if (*CurPtr == '-' || *CurPtr == '+') + if ((*CurPtr == '-' || *CurPtr == '+') && isDigit(CurPtr[1])) ++CurPtr; while (isDigit(*CurPtr)) ++CurPtr; @@ -145,9 +147,13 @@ // Disambiguate a .1243foo identifier from a floating literal. while (isDigit(*CurPtr)) ++CurPtr; - if (*CurPtr == 'e' || *CurPtr == 'E' || - !IsIdentifierChar(*CurPtr, AllowAtInIdentifier)) - return LexFloatLiteral(); + if ((!IsIdentifierChar(*CurPtr, AllowAtInIdentifier) && + (*CurPtr != 'e' && *CurPtr != 'E')) || + (!IsIdentifierChar(*CurPtr, AllowAtInIdentifier) && + (*CurPtr == 'e' && *CurPtr == 'E') && + (isDigit(CurPtr[1]) || + ((CurPtr[1] == '-' || CurPtr[1] == '+') && isDigit(CurPtr[2]))))) + return LexFloatLiteral(false); } while (IsIdentifierChar(*CurPtr, AllowAtInIdentifier)) @@ -326,9 +332,14 @@ unsigned Radix = doHexLookAhead(CurPtr, 10, LexMasmIntegers); bool isHex = Radix == 16; // Check for floating point literals. - if (!isHex && (*CurPtr == '.' || *CurPtr == 'e')) { + if ((!isHex && (*CurPtr == '.' || *CurPtr == 'e')) && + (isDigit(CurPtr[1]) || ((CurPtr[1] == '-' || CurPtr[1] == '+' || + (*CurPtr == '.' && CurPtr[1] == 'e')) && + isDigit(CurPtr[2])))) { ++CurPtr; - return LexFloatLiteral(); + if (CurPtr[-1] == '.') + return LexFloatLiteral(true); + return LexFloatLiteral(false); } StringRef Result(TokStart, CurPtr - TokStart); Index: llvm/test/MC/AsmParser/floating-literals.s =================================================================== --- llvm/test/MC/AsmParser/floating-literals.s +++ llvm/test/MC/AsmParser/floating-literals.s @@ -50,8 +50,11 @@ .double 2. // APFloat should reject these with an error, not crash: -//.double -1.2e+ -//.double -1.2e + +#CHECK-ERROR: unexpected token in '.double' directive +.double -1.2e+ +#CHECK-ERROR: unexpected token in '.double' directive +.double -1.2e # CHECK: .long 1310177520 .float 0x12f7.1ep+17