On 2019-03-11 11:06:37 +0000, Moritz Strübe wrote:
> On 11.03.2019 at 10:14 Jakub Jelinek wrote:
> > The fact that negative or >= bit precision shifts are UB is widely known,
[...]
And even in the case where the compiler maps the shift directly to
the asm shift (without optimizations), the behavior may depend on
the processor.
> Thanks for that explanation. None the less, a compile time warning
> would be nice.
It already does by default:
-Wshift-count-negative
Warn if shift count is negative. This warning is enabled
by default.
-Wshift-count-overflow
Warn if shift count >= width of type. This warning is
enabled by default.
Of course, if the compiler cannot guess that there will be such
an issue, it will not emit the warning. You certainly don't want
a warning for each non-trivial shift just because the compiler
cannot know whether the constraint on the shift count will be
satisfied.
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)