[Mlir-commits] [mlir] 6bfb412 - set the alignment of mlir::AttributeStorage to 64 bit explicitly to fix 32 bit platform
David Blaikie
llvmlistbot at llvm.org
Tue Nov 17 17:52:05 PST 2020
Author: daquexian
Date: 2020-11-17T17:51:53-08:00
New Revision: 6bfb4120ead7d7503f079960d7f98eacdf0be03a
URL: https://github.com/llvm/llvm-project/commit/6bfb4120ead7d7503f079960d7f98eacdf0be03a
DIFF: https://github.com/llvm/llvm-project/commit/6bfb4120ead7d7503f079960d7f98eacdf0be03a.diff
LOG: set the alignment of mlir::AttributeStorage to 64 bit explicitly to fix 32 bit platform
On some platform (like WebAssembly), alignof(mlir::AttributeStorage) is 4 instead of 8. As a result, it makes the program crashes since PointerLikeTypeTraits<mlir::Attribute>::NumLowBitsAvailable is 3.
So I explicitly set the alignment of mlir::AttributeStoarge to 64 bits, and set PointerLikeTypeTraits<mlir::Attribute>::NumLowBitsAvailable according to it.
I also fixed an another related error (alignof(NamedAttribute) -> alignof(DictionaryAttributeStorage)) based on reviewer's comments.
Reviewed By: dblaikie, rriddle
Differential Revision: https://reviews.llvm.org/D91062
Added:
Modified:
mlir/include/mlir/IR/AttributeSupport.h
mlir/include/mlir/IR/Attributes.h
mlir/lib/IR/AttributeDetail.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/AttributeSupport.h b/mlir/include/mlir/IR/AttributeSupport.h
index c0e3a0bb9b26..c228d1e867d2 100644
--- a/mlir/include/mlir/IR/AttributeSupport.h
+++ b/mlir/include/mlir/IR/AttributeSupport.h
@@ -79,7 +79,7 @@ class AttributeUniquer;
/// Base storage class appearing in an attribute. Derived storage classes should
/// only be constructed within the context of the AttributeUniquer.
-class AttributeStorage : public StorageUniquer::BaseStorage {
+class alignas(8) AttributeStorage : public StorageUniquer::BaseStorage {
friend detail::AttributeUniquer;
friend StorageUniquer;
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index b9503346dd6f..5464a1f1c80e 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -1714,7 +1714,8 @@ template <> struct PointerLikeTypeTraits<mlir::Attribute> {
static inline mlir::Attribute getFromVoidPointer(void *ptr) {
return mlir::Attribute::getFromOpaquePointer(ptr);
}
- static constexpr int NumLowBitsAvailable = 3;
+ static constexpr int NumLowBitsAvailable = llvm::PointerLikeTypeTraits<
+ mlir::AttributeStorage *>::NumLowBitsAvailable;
};
template <>
diff --git a/mlir/lib/IR/AttributeDetail.h b/mlir/lib/IR/AttributeDetail.h
index ad0b302bc78d..1c4acf81c88b 100644
--- a/mlir/lib/IR/AttributeDetail.h
+++ b/mlir/lib/IR/AttributeDetail.h
@@ -84,7 +84,7 @@ struct DictionaryAttributeStorage final
construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
auto size = DictionaryAttributeStorage::totalSizeToAlloc<NamedAttribute>(
key.size());
- auto rawMem = allocator.allocate(size, alignof(NamedAttribute));
+ auto rawMem = allocator.allocate(size, alignof(DictionaryAttributeStorage));
// Initialize the storage and trailing attribute list.
auto result = ::new (rawMem) DictionaryAttributeStorage(key.size());
More information about the Mlir-commits
mailing list