[PATCH] D101923: [TableGen] Make the NUL character invalid in .td files

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 13:30:57 PDT 2021


Paul-C-Anagnostopoulos added inline comments.


================
Comment at: llvm/lib/TableGen/TGLexer.cpp:420-424
+/// Or we may end up at the end of the buffer.
 void TGLexer::SkipBCPLComment() {
   ++CurPtr;  // skip the second slash.
-  while (true) {
-    switch (*CurPtr) {
-    case '\n':
-    case '\r':
-      return;  // Newline is end of comment.
-    case 0:
-      // If this is the end of the buffer, end the comment.
-      if (CurPtr == CurBuf.end())
-        return;
-      break;
-    }
-    // Otherwise, skip the character.
-    ++CurPtr;
-  }
+  auto EOLPos = CurBuf.find_first_of("\r\n", CurPtr - CurBuf.data());
+  CurPtr = (EOLPos == StringRef::npos) ? CurBuf.end() : CurBuf.data() + EOLPos;
----------------
dblaikie wrote:
> So previously a null character would terminate a comment - and with this change it won't terminate the comment anymore? Maybe this would be better in a separate patch (& maybe with a test demonstrating this behavior)
It didn't terminate the comment, but rather was included in the comment. Just as the new code does. 

Good idea to write a test for this. I will write one tomorrow.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101923/new/

https://reviews.llvm.org/D101923



More information about the llvm-commits mailing list