diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td --- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td +++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td @@ -142,7 +142,6 @@ 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 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -125,6 +125,11 @@ if (getValueAttr().isa()) return success(); + // Value must not be empty + StringAttr strAttr = getValueAttr().dyn_cast(); + if (strAttr && strAttr.getValue().empty()) + return emitOpError() << "value must not be empty"; + auto value = cast(getValueAttr()); Type type = getType(); if (!value.getType().isa() && type != value.getType()) diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir --- a/mlir/test/Dialect/EmitC/invalid_ops.mlir +++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir @@ -16,6 +16,14 @@ // ----- +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]} : () -> ()