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

    <tr>
        <th>Summary</th>
        <td>
            LTO doesn't remove self-referential arrays
        </td>
    </tr>

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

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

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

<pre>
    Tested with clang-16 and `main`

Self referential arrays which are unreachable are not removed when using `-flto`, for example `clang -flto -Os unreachable.cc`:
~~~c++
// unreachable.cc

#include <stdio.h>

unsigned char unreachable[] = {1, 2, 3, 4, (unsigned char)((unsigned long)unreachable & 0xff)};

int main() {
  printf("here\n");
  return 0;
}
~~~

results in:
~~~shell
$ nm a.out |grep unreach
0000000000001050 t _GLOBAL__sub_I_unreachable.cc
000000000000401c b unreachable
~~~

Removing the last array element works as expected.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU01v4zgM_TXyhYghy98HH5pks1igQIGd3gNZom3NyFIgyU176W8fyOmHO1PDoGGKfHx6JLn3ajSIHSn3pDwmfAmTdZ24ohyv1sqkt_Kle0QfUMJVhQmE5mbcZRVwI4FUdObKkIoSeiT07mZ_oB7A4YAOTVBcA3eOv3i4TkpMwB3CYhxyMfFe4_pvbACHs32KVSY0sHhlxgi_G3SwEZ8dYLAO8JnPF43xaGUCawDsHvwWNBUi5uRvhF5fXwVh-_jeaLITYac_EzY3ICxXRuhFIpD84INUNp1I_s82ZjGrdBLExN0W6yYlkPwIpN5nkTmLJo-miIaw5ks2YS1hzdarrRkJa7c6EVYBfR6GGFwfSb7fklEmwNqJCNPGujc_wMUpE4bVzyZ0SMqDIYxFlPwjyGFYnAH6iVofP6Tb1nHoFx08KLMV10-o9btyBZgZeGqXAKQ-jA4v7-LcIujmyWhJIcD53_uH_d39-eyX_vzf-bu-bLMKmgnov0j-Hdf_40DFMQoTguY-3OYQUOOMJsDVul8euAd8vqAIKNNEdrls85Yn2GU1zWnWNk2eTJ2sWZNVRV02RVXWPRWy7jnyqmKy6lHUieoYZXnGspZltChYShkb-qbNuShFjQ0nBcWZK51q_TSn1o2J8n7Bri7bqkk071H7dQkZM3iF9TC2qTwmros5u34ZPSmoVj74T5Sggsbu_vEBpEVvCKvfNwk86mH39xomi9PdFMLFxxaumzCqMC19KuxM2ClCv312F2d_ogiEnVZCnrDTSvh3AAAA__-2TElY">