Skip to content

Commit f563c68

Browse files
committed
Verify dcl_function_body and dcl_function_table
1 parent f385281 commit f563c68

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def DXSA_DclFunctionBody : DXSA_Op<"dcl_function_body"> {
730730
dxsa.dcl_function_body 0
731731
```
732732
}];
733-
let arguments = (ins I32Attr:$index);
733+
let arguments = (ins ConfinedAttr<I32Attr, [IntNonNegative]>:$index);
734734
let assemblyFormat = "$index attr-dict";
735735
}
736736

@@ -750,8 +750,10 @@ def DXSA_DclFunctionTable : DXSA_Op<"dcl_function_table"> {
750750
dxsa.dcl_function_table 0, <functions = [0, 1]>
751751
```
752752
}];
753-
let arguments = (ins I32Attr:$index, DenseI32ArrayAttr:$functions);
753+
let arguments = (ins ConfinedAttr<I32Attr, [IntNonNegative]>:$index,
754+
DenseI32ArrayAttr:$functions);
754755
let assemblyFormat = "$index `,` `<` `functions` `=` $functions `>` attr-dict";
756+
let hasVerifier = 1;
755757
}
756758

757759
#endif // DXSA_OPS

mlir/lib/Dialect/DXSA/IR/DXSA.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ void DXSADialect::initialize() {
4141
#define GET_OP_CLASSES
4242
#include "mlir/Dialect/DXSA/IR/DXSAOps.cpp.inc"
4343

44+
LogicalResult DclFunctionTable::verify() {
45+
for (int32_t functionIndex : getFunctions()) {
46+
if (functionIndex < 0) {
47+
return emitOpError("function body index must not be negative, got ")
48+
<< functionIndex;
49+
}
50+
}
51+
return success();
52+
}
53+
4454
//===----------------------------------------------------------------------===//
4555
// TableGen'd attribute method definitions
4656
//===----------------------------------------------------------------------===//
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_function_body' op attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
4+
dxsa.dcl_function_body -1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_function_table' op attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
4+
dxsa.dcl_function_table -1, <functions = [0, 1]>
5+
6+
// -----
7+
8+
// expected-error@+1 {{'dxsa.dcl_function_table' op function body index must not be negative, got -1}}
9+
dxsa.dcl_function_table 1, <functions = [0, -1]>

0 commit comments

Comments
 (0)