[LLVMdev] Can we assume const parameter and to-be-modified parameter do not alias?

yi_jiang
Fri, 09 Jan 2015 22:21:44 -0000

Hi,

This question is raised from the following example:

int foo (const int a[], int b[])
{
     ...
     b[i] = …
     …
}

Basically a[] is defined as read-only while b[] will be explicitly modified in
the function.  At the first glance, they can not be alias but  it seems that we
can not figure out the alias info between them now which prevent us from doing
some optimizations.   Here is the quote from:

c99 rationale, v5.10, p. 77

const is specified in such a way that an implementation is at liberty to put
const objects in read-only storage, and is encouraged to diagnose obvious
attempts to modify them, but is not required to track down all the subtle ways
that such checking can be subverted.

Our understanding is that it is user’s responsibility to guarantee that const
array will not be touched in any way and if not the behavior is undefined and in
this case it is safe to assume that they are not alias?