[llvm] [TableGen] Use PrintFatalError in ParseTreePattern for proper error handling of llvm-tblgen (PR #161417)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 11:40:32 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Prerona Chaudhuri (pchaudhuri-nv)
<details>
<summary>Changes</summary>
Fixes issue #<!-- -->157619 : TableGen asserts on invalid cast
---
Full diff: https://github.com/llvm/llvm-project/pull/161417.diff
2 Files Affected:
- (modified) llvm/test/TableGen/invalid-type-cast-patfrags.td (+4-4)
- (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+3-3)
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/161417
More information about the llvm-commits
mailing list