https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121165
Bug ID: 121165
Summary: false positive Warray-bounds while building openmpt
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Keywords: diagnostic, false-positive, needs-source
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 56456
Target Milestone: ---
Originally reported via masterdon:
https://hachyderm.io/@[email protected]/114873750597547044
https://paste.debian.net/hidden/c08ad8b8/:
```
manx@vmdebian13:~/tmp$ git clone --quiet https://github.com/OpenMPT/openmpt.git
openmpt.git
manx@vmdebian13:~/tmp$ cd openmpt.git/
manx@vmdebian13:~/tmp/openmpt.git$ git checkout --quiet
dc917f6a316238b040293c358664a4d1cc58dba8
manx@vmdebian13:~/tmp/openmpt.git$ g++ -std=c++23 -fexceptions -frtti -pthread
-fPIC -fsanitize=undefined -fvisibility=hidden -O3 -ffunction-sections
-fdata-sections -g -fno-omit-frame-pointer -Wall -Wextra -Wpedantic
-Wcast-align -Wcast-qual -Wdouble-promotion -Wfloat-conversion
-Wframe-larger-than=16000 -Winit-self -Wlogical-op -Wmissing-declarations
-Wpointer-arith -Wstrict-aliasing -Wsuggest-override
-Wundef -Wno-psabi -Isrc -Icommon -I. -DMPT_BUILD_CHECKED -D
MPT_SVNURL=\"https://source.openmpt.org/svn/openmpt/trunk/OpenMPT\" -D
MPT_SVNVERSION=\"23791\" -D MPT_SVNDATE=\"2025-07-17T20:14:34.082376Z\"
-DLIBOPENMPT_BUILD -DMPT_WITH_MINIZ -DMINIZ_NO_STDIO -Iinclude
-DMPT_WITH_MINIMP3 -Iinclude -DMPT_WITH_STBVORBIS -DSTB_VORBIS_NO_PULLDATA_API
-DSTB_VORBIS_NO_STDIO -Iinclude -c -o soundlib/Load_xmf.o
soundlib/Load_xmf.cpp
In file included from /usr/include/c++/14/array:43,
from src/mpt/base/span.hpp:11,
from common/stdafx.h:72,
from soundlib/Load_xmf.cpp:11:
In static member function ‘static constexpr _Up* std::__copy_move<_IsMove,
true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp =
const std::byte; _Up = std::byte; bool _IsMove = false]’,
inlined from ‘constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool
_IsMove = false; _II = const byte*; _OI = byte*]’ at
/usr/include/c++/14/bits/stl_algobase.h:521:30,
inlined from ‘constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool
_IsMove = false; _II = const byte*; _OI = byte*]’ at
/usr/include/c++/14/bits/stl_algobase.h:548:42,
inlined from ‘constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool
_IsMove = false; _II = const byte*; _OI = byte*]’ at
/usr/include/c++/14/bits/stl_algobase.h:555:31,
inlined from ‘constexpr _OI std::copy(_II, _II, _OI) [with _II = const
byte*; _OI = byte*]’ at /usr/include/c++/14/bits/stl_algobase.h:651:7,
inlined from ‘virtual mpt::mpt_libopenmpt::byte_span
mpt::mpt_libopenmpt::IO::FileDataMemory::Read(mpt::mpt_libopenmpt::IO::IFileData::pos_type,
mpt::mpt_libopenmpt::byte_span) const’ at
src/mpt/io_read/filedata_memory.hpp:68:12,
inlined from ‘Tspan mpt::mpt_libopenmpt::IO::FileCursor<Ttraits,
Tfilenametraits>::GetRaw(Tspan) const [with Tspan = std::span<std::byte>;
Ttraits = mpt::mpt_libopenmpt::IO::FileCursorTraitsMemory; Tfilenametraits =
mpt::mpt_libopenmpt::IO::FileCursorFilenameTraitsNone]’ at
src/mpt/io_read/filecursor.hpp:363:31,
inlined from ‘bool mpt::mpt_libopenmpt::IO::FileReader::Read(TFileCursor&,
T&) [with T = unsigned char; TFileCursor =
OpenMPT::detail::FileReader<mpt::mpt_libopenmpt::IO::FileCursorTraitsMemory,
mpt::mpt_libopenmpt::IO::FileCursorFilenameTraitsNone>]’ at
src/mpt/io_read/filereader.hpp:242:28,
inlined from ‘mpt::mpt_libopenmpt::uint8
mpt::mpt_libopenmpt::IO::FileReader::ReadUint8(TFileCursor&) [with TFileCursor
= OpenMPT::detail::FileReader<mpt::mpt_libopenmpt::IO::FileCursorTraitsMemory,
mpt::mpt_libopenmpt::IO::FileCursorFilenameTraitsNone>]’ at
src/mpt/io_read/filereader.hpp:459:23,
inlined from ‘OpenMPT::uint8 OpenMPT::detail::FileReader<Ttraits,
Tfilenametraits>::ReadUint8() [with Ttraits =
mpt::mpt_libopenmpt::IO::FileCursorTraitsMemory; Tfilenametraits =
mpt::mpt_libopenmpt::IO::FileCursorFilenameTraitsNone]’ at
soundlib/../common/FileReader.h:291:40,
inlined from ‘static OpenMPT::CSoundFile::ProbeResult
OpenMPT::CSoundFile::ProbeFileHeaderXMF(OpenMPT::MemoryFileReader, const
OpenMPT::uint64*)’ at soundlib/Load_xmf.cpp:120:29:
/usr/include/c++/14/bits/stl_algobase.h:452:30: warning: ‘void*
__builtin_memcpy(void*, const void*, long unsigned int)’ forming offset 1 is
out of the bounds [0, 1] of object ‘target’ with type
‘mpt::mpt_libopenmpt::uint8’ {aka ‘unsigned char’} [-Warray-bounds=]
452 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from soundlib/../common/FileReader.h:19,
from soundlib/Loaders.h:15,
from soundlib/Load_xmf.cpp:12:
src/mpt/io_read/filereader.hpp: In static member function ‘static
OpenMPT::CSoundFile::ProbeResult
OpenMPT::CSoundFile::ProbeFileHeaderXMF(OpenMPT::MemoryFileReader, const
OpenMPT::uint64*)’:
src/mpt/io_read/filereader.hpp:458:15: note: ‘target’ declared here
458 | uint8 target;
| ^~~~~~
manx@vmdebian13:~/tmp/openmpt.git$ g++ --version
g++ (Debian 14.2.0-19) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
I am filing this now so I don't forget while I try to reproduce it and see what
can be done about it. I suspect there is a missed optimization but I could be
wrong.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds