[clang] [llvm] [Coroutines] Replace coro.outside.frame metadata with an intrinsic (PR #129255)

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Wed May 6 02:20:05 PDT 2026


zmodem wrote:

> > if we promote the alloca to a register, we may spill that to the coroutine frame.
> 
> I feel this may not be bad according to our intention. The intention was simply something on the coroutine frame may introduce some memory issues. But if the alloca can be a register, there is no memory issues. So I think it is fine.

It can cause memory issues if the register gets put in the coro frame and there is a use after the coro frame is freed, as was the case in #192351.

It's also a strange semantic: if the intrinsic means "don't put this in the coro frame", it seems bad if it can end up in the frame after all.

Performance wise, I haven't come up with a case where the intrinsic would be a problem. Here's a basic test case:

```
#include <coroutine>
#include <stdio.h>

class BasicCoroutine { // Borrowed from https://theshoemaker.de/posts/yet-another-cpp-coroutine-tutorial
public:
  struct Promise {
    BasicCoroutine get_return_object() { return BasicCoroutine {}; }
    void unhandled_exception() noexcept { }
    void return_void() noexcept { }
    std::suspend_never initial_suspend() noexcept { return {}; }
    std::suspend_never final_suspend() noexcept { return {}; }
  };
  using promise_type = Promise;
};

struct Class {
  Class(int x) : x(x) {}
  int x;
};

void use(int x) noexcept;

BasicCoroutine coro(Class t) {
  use(t.x);
  co_return;
}

int main() {
  Class t(42);
  coro(t);
}
```

The `t` parameter will be put in an alloca passed to `coro.outside.frame`, but the code optimizes just fine.

https://github.com/llvm/llvm-project/pull/129255


More information about the cfe-commits mailing list