Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,24 @@ LogicalResult spirv::FuncOp::verifyType() {

LogicalResult spirv::FuncOp::verifyBody() {
FunctionType fnType = getFunctionType();
if (!isExternal()) {
Block &entryBlock = front();

unsigned numArguments = this->getNumArguments();
if (entryBlock.getNumArguments() != numArguments)
return emitOpError("entry block must have ")
<< numArguments << " arguments to match function signature";

for (auto [index, fnArgType, blockArgType] :
llvm::enumerate(getArgumentTypes(), entryBlock.getArgumentTypes())) {
if (blockArgType != fnArgType) {
return emitOpError("type of entry block argument #")
<< index << '(' << blockArgType
<< ") must match the type of the corresponding argument in "
<< "function signature(" << fnArgType << ')';
}
}
}

auto walkResult = walk([fnType](Operation *op) -> WalkResult {
if (auto retOp = dyn_cast<spirv::ReturnOp>(op)) {
Expand Down
17 changes: 17 additions & 0 deletions mlir/test/Dialect/SPIRV/IR/function-decorations.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,20 @@ spirv.func @no_decoration_name_attr(%arg0 : !spirv.ptr<i32, PhysicalStorageBuffe
spirv.func @no_decoration_name_attr(%arg0 : !spirv.ptr<i32, PhysicalStorageBuffer> { spirv.decoration = #spirv.decoration<Restrict>, random_attr = #spirv.decoration<Aliased> }) "None" {
spirv.Return
}

// -----

// expected-error @+1 {{'spirv.func' op entry block must have 1 arguments to match function signature}}
spirv.func @f(f32) "None" {
%c0 = arith.constant 0 : index
spirv.Return
}

// -----

// expected-error @+1 {{'spirv.func' op type of entry block argument #0('f64') must match the type of the corresponding argument in function signature('f32')}}
spirv.func @f(f32) "None" {
^bb0(%arg0: f64):
%c0 = arith.constant 0 : index
spirv.Return
}
Loading