Skip to content

Commit 01e1a5c

Browse files
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
1 parent a478e19 commit 01e1a5c

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/google/protobuf/any_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ TEST(AnyTest, TestPackAndUnpack) {
6363
}
6464

6565
TEST(AnyTest, TestPackFromSerializationExceedsSizeLimit) {
66+
#if defined(_MSC_VER) && defined(_M_IX86)
67+
GTEST_SKIP() << "This toolchain can't allocate that much memory.";
68+
#endif
6669
protobuf_unittest::TestAny submessage;
6770
submessage.mutable_text()->resize(INT_MAX, 'a');
6871
protobuf_unittest::TestAny message;

src/google/protobuf/generated_message_tctable_impl.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ class PROTOBUF_EXPORT TcParser final {
579579
template <typename T>
580580
static inline T& RefAt(void* x, size_t offset) {
581581
T* target = reinterpret_cast<T*>(static_cast<char*>(x) + offset);
582-
#ifndef NDEBUG
582+
#if !defined(NDEBUG) && !(defined(_MSC_VER) && defined(_M_IX86))
583+
// Check the alignment in debug mode, except in 32-bit msvc because it does
584+
// not respect the alignment as expressed by `alignof(T)`
583585
if (PROTOBUF_PREDICT_FALSE(
584586
reinterpret_cast<uintptr_t>(target) % alignof(T) != 0)) {
585587
AlignFail(std::integral_constant<size_t, alignof(T)>(),
@@ -593,18 +595,7 @@ class PROTOBUF_EXPORT TcParser final {
593595

594596
template <typename T>
595597
static inline const T& RefAt(const void* x, size_t offset) {
596-
const T* target =
597-
reinterpret_cast<const T*>(static_cast<const char*>(x) + offset);
598-
#ifndef NDEBUG
599-
if (PROTOBUF_PREDICT_FALSE(
600-
reinterpret_cast<uintptr_t>(target) % alignof(T) != 0)) {
601-
AlignFail(std::integral_constant<size_t, alignof(T)>(),
602-
reinterpret_cast<uintptr_t>(target));
603-
// Explicit abort to let compilers know this code-path does not return
604-
abort();
605-
}
606-
#endif
607-
return *target;
598+
return RefAt<T>(const_cast<void*>(x), offset);
608599
}
609600

610601
template <typename T>

0 commit comments

Comments
 (0)