flatbuffers
flatbuffers copied to clipboard
Compiling tests fails on s390x (big-endian) with -Werror=stringop-overflow
Compiling the C++ tests with:
- Fedora Linux (35, 36, or 37/Rawhide)
- flatbuffers 2.0.6
- gcc 11.3.1 or 12.1.1
using the distribution’s default flags for RPM builds, I see the following error on s390x
, which is the only big-endian primary architecture in Fedora Linux.
/usr/bin/g++ -DFLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1 -DFLATBUFFERS_LOCALE_INDEPENDENT=1 -DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE -I/builddir/build/BUILD/flatbuffers-2.0.6/include -I/builddir/build/BUILD/flatbuffers-2.0.6/grpc -I/builddir/build/BUILD/flatbuffers-2.0.6/redhat-linux-build/tests -I/builddir/build/BUILD/flatbuffers-2.0.6/redhat-linux-build/samples -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=zEC12 -mtune=z13 -fasynchronous-unwind-tables -fstack-clash-protection -std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow -faligned-new -Werror=implicit-fallthrough=2 -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter -fsigned-char -DNDEBUG -MD -MT CMakeFiles/flattests.dir/tests/test.cpp.o -MF CMakeFiles/flattests.dir/tests/test.cpp.o.d -o CMakeFiles/flattests.dir/tests/test.cpp.o -c /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp
In file included from /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/array.h:20,
from /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/flatbuffers.h:22,
from /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:19:
In function 'flatbuffers::WriteScalar<unsigned char>(void*, unsigned char)void',
inlined from 'flatbuffers::Vector<unsigned char>::Mutate(unsigned int, unsigned char const&)' at /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/vector.h:226:16,
inlined from 'MutateFlatBuffersTest(unsigned char*, unsigned long)' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:473:20:
/builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/base.h:420:29: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
420 | *reinterpret_cast<T *>(p) = EndianScalar(t);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:24:
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h: In function 'MutateFlatBuffersTest(unsigned char*, unsigned long)':
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h:1244:8: note: at offset 14 into destination object '<anonymous>' of size 1
1244 | struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
| ^~~~~~~
In function 'flatbuffers::WriteScalar<unsigned char>(void*, unsigned char)void',
inlined from 'flatbuffers::Vector<unsigned char>::Mutate(unsigned int, unsigned char const&)' at /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/vector.h:226:16,
inlined from 'MutateFlatBuffersTest(unsigned char*, unsigned long)' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:475:20:
/builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/base.h:420:29: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
420 | *reinterpret_cast<T *>(p) = EndianScalar(t);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h: In function 'MutateFlatBuffersTest(unsigned char*, unsigned long)':
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h:1244:8: note: at offset 14 into destination object '<anonymous>' of size 1
1244 | struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
| ^~~~~~~
In function 'flatbuffers::WriteScalar<signed char>(void*, signed char)void',
inlined from 'flatbuffers::Table::SetField<signed char>(unsigned short, signed char)bool' at /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/table.h:83:16,
inlined from 'optional_scalars::ScalarStuff::mutate_maybe_i8(signed char)' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/optional_scalars_generated.h:147:28,
inlined from 'OptionalScalarsTest()' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:3986:3:
/builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/base.h:420:29: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
420 | *reinterpret_cast<T *>(p) = EndianScalar(t);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:27:
/builddir/build/BUILD/flatbuffers-2.0.6/tests/optional_scalars_generated.h: In function 'OptionalScalarsTest()':
/builddir/build/BUILD/flatbuffers-2.0.6/tests/optional_scalars_generated.h:93:8: note: at offset 1 into destination object '<anonymous>' of size 1
93 | struct ScalarStuff FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
| ^~~~~~~~~~~
cc1plus: all warnings being treated as errors
If I add -Wno-error=stringop-overflow
, the build succeeds and the tests pass. I have not attempted to determine whether the warning reflects a real problem.