[cfe-commits] r57403 - /cfe/trunk/lib/Lex/Lexer.cpp

Chris Lattner sabre at nondot.org
Sat Oct 11 21:19:49 PDT 2008


Author: lattner
Date: Sat Oct 11 23:19:49 2008
New Revision: 57403

URL: http://llvm.org/viewvc/llvm-project?rev=57403&view=rev
Log:
When in keep whitespace mode, make sure to return block comments that are
unterminated.

Modified:
    cfe/trunk/lib/Lex/Lexer.cpp

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

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Sat Oct 11 23:19:49 2008
@@ -956,7 +956,17 @@
   if (C == 0 && CurPtr == BufferEnd+1) {
     if (!LexingRawMode)
       Diag(BufferPtr, diag::err_unterminated_block_comment);
-    BufferPtr = CurPtr-1;
+    --CurPtr;
+    
+    // KeepWhitespaceMode should return this broken comment as a token.  Since
+    // it isn't a well formed comment, just return it as an 'unknown' token.
+    if (isKeepWhitespaceMode()) {
+      Result.setKind(tok::unknown);
+      FormTokenWithChars(Result, CurPtr);
+      return true;
+    }
+    
+    BufferPtr = CurPtr;
     return false;
   }
   
@@ -1031,7 +1041,17 @@
       // Note: the user probably forgot a */.  We could continue immediately
       // after the /*, but this would involve lexing a lot of what really is the
       // comment, which surely would confuse the parser.
-      BufferPtr = CurPtr-1;
+      --CurPtr;
+      
+      // KeepWhitespaceMode should return this broken comment as a token.  Since
+      // it isn't a well formed comment, just return it as an 'unknown' token.
+      if (isKeepWhitespaceMode()) {
+        Result.setKind(tok::unknown);
+        FormTokenWithChars(Result, CurPtr);
+        return true;
+      }
+      
+      BufferPtr = CurPtr;
       return false;
     }
     C = *CurPtr++;





More information about the cfe-commits mailing list