[cfe-commits] r40379 - in /cfe/trunk: Lex/Lexer.cpp test/Lexer/block_cmt_end.c

Chris Lattner sabre at nondot.org
Sat Jul 21 16:43:38 PDT 2007


Author: lattner
Date: Sat Jul 21 18:43:37 2007
New Revision: 40379

URL: http://llvm.org/viewvc/llvm-project?rev=40379&view=rev
Log:
Fix a lexer bug where we incorrectly rejected
int i = /*/ */ 1;

Thanks to Neil for pointing this out.



Modified:
    cfe/trunk/Lex/Lexer.cpp
    cfe/trunk/test/Lexer/block_cmt_end.c

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

==============================================================================
--- cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/trunk/Lex/Lexer.cpp Sat Jul 21 18:43:37 2007
@@ -817,13 +817,24 @@
   // 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.

Modified: cfe/trunk/test/Lexer/block_cmt_end.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/block_cmt_end.c?rev=40379&r1=40378&r2=40379&view=diff

==============================================================================
--- cfe/trunk/test/Lexer/block_cmt_end.c (original)
+++ cfe/trunk/test/Lexer/block_cmt_end.c Sat Jul 21 18:43:37 2007
@@ -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:





More information about the cfe-commits mailing list