[llvm-branch-commits] [compiler-rt] [llvm] Write out raw profile bytes in little endian. (PR #150375)
Teresa Johnson via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 24 21:16:07 PDT 2025
================
@@ -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
More information about the llvm-branch-commits
mailing list