[Mlir-commits] [mlir] [mlir] Rectify mishandling in `DenseElementsAttr::get(...)` causing crash with assertion when using `mlir-opt --canonicalize` (PR #88314)

Rajveer Singh Bharadwaj llvmlistbot at llvm.org
Wed Apr 10 12:23:48 PDT 2024


https://github.com/Rajveer100 created https://github.com/llvm/llvm-project/pull/88314

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.

>From 44ea5e1b9943e7ebe635b8a67189b2bef6c7680d Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer at icloud.com>
Date: Thu, 11 Apr 2024 00:40:32 +0530
Subject: [PATCH] [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.
---
 mlir/lib/IR/BuiltinAttributes.cpp   |  2 ++
 mlir/test/mlir-opt/issue-74236.mlir | 10 ++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 mlir/test/mlir-opt/issue-74236.mlir

diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index 89b1ed67f5d067..adca7af7a91336 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -958,6 +958,8 @@ DenseElementsAttr DenseElementsAttr::get(ShapedType type,
       intVal = floatAttr.getValue().bitcastToAPInt();
     } else {
       auto intAttr = llvm::cast<IntegerAttr>(values[i]);
+      if (intAttr.getType().isIndex())
+        continue;
       assert(intAttr.getType() == eltType &&
              "expected integer attribute type to equal element type");
       intVal = intAttr.getValue();
diff --git a/mlir/test/mlir-opt/issue-74236.mlir b/mlir/test/mlir-opt/issue-74236.mlir
new file mode 100644
index 00000000000000..559daead0cf9c7
--- /dev/null
+++ b/mlir/test/mlir-opt/issue-74236.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt -split-input-file -verify-diagnostics %s
+
+llvm.func @malloc(i64) -> !llvm.ptr
+func.func @func2(%arg0: index, %arg1: memref<13x13xi64>, %arg2: index) {
+  %cst_7 = arith.constant dense<1526248407> : vector<1xi64>
+  %1 = llvm.mlir.constant(1 : index) : i64
+  %101 = vector.insert %1, %cst_7 [0] : i64 into vector<1xi64>
+  vector.print %101 : vector<1xi64>
+  return
+}



More information about the Mlir-commits mailing list