diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -374,6 +374,10 @@ template OpTy create(Location location, Args &&... args) { OperationState state(location, OpTy::getOperationName()); + if (!state.name.getAbstractOperation()) + llvm::report_fatal_error("Building op `" + + state.name.getStringRef().str() + + "` but it isn't registered in this MLIRContext"); OpTy::build(*this, state, std::forward(args)...); auto *op = createOperation(state); auto result = dyn_cast(op); @@ -390,6 +394,10 @@ // Create the operation without using 'createOperation' as we don't want to // insert it yet. OperationState state(location, OpTy::getOperationName()); + if (!state.name.getAbstractOperation()) + llvm::report_fatal_error("Building op `" + + state.name.getStringRef().str() + + "` but it isn't registered in this MLIRContext"); OpTy::build(*this, state, std::forward(args)...); Operation *op = Operation::create(state); diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -1235,7 +1235,9 @@ static bool classof(Operation *op) { if (auto *abstractOp = op->getAbstractOperation()) return TypeID::get() == abstractOp->typeID; - return op->getName().getStringRef() == ConcreteType::getOperationName(); + llvm_unreachable(Twine("Can't cast to unregistered operation") + + ConcreteType::getOperationName()); + return false; } /// This is the hook used by the AsmParser to parse the custom form of this diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -621,8 +621,9 @@ static Dialect &lookupDialectForSymbol(MLIRContext *ctx, TypeID typeID) { auto &impl = ctx->getImpl(); auto it = impl.registeredDialectSymbols.find(typeID); - assert(it != impl.registeredDialectSymbols.end() && - "symbol is not registered."); + if (it == impl.registeredDialectSymbols.end()) + llvm::report_fatal_error( + "Trying to create a type that was not registered in this MLIRContext."); return *it->second; }