[Mlir-commits] [mlir] 2aa1818 - Disallow to apply the op & to const
Marius Brehler
llvmlistbot at llvm.org
Thu Apr 27 08:44:39 PDT 2023
Author: Kiung Jung
Date: 2023-04-27T15:44:16Z
New Revision: 2aa1818a767de86824018bb1709cc47b6344fbf9
URL: https://github.com/llvm/llvm-project/commit/2aa1818a767de86824018bb1709cc47b6344fbf9
DIFF: https://github.com/llvm/llvm-project/commit/2aa1818a767de86824018bb1709cc47b6344fbf9.diff
LOG: Disallow to apply the op & to const
Disallow to apply the operator & (address of) to emitc.constant operations.
Reviewed By: marbre, simon-camp
Differential Revision: https://reviews.llvm.org/D147992
Added:
Modified:
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/test/Dialect/EmitC/invalid_ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index f6a815087673d..b3765b0a1e3b6 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -45,7 +45,6 @@ def EmitC_ApplyOp : EmitC_Op<"apply", []> {
```
}];
- // TODO: Disallow to apply the operator & (address of) to emitc.constant operations.
let arguments = (ins
Arg<StrAttr, "the operator to apply">:$applicableOperator,
AnyType:$operand
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 1a54614cae33b..fa6919f82f408 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -59,6 +59,10 @@ LogicalResult ApplyOp::verify() {
if (applicableOperatorStr != "&" && applicableOperatorStr != "*")
return emitOpError("applicable operator is illegal");
+ Operation *op = getOperand().getDefiningOp();
+ if (op && dyn_cast<ConstantOp>(op))
+ return emitOpError("cannot apply to constant");
+
return success();
}
diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index 64753b8096fe0..421a5fbab8832 100644
--- a/mlir/test/Dialect/EmitC/invalid_ops.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir
@@ -80,6 +80,15 @@ func.func @illegal_operator(%arg : i32) {
// -----
+func.func @illegal_operand() {
+ %1 = "emitc.constant"(){value = 42: i32} : () -> i32
+ // expected-error @+1 {{'emitc.apply' op cannot apply to constant}}
+ %2 = emitc.apply "&"(%1) : (i32) -> !emitc.ptr<i32>
+ return
+}
+
+// -----
+
func.func @var_attribute_return_type_1() {
// expected-error @+1 {{'emitc.variable' op requires attribute's type ('i64') to match op's return type ('i32')}}
%c0 = "emitc.variable"(){value = 42: i64} : () -> i32
More information about the Mlir-commits
mailing list