Skip to content

Commit

Permalink
//test/common/common:bit_array_test fails on big endian(s390x) as saf…
Browse files Browse the repository at this point in the history
…eMemcpyUnsafeDst doesn't return expected values

Signed-off-by: namrata-ibm <[email protected]>
  • Loading branch information
namrata-ibm committed May 28, 2024
1 parent 144759d commit ea377f3
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions source/common/common/bit_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <cstring>

#include "source/common/common/assert.h"
#include "source/common/common/safe_memcpy.h"

namespace Envoy {

Expand Down Expand Up @@ -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;
Expand All @@ -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_;
}

/**
Expand Down Expand Up @@ -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_; }
Expand All @@ -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<uint8_t[]> array_start_;
// Pointer to the end of the array. In cases where we allocate a word size of
Expand Down

0 comments on commit ea377f3

Please sign in to comment.