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

    <tr>
        <th>Summary</th>
        <td>
            miscompilation with coroutine since 15.0.0: function has no ret call
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    godbolt: https://godbolt.org/z/YveThKxn5

```cpp
#include <coroutine>
#include <string>
#include <variant>

using TestType = std::string; // bug does not happen on e.g. int

struct async_generator {
    struct promise_type {
        //does not happen if this type is simple (pointer, or variant without TestType)
        std::variant<std::monostate, TestType, promise_type*> continuation_;
        promise_type*                                         result_receiver_ = nullptr;

        auto initial_suspend() {
            return std::suspend_never{};
        }

        auto final_suspend() noexcept {
            struct Suspension {
                promise_type* this_;

                auto await_ready() noexcept {
                    return false;
                }

                auto await_suspend(std::coroutine_handle<>) noexcept {
                    if (this_->result_receiver_) {
                        std::coroutine_handle<promise_type>::from_promise(*this_->result_receiver_).resume();
                    }

                    if (std::holds_alternative<promise_type*>(this_->continuation_)) {
                        this_->continuation_ = std::monostate{};
                    }
                }

                auto await_resume() noexcept {
                }
            };
            return Suspension{this};
        }

        auto get_return_object() noexcept {
            return async_generator{this};
        }

        auto yield_value(TestType) noexcept {
            return std::suspend_always{};
        }

        void unhandled_exception() {
            std::terminate();
        }
    };

    ~async_generator() noexcept {
        std::coroutine_handle<promise_type>::from_promise(*controller_).destroy();
    }

    promise_type* controller_;
};

static auto bar() -> async_generator {
    co_yield "";
}

void foo() {
    asm("nop");//not strictly necessary, but bug is better visible that way
    bar();
}
```

clang++-14 -O3 -std=c++20 -stdlib=libc++
```asm
foo():                                # @foo()
        nop
        ret
```


clang++-15 -O3 -std=c++20 -stdlib=libc++
```asm
foo():                                # @foo()
        nop
```
</pre>
<img width="1px" height="1px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