New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coroutines do work with Apple Clang but not with gcc #5997
Comments
@hkaiser Do you know if we fixed that or is it still open? |
The last time I checked was on Rostam with a (slightly) different version than the one that caused the issue, and I wasn't able to reproduce it. Let me try to reproduce it again with the exact same versions. |
I was able to reproduce this. Thanks! Let me take a look. |
There is a similar issue with sender and receivers. I will open a new ticket for that. |
While I wasn't able to use llvm/clang for testing, I made a simple workaround for this. diff --git a/hpx/CMakeLists.txt b/hpx/CMakeLists.txt
index ed6f08e..bd6102b 100644
--- a/hpx/CMakeLists.txt
+++ b/hpx/CMakeLists.txt
@@ -37,7 +37,7 @@ add_hpx_executable(taylor_hpx_distributed SOURCES taylor_hpx_distributed.cpp)
add_test(NAME "HPX:_Taylor_distributed" COMMAND taylor_hpx_distributed)
if(${WITH_COROUTINES})
- #add_hpx_executable(taylor_hpx_future_coroutine SOURCES taylor_hpx_future_coroutine.cpp)
+ add_hpx_executable(taylor_hpx_future_coroutine SOURCES taylor_hpx_future_coroutine.cpp)
add_test(NAME "HPX:_Taylor_future_coroutine" COMMAND taylor_hpx_future_coroutine 100 0.5 3)
endif()
diff --git a/hpx/taylor_hpx_future_coroutine.cpp b/hpx/taylor_hpx_future_coroutine.cpp
index cb43f08..bb21098 100644
--- a/hpx/taylor_hpx_future_coroutine.cpp
+++ b/hpx/taylor_hpx_future_coroutine.cpp
@@ -40,7 +40,7 @@ hpx::future<double> run(size_t n, size_t amount, double x) {
auto futures2 = co_await hpx::when_all(std::move(futures));
- for (size_t i = 0; i < futures2.size(); i++) result += co_await futures2[i];
+ for (size_t i = 0; i < futures2.size(); i++) result += co_await std::move(futures2[i]);
co_return result;
} Output:
|
@SAtacker thanks a lot. I think I now remember reading somewhere that clang co_await expects an rvalue reference for non-copyable awaitables. |
On taking another look
What does this mean? |
It means that co_await should be usable on a lvalue (glvalue) and a rvalue (prvalue). If used on a rvalue, a temporary object should be created from it before co_await-ing. Clearly, clang doesn't get this right in this case. |
There is a similar issue with Sender and Receiver, I will open a new ticket for that. |
@SAtacker thanks for the fix and I will update the code. |
@SAtacker I found another issue using gcc 10.3.1 and here I get the following error
and it is the same without |
Thanks, let me take a better look. (At a glance it seemed like a g++-10 issue as I had read somewhere that gcc 10.x does additional move, however if you say that's not the case I would definitely take a better look.) |
I was able to reproduce it on |
Found the link for this bug report on gcc - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103963 |
@SAtacker does this work, then?
|
It does not : ( |
I am not sure but it seems like an issue related to name_lookup? |
Found a bunch of stuff related to lookup of promise type for coroutines. diff releases/gcc-10.4.1 releases/gcc-11.1.0 2020-02-04 Iain Sandoe <iain@sandoe.co.uk>
+
+ * coroutines.cc (find_promise_type): Delete unused forward
+ declaration.
+ (struct coroutine_info): Add a bool for no promise type error.
+ (coro_promise_type_found_p): Only emit the error for a missing
+ promise once in each affected coroutine.
+
+2020-02-03 Iain Sandoe <iain@sandoe.co.uk>
+
+ PR c++/93458
+ * coroutines.cc (struct coroutine_info): Add a bool flag to note
+ that we emitted an error for a bad function return type.
+ (get_coroutine_info): Tolerate an unset info table in case of
+ missing traits.
+ (find_coro_traits_template_decl): In case of error or if we didn't
+ find a type template, note we emitted the error and suppress
+ duplicates.
+ (find_coro_handle_template_decl): Likewise.
+ (instantiate_coro_traits): Only check for error_mark_node in the
+ return from lookup_qualified_name.
+ (coro_promise_type_found_p): Reorder initialization so that we check
+ for the traits and their usability before allocation of the info
+ table. Check for a suitable return type and emit a diagnostic for
+ here instead of relying on the lookup machinery. This allows the
+ error to have a better location, and means we can suppress multiple
+ copies.
+ (coro_function_valid_p): Re-check for a valid promise (and thus the
+ traits) before proceeding. Tolerate missing info as a fatal error. I think this is definitely a bug related to promise lookup. Perhaps can we reproduce this on godboldt @hkaiser ? |
Yes, I agree.
Please feel free to try ;-) |
@diehlpk I compiled the same code with gcc-10.4.0 and with gcc-11.x and it works. This must be a bug, however I am not able to reproduce it on godbolt. |
Expected Behavior
The code should compile with both clang and gcc.
Actual Behavior
However, using gcc results in this error
Steps to Reproduce the Problem
... Please be as specific as possible while describing how to reproduce your problem.
Specifications
... Please describe your environment
The text was updated successfully, but these errors were encountered: