diff --git a/flang/test/Fir/invalid-types.fir b/flang/test/Fir/invalid-types.fir --- a/flang/test/Fir/invalid-types.fir +++ b/flang/test/Fir/invalid-types.fir @@ -6,7 +6,7 @@ // ----- -// expected-error@+2 {{expected non-function type}} +// expected-error@+2 {{expected attribute value}} // expected-error@+1 {{expected affine map}} func private @box1() -> !fir.box, > diff --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp --- a/mlir/lib/Parser/AttributeParser.cpp +++ b/mlir/lib/Parser/AttributeParser.cpp @@ -206,10 +206,13 @@ return builder.getUnitAttr(); default: - // Parse a type attribute. - if (Type type = parseType()) - return TypeAttr::get(type); - return nullptr; + // Parse a type attribute. We parse `Optional` here to allow for providing a + // better error message. + Type type; + OptionalParseResult result = parseOptionalType(type); + if (!result.hasValue()) + return emitError("expected attribute value"), Attribute(); + return failed(*result) ? Attribute() : TypeAttr::get(type); } } diff --git a/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir b/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir --- a/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir @@ -116,7 +116,7 @@ %0 = spv.Constant 10 : i32 %1 = spv.Variable : !spv.ptr>, Function> %2 = spv.Load "Function" %1 ["Volatile"] : !spv.array<4x!spv.array<4xf32>> - // expected-error @+1 {{expected non-function type}} + // expected-error @+1 {{expected attribute value}} %3 = spv.CompositeExtract %2[%0] : !spv.array<4x!spv.array<4xf32>> return } @@ -132,7 +132,7 @@ // ----- func.func @composite_extract_invalid_index_identifier(%arg0 : !spv.array<4x!spv.array<4xf32>>) -> () { - // expected-error @+1 {{expected non-function type}} + // expected-error @+1 {{expected attribute value}} %0 = spv.CompositeExtract %arg0 ]1 : i32) : !spv.array<4x!spv.array<4xf32>> return } diff --git a/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir b/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir --- a/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir @@ -233,7 +233,7 @@ func.func @simple_load_missing_storageclass() -> () { %0 = spv.Variable : !spv.ptr - // expected-error @+1 {{expected non-function type}} + // expected-error @+1 {{expected attribute value}} %1 = spv.Load %0 : f32 return } @@ -387,7 +387,7 @@ func.func @simple_store_missing_ptr_type(%arg0 : f32) -> () { %0 = spv.Variable : !spv.ptr - // expected-error @+1 {{expected non-function type}} + // expected-error @+1 {{expected attribute value}} spv.Store %0, %arg0 : f32 return } diff --git a/mlir/test/IR/invalid-locations.mlir b/mlir/test/IR/invalid-locations.mlir --- a/mlir/test/IR/invalid-locations.mlir +++ b/mlir/test/IR/invalid-locations.mlir @@ -74,7 +74,7 @@ func.func @location_fused_missing_metadata() { ^bb: - // expected-error@+1 {{expected non-function type}} + // expected-error@+1 {{expected attribute value}} return loc(fused<) // expected-error {{expected valid attribute metadata}} } 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 @@ -261,7 +261,7 @@ // ----- func.func @nonconstant_step(%1 : i32) { - affine.for %2 = 1 to 5 step %1 { // expected-error {{expected non-function type}} + affine.for %2 = 1 to 5 step %1 { // expected-error {{expected attribute value}} // ----- @@ -618,7 +618,7 @@ // ----- func.func @max_in_upper_bound(%N : index) { - affine.for %i = 1 to max affine_map<(i)->(N, 100)> { //expected-error {{expected non-function type}} + affine.for %i = 1 to max affine_map<(i)->(N, 100)> { //expected-error {{expected attribute value}} } return } diff --git a/mlir/test/mlir-tblgen/attr-or-type-format.mlir b/mlir/test/mlir-tblgen/attr-or-type-format.mlir --- a/mlir/test/mlir-tblgen/attr-or-type-format.mlir +++ b/mlir/test/mlir-tblgen/attr-or-type-format.mlir @@ -23,7 +23,7 @@ func.func private @test_ugly_attr_missing_parameter() -> () attributes { // expected-error@+2 {{failed to parse TestAttrUgly parameter 'attr'}} - // expected-error@+1 {{expected non-function type}} + // expected-error@+1 {{expected attribute value}} attr = #test<"attr_ugly begin"> } @@ -97,7 +97,7 @@ // ----- func.func private @test_parse_param_after_struct() -> () attributes { - // expected-error@+2 {{expected non-function type}} + // expected-error@+2 {{expected attribute value}} // expected-error@+1 {{failed to parse TestAttrWithFormat parameter 'three'}} attr = #test.attr_with_format<42 : two = "foo", four = [1, 2, 3] : > }