[Mlir-commits] [mlir] 7c72f55 - [mlir] Fix emitting an error at EOF

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Mar 23 13:23:06 PDT 2022


Author: Mogball
Date: 2022-03-23T20:23:01Z
New Revision: 7c72f55ea84a59957ae0a00394c953088fc543e8

URL: https://github.com/llvm/llvm-project/commit/7c72f55ea84a59957ae0a00394c953088fc543e8
DIFF: https://github.com/llvm/llvm-project/commit/7c72f55ea84a59957ae0a00394c953088fc543e8.diff

LOG: [mlir] Fix emitting an error at EOF

Emitting at error at EOF will emit the diagnostic past the end of the file. When emitting an error during parsing at EOF, emit it at the previous character.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D122295

Added: 
    

Modified: 
    mlir/lib/Parser/Parser.h
    mlir/test/IR/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Parser/Parser.h b/mlir/lib/Parser/Parser.h
index fb138d94cf3b2..3abee1fb64744 100644
--- a/mlir/lib/Parser/Parser.h
+++ b/mlir/lib/Parser/Parser.h
@@ -69,6 +69,12 @@ class Parser {
 
   /// 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
index 83d3a5d39a99f..954f0b1d99c25 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -680,7 +680,7 @@ func @calls(%arg0: i32) {
   %z = "casdasda"(%x) : (ppop32) -> i32
 }
 // -----
-// expected-error at +2 {{expected SSA operand}}
+// expected-error at +1 {{expected SSA operand}}
 func at n(){^b(
 // -----
 
@@ -882,7 +882,7 @@ func @type_alias_unknown(!unknown_alias) -> () { // expected-error {{undefined s
 
 // -----
 
-!missing_type_alias = type // expected-error at +2 {{expected non-function type}}
+!missing_type_alias = type // expected-error at +1 {{expected non-function type}}
 
 // -----
 


        


More information about the Mlir-commits mailing list