Commit b25dd31a authored by Kyle Nekritz's avatar Kyle Nekritz Committed by Facebook Github Bot

Fix alignment issues in small_vector.

Summary: Packing the structs disregards the alignment of the storage. We should only do this on platforms where we do not need alignment.

Reviewed By: yfeldblum

Differential Revision: D7058593

fbshipit-source-id: 63b0d86bcf8b4f660ca244b1a4696e3ca64ecd6a
parent 478282cc
......@@ -55,6 +55,16 @@
#include <folly/portability/Malloc.h>
#include <folly/portability/TypeTraits.h>
#if (FOLLY_X64 || FOLLY_PPC64)
#define FOLLY_SV_PACK_ATTR FOLLY_PACK_ATTR
#define FOLLY_SV_PACK_PUSH FOLLY_PACK_PUSH
#define FOLLY_SV_PACK_POP FOLLY_PACK_POP
#else
#define FOLLY_SV_PACK_ATTR
#define FOLLY_SV_PACK_PUSH
#define FOLLY_SV_PACK_POP
#endif
// Ignore shadowing warnings within this file, so includers can use -Wshadow.
FOLLY_PUSH_WARNING
FOLLY_GCC_DISABLE_WARNING("-Wshadow")
......@@ -380,7 +390,7 @@ inline void* shiftPointer(void* p, size_t sizeBytes) {
} // namespace detail
//////////////////////////////////////////////////////////////////////
FOLLY_PACK_PUSH
FOLLY_SV_PACK_PUSH
template <
class Value,
std::size_t RequestedMaxInline = 1,
......@@ -1093,7 +1103,7 @@ class small_vector : public detail::small_vector_base<
void setCapacity(InternalSizeType c) {
capacity_ = c;
}
} FOLLY_PACK_ATTR;
} FOLLY_SV_PACK_ATTR;
struct HeapPtr {
// Lower order bit of heap_ is used as flag to indicate whether capacity is
......@@ -1107,7 +1117,7 @@ class small_vector : public detail::small_vector_base<
void setCapacity(InternalSizeType c) {
*static_cast<InternalSizeType*>(detail::pointerFlagClear(heap_)) = c;
}
} FOLLY_PACK_ATTR;
} FOLLY_SV_PACK_ATTR;
#if (FOLLY_X64 || FOLLY_PPC64)
typedef unsigned char InlineStorageDataType[sizeof(value_type) * MaxInline];
......@@ -1179,9 +1189,9 @@ class small_vector : public detail::small_vector_base<
auto vp = detail::pointerFlagClear(pdata_.heap_);
free(vp);
}
} FOLLY_PACK_ATTR u;
} FOLLY_PACK_ATTR;
FOLLY_PACK_POP
} FOLLY_SV_PACK_ATTR u;
} FOLLY_SV_PACK_ATTR;
FOLLY_SV_PACK_POP
//////////////////////////////////////////////////////////////////////
......@@ -1208,3 +1218,7 @@ struct IndexableTraits<small_vector<T, M, A, B, C>>
} // namespace folly
FOLLY_POP_WARNING
#undef FOLLY_SV_PACK_ATTR
#undef FOLLY_SV_PACK_PUSH
#undef FOLLY_SV_PACK_POP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment