[llvm] [TableGen] Improve the error report of getElementAsRecord (PR #189302)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 02:15:33 PDT 2026


https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/189302

>From 22a5aec2756db5ce2524ed22b91a35c358ed3d5b Mon Sep 17 00:00:00 2001
From: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: Mon, 30 Mar 2026 17:02:22 +0800
Subject: [PATCH 1/2] [TableGen] Add precommit tests

---
 llvm/test/TableGen/intrinsic-arginfo-error.td | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 llvm/test/TableGen/intrinsic-arginfo-error.td

diff --git a/llvm/test/TableGen/intrinsic-arginfo-error.td b/llvm/test/TableGen/intrinsic-arginfo-error.td
new file mode 100644
index 0000000000000..e06ce224cbf1b
--- /dev/null
+++ b/llvm/test/TableGen/intrinsic-arginfo-error.td
@@ -0,0 +1,10 @@
+// RUN: not llvm-tblgen -gen-intrinsic-enums -I %p/../../include %s 2>&1 | FileCheck %s
+
+include "llvm/IR/Intrinsics.td"
+
+// CHECK: error: Expected record in list!
+def int_test : DefaultAttrsIntrinsic<
+    [llvm_anyint_ty],
+    [llvm_anyint_ty,
+     LLVMMatchType<2>],
+    [IntrNoMem]>;

>From b2c4f43db4eab562255a89cb4a52eb1303d43795 Mon Sep 17 00:00:00 2001
From: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: Mon, 30 Mar 2026 11:43:07 +0800
Subject: [PATCH 2/2] [TableGen] Improve the error report of getElementAsRecord

---
 llvm/lib/TableGen/Record.cpp                  | 3 ++-
 llvm/test/TableGen/intrinsic-arginfo-error.td | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 8ad20b45f5e16..4e931209e3e7c 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -768,7 +768,8 @@ const Init *ListInit::convertInitializerTo(const RecTy *Ty) const {
 const Record *ListInit::getElementAsRecord(unsigned Idx) const {
   const auto *DI = dyn_cast<DefInit>(getElement(Idx));
   if (!DI)
-    PrintFatalError("Expected record in list!");
+    PrintFatalError("expected record type for the element with index " +
+                    Twine(Idx) + " in list " + getAsString());
   return DI->getDef();
 }
 
diff --git a/llvm/test/TableGen/intrinsic-arginfo-error.td b/llvm/test/TableGen/intrinsic-arginfo-error.td
index e06ce224cbf1b..a9d30b6bec05f 100644
--- a/llvm/test/TableGen/intrinsic-arginfo-error.td
+++ b/llvm/test/TableGen/intrinsic-arginfo-error.td
@@ -2,7 +2,7 @@
 
 include "llvm/IR/Intrinsics.td"
 
-// CHECK: error: Expected record in list!
+// CHECK: error: expected record type for the element with index 2 in list {{.*}}
 def int_test : DefaultAttrsIntrinsic<
     [llvm_anyint_ty],
     [llvm_anyint_ty,



More information about the llvm-commits mailing list