[Mlir-commits] [mlir] [mlir][EmitC] Disallow string attributes as initial values (PR #75310)

Simon Camphausen llvmlistbot at llvm.org
Wed Dec 20 06:26:56 PST 2023


================
@@ -50,6 +50,27 @@ void mlir::emitc::buildTerminatedBody(OpBuilder &builder, Location loc) {
   builder.create<emitc::YieldOp>(loc);
 }
 
+/// Check that the type of the initial value is compatible with the operations
+/// result type.
+static LogicalResult verifyInitializationAttribute(Operation *op,
+                                                   Attribute value) {
+  assert(op->getNumResults() == 1 && "operation must have 1 result");
+
+  if (llvm::isa<emitc::OpaqueAttr>(value))
+    return success();
+
+  if (llvm::isa<StringAttr>(value))
+    return op->emitOpError()
+           << "string attributes are not supported, use #emitc.opaque instead";
+  Type resultType = op->getResult(0).getType();
+  Type attrType = cast<TypedAttr>(value).getType();
+  if (!llvm::isa<NoneType>(attrType) && resultType != attrType)
+    return op->emitOpError()
+           << "requires attribute's type (" << attrType
+           << ") to match op's result type (" << resultType << ")";
----------------
simon-camp wrote:

I changed the error message, and also removed the check for NoneType, I don't think that was used anywhere..

https://github.com/llvm/llvm-project/pull/75310


More information about the Mlir-commits mailing list