Skip to content

Commit 44ea5e1

Browse files
committed
[mlir] Rectify mishandling in DenseElementsAttr::get(...) causing crash with assertion when using mlir-opt --canonicalize
Resolves #74236 In `BuiltinAttributes` when we recursively handle complex types and simplify them into integer, float, string, etc., index type needs to be handled for vector-based operations before making an assertion.
1 parent eb08c0f commit 44ea5e1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mlir/lib/IR/BuiltinAttributes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,8 @@ DenseElementsAttr DenseElementsAttr::get(ShapedType type,
958958
intVal = floatAttr.getValue().bitcastToAPInt();
959959
} else {
960960
auto intAttr = llvm::cast<IntegerAttr>(values[i]);
961+
if (intAttr.getType().isIndex())
962+
continue;
961963
assert(intAttr.getType() == eltType &&
962964
"expected integer attribute type to equal element type");
963965
intVal = intAttr.getValue();

mlir/test/mlir-opt/issue-74236.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: mlir-opt -split-input-file -verify-diagnostics %s
2+
3+
llvm.func @malloc(i64) -> !llvm.ptr
4+
func.func @func2(%arg0: index, %arg1: memref<13x13xi64>, %arg2: index) {
5+
%cst_7 = arith.constant dense<1526248407> : vector<1xi64>
6+
%1 = llvm.mlir.constant(1 : index) : i64
7+
%101 = vector.insert %1, %cst_7 [0] : i64 into vector<1xi64>
8+
vector.print %101 : vector<1xi64>
9+
return
10+
}

0 commit comments

Comments
 (0)