Skip to content

Commit 72783e4

Browse files
DinistroGeorgeARM
authored andcommitted
[MLIR][IR] Add assert to Operation::moveBefore (NFC) (llvm#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.
1 parent 618b7fb commit 72783e4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mlir/lib/IR/Operation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ void Operation::setAttrs(DictionaryAttr newAttrs) {
322322
}
323323
void Operation::setAttrs(ArrayRef<NamedAttribute> newAttrs) {
324324
if (getPropertiesStorageSize()) {
325-
// We're spliting the providing array of attributes by removing the inherentAttr
326-
// which will be stored in the properties.
325+
// We're spliting the providing array of attributes by removing the
326+
// inherentAttr which will be stored in the properties.
327327
SmallVector<NamedAttribute> discardableAttrs;
328328
discardableAttrs.reserve(newAttrs.size());
329329
for (NamedAttribute attr : newAttrs) {
@@ -560,6 +560,8 @@ void Operation::moveBefore(Operation *existingOp) {
560560
/// before `iterator` in the specified basic block.
561561
void Operation::moveBefore(Block *block,
562562
llvm::iplist<Operation>::iterator iterator) {
563+
assert(getBlock() &&
564+
"cannot move an operation that isn't contained in a block");
563565
block->getOperations().splice(iterator, getBlock()->getOperations(),
564566
getIterator());
565567
}

0 commit comments

Comments
 (0)