Issue 121092
Summary [C++ Coroutine] clang++ does not generate debug info for coroutine frame type when optimization enabled.
Labels clang
Assignees
Reporter KKRainbow
    When compiling with `-O0 -g`, the __coro_frame and `coro_frame_ty` exists in debug info

```
$ clang++ -O0 -g -std=c++20 ./test.cc
$ llvm-dwarfdump a.out| grep 'coro_frame'
                  DW_AT_name    ("__coro_frame")
 DW_AT_type    (0x00001f84 "_ZL9coro_taski.coro_frame_ty")
 DW_AT_name    ("__coro_frame")
                  DW_AT_type (0x00001f84 "_ZL9coro_taski.coro_frame_ty")
```

But when compilinig with `-O2 -g` (also -O1 / -O3), no coroutine types can be found in debug info.

This problem exists in both clang 18 and clang 19. GCC can generate corrent coroutine frame types after enabling any level optimization.


The code example is from https://clang.llvm.org/docs/DebuggingCoroutines.html#examples-to-print-coroutine-frames, also same for all other coroutine programs.


```
#include <coroutine>
#include <iostream>

struct task{
  struct promise_type {
 task get_return_object() { return std::coroutine_handle<promise_type>::from_promise(*this); }
 std::suspend_always initial_suspend() { return {}; }
    std::suspend_always final_suspend() noexcept { return {}; }
    void return_void() noexcept {}
 void unhandled_exception() noexcept {}

    int count = 0;
  };

 void resume() noexcept {
    handle.resume();
  }

 task(std::coroutine_handle<promise_type> hdl) : handle(hdl) {}
  ~task() {
 if (handle)
      handle.destroy();
  }

  std::coroutine_handle<> handle;
};

class await_counter : public std::suspend_always {
 public:
    template<class PromiseType>
    void await_suspend(std::coroutine_handle<PromiseType> handle) noexcept {
 handle.promise().count++;
    }
};

static task coro_task(int v) {
  int a = v;
  co_await await_counter{};
  a++;
  std::cout << a << "\n";
 a++;
  std::cout << a << "\n";
  a++;
  std::cout << a << "\n";
 co_await await_counter{};
  a++;
  std::cout << a << "\n";
  a++;
 std::cout << a << "\n";
}

int main() {
  task t = coro_task(43);
 t.resume();
  t.resume();
  t.resume();
  return 0;
}
```


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to