Issue 123347
Summary 17 Regression: over optimization at -O2
Labels new issue
Assignees
Reporter NewSigma
    godbolt: https://godbolt.org/z/4xEEz6fsY

```
#include <iostream>
#include <coroutine>
#include <utility>
#include <vector>

struct Promise {
 std::vector<int> obj;

    ~Promise() {
        std::cout << "~Promise: " << obj.data() << std::endl;
    }

    auto get_return_object() { return std::coroutine_handle<Promise>::from_promise(*this); };
 std::suspend_never initial_suspend() noexcept { return {}; }
 std::suspend_never final_suspend() noexcept { return {}; }
 std::suspend_always yield_value(std::vector<int> b) noexcept {
        obj = std::move(b);
        return {};
    }
    void return_void() noexcept {}
    void unhandled_exception() {}
};

struct coro {
    using promise_type = Promise;

    std::vector<int> arr;
 std::coroutine_handle<Promise> handle;

 coro(std::coroutine_handle<Promise> handle_) noexcept {
        handle = handle_;
        arr = std::move(handle_.promise().obj);
    }
};

coro fn() {
    co_yield std::vector<int>(1);
}

int main(int argc, char** argv) {
    coro cr = fn();
    std::cout << "main: " << cr.arr.data() << std::endl;
    cr.handle.resume();
    return 0;
}
```

The code works fine using clang 16, but it breaks using 17 ~ trunk.

Possible wrong result(-O2):
main: 0x61c7ada362f0
~Promise: 0x61c7ada362f0

Expected result(-O0):
main: 0x61c7ada362f0
~Promise: 0

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

Reply via email to