[IR Parser] Fix a crash handling zero width integer attributes.

llvm::APInt cannot hold zero bit values, therefore we shouldn't try
to form them.

Differential Revision: https://reviews.llvm.org/D94384
This commit is contained in:
Chris Lattner 2021-01-10 18:32:57 -08:00
parent ffa67873a3
commit dcac2da106
2 changed files with 13 additions and 0 deletions

View File

@ -334,6 +334,11 @@ static Optional<APInt> buildAttributeAPInt(Type type, bool isNegative,
// 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()) {

View File

@ -1252,3 +1252,11 @@ func @subtensor_wrong_static_type(%t: tensor<8x16x4xf32>, %idx : index) {
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
}