Fix the root cause of PR2750 instead of the side effect.

NumericLiteral parser is not careful about overrun because
it should never be possible.  It implicitly expects that its
input matched the regex for pp-constant.  Because of this, it
knows it can't be pointing to a prefix of something that
looks like a number.  This is all fine, except that __LINE__
does not prevent implicit concatenation from happening.  Fix
__LINE__ to not do this.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56818 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp
index 8c2f2af..a66aaa2 100644
--- a/lib/Lex/LiteralSupport.cpp
+++ b/lib/Lex/LiteralSupport.cpp
@@ -224,7 +224,7 @@
       saw_period = true;
       s = SkipDigits(s);
     } 
-    if (s != ThisTokEnd && (*s == 'e' || *s == 'E')) { // exponent
+    if ((*s == 'e' || *s == 'E')) { // exponent
       const char *Exponent = s;
       s++;
       saw_exponent = true;
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index fb9b613..43df71a 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -445,12 +445,15 @@
   Tok.clearFlag(Token::NeedsCleaning);
   
   if (II == Ident__LINE__) {
-    // __LINE__ expands to a simple numeric value.
-    sprintf(TmpBuffer, "%u", SourceMgr.getLogicalLineNumber(Tok.getLocation()));
-    unsigned Length = strlen(TmpBuffer);
+    // __LINE__ expands to a simple numeric value.  Add a space after it so that
+    // it will tokenize as a number (and not run into stuff after it in the temp
+    // buffer).
+    sprintf(TmpBuffer, "%u ",
+            SourceMgr.getLogicalLineNumber(Tok.getLocation()));
+    unsigned Length = strlen(TmpBuffer)-1;
     Tok.setKind(tok::numeric_constant);
     Tok.setLength(Length);
-    Tok.setLocation(CreateString(TmpBuffer, Length, Tok.getLocation()));
+    Tok.setLocation(CreateString(TmpBuffer, Length+1, Tok.getLocation()));
   } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
     SourceLocation Loc = Tok.getLocation();
     if (II == Ident__BASE_FILE__) {
@@ -489,9 +492,11 @@
     for (; Loc.isValid(); ++Depth)
       Loc = SourceMgr.getIncludeLoc(Loc);
     
-    // __INCLUDE_LEVEL__ expands to a simple numeric value.
-    sprintf(TmpBuffer, "%u", Depth);
-    unsigned Length = strlen(TmpBuffer);
+    // __INCLUDE_LEVEL__ expands to a simple numeric value.  Add a space after
+    // it so that it will tokenize as a number (and not run into stuff after it
+    // in the temp buffer).
+    sprintf(TmpBuffer, "%u ", Depth);
+    unsigned Length = strlen(TmpBuffer)-1;
     Tok.setKind(tok::numeric_constant);
     Tok.setLength(Length);
     Tok.setLocation(CreateString(TmpBuffer, Length, Tok.getLocation()));
@@ -523,7 +528,7 @@
     TmpBuffer[Len-1] = '"';  // Replace the newline with a quote.
     Tok.setKind(tok::string_literal);
     Tok.setLength(Len);
-    Tok.setLocation(CreateString(TmpBuffer, Len, Tok.getLocation()));
+    Tok.setLocation(CreateString(TmpBuffer, Len+1, Tok.getLocation()));
   } else {
     assert(0 && "Unknown identifier!");
   }