diff --git a/mlir/lib/IR/AttributeDetail.h b/mlir/lib/IR/AttributeDetail.h index a226a4c6ab22..21f8b68c265e 100644 --- a/mlir/lib/IR/AttributeDetail.h +++ b/mlir/lib/IR/AttributeDetail.h @@ -480,15 +480,22 @@ struct DenseElementsAttributeStorage : public AttributeStorage { /// Construct a new storage instance. static DenseElementsAttributeStorage * construct(AttributeStorageAllocator &allocator, KeyTy key) { - // If the data buffer is non-empty, we copy it into the allocator. - ArrayRef data = allocator.copyInto(key.data); + // If the data buffer is non-empty, we copy it into the allocator with a + // 64-bit alignment. + ArrayRef copy, data = key.data; + if (!data.empty()) { + char *rawData = reinterpret_cast( + allocator.allocate(data.size(), alignof(uint64_t))); + std::memcpy(rawData, data.data(), data.size()); - // If this is a boolean splat, make sure only the first bit is used. - if (key.isSplat && key.type.getElementTypeBitWidth() == 1) - const_cast(data.front()) &= 1; + // If this is a boolean splat, make sure only the first bit is used. + if (key.isSplat && key.type.getElementTypeBitWidth() == 1) + rawData[0] &= 1; + copy = ArrayRef(rawData, data.size()); + } return new (allocator.allocate()) - DenseElementsAttributeStorage(key.type, data, key.isSplat); + DenseElementsAttributeStorage(key.type, copy, key.isSplat); } ArrayRef data;