[LLVMdev] c const

Daniel Berlin dberlin at dberlin.org
Fri Aug 24 10:20:37 PDT 2007


On 8/22/07, Christopher Lamb <christopher.lamb at gmail.com> wrote:
>
>
> On Aug 22, 2007, at 3:48 PM, Duncan Sands wrote:
>
> Hi Christopher,
>
>
> If A and B are function arguments then there is no "based on"
> relationship between pointer expressions A+0 and B+0. This is because
> changing one of the pointers, A for example, to point to a copy of
> the object it points to would change the value of the pointer
> expression A+0, but not the expression B+0.
>
> I was assuming that *(A+0) and *(B+0) are pointer expressions.  Is
> that not the case?
> I believe the expressions you mention are indeed not  pointer expressions as
> they evaluate to a value of the pointed-to type rather than a pointer to the
> type. Only pointers may be "based on" other pointers from my reading of the
> spec.

Christopher, just to point something out.

Earlier you said that restrict says something about the relationship
of a pointer to non-restricted pointers.  This is not true except for
one small case.
Restricted pointers in general only tell you things about a
relationship to other restricted pointers.

IE the following is perfectly legal:

int foo(int *a, restrict int *b)
{
int *c = a;

a = b;
*a = 90;
a = c;
*a = 90;
}


The following is not:

int foo(int *a, restrict int *b, restrict int *c)
{
a = b;
*a = 90;
a = c;
*a = 90;
}

6.7.3.1 only says you can't change a pointer to point to *another
restricted pointer*.

"If P is assigned the value of a pointer expression that is based on
*another restricted pointer object P2*, associated with block B2, then
either the execution of B2 shall begin before
the execution of B, or the execution of B2 shall end prior to the
assignment. If these
requirements are not met, then the behavior is undeļ¬ned.
"

It also says that the behavior is only undefined if the value is modified.

This means loads from restricted pointers and non-restricted pointers
can alias, as can loads from restricted pointers and other restricted
pointers.

They even given an example of this, and declare it legal.

Restrict is sadly not that useful in the way the standard actually specfiies.




More information about the llvm-dev mailing list