[Mlir-commits] [mlir] eb22971 - [MLIR][EmitC] Add empty emitc.constant check

Marius Brehler llvmlistbot at llvm.org
Thu Apr 27 09:04:14 PDT 2023


Author: Kiung Jung
Date: 2023-04-27T16:03:53Z
New Revision: eb22971bfb84b05be5e3cbc8691bf70314e0097c

URL: https://github.com/llvm/llvm-project/commit/eb22971bfb84b05be5e3cbc8691bf70314e0097c
DIFF: https://github.com/llvm/llvm-project/commit/eb22971bfb84b05be5e3cbc8691bf70314e0097c.diff

LOG: [MLIR][EmitC] Add empty emitc.constant check

Implementing logic to check if the emitc dialect constant Op is empty.

Reviewed By: marbre

Differential Revision: https://reviews.llvm.org/D147907

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 b3765b0a1e3b6..4851d962025c3 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -142,7 +142,6 @@ def EmitC_ConstantOp : EmitC_Op<"constant", [ConstantLike]> {
   let results = (outs AnyType);
 
   let hasFolder = 1;
-  // TODO: Disallow empty constants.
   let hasVerifier = 1;
 }
 

diff  --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index fa6919f82f408..71904762d0b13 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -125,6 +125,11 @@ LogicalResult emitc::ConstantOp::verify() {
   if (getValueAttr().isa<emitc::OpaqueAttr>())
     return success();
 
+  // Value must not be empty
+  StringAttr strAttr = getValueAttr().dyn_cast<StringAttr>();
+  if (strAttr && strAttr.getValue().empty())
+    return emitOpError() << "value must not be empty";
+
   auto value = cast<TypedAttr>(getValueAttr());
   Type type = getType();
   if (!value.getType().isa<NoneType>() && type != value.getType())

diff  --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index 421a5fbab8832..377c84ef90dbd 100644
--- a/mlir/test/Dialect/EmitC/invalid_ops.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir
@@ -16,6 +16,14 @@ func.func @const_attribute_return_type_2() {
 
 // -----
 
+func.func @empty_constant() {
+    // expected-error @+1 {{'emitc.constant' op value must not be empty}}
+    %c0 = "emitc.constant"(){value = ""} : () -> i32
+    return
+}
+
+// -----
+
 func.func @index_args_out_of_range_1() {
     // expected-error @+1 {{'emitc.call' op index argument is out of range}}
     emitc.call "test" () {args = [0 : index]} : () -> ()


        


More information about the Mlir-commits mailing list