Sebastian Pop wrote on 19/07/2005 09:49:11:
> Robert Dewar wrote:
> >
> > and that is called a false positive if in fact the loop does
> > not overrun. this sounds very dubious to me
I concur.
>
> The problem is that the compiler has no other information about the
> number of iterations in the loop, otherwise it wouldn't spend cycles
> on computing such estimations. Because the compiler will use the
> estimation for transforming the code, it should warn the user.
But isn't it only an estimation? In other words, does it affect anything
but performance (in case of a wrong estimation)?
>
> If I understand correctly, you would like a warning that says: "your
> code is wrong: you access the array outside the allocated size".
> Well, this is feasible, but then, the warning will be effective only
> on loops that have statically determinable number of iterations.
>
> In my opinion both these warnings are useful.
>
I am not sure about it. If you have false positives that you have
no reasonable way to turn off (other than -Wno-xxxxx), then
the warning is useless. The only alternative for -Wno-xxxxx
in your example would be:
void foo (int N)
{
int i;
int A[123];
if (N > 123) // Turn the warning off.
abort();
for (i = 0; i < N; i++)
A[i] = ...
}
This is problematic:
1. I am not sure it will turn the warning off.
2. Even if it does, this defeats the whole idea of the original
optimization (gcc could have put the abort - it is allowed
to do so because N>123 triggers undefined behavior).
3. If the line with A[i]=.... contains a function call then it is
possible that the function calls exit, abort, longjmp or throw.
In that case, N>123 is perfectly legal (and my if..abort
is not viable - so again there is no way to shut the warning
off).
I guess that VRP is not allowed to propagate N <= 123 in
this case.
Michael