[llvm] e79f451 - TableGen: Replace assertion with error for unexpected pattern inputs (#159687)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 18 20:57:54 PDT 2025
Author: Matt Arsenault
Date: 2025-09-19T03:57:50Z
New Revision: e79f4511a22fadff502ad3a42812deca11feb407
URL: https://github.com/llvm/llvm-project/commit/e79f4511a22fadff502ad3a42812deca11feb407
DIFF: https://github.com/llvm/llvm-project/commit/e79f4511a22fadff502ad3a42812deca11feb407.diff
LOG: TableGen: Replace assertion with error for unexpected pattern inputs (#159687)
Added:
llvm/test/TableGen/dag-pattern-crash-on-set.td
Modified:
llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/dag-pattern-crash-on-set.td b/llvm/test/TableGen/dag-pattern-crash-on-set.td
new file mode 100644
index 0000000000000..5b726a7ed958e
--- /dev/null
+++ b/llvm/test/TableGen/dag-pattern-crash-on-set.td
@@ -0,0 +1,25 @@
+// RUN: not llvm-tblgen -gen-dag-isel -I %p/../../include -o /dev/null %s 2>&1 | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def MyTargetInstrInfo : InstrInfo;
+def MyTarget : Target {
+ let InstructionSet = MyTargetInstrInfo;
+}
+
+def R0 : Register<"r0">;
+def GPR : RegisterClass<"MyTarget", [i32], 32, (add R0)>;
+
+def LOAD : Instruction {
+ let Size = 2;
+ let OutOperandList = (outs GPR:$dst);
+ let InOperandList = (ins GPR:$addr);
+ let AsmString = "movimm $dst, $addr";
+}
+
+// CHECK: [[@LINE+1]]:5: error: In CrashPat: unknown node type 'set' in input pattern
+def CrashPat : Pat <
+ (set R0, (load GPR:$addr)),
+ (LOAD $addr)
+>;
+
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index f1f7cd72ef9f2..37844663dfc33 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -2795,7 +2795,11 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
return MadeChange;
}
- assert(getOperator()->isSubClassOf("SDNodeXForm") && "Unknown node type!");
+ if (!getOperator()->isSubClassOf("SDNodeXForm")) {
+ TP.error("unknown node type '" + getOperator()->getName() +
+ "' in input pattern");
+ return false;
+ }
// Node transforms always take one operand.
if (getNumChildren() != 1) {
More information about the llvm-commits
mailing list