[PATCH] D41834: [Lex] Fix handling numerical literals ending with ' and signed exponent.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 13:03:48 PST 2018


vsapsai created this revision.
vsapsai added reviewers: rsmith, t.p.northover.

For input `0'e+1` lexer tokenized as numeric constant only `0'e`. Later
NumericLiteralParser skipped 0 and ' as digits and parsed `e+1` as valid
exponent going past the end of the token. Because it didn't mark numeric
literal as having an error, it continued parsing and tried to expandUCNs
with StringRef of length -2.

The fix is to update error state when digit separator is encountered
after digits, so that we don't try to keep parsing invalid input.

Discovered by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4588

rdar://problem/36076719


https://reviews.llvm.org/D41834

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/cxx1y_digit_separators.cpp


Index: clang/test/Lexer/cxx1y_digit_separators.cpp
===================================================================
--- clang/test/Lexer/cxx1y_digit_separators.cpp
+++ clang/test/Lexer/cxx1y_digit_separators.cpp
@@ -51,6 +51,7 @@
   float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires a significand}}
   float v = 0e'f; // expected-error {{exponent has no digits}}
   float w = 0x0p'f; // expected-error {{exponent has no digits}}
+  float x = 0'e+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
 }
 
 #line 123'456
Index: clang/lib/Lex/LiteralSupport.cpp
===================================================================
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -787,10 +787,12 @@
   } else if (Pos == ThisTokEnd)
     return;
 
-  if (isDigitSeparator(*Pos))
+  if (isDigitSeparator(*Pos)) {
     PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Pos - ThisTokBegin),
             diag::err_digit_separator_not_between_digits)
       << IsAfterDigits;
+    hadError = true;
+  }
 }
 
 /// ParseNumberStartingWithZero - This method is called when the first character


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41834.128972.patch
Type: text/x-patch
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180108/26fff691/attachment.bin>


More information about the cfe-commits mailing list