[Mlir-commits] [mlir] [mlir][memref] Fix segfault in SROA. (PR #71063)

Mehdi Amini llvmlistbot at llvm.org
Thu Nov 2 16:24:48 PDT 2023


================
@@ -187,14 +187,28 @@ DeletionKind memref::LoadOp::removeBlockingUses(
   return DeletionKind::Delete;
 }
 
-/// Returns the index of a memref in attribute form, given its indices.
+/// Returns the index of a memref in attribute form, given its indices. Returns
+/// a null pointer if whether the indices form a valid index for the provided
+/// MemRefType cannot be computed.
 static Attribute getAttributeIndexFromIndexOperands(MLIRContext *ctx,
-                                                    ValueRange indices) {
+                                                    ValueRange indices,
+                                                    MemRefType memrefType) {
+  ArrayRef<int64_t> shape = memrefType.getShape();
+  if (indices.size() != memrefType.getShape().size())
+    return {};
   SmallVector<Attribute> index;
-  for (Value coord : indices) {
+  for (size_t i = 0; i < shape.size(); i++) {
+    Value coord = indices[i];
+    int64_t dimSize = shape[i];
     IntegerAttr coordAttr;
     if (!matchPattern(coord, m_Constant<IntegerAttr>(&coordAttr)))
       return {};
+    if (!coordAttr.getType().isIndex())
+      return {};
----------------
joker-eph wrote:

Why is index an issue?

https://github.com/llvm/llvm-project/pull/71063


More information about the Mlir-commits mailing list