diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp --- a/mlir/lib/IR/SymbolTable.cpp +++ b/mlir/lib/IR/SymbolTable.cpp @@ -151,6 +151,7 @@ } } +// TODO: Consider if this should be renamed to something like insertOrUpdate /// Insert a new symbol into the table and associated operation, and rename it /// as necessary to avoid collisions. void SymbolTable::insert(Operation *symbol, Block::iterator insertPt) { @@ -161,7 +162,11 @@ assert(insertPt->getParentOp() == symbolTableOp && "expected insertPt to be in the associated module operation"); - body.getOperations().insert(insertPt, symbol); + // TODO: consider if SymbolTable's constructor should behave the same. + if (!symbol->getParentOp()) + body.getOperations().insert(insertPt, symbol); + assert(symbol->getParentOp() == symbolTableOp && + "smybol is already inserted in another op"); // Add this symbol to the symbol table, uniquing the name if a conflict is // detected.