Skip to content

Commit

Permalink
[mlir][EmitC] Do not convert illegal types in EmitC (#104571)
Browse files Browse the repository at this point in the history
This patch adds check for unsupported types in emitc, which fixes a
crash. Fix #103706.
  • Loading branch information
CoTinker authored Aug 20, 2024
1 parent f1b6427 commit 3c53745
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ func.func @zero_rank() {

// expected-error@+1 {{failed to legalize operation 'memref.global'}}
memref.global "nested" constant @nested_global : memref<3x7xf32>

// -----

func.func @unsupported_type_f16() {
// expected-error@+1 {{failed to legalize operation 'memref.alloca'}}
%0 = memref.alloca() : memref<4xf16>
return
}

// -----

func.func @unsupported_type_i4() {
// expected-error@+1 {{failed to legalize operation 'memref.alloca'}}
%0 = memref.alloca() : memref<4xi4>
return
}

0 comments on commit 3c53745

Please sign in to comment.