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

Geoffrey Keating wrote:

>>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'.

Yes, of course, that's the buggy case.

IMO, this kind of thing is a really slippery slope.

We are talking about warnings here, so I don't see any 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

Then they are not optimizations, they are examples of wrong code!
But we are talking warnings here, so this seems an irrelevant comment

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