MuonIDHlt1Alg - Protect exp(x) call from undefined behaviour sanitizer warning
Addresses errors like
/cvmfs/lhcb.cern.ch/lib/lcg/releases/LCG_96b/vdt/0.4.3/x86_64-centos7-gcc9-dbg/include/vdt/exp.h:144:38: runtime error: left shift of negative value -22
#0 0x7faa6d5f2540 in vdt::fast_expf(float) /cvmfs/lhcb.cern.ch/lib/lcg/releases/LCG_96b/vdt/0.4.3/x86_64-centos7-gcc9-dbg/include/vdt/exp.h:144
#1 0x7faa6d5f2540 in auto details::Cache::foi(unsigned int, unsigned int, float) const::{lambda(auto:1 const&)#1}::operator()<std::array<std::vector<double, std::allocator<double> >, 3ul> >(std::array<std::vector<double, std::allocator<double> >, 3ul> const&) const ../Muon/MuonID/src/component/MuonIDHlt1Alg.cpp:131
#2 0x7faa6d5f2540 in details::Cache::foi(unsigned int, unsigned int, float) const ../Muon/MuonID/src/component/MuonIDHlt1Alg.cpp:133
Basic issue is not all values representable by a floating point can be passed to exp(x)
, only those exponents that would result in a valid floating point value can be passed, which is of course a much reduced range.
vdt::fast_exp
has some protection for this, but its implementation of that protection is flawed, as it computes and performs a bit shift operation before applying that protection, which results in that shift being run with an invalid shift value, hence the error above.
This MR protects the exp call by pre-computing the valid exponent range and then clamping the values passed to this at runtime.
Edited by Christopher Rob Jones