[llvm] [FixBUG][llvm-tblgen] : The correct td file ending with #endif cannot be compiled (PR #69411)

zhao jiangtao via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 00:45:52 PDT 2023


https://github.com/whousemyname updated https://github.com/llvm/llvm-project/pull/69411

>From 3cd14950047a4ffda1b6085a538382f728e114c9 Mon Sep 17 00:00:00 2001
From: angryZ <lazytortoisezzzz at gmail.com>
Date: Wed, 18 Oct 2023 10:39:56 +0800
Subject: [PATCH] [llvm][Tablegen][BUG] : The correct td file ending with
 #endif (there are no other characters after #endif, including newlines) still
 cannot be compiled. This PR is to solve this bug.

---
 llvm/lib/TableGen/TGLexer.cpp           | 2 +-
 llvm/test/TableGen/prep-endif-diag-1.td | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/TableGen/prep-endif-diag-1.td

diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index d5140e91fce9e94..3bedbcd6307fd15 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -664,7 +664,7 @@ tgtok::TokKind TGLexer::prepIsDirective() const {
           // It looks like TableGen does not support '\r' as the actual
           // carriage return, e.g. getNextChar() treats a single '\r'
           // as '\n'.  So we do the same here.
-          NextChar == '\r')
+          NextChar == '\r' || NextChar == '\0')
         return Kind;
 
       // Allow comments after some directives, e.g.:
diff --git a/llvm/test/TableGen/prep-endif-diag-1.td b/llvm/test/TableGen/prep-endif-diag-1.td
new file mode 100644
index 000000000000000..8ac37bc3f93c4fb
--- /dev/null
+++ b/llvm/test/TableGen/prep-endif-diag-1.td
@@ -0,0 +1,7 @@
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
+
+// CHECK: error: Reached EOF without matching #endif
+// CHECK: error: The latest preprocessor control is here
+// CHECK: error: Unexpected token at top level
+#ifdef adasd
+#endif
\ No newline at end of file



More information about the llvm-commits mailing list