my question is related to the different semantics of the restrict qualifier in C and the noalias attribute in LLVM when they are used as function parameters.
According to the LLVM documentation for noalias:
This indicates that objects accessed via pointer values based on the argument or return value are not also accessed, during the execution of the function, via pointer values not based on the argument or return value.
In case of the restrict qualifier, the draft of the C11 (Example 3, page124, sect. 6.7.3.1) puts an example where there is aliasing between two restrict arguments, which is fine as long as they only read data:
void h(int n, int * restrict p, int * restrict q, int * restrict r) {
int i;
for (i = 0; i < n; i++)
p[i] = q[i] + r[i];
}
To me, it seems as if the example given above would not satisfy the semantics of noalias. Is this the case?
As suggested by Jens Gustedt, digging into the links brought me to the AliasAnalysis page that states:
The most obvious example is when the two pointers point to non-overlapping memory ranges. Another is when the two pointers are only ever used for reading memory. Another is when the memory is freed and reallocated between accesses through one pointer and accesses through the other — in this case, there is a dependence, but it’s mediated by the free and reallocation.
This solves the question: the noalias
attribute is equivalent to the C restrict
qualifier in function parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With