diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -3065,7 +3065,9 @@ static LogicalResult convertFuncOpTypes(FunctionOpInterface funcOp, TypeConverter &typeConverter, ConversionPatternRewriter &rewriter) { - FunctionType type = funcOp.getFunctionType().cast(); + FunctionType type = dyn_cast(funcOp.getFunctionType()); + if (!type) + return failure(); // Convert the original function types. TypeConverter::SignatureConversion result(type.getNumInputs()); diff --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir --- a/mlir/test/Transforms/test-legalize-type-conversion.mlir +++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir @@ -121,3 +121,11 @@ "test.type_producer"() : () -> !test.test_rec> return } + +// ----- + +// CHECK-LABEL: @unsupported_func_op_interface +llvm.func @unsupported_func_op_interface() { + // CHECK: llvm.return + llvm.return +}