diff --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp --- a/mlir/lib/Parser/AttributeParser.cpp +++ b/mlir/lib/Parser/AttributeParser.cpp @@ -334,6 +334,11 @@ // Extend or truncate the bitwidth to the right size. unsigned width = type.isIndex() ? IndexType::kInternalStorageBitWidth : type.getIntOrFloatBitWidth(); + + // APInt cannot hold a zero bit value. + if (width == 0) + return llvm::None; + if (width > result.getBitWidth()) { result = result.zext(width); } else if (width < result.getBitWidth()) { diff --git a/mlir/test/IR/invalid-ops.mlir b/mlir/test/IR/invalid-ops.mlir --- a/mlir/test/IR/invalid-ops.mlir +++ b/mlir/test/IR/invalid-ops.mlir @@ -1252,3 +1252,11 @@ return } + +// ----- + +func @no_zero_bit_integer_attrs() { + // expected-error @+1 {{integer constant out of range for attribute}} + %x = "some.op"(){value = 0 : i0} : () -> f32 + return +} \ No newline at end of file