[llvm] [TableGen] Check for EOF in prepSkipRegion to avoid preprocessor crash. (PR #208961)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 11 15:48:13 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: Kevin Bravo (kbrav)

<details>
<summary>Changes</summary>

Part of #<!-- -->151476 

preSkipRegion currently scans a line until it finds a newline before advancing to the next line.  It crashes if it finds an EOF first.  This change checks for EOF to prevent a segmentation fault.

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


2 Files Affected:

- (modified) llvm/lib/TableGen/TGLexer.cpp (+2-1) 
- (added) llvm/test/TableGen/eof-after-endif.td (+5) 


``````````diff
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index ac46054a74d9e..b63e807572040 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -913,8 +913,9 @@ bool TGLexer::prepSkipRegion(bool MustNeverBeFalse) {
 
   do {
     // Skip all symbols to the line end.
-    while (*CurPtr != '\n')
+    while (CurPtr != CurBuf.end() && *CurPtr != '\n') {
       ++CurPtr;
+    }
 
     // Find the first non-whitespace symbol in the next line(s).
     if (!prepSkipLineBegin())
diff --git a/llvm/test/TableGen/eof-after-endif.td b/llvm/test/TableGen/eof-after-endif.td
new file mode 100644
index 0000000000000..a77ab9b18382f
--- /dev/null
+++ b/llvm/test/TableGen/eof-after-endif.td
@@ -0,0 +1,5 @@
+// Do not modify this file from a text editor.
+// It has no whitespace, newline, or carriage return after #endif.
+// RUN: not llvm-tblgen %s
+#ifdef FOO 
+#endif
\ No newline at end of file

``````````

</details>


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


More information about the llvm-commits mailing list