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
diff --git a/src/google/protobuf/any_test.cc b/src/google/protobuf/any_test.cc
index 8b544d9..b367b89 100644
--- a/src/google/protobuf/any_test.cc
+++ b/src/google/protobuf/any_test.cc
@@ -63,6 +63,9 @@
}
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;
diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h
index 6fa6423..acba789 100644
--- a/src/google/protobuf/generated_message_tctable_impl.h
+++ b/src/google/protobuf/generated_message_tctable_impl.h
@@ -583,7 +583,9 @@
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 @@
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>