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

    <tr>
        <th>Summary</th>
        <td>
            [ABI] [C++] [Coroutines]  Promise may not be at the fixed offset from the coroutine frame when Promise has large alignment
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            ABI,
            coroutines
      </td>
    </tr>

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

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

<pre>
    Reproducer: https://godbolt.org/z/WhG6z5czo

The ABI of coroutines require the layout of the coroutine frame to be:

```
struct coroutine_frame {
    void (*resume_fn)();
    void (*destroy_fn)();
    promise_type promise;
    ... // Other needed variables
};
```

In another words, the layout implies that the promise needs to be at the fixed offset from the coroutine frame. The offset is generally 16 (2 pointer size). However, currently the compiler will try to reorder the place of promise when the alignment of promise exceeds the max default align value (which is 16 too, but this 16 is irreverent with the above 16). So here is the problem.

Note that this promise won't be covered by the well-known coro handle alignment problem, which is covered by `-fcoro-aligned-allocation` option.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE1zmzAQ_TVw0ZiRhQFz4GDHkzaXttN2pr1lhLQYtQI5krBj__qugDhuJj3Ug0H7odV7bxdqI8_VVzhYIwcBNko3pPX-4HARsXu89kbWRvvE2D1aF_z_aD_kl0xcTER3Ed1M9-8tkM32gZiGCGPN4FUPjlh4GpQF4jGq-RndISFY1yTSWN5hhiE1hENvakY5na_RdN4Owr_ufJx2RsV2ihP8HY2SJGLriG0suKHDpD5i5egpo_T9TAlY2pz_mYridMrBoz8f4MX4KyFJEjKpRT4jOUt6AAmSHLlVvNbgZj7F7rrtDbfp_tAT3puxwslY6SJ2dyud6g5aoaq-5X70z1jG49wkIZlDjXpGAKZpHHiU2HTvqZ6Q0LY5STmyhx4s1_pMlnnQhpGDUb1HOE5dAGVJyEdzgiPOCSITg7XQe8yeSncHpQNypTXx9hzwWEAa6BvBai7CYVfUpxb6McK12vcdlrqNwrOYWGFCx5-JhIYP2k_JqKweIEA8tUq0ATsi9sYEXPUQJJhceFeIEhGH8ifl2-nE2hwB4yOlb4ag4hByZ1GxZV1y25hPxsOL7Jh2ZWBwYgofZBcmnCFJPalxAq0Xv3tz6kfNSct7qW-ZzqcEvFcKNzVwMBZN2LkYt4DEpzaCe4VH5pSYQ1glMVTLPM_KYk1TGssqlWVa8tgrr6GKsi2-kVG2I7i6i9g2XLN1fUWDg3yZ-XT8THD-_neMpk6-FGm5w4G1-xu28WB19eazgq0Y6gSnBg2tjy-PBQrzC4RHUzk3IEB2n63TsojbKitFwWqZy1VDIV2tgRZMrGjGBBVC1jTWvAbtAvGIMTExZhTXQWZ8BDmuxutnKviyXawqRhlb0mVB0xXqmayz1brJm6YASZc5TaMVhY4rnQSg4YMY22rEXA97h0GtnHevQe5caN3YiFCfD741trprB94_qZ9DGY8Mq5HeHyO9ym8">