diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 3a817e9231a3..b9b903cd2b5e 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1785,7 +1785,20 @@ public: // Handle delimiters. switch (delimiter) { case Delimiter::None: - break; + // Don't check for the absence of a delimiter if the number of operands + // is unknown (and hence the operand list could be empty). + if (requiredOperandCount == -1) + break; + // Token already matches an identifier and so can't be a delimiter. + if (parser.getToken().is(Token::percent_identifier)) + break; + // Test against known delimiters. + if (parser.getToken().is(Token::l_paren) || + parser.getToken().is(Token::l_square)) + return emitError(startLoc, "unexpected delimiter"); + return emitError(startLoc, "unable to parse '" + + parser.getTokenSpelling() + + "' as operand"); case Delimiter::OptionalParen: if (parser.getToken().isNot(Token::l_paren)) return false; diff --git a/mlir/test/IR/invalid-ops.mlir b/mlir/test/IR/invalid-ops.mlir index 62944e4ac6f6..1e4e6965c439 100644 --- a/mlir/test/IR/invalid-ops.mlir +++ b/mlir/test/IR/invalid-ops.mlir @@ -126,5 +126,20 @@ mlfunc @calls(%arg0 : i32) { cfgfunc @cfgfunc_with_ops(f32) { bb0(%a : f32): - %sf = addf(%a, %a) : f32 // expected-error {{custom op 'addf' expected 2 operands}} + %sf = addf %a, %a, %a : f32 // expected-error {{custom op 'addf' expected 2 operands}} } + +// ----- + +cfgfunc @cfgfunc_with_ops(f32) { +bb0(%a : f32): + %sf = addf(%a, %a) : f32 // expected-error {{unexpected delimiter}} +} + +// ----- + +cfgfunc @cfgfunc_with_ops(f32) { +bb0(%a : f32): + %sf = addf{%a, %a} : f32 // expected-error {{unable to parse '{' as operand}} +} +