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

    <tr>
        <th>Summary</th>
        <td>
            Segmentation fault in the Attributor pass when analyzing store instructions with byval arguments
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ayrivera-intel
      </td>
    </tr>
</table>

<pre>
    Hi,

I attached an example that produces a segmentation fault in the Attributor pass. The example is pretty simple, a function @foo that allocates a space which is a structure, the argument of @foo is written in one field, then calls @bar. Function @bar will have the allocated space as parameter but set as byval and will write in another field of this space.

I'm not familiar with this optimization, but will try to explain the best I can. Tracing the issue I found that getAAFor is called in lib/Transform/IPO/AttributorAttributes.cpp line 1495 , the creation of an AA calls a function that updates the information (updateImpl), which calls translateAndAddCalleeState from line 1628 in the same file. In this function, the condition in 1296 (`IsByval && !RAcc.isRead()`) happens for one of the entries of the iterator (It.second). This means that addChange didn't run for a particular access.

Once the AA is created for line 1495, the function translateAndAddCalleeState runs again in line 1498. But now it have states (It) where the second entry in the pair is a null pointer. This produces a segmentation fault when traversing the loop in line 1296. It seems that skipping addChange during the first call of translateAndAddCalleeState prevents updating the access information and populates the map with null pointers.

The issue can be reproduced with the following command:

`opt -passes=attributor simple.ll -S`

I also attached a text file that contains the information of the crash.

[attributor_crash.txt](https://github.com/llvm/llvm-project/files/8783059/attributor_crash.txt)
[simple.zip](https://github.com/llvm/llvm-project/files/8783063/simple.zip)


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