[mlir] Check FunctionOpInterface castable type
authorKai Sasaki <lewuathe@gmail.com>
Sat, 22 Apr 2023 03:39:50 +0000 (12:39 +0900)
committerKai Sasaki <lewuathe@gmail.com>
Sat, 22 Apr 2023 03:40:03 +0000 (12:40 +0900)
As convertFuncOpTypes does not support other FuncOpInterface types, we should check the type to avoid assertion failure. The original issue was reported https://github.com/llvm/llvm-project/issues/61858.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D148873

mlir/lib/Transforms/Utils/DialectConversion.cpp
mlir/test/Transforms/test-legalize-type-conversion.mlir

index f5e9e71..f812d4d 100644 (file)
@@ -3065,7 +3065,9 @@ std::optional<Attribute> TypeConverter::convertTypeAttribute(Type type,
 static LogicalResult convertFuncOpTypes(FunctionOpInterface funcOp,
                                         TypeConverter &typeConverter,
                                         ConversionPatternRewriter &rewriter) {
-  FunctionType type = funcOp.getFunctionType().cast<FunctionType>();
+  FunctionType type = dyn_cast<FunctionType>(funcOp.getFunctionType());
+  if (!type)
+    return failure();
 
   // Convert the original function types.
   TypeConverter::SignatureConversion result(type.getNumInputs());
index 0649273..b35cda8 100644 (file)
@@ -121,3 +121,11 @@ func.func @recursive_type_conversion() {
   "test.type_producer"() : () -> !test.test_rec<something, test_rec<something>>
   return
 }
+
+// -----
+
+// CHECK-LABEL: @unsupported_func_op_interface
+llvm.func @unsupported_func_op_interface() {
+  // CHECK: llvm.return
+  llvm.return
+}