[mlir] Fix ConstantOp verifier

This restricts the attributes to integers for constants of type
IndexType. So far an attribute like StringAttr as in

  %c1 = constant "" : index

is valid.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D98216
This commit is contained in:
Marius Brehler 2021-03-08 22:34:48 +01:00
parent 154395536e
commit 849f8183fb
2 changed files with 10 additions and 3 deletions

View File

@ -1205,10 +1205,9 @@ static LogicalResult verify(ConstantOp &op) {
return op.emitOpError() << "requires attribute's type (" << value.getType()
<< ") to match op's return type (" << type << ")";
if (type.isa<IndexType>() || value.isa<BoolAttr>())
return success();
if (auto intAttr = value.dyn_cast<IntegerAttr>()) {
if (type.isa<IndexType>() || value.isa<BoolAttr>())
return success();
IntegerType intType = type.cast<IntegerType>();
if (!intType.isSignless())
return op.emitOpError("requires integer result types to be signless");

View File

@ -247,3 +247,11 @@ func @non_signless_constant() {
%0 = constant 0 : si32
return
}
// -----
func @unsupported_attribute() {
// expected-error @+1 {{unsupported 'value' attribute: "" : index}}
%0 = constant "" : index
return
}