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

Joerg Sonnenberger joerg at britannica.bec.de
Wed Dec 12 13:26:57 PST 2012

On Wed, Dec 12, 2012 at 11:01:01AM -0800, Dan Gohman wrote:
> > 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.

The original issue is that clang maps restrict on function arguments to
NoAlias and that makes compares against the address of global variables
false. Minimal test case:

@y = external global i32

define zeroext i1 @t(i32* noalias %x) nounwind uwtable readnone {
  %cmp = icmp eq i32* %x, @y
  ret i1 %cmp


More information about the llvm-dev mailing list