[Mlir-commits] [mlir] [mlir][EmitC] Disallow string attributes as initial values (PR #75310)
Gil Rapaport
llvmlistbot at llvm.org
Sun Dec 17 04:20:35 PST 2023
================
@@ -50,6 +50,26 @@ 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.
+LogicalResult verifyInitializationAttribute(Operation *op, Attribute value,
+ Type expectedType) {
+ 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";
+
+ auto typedValue = cast<TypedAttr>(value);
+ if (!llvm::isa<NoneType>(typedValue.getType()) &&
+ expectedType != typedValue.getType())
+ return op->emitOpError()
+ << "requires attribute's type (" << typedValue.getType()
+ << ") to match op's return type (" << expectedType << ")";
----------------
aniragil wrote:
```suggestion
<< ") to be " << expectedType;
```
https://github.com/llvm/llvm-project/pull/75310
More information about the Mlir-commits
mailing list