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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Aug 16 02:31:31 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Longsheng Mou (CoTinker)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/104571.diff


2 Files Affected:

- (modified) mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp (+2-1) 
- (modified) mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir (+16) 


``````````diff
diff --git a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
index e0c421741b3055..e968675a648c22 100644
--- a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
+++ b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
@@ -177,7 +177,8 @@ void mlir::populateMemRefToEmitCTypeConversion(TypeConverter &typeConverter) {
         }
         Type convertedElementType =
             typeConverter.convertType(memRefType.getElementType());
-        if (!convertedElementType)
+        if (!convertedElementType ||
+            !emitc::isSupportedEmitCType(convertedElementType))
           return {};
         return emitc::ArrayType::get(memRefType.getShape(),
                                      convertedElementType);
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/104571


More information about the Mlir-commits mailing list