Re: Having fun with the following C code (UB)
On 2014-04-14 14:14:14 +0200, Raphael Geissert wrote:
> Vincent Lefevre wrote:
> [...]
> > int foo (int d)
> > {
> > int m;
> > m = d * 64;
> > return m;
> > }
> [...]
> > while the cause of a potential bug would be the same. For consistency,
> > GCC should have warned for the first code too.
>
> No, there is no optimisation in that case, so there is no warning. It only
> warns when it uses the knowledge that "(signed) integer overflow isn't
> possible" to optimise away some redundant code.
But what I mean is that it's pointless to emit such a warning when
the effect of the potential integer overflow is already visible,
for instance in printf below:
m = d * C;
printf ("%d\n", m);
return m >= 0;
If there was an integer overflow, you will get an incorrect value
output by the printf. This means that it is very likely to be a false
positive. So, one doesn't want the warning.
--
Vincent Lefèvre <vincent@vinc17.net> - 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)
Reply to: