<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJy1VUFv6zYM_jXOhWhgy4njHHxok3Yo0AcMPWzHB1mWY-3JkmHJydpfv092msR9r4dhWKDIEkmRHymSKm31Vjz-zdtOyyi9p8b7zmERsSeMg61Kq_3S9gfs3vF_5Hn_-_tvSR7F-yi-n-bnmjgduR4kKUeDkxVx0VvnyA2uk8Ypa6izynhH3FSkfJBz3vaQBNWSbyQJ29vBKyOp7nkrI7YLgq06NJ4afpQ4CmGYUVCv1cG00vglPXtyUrYOOjjEZWv7N6pt_yudwSzX2gruYfmkfAPgnebKkACdgCTKYtvJngMcGXmKWO7UO8BswVjeOv2nhAdDW2poGjo46Bto73oLSkunRho6SBM0KXOgl5c_vtHzK2DYlr69PL8G98oBgfAR2ziS3L0F872EhmoQMvg-AtxF7AGDxVdn4ISjk9R6Bug8Z_F5jFvn-0H4KV7cwZt1wuAM2SOQBSLQR5uHSfiWCtEgBx7crEJGpPcC5ilKdxgUMbazxgXtMrAD4crD2RwX2_n-uw-xY3mIzqiQremM4aopWu9M-KQPMLg_g4k2j_8Oz15O3v5PeHCeDEjnOIN-WY_z0SIxnTI_oH0GPDsDvxUWXReuc_LjnCe2h3mBoPqriwOsZiuATh-pVqU1XAg1xeIDx8fl_XwIyR2le4rHXBuXyQUzzVLA-RvG2Qc3RupKPjVKyxBLBFle7NNN-uAn7Pc3JXVF5c1JIj6EIm-7EQSfs0baXBxgkfQg48iM8QW0yyVdF_MymGakSzf4EKOvC-Z1MNNint0xTT_c0N3d3VTrGGM5O8_Fj5u-cu6Ehlo0ll8pSzbZF6pmPesTvkVVpNU23fIFotnYvpDvzaCROsfF0OviU-dG6xjKpbAtNlofPz53aC9_SYH4PSnnBokaeFqnySpfNEXJV1mdinUWs7oq420tyoRt07KsV1lW82SheSm1K6I1GhITH30pFAoby2a0E8qykkjpsY72i_-OTBUsZixOEhbn8TrJl_E2367qdLMqE1HlpYhWsUSs9TLoCY_Voi9GleVwcGBq5by7MrlzIevl6AgQeuX1uNldGizItPv0dvz0cJx6i85-eYoWI-xixPwPHCYsUA>53148</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Coroutines] Coroutine frame allocated with a wrong alignment
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            llvm:codegen
      </td>
    </tr>

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

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

<pre>
    Example: https://godbolt.org/z/Ea8rPzG18

If a value is used across suspension points and it is stored into the coroutine frame, it might have an invalid alignment. It seems that memory for the coroutine frame is allocated with a plain call to `operator new(size)`.

We stumbled upon this problem when generating LLVM IR from MLIR, but it's easy to reproduce it with C++20 coroutines as well.


```
struct alignas(512) overaligned {
 overaligned() { std::cout << "Consructed: " << ((intptr_t)(this) % 512) << "\n"; }
 ~overaligned() { std::cout << "Destructed: " << ((intptr_t)(this) % 512) << "\n"; }
 int n;
};

void sink(overaligned&) {

cppcoro::generator<const std::uint64_t> fibonacci()
{
  std::uint64_t a = 0, b = 1;
  overaligned st;
  sink(st);
  while (true)
  {
    co_yield b;
    auto tmp = a;
    a = b;
    b += tmp;
    sink(st);
  }
}
```

output:

```
Run
Consructed: 0       <--- this is from stack allocated value in main
Consructed: 176   <--- this is from the coroutine
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VU1v4zgM_TXKhWhgy_lwDj60Sbso0AEWPeweB7KsxNqRJcOSk21__T7ZaRJ3poc5bKA4MkmR71EkU7rqrXj8VzStUSy7pzqE1mPD-BPWwVWlM2HuugPe3vF9FHn35_sfac6SHUvux-fzngQdhekVaU-9VxUJ2Tnvyfe-VdZrZ6l12gZPwlakQ7TzwXWwhNRRqBVJ17k-aKto34lGMb6Nho0-1IFqcVQ4CmOE0XBv9ME2yoY5PQfySjUePgTMVeO6N9q77lc-Y1hhjJM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