================ @@ -23,7 +20,16 @@ using ::llvm::memprof::encodeHistogramCount; namespace { template <class T> char *WriteBytes(const T &Pod, char *Buffer) { - *(T *)Buffer = Pod; + static_assert(is_trivially_copyable<T>::value, "T must be POD"); + const uint8_t *Src = reinterpret_cast<const uint8_t *>(&Pod); + for (size_t I = 0; I < sizeof(T); ++I) { + Buffer[I] = Src[I]; + } +#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + for (size_t i = 0; i < sizeof(T) / 2; ++i) { + std::swap(buffer[i], buffer[sizeof(T) - 1 - i]); ---------------- teresajohnson wrote:
alternatively, copy in from Src above in the current direction if little endian, and in reverse order if big endian (rather than copy and swap in the BE case)? https://github.com/llvm/llvm-project/pull/150375 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits