Skip to content

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Sep 19, 2025

No description provided.

@arsenm arsenm added the tablegen label Sep 19, 2025 — with Graphite App
Copy link
Contributor Author

arsenm commented Sep 19, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm marked this pull request as ready for review September 19, 2025 01:53
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2025

@llvm/pr-subscribers-tablegen

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/159687.diff

2 Files Affected:

  • (added) llvm/test/TableGen/dag-pattern-crash-on-set.td (+25)
  • (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+4-1)
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..dd273228033ff
--- /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..22bcf733501a4 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -2795,7 +2795,10 @@ 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) {

Copy link

github-actions bot commented Sep 19, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@arsenm arsenm force-pushed the users/arsenm/tablegen/replace-assert-error-unexpected-pattern-class branch from 9e2cca9 to aea320c Compare September 19, 2025 02:01
Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of supporting this syntax on top-level patterns, but trying to implement it revealed several issues that are not trivial to fix.

arsenm and others added 2 commits September 19, 2025 12:22
Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
@arsenm arsenm enabled auto-merge (squash) September 19, 2025 03:46
@arsenm arsenm merged commit e79f451 into main Sep 19, 2025
9 checks passed
@arsenm arsenm deleted the users/arsenm/tablegen/replace-assert-error-unexpected-pattern-class branch September 19, 2025 03:57
YixingZhang007 pushed a commit to YixingZhang007/llvm-project that referenced this pull request Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants