Return failure on failure in convertBlockSignature.
authorStella Laurenzo <stellaraccident@gmail.com>
Wed, 6 Oct 2021 20:54:13 +0000 (13:54 -0700)
committerStella Laurenzo <stellaraccident@gmail.com>
Wed, 6 Oct 2021 22:35:31 +0000 (15:35 -0700)
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

mlir/lib/Transforms/Utils/DialectConversion.cpp
mlir/test/Transforms/test-legalize-type-conversion.mlir

index a748eb9..3ee743b 100644 (file)
@@ -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));
index e7ffb7a..59c62d1 100644 (file)
@@ -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
+}