Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings on GCC 10 + LTO #597

Closed
phprus opened this issue Jul 27, 2021 · 7 comments
Closed

Warnings on GCC 10 + LTO #597

phprus opened this issue Jul 27, 2021 · 7 comments

Comments

@phprus
Copy link

phprus commented Jul 27, 2021

Commit: 26cedfa

GCC: gcc version 10.2.1 20200825 [revision c0746a1beb1ba073c7981eb09f55b3d993b32e5c] (SUSE Linux)

CMake command:

CC=gcc-10 CXX=g++-10 cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBOOST_JSON_STANDALONE=ON -DBUILD_TESTING=ON -DBOOST_JSON_BUILD_TESTS=ON -DBOOST_JSON_BUILD_FUZZERS=OFF -DBOOST_JSON_BUILD_EXAMPLES=OFF -DCMAKE_CXX_FLAGS="-flto -fno-fat-lto-objects" ../..

Warnings:

[ 12%] Linking CXX executable boost_json-limits
cd /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/build/gcc10/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/boost_json-limits.dir/link.txt --verbose=1
/usr/bin/g++-10  -flto -fno-fat-lto-objects -O3 -DNDEBUG   CMakeFiles/boost_json-limits.dir/limits.cpp.o CMakeFiles/boost_json-limits.dir/main.cpp.o CMakeFiles/boost_json-limits.dir/__/src/src.cpp.o  -o boost_json-limits 
In function ‘relocate’,
    inlined from ‘__ct ’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/impl/array.ipp:92:17,
    inlined from ‘insert’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/impl/array.ipp:458:26,
    inlined from ‘testArray.constprop’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/test/limits.cpp:169:13:
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/impl/array.hpp:122:17: warning: ‘__builtin_memmove’ writing between 24 and 103079215080 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
  122 |     std::memmove(
      |                 ^
In member function ‘term’,
    inlined from ‘resize.constprop’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/impl/string.ipp:357:19:
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/detail/string_impl.hpp:313:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  313 |             s_.buf[n] = 0;
      |                       ^
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/impl/string.ipp: In member function ‘resize.constprop’:
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/detail/string_impl.hpp:62:14: note: at offset [100, 1001] to object ‘buf’ with size 15 declared here
   62 |         char buf[sbo_chars_ + 1];
      |              ^
In member function ‘term’,
    inlined from ‘append’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/detail/impl/string_impl.ipp:172:13,
    inlined from ‘append’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/impl/string.ipp:239:35,
    inlined from ‘testString.constprop’ at /home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/test/limits.cpp:192:17:
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/detail/string_impl.hpp:313:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  313 |             s_.buf[n] = 0;
      |                       ^
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/test/limits.cpp: In function ‘testString.constprop’:
/home/.../boostorg/json/json-26cedfabfc1ff13cd6fbc3d8ae03c33724d2343d/include/boost/json/detail/string_impl.hpp:62:14: note: at offset [886, 4294968294] to object ‘buf’ with size 15 declared here
   62 |         char buf[sbo_chars_ + 1];
      |              ^
@grisumbras
Copy link
Member

I've investigated the errors and as far as I can see, the static analyzer GCC uses when lto is enabled is kind of faulty. If the library is built in debug mode gcc do see stuff better and the warning doesn't appear. I recommend you to disable the warning (at least, when building Json).

@vinniefalco
Copy link
Member

Is this an shipping release of GCC or is it a beta?

@phprus
Copy link
Author

phprus commented Jul 27, 2021

@vinniefalco
Copy link
Member

Do you think that's best?

@grisumbras
Copy link
Member

I'm not sure it's actually doable. The warning is emitted by the linker and it seems LTO "objects" don't store pragma information, so disabling this warning with a pragma doesn't do anything. The only way I've managed to disable the warning is to pass "-Wno-stringop-overflow" to the linker. I guess, we could add linking flags to tests via build scripts.

@phprus
Copy link
Author

phprus commented Aug 3, 2021

@grisumbras, you're right, pragma doesn't work. Linker flag required.

@grisumbras
Copy link
Member

I'm inclined to do nothing here.

@grisumbras grisumbras closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants