[Mlir-commits] [mlir] 5627225 - Return failure on failure in convertBlockSignature.

Stella Laurenzo llvmlistbot at llvm.org
Wed Oct 6 15:35:54 PDT 2021


Author: Stella Laurenzo
Date: 2021-10-06T15:35:31-07:00
New Revision: 56272257f3f3696a718abeb73bee4c2cc0a14b01

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

LOG: Return failure on failure in convertBlockSignature.

This was causing a subsequent assert/crash when a type converter failed to convert a block argument.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D110985

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 a748eb9164f3..3ee743b2c475 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -1147,6 +1147,8 @@ FailureOr<Block *> ConversionPatternRewriterImpl::convertBlockSignature(
                        block, converter, *conversion, mapping, argReplacements)
                  : argConverter.convertSignature(block, converter, mapping,
                                                  argReplacements);
+  if (failed(result))
+    return failure();
   if (Block *newBlock = result.getValue()) {
     if (newBlock != block)
       blockActions.push_back(BlockAction::getTypeConversion(newBlock));

diff  --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir
index e7ffb7ae6a3e..59c62d188d45 100644
--- a/mlir/test/Transforms/test-legalize-type-conversion.mlir
+++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir
@@ -99,3 +99,17 @@ func @test_signature_conversion_undo() {
   }) : () -> ()
   return
 }
+
+// -----
+
+// Should not segfault here but gracefully fail.
+// CHECK-LABEL: func @test_block_argument_not_converted
+func @test_block_argument_not_converted() {
+  "test.unsupported_block_arg_type"() ({
+    // NOTE: The test pass does not convert `index` types.
+    // CHECK: ^bb0({{.*}}: index):
+    ^bb0(%0 : index):
+      "test.return"(%0) : (index) -> ()
+  }) : () -> ()
+  return
+}


        


More information about the Mlir-commits mailing list