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

    <tr>
        <th>Summary</th>
        <td>
            clang 18 fails to apply HALO
        </td>
    </tr>

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

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

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

<pre>
    While clang 17.0.1 is able to elide the heap allocations of the coroutines, clang 18.1.0 does not seem to be able to do so even for simple coroutine code like this:

```cpp
struct initiation : public std::suspend_always
{
    struct promise_type
    {
 constexpr auto initial_suspend() const noexcept { return std::suspend_always{}; }

        constexpr auto final_suspend() const noexcept {
            struct final_awaiter : public std::suspend_always
            {
                auto await_suspend(std::coroutine_handle<initiation::promise_type> h) noexcept -> std::coroutine_handle<>
                {
                    return h.promise().previous;
                }
            };
 return final_awaiter{};
        }

        [[noreturn]] void unhandled_exception() const { std::terminate(); }

        constexpr auto get_return_object() noexcept -> initiation
        {
 return initiation{std::coroutine_handle<promise_type>::from_promise(*this)};
 }

        constexpr void return_value(int a) noexcept {
 returned_value = a;
        }

        // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
 std::coroutine_handle<> previous = std::noop_coroutine();
        // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
        int returned_value;
    };

    constexpr initiation(std::coroutine_handle<promise_type> handle) : coro(handle) {}

    // no copying
    constexpr initiation(const initiation&) = delete;

    constexpr initiation(initiation&&) = default;
 constexpr ~initiation() noexcept
    {
        coro.destroy();
 }
     
    constexpr auto await_suspend(std::coroutine_handle<> awaiting_coro) const noexcept
        -> std::coroutine_handle<>
 {
        coro.promise().previous = awaiting_coro;
        return coro;
    }

    constexpr auto await_resume() const noexcept -> int
    {
        if constexpr(not std::is_void_v<int>) {
 return coro.promise().returned_value;
        }
    }

    // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
 std::coroutine_handle<promise_type> coro;
};



inline auto handle(int a) -> initiation
{
    co_return a;
}

inline auto handle2(int a) -> initiation
{
    co_return co_await handle(a);
}

inline auto handle3(int a) -> initiation
{
 co_return co_await handle2(a);
}

auto main() -> int
{
 auto awaitable = handle3(5);
    while(not awaitable.coro.done()) {
 awaitable.coro.resume();
    }
    auto ret = awaitable.coro.promise().returned_value;
    std::cout << ret << std::endl;
}
```
[link to godbold](https://godbolt.org/z/cf47qoWqY)


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V81u4zYQfhr6QliQKduyDzrEcYwusM2iwALbngRKGtlsKFJLUt51D332gqKsv8iJU6AVAlkhh9_MfPNDkmrNjgIgQqsdWu1ntDInqaI9VS_fmDj-mv5W0fRllsjsEn07MQ445VQc8SL0fG-BmcY04YCNxMBZBticAJ-AlphyLlNqmBQay7weT6WSlWECNCKPV5yNt_B8nEnQWEiDNUBh0RJogTOJtcRwBoFzqbBmRcl7YDiVGWDOXqxyplHwgPw98q_vte_-0rJ0I9qoKjWYCWZYbR9GwQMuq4SzFGuTWYDgQVe6BJHFlP-gF91ghTv3gTHGDUypZME0xOZSQjfZSaZSaAM_S4VpZWSjlccNPCIbRLZOCAsJP1MojV2NFZhKiZv2hDsU7lGww_an5y5unpHanIk7lA4hek665fQHZQbU3XT1gSbR7VObVyP3zGth2yDHJyoyDih47OLmRAYBCJ7wyfrWejW3Q2_BoeBp2rCbFtunic7Ja7Q7Sr1SwZnJSqPgxto2WuPBdkGDPGC8jfZw7Y3Q14W8E9IhodUerfb4LFmGK-HczmLHjuWwnws271quDKiCCWoa3-7PtSOY2OmOZfInpKbRMYxJL4wjp0ZM9ATD3VuRHCWCk8uVLOJ-kB7qHkG2A0Lfdaymr3HqTHllsZgwmA4cG9sOmRPGKNhjenf8yAGRA37-8vnT89fnp9-_fv70_ITIpmA6nQsp5qViZ2pgXkCRgJqfqWK2Veo5E_OUU62hdtCBvpP7-JqytY2tsJ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