[Mlir-commits] [mlir] [mlir] Reject dense_resource blobs with zero alignment (PR #181350)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 13 04:10:33 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Ayush Kumar Gaur (Ayush3941)

<details>
<summary>Changes</summary>

### What's the problem 

mlir-opt could abort with “LLVM ERROR: out of memory” when parsing dense_resource blobs whose first 4 bytes encode alignment=0.

### Why it happened

The parser allowed alignment=0 due to a missing validation check, leading to invalid allocator calls.

### Whats the Fix

Reject alignment=0 (and non-power-of-2 values) with a proper diagnostic and add a regression test.

---
Full diff: https://github.com/llvm/llvm-project/pull/181350.diff


2 Files Affected:

- (modified) mlir/lib/AsmParser/Parser.cpp (+1-1) 
- (added) mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir (+12) 


``````````diff
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 22928df03fbc7..f53cfec377bf6 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -2699,7 +2699,7 @@ class ParsedResourceEntry : public AsmParsedResourceEntry {
     }
     llvm::support::ulittle32_t align;
     memcpy(&align, blobData->data(), sizeof(uint32_t));
-    if (align && !llvm::isPowerOf2_32(align)) {
+    if (align==0 || !llvm::isPowerOf2_32(align)) {
       return p.emitError(value.getLoc(),
                          "expected hex string blob for key '" + key +
                              "' to encode alignment in first 4 bytes, but got "
diff --git a/mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir b/mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir
new file mode 100644
index 0000000000000..3d1f22089b83d
--- /dev/null
+++ b/mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt -allow-unregistered-dialect %s -verify-diagnostics
+
+"test.user_op"() {attr = dense_resource<double_data> : tensor<2xf64>} : () -> ()
+
+{-#
+  dialect_resources: {
+    builtin: {
+      // expected-error @+1 {{expected hex string blob for key 'double_data' to encode alignment in first 4 bytes, but got non-power-of-2 value: 0}}
+      double_data: "0x000000000000F03F0000000000000040"
+    }
+  }
+#-}

``````````

</details>


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


More information about the Mlir-commits mailing list