Skip to content

Commit 898e809

Browse files
committed
[mlir] Fix a crash when creating a 1d zero element LLVM constant
Fixes a regression introduced in f9be7a7 Differential Revision: https://reviews.llvm.org/D112208
1 parent 376c138 commit 898e809

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ convertDenseElementsAttr(Location loc, DenseElementsAttr denseElementsAttr,
119119
if (!llvm::ConstantDataSequential::isElementTypeCompatible(innermostLLVMType))
120120
return nullptr;
121121

122+
ShapedType type = denseElementsAttr.getType();
123+
if (type.getNumElements() == 0)
124+
return nullptr;
125+
122126
// Compute the shape of all dimensions but the innermost. Note that the
123127
// innermost dimension may be that of the vector element type.
124-
ShapedType type = denseElementsAttr.getType();
125128
bool hasVectorElementType = type.getElementType().isa<VectorType>();
126129
unsigned numAggregates =
127130
denseElementsAttr.getNumElements() /

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ llvm.mlir.global internal @int_global_array(dense<62> : vector<3xi32>) : !llvm.a
2121
// CHECK: @int_global_array_zero_elements = internal constant [3 x [0 x [4 x float]]] zeroinitializer
2222
llvm.mlir.global internal constant @int_global_array_zero_elements(dense<> : tensor<3x0x4xf32>) : !llvm.array<3 x array<0 x array<4 x f32>>>
2323

24+
// CHECK: @int_global_array_zero_elements_1d = internal constant [0 x float] zeroinitializer
25+
llvm.mlir.global internal constant @int_global_array_zero_elements_1d(dense<> : tensor<0xf32>) : !llvm.array<0 x f32>
26+
2427
// CHECK: @i32_global_addr_space = internal addrspace(7) global i32 62
2528
llvm.mlir.global internal @i32_global_addr_space(62: i32) {addr_space = 7 : i32} : i32
2629

0 commit comments

Comments
 (0)