[cfe-commits] r147138 - in /cfe/trunk: lib/Lex/Lexer.cpp test/Lexer/escape_newline.c

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Dec 21 20:38:07 PST 2011


Author: akirtzidis
Date: Wed Dec 21 22:38:07 2011
New Revision: 147138

URL: http://llvm.org/viewvc/llvm-project?rev=147138&view=rev
Log:
In Lexer::getCharAndSizeSlow[NoWarn] if we come up against

\<newline><newline>

don't consume the second newline.

Thanks to David Blaikie for pointing out the crash!

Modified:
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/test/Lexer/escape_newline.c

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=147138&r1=147137&r2=147138&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Wed Dec 21 22:38:07 2011
@@ -1172,8 +1172,11 @@
       Size += EscapedNewLineSize;
       Ptr  += EscapedNewLineSize;
 
-      if (Ptr[0] == '\0')
-        return '\\';
+      // If the char that we finally got was a \n, then we must have had
+      // something like \<newline><newline>.  We don't want to consume the
+      // second newline.
+      if (*Ptr == '\n' || *Ptr == '\r' || *Ptr == '\0')
+        return ' ';
 
       // Use slow version to accumulate a correct size field.
       return getCharAndSizeSlow(Ptr, Size, Tok);
@@ -1226,8 +1229,11 @@
       Size += EscapedNewLineSize;
       Ptr  += EscapedNewLineSize;
 
-      if (Ptr[0] == '\0')
-        return '\\';
+      // If the char that we finally got was a \n, then we must have had
+      // something like \<newline><newline>.  We don't want to consume the
+      // second newline.
+      if (*Ptr == '\n' || *Ptr == '\r' || *Ptr == '\0')
+        return ' ';
 
       // Use slow version to accumulate a correct size field.
       return getCharAndSizeSlowNoWarn(Ptr, Size, Features);
@@ -1696,14 +1702,6 @@
       break;
     }
 
-    // If the char that we finally got was a \n, then we must have had something
-    // like \<newline><newline>.  We don't want to have consumed the second
-    // newline, we want CurPtr, to end up pointing to it down below.
-    if (C == '\n' || C == '\r') {
-      --CurPtr;
-      C = 'x'; // doesn't matter what this is.
-    }
-
     // If we read multiple characters, and one of those characters was a \r or
     // \n, then we had an escaped newline within the comment.  Emit diagnostic
     // unless the next line is also a // comment.

Modified: cfe/trunk/test/Lexer/escape_newline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/escape_newline.c?rev=147138&r1=147137&r2=147138&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/escape_newline.c (original)
+++ cfe/trunk/test/Lexer/escape_newline.c Wed Dec 21 22:38:07 2011
@@ -8,3 +8,4 @@
 >
 
 // \
+





More information about the cfe-commits mailing list