From ea377f36c5c7c311a32e5bc3a46b55a7d0c244b6 Mon Sep 17 00:00:00 2001 From: namrata-ibm Date: Tue, 28 May 2024 12:27:13 +0000 Subject: [PATCH] //test/common/common:bit_array_test fails on big endian(s390x) as safeMemcpyUnsafeDst doesn't return expected values Signed-off-by: namrata-ibm --- source/common/common/bit_array.h | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/source/common/common/bit_array.h b/source/common/common/bit_array.h index c4aced97dac3a..155bfb91ac3d2 100644 --- a/source/common/common/bit_array.h +++ b/source/common/common/bit_array.h @@ -4,7 +4,6 @@ #include #include "source/common/common/assert.h" -#include "source/common/common/safe_memcpy.h" namespace Envoy { @@ -50,7 +49,7 @@ class BitArray { RELEASE_ASSERT(ENVOY_BIT_ARRAY_SUPPORTED, "BitArray requires 64-bit architecture."); // Init padding to avoid sanitizer complaints if reading the last elements. uint8_t* padding_start = array_start_.get() + (bytesNeeded(width, num_items) - WordSize); - storeUnsignedWord(padding_start, 0); + absl::little_endian::Store64(padding_start, 0); } static constexpr int MaxBitWidth = 32; @@ -74,7 +73,7 @@ class BitArray { // containing the element. We shift this to get have the element's bits // at bit 0, and then apply the mask which will capture all the bits // pertaining to this element. - return (loadUnsignedWord(byte0) >> index_of_0th_bit) & mask_; + return (absl::little_endian::Load64(byte0) >> index_of_0th_bit) & mask_; } /** @@ -109,8 +108,8 @@ class BitArray { // We then bitwise-or this to capture the value we're assigning to the // element. const uint64_t value_to_store = - ((loadUnsignedWord(byte0) & mask_to_preserve) | (shifted_value & mask_to_write)); - storeUnsignedWord(byte0, value_to_store); + ((absl::little_endian::Load64(byte0) & mask_to_preserve) | (shifted_value & mask_to_write)); + absl::little_endian::Store64(byte0, value_to_store); } size_t size() const { return num_items_; } @@ -128,16 +127,6 @@ class BitArray { return std::max(bytes_required, minimum_bytes_required_without_padding) + padding; } - static inline void storeUnsignedWord(void* destination, uint64_t value) { - safeMemcpyUnsafeDst(destination, &value); - } - - static inline uint64_t loadUnsignedWord(const void* source) { - uint64_t destination; - safeMemcpyUnsafeSrc(&destination, source); - return destination; - } - // Backing storage for the underlying array of bits. std::unique_ptr array_start_; // Pointer to the end of the array. In cases where we allocate a word size of