https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118475

--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
> 
> Valgrind complains about uninitialised variables:
> ```
> ==903347== Conditional jump or move depends on uninitialised value(s)
> ==903347==    at 0x794D60: ~__shared_count (shared_ptr_base.h:1069)
> ==903347==    by 0x794D60: ~__shared_ptr (shared_ptr_base.h:1532)
> ==903347==    by 0x794D60: operator= (shared_ptr_base.h:1628)
> ==903347==    by 0x794D60: operator= (shared_ptr.h:439)
> ==903347==    by 0x794D60: SBLASTER::SBLASTER(Section*) (sblaster.cpp:3296)
> ==903347==    by 0x78FC00: make_unique<SBLASTER, Section*&>
> (unique_ptr.h:1077)
> ==903347==    by 0x78FC00: init_sblaster(Section*) (sblaster.cpp:3514)

Now, interestingly, we get:
```
$ g++ -c ../build/src/hardware/libhardware.a.p/sblaster.cpp.ii -std=gnu++20 -O2
-fPIC -Wall -Wextra
[...]
In member function ‘SbInfo& SbInfo::operator=(SbInfo&&)’,
    inlined from ‘SBLASTER::~SBLASTER()’ at
../src/hardware/sblaster.cpp:3416:9:
../src/hardware/sblaster.cpp:110:8: warning: ‘<anonymous>.SbInfo::freq_hz’ may
be used uninitialized [-Wmaybe-uninitialized]
  110 | struct SbInfo {
      |        ^~~~~~
../src/hardware/sblaster.cpp: In destructor ‘SBLASTER::~SBLASTER()’:
../src/hardware/sblaster.cpp:3416:23: note: ‘<anonymous>’ declared here
 3416 |                 sb = {};
      |                       ^
In member function ‘SbInfo& SbInfo::operator=(SbInfo&&)’,
    inlined from ‘SBLASTER::~SBLASTER()’ at
../src/hardware/sblaster.cpp:3416:9:
../src/hardware/sblaster.cpp:110:8: warning: ‘<anonymous>’ may be used
uninitialized [-Wmaybe-uninitialized]
  110 | struct SbInfo {
      |        ^~~~~~
[...]
In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/shared_ptr.h:53,
                 from
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/memory:82,
                 from ../include/dosbox.h:26,
                 from ../include/mixer.h:25,
                 from ../include/audio_vector.h:26,
                 from ../src/hardware/sblaster.cpp:29:
In constructor ‘std::__shared_ptr<_Tp,
_Lp>::__shared_ptr(std::__shared_ptr<_Tp, _Lp>&&) [with _Tp = MixerChannel;
__gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’,
    inlined from ‘std::__shared_ptr<_Tp, _Lp>& std::__shared_ptr<_Tp,
_Lp>::operator=(std::__shared_ptr<_Tp, _Lp>&&) [with _Tp = MixerChannel;
__gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/shared_ptr_base.h:1628:2,
    inlined from ‘std::shared_ptr<_Tp>&
std::shared_ptr<_Tp>::operator=(std::shared_ptr<_Tp>&&) [with _Tp =
MixerChannel]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/shared_ptr.h:439:36,
    inlined from ‘SbInfo& SbInfo::operator=(SbInfo&&)’ at
../src/hardware/sblaster.cpp:110:8,
    inlined from ‘SBLASTER::~SBLASTER()’ at
../src/hardware/sblaster.cpp:3416:9:
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/shared_ptr_base.h:1540:20:
warning: ‘<anonymous>’ may be used uninitialized [-Wmaybe-uninitialized]
 1540 |       : _M_ptr(__r._M_ptr), _M_refcount()
      |                ~~~~^~~~~~
../src/hardware/sblaster.cpp: In destructor ‘SBLASTER::~SBLASTER()’:
../src/hardware/sblaster.cpp:3416:23: note: ‘<anonymous>’ declared here
 3416 |                 sb = {};
      |                       ^
```

which I can't make much sense of, but it's clearly related to the Valgrind
output. Is there really something uninitialised here in the code, or is it
being miscompiled?

Reply via email to