diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp index 9f5dd2c9e3b72..528b4f586d66f 100644 --- a/mlir/lib/IR/SymbolTable.cpp +++ b/mlir/lib/IR/SymbolTable.cpp @@ -132,8 +132,6 @@ SymbolTable::SymbolTable(Operation *symbolTableOp) auto inserted = symbolTable.insert({name, &op}); (void)inserted; - assert(inserted.second && - "expected region to contain uniquely named symbol operations"); } } diff --git a/mlir/unittests/IR/SymbolTableTest.cpp b/mlir/unittests/IR/SymbolTableTest.cpp index 864eb40898335..45d48f62c10b3 100644 --- a/mlir/unittests/IR/SymbolTableTest.cpp +++ b/mlir/unittests/IR/SymbolTableTest.cpp @@ -166,4 +166,34 @@ TEST(SymbolOpInterface, Visibility) { ASSERT_EQ(diagStr, expectedDiag); } +TEST(SymbolOpInterface, Duplicate) { + DialectRegistry registry; + ::test::registerTestDialect(registry); + MLIRContext context(registry); + + constexpr static StringLiteral kInput = R"MLIR( + "test.overridden_symbol_visibility"() {sym_name = "duplicate_symbol_name"} : () -> () + "test.overridden_symbol_visibility"() {sym_name = "duplicate_symbol_name"} : () -> () + )MLIR"; + + constexpr bool verifyAfterParse = false; + ParserConfig parserConfig(&context, verifyAfterParse); + OwningOpRef module = + parseSourceString(kInput, parserConfig); + + // copying an existing symboltable instance should not crash + SymbolTable symbolTable(module.get()); + + std::string diagStr; + constexpr static StringLiteral expectedDiag = + "redefinition of symbol named 'duplicate_symbol_name'"; + context.getDiagEngine().registerHandler( + [&diagStr](Diagnostic &diag) { diagStr += diag.str(); }); + + LogicalResult res = mlir::verify(module.get(), true); + + ASSERT_FALSE(succeeded(res)); + ASSERT_EQ(diagStr, expectedDiag); +} + } // namespace