]> granicus.if.org Git - clang/commitdiff
In Lexer::getCharAndSizeSlow[NoWarn] if we come up against
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 22 Dec 2011 04:38:07 +0000 (04:38 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 22 Dec 2011 04:38:07 +0000 (04:38 +0000)
\<newline><newline>

don't consume the second newline.

Thanks to David Blaikie for pointing out the crash!

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

lib/Lex/Lexer.cpp
test/Lexer/escape_newline.c

index acb5b8a797edd7fb0dfb1702dce97faef57722ee..d3a97b42b1917e6a00cf4e0d32431ecb7a51ee05 100644 (file)
@@ -1172,8 +1172,11 @@ Slash:
       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 @@ Slash:
       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 @@ bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) {
       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.
index 5e3002859c6336a6dce83bfafa63706033f9a3bf..d0f27dffdf71913b9089be44500627aa0a0733bd 100644 (file)
@@ -8,3 +8,4 @@
 >
 
 // \
+