[llvm] [TableGen] Use PrintFatalError in ParseTreePattern for proper error handling of llvm-tblgen (PR #161417)

Prerona Chaudhuri via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 11:39:40 PDT 2025


https://github.com/pchaudhuri-nv created https://github.com/llvm/llvm-project/pull/161417

Fixes issue #157619 : TableGen asserts on invalid cast

>From 3bfaa52b79add045d770eb8cba48b808a15ba464 Mon Sep 17 00:00:00 2001
From: pchaudhuri-nv <prerona.chaudhuri16 at vit.edu>
Date: Tue, 30 Sep 2025 18:30:56 +0000
Subject: [PATCH] fic

---
 llvm/test/TableGen/invalid-type-cast-patfrags.td  | 8 ++++----
 llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/test/TableGen/invalid-type-cast-patfrags.td b/llvm/test/TableGen/invalid-type-cast-patfrags.td
index 49d8a73b81078..fe63a71a17352 100644
--- a/llvm/test/TableGen/invalid-type-cast-patfrags.td
+++ b/llvm/test/TableGen/invalid-type-cast-patfrags.td
@@ -19,21 +19,21 @@ def INSTR_BAR : Instruction {
 }
 
 #ifdef ERROR1
-// ERROR1: [[@LINE+1]]:1: error: {{.*}} Invalid number of type casts!
+// ERROR1: error: Invalid number of type casts!
 def : Pat<([i32, i32, i32] (int_foo (i32 GPR32:$a))), ([i32, i32, i32] (INSTR_FOO $a))>;
 #endif
 
 #ifdef ERROR2
-// ERROR2: [[@LINE+1]]:1: error: {{.*}} Invalid number of type casts!
+// ERROR2: error: Invalid number of type casts!
 def : Pat<([]<ValueType> (int_bar)), ([]<ValueType> (INSTR_BAR))>;
 #endif
 
 #ifdef ERROR3
-// ERROR3: [[@LINE+1]]:1: error: {{.*}} Type cast only takes one operand!
+// ERROR3: error: Type cast only takes one operand!
 def : Pat<([i32, i32] (int_foo), (int_foo)), ([i32, i32] (INSTR_FOO))>;
 #endif
 
 #ifdef ERROR4
-// ERROR4: [[@LINE+1]]:1: error: {{.*}} Type cast should not have a name!
+// ERROR4: error: Type cast should not have a name!
 def : Pat<([i32, i32] ([i32, i32] (int_foo)):$name), ([i32, i32] (INSTR_FOO))>;
 #endif
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 75bea77faba42..02b4cb78948e3 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -3014,10 +3014,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
 
   auto ParseCastOperand = [this](const DagInit *Dag, StringRef OpName) {
     if (Dag->getNumArgs() != 1)
-      error("Type cast only takes one operand!");
+      PrintFatalError("Type cast only takes one operand!");
 
     if (!OpName.empty())
-      error("Type cast should not have a name!");
+      PrintFatalError("Type cast should not have a name!");
 
     return ParseTreePattern(Dag->getArg(0), Dag->getArgNameStr(0));
   };
@@ -3029,7 +3029,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
 
     size_t NumTypes = New->getNumTypes();
     if (LI->empty() || LI->size() != NumTypes)
-      error("Invalid number of type casts!");
+      PrintFatalError("Invalid number of type casts!");
 
     // Apply the type casts.
     const CodeGenHwModes &CGH = getDAGPatterns().getTargetInfo().getHwModes();



More information about the llvm-commits mailing list