[mlir] Add a better error message when failing to parse an attribute
authorRiver Riddle <riddleriver@gmail.com>
Tue, 3 May 2022 19:54:31 +0000 (12:54 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Thu, 5 May 2022 22:06:11 +0000 (15:06 -0700)
commit6609c1cc5997baa75c45283fd559897334e5d1a2
treeb88b711be8adf58bf7c0207085cc6c50557fdddb
parentba1ac98c62e847551bd7ed7d48d811228f7f4619
[mlir] Add a better error message when failing to parse an attribute

The fallback attribute parse path is parsing a Type attribute, but this results
in a really unintuitive error message: `expected non-function type`, which
doesn't really hint at tall that we were trying to parse an attribute. This
commit fixes this by trying to optionally parse a type, and on failure
emitting an error that we were expecting an attribute.

Differential Revision: https://reviews.llvm.org/D124870
flang/test/Fir/invalid-types.fir
mlir/lib/Parser/AttributeParser.cpp
mlir/test/Dialect/SPIRV/IR/composite-ops.mlir
mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
mlir/test/IR/invalid-locations.mlir
mlir/test/IR/invalid.mlir
mlir/test/mlir-tblgen/attr-or-type-format.mlir