Index: mlir/include/mlir/Dialect/EmitC/IR/EmitC.td =================================================================== --- mlir/include/mlir/Dialect/EmitC/IR/EmitC.td +++ mlir/include/mlir/Dialect/EmitC/IR/EmitC.td @@ -143,7 +143,6 @@ let results = (outs AnyType); let hasFolder = 1; - // TODO: Disallow empty constants. let hasVerifier = 1; } Index: mlir/lib/Dialect/EmitC/IR/EmitC.cpp =================================================================== --- mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -121,6 +121,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"; + TypedAttr value = getValueAttr(); Type type = getType(); if (!value.getType().isa() && type != value.getType()) @@ -129,9 +134,7 @@ return success(); } -OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { - return getValue(); -} +OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { return getValue(); } //===----------------------------------------------------------------------===// // IncludeOp Index: mlir/test/Dialect/EmitC/invalid_ops.mlir =================================================================== --- mlir/test/Dialect/EmitC/invalid_ops.mlir +++ 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]} : () -> ()