<div dir="ltr">Ping.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 12, 2013 at 12:45 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im HOEnZb">ruiu added you to the CC list for the revision "Fix block comment parser".<br>
<br>
</div><div class="HOEnZb"><div class="h5">Fixes a bug in block comment parser. Clang is now able to parse the following block comment.<br>
<br>
/* *\<br>
\<br>
/<br>
<br>
Before this patch, Clang could skip only one escaped newline between * and /.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D777" target="_blank">http://llvm-reviews.chandlerc.com/D777</a><br>
<br>
Files:<br>
  lib/Lex/Lexer.cpp<br>
  test/Lexer/block_cmt_end.c<br>
<br>
Index: lib/Lex/Lexer.cpp<br>
===================================================================<br>
--- lib/Lex/Lexer.cpp<br>
+++ lib/Lex/Lexer.cpp<br>
@@ -2076,58 +2076,66 @@<br>
 static bool isEndOfBlockCommentWithEscapedNewLine(const char *CurPtr,<br>
                                                   Lexer *L) {<br>
   assert(CurPtr[0] == '\n' || CurPtr[0] == '\r');<br>
+  const char *WhitespacePos = 0;<br>
+  const char *TrigraphPos = 0;<br>
<br>
-  // Back up off the newline.<br>
-  --CurPtr;<br>
-<br>
-  // If this is a two-character newline sequence, skip the other character.<br>
-  if (CurPtr[0] == '\n' || CurPtr[0] == '\r') {<br>
-    // \n\n or \r\r -> not escaped newline.<br>
-    if (CurPtr[0] == CurPtr[1])<br>
-      return false;<br>
-    // \n\r or \r\n -> skip the newline.<br>
+  // Skip escaped newlines, or return if it's not an escaped newline sequence.<br>
+  do {<br>
+    // Back up off the newline.<br>
     --CurPtr;<br>
-  }<br>
<br>
-  // If we have horizontal whitespace, skip over it.  We allow whitespace<br>
-  // between the slash and newline.<br>
-  bool HasSpace = false;<br>
-  while (isHorizontalWhitespace(*CurPtr) || *CurPtr == 0) {<br>
-    --CurPtr;<br>
-    HasSpace = true;<br>
-  }<br>
+    // If this is a two-character newline sequence, skip the other character.<br>
+    if (CurPtr[0] == '\n' || CurPtr[0] == '\r') {<br>
+      // \n\n or \r\r -> not escaped newline.<br>
+      if (CurPtr[0] == CurPtr[1])<br>
+        return false;<br>
+      // \n\r or \r\n -> skip the newline.<br>
+      --CurPtr;<br>
+    }<br>
<br>
-  // If we have a slash, we know this is an escaped newline.<br>
-  if (*CurPtr == '\\') {<br>
-    if (CurPtr[-1] != '*') return false;<br>
-  } else {<br>
-    // It isn't a slash, is it the ?? / trigraph?<br>
-    if (CurPtr[0] != '/' || CurPtr[-1] != '?' || CurPtr[-2] != '?' ||<br>
-        CurPtr[-3] != '*')<br>
+    // If we have horizontal whitespace, skip over it.  We allow whitespace<br>
+    // between the backslash and newline.<br>
+    while (isHorizontalWhitespace(*CurPtr) || *CurPtr == 0) {<br>
</div></div><div class="im HOEnZb">+      WhitespacePos = CurPtr;<br>
+      --CurPtr;<br>
</div><div class="im HOEnZb">+    }<br>
+<br>
+    // If we have a backslash, skip over it.<br>
+    if (*CurPtr == '\\') {<br>
+      --CurPtr;<br>
+    } else if (CurPtr[0] == '/' || CurPtr[-1] == '?' || CurPtr[-2] == '?') {<br>
+      // It was not a backslash, but the trigraph equivalent to backslash.<br>
+      TrigraphPos = CurPtr - 2;<br>
+      CurPtr -= 3;<br>
+    } else {<br>
       return false;<br>
+    }<br>
+  } while (*CurPtr == '\n' || *CurPtr == '\r');<br>
<br>
</div><div class="im HOEnZb">-    // This is the trigraph ending the comment.  Emit a stern warning!<br>
-    CurPtr -= 2;<br>
+  // If the character before an escaped newline is not '*', the last<br>
+  // slash was not the end of block comment after all.<br>
+  if (*CurPtr != '*')<br>
+    return false;<br>
<br>
</div><div class="im HOEnZb">-    // If no trigraphs are enabled, warn that we ignored this trigraph and<br>
-    // ignore this * character.<br>
+  // If no trigraphs are enabled, warn that we ignored this trigraph and ignore<br>
+  // this * character.<br>
+  if (TrigraphPos) {<br>
     if (!L->getLangOpts().Trigraphs) {<br>
       if (!L->isLexingRawMode())<br>
-        L->Diag(CurPtr, diag::trigraph_ignored_block_comment);<br>
+        L->Diag(TrigraphPos, diag::trigraph_ignored_block_comment);<br>
       return false;<br>
     }<br>
     if (!L->isLexingRawMode())<br>
-      L->Diag(CurPtr, diag::trigraph_ends_block_comment);<br>
+      L->Diag(TrigraphPos, diag::trigraph_ends_block_comment);<br>
   }<br>
<br>
</div><div class="im HOEnZb">   // Warn about having an escaped newline between the */ characters.<br>
</div><div class="im HOEnZb">   if (!L->isLexingRawMode())<br>
     L->Diag(CurPtr, diag::escaped_newline_block_comment_end);<br>
