Fixes for 32-bit MSVC.

Disable the alignment check in 32-bit msvc.
This toolchain has a difference between "natural" and "required" alignment of
types and it can have the alignment of members of type `T` to be smaller than
`alignof(T)`.

Also, disable AnyTest.TestPackFromSerializationExceedsSizeLimit there because it can't allocate that much memory.

PiperOrigin-RevId: 559495544
pull/13647/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 9a0bc392b3
commit 66cf6b1d9c
  1. 3
      src/google/protobuf/any_test.cc
  2. 17
      src/google/protobuf/generated_message_tctable_impl.h

@ -63,6 +63,9 @@ TEST(AnyTest, TestPackAndUnpack) {
}
TEST(AnyTest, TestPackFromSerializationExceedsSizeLimit) {
#if defined(_MSC_VER) && defined(_M_IX86)
GTEST_SKIP() << "This toolchain can't allocate that much memory.";
#endif
protobuf_unittest::TestAny submessage;
submessage.mutable_text()->resize(INT_MAX, 'a');
protobuf_unittest::TestAny message;

@ -583,7 +583,9 @@ class PROTOBUF_EXPORT TcParser final {
template <typename T>
static inline T& RefAt(void* x, size_t offset) {
T* target = reinterpret_cast<T*>(static_cast<char*>(x) + offset);
#ifndef NDEBUG
#if !defined(NDEBUG) && !(defined(_MSC_VER) && defined(_M_IX86))
// Check the alignment in debug mode, except in 32-bit msvc because it does
// not respect the alignment as expressed by `alignof(T)`
if (PROTOBUF_PREDICT_FALSE(
reinterpret_cast<uintptr_t>(target) % alignof(T) != 0)) {
AlignFail(std::integral_constant<size_t, alignof(T)>(),
@ -597,18 +599,7 @@ class PROTOBUF_EXPORT TcParser final {
template <typename T>
static inline const T& RefAt(const void* x, size_t offset) {
const T* target =
reinterpret_cast<const T*>(static_cast<const char*>(x) + offset);
#ifndef NDEBUG
if (PROTOBUF_PREDICT_FALSE(
reinterpret_cast<uintptr_t>(target) % alignof(T) != 0)) {
AlignFail(std::integral_constant<size_t, alignof(T)>(),
reinterpret_cast<uintptr_t>(target));
// Explicit abort to let compilers know this code-path does not return
abort();
}
#endif
return *target;
return RefAt<T>(const_cast<void*>(x), offset);
}
template <typename T, bool is_split>

Loading…
Cancel
Save