diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -99,7 +99,7 @@ MLIRContext *getContext() { return location->getContext(); } /// Return the dialect this operation is associated with, or nullptr if the - /// associated dialect is not registered. + /// associated dialect is not loaded. Dialect *getDialect() { return getName().getDialect(); } /// The source location the operation was defined or derived from. diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -383,8 +383,8 @@ /// Return the name of the dialect this operation is registered to. StringRef getDialectNamespace() const; - /// Return the Dialect this operation is registered to if it is loaded in the - /// context, or nullptr if the dialect isn't loaded. + /// Return the dialect this operation is registered to if the dialect is + /// loaded in the context, or nullptr if the dialect isn't loaded. Dialect *getDialect() const { if (const auto *abstractOp = getAbstractOperation()) return &abstractOp->dialect; diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -180,7 +180,7 @@ name.getStringRef() + " created with unregistered dialect. If this is intended, please call " "allowUnregisteredDialects() on the MLIRContext, or use " - "-allow-unregistered-dialect with the MLIR opt tool used"); + "-allow-unregistered-dialect with the MLIR tool used."); #endif } diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -510,7 +510,7 @@ errors.push_back(entry.second.getPointer()); llvm::array_pod_sort(errors.begin(), errors.end()); - for (auto entry : errors) { + for (const char *entry : errors) { auto loc = SMLoc::getFromPointer(entry); emitError(loc, "use of undeclared SSA value name"); } @@ -989,9 +989,18 @@ // Lazy load dialects in the context as needed. if (!result.name.getAbstractOperation()) { StringRef dialectName = StringRef(name).split('.').first; - if (!getContext()->getLoadedDialect(dialectName) && - getContext()->getOrLoadDialect(dialectName)) { - result.name = OperationName(name, getContext()); + if (!getContext()->getLoadedDialect(dialectName)) { + if (getContext()->getOrLoadDialect(dialectName)) { + result.name = OperationName(name, getContext()); + } else if (!getContext()->allowsUnregisteredDialects()) { + // Emit an error if the dialect couldn't be loaded (i.e., it was not + // registered) and unregistered dialects aren't allowed). + return emitError( + "operation being parsed with an unregistered dialect. If " + "this is intended, please use -allow-unregistered-dialect " + "with the MLIR tool used"), + nullptr; + } } } @@ -1689,8 +1698,8 @@ pushSSANameScope(isIsolatedNameScope); // Parse the first block directly to allow for it to be unnamed. - auto owning_block = std::make_unique(); - Block *block = owning_block.get(); + auto owningBlock = std::make_unique(); + Block *block = owningBlock.get(); // If this block is not defined in the source file, add a definition for it // now in the assembly state. Blocks with a name will be defined when the name @@ -1737,7 +1746,7 @@ } // Parse the rest of the region. - region.push_back(owning_block.release()); + region.push_back(owningBlock.release()); while (getToken().isNot(Token::r_brace)) { Block *newBlock = nullptr; if (parseBlock(newBlock)) @@ -2071,13 +2080,13 @@ return emitError(mlir::UnknownLoc::get(context), "only main buffer parsed at the moment"); } - auto file_or_err = llvm::MemoryBuffer::getFileOrSTDIN(filename); - if (std::error_code error = file_or_err.getError()) + auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); + if (std::error_code error = fileOrErr.getError()) return emitError(mlir::UnknownLoc::get(context), "could not open input file " + filename); // Load the MLIR source file. - sourceMgr.AddNewSourceBuffer(std::move(*file_or_err), llvm::SMLoc()); + sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), llvm::SMLoc()); return parseSourceFile(sourceMgr, block, context, sourceFileLoc, asmState); } diff --git a/mlir/test/IR/invalid-unregistered.mlir b/mlir/test/IR/invalid-unregistered.mlir --- a/mlir/test/IR/invalid-unregistered.mlir +++ b/mlir/test/IR/invalid-unregistered.mlir @@ -1,8 +1,6 @@ // RUN: mlir-opt %s -split-input-file -verify-diagnostics -// REQUIRES: noasserts - -// expected-error @below {{op created with unregistered dialect}} +// expected-error @below {{operation being parsed with an unregistered dialect}} "unregistered_dialect.op"() : () -> () // -----