This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -funsafe-loop-optimizations
- From: Geoffrey Keating <geoffk at geoffk dot org>
- To: dewar at gnat dot com (Robert Dewar)
- Cc: dberlin at dberlin dot org, dje at watson dot ibm dot com, galibert at pobox dot com, gcc at gcc dot gnu dot org, rth at redhat dot com
- Date: 01 Jan 2005 15:54:00 -0800
- Subject: Re: -funsafe-loop-optimizations
- References: <20050101171307.D95EB9611@nile.gnat.com>
dewar@gnat.com (Robert Dewar) writes:
> > (because it is infinite if n is ~0). So they aren't a "presumed
> > mistake". I think the warning would only be useful for people who were
> > considering turning on the matching optimization.
>
> But how useful? I would guess that virtually 100% of such warnings would
> be false positives, in the sense that they are not warning of situations
> in which the standard semantics would be fine. Let's take the example:
>
> > void foo (unsigned int n)
> > {
> > for (i = 0; i <= n; i++)
> > bar ();
> > }
>
> I simply don't believe that anyone would write this code, expecting that
> in the case where n was the max value, an infinite loop would occur, and
> that's just what the programmer wants.
They might not expect an infinite loop, but they might very well
expect that the last case gets executed; for instance, if bar does
if (a[i] == i)
exit (0);
and 'a' happens to be an array with exactly 256 elements, and 'i' is
of type 'unsigned char'.
IMO, this kind of thing is a really slippery slope. There are
probably hundreds of optimisations that are much easier to do if you
just assume some apparently-trivial condition like "this procedure
terminates".