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
This commit is contained in:
Stella Laurenzo 2021-10-06 13:54:13 -07:00
parent ae4c0c7cfc
commit 56272257f3
2 changed files with 16 additions and 0 deletions

View 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));

View 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
}