[Mlir-commits] [mlir] [mlir] Fix alignment assertion for empty DenseArrayAttr (PR #211730)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 23 22:53:45 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-ods
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
After #<!-- -->207274, libc++ fails __assume_aligned assertion in __assume_valid_range.
`operator ArrayRef<T>()` just a cast of
`raw.data()`. `raw` is aligned copy of range from
from BytecodeReader done by
Builtin_DenseArrayRawDataParameter allocator.
However, if range is empty, aligned copying was
omitted, leaving unaligned `ArrayRef<char>`.
The fix is to replace unalined ArrayRef<> with
aligned default constructed.
---
Full diff: https://github.com/llvm/llvm-project/pull/211730.diff
2 Files Affected:
- (modified) mlir/include/mlir/IR/BuiltinAttributes.td (+3)
- (modified) mlir/lib/IR/BuiltinAttributes.cpp (+2)
``````````diff
diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td
index f238137734d56..ba2c374a9ab48 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.td
+++ b/mlir/include/mlir/IR/BuiltinAttributes.td
@@ -160,6 +160,9 @@ def Builtin_DenseArrayRawDataParameter : ArrayRefParameter<
$_allocator.allocate($_self.size(), alignof(uint64_t)));
llvm::uninitialized_copy($_self, alloc);
$_dst = ArrayRef<char>(alloc, $_self.size());
+ } else {
+ // Align possibly unaligned empty range.
+ $_dst = {};
}
}];
}
diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index 9fda2ef8e5059..888b989785498 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -21,6 +21,7 @@
#include "llvm/ADT/APSInt.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
+#include "llvm/Support/Alignment.h"
#include "llvm/Support/Endian.h"
#include <optional>
@@ -822,6 +823,7 @@ Attribute DenseArrayAttrImpl<T>::parse(AsmParser &parser, Type odsType) {
template <typename T>
DenseArrayAttrImpl<T>::operator ArrayRef<T>() const {
ArrayRef<char> raw = getRawData();
+ assert(llvm::isAddrAligned(llvm::Align(alignof(T)), raw.data()));
assert((raw.size() % sizeof(T)) == 0);
return ArrayRef<T>(reinterpret_cast<const T *>(raw.data()),
raw.size() / sizeof(T));
``````````
</details>
https://github.com/llvm/llvm-project/pull/211730
More information about the Mlir-commits
mailing list