Issue 53148
Summary [Coroutines] Coroutine frame allocated with a wrong alignment
Labels c++20, llvm:codegen
Assignees
Reporter ezhulenev
    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
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to