Skip to content

Commit 7b825e1

Browse files
Merge pull request #13656 from protocolbuffers/backport-tdp-msvc-32
Backport MSVC 32-bit fix
2 parents 57d1229 + 5626baf commit 7b825e1

4 files changed

Lines changed: 21 additions & 43 deletions

File tree

.github/workflows/test_cpp.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,19 @@ jobs:
348348
-Dprotobuf_BUILD_SHARED_LIBS=OFF
349349
-Dprotobuf_BUILD_EXAMPLES=ON
350350
vsversion: '2019'
351-
# TODO(b/285566773) Re-enable this test.
352-
# This is broken due to a github runner update.
353-
# See https://github.com/actions/runner-images/issues/7662 for more details
354-
#- name: Windows CMake 2022
355-
# os: windows-2022
356-
# flags: >-
357-
# -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
358-
# -Dprotobuf_BUILD_SHARED_LIBS=OFF
359-
# -Dprotobuf_BUILD_EXAMPLES=ON
360-
# vsversion: '2022'
351+
- name: Windows CMake 2022
352+
os: windows-2022
353+
flags: >-
354+
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
355+
-Dprotobuf_BUILD_SHARED_LIBS=OFF
356+
-Dprotobuf_BUILD_EXAMPLES=ON
357+
vsversion: '2022'
358+
- name: Windows CMake 32-bit
359+
os: windows-2019
360+
flags: >-
361+
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
362+
vsversion: '2019'
363+
windows-arch: 'win32'
361364
- name: Windows CMake Shared
362365
os: windows-2019
363366
flags: >-
@@ -386,6 +389,7 @@ jobs:
386389
with:
387390
cache-prefix: ${{ matrix.name }}
388391
vsversion: ${{ matrix.vsversion }}
392+
windows-arch: ${{ matrix.windows-arch || 'win64' }}
389393

390394
# Install phase.
391395
- name: Configure CMake for install

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>

src/google/protobuf/io/zero_copy_stream_unittest.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -729,26 +729,6 @@ TEST_F(IoTest, StringIo) {
729729
}
730730
}
731731

732-
// Verifies that outputs up to kint32max can be created.
733-
TEST_F(IoTest, LargeOutput) {
734-
// Filter out this test on 32-bit architectures and builds where our test
735-
// infrastructure can't handle it.
736-
if(sizeof(void*) < 8) return;
737-
#if !defined(THREAD_SANITIZER) && !defined(MEMORY_SANITIZER) && \
738-
!defined(_MSC_VER)
739-
std::string str;
740-
StringOutputStream output(&str);
741-
void* unused_data;
742-
int size;
743-
// Repeatedly calling Next should eventually grow the buffer to kint32max.
744-
do {
745-
EXPECT_TRUE(output.Next(&unused_data, &size));
746-
} while (str.size() < std::numeric_limits<int>::max());
747-
// Further increases should be possible.
748-
output.Next(&unused_data, &size);
749-
EXPECT_GT(size, 0);
750-
#endif // !THREAD_SANITIZER && !MEMORY_SANITIZER
751-
}
752732

753733
TEST(DefaultReadCordTest, ReadSmallCord) {
754734
std::string source = "abcdefghijk";

0 commit comments

Comments
 (0)