[PATCH] D57321: Fix LexFloatLiteral Lexing
Brandon Jones via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 28 04:55:07 PST 2019
BrandonTJones updated this revision to Diff 183829.
BrandonTJones added a comment.
I fixed the -U modifier on my diff as my diff was incorrect
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57321/new/
https://reviews.llvm.org/D57321
Files:
llvm/include/llvm/MC/MCParser/AsmLexer.h
llvm/lib/MC/MCParser/AsmLexer.cpp
llvm/test/MC/AsmParser/floating-literals.s
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
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/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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57321.183829.patch
Type: text/x-patch
Size: 3548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190128/ea4c7765/attachment.bin>
More information about the llvm-commits
mailing list