diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 0e4589a209181..fc9d449ecc143 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1504,7 +1504,8 @@ ParseResult OperationParser::parseRegion( pushSSANameScope(isIsolatedNameScope); // Parse the first block directly to allow for it to be unnamed. - Block *block = new Block(); + auto owning_block = std::make_unique(); + Block *block = owning_block.get(); // Add arguments to the entry block. if (!entryArguments.empty()) { @@ -1519,7 +1520,6 @@ ParseResult OperationParser::parseRegion( } if (addDefinition(placeholderArgPair.first, block->addArgument(placeholderArgPair.second))) { - delete block; return failure(); } } @@ -1530,19 +1530,17 @@ ParseResult OperationParser::parseRegion( } if (parseBlock(block)) { - delete block; return failure(); } // Verify that no other arguments were parsed. if (!entryArguments.empty() && block->getNumArguments() > entryArguments.size()) { - delete block; return emitError("entry block arguments were already defined"); } // Parse the rest of the region. - region.push_back(block); + region.push_back(owning_block.release()); if (parseRegionBody(region)) return failure();