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

    <tr>
        <th>Summary</th>
        <td>
            [clang][CodeGen] Assertion failure for dynamically-initialized const variable with addrspace
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          brunodf-snps
      </td>
    </tr>
</table>

<pre>
    An assertion failure in clang prevents to use a `const` global variable in a (non-default) address space with a dynamic initialization, for example:

```
int f();
extern const int __attribute__((address_space(10))) test3 = f();
```

[Godbolt demo](https://godbolt.org/z/1oajdfqx6)

The issue is related to the emission of an `llvm.invariant.start` intrinsic in the dynamic initialization of `const` variables.

(Issue diagnosed with help from @kortbeek-snps.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU8GOozgQ_ZriUgoyBpPkwKEzUUZ733tU4AI8Y-ysbbLd8_UrnExvb_dKlqNA1ePVe68oRjM55g7UCdS5oDXNPnR9WJ3X4y66Wyx6r9-6F4cUI4dkvMORjF0Do3E4WHIT3gLf2aWIyeMaGQmhFYN3MUErcLK-J4t3CoZ6m9sIQR6cdzvNI602gTwiaR04Row3Ghj_NmlGQv3maDEDGmeSIWt-0cYA5DccfUB-peVmGeoXEGcQv-9WPE_-a1zCEeQB5BHq0-MZvyYODjNF3AquV0opmH5NfL3m4sOTzzXzAXmoxIaQDyaOqUaoz1-QP338eavTd697bxNqXjyoM8jDnNItbtTlBeRlerwvfZhAXn6BvFSefujxr9d2g_8A9ufMaGJctxsDW0qsN-HTzMiLiXGzyI9IbnPB2vtSGpfFd6mMiUI2xbgUjItZ2tz6_0pvQB-9_G1iLP8znzz8kRlpQ5PzkfXDv5ntDcfgF4RG_PQh9cw_c6pKkMdCd7U-1kcquKv21V4JJdqqmDsl5FjpStLYVu1-aFVPzLU8VErWSrVVYTopZCNa0VSyaWRVNnslqBY86LbVLQtoBC9kbJnH92EqsmLdsakbVVjq2caceSlzgkHKLf6h2-p3_TpFaIQ1McV_EZJJNi_Ko0OdQZ2-ec3f2YE648uX9dgS-lSVrH3bvSvL-pm895V4pF3rkMNWrMF2n-Jh0rz25eAXkJeN0vNndwv-Bw8J5CVPGEFeHkPeO_lPAAAA____RT15">