[PATCH] D57321: Fix LexFloatLiteral Lexing

Brandon Jones via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 28 04:41:51 PST 2019


BrandonTJones created this revision.
BrandonTJones added a reviewer: clayborg.
Herald added subscribers: llvm-commits, hiraditya.

Fix LexFloatLiteral Lexing to enforce the correct format before returning AsmToken::Real. It now reports an error on a wider range of invalid inputs. See test update for details.


Repository:
  rL LLVM

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
@@ -53,2 +53,5 @@
-//.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
Index: llvm/lib/MC/MCParser/AsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmLexer.cpp
+++ llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -69 +69 @@
-AsmToken AsmLexer::LexFloatLiteral() {
+AsmToken AsmLexer::LexFloatLiteral(bool isDotSeperated) {
@@ -77 +77,3 @@
-  if (*CurPtr == 'e' || *CurPtr == 'E') {
+  if (isDotSeperated && (*CurPtr == 'e' || *CurPtr == 'E') &&
+      (isDigit(CurPtr[1]) ||
+       ((CurPtr[1] == '-' || CurPtr[1] == '+') && isDigit(CurPtr[2])))) {
@@ -79 +81 @@
-    if (*CurPtr == '-' || *CurPtr == '+')
+    if ((*CurPtr == '-' || *CurPtr == '+') && isDigit(CurPtr[1]))
@@ -148,3 +150,7 @@
-    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);
@@ -329 +335,4 @@
-    if (!isHex && (*CurPtr == '.' || *CurPtr == 'e')) {
+    if ((!isHex && (*CurPtr == '.' || *CurPtr == 'e')) &&
+        (isDigit(CurPtr[1]) || ((CurPtr[1] == '-' || CurPtr[1] == '+' ||
+                                 (*CurPtr == '.' && CurPtr[1] == 'e')) &&
+                                isDigit(CurPtr[2])))) {
@@ -331 +340,3 @@
-      return LexFloatLiteral();
+      if (CurPtr[-1] == '.')
+        return LexFloatLiteral(true);
+      return LexFloatLiteral(false);
Index: llvm/include/llvm/MC/MCParser/AsmLexer.h
===================================================================
--- llvm/include/llvm/MC/MCParser/AsmLexer.h
+++ llvm/include/llvm/MC/MCParser/AsmLexer.h
@@ -65 +65 @@
-  AsmToken LexFloatLiteral();
+  AsmToken LexFloatLiteral(bool isDotSeperated);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57321.183827.patch
Type: text/x-patch
Size: 2379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190128/8681a060/attachment.bin>


More information about the llvm-commits mailing list