[cfe-dev] [LLVMdev] no-alias generated as result of restrict function arguments

Dan Gohman dan433584 at gmail.com
Wed Dec 12 11:01:01 PST 2012


On Wed, Dec 12, 2012 at 8:38 AM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> On Tue, Dec 11, 2012 at 03:17:43AM -0800, Chandler Carruth wrote:
>> As Joerg pointed out in IRC, 'y' is an lvalue, but we do not use it to
>> access the object it designates, we only use it to compute the address, and
>> thus restrict should have no bearing on it. That would in turn make Clang's
>> optimization incorrect and also seems likely to make 'noalias' essentially
>> useless for modeling restrict. =/
>
> Looking a bit deeper, the issue is ultimately that isIdentifiedObject is
> true if NoAlias is specified for the argument. There is a comment at the
> beginning of AliasAnalysis.h that NoAlias doesn't imply inequal
> pointers.
>
> One of the uses in BasicAliasAnalysis.cpp seems also questionable
> ("Constant pointers can't alias with non-const isIdentifiedObject objects")
> in this light. What does constant pointer in this context mean?

It means the pointer value itself satisfies isa<Constant>.

> Is that
> assumption violated if I explicitly cast away const and pass the result
> to a function with NoAlias argument?

Not immediately, no. It means that you can't access the constant
pointer's pointee directly within the noalias argument's scope. Access
to that object must go through the noalias argument.

Restrict on a pointer loosely means "All accesses to my pointee(s) in
my scope must go through me". It doesn't mean "I'm the only pointer
value in the  program which points to my pointee(s)"; in fact, that
would be an unusable definition. Consequently, pointers that aren't
used to access objects aren't constrained by restrict rules.

Dan



More information about the cfe-dev mailing list