unusual warnings in gcc 16 with LTO
- Dominant language
- C++
- Stars
- 25.8k
- Forks
- 3.1k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
The crux of the warning is:
```
/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:1209:11: warning: writing 2 bytes into a region of size 0 [-Wstringop-overflow=]
1209 | memcpy(out, digits2(value), 2);
| ^
/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h: In function ‘write_fixed’:
/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2433:8: note: at offset [-11, -1] into destination object ‘buffer’ of size 11
2433 | Char buffer[digits10() + 2];
| ^
```
Note this only happens since
```
$ gcc --version
gcc (GCC) 16.1.1 20260430
````
which has just been pushed into the repos on Arch Linux.
compiling fmtlib as static lib, and then linking with LTO enabled...
```cmake
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 12.1.0
)
FetchContent_MakeAvailable(fmt)
add_executable(app ...)
target_compile_features(app PRIVATE cxx_std_26)
target_link_libraries(app PRIVATE fmt )
```
and during link stage, I get these odd warnings
```bash
cmake -GNinja -S . -B ./build/gcc/release -DCMAKE_COLOR_DIAGNOSTICS=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=release
....
[2/11] /usr/bin/g++ -I/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include -O3 -DNDEBUG -std=c++20 -flto=auto -fno-fat-lto-objects -fdiagnostics-color=always -MD -MT _deps/fmt-build/CMakeFiles/fmt.dir/src/os.cc.o -MF _deps/fmt-build/CMakeFiles/fmt.dir/src/os.cc.o.d -o _deps/fmt-build/CMakeFiles/fmt.dir/src/os.cc.o -c /home/oliver/psmem/build/gcc/release/_deps/fmt-src/src/os.cc
[3/11] /usr/bin/g++ -I/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include -I/home/oliver/psmem/include -I/home/oliver/psmem/build/gcc/release/_deps/termbox2_src-src -I/home/oliver/psmem/build/gcc/release/_deps/unordered_dense-src/include -O3 -DNDEBUG -std=c++26 -flto=auto -fno-fat-lto-objects -fdiagnostics-color=always -Wall -Wextra -Wshadow -fdiagnostics-color=always -MD -MT CMakeFiles/psmem.dir/src/proc.cpp.o -MF CMakeFiles/psmem.dir/src/proc.cpp.o.d -o CMakeFiles/psmem.dir/src/proc.cpp.o -c /home/oliver/psmem/src/proc.cpp
[4/11] /usr/bin/g++ -I/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include -O3 -DNDEBUG -std=c++20 -flto=auto -fno-fat-lto-objects -fdiagnostics-color=always -MD -MT _deps/fmt-build/CMakeFiles/fmt.dir/src/format.cc.o -MF _deps/fmt-build/CMakeFiles/fmt.dir/src/format.cc.o.d -o _deps/fmt-build/CMakeFiles/fmt.dir/src/format.cc.o -c /home/oliver/psmem/build/gcc/release/_deps/fmt-src/src/format.cc
[5/11] : && /usr/bin/cmake -E rm -f _deps/fmt-build/libfmt.a && "/usr/bin/gcc-ar" qc _deps/fmt-build/libfmt.a _deps/fmt-build/CMakeFiles/fmt.dir/src/format.cc.o _deps/fmt-build/CMakeFiles/fmt.dir/src/os.cc.o && "/usr/bin/gcc-ranlib" _deps/fmt-build/libfmt.a && :
...
[11/11] : && /usr/bin/g++ -O3 -DNDEBUG -flto=auto -fno-fat-lto-objects -fuse-ld=mold -Wl,--dependency-file=CMakeFiles/psmem.dir/link.d CMakeFiles/psmem.dir/app/psmem.cpp.o CMakeFiles/psmem.dir/src/proc.cpp.o -o psmem _deps/fmt-build/libfmt.a libtermbox2.a _deps/fmt-build/libfmt.a && :
In function ‘write2digits’,
inlined from ‘write_significand’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2415:17,
inlined from ‘write_significand’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2407:13,
inlined from ‘write_significand’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2434:31,
inlined from ‘write_significand’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2461:20,
inlined from ‘operator()’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2539:33,
inlined from ‘write_padded’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:1701:9,
inlined from ‘write_padded’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:1710:43,
inlined from ‘write_fixed’ at /home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2536:44:
/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:1209:11: warning: writing 2 bytes into a region of size 0 [-Wstringop-overflow=]
1209 | memcpy(out, digits2(value), 2);
| ^
/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h: In function ‘write_fixed’:
/home/oliver/psmem/build/gcc/release/_deps/fmt-src/include/fmt/format.h:2433:8: note: at offset [-11, -1] into destination object ‘buffer’ of size 11
2433 | Char buffer[digits10() + 2];
| ^
```
Things I have tried:
- disabling LTO removes the warnings
- the above uses the `mold` linker but normal `ld` produces the same warnings
- changing to `-DCMAKE_BUILD_TYPE=debug` makes the warnings go away.
- using latest git fmt instead of TAG=12.1.0 produces the same warnings (now line 1208)
These may very well be over eager new gcc....or bizarre UB in my code?
Contributor guide
Assessment
This issue has not been assessed yet.