diff options
| -rw-r--r-- | mlir/include/mlir/IR/OpImplementation.h | 16 | ||||
| -rw-r--r-- | mlir/lib/IR/FunctionSupport.cpp | 8 | ||||
| -rw-r--r-- | mlir/lib/IR/Module.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Parser/Parser.cpp | 16 | ||||
| -rw-r--r-- | mlir/test/IR/invalid-func-op.mlir | 2 |
5 files changed, 29 insertions, 17 deletions
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index a167a7df14c..46c6701afbc 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -357,9 +357,21 @@ public: // Identifier Parsing //===--------------------------------------------------------------------===// + /// Parse an @-identifier and store it (without the '@' symbol) in a string + /// attribute named 'attrName'. + ParseResult parseSymbolName(StringAttr &result, StringRef attrName, + SmallVectorImpl<NamedAttribute> &attrs) { + if (failed(parseOptionalSymbolName(result, attrName, attrs))) + return emitError(getCurrentLocation()) + << "expected valid '@'-identifier for symbol name"; + return success(); + } + + /// Parse an optional @-identifier and store it (without the '@' symbol) in a + /// string attribute named 'attrName'. virtual ParseResult - parseSymbolName(StringAttr &result, StringRef attrName, - SmallVectorImpl<NamedAttribute> &attrs) = 0; + parseOptionalSymbolName(StringAttr &result, StringRef attrName, + SmallVectorImpl<NamedAttribute> &attrs) = 0; //===--------------------------------------------------------------------===// // Operand Parsing diff --git a/mlir/lib/IR/FunctionSupport.cpp b/mlir/lib/IR/FunctionSupport.cpp index 29cae177cec..6b27eb833bf 100644 --- a/mlir/lib/IR/FunctionSupport.cpp +++ b/mlir/lib/IR/FunctionSupport.cpp @@ -159,12 +159,10 @@ mlir::impl::parseFunctionLikeOp(OpAsmParser &parser, OperationState &result, auto &builder = parser.getBuilder(); // Parse the name as a symbol reference attribute. - FlatSymbolRefAttr nameAttr; - if (parser.parseAttribute(nameAttr, ::mlir::SymbolTable::getSymbolAttrName(), - result.attributes)) + StringAttr nameAttr; + if (parser.parseSymbolName(nameAttr, ::mlir::SymbolTable::getSymbolAttrName(), + result.attributes)) return failure(); - // Convert the parsed function attr into a string attr. - result.attributes.back().second = builder.getStringAttr(nameAttr.getValue()); // Parse the function signature. auto signatureLocation = parser.getCurrentLocation(); diff --git a/mlir/lib/IR/Module.cpp b/mlir/lib/IR/Module.cpp index f5cc98e39cf..79e04521e9c 100644 --- a/mlir/lib/IR/Module.cpp +++ b/mlir/lib/IR/Module.cpp @@ -44,8 +44,8 @@ ModuleOp ModuleOp::create(Location loc, Optional<StringRef> name) { ParseResult ModuleOp::parse(OpAsmParser &parser, OperationState &result) { // If the name is present, parse it. StringAttr nameAttr; - (void)parser.parseSymbolName(nameAttr, mlir::SymbolTable::getSymbolAttrName(), - result.attributes); + (void)parser.parseOptionalSymbolName( + nameAttr, mlir::SymbolTable::getSymbolAttrName(), result.attributes); // If module attributes are present, parse them. if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 2843aae4bb8..9dd6d507ab9 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -847,12 +847,13 @@ static T parseSymbol(llvm::StringRef inputStr, MLIRContext *context, //===----------------------------------------------------------------------===// InFlightDiagnostic Parser::emitError(SMLoc loc, const Twine &message) { + auto diag = mlir::emitError(getEncodedSourceLocation(loc), message); + // If we hit a parse error in response to a lexer error, then the lexer // already reported the error. if (getToken().is(Token::error)) - return InFlightDiagnostic(); - - return mlir::emitError(getEncodedSourceLocation(loc), message); + diag.abandon(); + return diag; } //===----------------------------------------------------------------------===// @@ -3937,10 +3938,11 @@ public: return success(); } - /// Parse an @-identifier and store it (without the '@' symbol) in a string - /// attribute named 'attrName'. - ParseResult parseSymbolName(StringAttr &result, StringRef attrName, - SmallVectorImpl<NamedAttribute> &attrs) override { + /// Parse an optional @-identifier and store it (without the '@' symbol) in a + /// string attribute named 'attrName'. + ParseResult + parseOptionalSymbolName(StringAttr &result, StringRef attrName, + SmallVectorImpl<NamedAttribute> &attrs) override { Token atToken = parser.getToken(); if (atToken.isNot(Token::at_identifier)) return failure(); diff --git a/mlir/test/IR/invalid-func-op.mlir b/mlir/test/IR/invalid-func-op.mlir index 15547369fc7..20af5ece6b1 100644 --- a/mlir/test/IR/invalid-func-op.mlir +++ b/mlir/test/IR/invalid-func-op.mlir @@ -3,7 +3,7 @@ // ----- func @func_op() { - // expected-error@+1 {{expected non-function type}} + // expected-error@+1 {{expected valid '@'-identifier for symbol name}} func missingsigil() -> (i1, index, f32) return } |

