[Mlir-commits] [mlir] [mlir][Parser] Fix crash after block parsing failure (PR #128011)
Matthias Springer
llvmlistbot at llvm.org
Thu Feb 20 06:48:13 PST 2025
https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/128011
Fix a crash when parsing malformed block that defines values that preceding operations refer to (which would be a dominance error).
Previously: Producer multiple error messages and then crashes as follows:
```
LLVM ERROR: operation destroyed but still has uses
```
Now: Report an error that the block is malformed. No crash.
>From 8ed81b74b6f4954666fc193f3bdcaafec3de7301 Mon Sep 17 00:00:00 2001
From: Matthias Springer <mspringer at nvidia.com>
Date: Thu, 20 Feb 2025 15:43:36 +0100
Subject: [PATCH] [mlir][Parser] Fix crash after block parsing failure
---
mlir/lib/AsmParser/Parser.cpp | 4 ++++
mlir/test/IR/invalid.mlir | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index b5f1d2e27c9ba..8c18f3a751394 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -2228,6 +2228,10 @@ ParseResult OperationParser::parseRegionBody(Region ®ion, SMLoc startLoc,
// Parse the first block directly to allow for it to be unnamed.
auto owningBlock = std::make_unique<Block>();
+ auto cleanup = llvm::make_scope_exit([&] {
+ if (owningBlock)
+ owningBlock->dropAllDefinedValueUses();
+ });
Block *block = owningBlock.get();
// If this block is not defined in the source file, add a definition for it
diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index 861f4ef6c020d..d5b23fcf27950 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -675,3 +675,17 @@ func.func @error_at_end_of_line() {
// -----
@foo // expected-error {{expected operation name in quotes}}
+
+// -----
+
+func.func @drop_references_on_block_parse_error(){
+ "test.user"(%i, %1) : (index, index) -> ()
+ "test.op_with_region"() ({
+ ^bb0(%i : index):
+ // expected-error @below{{expected operation name in quotes}}
+ %1 = "test.foo"() : () -> (index)
+ // Syntax error to abort parsing this block.
+ 123
+ }) : () -> ()
+ return
+}
More information about the Mlir-commits
mailing list