Skip to content

Commit 68bd274

Browse files
committed
Verify entry block in SPIRV dialect
1 parent a415b7f commit 68bd274

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,14 @@ LogicalResult spirv::FuncOp::verifyType() {
10211021

10221022
LogicalResult spirv::FuncOp::verifyBody() {
10231023
FunctionType fnType = getFunctionType();
1024+
if (!isExternal()) {
1025+
Block &entryBlock = front();
1026+
1027+
unsigned numArguments = this->getNumArguments();
1028+
if (entryBlock.getNumArguments() != numArguments)
1029+
return emitOpError("entry block must have ")
1030+
<< numArguments << " arguments to match function signature";
1031+
}
10241032

10251033
auto walkResult = walk([fnType](Operation *op) -> WalkResult {
10261034
if (auto retOp = dyn_cast<spirv::ReturnOp>(op)) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Bug: https://github.com/llvm/llvm-project/issues/132894
2+
3+
// RUN: not mlir-opt %s 2>&1 | FileCheck %s
4+
5+
// CHECK: error: 'spirv.func' op entry block must have 1 arguments to match function signature
6+
module {
7+
spirv.func @f(f32) "None" {
8+
%c0 = arith.constant 0 : index
9+
spirv.Return
10+
}
11+
}
12+

0 commit comments

Comments
 (0)