[cfe-commits] r68430 - in /cfe/trunk: lib/Lex/Lexer.cpp test/Lexer/comment-escape.c

Chris Lattner sabre at nondot.org
Sat Apr 4 17:26:44 PDT 2009


Author: lattner
Date: Sat Apr  4 19:26:41 2009
New Revision: 68430

URL: http://llvm.org/viewvc/llvm-project?rev=68430&view=rev
Log:
fix rdar://6757323, where an escaped newline in a // comment
was causing the char after the newline to get eaten.

Added:
    cfe/trunk/test/Lexer/comment-escape.c
Modified:
    cfe/trunk/lib/Lex/Lexer.cpp

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=68430&r1=68429&r2=68430&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Sat Apr  4 19:26:41 2009
@@ -848,6 +848,14 @@
     LexingRawMode = true;
     C = getAndAdvanceChar(CurPtr, Result);
     LexingRawMode = OldRawMode;
+
+    // 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

Added: cfe/trunk/test/Lexer/comment-escape.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/comment-escape.c?rev=68430&view=auto

==============================================================================
--- cfe/trunk/test/Lexer/comment-escape.c (added)
+++ cfe/trunk/test/Lexer/comment-escape.c Sat Apr  4 19:26:41 2009
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only %s 
+// rdar://6757323
+// foo \
+
+#define	blork 32
+





More information about the cfe-commits mailing list