[mlir][func] Guard for unranked memref with the bare ptr memref call

Lowering the call op with use-bare-ptr-memref-call crashes due to the unsupported unranked memref type. We can prevent the crash by checking the type of operand in the pass instead of the assertion in the type converter.

Issue: https://github.com/llvm/llvm-project/issues/61872

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D148078
This commit is contained in:
Kai Sasaki
2023-04-13 10:41:56 +09:00
parent e76cfaca70
commit 7a0dd35493
2 changed files with 21 additions and 0 deletions

View File

@@ -542,6 +542,16 @@ struct CallOpInterfaceLowering : public ConvertOpToLLVMPattern<CallOpType> {
return failure();
}
if (useBarePtrCallConv) {
for (auto it : callOp->getOperands()) {
Type operandType = it.getType();
if (operandType.isa<UnrankedMemRefType>()) {
// Unranked memref is not supported in the bare pointer calling
// convention.
return failure();
}
}
}
auto promoted = this->getTypeConverter()->promoteOperands(
callOp.getLoc(), /*opOperands=*/callOp->getOperands(),
adaptor.getOperands(), rewriter, useBarePtrCallConv);

View File

@@ -103,3 +103,14 @@ func.func @check_return(%in : memref<?xi8>) -> memref<?xi8> {
func.func @unconvertible_multiresult(%arg0: memref<?xf32> , %arg1: memref<?xf32>) -> (memref<?xf32>, memref<?xf32>) {
return %arg0, %arg1 : memref<?xf32>, memref<?xf32>
}
// -----
// BAREPTR-LABEL: func @unranked_memref(
// BAREPTR-SAME: %{{.*}}: memref<*xi32>)
func.func @unranked_memref(%arg0:memref<*xi32>) {
// BAREPTR: call @printMemrefI32(%arg{{.*}}) : (memref<*xi32>) -> ()
// BAREPTR-NEXT: llvm.return
call @printMemrefI32(%arg0) : (memref<*xi32>) -> ()
return
}
func.func private @printMemrefI32(memref<*xi32>)