]> granicus.if.org Git - clang/commitdiff
fix rdar://6757323, where an escaped newline in a // comment
authorChris Lattner <sabre@nondot.org>
Sun, 5 Apr 2009 00:26:41 +0000 (00:26 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 5 Apr 2009 00:26:41 +0000 (00:26 +0000)
was causing the char after the newline to get eaten.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68430 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/Lexer/comment-escape.c [new file with mode: 0644]

index 3a3e86a3cf1daf03985b47f90ffaf567118df2f1..059afe2182201f3c4205c52f3489b1c645a04940 100644 (file)
@@ -848,6 +848,14 @@ bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) {
     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
diff --git a/test/Lexer/comment-escape.c b/test/Lexer/comment-escape.c
new file mode 100644 (file)
index 0000000..c568cd6
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only %s 
+// rdar://6757323
+// foo \
+
+#define        blork 32
+