diff --git a/mlir/lib/Parser/Parser.h b/mlir/lib/Parser/Parser.h --- a/mlir/lib/Parser/Parser.h +++ b/mlir/lib/Parser/Parser.h @@ -69,6 +69,12 @@ /// Emit an error and return failure. InFlightDiagnostic emitError(const Twine &message = {}) { + // If the error is to be emitted at EOF, move it back one character. + if (state.curToken.is(Token::eof)) { + return emitError( + SMLoc::getFromPointer(state.curToken.getLoc().getPointer() - 1), + message); + } return emitError(state.curToken.getLoc(), message); } InFlightDiagnostic emitError(SMLoc loc, const Twine &message = {}); 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 @@ -680,7 +680,7 @@ %z = "casdasda"(%x) : (ppop32) -> i32 } // ----- -// expected-error@+2 {{expected SSA operand}} +// expected-error@+1 {{expected SSA operand}} func@n(){^b( // ----- @@ -882,7 +882,7 @@ // ----- -!missing_type_alias = type // expected-error@+2 {{expected non-function type}} +!missing_type_alias = type // expected-error@+1 {{expected non-function type}} // -----