[Mlir-commits] [mlir] 906f520 - [mlir] Fix alignment assertion for empty DenseArrayAttr (#211730)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 23 23:04:28 PDT 2026
Author: Vitaly Buka
Date: 2026-07-23T23:04:23-07:00
New Revision: 906f520af01a4c788935f24caea00237b42624e2
URL: https://github.com/llvm/llvm-project/commit/906f520af01a4c788935f24caea00237b42624e2
DIFF: https://github.com/llvm/llvm-project/commit/906f520af01a4c788935f24caea00237b42624e2.diff
LOG: [mlir] Fix alignment assertion for empty DenseArrayAttr (#211730)
After #207274, libc++ fails __assume_aligned assertion in
__assume_valid_range.
https://lab.llvm.org/buildbot/#/builders/25/builds/18994
`DenseArrayAttrImpl<T>::operator ArrayRef<T>()` is 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 unaligned `ArrayRef<>` with
aligned default constructed.
Added:
Modified:
mlir/include/mlir/IR/BuiltinAttributes.td
mlir/lib/IR/BuiltinAttributes.cpp
Removed:
################################################################################
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..0f84f7a682fcf 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -19,6 +19,7 @@
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/Types.h"
#include "llvm/ADT/APSInt.h"
+#include "llvm/Support/Alignment.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/Endian.h"
@@ -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));
More information about the Mlir-commits
mailing list