[Mlir-commits] [mlir] 849f818 - [mlir] Fix ConstantOp verifier
Marius Brehler
llvmlistbot at llvm.org
Thu Mar 11 23:50:09 PST 2021
Author: Marius Brehler
Date: 2021-03-12T08:49:25+01:00
New Revision: 849f8183fb99acab43336eb1a576a142b2e35570
URL: https://github.com/llvm/llvm-project/commit/849f8183fb99acab43336eb1a576a142b2e35570
DIFF: https://github.com/llvm/llvm-project/commit/849f8183fb99acab43336eb1a576a142b2e35570.diff
LOG: [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
Added:
Modified:
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/Dialect/Standard/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
index eb7ed2f7418c..2302457bae57 100644
--- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -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");
diff --git a/mlir/test/Dialect/Standard/invalid.mlir b/mlir/test/Dialect/Standard/invalid.mlir
index 7a8af9f409c4..9b986e5ef75f 100644
--- a/mlir/test/Dialect/Standard/invalid.mlir
+++ b/mlir/test/Dialect/Standard/invalid.mlir
@@ -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
+}
More information about the Mlir-commits
mailing list