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

    <tr>
        <th>Summary</th>
        <td>
            Question about how to use the store IR instruction to obtain the blockaddress
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
     I am writing to enquire about a question.
When I read the IR language generated by a piece of C programs, I found that in C programs, the behavior of getting tag addresses is handled by a store directive after it is translated into IR.
![image](https://user-images.githubusercontent.com/62325246/202606156-77e8c676-199b-4ccc-9069-1c6439a14c60.png)

However, I read the official documents. Here's how Blockaddress works:


> blockaddress(@function, %block)
>    The 'blockaddress' constant computes the address of the specified basic block in the specified function, and always has an i8* type. Taking the address of the entry block is illegal.

>    This value only has defined behavior when used as an operand to the '[indirectbr](file:///D:/opensourse/llvm-3.0.src/docs/LangRef.html#i_indirectbr)' instruction, or for comparisons against null. Pointer equality tests between labels addresses results in undefined behavior — though, again, comparison against null is ok, and no label is equal to the null pointer. This may be passed around as an opaque pointer sized value as long as the bits are not inspected. This allows ptrtoint and arithmetic to be performed on these values so long as the original value is reconstituted before the indirectbr instruction.

>    Finally, some targets may provide defined semantics when using the value as the operand to an inline assembly, but that is target specific.

So I want to figure out how stores construct blockaddress in the IR program by storing them in%5.
    What should I do if I want to use C++ to construct this store directive to get Addresses of Basic Blocks?
    
    I made some attempts, such as constructing an indirectbr:
    
![image](https://user-images.githubusercontent.com/62325246/202606387-3001ec89-1530-4547-8650-f723bb534da0.png)

   The IR program generated is as follows:
    
![image](https://user-images.githubusercontent.com/62325246/202606420-1e53d85d-fd28-40b4-9f9c-4970ba7e0e60.png)

    After my test, it can be executed correctly. Therefore, I want to know how to construct a similar store IR to store the address of the basic block in the array.
    
    That's my question. Look forward to your reply.Thanks!
    Best Regards, 
    zevorn.









</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VsuSozYU_Rq8UUEB5mEWXnTPTNd01SySzlRlmRIgsNICeSTRjufrc64APzq9yCbpcmOwHvfonnPPpdbtec-eGR_YyUgnx545zcT4Y5JGMF7ryTHOfkzCOqnHKIg_B_HD7wcxYo0RvGXuINjzC1N87CfeC9aLURjuRMvqM1YepWgE0x37xI5G94YPNkg_YXGnp5FWc8fk-G6U9qzFgb9JbWhtL9yMjPeMt60R1grLpGUHPrZqDWWdBuQWuBsn3wC-c8Iw6WiiM3y0ysOSIw74_LIcJUiTIH-UA6AH-ecg3R2cO9pgi4EnfCYrTOhHbdRLd5hq-qXRoxOjixo9YE6RbtM8zQrcpnFaxEWSF2FZil1TlEWYVFUdZk3ThFVcVGHSFNm24knWFHF0HPsgrRYg_vpVn8SbMHOKLvnVXScbyRVrdTMNiGwj9lUYEaQlcqBP7FHp5nXJDDtp8-pPcLPvct1-YfXNVBw3yOJuGhsil4IGae4nXGFhCf6-AwWi3S8uGRJhHR8dbobj5EAKwV2BgDl6tEfRyE4STdzKZkZApN8P3sIArYyrEz8TxRaPTO6C9IG581FE7Dt_9Wr4ZyikxpzXAFCIUqLnKnqfA38gjL9xNSG7ozr7MK3o5EgwV-mdSOcgHGA8CH2EtEm12kdDBkg74yy52swC6qQSF_3g83l-wNrR6slYsPak1NsQbqM4sqbBI2hFOp--oYZeRBcd3KCCdCv_uNkafCDfEuk20yVNgNjhn5LPjbQgg_Ge0yQ2TkpF7BcNtaMIxI-JK-nODBQ5iwO6k8DRFK-Fsjclha9JYQLIQXW-T0fwJQ12cVBlOL2e-oNniuLRzRXEHQaiQb-unI56jkm_ekxrKv3U44w2mskZOJgU7MitJ8B4v1h54HCkdT6z8idmzGRigtIQB5-lWEuchsMWRk0-Q2qDBywRuFL6ZNnRGUc7zaqDCR4G4aBTQKP4wiDHAwJor1gr5kiWWX0XShvZyxFHmoFIyqavD-kmb4eiI3-iqVdebxn9SKZPtK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