[Mlir-commits] [mlir] 5f34259 - [mlir] FuncToLLVM: fail gracefully in bare pointer multi-result covnersion

Alex Zinenko llvmlistbot at llvm.org
Mon Mar 27 07:54:23 PDT 2023


Author: Alex Zinenko
Date: 2023-03-27T14:53:11Z
New Revision: 5f34259609f604bfcd5cbf324a32d265e6a5d347

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

LOG: [mlir] FuncToLLVM: fail gracefully in bare pointer multi-result covnersion

When type conversion fails, return pattern failure instead of crashing.

Closes #61717.

Added: 
    

Modified: 
    mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
    mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index bbfb6281163b..7200b2b3ea9a 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -675,6 +675,9 @@ struct ReturnOpLowering : public ConvertOpToLLVMPattern<func::ReturnOp> {
     // returning.
     auto packedType =
         getTypeConverter()->packFunctionResults(op.getOperandTypes());
+    if (!packedType) {
+      return rewriter.notifyMatchFailure(op, "could not convert result types");
+    }
 
     Value packed = rewriter.create<LLVM::UndefOp>(loc, packedType);
     for (auto [idx, operand] : llvm::enumerate(updatedOperands)) {

diff  --git a/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir b/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
index e8f73a37ac04..8663ce8cbbf2 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
@@ -95,3 +95,11 @@ func.func @check_return(%in : memref<?xi8>) -> memref<?xi8> {
   // BAREPTR: llvm.return {{.*}} : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
   return %in : memref<?xi8>
 }
+
+// -----
+
+// BAREPTR-LABEL: func @unconvertible_multiresult
+// BAREPTR-SAME: %{{.*}}: memref<?xf32>, %{{.*}}: memref<?xf32>) -> (memref<?xf32>, memref<?xf32>)
+func.func @unconvertible_multiresult(%arg0: memref<?xf32> , %arg1: memref<?xf32>) -> (memref<?xf32>, memref<?xf32>) {
+  return %arg0, %arg1 : memref<?xf32>, memref<?xf32>
+}


        


More information about the Mlir-commits mailing list