diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -1205,9 +1205,15 @@ return op.emitOpError() << "requires attribute's type (" << value.getType() << ") to match op's return type (" << type << ")"; - if (type.isa() || value.isa()) + if (value.isa()) return success(); + if (type.isa()) { + if (!value.isa()) + return op.emitOpError("requires 'value' to be an integer constant"); + return success(); + } + if (auto intAttr = value.dyn_cast()) { IntegerType intType = type.cast(); if (!intType.isSignless()) diff --git a/mlir/test/Dialect/Standard/invalid.mlir b/mlir/test/Dialect/Standard/invalid.mlir --- a/mlir/test/Dialect/Standard/invalid.mlir +++ b/mlir/test/Dialect/Standard/invalid.mlir @@ -247,3 +247,11 @@ %0 = constant 0 : si32 return } + +// ----- + +func @mismatched_types() { + // expected-error @+1 {{requires 'value' to be an integer constant}} + %0 = constant "" : index + return +}