CBFalconer wrote:
Frank Heckenbach wrote:
Mirsad Todorovac wrote:
... snip ...
For expensive loops that don't have constant upper and lower band but variable, this could be done (at the beginning of the expensive loop):
1. compiler checks the minimum bounds for arrays inside loop
I.e., it has to resolve equations!? (If a is an array [1 .. 20] and in the loop it says `a [i * i - 3]', it should find that i is allowed to be in the range 2 .. 4 and -4 .. -2?
Horrors. If i is a subrange, the compiler can calculate (mini * mini - 3) and (maxi * maxi - 3). If these are satisfactory then it omits the range checks on the index operation.
Nice, but wrong (e.g.: i: -4 .. 4)!
This is simply pushing the calculated index, a min and a max from the array declaration, and calling chk.
As I said, we'll do inline checks which are faster (and probably even easier). That's really not the problem.
What if the loop calls any routine which might (directly or indirectly) call Halt conditionally?
So what? A halt is a halt is a halt.
If the analysis finds that a `for' loop has an "inevitable" range error, but `Halt' is called before it, the error is not that inevitable.
My pseudo code probably looks nothing like yours, I am not familiar with GCCs intermediate forms, which I believe are designed for optimization analysis. So I am limiting myself to prodding, having been there in the past.
You don't have to know about the intermediate forms ("tree nodes" and "rtl"). Just describing things in terms of Pascal (or C) code should be enough -- we can translate it into tree nodes then.
Frank