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

Disable the -Wstringop-overflow warning from GCC 7 #2442

Merged
merged 1 commit into from
Aug 2, 2021

Conversation

phprus
Copy link
Contributor

@phprus phprus commented Aug 2, 2021

Fix for false positive warnings if LTO is enabled:

[  6%] Building CXX object fmt/test/CMakeFiles/chrono-test.dir/chrono-test.cc.o
cd /home/.../devel/build/target_opensuse-gcc10/fmt/test && /usr/bin/g++-10  -DGTEST_HAS_STD_WSTRING=1 -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1 -I/home/.../devel/fmt/src/include -isystem /home/.../devel/fmt/src/test/gtest/.  -fno-builtin-memcmp -msse -msse2 -msse3 -mssse3 -O3 -DNDEBUG -flto -fno-fat-lto-objects -fvisibility=hidden -fvisibility-inlines-hidden   -fno-delete-null-pointer-checks -std=gnu++17 -o CMakeFiles/chrono-test.dir/chrono-test.cc.o -c /home/.../devel/fmt/src/test/chrono-test.cc
[  6%] Linking CXX executable ../../bin/chrono-test
cd /home/.../devel/build/target_opensuse-gcc10/fmt/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/chrono-test.dir/link.txt --verbose=1
/usr/bin/g++-10  -fno-builtin-memcmp -msse -msse2 -msse3 -mssse3 -O3 -DNDEBUG -flto -fno-fat-lto-objects  -Wl,--disable-new-dtags CMakeFiles/chrono-test.dir/chrono-test.cc.o  -o ../../bin/chrono-test  libtest-main.a ../libfmt.a gtest/libgtest.a -pthread 
In function ‘format_decimal’,
    inlined from ‘format_decimal’ at /home/.../devel/fmt/src/include/fmt/format.h:1098:28,
    inlined from ‘write.constprop’ at /home/.../devel/fmt/src/include/fmt/chrono.h:1021:36:
/home/.../devel/fmt/src/include/fmt/format.h:1051:59: warning: writing 2 bytes into a region of size 0 [-Wstringop-overflow=]
 1051 | FMT_INLINE void copy2(char* dst, const char* src) { memcpy(dst, src, 2); }
      |                                                           ^
/home/.../devel/fmt/src/include/fmt/chrono.h: In member function ‘write.constprop’:
/home/.../devel/fmt/src/include/fmt/format.h:1097:8: note: at offset -2 to object ‘buffer’ with size 10 declared here
 1097 |   Char buffer[digits10<UInt>() + 1];
      |        ^
In function ‘format_decimal’,
    inlined from ‘format_decimal’ at /home/.../devel/fmt/src/include/fmt/format.h:1098:28,
    inlined from ‘write.constprop’ at /home/.../devel/fmt/src/include/fmt/chrono.h:1021:36:
/home/.../devel/fmt/src/include/fmt/format.h:1084:12: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1084 |     *--out = static_cast<Char>('0' + value);
      |            ^
/home/.../devel/fmt/src/include/fmt/chrono.h: In member function ‘write.constprop’:
/home/.../devel/fmt/src/include/fmt/format.h:1097:8: note: at offset -1 to object ‘buffer’ with size 10 declared here
 1097 |   Char buffer[digits10<UInt>() + 1];
      |        ^
In function ‘format_decimal’,
    inlined from ‘format_decimal’ at /home/.../devel/fmt/src/include/fmt/format.h:1098:28,
    inlined from ‘write.constprop’ at /home/.../devel/fmt/src/include/fmt/chrono.h:1021:36:
/home/.../devel/fmt/src/include/fmt/format.h:1051:59: warning: writing 2 bytes into a region of size 0 [-Wstringop-overflow=]
 1051 | FMT_INLINE void copy2(char* dst, const char* src) { memcpy(dst, src, 2); }
      |                                                           ^
/home/.../devel/fmt/src/include/fmt/chrono.h: In member function ‘write.constprop’:
/home/.../devel/fmt/src/include/fmt/format.h:1097:8: note: at offset -2 to object ‘buffer’ with size 10 declared here
 1097 |   Char buffer[digits10<UInt>() + 1];
      |        ^
In function ‘format_decimal’,
    inlined from ‘format_decimal’ at /home/.../devel/fmt/src/include/fmt/format.h:1098:28,
    inlined from ‘write.constprop’ at /home/.../devel/fmt/src/include/fmt/chrono.h:1021:36:
/home/.../devel/fmt/src/include/fmt/format.h:1084:12: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1084 |     *--out = static_cast<Char>('0' + value);
      |            ^
/home/.../devel/fmt/src/include/fmt/chrono.h: In member function ‘write.constprop’:
/home/.../devel/fmt/src/include/fmt/format.h:1097:8: note: at offset -1 to object ‘buffer’ with size 10 declared here
 1097 |   Char buffer[digits10<UInt>() + 1];
      |        ^
make[2]: выход из каталога «/home/.../devel/build/target_opensuse-gcc10»

Discussion in Boost.JSON issue: boostorg/json#597

@vitaut
Copy link
Contributor

vitaut commented Aug 2, 2021

Thanks for the PR but since it's a false positive please report to gcc maintainers.

@@ -26,6 +26,10 @@ function(add_fmt_executable name)
if (MINGW)
target_link_libraries(${name} -static-libgcc -static-libstdc++)
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a link to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443 or whatever the most relevant gcc bug is?

Also is it fixed in gcc 11?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

There are no warnings in gcc version 11.1.1 20210721 [revision 076930b9690ac3564638636f6b13bbb6bc608aea] (SUSE Linux).

@vitaut vitaut merged commit 0721170 into fmtlib:master Aug 2, 2021
@vitaut
Copy link
Contributor

vitaut commented Aug 2, 2021

Thank you!

sthagen added a commit to sthagen/fmtlib-fmt that referenced this pull request Aug 3, 2021
Disable the -Wstringop-overflow warning from GCC 7 (fmtlib#2442)
PoetaKodu pushed a commit to pacc-repo/fmt that referenced this pull request Nov 11, 2021
github-actions bot pushed a commit to THIS-IS-NOT-A-BACKUP/MKVToolNix that referenced this pull request Nov 4, 2022
dr7ana added a commit to dr7ana/libquic that referenced this pull request Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this pull request Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this pull request Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this pull request Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this pull request Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
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

Successfully merging this pull request may close these issues.

2 participants