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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 27 23:02:03 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: Kevin Bravo (kbrav)

<details>
<summary>Changes</summary>

`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. 

---
Full diff: https://github.com/llvm/llvm-project/pull/212411.diff


2 Files Affected:

- (modified) llvm/lib/TableGen/TGLexer.cpp (+1-1) 
- (added) llvm/test/TableGen/cr-after-endif.td (+9) 


``````````diff
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/cr-after-endif.td b/llvm/test/TableGen/cr-after-endif.td
new file mode 100644
index 0000000000000..3b991ced1e673
--- /dev/null
+++ b/llvm/test/TableGen/cr-after-endif.td
@@ -0,0 +1,9 @@
+// LineEnd ::=  newline | return | EOF
+// Preprocessor must treat the \r after `hello` as a line end so that it
+// doesn't skip the first #endif thinking that it's part of the #ifdef body.
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
+// CHECK: :[[@LINE+4]]:2: error: #endif without #ifdef
+// CHECK: :[[@LINE+3]]:2: error: Unexpected token at top level
+#ifdef FOO
+hello
#endif
+#endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/212411


More information about the llvm-commits mailing list