[Mlir-commits] [mlir] e5f8cdd - [mlir] Check FunctionOpInterface castable type

Kai Sasaki llvmlistbot at llvm.org
Fri Apr 21 20:53:05 PDT 2023


Author: Kai Sasaki
Date: 2023-04-22T12:40:03+09:00
New Revision: e5f8cdd68527b718ecfcc4724e3358b34e5014e5

URL: https://github.com/llvm/llvm-project/commit/e5f8cdd68527b718ecfcc4724e3358b34e5014e5
DIFF: https://github.com/llvm/llvm-project/commit/e5f8cdd68527b718ecfcc4724e3358b34e5014e5.diff

LOG: [mlir] Check FunctionOpInterface castable type

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index f5e9e71506e38..f812d4d72ca98 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -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());

diff  --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir
index 0649273769e9d..b35cda8e724f6 100644
--- a/mlir/test/Transforms/test-legalize-type-conversion.mlir
+++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir
@@ -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
+}


        


More information about the Mlir-commits mailing list