[mlir] Fix a crash when creating a 1d zero element LLVM constant

Fixes a regression introduced in f9be7a7afd

Differential Revision: https://reviews.llvm.org/D112208
This commit is contained in:
Benjamin Kramer 2021-10-21 11:57:16 +02:00
parent 376c1389f6
commit 898e80964c
2 changed files with 7 additions and 1 deletions

View File

@ -119,9 +119,12 @@ convertDenseElementsAttr(Location loc, DenseElementsAttr denseElementsAttr,
if (!llvm::ConstantDataSequential::isElementTypeCompatible(innermostLLVMType))
return nullptr;
ShapedType type = denseElementsAttr.getType();
if (type.getNumElements() == 0)
return nullptr;
// Compute the shape of all dimensions but the innermost. Note that the
// innermost dimension may be that of the vector element type.
ShapedType type = denseElementsAttr.getType();
bool hasVectorElementType = type.getElementType().isa<VectorType>();
unsigned numAggregates =
denseElementsAttr.getNumElements() /

View File

@ -21,6 +21,9 @@ llvm.mlir.global internal @int_global_array(dense<62> : vector<3xi32>) : !llvm.a
// CHECK: @int_global_array_zero_elements = internal constant [3 x [0 x [4 x float]]] zeroinitializer
llvm.mlir.global internal constant @int_global_array_zero_elements(dense<> : tensor<3x0x4xf32>) : !llvm.array<3 x array<0 x array<4 x f32>>>
// CHECK: @int_global_array_zero_elements_1d = internal constant [0 x float] zeroinitializer
llvm.mlir.global internal constant @int_global_array_zero_elements_1d(dense<> : tensor<0xf32>) : !llvm.array<0 x f32>
// CHECK: @i32_global_addr_space = internal addrspace(7) global i32 62
llvm.mlir.global internal @i32_global_addr_space(62: i32) {addr_space = 7 : i32} : i32