MetaScale/nt2 — Issue #114: rol / ror rely on undefined behaviour (shifting by integer size)
Author: mgaunard
Created: 2011-12-08 11:52:06+00:00
State: open

x >> 32, with x an uint32_t, is undefined according to C and C++.
In practice it's either x or 0 (both of which work correctly for rol/ror), but clang does not define the result of this operation at all and allows itself to do certain optimizations.

This shift is invoked when doing a rol or ror of 0.

A possible way to fix it is to change

shri(a0, CHAR_BIT*sizeof(A0)-a1)

by

shri(a0, (CHAR_BIT*sizeof(A0)-a1) & (CHAR_BIT*sizeof(A0)-1))

but this could have some overhead on other compilers that define shri correctly for 32.