diff --git a/mlir/lib/Tools/PDLL/Parser/Lexer.cpp b/mlir/lib/Tools/PDLL/Parser/Lexer.cpp --- a/mlir/lib/Tools/PDLL/Parser/Lexer.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Lexer.cpp @@ -355,19 +355,28 @@ case '"': // If this is a string block, we only end the string when we encounter a // `}]`. - if (!isStringBlock) return formToken(Token::string, tokStart); + if (!isStringBlock) + return formToken(Token::string, tokStart); continue; case '}': // If this is a string block, we only end the string when we encounter a // `}]`. - if (!isStringBlock || *curPtr != ']') continue; + if (!isStringBlock || *curPtr != ']') + continue; ++curPtr; return formToken(Token::string_block, tokStart); - case 0: + case 0: { // If this is a random nul character in the middle of a string, just - // include it. If it is the end of file, then it is an error. - if (curPtr - 1 != curBuffer.end()) continue; - LLVM_FALLTHROUGH; + // include it. If it is the end of file, then it is an error. + if (curPtr - 1 != curBuffer.end()) + continue; + --curPtr; + + StringRef expectedEndStr = isStringBlock ? "}]" : "\""; + return emitError(curPtr - 1, + "expected '" + expectedEndStr + "' in string literal"); + } + case '\n': case '\v': case '\f': diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -1245,6 +1245,8 @@ } else if (isInline) { return emitError(name.getLoc(), "external declarations must be declared in global scope"); + } else if (curToken.is(Token::error)) { + return failure(); } if (failed(parseToken(Token::semicolon, "expected `;` after native declaration"))) diff --git a/mlir/test/mlir-pdll/Parser/string-eof.pdll b/mlir/test/mlir-pdll/Parser/string-eof.pdll new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-pdll/Parser/string-eof.pdll @@ -0,0 +1,9 @@ +// RUN: not mlir-pdll %s -I %S -split-input-file 2>&1 | FileCheck %s + +// CHECK: expected '}]' in string literal +Constraint Cst() [{ + +// ----- + +// CHECK: expected '"' in string literal +Constraint Cst() " \ No newline at end of file