[llvm] df89bca - [TableGen] Treat carriage return as line end in prepSkipRegion (#212411)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 08:08:21 PDT 2026


Author: Kevin Bravo
Date: 2026-07-28T16:08:16+01:00
New Revision: df89bcad92cd1a8539d85b200e89182f26743b6f

URL: https://github.com/llvm/llvm-project/commit/df89bcad92cd1a8539d85b200e89182f26743b6f
DIFF: https://github.com/llvm/llvm-project/commit/df89bcad92cd1a8539d85b200e89182f26743b6f.diff

LOG: [TableGen] Treat carriage return as line end in prepSkipRegion (#212411)

`prepSkipRegion` currently only treats newline and EOF as end of line.
However, in the TableGen Programmer's Reference:

LineEnd ::=  newline | return | EOF

So carriage return is a valid end-of-line, but `prepSkipRegion` ignores
it and skips code after the carriage return that it shouldn't. This
change fixes the end-of-line check in `prepSkipRegion` so that it also
treats carriage return as end of line.

Related issue: #151476.

Added: 
    llvm/test/TableGen/ifdef-cr-instead-of-newline.td

Modified: 
    llvm/lib/TableGen/TGLexer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index 238b1a35a85d3..ea0b10b1b443a 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -913,7 +913,7 @@ bool TGLexer::prepSkipRegion(bool MustNeverBeFalse) {
 
   do {
     // Skip all symbols to the line end.
-    while (CurPtr != CurBuf.end() && *CurPtr != '\n')
+    while (CurPtr != CurBuf.end() && *CurPtr != '\n' && *CurPtr != '\r')
       ++CurPtr;
 
     // Find the first non-whitespace symbol in the next line(s).

diff  --git a/llvm/test/TableGen/ifdef-cr-instead-of-newline.td b/llvm/test/TableGen/ifdef-cr-instead-of-newline.td
new file mode 100644
index 0000000000000..207e8abdd368c
--- /dev/null
+++ b/llvm/test/TableGen/ifdef-cr-instead-of-newline.td
@@ -0,0 +1,7 @@
+// LineEnd ::=  newline | return | EOF
+// Preprocessor must treat all the \r's as line ends.
+// This means, for example, not skipping the first #endif thinking that it's
+// part of the #ifdef body.
+// RUN: printf "#ifdef FOO\rhello\r#endif\r#endif\r" | not llvm-tblgen 2>&1 | FileCheck %s
+// CHECK: :1:26: error: #endif without #ifdef
+// CHECK-NOT: error:


        


More information about the llvm-commits mailing list