diff --git a/mlir/lib/Support/InterfaceSupport.cpp b/mlir/lib/Support/InterfaceSupport.cpp --- a/mlir/lib/Support/InterfaceSupport.cpp +++ b/mlir/lib/Support/InterfaceSupport.cpp @@ -28,6 +28,7 @@ }); if (it != interfaces.end() && it->first == id) { LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration"); + free(element.second); continue; } interfaces.insert(it, element); diff --git a/mlir/unittests/IR/InterfaceAttachmentTest.cpp b/mlir/unittests/IR/InterfaceAttachmentTest.cpp --- a/mlir/unittests/IR/InterfaceAttachmentTest.cpp +++ b/mlir/unittests/IR/InterfaceAttachmentTest.cpp @@ -20,6 +20,7 @@ #include "../../test/lib/Dialect/Test/TestAttributes.h" #include "../../test/lib/Dialect/Test/TestDialect.h" #include "../../test/lib/Dialect/Test/TestTypes.h" +#include "mlir/IR/OwningOpRef.h" using namespace mlir; using namespace test; @@ -291,12 +292,12 @@ MLIRContext context; // Initially, the operation doesn't have the interface. - auto moduleOp = ModuleOp::create(UnknownLoc::get(&context)); - ASSERT_FALSE(isa(moduleOp.getOperation())); + OwningOpRef moduleOp = ModuleOp::create(UnknownLoc::get(&context)); + ASSERT_FALSE(isa(moduleOp->getOperation())); // We can attach an external interface and now the operaiton has it. ModuleOp::attachInterface(context); - auto iface = dyn_cast(moduleOp.getOperation()); + auto iface = dyn_cast(moduleOp->getOperation()); ASSERT_TRUE(iface != nullptr); EXPECT_EQ(iface.getNameLengthPlusArg(10), 24u); EXPECT_EQ(iface.getNameLengthTimesArg(3), 42u); @@ -304,11 +305,12 @@ EXPECT_EQ(iface.getNameLengthMinusArg(5), 9u); // Default implementation can be overridden. - auto funcOp = FuncOp::create(UnknownLoc::get(&context), "function", - FunctionType::get(&context, {}, {})); - ASSERT_FALSE(isa(funcOp.getOperation())); + OwningOpRef funcOp = + FuncOp::create(UnknownLoc::get(&context), "function", + FunctionType::get(&context, {}, {})); + ASSERT_FALSE(isa(funcOp->getOperation())); FuncOp::attachInterface(context); - iface = dyn_cast(funcOp.getOperation()); + iface = dyn_cast(funcOp->getOperation()); ASSERT_TRUE(iface != nullptr); EXPECT_EQ(iface.getNameLengthPlusArg(10), 22u); EXPECT_EQ(iface.getNameLengthTimesArg(0), 42u); @@ -317,8 +319,9 @@ // Another context doesn't have the interfaces registered. MLIRContext other; - auto otherModuleOp = ModuleOp::create(UnknownLoc::get(&other)); - ASSERT_FALSE(isa(otherModuleOp.getOperation())); + OwningOpRef otherModuleOp = + ModuleOp::create(UnknownLoc::get(&other)); + ASSERT_FALSE(isa(otherModuleOp->getOperation())); } template @@ -346,8 +349,8 @@ MLIRContext context(registry); context.loadDialect(); - ModuleOp module = ModuleOp::create(UnknownLoc::get(&context)); - OpBuilder builder(module); + OwningOpRef module = ModuleOp::create(UnknownLoc::get(&context)); + OpBuilder builder(module->getBody(), module->getBody()->begin()); auto opJ = builder.create(builder.getUnknownLoc(), builder.getI32Type()); auto opH = @@ -355,7 +358,7 @@ auto opI = builder.create(builder.getUnknownLoc(), opJ.getResult()); - EXPECT_TRUE(isa(module.getOperation())); + EXPECT_TRUE(isa(module->getOperation())); EXPECT_TRUE(isa(opJ.getOperation())); EXPECT_TRUE(isa(opH.getOperation())); EXPECT_FALSE(isa(opI.getOperation())); @@ -373,8 +376,8 @@ MLIRContext context; context.loadDialect(); - ModuleOp module = ModuleOp::create(UnknownLoc::get(&context)); - OpBuilder builder(module); + OwningOpRef module = ModuleOp::create(UnknownLoc::get(&context)); + OpBuilder builder(module->getBody(), module->getBody()->begin()); auto opJ = builder.create(builder.getUnknownLoc(), builder.getI32Type()); auto opH = @@ -382,14 +385,14 @@ auto opI = builder.create(builder.getUnknownLoc(), opJ.getResult()); - EXPECT_FALSE(isa(module.getOperation())); + EXPECT_FALSE(isa(module->getOperation())); EXPECT_FALSE(isa(opJ.getOperation())); EXPECT_FALSE(isa(opH.getOperation())); EXPECT_FALSE(isa(opI.getOperation())); context.appendDialectRegistry(registry); - EXPECT_TRUE(isa(module.getOperation())); + EXPECT_TRUE(isa(module->getOperation())); EXPECT_TRUE(isa(opJ.getOperation())); EXPECT_TRUE(isa(opH.getOperation())); EXPECT_FALSE(isa(opI.getOperation()));