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

Joerg Sonnenberger joerg at britannica.bec.de
Wed Dec 12 08:38:30 PST 2012

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

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? Is that
assumption violated if I explicitly cast away const and pass the result
to a function with NoAlias argument?

I think the required changes for correctness of C restrict would be:
Two identified objects do not alias, if they are both NoAlias arguments
or both are not NoAlias arguments. If one of the identified objects is a
NoAlias argument and the context in question considers the referenced
object, they don't alias. For the purpose of pointer comparision, they
are may be equal.


More information about the llvm-dev mailing list