icecube / photospline

https://docs.icecube.aq/photospline/v2.0.7/
BSD 2-Clause "Simplified" License
5 stars 12 forks source link

variable 'dummy' set but not used #32

Closed kjmeagher closed 1 year ago

kjmeagher commented 1 year ago

I am getting a lot of warnings like this from code that uses photo spline. It looks like dummy is only being used on certain code paths

/usr/local/include/photospline/detail/bspline_eval.h:590:18: warning: variable 'dummy' set but not used [-Wunused-but-set-variable]
        volatile double dummy;
cnweaver commented 1 year ago

The variable is always used, and the compiler warning is arguably wrong-ish, but see if the change in https://github.com/icecube/photospline/pull/33 cleans this up for you.

kjmeagher commented 1 year ago

That solution removes the warning, but I don't see why the warning is wrong, dummy is never accessed

cnweaver commented 1 year ago

The value is never loaded (since the variable is defined locally it cannot be used from elsewhere and cannot be something memory mapped) but the variable is used as a sink to ensure that the result of the calculations being benchmarked cannot be optimized away, as removing writes to volatile variables is forbidden. So, the compiler is trying to be helpful about identifying dead code, but does not actually understand the context, so while the warning is technically correct (up to poor wording), it is not useful.

cnweaver commented 1 year ago

Fixed by https://github.com/icecube/photospline/pull/33