[Mlir-commits] [mlir] 898e809 - [mlir] Fix a crash when creating a 1d zero element LLVM constant

Benjamin Kramer llvmlistbot at llvm.org
Thu Oct 21 03:56:30 PDT 2021


Author: Benjamin Kramer
Date: 2021-10-21T12:55:08+02:00
New Revision: 898e80964c950fb49a133ff6018079fe8a7c922b

URL: https://github.com/llvm/llvm-project/commit/898e80964c950fb49a133ff6018079fe8a7c922b
DIFF: https://github.com/llvm/llvm-project/commit/898e80964c950fb49a133ff6018079fe8a7c922b.diff

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

Fixes a regression introduced in f9be7a7afda3c90b99c9f50e5eff1624da5a6511

Differential Revision: https://reviews.llvm.org/D112208

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
    mlir/test/Target/LLVMIR/llvmir.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index e67fda6e0ab63..94c20acd94fb5 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -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() /

diff  --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index f020840ce4a13..2d1af3a30d0c8 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -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
 


        


More information about the Mlir-commits mailing list