Possible use of uninitialized values in ReSID "new" 8580 filter
Versatile Commodore Emulator
Brought to you by:
blackystardust,
gpz
GCC 14.1 warns about possible use of uninitialized values in filter8580new.cc
:
Making all in resid
../../../../trunk/vice/src/resid/filter8580new.cc: In constructor 'reSID::Filter::Filter()':
../../../../trunk/vice/src/resid/filter8580new.cc:326:54: warning: 'scaled_voltage' may be used uninitialized [-Wmaybe-uninitialized]
326 | if (scaled_voltage[fi.opamp_voltage_size - 1][0] > 65535.) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
../../../../trunk/vice/src/resid/filter8580new.cc:301:20: note: 'scaled_voltage' declared here
301 | double_point scaled_voltage[50];
| ^~~~~~~~~~~~~~
The code initializing the scaled_voltage[]
array looks okay to me though, but still worth taking a look I suppose.
Seems like a false positive to me, maybe the compiler is getting confused by the fact we only use part of the
scaled_voltage
array. This could be silenced with amemset
call.Will give it a more thorough check once I have gcc-14 installed.
Just for the record I can reproduce this with -O3 but not with -O2 (gcc-14.2)
Hmmm, this trivial patch silence the warning:
Since
fi.opamp_voltage_size - 1
is used in multiple places we can apply a nicer version like the one attached, but I'd like to file a gcc bug in case the compiler is optimizing too aggressively, unless someone can spot something wrong in the code. Next steps are single out the specific optimization flag that trigger the issue and produce a minimal test case.Bug filed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116315
As suggested the proper way to silence the warning is adding an assert.
This however would require some machinery to define NDEBUG for standard builds in resid (and while at it maybe rename the configure.in into a more modern configure.ac)
And here comes the build part, adding an --enable-debug option to resid.
To be applied with the above v2 patch.
so i should apply the last 2 patches? :)
Yes, one to define NDEBUG in resid for non-debug builds and the other for the assert that silence the warning
applied in r45317 - thanks!