Add a parseAttribute<AttrType> overload for the non-type case.
authorRiver Riddle <riverriddle@google.com>
Mon, 18 Nov 2019 21:11:00 +0000 (13:11 -0800)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 18 Nov 2019 21:11:36 +0000 (13:11 -0800)
The variant that accepts a type will check that the parsed attribute is a valid instance of AttrType. The non-type variant would silently fail in this case, leading to garbage attribute values.

PiperOrigin-RevId: 281136528

mlir/include/mlir/IR/DialectImplementation.h
mlir/include/mlir/IR/OpImplementation.h
mlir/test/Dialect/SPIRV/structure-ops.mlir

index effcf49..b8452ac 100644 (file)
@@ -284,7 +284,7 @@ public:
     // Check for the right kind of attribute.
     result = attr.dyn_cast<AttrType>();
     if (!result)
-      return emitError(loc, "invalid kind of constant specified");
+      return emitError(loc, "invalid kind of attribute specified");
     return success();
   }
 
index 46c6701..4a970c0 100644 (file)
@@ -318,6 +318,13 @@ public:
     return parseAttribute(result, Type(), attrName, attrs);
   }
 
+  /// Parse an attribute of a specific kind and type.
+  template <typename AttrType>
+  ParseResult parseAttribute(AttrType &result, StringRef attrName,
+                             SmallVectorImpl<NamedAttribute> &attrs) {
+    return parseAttribute(result, Type(), attrName, attrs);
+  }
+
   /// Parse an arbitrary attribute of a given type and return it in result. This
   /// also adds the attribute to the specified attribute list with the specified
   /// name.
@@ -339,7 +346,7 @@ public:
     // Check for the right kind of attribute.
     result = attr.dyn_cast<AttrType>();
     if (!result)
-      return emitError(loc, "invalid kind of constant specified");
+      return emitError(loc, "invalid kind of attribute specified");
 
     return success();
   }
index f3bb327..2bbb03f 100644 (file)
@@ -121,7 +121,7 @@ spv.module "Logical" "GLSL450" {
    func @do_nothing() -> () {
      spv.Return
    }
-   // expected-error @+1 {{invalid kind of constant specified}}
+   // expected-error @+1 {{invalid kind of attribute specified}}
    spv.EntryPoint "GLCompute" "do_nothing"
 }