[Mlir-commits] [mlir] 3c53745 - [mlir][EmitC] Do not convert illegal types in EmitC (#104571)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Aug 20 02:50:01 PDT 2024


Author: Longsheng Mou
Date: 2024-08-20T17:49:58+08:00
New Revision: 3c5374595bf20bd9665dce5b832d7cc1f09b8415

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

LOG: [mlir][EmitC] Do not convert illegal types in EmitC (#104571)

This patch adds check for unsupported types in emitc, which fixes a
crash. Fix #103706.

Added: 
    

Modified: 
    mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
    mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
index 4e5d1912d15729..11bfde890bce87 100644
--- a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
+++ b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
@@ -33,9 +33,9 @@ struct ConvertMemRefToEmitCPass
 
     // Fallback for other types.
     converter.addConversion([](Type type) -> std::optional<Type> {
-      if (isa<MemRefType>(type))
-        return {};
-      return type;
+      if (emitc::isSupportedEmitCType(type))
+        return type;
+      return {};
     });
 
     populateMemRefToEmitCTypeConversion(converter);

diff  --git a/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir b/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
index 89dafa7529ed53..836d8aedefc1f0 100644
--- a/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
+++ b/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
@@ -43,3 +43,19 @@ func.func @zero_rank() {
 
 // expected-error at +1 {{failed to legalize operation 'memref.global'}}
 memref.global "nested" constant @nested_global : memref<3x7xf32>
+
+// -----
+
+func.func @unsupported_type_f16() {
+  // expected-error at +1 {{failed to legalize operation 'memref.alloca'}}
+  %0 = memref.alloca() : memref<4xf16>
+  return
+}
+
+// -----
+
+func.func @unsupported_type_i4() {
+  // expected-error at +1 {{failed to legalize operation 'memref.alloca'}}
+  %0 = memref.alloca() : memref<4xi4>
+  return
+}


        


More information about the Mlir-commits mailing list