Skip to content

Commit

Permalink
Fixes for 32-bit MSVC.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
protobuf-github-bot authored and Copybara-Service committed Aug 23, 2023
1 parent 9a0bc39 commit 66cf6b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/google/protobuf/any_test.cc
Expand Up @@ -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;
Expand Down
17 changes: 4 additions & 13 deletions src/google/protobuf/generated_message_tctable_impl.h
Expand Up @@ -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)>(),
Expand All @@ -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>
Expand Down

0 comments on commit 66cf6b1

Please sign in to comment.