[llvm] [TableGen] Avoid crashing on a missing instruction pattern result (PR #228075)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 06:30:48 PDT 2026
https://github.com/kiran-isaac updated https://github.com/llvm/llvm-project/pull/228075
>From fd39b24617d6800debc2a3060a3385f21d332722 Mon Sep 17 00:00:00 2001
From: Kiran <kiran.sturt at arm.com>
Date: Wed, 30 Sep 2026 18:26:47 +0100
Subject: [PATCH] [TableGen] Avoid crashing on a missing instruction pattern
result
When an instruction pattern's result name does not match the declared
output operand, TableGen diagnoses the mismatch but continues and
dereferences InstResults.end().
Make this diagnostic fatal, preserving the existing message and pattern
dump while stopping before the invalid access.
Add regression coverage for invalid and valid result names with both
-gen-instr-info and -gen-dag-isel.
Validation: all 457 tests in llvm/test/TableGen pass.
---
.../dag-pattern-invalid-instruction-result.td | 22 +++++++++++++++++++
.../TableGen/Common/CodeGenDAGPatterns.cpp | 8 +++++--
2 files changed, 28 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/TableGen/dag-pattern-invalid-instruction-result.td
diff --git a/llvm/test/TableGen/dag-pattern-invalid-instruction-result.td b/llvm/test/TableGen/dag-pattern-invalid-instruction-result.td
new file mode 100644
index 0000000000000..00c52b9ea367d
--- /dev/null
+++ b/llvm/test/TableGen/dag-pattern-invalid-instruction-result.td
@@ -0,0 +1,22 @@
+// RUN: not llvm-tblgen -gen-instr-info -I %p/../../include %s -o /dev/null 2>&1 | FileCheck %s
+// RUN: llvm-tblgen -gen-instr-info -I %p/../../include %s -DVALID_RESULT -o /dev/null
+// RUN: not llvm-tblgen -gen-dag-isel -I %p/../../include %s -o /dev/null 2>&1 | FileCheck %s
+// RUN: llvm-tblgen -gen-dag-isel -I %p/../../include %s -DVALID_RESULT -o /dev/null
+
+include "llvm/Target/Target.td"
+
+def : Target { let InstructionSet = InstrInfo<>; }
+def GPR : RegisterClass<"Test", [i32], 32, (add Register<"r0">)>;
+defm : RemapAllTargetPseudoPointerOperands<GPR>;
+
+// CHECK: :[[@LINE+1]]:5: error: In Bad: Operand $dst does not exist in operand list!
+def Bad : Instruction {
+ let Namespace = "Test";
+ let OutOperandList = (outs GPR:$dst);
+ let InOperandList = (ins);
+#ifdef VALID_RESULT
+ let Pattern = [(set GPR:$dst, 0)];
+#else
+ let Pattern = [(set GPR:$other, 0)];
+#endif
+}
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index dbfc7f18c08d3..fb98517d48f0e 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -4002,8 +4002,12 @@ void CodeGenDAGPatterns::parseInstructionPattern(const CodeGenInstruction &CGI,
// Check that it exists in InstResults.
auto InstResultIter = InstResults.find(OpName);
- if (InstResultIter == InstResults.end() || !InstResultIter->second)
- I.error("Operand $" + OpName + " does not exist in operand list!");
+ if (InstResultIter == InstResults.end() || !InstResultIter->second) {
+ I.dump();
+ PrintFatalError(CGI.TheDef,
+ "In " + CGI.TheDef->getName() + ": Operand $" + OpName +
+ " does not exist in operand list!");
+ }
TreePatternNodePtr RNode = InstResultIter->second;
const Record *R = cast<DefInit>(RNode->getLeafValue())->getDef();
More information about the llvm-commits
mailing list