[Mlir-commits] [mlir] [MLIR][IR] Add assert to Operation::moveBefore (NFC) (PR #137772)
Christian Ulmann
llvmlistbot at llvm.org
Tue Apr 29 01:59:53 PDT 2025
https://github.com/Dinistro created https://github.com/llvm/llvm-project/pull/137772
This commit adds an assert to `Operation::moveBefore` which ensures that moving of operations without a parent block is detected early on. This case otherwise runs into a segfault, as it's assumed that there is an parent block.
>From cd357382566cdde0e8fe82950d68098e86be2c86 Mon Sep 17 00:00:00 2001
From: Christian Ulmann <christian.ulmann at nextsilicon.com>
Date: Tue, 29 Apr 2025 08:57:16 +0000
Subject: [PATCH] [MLIR][IR] Add assert to Operation::moveBefore (NFC)
This commit adds an assert to `Operation::moveBefore` which ensures that
moving of operations without a parent block is detected early on.
This case otherwise runs into a segfault, as it's assumed that there is
an parent block.
---
mlir/lib/IR/Operation.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index fe0fee0f8db2c..a479ff97f3f16 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -322,8 +322,8 @@ void Operation::setAttrs(DictionaryAttr newAttrs) {
}
void Operation::setAttrs(ArrayRef<NamedAttribute> newAttrs) {
if (getPropertiesStorageSize()) {
- // We're spliting the providing array of attributes by removing the inherentAttr
- // which will be stored in the properties.
+ // We're spliting the providing array of attributes by removing the
+ // inherentAttr which will be stored in the properties.
SmallVector<NamedAttribute> discardableAttrs;
discardableAttrs.reserve(newAttrs.size());
for (NamedAttribute attr : newAttrs) {
@@ -560,6 +560,8 @@ void Operation::moveBefore(Operation *existingOp) {
/// before `iterator` in the specified basic block.
void Operation::moveBefore(Block *block,
llvm::iplist<Operation>::iterator iterator) {
+ assert(getBlock() &&
+ "cannot move an operation that isn't contained in a block");
block->getOperations().splice(iterator, getBlock()->getOperations(),
getIterator());
}
More information about the Mlir-commits
mailing list