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

    <tr>
        <th>Summary</th>
        <td>
            flang built with thinLTO causes crashes at runtime due to stack mis-alignment
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            flang,
            LTO
      </td>
    </tr>

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

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

<pre>
    When building flang with -flto=thin, the unit tests for flang cause segmentation faults. After some investigation I believe this is due to stack misalignment happening somewhere. 

The issue seems to be that the `MLIR::TypeStorage` class expects to be aligned to 8 bytes, as it inherits from `MLIR::StorageUniquer::BaseStorage` which has `alignas(8)`. But further up the stack `fir::BoxType`'s `impl` pointer ends up only being 4 byte aligned, and so calling member functions on it causes the segmentation fault. All these variables are on the stack so I am not sure why the alignment should be wrong. Specifically the crashes are happening in `MLIR::TypeConverter::convertType` when the callback is applied to `t`: https://github.com/llvm/llvm-project/blob/flang-lto/mlir/lib/Transforms/Utils/DialectConversion.cpp#L2965

Unfortunately that's as far as I could get with my investigation.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMFu4zgM_RrlQtSwFcdJDj5kGgQo0MUAOyn2LDu0zV1Z8opUMvn7hexmOkVPe4kii3rie4-kYabeIdZq801tjisTZfChPporXc4hNvdV4y_3-q8BHTSR7IVcD501rocbyQBPnRWv1kcZyCn9DDIgREcCgiwMnQ_v0a2JjMDYj-jECHkHnYlWOINDJxiA_YhA7oos1C8BL9CgJbwiyEAMxHCJCOKBxbT_wEhsLPUuIcJgpgldyi4B3QYMmIHKjyo_LL_nAYGYY0oCR04wTQI2MietqvyP15c_1fqg1ofzfcIf4oPpUVU5tNYwA_6csJXHxfllvKTdDpq7ICf6hoEEyA0YKNEPfvyM_I765ujfiGH59s3w76_dBmoHGAynm_MzhpXe7ZTeqyrP4FsU6GKQAQPEaU5-0UNVeUcPTP8zkVBVrvR2RqJxsgl-8uSS3ugunO57Z-_QYFKunIk8qM183AXYQ2usTQEjjg0G6KJrk0EM3iW-s7e8ZPLF4AwO1qYzRriaQKaxyGACpssfybOHFzAjOC_AMSDchvt8_GExDz7aSxL_FrzrM_gxYUsdpeyW2DYYHt7RPwqC3Fd3n727YpCHBe2yfZcMbqncZ0BjbZPSIwYzTZYWx1WVS5J2fYBBZOIEok9Kn3qSITZZ60elT9ZeH8vTFPzf2IrSp8b6RunT3BVPqXn0abQUUiClg3MwjjsfRlb69CZk03okY7GVJWsm77J2mpRev-p9tfm9yt9c54NEZwRnTYzM_huGzoS0vEA7q9ijLB083j93Xba61OvLfr03K6yLalvk6yrflquhrrpi3XZmi2VR7ky1a6vNvtw35b4we73ZbldU61zrQhdlUZVFUWZ5sSvNbteusd1stsVWlTmOhmyWNMl86FdzR9ab_UYXK2satDxPIq3bpI_SWulnpXX3afd6_p7-b46rUM_qNrFnVeaWWPgDW0gs1sv4SbPrnXAaVa_n74-q_VUzAiE6oRG_TJmnXzW4isHW_9vymWSyceb5XwAAAP__1p3VnQ">