diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -119,9 +119,12 @@ 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(); unsigned numAggregates = denseElementsAttr.getNumElements() / diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir --- a/mlir/test/Target/LLVMIR/llvmir.mlir +++ b/mlir/test/Target/LLVMIR/llvmir.mlir @@ -21,6 +21,9 @@ // 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