PATCH to implement `restrict' in C

Richard Henderson
Sat Oct 10 18:35:00 GMT 1998

On Sat, Oct 10, 1998 at 02:50:06PM -0700, Mark Mitchell wrote:
> Unfortunately, your understanding is incorrect. :-)

I'm not convinced.

>   "A pointer expression E is said to be based on P if ... modifying P to
>    point to a copy of the array into which it formerly pointed would
>    change the value of E."


>   void h(int n, int* const restrict p, int* const q, int* const r)
>   { ... }
> where, as explained in the draft, the const-ness of `q' and `r'
> prevents them from becoming based on `p'.  However, if they were
> non-const, all bets are off; it would be legal to write:
>   q = p;
>   q[0] = p[0];

But if the assignment `q = p' did not exist, then Q could not
be said to be based on P and so there is no aliasing possible. 

Solving this correctly is a data flow problem.  I guess you are trying
for a subset of the full solution, though its so restricted I'm not
sure how useful it would actually be.  If I understand your proposal
correctly, given

	void foo(int * restrict a, int * b)
	  int i;
	  for (i = 0; i < 100; i++)
	    b[i] = a[i] + a[i-1];

you would incorrectly report true_dependance between B[i] and A[i-1].

I suppose it is something, though, and gets the parsing in to the
front end so that we can solve the problem for real later.


More information about the Gcc-patches mailing list