Skip to content

Commit d6e8466

Browse files
jayfoadakadutta
authored andcommitted
[TableGen] Diagnose negative !listsplat count (llvm#163152)
1 parent 6d55b4d commit d6e8466

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llvm/lib/TableGen/Record.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,9 +1363,12 @@ const Init *BinOpInit::Fold(const Record *CurRec) const {
13631363
}
13641364
case LISTSPLAT: {
13651365
const auto *Value = dyn_cast<TypedInit>(LHS);
1366-
const auto *Size = dyn_cast<IntInit>(RHS);
1367-
if (Value && Size) {
1368-
SmallVector<const Init *, 8> Args(Size->getValue(), Value);
1366+
const auto *Count = dyn_cast<IntInit>(RHS);
1367+
if (Value && Count) {
1368+
if (Count->getValue() < 0)
1369+
PrintFatalError(Twine("!listsplat count ") + Count->getAsString() +
1370+
" is negative");
1371+
SmallVector<const Init *, 8> Args(Count->getValue(), Value);
13691372
return ListInit::get(Args, Value->getType());
13701373
}
13711374
break;

llvm/test/TableGen/listsplat.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: llvm-tblgen %s | FileCheck %s
2+
// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
23

34
// CHECK: ------------- Classes -----------------
45
// CHECK-NEXT: class X<int X:a = ?, int X:b = ?> {
@@ -73,3 +74,8 @@ def DYa1 : Y<"a", 1>;
7374
def DYa2 : Y<"a", 2>;
7475

7576
def DZ : X<42, !size([1, 2, 3])>;
77+
78+
#ifdef ERROR1
79+
// ERROR1: !listsplat count -1 is negative
80+
defvar E = !listsplat("", -1);
81+
#endif

0 commit comments

Comments
 (0)