[LLVMdev] c const

Duncan Sands baldrick at free.fr
Wed Aug 22 13:19:03 PDT 2007


Hi Christopher,

> >> In C/C++ a restrict pointer is also assumed not to alias any other
> >> parameters, global values or local value. However the compiler must
> >> not assume that pointers "based on" a restrict pointer do not alias.
> >
> > does "based on" mean something like: copies of the pointer made in the
> > function body?
> 
> To be precise (brackets mine):
> 
> In what follows, a pointer expression E is said to be based on object  
> P [a pointer] if (at some
> sequence point in the execution of B [the enclosing block] prior to  
> the evaluation of E) modifying P to point to
> a copy of the array object into which it formerly pointed would  
> change the value of E.
> Note that ‘‘based’’ is defined only for expressions with pointer types.
> 
> This is from http://www.open-std.org/jtc1/sc22/wg14/www/docs/ 
> n1124.pdf Sec 6.7.3.1 para 3

suppose A and B are array pointers, and are in fact equal.  Consider
the code sequences

(i)
x = A[0]	(a)
B[0] = 1	(b)

and

(ii)
B[0] = 1	(b)
x = A[0]	(a)

If I understand right, (i)(b) is not based on A, either because it
has no value (not sure what "the value of E" means) or because changing
A to point to a copy would make no difference because (i)(a) is only a
read.  Also (i)(a) is not based on B because this is the first instruction.
On the other hand (ii)(a) is based on B because the value of x
is 1, but would be something else if B was changed to point to a copy.

Does this mean that if B is a restricted pointer, then the lines can be
swapped in (i).  That if A is a restricted pointer then the lines can be
swapped in (i) and (ii)?

This sounds very similar to the Ada setup, though somehow "dual" to it.

Ciao,

Duncan.




More information about the llvm-dev mailing list