[llvm-dev] Aliasing rules for const type pointer

Nema, Ashutosh via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 10 22:32:43 PDT 2019


I'm not clear with the aliasing rules for the pointer pointing to const memory.

It will be great help if someone clarify my doubts.

Consider below test program:
int foo(int *A, int *B, const int *C, int len) {
  for (int i = 0; i < len; i++)
    A[i] = B[i] + *C;

In this test case the type for "C" is const int * type, it means the pointer is pointing to a memory which is of type constant.

My understanding is value at *C can't be modified in the program, so its invariant and possibly can be hoisted.

There is a possibility that address pointed by C can alias with the address range pointed by A.

But in this case since user has mentioned value pointed by C as constant so I feel aliasing should not be an issue.

Please correct if something wrong with this understanding.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190611/c3260670/attachment.html>

More information about the llvm-dev mailing list