Author: hans
Date: Thu Feb  8 00:17:53 2018
New Revision: 324579

URL: http://llvm.org/viewvc/llvm-project?rev=324579&view=rev
Log:
Merging r324419:
------------------------------------------------------------------------
r324419 | vsapsai | 2018-02-06 23:39:25 +0100 (Tue, 06 Feb 2018) | 23 lines

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

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 not to parse exponent when we reached the end of token.

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

rdar://problem/36076719

Reviewers: rsmith, t.p.northover

Reviewed By: rsmith

Subscribers: cfe-commits, jkorous-apple

Differential Revision: https://reviews.llvm.org/D41834

------------------------------------------------------------------------

Modified:
    cfe/branches/release_60/   (props changed)
    cfe/branches/release_60/lib/Lex/LiteralSupport.cpp
    cfe/branches/release_60/test/Lexer/cxx1y_digit_separators.cpp

Propchange: cfe/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb  8 00:17:53 2018
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322245-322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123,323155,323360,323485,323904,323935,324059,324134,324246,324439
+/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322245-322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123,323155,323360,323485,323904,323935,324059,324134,324246,324419,324439
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_60/lib/Lex/LiteralSupport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/Lex/LiteralSupport.cpp?rev=324579&r1=324578&r2=324579&view=diff
==============================================================================
--- cfe/branches/release_60/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/branches/release_60/lib/Lex/LiteralSupport.cpp Thu Feb  8 00:17:53 2018
@@ -738,15 +738,17 @@ void NumericLiteralParser::ParseDecimalO
     s++;
     radix = 10;
     saw_exponent = true;
-    if (*s == '+' || *s == '-')  s++; // sign
+    if (s != ThisTokEnd && (*s == '+' || *s == '-'))  s++; // sign
     const char *first_non_digit = SkipDigits(s);
     if (containsDigits(s, first_non_digit)) {
       checkSeparator(TokLoc, s, CSK_BeforeDigits);
       s = first_non_digit;
     } else {
-      PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
-              diag::err_exponent_has_no_digits);
-      hadError = true;
+      if (!hadError) {
+        PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
+                diag::err_exponent_has_no_digits);
+        hadError = true;
+      }
       return;
     }
   }
@@ -787,10 +789,12 @@ void NumericLiteralParser::checkSeparato
   } 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
@@ -840,12 +844,14 @@ void NumericLiteralParser::ParseNumberSt
       const char *Exponent = s;
       s++;
       saw_exponent = true;
-      if (*s == '+' || *s == '-')  s++; // sign
+      if (s != ThisTokEnd && (*s == '+' || *s == '-'))  s++; // sign
       const char *first_non_digit = SkipDigits(s);
       if (!containsDigits(s, first_non_digit)) {
-        PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
-                diag::err_exponent_has_no_digits);
-        hadError = true;
+        if (!hadError) {
+          PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
+                  diag::err_exponent_has_no_digits);
+          hadError = true;
+        }
         return;
       }
       checkSeparator(TokLoc, s, CSK_BeforeDigits);

Modified: cfe/branches/release_60/test/Lexer/cxx1y_digit_separators.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/test/Lexer/cxx1y_digit_separators.cpp?rev=324579&r1=324578&r2=324579&view=diff
==============================================================================
--- cfe/branches/release_60/test/Lexer/cxx1y_digit_separators.cpp (original)
+++ cfe/branches/release_60/test/Lexer/cxx1y_digit_separators.cpp Thu Feb  8 
00:17:53 2018
@@ -51,6 +51,8 @@ namespace floating {
   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}}
+  float y = 0x0'p+1; // expected-error {{digit separator cannot appear at end 
of digit sequence}}
 }
 
 #line 123'456


_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to