]> granicus.if.org Git - clang/commitdiff
Fix a lexer bug where we incorrectly rejected
authorChris Lattner <sabre@nondot.org>
Sat, 21 Jul 2007 23:43:37 +0000 (23:43 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Jul 2007 23:43:37 +0000 (23:43 +0000)
int i = /*/ */ 1;

Thanks to Neil for pointing this out.

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

Lex/Lexer.cpp
test/Lexer/block_cmt_end.c

index 1518d8895ce386a3096706a86c17823c38c45617..e92fc94da2e8c3af8915615bbfe262de9d72b86e 100644 (file)
@@ -817,13 +817,24 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) {
   // we find it, check to see if it was preceeded by a *.  This common
   // optimization helps people who like to put a lot of * characters in their
   // comments.
-  unsigned char C = *CurPtr++;
+
+  // The first character we get with newlines and trigraphs skipped to handle
+  // the degenerate /*/ case below correctly if the * has an escaped newline
+  // after it.
+  unsigned CharSize;
+  unsigned char C = getCharAndSize(CurPtr, CharSize);
+  CurPtr += CharSize;
   if (C == 0 && CurPtr == BufferEnd+1) {
     Diag(BufferPtr, diag::err_unterminated_block_comment);
     BufferPtr = CurPtr-1;
     return true;
   }
   
+  // Check to see if the first character after the '/*' is another /.  If so,
+  // then this slash does not end the block comment, it is part of it.
+  if (C == '/')
+    C = *CurPtr++;
+  
   while (1) {
     // Skip over all non-interesting characters until we find end of buffer or a
     // (probably ending) '/' character.
index b111b2a23e3b13151f2a9df142377f02c6e5c2ce..20d9045221358ac569d5a79499b846a540f6cfde 100644 (file)
@@ -6,6 +6,9 @@
   RUN: clang -parse-ast-check %s
  */
 
+// This is a simple comment, /*/ does not end a comment, the trailing */ does.
+int i = /*/ */ 1;
+
 /* abc
 
 next comment ends with normal escaped newline: