-
Notifications
You must be signed in to change notification settings - Fork 15.2k
TableGen: Replace assertion with error for unexpected pattern inputs #159687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TableGen: Replace assertion with error for unexpected pattern inputs #159687
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-tablegen Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/159687.diff 2 Files Affected:
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) {
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
9e2cca9
to
aea320c
Compare
There was a problem hiding this 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.
Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
No description provided.