diff --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp --- a/mlir/lib/Parser/AttributeParser.cpp +++ b/mlir/lib/Parser/AttributeParser.cpp @@ -169,8 +169,10 @@ const char *curPointer = getToken().getLoc().getPointer(); consumeToken(Token::colon); if (!consumeIf(Token::colon)) { - state.lex.resetPointer(curPointer); - consumeToken(); + if (getToken().isNot(Token::eof, Token::error)) { + state.lex.resetPointer(curPointer); + consumeToken(); + } break; } // Parse the reference itself. @@ -281,6 +283,9 @@ if (!splitName.second.empty()) getContext()->getOrLoadDialect(splitName.first); + if (nameId->size() == 0) + return emitError("expected valid attribute name"); + // Try to parse the '=' for the attribute value. if (!consumeIf(Token::equal)) { // If there is no '=', we treat this as a unit attribute. diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -1643,3 +1643,13 @@ // ----- func @foo() {} // expected-error {{expected non-empty function body}} + +// ----- + +"t"(){""} // expected-error {{expected valid attribute name}} + +// ----- + +// FIXME: Error reported at EOF token results in being reported post end of file. +"f"() { b = [@m: // expected-error@+2 {{expected ']'}} +