[llvm] 437b42f - [TableGen] don't print redundant diagnostic when parser sees Error token at end of file. (#212410)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 02:01:58 PDT 2026
Author: Kevin Bravo
Date: 2026-07-28T10:01:53+01:00
New Revision: 437b42f23250660f9a3f262ca6626324cd32a094
URL: https://github.com/llvm/llvm-project/commit/437b42f23250660f9a3f262ca6626324cd32a094
DIFF: https://github.com/llvm/llvm-project/commit/437b42f23250660f9a3f262ca6626324cd32a094.diff
LOG: [TableGen] don't print redundant diagnostic when parser sees Error token at end of file. (#212410)
Fixes #151476.
Currently TableGen parser emits `error: Unexpected token at top level`
when it sees `tgtok::Error` token after failing to parse the object
list, even though that token's corresponding diagnostics were already
emitted during lexing. This change makes `ParseFile` return true when it
sees `tgtok::Error` at end of file, thereby avoiding the redundant
diagnostic.
Added:
Modified:
llvm/lib/TableGen/TGParser.cpp
llvm/test/TableGen/eof-after-endif.td
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 6dbf9c90019f7..94bdc4e6c6df4 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -4778,6 +4778,9 @@ bool TGParser::ParseFile() {
if (Lex.getCode() == tgtok::Eof)
return false;
+ if (Lex.getCode() == tgtok::Error)
+ return true;
+
return TokError("Unexpected token at top level");
}
diff --git a/llvm/test/TableGen/eof-after-endif.td b/llvm/test/TableGen/eof-after-endif.td
index 558a7422a5269..334ffb786af8e 100644
--- a/llvm/test/TableGen/eof-after-endif.td
+++ b/llvm/test/TableGen/eof-after-endif.td
@@ -5,6 +5,6 @@
// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
// CHECK: :[[@LINE+4]]:7: error: reached EOF without matching #endif
// CHECK: :[[@LINE+2]]:8: error: the latest preprocessor control is here
-// CHECK: :[[@LINE+2]]:7: error: Unexpected token at top level
+// CHECK-NOT: error:
#ifdef FOO
#endif
\ No newline at end of file
More information about the llvm-commits
mailing list