<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/104508>104508</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Attributor]: AAPointerInfo does not keep track of access bins properly when a pointer is copied to a new pointer. 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vidsinghal
      </td>
    </tr>
</table>

<pre>
    
```
#include <stdio.h>
#include <stdlib.h>


typedef struct {
    int a; 
    int b; 
 int c;
} Prod;


Prod* foo(){

    Prod *P1 = (Prod*) malloc(sizeof(Prod));
    P1->a = 9; 
    P1->b = 10;

    Prod *P2;
    P2 = P1; 
    P2->c = 20;  

    return P2; 
}

int main(){
    Prod *P = foo(); 
    printf("a: %d, b: %d, c: %d\n", P->a, P->b, P->c);
}
```

> clang -Xclang -disable-O0-optnone -save-temps file.c
> opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -debug-only=attributor file.bc -o file.out.bc

Expected two distinct bins [0, 4] and [4, 8] for Pointer P1. 
In reality records 4 accesses in one bin [0, 8]
[Attributor] Got 4 initial uses to check
[AAPointerInfo] Analyze   %P1 = alloca ptr, align 8 in   %0 = load ptr, ptr %P1, align 8
[AAPointerInfo] Analyze   %P1 = alloca ptr, align 8 in   %1 = load ptr, ptr %P1, align 8
[AAPointerInfo] Analyze   %P1 = alloca ptr, align 8 in %2 = load ptr, ptr %P1, align 8
Accesses by bin after update:
[0-8] : 4
     - 9 -   store ptr %call, ptr %P1, align 8
       - c:   %call = call noalias ptr @malloc(i64 noundef 12) #3
     - 5 -   %0 = load ptr, ptr %P1, align 8
       - c: <unknown>
     - 5 -   %1 = load ptr, ptr %P1, align 8
       - c: <unknown>
     - 5 -   %2 = load ptr, ptr %P1, align 8
       - c: <unknown>

Expected 3 bins for Pointer P2. ([0, 4], [4, 8], [8, 12])
In reality, records 3 access in one bin [0, 8]
The access to element c of struct is never recorded, [8, 12]
[Attributor] Got 3 initial uses to check
[AAPointerInfo] Analyze   %P2 = alloca ptr, align 8 in   store ptr %2, ptr %P2, align 8
[AAPointerInfo] Analyze   %P2 = alloca ptr, align 8 in   %3 = load ptr, ptr %P2, align 8
[AAPointerInfo] Analyze   %P2 = alloca ptr, align 8 in   %4 = load ptr, ptr %P2, align 8
Accesses by bin after update:
[0-8] : 3
     - 9 -   store ptr %2, ptr %P2, align 8
       - c:   %call = call noalias ptr @malloc(i64 noundef 12) #3
     - 5 -   %3 = load ptr, ptr %P2, align 8
       - c: <unknown>
     - 5 -   %4 = load ptr, ptr %P2, align 8
       - c: <unknown>

Expected 3 bins for Pointer P. ([0, 4], [4, 8], [8, 12])
In reality, records 4 accesses in one bin [0, 8]
bin [8, 12], ie, access to c is not there. 
[AAPointerInfo] Analyze   %P = alloca ptr, align 8 in   store ptr %call, ptr %P, align 8
[AAPointerInfo] Analyze   %P = alloca ptr, align 8 in   %0 = load ptr, ptr %P, align 8
[AAPointerInfo] Analyze   %P = alloca ptr, align 8 in   %2 = load ptr, ptr %P, align 8
[AAPointerInfo] Analyze   %P = alloca ptr, align 8 in   %4 = load ptr, ptr %P, align 8
Accesses by bin after update:
[0-8] : 4
     - 9 - store ptr %call, ptr %P, align 8
       - c:   %call = call noalias ptr @malloc(i64 noundef 12) #3
     - 5 -   %0 = load ptr, ptr %P, align 8
 - c: <unknown>
     - 5 -   %2 = load ptr, ptr %P, align 8
 - c: <unknown>
     - 5 -   %4 = load ptr, ptr %P, align 8
       - c: <unknown>







</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWE1z4ygQ_TX40iWXBJI_Dj44cbI1p_VhD3tFqGWzwaAClKzn12-BZVnyVMbjmWS2yqUPGl4_unkNFndO7jTiihQPpNhMeOv3xq5eZeWk3u25mpSmOq5IuiHpmszS7nd6pUxqodoKgbBH5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