<br>
</div><div class="HOEnZb"><div class="h5">   // If there was space between the backslash and newline, warn about it.<br>
-  if (HasSpace && !L->isLexingRawMode())<br>
-    L->Diag(CurPtr, diag::backslash_newline_space);<br>
-<br>
+  if (WhitespacePos && !L->isLexingRawMode())<br>
+    L->Diag(WhitespacePos, diag::backslash_newline_space);<br>
   return true;<br>
 }<br>
<br>
Index: test/Lexer/block_cmt_end.c<br>
===================================================================<br>
--- test/Lexer/block_cmt_end.c<br>
+++ test/Lexer/block_cmt_end.c<br>
@@ -3,7 +3,7 @@<br>
   RUN: %clang_cc1 -E -trigraphs %s | grep foo<br>
   RUN: %clang_cc1 -E -trigraphs %s | not grep qux<br>
   RUN: %clang_cc1 -E -trigraphs %s | not grep xyz<br>
-  RUN: %clang_cc1 -fsyntax-only -trigraphs -verify %s<br>
+  RUN: %clang_cc1 -fsyntax-only -trigraphs -verify %s<br>
 */<br>
<br>
 // This is a simple comment, /*/ does not end a comment, the trailing */ does.<br>
@@ -14,21 +14,36 @@<br>
 next comment ends with normal escaped newline:<br>
 */<br>
<br>
-/* expected-warning {{escaped newline}} expected-warning {{backslash and newline}}  *\<br>
+/* expected-warning {{escaped newline}} *\<br>
+\<br>
 /<br>
<br>
+/* expected-warning@24 {{escaped newline}}<br>
+   expected-warning@25 {{trigraph ends block comment}}<br>
+   expected-warning@26 {{backslash and newline separated by space}}<br>
+*\<br>
+??/<br>
+\<br>
+/<br>
+<br>
+// "*\n/" does not end a comment.<br>
+/* *<br>
+/<br>
+*/<br>
+<br>
+// "* \\\n/" does not end a comment.<br>
+/* * \<br>
+/<br>
+*/<br>
+<br>
 int bar /* expected-error {{expected ';' after top level declarator}} */<br>
<br>
 /* xyz<br>
<br>
 next comment ends with a trigraph escaped newline: */<br>
<br>
-/* expected-warning {{escaped newline between}}   expected-warning {{backslash and newline separated by space}}    expected-warning {{trigraph ends block comment}}   *??/<br>
-/<br>
-<br>
 foo<br>
<br>
-<br>
 // rdar://6060752 - We should not get warnings about trigraphs in comments:<br>
 // '????'<br>
 /* ???? */<br>
</div></div><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>