This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -funsafe-loop-optimizations

On Sat, Jan 01, 2005 at 12:15:32PM -0500, Robert Dewar wrote:
> Daniel Jacobowitz wrote:
> >(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.
> I can easily believe that this program might have a bug, in that the 
> function
> misbehaves if n is the max value, but in that case, the warning is useful
> in any case, regardless of the proposed "optimization".

It's a funny sort of "bug" unless we have useful ways to "fix" it :-)
I suppose you could write "< n + 1" instead, which is the same except for
transforming Inf iterations to 0...

Daniel Jacobowitz

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]