Unsafe implementation of bitwise circular shift in cetlib/bit_manipulation.h
Unit tests of
cet:circ_lshift revealed errors on clang for shifts of n=0 when compiled with optimizations higher than
-O1. Though not traced directly in assembly, research shows that implementation of shift in
cet::circ_lshift is non-portable as there is no protection against the undefined n=32=0 shifts. See, e.g.
It is likely this has never been picked up as GCC recognizes the used implementation, even though it is is non-portable:
Clang (and Intel's) rotation optimizations are likely different, resulting in the observed undefined behaviour at higher optimizations.
The attached patch updates the implementation of
cet::circ_lshift to use Regehr/Cordes portable method to protect against null shifts:
This is currently un-optimized and there may be improvements should cet::circ_lshift be used in performance critical areas.