[llvm] 68f121e - [TableGen] Diagnose negative !listsplat count (#163152)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 13 07:51:17 PDT 2025


Author: Jay Foad
Date: 2025-10-13T15:51:13+01:00
New Revision: 68f121e9ade61d681b610bd53bc0c8084759a618

URL: https://github.com/llvm/llvm-project/commit/68f121e9ade61d681b610bd53bc0c8084759a618
DIFF: https://github.com/llvm/llvm-project/commit/68f121e9ade61d681b610bd53bc0c8084759a618.diff

LOG: [TableGen] Diagnose negative !listsplat count (#163152)

Added: 
    

Modified: 
    llvm/lib/TableGen/Record.cpp
    llvm/test/TableGen/listsplat.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 2ea3a24bb8eb2..afce803f3f568 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -1363,9 +1363,12 @@ const Init *BinOpInit::Fold(const Record *CurRec) const {
   }
   case LISTSPLAT: {
     const auto *Value = dyn_cast<TypedInit>(LHS);
-    const auto *Size = dyn_cast<IntInit>(RHS);
-    if (Value && Size) {
-      SmallVector<const Init *, 8> Args(Size->getValue(), Value);
+    const auto *Count = dyn_cast<IntInit>(RHS);
+    if (Value && Count) {
+      if (Count->getValue() < 0)
+        PrintFatalError(Twine("!listsplat count ") + Count->getAsString() +
+                        " is negative");
+      SmallVector<const Init *, 8> Args(Count->getValue(), Value);
       return ListInit::get(Args, Value->getType());
     }
     break;

diff  --git a/llvm/test/TableGen/listsplat.td b/llvm/test/TableGen/listsplat.td
index 5a93a4c722c05..43803d6e6fbe3 100644
--- a/llvm/test/TableGen/listsplat.td
+++ b/llvm/test/TableGen/listsplat.td
@@ -1,4 +1,5 @@
 // RUN: llvm-tblgen %s | FileCheck %s
+// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
 
 // CHECK: ------------- Classes -----------------
 // CHECK-NEXT: class X<int X:a = ?, int X:b = ?> {
@@ -73,3 +74,8 @@ def DYa1 : Y<"a", 1>;
 def DYa2 : Y<"a", 2>;
 
 def DZ : X<42, !size([1, 2, 3])>;
+
+#ifdef ERROR1
+// ERROR1: !listsplat count -1 is negative
+defvar E = !listsplat("", -1);
+#endif


        


More information about the llvm-commits mailing list